From 718835820319a7782e418600e01a266ded325a0a Mon Sep 17 00:00:00 2001 From: Miklos Marton Date: Fri, 8 Nov 2024 10:32:21 +0100 Subject: [PATCH 1/3] Fix parsing Macros Change String Value command Fixes AgIsoVirtualTerminal/#39 --- .../isobus_virtual_terminal_objects.hpp | 1 + .../src/isobus_virtual_terminal_objects.cpp | 15 +--- ...obus_virtual_terminal_working_set_base.cpp | 79 +++++++++++-------- 3 files changed, 52 insertions(+), 43 deletions(-) diff --git a/isobus/include/isobus/isobus/isobus_virtual_terminal_objects.hpp b/isobus/include/isobus/isobus/isobus_virtual_terminal_objects.hpp index 7171919f..7a32ca72 100644 --- a/isobus/include/isobus/isobus/isobus_virtual_terminal_objects.hpp +++ b/isobus/include/isobus/isobus/isobus_virtual_terminal_objects.hpp @@ -11,6 +11,7 @@ #include "isobus/isobus/can_constants.hpp" +#include #include #include #include diff --git a/isobus/src/isobus_virtual_terminal_objects.cpp b/isobus/src/isobus_virtual_terminal_objects.cpp index 4c14296b..a639b0a2 100644 --- a/isobus/src/isobus_virtual_terminal_objects.cpp +++ b/isobus/src/isobus_virtual_terminal_objects.cpp @@ -7638,18 +7638,9 @@ namespace isobus { for (const auto &command : commandPackets) { - bool currentCommandAllowed = false; - - for (const auto &allowedCommand : ALLOWED_COMMANDS_LOOKUP_TABLE) - { - if (!command.empty() && (command.at(0) == allowedCommand)) - { - currentCommandAllowed = true; - break; - } - } - - if (!currentCommandAllowed) + if (command.empty() || + std::find(ALLOWED_COMMANDS_LOOKUP_TABLE.begin(), ALLOWED_COMMANDS_LOOKUP_TABLE.end(), command[0]) == + ALLOWED_COMMANDS_LOOKUP_TABLE.end()) { retVal = false; break; diff --git a/isobus/src/isobus_virtual_terminal_working_set_base.cpp b/isobus/src/isobus_virtual_terminal_working_set_base.cpp index 0d7a7daa..254ce828 100644 --- a/isobus/src/isobus_virtual_terminal_working_set_base.cpp +++ b/isobus/src/isobus_virtual_terminal_working_set_base.cpp @@ -2753,39 +2753,56 @@ namespace isobus while (numberBytesProcessed < numberBytesToFollow) { - if (180 == iopData[0]) // Special case for change child position, which is 9 bytes. + auto commandLength = 8; + switch (static_cast(iopData[0])) { - retVal = tempObject->add_command_packet({ - iopData[0], - iopData[1], - iopData[2], - iopData[3], - iopData[4], - iopData[5], - iopData[6], - iopData[7], - iopData[8], - }); - iopLength -= CAN_DATA_LENGTH + 1; - iopData += CAN_DATA_LENGTH + 1; - numberBytesProcessed += CAN_DATA_LENGTH + 1; - } - else - { - retVal = tempObject->add_command_packet({ - iopData[0], - iopData[1], - iopData[2], - iopData[3], - iopData[4], - iopData[5], - iopData[6], - iopData[7], - }); - iopLength -= CAN_DATA_LENGTH; - iopData += CAN_DATA_LENGTH; - numberBytesProcessed += CAN_DATA_LENGTH; + case Macro::Command::ChangeChildPosition: + // special case: 9 bytes + retVal = tempObject->add_command_packet({ + iopData[0], + iopData[1], + iopData[2], + iopData[3], + iopData[4], + iopData[5], + iopData[6], + iopData[7], + iopData[8], + }); + commandLength = 9; + break; + case Macro::Command::GraphicsContextCommand: + // FIXME + break; + case Macro::Command::ChangeStringValue: { + // Change string value has variable length + std::vector command; + auto stringLength = static_cast(static_cast(iopData[3]) | (static_cast(iopData[4]) << 8)); + for (int i = 0; i<(stringLength + 5); i++) { + command.push_back(iopData[i]); + } + retVal = tempObject->add_command_packet(command); + commandLength = 5 + stringLength; + break; + } + default: + // all other macro commands are 8 byte long + retVal = tempObject->add_command_packet({ + iopData[0], + iopData[1], + iopData[2], + iopData[3], + iopData[4], + iopData[5], + iopData[6], + iopData[7], + }); + commandLength = 8; + break; } + iopLength -= commandLength; + iopData += commandLength; + numberBytesProcessed += commandLength; if (!retVal) { From 990c3d79cf63a7e44b57d89e43c8a6dd8c10023d Mon Sep 17 00:00:00 2001 From: Miklos Marton Date: Mon, 11 Nov 2024 14:26:13 +0100 Subject: [PATCH 2/3] Fix code formatting --- ...obus_virtual_terminal_working_set_base.cpp | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/isobus/src/isobus_virtual_terminal_working_set_base.cpp b/isobus/src/isobus_virtual_terminal_working_set_base.cpp index 254ce828..a3031a6f 100644 --- a/isobus/src/isobus_virtual_terminal_working_set_base.cpp +++ b/isobus/src/isobus_virtual_terminal_working_set_base.cpp @@ -2759,26 +2759,28 @@ namespace isobus case Macro::Command::ChangeChildPosition: // special case: 9 bytes retVal = tempObject->add_command_packet({ - iopData[0], - iopData[1], - iopData[2], - iopData[3], - iopData[4], - iopData[5], - iopData[6], - iopData[7], - iopData[8], + iopData[0], + iopData[1], + iopData[2], + iopData[3], + iopData[4], + iopData[5], + iopData[6], + iopData[7], + iopData[8], }); commandLength = 9; break; case Macro::Command::GraphicsContextCommand: // FIXME break; - case Macro::Command::ChangeStringValue: { + case Macro::Command::ChangeStringValue: + { // Change string value has variable length std::vector command; auto stringLength = static_cast(static_cast(iopData[3]) | (static_cast(iopData[4]) << 8)); - for (int i = 0; i<(stringLength + 5); i++) { + for (int i = 0; i < (stringLength + 5); i++) + { command.push_back(iopData[i]); } retVal = tempObject->add_command_packet(command); @@ -2788,14 +2790,14 @@ namespace isobus default: // all other macro commands are 8 byte long retVal = tempObject->add_command_packet({ - iopData[0], - iopData[1], - iopData[2], - iopData[3], - iopData[4], - iopData[5], - iopData[6], - iopData[7], + iopData[0], + iopData[1], + iopData[2], + iopData[3], + iopData[4], + iopData[5], + iopData[6], + iopData[7], }); commandLength = 8; break; From bf214ee2d17d240fcf252b41a0ea83813d545167 Mon Sep 17 00:00:00 2001 From: Miklos Marton Date: Mon, 11 Nov 2024 14:33:18 +0100 Subject: [PATCH 3/3] Fix formatting #2 --- isobus/src/isobus_virtual_terminal_objects.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/isobus/src/isobus_virtual_terminal_objects.cpp b/isobus/src/isobus_virtual_terminal_objects.cpp index a639b0a2..5842ee0a 100644 --- a/isobus/src/isobus_virtual_terminal_objects.cpp +++ b/isobus/src/isobus_virtual_terminal_objects.cpp @@ -7639,8 +7639,8 @@ namespace isobus for (const auto &command : commandPackets) { if (command.empty() || - std::find(ALLOWED_COMMANDS_LOOKUP_TABLE.begin(), ALLOWED_COMMANDS_LOOKUP_TABLE.end(), command[0]) == - ALLOWED_COMMANDS_LOOKUP_TABLE.end()) + std::find(ALLOWED_COMMANDS_LOOKUP_TABLE.begin(), ALLOWED_COMMANDS_LOOKUP_TABLE.end(), command[0]) == + ALLOWED_COMMANDS_LOOKUP_TABLE.end()) { retVal = false; break;