Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed . to _ in agent device topic for ignition #400

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/mtconnect/device_model/agent_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ namespace mtconnect {
}
return factory;
}

entity::FactoryPtr AgentDevice::getRoot()
{
static auto factory = make_shared<Factory>(
Requirements {{"Agent", ValueType::ENTITY, getFactory(), 1, Requirement::Infinite}});

return factory;
}


AgentDevice::AgentDevice(const std::string &name, entity::Properties &props)
: Device(name, props)
Expand Down
1 change: 1 addition & 0 deletions src/mtconnect/device_model/agent_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace mtconnect {
AgentDevice(const std::string &name, entity::Properties &props);
~AgentDevice() override = default;
static entity::FactoryPtr getFactory();
static entity::FactoryPtr getRoot();

/// @brief initialize the agent device and add the device changed and removed data items
void initialize() override
Expand Down
2 changes: 1 addition & 1 deletion src/mtconnect/sink/mqtt_sink/mqtt2_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace mtconnect {
uuid = *(device->getUuid());
if (std::dynamic_pointer_cast<device_model::AgentDevice>(device))
{
uuid.insert(0, "Agent.");
uuid.insert(0, "Agent_");
}
}

Expand Down
35 changes: 35 additions & 0 deletions test_package/mqtt_sink_2_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,38 @@ TEST_F(MqttSink2Test, mqtt_sink_should_publish_Probe_no_device_in_format)

ASSERT_TRUE(waitFor(1s, [&gotDevice]() { return gotDevice; }));
}

TEST_F(MqttSink2Test, mqtt_sink_should_publish_agent_device)
{
ConfigOptions options;
createServer(options);
startServer();
ASSERT_NE(0, m_port);

entity::JsonParser parser;

DevicePtr ad;
string agent_topic;

auto handler = make_unique<ClientHandler>();
bool gotDevice = false;
handler->m_receive = [&gotDevice, &parser, &agent_topic, &ad ](std::shared_ptr<MqttClient> client,
const std::string &topic, const std::string &payload) {
EXPECT_EQ(agent_topic, topic);
gotDevice = true;
};

createClient(options, std::move(handler));
ASSERT_TRUE(startClient());
createAgent();

ad = m_agentTestHelper->m_agent->getAgentDevice();
agent_topic = "MTConnect/Probe/Agent_"s + *ad->getUuid();
m_client->subscribe(agent_topic);

auto service = m_agentTestHelper->getMqtt2Service();

ASSERT_TRUE(waitFor(60s, [&service]() { return service->isConnected(); }));

ASSERT_TRUE(waitFor(1s, [&gotDevice]() { return gotDevice; }));
}
Loading