Skip to content

Commit

Permalink
Merged in latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wsobel committed Apr 15, 2021
2 parents 9ef6a9a + 3f84a55 commit 3bb1201
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(AGENT_VERSION_MAJOR 1)
set(AGENT_VERSION_MINOR 7)
set(AGENT_VERSION_PATCH 0)
set(AGENT_VERSION_BUILD 2)
#set(AGENT_VERSION_RC "RC8")
#set(AGENT_VERSION_RC "RC9")

# This minimum version is to support Visual Studio 2017 and C++ feature checking and FetchContent
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
Expand Down Expand Up @@ -103,3 +103,4 @@ set(CPACK_PACKAGE_VENDOR "MTConnect.org")

include(CPack)


6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ Configuration Parameters
* `ShdrVersion` - Specifies the SHDR protocol version used by the adapter. When greater than one (1), allows multiple complex observations, like `Condition` and `Message` on the same line. If it equials one (1), then any observation requiring more than a key/value pair need to be on separate lines. This is the default for all adapters.

*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.
*Default*: false


### Adapter configuration items ###
Expand Down Expand Up @@ -721,6 +724,9 @@ Configuration Parameters

*Default*: 1

* `SuppressIPAddress` - Suppress the Adapter IP Address and port when creating the Agent Device ids and names for 1.7.
*Default*: false


logger_config configuration items
-----
Expand Down
4 changes: 3 additions & 1 deletion src/adapter/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "device_model/device.hpp"

#include <dlib/logger.h>
#include <dlib/md5.h>

#include <algorithm>
#include <chrono>
Expand Down Expand Up @@ -57,7 +58,8 @@ namespace mtconnect

stringstream identity;
identity << '_' << server << '_' << port;
m_identity = identity.str();
m_identity = string("_") + dlib::md5(identity.str()).substr(0, 10);

m_options[configuration::AdapterIdentity] = m_identity;
m_handler = m_pipeline->makeHandler();
if (m_pipeline->hasContract())
Expand Down
2 changes: 2 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ namespace mtconnect
options[configuration::UpcaseDataItemValue] = upcaseValue;
options[configuration::FilterDuplicates] = filterDuplicates;
assign_value<int>(configuration::ShdrVersion, reader, options, 1);
assign_bool_value(configuration::SuppressIPAddress, reader, options, false);

m_agent->initialize(m_pipelineContext, options);

Expand Down Expand Up @@ -758,6 +759,7 @@ namespace mtconnect
assign_value<Seconds>(configuration::ReconnectInterval, adapter, adapterOptions);
assign_value<Seconds>(configuration::LegacyTimeout, adapter, adapterOptions);
assign_bool_value(configuration::PreserveUUID, adapter, adapterOptions);
assign_bool_value(configuration::SuppressIPAddress, adapter, adapterOptions);
device->m_preserveUuid = get<bool>(adapterOptions[configuration::PreserveUUID]);

const string host = get_with_default(adapter, configuration::Host, (string) "localhost");
Expand Down
1 change: 1 addition & 0 deletions src/config_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ namespace mtconnect
DECLARE_CONFIGURATION(LegacyTimeout);
DECLARE_CONFIGURATION(AdditionalDevices);
DECLARE_CONFIGURATION(AdapterIdentity);
DECLARE_CONFIGURATION(SuppressIPAddress);
}
}
23 changes: 19 additions & 4 deletions src/device_model/agent_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
#include "agent_device.hpp"

#include "adapter/adapter.hpp"
#include "utilities.hpp"
#include "config_options.hpp"

#include <dlib/logger.h>
#include <dlib/md5.h>

using namespace std;

Expand All @@ -42,12 +45,23 @@ namespace mtconnect

void AgentDevice::addAdapter(const adapter::Adapter *adapter)
{
bool suppress = GetOption<bool>(adapter->getOptions(), configuration::SuppressIPAddress).value_or(false);
auto id = adapter->getIdentity();

stringstream name;
name << adapter->getServer() << ':' << adapter->getPort();

auto comp = new Component("Adapter", {{"id", id}, {"name", name.str()}});
std::map<string, string> attrs{{"id", id}};
if (!suppress)
{
stringstream name;
name << adapter->getServer() << ':' << adapter->getPort();
attrs["name"] = name.str();
}
else
{
auto device = GetOption<string>(adapter->getOptions(), configuration::Device);
if (device)
attrs["name"] = *device;
}
auto comp = new Component("Adapter", attrs);
m_adapters->addChild(comp);

{
Expand All @@ -58,6 +72,7 @@ namespace mtconnect
comp->addDataItem(di);
}

if (!suppress)
{
auto di = new DataItem(
{{"type", "ADAPTER_URI"}, {"id", id + "_adapter_uri"}, {"category", "EVENT"}});
Expand Down
28 changes: 23 additions & 5 deletions test/agent_device_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ class AgentDeviceTest : public testing::Test
m_agentTestHelper.reset();
}

void addAdapter()
void addAdapter(bool suppress = false)
{
m_agentTestHelper->addAdapter({}, "127.0.0.1", m_port, "LinuxCNC");
ConfigOptions options{{configuration::SuppressIPAddress, suppress}};
m_agentTestHelper->addAdapter(options, "127.0.0.1", m_port, "LinuxCNC");
m_agentTestHelper->m_adapter->setReconnectInterval(1s);
}

Expand Down Expand Up @@ -128,24 +129,41 @@ TEST_F(AgentDeviceTest, DeviceAddedItemsInBuffer)
#define ADAPTER_PATH ADAPTERS_PATH "/m:Components/m:Adapter"
#define ADAPTER_DATA_ITEMS_PATH ADAPTER_PATH "/m:DataItems"

#define ID_PREFIX "_83a0a5df80"

TEST_F(AgentDeviceTest, AdapterAddedProbeTest)
{
addAdapter();
{
PARSE_XML_RESPONSE("/Agent/probe");
ASSERT_XML_PATH_COUNT(doc, ADAPTERS_PATH "/*", 1);
ASSERT_XML_PATH_EQUAL(doc, ADAPTER_PATH "@id", "_127.0.0.1_21788");
ASSERT_XML_PATH_EQUAL(doc, ADAPTER_PATH "@id", ID_PREFIX);
ASSERT_XML_PATH_EQUAL(doc, ADAPTER_PATH "@name", "127.0.0.1:21788");

ASSERT_XML_PATH_EQUAL(doc, ADAPTER_DATA_ITEMS_PATH
"/m:DataItem[@id='_127.0.0.1_21788_adapter_uri']@type",
"/m:DataItem[@id='" ID_PREFIX "_adapter_uri']@type",
"ADAPTER_URI");
ASSERT_XML_PATH_EQUAL(doc, ADAPTER_DATA_ITEMS_PATH
"/m:DataItem[@id='_127.0.0.1_21788_adapter_uri']/m:Constraints/m:Value",
"/m:DataItem[@id='" ID_PREFIX "_adapter_uri']/m:Constraints/m:Value",
m_agentTestHelper->m_adapter->getUrl().c_str());
}
}

TEST_F(AgentDeviceTest, adapter_component_with_ip_address_suppressed)
{
addAdapter(true);
{
PARSE_XML_RESPONSE("/Agent/probe");
m_agentTestHelper->printResponse();
ASSERT_XML_PATH_COUNT(doc, ADAPTERS_PATH "/*", 1);
ASSERT_XML_PATH_EQUAL(doc, ADAPTER_PATH "@id", ID_PREFIX);
ASSERT_XML_PATH_EQUAL(doc, ADAPTER_PATH "@name", "LinuxCNC");

ASSERT_XML_PATH_COUNT(doc, ADAPTER_DATA_ITEMS_PATH
"/m:DataItem[@id='" ID_PREFIX "_adapter_uri']", 0);
}
}

#define AGENT_DEVICE_STREAM "//m:DeviceStream[@name='Agent']"
#define AGENT_DEVICE_DEVICE_STREAM AGENT_DEVICE_STREAM "/m:ComponentStream[@component='Agent']"
#define AGENT_DEVICE_ADAPTER_STREAM AGENT_DEVICE_STREAM "/m:ComponentStream[@component='Adapter']"
Expand Down

0 comments on commit 3bb1201

Please sign in to comment.