From 08aa8cf9cdfd4a844ba3beeee17ea6f6b05dbf9f Mon Sep 17 00:00:00 2001 From: Adrian Del Grosso <10929341+ad3154@users.noreply.github.com> Date: Fri, 29 Dec 2023 11:21:24 -0700 Subject: [PATCH] Fixed various start/stop issues Fixed frame handlers being removed and not re-added after the hardware interface was stopped. Changed the order of how we manage working set activation to avoid a possible deadlock between the Juce message thread and the callback mutex. Fixed issue with windows executable not being packaged into installer. Fixed accidentally drawing timed-out working set icons. Clarified start instructions. --- CMakeLists.txt | 9 +++++++ src/DataMaskRenderAreaComponent.cpp | 2 +- src/ServerMainComponent.cpp | 39 +++++++++++++++++++++++------ src/WorkingSetSelectorComponent.cpp | 4 ++- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85ba0dc..58ecc88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,7 @@ if(MSVC) ) endif() +if(APPLE) install( TARGETS AgISOVirtualTerminal RUNTIME @@ -124,6 +125,14 @@ install( BUNDLE DESTINATION . COMPONENT applications ) +else() +install( + TARGETS AgISOVirtualTerminal + RUNTIME + DESTINATION bin + COMPONENT applications + ) +endif() if(MSVC) install(FILES ${CMAKE_CURRENT_LIST_DIR}/lib/Usbcan64.dll DESTINATION bin COMPONENT applications) diff --git a/src/DataMaskRenderAreaComponent.cpp b/src/DataMaskRenderAreaComponent.cpp index 75a3bd7..ff54b7b 100644 --- a/src/DataMaskRenderAreaComponent.cpp +++ b/src/DataMaskRenderAreaComponent.cpp @@ -57,7 +57,7 @@ void DataMaskRenderAreaComponent::paint(Graphics &g) if (!hasStarted) { - g.drawFittedText("To start the VT server, select \"start\" from the file menu in the top left.", 0, 440, 400, 40, Justification::centredTop, 2); + g.drawFittedText("To start the VT server, select \"Start/Stop\" from the control menu in the top left.", 0, 440, 400, 40, Justification::centredTop, 2); } } } diff --git a/src/ServerMainComponent.cpp b/src/ServerMainComponent.cpp index f26ee59..49d468a 100644 --- a/src/ServerMainComponent.cpp +++ b/src/ServerMainComponent.cpp @@ -406,14 +406,6 @@ void ServerMainComponent::timerCallback() { ws->join_parsing_thread(); - if (ws->get_was_object_pool_loaded_from_non_volatile_memory()) - { - send_load_version_response(0, ws->get_control_function()); - } - else - { - send_end_of_object_pool_response(true, isobus::NULL_OBJECT_ID, isobus::NULL_OBJECT_ID, 0, ws->get_control_function()); - } workingSetSelector.update_drawn_working_sets(managedWorkingSetList); auto workingSetObject = std::static_pointer_cast(ws->get_working_set_object()); @@ -424,6 +416,15 @@ void ServerMainComponent::timerCallback() ws->set_working_set_maintenance_message_timestamp_ms(isobus::SystemTiming::get_timestamp_ms()); change_selected_working_set(0); } + + if (ws->get_was_object_pool_loaded_from_non_volatile_memory()) + { + send_load_version_response(0, ws->get_control_function()); + } + else + { + send_end_of_object_pool_response(true, isobus::NULL_OBJECT_ID, isobus::NULL_OBJECT_ID, 0, ws->get_control_function()); + } } else if (isobus::VirtualTerminalServerManagedWorkingSet::ObjectPoolProcessingThreadState::Fail == ws->get_object_pool_processing_state()) { @@ -787,7 +788,29 @@ bool ServerMainComponent::perform(const InvocationInfo &info) if (hasStartBeenCalled) { isobus::CANStackLogger::info("Stopping CAN interface"); + + // Save the frame handlers so we can re-add them after stopping the interface +#ifdef JUCE_WINDOWS + auto canDriver0 = isobus::CANHardwareInterface::get_assigned_can_channel_frame_handler(0); + auto canDriver1 = isobus::CANHardwareInterface::get_assigned_can_channel_frame_handler(1); + auto canDriver2 = isobus::CANHardwareInterface::get_assigned_can_channel_frame_handler(2); + auto canDriver3 = isobus::CANHardwareInterface::get_assigned_can_channel_frame_handler(3); +#else + auto canDriver = isobus::CANHardwareInterface::get_assigned_can_channel_frame_handler(0); +#endif + isobus::CANHardwareInterface::stop(); + + // Since "Stop" clears all frame handlers, we need to re-add the ones we saved +#ifdef JUCE_WINDOWS + isobus::CANHardwareInterface::assign_can_channel_frame_handler(0, canDriver0); + isobus::CANHardwareInterface::assign_can_channel_frame_handler(1, canDriver1); + isobus::CANHardwareInterface::assign_can_channel_frame_handler(2, canDriver2); + isobus::CANHardwareInterface::assign_can_channel_frame_handler(3, canDriver3); +#else + isobus::CANHardwareInterface::assign_can_channel_frame_handler(0, canDriver); +#endif + dataMaskRenderer.set_has_started(false); hasStartBeenCalled = false; } diff --git a/src/WorkingSetSelectorComponent.cpp b/src/WorkingSetSelectorComponent.cpp index 3a0ec43..84a7a6f 100644 --- a/src/WorkingSetSelectorComponent.cpp +++ b/src/WorkingSetSelectorComponent.cpp @@ -6,6 +6,7 @@ #include "WorkingSetSelectorComponent.hpp" #include "JuceManagedWorkingSetCache.hpp" #include "ServerMainComponent.hpp" +#include "isobus/utility/system_timing.hpp" WorkingSetSelectorComponent::WorkingSetSelectorComponent(ServerMainComponent &server) : parentServer(server) @@ -22,7 +23,8 @@ void WorkingSetSelectorComponent::update_drawn_working_sets(std::vectorget_object_pool_processing_state()) + if ((isobus::VirtualTerminalServerManagedWorkingSet::ObjectPoolProcessingThreadState::Joined == managedWorkingSetList.at(i)->get_object_pool_processing_state()) && + (!isobus::SystemTiming::time_expired_ms(managedWorkingSetList.at(i)->get_working_set_maintenance_message_timestamp_ms(), 3000))) { auto workingSetObject = managedWorkingSetList.at(i)->get_working_set_object();