From a16446a2f2bf1de8a3a6843a9aced88bee186f89 Mon Sep 17 00:00:00 2001 From: Miklos Marton Date: Wed, 1 Jan 2025 00:31:04 +0100 Subject: [PATCH] Add infrastructure to monitor the VT IOP loading progress --- .../isobus/isobus_virtual_terminal_server.hpp | 1 + ...al_terminal_server_managed_working_set.hpp | 7 ++++ ...obus_virtual_terminal_working_set_base.hpp | 1 + isobus/src/isobus_virtual_terminal_server.cpp | 2 + ...al_terminal_server_managed_working_set.cpp | 41 +++++++++++++++++++ ...obus_virtual_terminal_working_set_base.cpp | 1 + 6 files changed, 53 insertions(+) diff --git a/isobus/include/isobus/isobus/isobus_virtual_terminal_server.hpp b/isobus/include/isobus/isobus/isobus_virtual_terminal_server.hpp index c82fe69f..8b7461dc 100644 --- a/isobus/include/isobus/isobus/isobus_virtual_terminal_server.hpp +++ b/isobus/include/isobus/isobus/isobus_virtual_terminal_server.hpp @@ -673,6 +673,7 @@ namespace isobus LanguageCommandInterface languageCommandInterface; ///< The language command interface for the server std::shared_ptr serverInternalControlFunction; ///< The internal control function for the server std::vector> managedWorkingSetList; ///< The list of managed working sets + std::map, bool> managedWorkingSetIopLoadStateMap; std::shared_ptr activeWorkingSet; ///< The active working set std::uint32_t statusMessageTimestamp_ms = 0; ///< The timestamp of the last status message sent std::uint16_t activeWorkingSetDataMaskObjectID = NULL_OBJECT_ID; ///< The object ID of the active working set's data mask diff --git a/isobus/include/isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp b/isobus/include/isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp index 36ce980c..e50a24f4 100644 --- a/isobus/include/isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp +++ b/isobus/include/isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp @@ -121,6 +121,12 @@ namespace isobus /// @returns true if the working set should be deleted, otherwise false bool is_deletion_requested() const; + void set_iop_size(std::uint32_t newIopSize); + + float iop_load_percentage() const; + + bool is_object_pool_transfer_in_progress() const; + private: /// @brief Sets the object pool processing state to a new value /// @param[in] value The new state of processing the object pool @@ -138,6 +144,7 @@ namespace isobus std::uint16_t focusedObject = NULL_OBJECT_ID; ///< Stores the object ID of the currently focused object bool wasLoadedFromNonVolatileMemory = false; ///< Used to tell the server how this object pool was obtained bool workingSetDeletionRequested = false; ///< Used to tell the server to delete this working set + bool objectPoolTransferInProgress = false; }; } // namespace isobus diff --git a/isobus/include/isobus/isobus/isobus_virtual_terminal_working_set_base.hpp b/isobus/include/isobus/isobus/isobus_virtual_terminal_working_set_base.hpp index 868527fe..d7ff2098 100644 --- a/isobus/include/isobus/isobus/isobus_virtual_terminal_working_set_base.hpp +++ b/isobus/include/isobus/isobus/isobus_virtual_terminal_working_set_base.hpp @@ -92,6 +92,7 @@ namespace isobus std::mutex managedWorkingSetMutex; ///< A mutex to protect the interface of the managed working set VTColourTable workingSetColourTable; ///< This working set's colour table + std::uint32_t iopSize = 0, transferredIopSize = 0; std::map> vtObjectTree; ///< The C++ object representation (deserialized) of the object pool being managed std::vector> iopFilesRawData; ///< Raw IOP File data from the client std::uint16_t workingSetID = NULL_OBJECT_ID; ///< Stores the object ID of the working set object itself diff --git a/isobus/src/isobus_virtual_terminal_server.cpp b/isobus/src/isobus_virtual_terminal_server.cpp index 158ba84e..97cf68cc 100644 --- a/isobus/src/isobus_virtual_terminal_server.cpp +++ b/isobus/src/isobus_virtual_terminal_server.cpp @@ -283,6 +283,7 @@ namespace isobus { CANStackLogger::debug("[VT Server]: Callback indicated there may be enough memory, but since there is overhead associated to object storage it is impossible to be sure.", requiredMemory); } + cf->set_iop_size(requiredMemory); std::array buffer = { 0 }; buffer[0] = static_cast(Function::GetMemoryMessage); @@ -447,6 +448,7 @@ namespace isobus auto loadedVersion = parentServer->load_version(versionLabel, message.get_source_control_function()->get_NAME()); if (!loadedVersion.empty()) { + cf->set_iop_size(loadedVersion.size()); cf->add_iop_raw_data(loadedVersion); } else diff --git a/isobus/src/isobus_virtual_terminal_server_managed_working_set.cpp b/isobus/src/isobus_virtual_terminal_server_managed_working_set.cpp index 8fbcf0e8..ab560cf0 100644 --- a/isobus/src/isobus_virtual_terminal_server_managed_working_set.cpp +++ b/isobus/src/isobus_virtual_terminal_server_managed_working_set.cpp @@ -8,6 +8,7 @@ //================================================================================================ #include "isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp" +#include "isobus/isobus/can_network_manager.hpp" #include "isobus/isobus/can_stack_logger.hpp" #include "isobus/utility/to_string.hpp" @@ -127,10 +128,45 @@ namespace isobus return workingSetDeletionRequested; } + void VirtualTerminalServerManagedWorkingSet::set_iop_size(std::uint32_t newIopSize) + { + const std::lock_guard lock(managedWorkingSetMutex); + objectPoolTransferInProgress = true; + iopSize = newIopSize; + } + + float VirtualTerminalServerManagedWorkingSet::iop_load_percentage() const + { + if (iopSize == 0) + { + return 0.0f; + } + + auto totalTransferredSize = transferredIopSize; + if (totalTransferredSize < iopSize) { + // if IOP transfer is not completed check if there is an ongoing IOP transfer to us + auto sessions = CANNetworkManager::CANNetwork.get_active_transport_protocol_sessions(0); + for (const auto &session : sessions) + { + if (session->get_source()->get_address() == get_control_function()->get_address()) + { + totalTransferredSize += session->get_total_bytes_transferred(); + break; + } + } + } + + return (totalTransferredSize / (float)iopSize) * 100.0f; + } + void VirtualTerminalServerManagedWorkingSet::set_object_pool_processing_state(ObjectPoolProcessingThreadState value) { const std::lock_guard lock(managedWorkingSetMutex); processingState = value; + if (value != ObjectPoolProcessingThreadState::None) + { + objectPoolTransferInProgress = false; + } } void VirtualTerminalServerManagedWorkingSet::worker_thread_function() @@ -170,4 +206,9 @@ namespace isobus } } + bool VirtualTerminalServerManagedWorkingSet::is_object_pool_transfer_in_progress() const + { + return objectPoolTransferInProgress; + } + } // namespace isobus diff --git a/isobus/src/isobus_virtual_terminal_working_set_base.cpp b/isobus/src/isobus_virtual_terminal_working_set_base.cpp index 2b4bfda8..235df812 100644 --- a/isobus/src/isobus_virtual_terminal_working_set_base.cpp +++ b/isobus/src/isobus_virtual_terminal_working_set_base.cpp @@ -24,6 +24,7 @@ namespace isobus void VirtualTerminalWorkingSetBase::add_iop_raw_data(const std::vector &dataToAdd) { + transferredIopSize += dataToAdd.size(); iopFilesRawData.push_back(dataToAdd); }