From 850b21b281dbada536ca04e57dcbba2720f58ea3 Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Sun, 28 Apr 2024 12:58:57 -0400 Subject: [PATCH 1/4] Added initial value handling --- src/mtconnect/agent.cpp | 18 +++++++++++++++ .../device_model/data_item/data_item.cpp | 7 +++++- .../device_model/data_item/data_item.hpp | 11 +++++---- test_package/agent_test.cpp | 23 +++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/mtconnect/agent.cpp b/src/mtconnect/agent.cpp index 592af871..d8f69601 100644 --- a/src/mtconnect/agent.cpp +++ b/src/mtconnect/agent.cpp @@ -280,6 +280,24 @@ namespace mtconnect { // --------------------------------------- void Agent::receiveObservation(observation::ObservationPtr observation) { + // Check for availability + if (observation->getDataItem()->getType() == "AVAILABILITY" && !observation->isUnavailable()) + { + // Set all the initial values. + auto device = observation->getDataItem()->getComponent()->getDevice(); + for (auto item : device->getDeviceDataItems()) + { + if (item.expired()) + continue; + + auto di = item.lock(); + if (di->hasInitialValue()) + { + m_loopback->receive(di, *di->getInitialValue()); + } + } + } + std::lock_guard lock(m_circularBuffer); if (m_circularBuffer.addToBuffer(observation) != 0) { diff --git a/src/mtconnect/device_model/data_item/data_item.cpp b/src/mtconnect/device_model/data_item/data_item.cpp index df8d5c33..162c31d7 100644 --- a/src/mtconnect/device_model/data_item/data_item.cpp +++ b/src/mtconnect/device_model/data_item/data_item.cpp @@ -70,7 +70,7 @@ namespace mtconnect { {"Definition", ValueType::ENTITY, definition, false}, {"Constraints", ValueType::ENTITY_LIST, constraints, false}, {"Relationships", ValueType::ENTITY_LIST, relationships, false}, - {"InitialValue", ValueType::DOUBLE, false}, + {"InitialValue", ValueType::STRING, false}, {"ResetTrigger", false}}); factory->setFunction([](const std::string &name, Properties &props) -> EntityPtr { auto ptr = make_shared(name, props); @@ -201,6 +201,11 @@ namespace mtconnect { } } } + + if (const auto &init = maybeGet("InitialValue"); init) + { + m_initialValue = *init; + } if (const auto &filters = getList("Filters")) { diff --git a/src/mtconnect/device_model/data_item/data_item.hpp b/src/mtconnect/device_model/data_item/data_item.hpp index 6c4a7803..562f98f1 100644 --- a/src/mtconnect/device_model/data_item/data_item.hpp +++ b/src/mtconnect/device_model/data_item/data_item.hpp @@ -139,7 +139,11 @@ namespace mtconnect { /// @brief get the topic name leaf node for this data item /// @return the topic name const auto &getTopicName() const { return m_topicName; } - + + /// @brief get the initial value if one is set + /// @return optional initial value + const auto &getInitialValue() const { return m_initialValue; } + Category getCategory() const { return m_category; } Representation getRepresentation() const { return m_representation; } SpecialClass getSpecialClass() const { return m_specialClass; } @@ -169,6 +173,7 @@ namespace mtconnect { bool isDiscrete() const { return m_discrete; } bool isThreeSpace() const { return m_specialClass == THREE_SPACE_CLS; } bool isOrphan() const { return m_component.expired(); } + bool hasInitialValue() const { return bool(m_initialValue); } ///@} void makeDiscrete() @@ -279,6 +284,7 @@ namespace mtconnect { std::optional m_source; std::string m_preferredName; std::optional m_constantValue; + std::optional m_initialValue; std::optional m_minimumDelta; std::optional m_minimumPeriod; std::string m_key; @@ -301,9 +307,6 @@ namespace mtconnect { // The reset trigger; std::string m_resetTrigger; - // Initial value - std::string m_initialValue; - // Component that data item is associated with std::weak_ptr m_component; std::weak_ptr m_composition; diff --git a/test_package/agent_test.cpp b/test_package/agent_test.cpp index b4d44155..798e8a9c 100644 --- a/test_package/agent_test.cpp +++ b/test_package/agent_test.cpp @@ -3075,3 +3075,26 @@ TEST_F(AgentTest, should_set_sender_from_config_in_XML_header) ASSERT_XML_PATH_EQUAL(doc, "//m:Header@sender", "MachineXXX"); } } + +TEST_F(AgentTest, should_initialize_observaton_to_initial_value_when_available) +{ + m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.2", 4, true); + + auto device = m_agentTestHelper->getAgent()->getDeviceByName("LinuxCNC"); + ASSERT_TRUE(device); + + addAdapter(); + + { + PARSE_XML_RESPONSE("/current"); + ASSERT_XML_PATH_EQUAL(doc, "//m:DeviceStream//m:PartCount", "UNAVAILABLE"); + } + + m_agentTestHelper->m_adapter->processData("2024-01-22T20:00:00Z|avail|AVAILABLE"); + + { + PARSE_XML_RESPONSE("/current"); + ASSERT_XML_PATH_EQUAL(doc, "//m:DeviceStream//m:PartCount", "0"); + } + +} From 794da5c8b8892e67d5a78b7ba53ff3a3aa4d69ab Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Sun, 28 Apr 2024 13:10:33 -0400 Subject: [PATCH 2/4] use brew on mac to install conan 2 --- .github/workflows/build.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 263808dc..e503cfb9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -170,8 +170,9 @@ jobs: key: ${{ runner.os }}-build-${{ matrix.shared }}-${{ hashFiles('**/conanfile.py') }} - name: Install Conan - uses: turtlebrowser/get-conan@v1.2 - + run: | + brew install conan + - name: Setup Conan if: steps.cache.outputs.cache-hit != 'true' run: | From ea6bd34b6a8e4c6ccebcf2dbd697b8860f20f4f4 Mon Sep 17 00:00:00 2001 From: William Sobel Date: Sun, 28 Apr 2024 15:22:22 -0400 Subject: [PATCH 3/4] Fixed initial value. Changed to string. --- test_package/json_printer_probe_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_package/json_printer_probe_test.cpp b/test_package/json_printer_probe_test.cpp index 36b6e711..c3b6ed06 100644 --- a/test_package/json_printer_probe_test.cpp +++ b/test_package/json_printer_probe_test.cpp @@ -246,7 +246,7 @@ TEST_F(JsonPrinterProbeTest, InitialValue) json count = ::find(items, "/DataItem/id", "d2e9e4a0"); ASSERT_TRUE(count.is_object()); - ASSERT_EQ(1.0, count.at("/DataItem/InitialValue"_json_pointer).get()); + ASSERT_EQ("1", count.at("/DataItem/InitialValue"_json_pointer).get()); } TEST_F(JsonPrinterProbeTest, DataItemFilters) From de28136e38be3d9f48c36fb538c9655596e5ff82 Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Sun, 28 Apr 2024 16:25:10 -0400 Subject: [PATCH 4/4] version 2.3.0.8 --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f55bb6b7..95ce6c8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,7 @@ set(AGENT_VERSION_MAJOR 2) set(AGENT_VERSION_MINOR 3) set(AGENT_VERSION_PATCH 0) -set(AGENT_VERSION_BUILD 7 -) +set(AGENT_VERSION_BUILD 8) set(AGENT_VERSION_RC "") # This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent