From d511a49a4ef458d18d0a425fc5f65ac8c766800b Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Wed, 3 Apr 2024 17:02:03 -0400 Subject: [PATCH] allow preserve uuid in adapter config to associate with device. --- src/mtconnect/agent.cpp | 5 ++++ src/mtconnect/configuration/agent_config.cpp | 11 ++++++-- test_package/agent_test.cpp | 28 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/mtconnect/agent.cpp b/src/mtconnect/agent.cpp index 59fad7ee..592af871 100644 --- a/src/mtconnect/agent.cpp +++ b/src/mtconnect/agent.cpp @@ -857,6 +857,11 @@ namespace mtconnect { errors); device->addDataItem(di, errors); } + + if (IsOptionSet(m_options, mtconnect::configuration::PreserveUUID)) + { + device->setPreserveUuid(*GetOption(m_options, mtconnect::configuration::PreserveUUID)); + } } void Agent::initializeDataItems(DevicePtr device, std::optional> skip) diff --git a/src/mtconnect/configuration/agent_config.cpp b/src/mtconnect/configuration/agent_config.cpp index 6f8ccf90..ec196bad 100644 --- a/src/mtconnect/configuration/agent_config.cpp +++ b/src/mtconnect/configuration/agent_config.cpp @@ -887,10 +887,11 @@ namespace mtconnect::configuration { m_version = *m_agent->getSchemaVersion(); DevicePtr device; - if (IsOptionSet(options, configuration::PreserveUUID)) + auto preserve = GetOption(options, configuration::PreserveUUID); + if (preserve) { for (auto device : m_agent->getDevices()) - device->setPreserveUuid(IsOptionSet(options, configuration::PreserveUUID)); + device->setPreserveUuid(*preserve); } loadAdapters(config, options); @@ -994,6 +995,12 @@ namespace mtconnect::configuration { m_agent->deviceChanged(device, oldUuid, *device->getComponentName()); } + auto preserve = GetOption(adapterOptions, configuration::PreserveUUID); + if (preserve) + { + device->setPreserveUuid(*preserve); + } + auto additional = block.second.get_optional(configuration::AdditionalDevices); if (additional) { diff --git a/test_package/agent_test.cpp b/test_package/agent_test.cpp index 3e03e8d5..b4d44155 100644 --- a/test_package/agent_test.cpp +++ b/test_package/agent_test.cpp @@ -1686,6 +1686,34 @@ TEST_F(AgentTest, adapter_should_receive_commands) ASSERT_EQ("MK-1234", *GetOption(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");