Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing Macros Change String Value command #505

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "isobus/isobus/can_constants.hpp"

#include <algorithm>
#include <array>
#include <map>
#include <memory>
Expand Down
15 changes: 3 additions & 12 deletions isobus/src/isobus_virtual_terminal_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
81 changes: 50 additions & 31 deletions isobus/src/isobus_virtual_terminal_working_set_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2753,39 +2753,58 @@ 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<Macro::Command>(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<std::uint8_t> command;
auto stringLength = static_cast<std::uint16_t>(static_cast<std::uint16_t>(iopData[3]) | (static_cast<std::uint16_t>(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)
{
Expand Down
Loading