From 9e253a750f1ec76bc7f23e526bd58b4e6be77c83 Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Mon, 30 May 2022 12:13:52 -0700 Subject: [PATCH 1/8] Made AssetChanged and Removed attribute assetType UNAVAILABLE when observation is unavailable --- src/observation/observation.cpp | 7 ++++- src/observation/observation.hpp | 2 -- test/observation_test.cpp | 48 ++++++++++++++++----------------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/observation/observation.cpp b/src/observation/observation.cpp index 4847c50ec..3bc0b13df 100644 --- a/src/observation/observation.cpp +++ b/src/observation/observation.cpp @@ -308,7 +308,12 @@ namespace mtconnect { { factory = make_shared(*Event::getFactory()); factory->setFunction([](const std::string &name, Properties &props) -> EntityPtr { - return make_shared(name, props); + auto ent = make_shared(name, props); + if (!ent->hasProperty("assetType") && !ent->hasValue()) + { + ent->setProperty("assetType", "UNAVAILABLE"s); + } + return ent; }); factory->addRequirements(Requirements({{"assetType", false}})); } diff --git a/src/observation/observation.hpp b/src/observation/observation.hpp index d0cc191ce..fcf882a85 100644 --- a/src/observation/observation.hpp +++ b/src/observation/observation.hpp @@ -316,8 +316,6 @@ namespace mtconnect { class AssetEvent : public Event { public: - using super = Event; - using Event::Event; static entity::FactoryPtr getFactory(); ~AssetEvent() override = default; diff --git a/test/observation_test.cpp b/test/observation_test.cpp index e0c30533a..5bd021d30 100644 --- a/test/observation_test.cpp +++ b/test/observation_test.cpp @@ -228,6 +228,30 @@ TEST_F(ObservationTest, subType_prefix_should_be_passed_through) ASSERT_EQ("x:AUTO", event->get("subType")); } +TEST_F(ObservationTest, shoud_handle_asset_type) +{ + ErrorList errors; + auto dataItem = DataItem::make( + {{"id", "c1"s}, {"category", "EVENT"s}, {"type", "ASSET_CHANGED"s}}, + errors); + + auto event1 = Observation::make(dataItem, {{"VALUE", "123"s}, {"assetType", "CuttingTool"s}}, + m_time, errors); + ASSERT_EQ(0, errors.size()); + + ASSERT_EQ("CuttingTool"s, event1->get("assetType")); + ASSERT_EQ("123"s, event1->getValue()); + + + auto event2 = Observation::make(dataItem, {{"VALUE", "UNAVAILABLE"s}}, + m_time, errors); + ASSERT_EQ(0, errors.size()); + + ASSERT_TRUE(event2->isUnavailable()); + ASSERT_EQ("UNAVAILABLE"s, event2->get("assetType")); +} + + // TODO: Make sure these tests are covered someplace else. Refactoring // Moved this functionality outside the observation. @@ -359,28 +383,4 @@ TEST_F(ObservationTest, Duration) d.reset(); } -TEST_F(ObservationTest, AssetChanged) -{ - string time("2011-02-18T15:52:41Z@200.1232"); - std::map attributes1; - attributes1["id"] = "1"; - attributes1["name"] = "ac"; - attributes1["type"] = "ASSET_CHANGED"; - attributes1["category"] = "EVENT"; - auto d = make_unique(attributes1); - - ASSERT_TRUE(d->isAssetChanged()); - - ObservationPtr event1(new Observation(*d, time, (string) "CuttingTool|123", 123), true); - const auto &attr_list = event1->getAttributes(); - map attrs1; - - for (const auto &attr : attr_list) - attrs1[attr.first] = attr.second; - - ASSERT_EQ((string) "CuttingTool", attrs1["assetType"]); - ASSERT_EQ((string) "123", event1->getValue()); - - d.reset(); -} #endif From 7180ce65b7f4500a42cbf5a2dde48f34e3693f21 Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Mon, 30 May 2022 12:18:07 -0700 Subject: [PATCH 2/8] Version 2.0.0.6 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21b4e2af5..eba09bd34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ set(AGENT_VERSION_MAJOR 2) set(AGENT_VERSION_MINOR 0) set(AGENT_VERSION_PATCH 0) -set(AGENT_VERSION_BUILD 5) +set(AGENT_VERSION_BUILD 6) set(AGENT_VERSION_RC "") # This minimum version is to support Visual Studio 2017 and C++ feature checking and FetchContent From e4404b130d6b3d3a1f64e8495e0c68e7641e41c5 Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Mon, 30 May 2022 13:32:48 -0700 Subject: [PATCH 3/8] Changed badge to public CI/CD --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28c4e2dd0..0e53ba776 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ MTConnect C++ Agent Version 2.0 -------- -[![Build status](https://ci.appveyor.com/api/projects/status/g4xdyitw7h41rl48?svg=true)](https://ci.appveyor.com/project/WilliamSobel/cppagent_dev) +[![Build status](https://ci.appveyor.com/api/projects/status/g4xdyitw7h41rl48/branch/master?svg=true)](https://ci.appveyor.com/project/WilliamSobel/cppagent/branch/master) The C++ Agent provides the a complete implementation of the HTTP server required by the MTConnect standard. The agent provides the From bbd6287f0b4e077e1391841b95654ed6b3d35e2c Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Mon, 30 May 2022 13:53:57 -0700 Subject: [PATCH 4/8] Updated build instructions --- README.md | 102 +++++++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 0e53ba776..4dc931f20 100644 --- a/README.md +++ b/README.md @@ -11,19 +11,19 @@ the devices and the location of the adapter. Pre-built binary releases for Windows are available from [Releases](https://github.com/mtconnect/cppagent/releases) for those who do not want to build the agent themselves. For *NIX users, you will need libxml2, cppunit, and cmake as well as build essentials. -Version 2.0.0.1 Rearchitecture of the agent with TLS, MQTT Adapter, Ruby Interpreter, Agent Adaptr, and much more +Version 2.0.0 Rearchitecture of the agent with TLS, MQTT Adapter, Ruby Interpreter, Agent Adaptr, and much more -Version 1.7.0.0 added kinematics, solid models, and new specifications types. +Version 1.7.0 added kinematics, solid models, and new specifications types. -Version 1.6.0.0 added coordinate systems, specifications, and tabular data. +Version 1.6.0 added coordinate systems, specifications, and tabular data. -Version 1.5.0.0 added Data Set capabilities and has been updated to use C++ 14. +Version 1.5.0 added Data Set capabilities and has been updated to use C++ 14. -Version 1.4.0.0 added time period filter constraint, compositions, initial values, and reset triggers. +Version 1.4.0 added time period filter constraint, compositions, initial values, and reset triggers. -Version 1.3.0.0 added the filter constraints, references, cutting tool archetypes, and formatting styles. +Version 1.3.0 added the filter constraints, references, cutting tool archetypes, and formatting styles. -Version 1.2.0.0 added the capability to support assets. +Version 1.2.0 added the capability to support assets. Version 1.1.0.8 add the ability to run the C++ Agent as a Windows service and support for a configuration file instead of command line @@ -89,18 +89,7 @@ later. Building ------- -Download cmake from [cmake](http://www.cmake.org/cmake/resources/software.html) - -Make sure to initialize submodules: - - git submodule init - git submodule update - -Configure cmake using the `CMakeLists.txt` file in the agent -directory. This will generate a project file for the target -platform. See CMake documentation for more information. - - +Platform specific instructions are at the end of the README. Configuration ------ @@ -139,7 +128,7 @@ Each set of files must be declared using a named file description, like schema o styles and the local `Path` and the `Location` the files will be mapped to in the HTTP server namespace. For example: - http://example.com:5000/schemas/MTConnectStreams_1.7.xsd will map to ../schemas/MTConnectStreams_1.7.xsd + http://example.com:5000/schemas/MTConnectStreams_2.0.xsd will map to ../schemas/MTConnectStreams_2.0.xsd All files will be mapped and the directory names do not need to be the same. These files can be either served directly or can be used to extend the schema or add XSLT stylesheets for formatting the XML in browsers. @@ -149,12 +138,12 @@ To specify the new schema for the documents, use the following declaration: StreamsNamespaces { e { - Urn = urn:example.com:ExampleStreams:1.7 - Location = /schemas/ExampleStreams_1.7.xsd + Urn = urn:example.com:ExampleStreams:2.0 + Location = /schemas/ExampleStreams_2.0.xsd } } -This will use the ExampleStreams_1.7.xsd schema in the document. The `e` is the alias that will be +This will use the ExampleStreams_2.0.xsd schema in the document. The `e` is the alias that will be used to reference the extended schema. The `Location` is the location of the xsd file relative in the agent namespace. The `Location` must be mapped in the `Files` section. @@ -439,20 +428,20 @@ namespace -- you cannot change it. StreamsNamespaces { m { - Location = /schemas/MTConnectStreams_1.7.xsd - Path = ./MTConnectStreams_1.7.xsd + Location = /schemas/MTConnectStreams_2.0.xsd + Path = ./MTConnectStreams_2.0.xsd } } DevicesNamespaces { m { - Location = /schemas/MTConnectDevices_1.7.xsd - Path = ./MTConnectDevices_1.7.xsd + Location = /schemas/MTConnectDevices_2.0.xsd + Path = ./MTConnectDevices_2.0.xsd } } The MTConnect agent will now serve the standard MTConnect schema files -from the local directory using the schema path /schemas/MTConnectDevices_1.7.xsd. +from the local directory using the schema path /schemas/MTConnectDevices_2.0.xsd. ### Example: 10 ### @@ -464,19 +453,19 @@ Agent serve them up locally. DevicesNamespaces { x { - Urn = urn:example.com:ExampleDevices:1.7 - Location = /schemas/ExampleDevices_1.7.xsd - Path = ./ExampleDevices_1.7.xsd + Urn = urn:example.com:ExampleDevices:2.0 + Location = /schemas/ExampleDevices_2.0.xsd + Path = ./ExampleDevices_2.0.xsd } Files { stream { - Location = /schemas/MTConnectStreams_1.7.xsd - Path = ./MTConnectStreams_1.7.xsd + Location = /schemas/MTConnectStreams_2.0.xsd + Path = ./MTConnectStreams_2.0.xsd } device { - Location = /schemas/MTConnectDevices_1.7.xsd - Path = ./MTConnectDevices_1.7.xsd + Location = /schemas/MTConnectDevices_2.0.xsd + Path = ./MTConnectDevices_2.0.xsd } } @@ -484,20 +473,20 @@ Or use the short form for all files: Files { schemas { - Location = /schemas/MTConnectStreams_1.7.xsd - Path = ./MTConnectStreams_1.7.xsd + Location = /schemas/MTConnectStreams_2.0.xsd + Path = ./MTConnectStreams_2.0.xsd } } If you have specified in your xs:include schemaLocation inside the -ExampleDevices_1.7.xsd file the location "/schemas/MTConnectStreams_1.7.xsd", +ExampleDevices_2.0.xsd file the location "/schemas/MTConnectStreams_2.0.xsd", this will allow it to be served properly. This can also be done using the Devices namespace: DevicesNamespaces { m { - Location = /schemas/MTConnectDevices_1.7.xsd - Path = ./MTConnectDevices_1.7.xsd + Location = /schemas/MTConnectDevices_2.0.xsd + Path = ./MTConnectDevices_2.0.xsd } } @@ -651,7 +640,7 @@ Configuration Parameters * `SchemaVersion` - Change the schema version to a different version number. - *Default*: 1.7 + *Default*: 2.0 * `ConversionRequired` - Global default for data item units conversion in the agent. Assumes the adapter has already done unit conversion. @@ -678,7 +667,7 @@ Configuration Parameters *Default*: 1 -* `SuppressIPAddress` - Suppress the Adapter IP Address and port when creating the Agent Device ids and names for 1.7. This applies to all adapters. +* `SuppressIPAddress` - Suppress the Adapter IP Address and port when creating the Agent Device ids and names. This applies to all adapters. *Default*: false @@ -821,7 +810,7 @@ The following parameters must be present to enable https requests. If there is n *Default*: 1 - * `SuppressIPAddress` - Suppress the Adapter IP Address and port when creating the Agent Device ids and names for 1.7. + * `SuppressIPAddress` - Suppress the Adapter IP Address and port when creating the Agent Device ids and names. *Default*: false @@ -879,7 +868,7 @@ logger_config configuration items *Default*: NEVER -Adapter Agent Protocol Version 1.7 +Adapter Agent Protocol Version 2.0 ======= The principle adapter data format is a simple plain text stream separated by the pipe character `|`. Every line except for commands starts with an optional timestamp in UTC. If the timestamp is not supplied the agent will supply a timestamp of its own taken at the arrival time of the data to the agent. The remainder of the line is a key followed by data – depending on the type of data item is being written to. @@ -1221,25 +1210,42 @@ An example in ruby is as follows: > r.body => "" -# Building the agent on Windows and Ubuntu +# Building the agent + +## Overview + +The agent build is dependent on the following utilities: + +* C++ Compiler compliant with C++ 17 +* git is optional but suggested to download source and update when changes occur +* cmake for build generator and testing +* python 3 and pip to support conan for dependency and package management +* ruby and rake for mruby to support building the embedded scripting engine [not required if -o with_ruby=False] ## Building on Windows The MTConnect Agent uses the conan package manager to install dependencies: - [Conan Package Manager Downloads](https://conan.io/downloads.html) + [python 3](https://www.python.org/downloads/) and [Conan Package Manager Downloads](https://conan.io/downloads.html) Download the Windows installer for your platform and run the installer. -You also need CMake [CMake](https://cmake.org/download/) and git [git](https://git-scm.com/download/win) +You also need [git](https://git-scm.com/download/win) and [ruby](https://rubyinstaller.org) if you want to embed mruby. + +CMake is installed as part of Visual Studio. If you are using Visual Studio for the build, use the bundled version. Otherwise download from CMake [CMake](https://cmake.org/download/). ### Setting up build +Install dependencies from the downloads above. Make sure python, ruby, and cmake are in your path. + + pip install --upgrade pip + pip install conan + Clone the agent to another directory: git clone https://github.com/mtconnect/cppagent.git -Make a build subdirectory of `cppagent_dev` +Make a build subdirectory of `cppagent` cd cppagent conan export conan\mqtt_cpp From db9924f5b6813c4deb079b2fe137a4e71336f1a6 Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Mon, 30 May 2022 13:59:30 -0700 Subject: [PATCH 5/8] Added section on *NIX resources --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 4dc931f20..5dda4fab6 100644 --- a/README.md +++ b/README.md @@ -1281,6 +1281,16 @@ The windows XP 140 XP toolchain needs to be installed under individual component cpack -G ZIP +## *NIX Builds + +The minimum memory (main + swap) when building with on CPU is 3GB. Less than that will likely cause the build to fail. + +If the build runs out of resources, there are two options, you can add swap or set the following environment variable: + + export CONAN_CPU_COUNT=1 + +to instruct conan to not parallelize the builds. Some of the modules that include boost beast require significant resources to build. + ## Building on Ubuntu on 20.04 LTS ### Setup the build From 8138423cda9c1f7c4c12249e45a38a79ee6d57e4 Mon Sep 17 00:00:00 2001 From: shaurabhsingh <33585615+shaurabhsingh@users.noreply.github.com> Date: Tue, 31 May 2022 21:30:24 +0530 Subject: [PATCH 6/8] Updated SchemaVersion --- simulator/agent.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simulator/agent.cfg b/simulator/agent.cfg index 464d75271..f1f09d7b6 100755 --- a/simulator/agent.cfg +++ b/simulator/agent.cfg @@ -2,7 +2,7 @@ Devices = ../simulator/VMC-3Axis.xml AllowPut = true ReconnectInterval = 1000 BufferSize = 17 -SchemaVersion = 1.7 +SchemaVersion = 2.0 MonitorConfigFiles = true Pretty = true # MinimumConfigReloadAge = 30 From 62d589146dc35de07075e78654e5258b6a453fa9 Mon Sep 17 00:00:00 2001 From: shaurabhsingh <33585615+shaurabhsingh@users.noreply.github.com> Date: Tue, 31 May 2022 21:44:49 +0530 Subject: [PATCH 7/8] Updated mtconnect logo src --- styles/styles.xsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/styles/styles.xsl b/styles/styles.xsl index 1b5b17e01..e34f9075b 100644 --- a/styles/styles.xsl +++ b/styles/styles.xsl @@ -39,7 +39,7 @@ - Brand + Brand