Skip to content

Commit

Permalink
fix: resulttype
Browse files Browse the repository at this point in the history
  • Loading branch information
wlkrm committed Feb 12, 2025
1 parent 4de8a81 commit 8ac4009
Show file tree
Hide file tree
Showing 22 changed files with 3,836 additions and 1,839 deletions.
864 changes: 373 additions & 491 deletions DashboardClient/DashboardClient.cpp

Large diffs are not rendered by default.

393 changes: 174 additions & 219 deletions DashboardClient/IDashboardDataClient.hpp

Large diffs are not rendered by default.

37 changes: 19 additions & 18 deletions DashboardOpcUaClient.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*
* Copyright 2021 (c) Christian von Arnim, ISW University of Stuttgart (for umati and VDW e.V.)
*/

Expand All @@ -18,21 +18,22 @@
#include <functional>

class DashboardOpcUaClient {
public:
DashboardOpcUaClient(std::shared_ptr<Umati::Util::Configuration> configuration, std::function<void()> issueReset);
public:
DashboardOpcUaClient(std::shared_ptr<Umati::Util::Configuration> configuration, std::function<void()> issueReset);

bool connect(std::atomic_bool &running);
void ReadTypes();
void StartMachineObserver();
void Iterate();
protected:
std::function<void()> m_issueReset;
std::shared_ptr<Umati::OpcUa::OpcUaInterface> m_opcUaWrapper;
std::shared_ptr<Umati::OpcUa::OpcUaClient> m_pClient;
std::shared_ptr<Umati::MqttPublisher_Paho::MqttPublisher_Paho> m_pPublisher;
std::shared_ptr<Umati::Dashboard::OpcUaTypeReader> m_pOpcUaTypeReader;
std::shared_ptr<Umati::MachineObserver::DashboardMachineObserver> m_pMachineObserver;
std::chrono::time_point<std::chrono::steady_clock> m_lastPublish;
std::chrono::time_point<std::chrono::steady_clock> m_lastConnectionVerify;
std::vector<ModelOpcUa::NodeId_t> m_machinesFilter;
bool connect(std::atomic_bool &running);
void ReadTypes();
void StartMachineObserver();
void Iterate();

protected:
std::function<void()> m_issueReset;
std::shared_ptr<Umati::OpcUa::OpcUaInterface> m_opcUaWrapper;
std::shared_ptr<Umati::OpcUa::OpcUaClient> m_pClient;
std::shared_ptr<Umati::MqttPublisher_Paho::MqttPublisher_Paho> m_pPublisher;
std::shared_ptr<Umati::Dashboard::OpcUaTypeReader> m_pOpcUaTypeReader;
std::shared_ptr<Umati::MachineObserver::DashboardMachineObserver> m_pMachineObserver;
std::chrono::time_point<std::chrono::steady_clock> m_lastPublish;
std::chrono::time_point<std::chrono::steady_clock> m_lastConnectionVerify;
std::vector<ModelOpcUa::NodeId_t> m_machinesFilter;
};
101 changes: 45 additions & 56 deletions Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,76 +36,65 @@
#include <chrono>
#include <iomanip>


std::atomic_bool running = {true};
std::atomic_bool reset = {false};

static void stopHandler(int sig)
{
LOG(INFO) << "Execution termindated by ctrl-c";
running = false;
static void stopHandler(int sig) {
LOG(INFO) << "Execution termindated by ctrl-c";
running = false;
}

static void issueReset()
{
LOG(INFO) << "Requesting reset";
reset = true;
static void issueReset() {
LOG(INFO) << "Requesting reset";
reset = true;
}

int main(int argc, char *argv[])
{
Umati::Util::ConfigureLogger("DashboardOpcUaClient");
int main(int argc, char *argv[]) {
Umati::Util::ConfigureLogger("DashboardOpcUaClient");

signal(SIGINT, stopHandler);
signal(SIGTERM, stopHandler);
signal(SIGINT, stopHandler);
signal(SIGTERM, stopHandler);

LOG(INFO) << "Start Dashboard OPC UA Client";
LOG(INFO) << "OPC UA Dashboard Client Version: " << gitClientVersion <<std::endl;
LOG(INFO) << "Start Dashboard OPC UA Client";
LOG(INFO) << "OPC UA Dashboard Client Version: " << gitClientVersion << std::endl;

std::string configFilename("configuration.json");

std::string configFilename("configuration.json");
if (argc >= 2) {
configFilename = argv[1];
}

if (argc >= 2)
{
configFilename = argv[1];
}
std::shared_ptr<Umati::Util::Configuration> config;
try {
config = std::make_shared<Umati::Util::ConfigurationJsonFile>(configFilename);
Umati::MachineObserver::Topics::Prefix = config->getMqtt().Prefix;
Umati::MachineObserver::Topics::ClientId = config->getMqtt().ClientId;
} catch (Umati::Util::Exception::ConfigurationException &ex) {
LOG(ERROR) << "Configuration could not be loaded: " << ex.what();
std::cout << "Usage <>.exe [ConfigurationFileName]";
return 1;
}

std::shared_ptr<Umati::Util::Configuration> config;
try
{
config = std::make_shared<Umati::Util::ConfigurationJsonFile>(configFilename);
Umati::MachineObserver::Topics::Prefix = config->getMqtt().Prefix;
Umati::MachineObserver::Topics::ClientId = config->getMqtt().ClientId;
}
catch (Umati::Util::Exception::ConfigurationException &ex)
{
LOG(ERROR) << "Configuration could not be loaded: " << ex.what();
std::cout << "Usage <>.exe [ConfigurationFileName]";
return 1;
}
std::size_t resetCounter = 0;
while (running) {
if (reset) {
++resetCounter;
reset = false;
}
DashboardOpcUaClient dashboardClient(config, issueReset);

std::size_t resetCounter = 0;
while(running) {
if(reset) {
++resetCounter;
reset = false;
}
DashboardOpcUaClient dashboardClient(config, issueReset);
if (!dashboardClient.connect(running)) {
LOG(INFO) << "Connection not established, exiting.";
return -1;
}

if (!dashboardClient.connect(running))
{
LOG(INFO) << "Connection not established, exiting.";
return -1;
}
dashboardClient.ReadTypes();
dashboardClient.StartMachineObserver();
while (running && !reset) {
dashboardClient.Iterate();
}
}

dashboardClient.ReadTypes();
dashboardClient.StartMachineObserver();
while (running && !reset)
{
dashboardClient.Iterate();
}
}

LOG(INFO) << "End Dashboard OPC UA Client";
return 0;
LOG(INFO) << "End Dashboard OPC UA Client";
return 0;
}
Loading

0 comments on commit 8ac4009

Please sign in to comment.