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 @@ -453,6 +453,14 @@ namespace isobus
/// @param[in] value The object ID of the active mask for this working set
void set_active_mask(std::uint16_t value);

/// @brief Returns the languages the working set supports, as listed in its object (ISO 11783-6 Table B.2)
/// @returns The two-letter language codes, like "en", in the order of the object pool
const std::vector<std::string> &get_language_codes() const;

/// @brief Sets the languages the working set supports
/// @param[in] codes The two-letter language codes, like "en"
void set_language_codes(std::vector<std::string> codes);

private:
static constexpr std::uint32_t MIN_OBJECT_LENGTH = 10; ///< The fewest bytes of IOP data that can represent this object

Expand Down
10 changes: 10 additions & 0 deletions isobus/src/isobus_virtual_terminal_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,16 @@ namespace isobus
activeMask = value;
}

const std::vector<std::string> &WorkingSet::get_language_codes() const
{
return languageCodes;
}

void WorkingSet::set_language_codes(std::vector<std::string> codes)
{
languageCodes = std::move(codes);
}

VirtualTerminalObjectType DataMask::get_object_type() const
{
return VirtualTerminalObjectType::DataMask;
Expand Down
5 changes: 5 additions & 0 deletions isobus/src/isobus_virtual_terminal_working_set_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ namespace isobus
// Next, parse language list
if (iopLength >= static_cast<std::uint16_t>(numberOfLanguagesToFollow * 2))
{
// Any two letters are kept, as Table B.2 asks to accept all combinations of a-z and A-Z
std::vector<std::string> languageCodes;
languageCodes.reserve(numberOfLanguagesToFollow);
for (std::uint_fast8_t i = 0; i < numberOfLanguagesToFollow; i++)
{
std::string langCode;
Expand All @@ -222,7 +225,9 @@ namespace isobus
iopLength -= 2;
iopData += 2;
LOG_DEBUG("[WS]: IOP Language parsed: " + langCode);
languageCodes.push_back(std::move(langCode));
}
tempObject->set_language_codes(std::move(languageCodes));
retVal = true;
}
else
Expand Down
24 changes: 24 additions & 0 deletions test/vt_server_managed_working_set_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,30 @@ TEST(VirtualTerminalServerTest, WorkingSetSpecialControlsReadsEachLanguagePairOn
EXPECT_EQ("DE", codes[1].countryCode);
}

TEST(VirtualTerminalServerTest, WorkingSetKeepsItsLanguageCodes)
{
// Working Set 1 with no children or macros, and the languages "en", "DE" and "xY"
std::vector<std::uint8_t> object = { 0x01, 0x00, static_cast<std::uint8_t>(VirtualTerminalObjectType::WorkingSet), 0x00, 0x01, 0xE8, 0x03, 0x00, 0x00, 0x03, 'e', 'n', 'D', 'E', 'x', 'Y' };

VirtualTerminalServerManagedWorkingSet workingSet;
ASSERT_TRUE(workingSet.parse_iop_into_objects(object.data(), static_cast<std::uint32_t>(object.size())));

auto workingSetObject = std::static_pointer_cast<WorkingSet>(workingSet.get_object_by_id(1));
ASSERT_NE(nullptr, workingSetObject);
// Any pair of letters is accepted, not only the codes of ISO 639 (ISO 11783-6 Table B.2)
EXPECT_EQ((std::vector<std::string>{ "en", "DE", "xY" }), workingSetObject->get_language_codes());

std::vector<std::uint8_t> noLanguages = { 0x01, 0x00, static_cast<std::uint8_t>(VirtualTerminalObjectType::WorkingSet), 0x00, 0x01, 0xE8, 0x03, 0x00, 0x00, 0x00 };
VirtualTerminalServerManagedWorkingSet noLanguagesWorkingSet;
ASSERT_TRUE(noLanguagesWorkingSet.parse_iop_into_objects(noLanguages.data(), static_cast<std::uint32_t>(noLanguages.size())));
auto noLanguagesObject = std::static_pointer_cast<WorkingSet>(noLanguagesWorkingSet.get_object_by_id(1));
ASSERT_NE(nullptr, noLanguagesObject);
EXPECT_TRUE(noLanguagesObject->get_language_codes().empty());

noLanguagesObject->set_language_codes({ "fr" });
EXPECT_EQ((std::vector<std::string>{ "fr" }), noLanguagesObject->get_language_codes());
}

TEST(VirtualTerminalServerTest, ObjectOfAnotherTypeDoesNotReplaceAnObject)
{
// Container 1 (10x10), then a Number Variable with the same ID
Expand Down
Loading