Skip to content
Open
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 @@ -253,7 +253,7 @@ namespace isobus
{
TooManyRanges = 0x01, ///< Too many ranges (more than 255 sub-ranges in the requested range)
ErrorInCodePlane = 0x02,
AnyOtherError = 0x08
AnyOtherError = 0x10
};

/// @brief A struct for storing information of a function assigned to an auxiliary input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ namespace isobus
/// @param[in] xOffset The relative amount to offset the object(s) by in the X axis
/// @param[in] yOffset The relative amount to offset the object(s) by in the Y axis
/// @returns true if any child matched the specified object ID, otherwise false if no children were found with the specified ID.
bool offset_all_children_with_id(std::uint16_t childObjectID, std::int8_t xOffset, std::int8_t yOffset);
bool offset_all_children_with_id(std::uint16_t childObjectID, std::int16_t xOffset, std::int16_t yOffset);

/// @brief Removes an object reference from another object. All fields must exactly match for the object to be removed.
/// This is because objects can have multiple of the same child at different places, so we can't infer which one to
Expand Down
2 changes: 1 addition & 1 deletion isobus/src/isobus_virtual_terminal_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace isobus
}
}

bool VTObject::offset_all_children_with_id(std::uint16_t childObjectID, std::int8_t xOffset, std::int8_t yOffset)
bool VTObject::offset_all_children_with_id(std::uint16_t childObjectID, std::int16_t xOffset, std::int16_t yOffset)
{
bool retVal = false;

Expand Down
32 changes: 24 additions & 8 deletions isobus/src/isobus_virtual_terminal_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,12 @@ namespace isobus
std::uint16_t lastWideCharInInquiryRange = get_little_endian_uint16(data, 4);
auto errorCode = get_supported_wide_chars(codePlane, firstWideCharInInquiryRange, lastWideCharInInquiryRange, numberOfRanges, wideCharRangeArray);

if (0 != static_cast<std::uint8_t>(errorCode))
{
numberOfRanges = 0;
wideCharRangeArray.clear();
}

std::vector<std::uint8_t> buffer;
buffer.push_back(static_cast<std::uint8_t>(Function::GetSupportedWidecharsMessage));
buffer.push_back(codePlane);
Expand Down Expand Up @@ -1271,7 +1277,9 @@ namespace isobus
}
else
{
LOG_WARNING("[VT Server]: End of object pool message ignored - no object pools are loaded for the source control function");
LOG_WARNING("[VT Server]: End of object pool message rejected - no object pools are loaded for the source control function");
remove_object_pool(managedWorkingSet);
send_end_of_object_pool_response(false, NULL_OBJECT_ID, NULL_OBJECT_ID, get_bit(static_cast<std::uint8_t>(ObjectPoolErrorBit::AnyOtherError)), message.get_source_control_function(), false, &pendingObjectPoolDeletions.back().failure);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pool is deleted here, so should byte 7 also have bit 3 "object pool was deleted from volatile memory" (C.2.5), like the dropped transfer case just above? Right now only bit 2 "any other error" is set, so the client isn't told that the pool is gone.

}
}
break;
Expand Down Expand Up @@ -1428,7 +1436,9 @@ namespace isobus
auto objectId = get_little_endian_uint16(data, 1);
auto targetObject = managedWorkingSet->get_object_by_id(objectId);

if ((nullptr != targetObject) && (VirtualTerminalObjectType::Container == targetObject->get_object_type()))
const bool isContainer = (nullptr != targetObject) && (VirtualTerminalObjectType::Container == targetObject->get_object_type());

if (isContainer && (data[3] <= 1))
{
std::static_pointer_cast<Container>(targetObject)->set_hidden(0 == data[3]);
send_hide_show_object_response(objectId, 0, (0 != data[3]), managedWorkingSet->get_control_function());
Expand All @@ -1446,6 +1456,11 @@ namespace isobus
process_macro(targetObject, EventID::OnShow, targetObject->get_object_type(), managedWorkingSet);
}
}
else if (isContainer)
{
send_hide_show_object_response(objectId, get_bit(static_cast<std::uint8_t>(HideShowObjectErrorBit::CommandError)), (0 != data[3]), managedWorkingSet->get_control_function());
LOG_WARNING("[VT Server]: Client %u hide/show object command for %u has an invalid value %u", managedWorkingSet->get_control_function()->get_address(), objectId, data[3]);
}
else
{
send_hide_show_object_response(objectId, get_bit(static_cast<std::uint8_t>(HideShowObjectErrorBit::InvalidObjectID)), (0 != data[3]), managedWorkingSet->get_control_function());
Expand Down Expand Up @@ -1560,8 +1575,8 @@ namespace isobus

if (nullptr != lTargetObject)
{
auto xRelativeChange = static_cast<std::int8_t>(static_cast<std::int16_t>(data[5]) - 127);
auto yRelativeChange = static_cast<std::int8_t>(static_cast<std::int16_t>(data[6]) - 127);
auto xRelativeChange = static_cast<std::int16_t>(data[5] - 127);
auto yRelativeChange = static_cast<std::int16_t>(data[6] - 127);
bool anyObjectMatched = parentObject->offset_all_children_with_id(objectID, xRelativeChange, yRelativeChange);

if (anyObjectMatched)
Expand Down Expand Up @@ -2865,7 +2880,7 @@ namespace isobus
if ((nullptr != message.get_source_control_function()) &&
(nullptr != parentServer) &&
((CAN_DATA_LENGTH <= message.get_data_length()) ||
((message.get_data_length() > 5) && (static_cast<std::uint8_t>(Function::ChangeStringValueCommand) == message.get_uint8_at(0))))) // Technically this message can be 6 bytes
((message.get_data_length() > 5) && (static_cast<std::uint8_t>(Function::ChangeStringValueCommand) == message.get_uint8_at(0)) && (static_cast<std::uint32_t>(CANLibParameterGroupNumber::ECUtoVirtualTerminal) == message.get_identifier().get_parameter_group_number())))) // Technically this message can be 6 bytes
{
if (static_cast<std::uint32_t>(CANLibParameterGroupNumber::WorkingSetMaster) == message.get_identifier().get_parameter_group_number())
{
Expand Down Expand Up @@ -2928,7 +2943,7 @@ namespace isobus
CAN_DATA_LENGTH,
source,
destination,
get_priority());
CANIdentifier::CANPriority::PriorityDefault6);
}
return retVal;
}
Expand Down Expand Up @@ -3800,13 +3815,14 @@ namespace isobus
if (extendedMacro)
{
buffer[2] = get_high_byte(objectID);
buffer[3] = errorBitfield;
}
else
{
buffer[2] = 0xFF;
buffer[2] = errorBitfield;
buffer[3] = 0xFF;
}

buffer[3] = errorBitfield;
buffer[4] = 0xFF;
buffer[5] = 0xFF;
buffer[6] = 0xFF;
Expand Down
122 changes: 112 additions & 10 deletions test/vt_server_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ class DerivedTestVTServer : public VirtualTerminalServer
}
}

SupportedWideCharsErrorCode get_supported_wide_chars(std::uint8_t, std::uint16_t, std::uint16_t, std::uint8_t &numberOfRanges, std::vector<std::uint8_t> &) override
SupportedWideCharsErrorCode get_supported_wide_chars(std::uint8_t, std::uint16_t, std::uint16_t, std::uint8_t &numberOfRanges, std::vector<std::uint8_t> &wideCharRangeArray) override
{
numberOfRanges = 0;
return static_cast<SupportedWideCharsErrorCode>(0);
numberOfRanges = wideCharRangeCount;
wideCharRangeArray = wideCharRanges;
return wideCharsErrorCode;
}

std::vector<std::array<std::uint8_t, 7>> get_versions(NAME) override
Expand Down Expand Up @@ -290,6 +291,9 @@ class DerivedTestVTServer : public VirtualTerminalServer
using VirtualTerminalServer::send_status_message;
using VirtualTerminalServer::store_rx_message;

SupportedWideCharsErrorCode wideCharsErrorCode = static_cast<SupportedWideCharsErrorCode>(0);
std::uint8_t wideCharRangeCount = 0;
std::vector<std::uint8_t> wideCharRanges;
std::vector<std::uint8_t> versionToLoad;
VTVersion version = VTVersion::Version3;
bool saveSucceeds = true;
Expand Down Expand Up @@ -526,10 +530,10 @@ class VirtualTerminalServerMessagingTest : public AgIsoStackTestFixture
return foundNack;
}

// A managed working set without an object pool gets no response to an End of Object Pool message, an unmanaged one gets a NACK
// Probes with a Change Numeric Value for the null object ID, which changes nothing in a managed working set
bool is_managed(std::shared_ptr<InternalControlFunction> server, std::shared_ptr<ControlFunction> client, VirtualCANPlugin &plugin)
{
return !is_nacked(server, client, plugin, { 0x12, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
return !is_nacked(server, client, plugin, { 0xA8, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00 });
}

void receive_working_set_member_from_client(std::shared_ptr<ControlFunction> master, std::shared_ptr<ControlFunction> member)
Expand Down Expand Up @@ -628,6 +632,9 @@ static const std::vector<std::uint8_t> SELECTABLE_OBJECT_POOL = { 0x11, 0x00, 0x
/// and Macro 5, which Line 3 runs On Change End Point to resize Polygon 2 to 7x8
static const std::vector<std::uint8_t> POLYGON_AND_LINE_OBJECT_POOL = { 0x11, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE8, 0x03, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1B, 0xFF, 0xFF, 0x02, 0x00, 0x10, 0x64, 0x00, 0x32, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x21, 0x00, 0x11, 0x00, 0x03, 0x00, 0x0D, 0xFF, 0xFF, 0x0A, 0x00, 0x14, 0x00, 0x00, 0x01, 0x12, 0x05, 0x05, 0x00, 0x1C, 0x08, 0x00, 0xA6, 0x02, 0x00, 0x07, 0x00, 0x08, 0x00, 0xFF };

/// @brief Working Set 0 holds Object Pointer 1; Data Mask 1000 holds disabled Input Boolean 4 and hidden Container 2 (Input Boolean 3); Input Boolean 5 is on no mask
static const std::vector<std::uint8_t> INPUT_AND_CONTAINER_OBJECT_POOL = { 0x11, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE8, 0x03, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1B, 0xFF, 0xFF, 0xE8, 0x03, 0x01, 0x00, 0xFF, 0xFF, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x0A, 0x00, 0x0A, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0A, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x00, 0x04, 0x00, 0x07, 0x00, 0x0A, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x0A, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x00 };

/// @brief A VT server on a virtual bus with one connected client
class VirtualTerminalServerBusTest : public VirtualTerminalServerMessagingTest
{
Expand Down Expand Up @@ -774,7 +781,7 @@ TEST_F(VirtualTerminalServerBusTest, NackForUnmanagedWorkingSetIsSentToTheWorkin
time_source.update_for_ms(5);
ASSERT_TRUE(testPlugin.read_frame(nackFrame));

const std::uint32_t expectedUnicastIdentifier = test_helpers::create_ext_can_id(static_cast<std::uint8_t>(CANIdentifier::CANPriority::PriorityLowest7),
const std::uint32_t expectedUnicastIdentifier = test_helpers::create_ext_can_id(static_cast<std::uint8_t>(CANIdentifier::CANPriority::PriorityDefault6),
static_cast<std::uint32_t>(CANLibParameterGroupNumber::Acknowledge),
client,
internalECU);
Expand Down Expand Up @@ -807,6 +814,21 @@ TEST_F(VirtualTerminalServerBusTest, BroadcastFromUnmanagedClientIsNotNacked)
EXPECT_TRUE(is_nacked(internalECU, client, testPlugin, { 0x12, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }));
}

TEST_F(VirtualTerminalServerBusTest, ShortWorkingSetMemberFrameStartingWithChangeStringValueIsIgnored)
{
receive_from_client(internalECU, client, { 0xFF, 0x01, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
testPlugin.clear_queue();

CANNetworkManager::CANNetwork.process_receive_can_message_frame(test_helpers::create_message_frame_broadcast(5,
static_cast<std::uint32_t>(CANLibParameterGroupNumber::WorkingSetMember),
client,
{ 0xB3, 0x01, 0x02, 0x03, 0x04, 0x05 }));
CANNetworkManager::CANNetwork.update();

EXPECT_NO_THROW(server->process_rx_messages());
EXPECT_EQ(1U, server->managedWorkingSetList.size());
}

TEST_F(VirtualTerminalServerBusTest, CommandsAreDroppedWhenTheQueueIsFull)
{
receive_from_client(internalECU, client, { 0xFF, 0x01, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
Expand Down Expand Up @@ -1019,6 +1041,19 @@ TEST_F(VirtualTerminalServerBusTest, EndOfObjectPoolResponseReportsAnErrorWhenTh
EXPECT_EQ((std::vector<std::string>{ "parsed:81", "suspended:81" }), order);
}

TEST_F(VirtualTerminalServerBusTest, EndOfObjectPoolWithNoObjectPoolIsAnsweredWithAnError)
{
receive_from_client(internalECU, client, { 0xFF, 0x01, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
testPlugin.clear_queue();

CANMessageFrame response = {};
ASSERT_TRUE(send_and_poll({ 0x12, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, response));
EXPECT_EQ(0x01, response.data[1]); // Error in object pool
EXPECT_EQ(0x04, response.data[6]); // Any other error
EXPECT_TRUE(server->parsedWorkingSets.empty());
expect_single_suspension(0x01, NULL_OBJECT_ID, NULL_OBJECT_ID, 0x04);
}

TEST_F(VirtualTerminalServerBusTest, EndOfObjectPoolResponseReportsAnErrorWhenTheObjectPoolHasNoWorkingSetObject)
{
receive_from_client(internalECU, client, { 0xFF, 0x01, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
Expand Down Expand Up @@ -1540,11 +1575,35 @@ TEST_F(VirtualTerminalServerBusTest, ExecuteMacroCommandIsStillAnswered)

ASSERT_TRUE(connected);
ASSERT_TRUE(answered);
EXPECT_EQ(0x05, response.data[1]);
EXPECT_EQ(0x00, response.data[3]);
EXPECT_EQ((std::vector<std::uint8_t>{ 0xBE, 0x05, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }), payload_of(response));
EXPECT_EQ(7, server->managedWorkingSetList.front()->get_object_by_id(2)->get_width());
}

TEST_F(VirtualTerminalServerBusTest, ExecuteMacroCommandResponseCarriesTheErrorAtIndex2)
{
CANMessageFrame response = {};

const bool connected = upload_pool(POLYGON_AND_LINE_OBJECT_POOL);
// Object 2 is a polygon, not a macro
const bool answered = send_and_poll({ 0xBE, 0x02, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, response);

ASSERT_TRUE(connected);
ASSERT_TRUE(answered);
EXPECT_EQ((std::vector<std::uint8_t>{ 0xBE, 0x02, 0x02, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }), payload_of(response));
}

TEST_F(VirtualTerminalServerBusTest, ExecuteExtendedMacroCommandResponseCarriesBothIDBytes)
{
CANMessageFrame response = {};

const bool connected = upload_pool(POLYGON_AND_LINE_OBJECT_POOL);
const bool answered = send_and_poll({ 0xBC, 0x34, 0x12, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, response);

ASSERT_TRUE(connected);
ASSERT_TRUE(answered);
EXPECT_EQ((std::vector<std::uint8_t>{ 0xBC, 0x34, 0x12, 0x01, 0xFF, 0xFF, 0xFF, 0xFF }), payload_of(response));
}

TEST_F(VirtualTerminalServerBusTest, ThrowingMacroCommandDoesNotSilenceLaterResponses)
{
CANMessageFrame response = {};
Expand Down Expand Up @@ -1608,8 +1667,7 @@ TEST_F(VirtualTerminalServerBusTest, CommandsToObjectsOfTheWrongTypeReportTheErr
return errorByteOf(*command.begin(), errorByte);
};

// Working Set 0 holds Object Pointer 1; Data Mask 1000 holds disabled Input Boolean 4 and hidden Container 2 (Input Boolean 3); Input Boolean 5 is on no mask
const bool connected = upload_pool({ 0x11, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE8, 0x03, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1B, 0xFF, 0xFF, 0xE8, 0x03, 0x01, 0x00, 0xFF, 0xFF, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x0A, 0x00, 0x0A, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0A, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x00, 0x04, 0x00, 0x07, 0x00, 0x0A, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x0A, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x00 });
const bool connected = upload_pool(INPUT_AND_CONTAINER_OBJECT_POOL);

const int changeSize = errorCodeOf({ 0xA6, 0x01, 0x00, 0x0A, 0x00, 0x0A, 0x00, 0xFF }, 3);
const int changeBackgroundColour = errorCodeOf({ 0xA7, 0x01, 0x00, 0x05, 0xFF, 0xFF, 0xFF, 0xFF }, 4);
Expand Down Expand Up @@ -1668,6 +1726,50 @@ TEST_F(VirtualTerminalServerBusTest, CommandsToObjectsOfTheWrongTypeReportTheErr
EXPECT_EQ(0x00, openOnVersion3.data[4]);
}

TEST_F(VirtualTerminalServerBusTest, HideShowObjectWithAnInvalidCommandValueIsRefusedAndKeepsTheContainerState)
{
CANMessageFrame response = {};

const bool connected = upload_pool(INPUT_AND_CONTAINER_OBJECT_POOL);
const bool answered = send_and_poll({ 0xA0, 0x02, 0x00, 0x02, 0xFF, 0xFF, 0xFF, 0xFF }, response);

ASSERT_TRUE(connected);
ASSERT_TRUE(answered);
EXPECT_EQ(0x04, response.data[4]); // Command error
EXPECT_TRUE(std::static_pointer_cast<Container>(server->managedWorkingSetList.front()->get_object_by_id(2))->get_hidden());
}

TEST_F(VirtualTerminalServerBusTest, ChangeChildLocationOffsetOf255MovesTheChildBy128Pixels)
{
CANMessageFrame response = {};

ASSERT_TRUE(upload_pool(INPUT_AND_CONTAINER_OBJECT_POOL));
ASSERT_TRUE(send_and_poll({ 0xA5, 0xE8, 0x03, 0x02, 0x00, 0xFF, 0x7F, 0xFF }, response));
const auto dataMask = server->managedWorkingSetList.front()->get_object_by_id(1000);

ASSERT_NE(nullptr, dataMask);
EXPECT_EQ(0x00, response.data[5]);
ASSERT_EQ(2U, dataMask->get_number_children());
EXPECT_EQ(2, dataMask->get_child_id(1));
EXPECT_EQ(128, dataMask->get_child_x(1));
EXPECT_EQ(0, dataMask->get_child_y(1));
}

TEST_F(VirtualTerminalServerBusTest, SupportedWideCharsErrorResponseCarriesNoRanges)
{
CANMessageFrame response = {};

receive_from_client(internalECU, client, { 0xFF, 0x01, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
testPlugin.clear_queue();
server->wideCharsErrorCode = VirtualTerminalBase::SupportedWideCharsErrorCode::AnyOtherError;
server->wideCharRangeCount = 2;
server->wideCharRanges = { 0x20, 0x00, 0x7E, 0x00, 0xA0, 0x00, 0xFF, 0x00 };
const bool answered = send_and_poll({ 0xC1, 0x00, 0x20, 0x00, 0xFF, 0x00, 0xFF, 0xFF }, response);

ASSERT_TRUE(answered);
EXPECT_EQ((std::vector<std::uint8_t>{ 0xC1, 0x00, 0x20, 0x00, 0xFF, 0x00, 0x10, 0x00 }), payload_of(response));
}

TEST_F(VirtualTerminalServerBusTest, GetSupportedObjectsResponseIsASortedListOfVariableLength)
{
CANMessageFrame emptyResponse = {};
Expand Down
Loading