Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cor3ntin committed Aug 27, 2019
1 parent 8a6f6fd commit e4a7556
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,24 +209,35 @@ Rectangle {
})
}


Component.onCompleted: {
client.localEndpointChanged.connect(function () {
localEndpoint = client.localEndpoint
donglesManager = null
dongles = null
if(!localEndpoint) {
return
}

donglesManager = localEndpoint.donglesManager

if(!donglesManager) {
return
}

dongles = donglesManager.dongles
donglesManager.donglesChanged.connect(function () {
dongles = null
if(donglesManager) {
dongles = donglesManager.dongles
console.log("Dongles connected: %1".arg(dongles.length))
}
donglesManager.donglesChanged.connect(function() {
if(!wirelessConfigurator)
return;

wirelessConfigurator.dongles = donglesManager.dongles
console.log("Dongles connected: %1".arg(dongles.length))
updateState()
})

localEndpoint.nodesChanged.connect(function () {
nodes = null
if(localEndpoint)
nodes = localEndpoint.nodes
if(!wirelessConfigurator)
return;
wirelessConfigurator.nodes = localEndpoint.nodes
updateState()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Thymio2WirelessDonglesManager* ThymioDeviceManagerClientEndpoint::donglesManager
void ThymioDeviceManagerClientEndpoint::checkSocketHealth() {
if(m_last_message_reception_date.msecsTo(QDateTime::currentDateTime()) > 10 * 1000) {
qWarning() << "Connection timed out";
m_socket->disconnectFromHost();
// m_socket->disconnectFromHost();
disconnect(m_socket_health_check_timer);
}
}
Expand Down
11 changes: 8 additions & 3 deletions aseba/thymio-device-manager/aseba_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ void aseba_endpoint::free_endpoint() {
} // namespace mobsya

void aseba_endpoint::stop() {
variant_ns::visit(overloaded{[this](tcp_socket& socket) { socket.cancel(); }
variant_ns::visit(overloaded{[](tcp_socket& socket) { socket.cancel(); }
#ifdef MOBSYA_TDM_ENABLE_SERIAL
,
[this](mobsya::usb_serial_port& d) { d.cancel(); }
[](mobsya::usb_serial_port& d) {
boost::system::error_code ec;
d.cancel(ec);
}
#endif
#ifdef MOBSYA_TDM_ENABLE_USB
,
Expand Down Expand Up @@ -263,7 +266,6 @@ bool aseba_endpoint::wireless_enable_configuration_mode(bool enable) {
#ifdef MOBSYA_TDM_ENABLE_SERIAL
if(variant_ns::holds_alternative<usb_serial_port>(m_endpoint)) {
boost::asio::use_service<serial_acceptor_service>(m_io_context).pause(true);
boost::system::error_code ec;
serial().purge();
serial().set_rts(enable);
serial().set_data_terminal_ready(!enable);
Expand All @@ -286,8 +288,11 @@ bool aseba_endpoint::sync_wireless_dongle_settings(bool flash) {
[this, s, flash](auto& device) {
boost::system::error_code ec;
m_wireless_dongle_settings->data.ctrl = flash ? 0x01 : 0;
mLogDebug("Write");
if(device.write_some(boost::asio::buffer(&m_wireless_dongle_settings->data, s), ec) != s)
return false;
boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
mLogDebug("Read");
auto read = device.read_some(boost::asio::buffer(&m_wireless_dongle_settings->data, s), ec);
if(read < s - 1)
return false;
Expand Down
4 changes: 2 additions & 2 deletions aseba/thymio-device-manager/aseba_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,8 @@ bool aseba_node::set_rf_settings(uint16_t network, uint16_t node, uint8_t channe
auto ep = endpoint();

write_message(std::make_shared<Aseba::SetDeviceInfo>(native_id(), DEVICE_INFO_THYMIO2_RF_SETTINGS, data));
std::this_thread::sleep_for(std::chrono::milliseconds(500));
endpoint()->reboot();
write_message(std::make_shared<Aseba::Reboot>(native_id()));
// std::this_thread::sleep_for(std::chrono::milliseconds(500));
return true;
}

Expand Down
5 changes: 4 additions & 1 deletion aseba/thymio-device-manager/serialacceptor_udev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ void serial_acceptor_service::shutdown() {
}

void serial_acceptor_service::free_device(const std::string& s) {
m_known_devices.erase(std::find(m_known_devices.begin(), m_known_devices.end(), s));
auto it = std::find(m_known_devices.begin(), m_known_devices.end(), s);
if(it != m_known_devices.end()) {
m_known_devices.erase(it);
}
m_active_timer.expires_from_now(boost::posix_time::milliseconds(500));
m_active_timer.async_wait(boost::asio::bind_executor(
m_strand, boost::bind(&serial_acceptor_service::handle_request_by_active_enumeration, this)));
Expand Down

0 comments on commit e4a7556

Please sign in to comment.