Skip to content

Commit

Permalink
Merge pull request #433 from mtconnect/419_uuid_issues_with_preserve_id
Browse files Browse the repository at this point in the history
  • Loading branch information
wsobel authored Apr 3, 2024
2 parents 9f992f9 + 3d3a6c5 commit 96715d9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/mtconnect/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,11 @@ namespace mtconnect {
errors);
device->addDataItem(di, errors);
}

if (IsOptionSet(m_options, mtconnect::configuration::PreserveUUID))
{
device->setPreserveUuid(*GetOption<bool>(m_options, mtconnect::configuration::PreserveUUID));
}
}

void Agent::initializeDataItems(DevicePtr device, std::optional<std::set<std::string>> skip)
Expand Down
11 changes: 9 additions & 2 deletions src/mtconnect/configuration/agent_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,11 @@ namespace mtconnect::configuration {
m_version = *m_agent->getSchemaVersion();

DevicePtr device;
if (IsOptionSet(options, configuration::PreserveUUID))
auto preserve = GetOption<bool>(options, configuration::PreserveUUID);
if (preserve)
{
for (auto device : m_agent->getDevices())
device->setPreserveUuid(IsOptionSet(options, configuration::PreserveUUID));
device->setPreserveUuid(*preserve);
}

loadAdapters(config, options);
Expand Down Expand Up @@ -994,6 +995,12 @@ namespace mtconnect::configuration {
m_agent->deviceChanged(device, oldUuid, *device->getComponentName());
}

auto preserve = GetOption<bool>(adapterOptions, configuration::PreserveUUID);
if (preserve && device)
{
device->setPreserveUuid(*preserve);
}

auto additional = block.second.get_optional<string>(configuration::AdditionalDevices);
if (additional)
{
Expand Down
28 changes: 28 additions & 0 deletions test_package/agent_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,34 @@ TEST_F(AgentTest, adapter_should_receive_commands)
ASSERT_EQ("MK-1234", *GetOption<string>(options, configuration::Device));
}

TEST_F(AgentTest, adapter_should_not_process_uuid_command_with_preserve_uuid)
{
auto agent = m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.3", 4, false,
true, {{configuration::PreserveUUID, true}});
addAdapter();

auto device = agent->getDeviceByName("LinuxCNC");
ASSERT_TRUE(device);
ASSERT_TRUE(device->preserveUuid());

m_agentTestHelper->m_adapter->parseBuffer("* uuid: MK-1234\n");

{
PARSE_XML_RESPONSE("/probe");
ASSERT_XML_PATH_EQUAL(doc, "//m:Device@uuid", "000");
}

m_agentTestHelper->m_adapter->processData(
"2021-02-01T12:00:00Z|block|G01X00|mode|AUTOMATIC|execution|READY");

{
PARSE_XML_RESPONSE("/current");
ASSERT_XML_PATH_EQUAL(doc, "//m:Block", "G01X00");
ASSERT_XML_PATH_EQUAL(doc, "//m:ControllerMode", "AUTOMATIC");
ASSERT_XML_PATH_EQUAL(doc, "//m:Execution", "READY");
}
}

TEST_F(AgentTest, adapter_should_receive_device_commands)
{
m_agentTestHelper->createAgent("/samples/two_devices.xml");
Expand Down

0 comments on commit 96715d9

Please sign in to comment.