Skip to content

Commit

Permalink
Fixed various start/stop issues
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ad3154 committed Dec 29, 2023
1 parent e49bb07 commit 08aa8cf
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,22 @@ if(MSVC)
)
endif()

if(APPLE)
install(
TARGETS AgISOVirtualTerminal
RUNTIME
DESTINATION bin
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)
Expand Down
2 changes: 1 addition & 1 deletion src/DataMaskRenderAreaComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
39 changes: 31 additions & 8 deletions src/ServerMainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<isobus::WorkingSet>(ws->get_working_set_object());
Expand All @@ -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())
{
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/WorkingSetSelectorComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -22,7 +23,8 @@ void WorkingSetSelectorComponent::update_drawn_working_sets(std::vector<std::sha
{
children.push_back({ managedWorkingSetList.at(i) });

if (isobus::VirtualTerminalServerManagedWorkingSet::ObjectPoolProcessingThreadState::Joined == managedWorkingSetList.at(i)->get_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();

Expand Down

0 comments on commit 08aa8cf

Please sign in to comment.