Skip to content

Commit

Permalink
feat(vt-client): add active data/alarm/softkey mask to state tracker …
Browse files Browse the repository at this point in the history
…and updater
  • Loading branch information
GwnDaan committed Jan 21, 2024
1 parent b6387b0 commit fbc4c39
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 109 deletions.
31 changes: 18 additions & 13 deletions examples/virtual_terminal/esp32_platformio_object_pool/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "isobus/isobus/can_partnered_control_function.hpp"
#include "isobus/isobus/can_stack_logger.hpp"
#include "isobus/isobus/isobus_virtual_terminal_client.hpp"
#include "isobus/isobus/isobus_virtual_terminal_client_update_helper.hpp"
#include "isobus/utility/iop_file_interface.hpp"

#include "console_logger.cpp"
Expand All @@ -17,40 +18,40 @@
#include <memory>

//! It is discouraged to use global variables, but it is done here for simplicity.
static std::shared_ptr<isobus::VirtualTerminalClient> TestVirtualTerminalClient = nullptr;
static std::shared_ptr<isobus::VirtualTerminalClient> virtualTerminalClient = nullptr;
static std::shared_ptr<isobus::VirtualTerminalClientUpdateHelper> virtualTerminalUpdateHelper = nullptr;

// This callback will provide us with event driven notifications of button presses from the stack
void handleVTKeyEvents(const isobus::VirtualTerminalClient::VTKeyEvent &event)
{
static std::uint32_t exampleNumberOutput = 214748364; // In the object pool the output number has an offset of -214748364 so we use this to represent 0.

switch (event.keyEvent)
{
case isobus::VirtualTerminalClient::KeyActivationCode::ButtonUnlatchedOrReleased:
case isobus::VirtualTerminalClient::KeyActivationCode::ButtonStillHeld:
{
switch (event.objectID)
{
case Plus_Button:
{
TestVirtualTerminalClient->send_change_numeric_value(ButtonExampleNumber_VarNum, ++exampleNumberOutput);
virtualTerminalUpdateHelper->increase_numeric_value(ButtonExampleNumber_VarNum);
}
break;

case Minus_Button:
{
TestVirtualTerminalClient->send_change_numeric_value(ButtonExampleNumber_VarNum, --exampleNumberOutput);
virtualTerminalUpdateHelper->decrease_numeric_value(ButtonExampleNumber_VarNum);
}
break;

case alarm_SoftKey:
{
TestVirtualTerminalClient->send_change_active_mask(example_WorkingSet, example_AlarmMask);
virtualTerminalUpdateHelper->set_active_data_or_alarm_mask(example_WorkingSet, example_AlarmMask);
}
break;

case acknowledgeAlarm_SoftKey:
{
TestVirtualTerminalClient->send_change_active_mask(example_WorkingSet, mainRunscreen_DataMask);
virtualTerminalUpdateHelper->set_active_data_or_alarm_mask(example_WorkingSet, mainRunscreen_DataMask);
}
break;

Expand Down Expand Up @@ -107,18 +108,22 @@ extern "C" void app_main()
auto TestInternalECU = isobus::InternalControlFunction::create(TestDeviceNAME, 0x1C, 0);
auto TestPartnerVT = isobus::PartneredControlFunction::create(0, vtNameFilters);

TestVirtualTerminalClient = std::make_shared<isobus::VirtualTerminalClient>(TestPartnerVT, TestInternalECU);
TestVirtualTerminalClient->set_object_pool(0, testPool, (object_pool_end - object_pool_start) - 1, "ais1");
auto softKeyListener = TestVirtualTerminalClient->add_vt_soft_key_event_listener(handleVTKeyEvents);
auto buttonListener = TestVirtualTerminalClient->add_vt_button_event_listener(handleVTKeyEvents);
TestVirtualTerminalClient->initialize(true);
virtualTerminalClient = std::make_shared<isobus::VirtualTerminalClient>(TestPartnerVT, TestInternalECU);
virtualTerminalClient->set_object_pool(0, testPool, (object_pool_end - object_pool_start) - 1, "ais1");
auto softKeyListener = virtualTerminalClient->add_vt_soft_key_event_listener(handleVTKeyEvents);
auto buttonListener = virtualTerminalClient->add_vt_button_event_listener(handleVTKeyEvents);
virtualTerminalClient->initialize(true);

virtualTerminalUpdateHelper = std::make_shared<isobus::VirtualTerminalClientUpdateHelper>(virtualTerminalClient);
virtualTerminalUpdateHelper->add_tracked_numeric_value(ButtonExampleNumber_VarNum, 214748364); // In the object pool the output number has an offset of -214748364 so we use this to represent 0.
virtualTerminalUpdateHelper->initialize();

while (true)
{
// CAN stack runs in other threads. Do nothing forever.
vTaskDelay(10);
}

TestVirtualTerminalClient->terminate();
virtualTerminalClient->terminate();
isobus::CANHardwareInterface::stop();
}
4 changes: 2 additions & 2 deletions examples/virtual_terminal/version3_object_pool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ void handleVTKeyEvents(const isobus::VirtualTerminalClient::VTKeyEvent &event)

case alarm_SoftKey:
{
virtualTerminalClient->send_change_active_mask(example_WorkingSet, example_AlarmMask);
virtualTerminalUpdateHelper->set_active_data_or_alarm_mask(example_WorkingSet, example_AlarmMask);
}
break;

case acknowledgeAlarm_SoftKey:
{
virtualTerminalClient->send_change_active_mask(example_WorkingSet, mainRunscreen_DataMask);
virtualTerminalUpdateHelper->set_active_data_or_alarm_mask(example_WorkingSet, mainRunscreen_DataMask);
}
break;

Expand Down
15 changes: 0 additions & 15 deletions isobus/include/isobus/isobus/isobus_virtual_terminal_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,6 @@ namespace isobus
/// @returns The internal control function being used by the client
std::shared_ptr<InternalControlFunction> get_internal_control_function() const;

/// @brief Returns the active working set master's address
/// @returns The active working set master's address, or 0xFE (NULL_CAN_ADDRESS) if none or unknown
std::uint8_t get_active_working_set_master_address() const;

/// @brief A struct for storing information of a VT key input event
struct VTKeyEvent
{
Expand Down Expand Up @@ -1206,14 +1202,6 @@ namespace isobus
/// @returns true if the VT version is supported by the VT server
bool is_vt_version_supported(VTVersion value) const;

/// @brief Returns the current data mask displayed by the VT server
/// @returns The object ID of the data mask visible
std::uint16_t get_visible_data_mask() const;

/// @brief Returns the current soft key mask displayed by the VT server
/// @returns The object ID of the soft key mask visible
std::uint16_t get_visible_soft_key_mask() const;

// ************************************************
// Object Pool Interface
// ************************************************
Expand Down Expand Up @@ -1606,9 +1594,6 @@ namespace isobus

// Status message contents from the VT
std::uint32_t lastVTStatusTimestamp_ms = 0; ///< The timestamp of the last VT status message
std::uint16_t activeWorkingSetDataMaskObjectID = NULL_OBJECT_ID; ///< The active working set data mask object ID
std::uint16_t activeWorkingSetSoftKeyMaskObjectID = NULL_OBJECT_ID; ///< The active working set's softkey mask object ID
std::uint8_t activeWorkingSetMasterAddress = NULL_CAN_ADDRESS; ///< The active working set master address
std::uint8_t busyCodesBitfield = 0; ///< The VT server's busy codes
std::uint8_t currentCommandFunctionCode = 0; ///< The VT server's current command function code

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ namespace isobus
/// @return The current numeric value of the tracked object.
std::uint32_t get_numeric_value(std::uint16_t objectId) const;

/// @brief Get the data/alarm mask currently active on the server for this client. It may not be displayed if the working set is not active.
/// @return The data/alarm mask currently active on the server for this client.
std::uint16_t get_active_mask() const;

/// @brief Adds a data/alarm mask to track the soft key mask for.
/// @param[in] dataOrAlarmMaskId The data/alarm mask to track the soft key mask for.
/// @param[in] initialSoftKeyMaskId The initial soft key mask to associate with the data/alarm mask.
void add_tracked_soft_key_mask(std::uint16_t dataOrAlarmMaskId, std::uint16_t initialSoftKeyMaskId);

/// @brief Removes a data/alarm mask from tracking the soft key mask for.
/// @param[in] dataOrAlarmMaskId The data/alarm mask to remove the soft key mask from tracking for.
void remove_tracked_soft_key_mask(std::uint16_t dataOrAlarmMaskId);

/// @brief Get the soft key mask currently active on thse server for this client. It may not be displayed if the working set is not active.
/// @return The soft key mask currently active on the server for this client.
std::uint16_t get_active_soft_key_mask() const;

/// @brief Get the soft key mask currently associated with a data/alarm mask.
/// @param[in] dataOrAlarmMaskId The data/alarm mask to get the currently associated soft key mask for.
/// @return The soft key mask currently associated with the supplied mask.
std::uint16_t get_soft_key_mask(std::uint16_t dataOrAlarmMaskId) const;

/// @brief Get whether the working set of the client is active on the server.
/// @return True if the working set is active, false otherwise.
bool is_working_set_active() const;

protected:
std::shared_ptr<ControlFunction> client; ///< The control function of the virtual terminal client to track.

Expand All @@ -64,9 +90,9 @@ namespace isobus
//! TODO: add font attribute state
//! TODO: add line attribute state
//! TODO: add fill attribute state
std::uint16_t currentActiveMask; ///< Holds the currently active mask.
//! TODO: std::uint16_t currentWorkingSet; ///< Holds the working set of the current active mask.
//! TODO: std::map<std::uint16_t, std::uint16_t> softKeyMasks; ///< Holds the data/alarms masks with their associated soft keys masks for tracked objects.
std::uint16_t activeDataOrAlarmMask; ///< Holds the data mask currently visible on the server for this client.
std::uint8_t activeWorkingSetAddress; ///< Holds the address of the control function that currently has it's working set active on the server.
std::map<std::uint16_t, std::uint16_t> softKeyMasks; ///< Holds the data/alarms masks with their associated soft keys masks for tracked objects.
//! TODO: std::map<std::uint16_t, std::pair<std::uint8_t, std::uint32_t>> attributeStates; ///< Holds the 'attribute' state of tracked objects.
//! TODO: std::map<std::uint16_t, std::uint8_t> alarmMaskPrioritiesStates; ///< Holds the 'alarm mask priority' state of tracked objects.
//! TODO: std::map<std::uint16_t, std::pair<std::uint8_t, std::uint16_t>> listItemStates; ///< Holds the 'list item' state of tracked objects.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ namespace isobus
/// @return True if the value was decreased successfully, false otherwise.
bool decrease_numeric_value(std::uint16_t objectId, std::uint32_t step = 1);

/// @brief Sets the active data/alarm mask.
/// @param[in] workingSetId The working set to set the active data/alarm mask for.
/// @param[in] dataOrAlarmMaskId The data/alarm mask to set active.
/// @return True if the data/alarm mask was set active successfully, false otherwise.
bool set_active_data_or_alarm_mask(std::uint16_t workingSetId, std::uint16_t dataOrAlarmMaskId);

/// @brief Sets the active soft key mask.
/// @param[in] maskType The type of mask to set the active soft key mask for.
/// @param[in] maskId The mask to set the active soft key mask for.
/// @param[in] softKeyMaskId The soft key mask to set active.
/// @return True if the soft key mask was set active successfully, false otherwise.
bool set_active_soft_key_mask(VirtualTerminalClient::MaskType maskType, std::uint16_t maskId, std::uint16_t softKeyMaskId);

private:
std::shared_ptr<VirtualTerminalClient> client; ///< Holds the vt client.
};
Expand Down
24 changes: 0 additions & 24 deletions isobus/src/isobus_virtual_terminal_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,6 @@ namespace isobus
return myControlFunction;
}

std::uint8_t VirtualTerminalClient::get_active_working_set_master_address() const
{
std::uint8_t retVal = NULL_CAN_ADDRESS;

if (get_is_connected())
{
retVal = activeWorkingSetMasterAddress;
}
return retVal;
}

std::shared_ptr<void> VirtualTerminalClient::add_vt_soft_key_event_listener(std::function<void(const VTKeyEvent &)> callback)
{
return softKeyEventDispatcher.add_listener(callback);
Expand Down Expand Up @@ -1209,16 +1198,6 @@ namespace isobus
return retVal;
}

std::uint16_t VirtualTerminalClient::get_visible_data_mask() const
{
return activeWorkingSetDataMaskObjectID;
}

std::uint16_t VirtualTerminalClient::get_visible_soft_key_mask() const
{
return activeWorkingSetSoftKeyMaskObjectID;
}

void VirtualTerminalClient::set_object_pool(std::uint8_t poolIndex, const std::uint8_t *pool, std::uint32_t size, std::string version)
{
if ((nullptr != pool) &&
Expand Down Expand Up @@ -2932,9 +2911,6 @@ namespace isobus
case static_cast<std::uint8_t>(Function::VTStatusMessage):
{
parentVT->lastVTStatusTimestamp_ms = SystemTiming::get_timestamp_ms();
parentVT->activeWorkingSetMasterAddress = message.get_uint8_at(1);
parentVT->activeWorkingSetDataMaskObjectID = message.get_uint16_at(2);
parentVT->activeWorkingSetSoftKeyMaskObjectID = message.get_uint16_at(4);
parentVT->busyCodesBitfield = message.get_uint8_at(6);
parentVT->currentCommandFunctionCode = message.get_uint8_at(7);
}
Expand Down
Loading

0 comments on commit fbc4c39

Please sign in to comment.