Skip to content

Commit

Permalink
Add infrastructure to monitor the VT IOP loading progress
Browse files Browse the repository at this point in the history
  • Loading branch information
martonmiklos committed Jan 11, 2025
1 parent 4ad8020 commit a16446a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ namespace isobus
LanguageCommandInterface languageCommandInterface; ///< The language command interface for the server
std::shared_ptr<InternalControlFunction> serverInternalControlFunction; ///< The internal control function for the server
std::vector<std::shared_ptr<VirtualTerminalServerManagedWorkingSet>> managedWorkingSetList; ///< The list of managed working sets
std::map<std::shared_ptr<VirtualTerminalServerManagedWorkingSet>, bool> managedWorkingSetIopLoadStateMap;
std::shared_ptr<VirtualTerminalServerManagedWorkingSet> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint16_t, std::shared_ptr<VTObject>> vtObjectTree; ///< The C++ object representation (deserialized) of the object pool being managed
std::vector<std::vector<std::uint8_t>> 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
Expand Down
2 changes: 2 additions & 0 deletions isobus/src/isobus_virtual_terminal_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t, CAN_DATA_LENGTH> buffer = { 0 };
buffer[0] = static_cast<std::uint8_t>(Function::GetMemoryMessage);
Expand Down Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions isobus/src/isobus_virtual_terminal_server_managed_working_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -127,10 +128,45 @@ namespace isobus
return workingSetDeletionRequested;
}

void VirtualTerminalServerManagedWorkingSet::set_iop_size(std::uint32_t newIopSize)
{
const std::lock_guard<std::mutex> 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<std::mutex> lock(managedWorkingSetMutex);
processingState = value;
if (value != ObjectPoolProcessingThreadState::None)
{
objectPoolTransferInProgress = false;
}
}

void VirtualTerminalServerManagedWorkingSet::worker_thread_function()
Expand Down Expand Up @@ -170,4 +206,9 @@ namespace isobus
}
}

bool VirtualTerminalServerManagedWorkingSet::is_object_pool_transfer_in_progress() const
{
return objectPoolTransferInProgress;
}

} // namespace isobus
1 change: 1 addition & 0 deletions isobus/src/isobus_virtual_terminal_working_set_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace isobus

void VirtualTerminalWorkingSetBase::add_iop_raw_data(const std::vector<std::uint8_t> &dataToAdd)
{
transferredIopSize += dataToAdd.size();
iopFilesRawData.push_back(dataToAdd);
}

Expand Down

0 comments on commit a16446a

Please sign in to comment.