Die Migration der Bereiche "Docker Registry" und "Artifiacts" ist fast abgeschlossen. Die letzten Daten werden im Laufe des heutigen Abend (05.08.2021) noch vollständig hochgeladen. Das Anlegen neuer Images und Artifacts funktioniert bereits wieder.

Commit bcd6b468 authored by Unknown's avatar Unknown
Browse files

Added types N,Z,B

parent af3d9cb8
......@@ -31,10 +31,16 @@ ENDIF()
# Adding library as a target
add_library(MqttAdapter_tests_a_compA
Callback.cpp
CallbackQ.cpp
CallbackN.cpp
CallbackZ.cpp
CallbackB.cpp
MqttAdapter_tests_a_compA.cpp
tests_a_compA.cpp
Callback.hpp
CallbackQ.hpp
CallbackN.hpp
CallbackZ.hpp
CallbackB.hpp
MqttAdapter_tests_a_compA.h
tests_a_compA.h
)
......
/* (c) https://github.com/MontiCore/monticore */
#include "CallbackB.hpp"
CallbackB::CallbackB(mqtt::client& cli, bool* port) : mqtt::callback(), cli_(cli)
{
port_ = port;
}
// Callback for when connected to broker
void CallbackB::connected(const std::string& cause)
{
cout << "Connected" <<endl;
}
// Callback for when the connection is lost.
void CallbackB::connection_lost(const std::string& cause)
{
cout << "\nConnection lost";
if (!cause.empty())
cout << ": " << cause << endl;
}
// Callback for when message is received
void CallbackB::message_arrived(mqtt::const_message_ptr msg)
{
cout << "Message received "<< msg->get_topic() << ": " << msg->get_payload_str() << endl;
bool value = ((std::stod (msg->get_payload_str())) > 1.0e-10);
*port_ = value;
}
/* (c) https://github.com/MontiCore/monticore */
#ifndef Callback_hpp
#define Callback_hpp
#ifndef CallbackB_hpp
#define CallbackB_hpp
#include "tests_a_compA.h"
#include "mqtt/client.h"
using namespace std;
class Callback : public virtual mqtt::callback
class CallbackB : public virtual mqtt::callback
{
mqtt::client& cli_;
public:
Callback(mqtt::client& cli, tests_a_compA* comp);
CallbackB(mqtt::client& cli, bool* port);
void connected(const std::string& cause);
void connection_lost(const std::string& cause);
void message_arrived(mqtt::const_message_ptr msg);
private:
tests_a_compA* comp_;
bool* port_;
};
#endif /* Callback_hpp */
#endif /* CallbackB_hpp */
/* (c) https://github.com/MontiCore/monticore */
#include "CallbackN.hpp"
CallbackN::CallbackN(mqtt::client& cli, int* port) : mqtt::callback(), cli_(cli)
{
port_ = port;
}
// Callback for when connected to broker
void CallbackN::connected(const std::string& cause)
{
cout << "Connected" <<endl;
}
// Callback for when the connection is lost.
void CallbackN::connection_lost(const std::string& cause)
{
cout << "\nConnection lost";
if (!cause.empty())
cout << ": " << cause << endl;
}
// Callback for when message is received
void CallbackN::message_arrived(mqtt::const_message_ptr msg)
{
cout << "Message received "<< msg->get_topic() << ": " << msg->get_payload_str() << endl;
int value = std::stoi (msg->get_payload_str());
*port_ = value;
}
/* (c) https://github.com/MontiCore/monticore */
#ifndef CallbackN_hpp
#define CallbackN_hpp
#include "tests_a_compA.h"
#include "mqtt/client.h"
using namespace std;
class CallbackN : public virtual mqtt::callback
{
mqtt::client& cli_;
public:
CallbackN(mqtt::client& cli, int* port);
void connected(const std::string& cause);
void connection_lost(const std::string& cause);
void message_arrived(mqtt::const_message_ptr msg);
private:
int* port_;
};
#endif /* CallbackN_hpp */
/* (c) https://github.com/MontiCore/monticore */
#include "Callback.hpp"
#include "CallbackQ.hpp"
Callback::Callback(mqtt::client& cli, tests_a_compA* comp) : mqtt::callback(), cli_(cli)
CallbackQ::CallbackQ(mqtt::client& cli, double* port) : mqtt::callback(), cli_(cli)
{
comp_ = comp;
port_ = port;
}
// Callback for when connected to broker
void Callback::connected(const std::string& cause)
void CallbackQ::connected(const std::string& cause)
{
cout << "Connected" <<endl;
cout << "Connected" <<endl;
}
// Callback for when the connection is lost.
void Callback::connection_lost(const std::string& cause)
void CallbackQ::connection_lost(const std::string& cause)
{
cout << "\nConnection lost";
if (!cause.empty())
......@@ -21,13 +21,10 @@ void Callback::connection_lost(const std::string& cause)
}
// Callback for when message is received
void Callback::message_arrived(mqtt::const_message_ptr msg)
void CallbackQ::message_arrived(mqtt::const_message_ptr msg)
{
cout << "Message received "<< msg->get_topic() << ": " << msg->get_payload_str() << endl;
std::string::size_type sz;
double value = std::stod (msg->get_payload_str(),&sz);
comp_->mqttIn = value;
*port_ = value;
}
/* (c) https://github.com/MontiCore/monticore */
#ifndef CallbackQ_hpp
#define CallbackQ_hpp
#include "tests_a_compA.h"
#include "mqtt/client.h"
using namespace std;
class CallbackQ : public virtual mqtt::callback
{
mqtt::client& cli_;
public:
CallbackQ(mqtt::client& cli, double* port);
void connected(const std::string& cause);
void connection_lost(const std::string& cause);
void message_arrived(mqtt::const_message_ptr msg);
private:
double* port_;
};
#endif /* CallbackQ_hpp */
/* (c) https://github.com/MontiCore/monticore */
#include "CallbackZ.hpp"
CallbackZ::CallbackZ(mqtt::client& cli, int* port) : mqtt::callback(), cli_(cli)
{
port_ = port;
}
// Callback for when connected to broker
void CallbackZ::connected(const std::string& cause)
{
cout << "Connected" <<endl;
}
// Callback for when the connection is lost.
void CallbackZ::connection_lost(const std::string& cause)
{
cout << "\nConnection lost";
if (!cause.empty())
cout << ": " << cause << endl;
}
// Callback for when message is received
void CallbackZ::message_arrived(mqtt::const_message_ptr msg)
{
cout << "Message received "<< msg->get_topic() << ": " << msg->get_payload_str() << endl;
int value = std::stoi (msg->get_payload_str());
*port_ = value;
}
/* (c) https://github.com/MontiCore/monticore */
#ifndef CallbackZ_hpp
#define CallbackZ_hpp
#include "tests_a_compA.h"
#include "mqtt/client.h"
using namespace std;
class CallbackZ : public virtual mqtt::callback
{
mqtt::client& cli_;
public:
CallbackZ(mqtt::client& cli, int* port);
void connected(const std::string& cause);
void connection_lost(const std::string& cause);
void message_arrived(mqtt::const_message_ptr msg);
private:
int* port_;
};
#endif /* CallbackZ_hpp */
......@@ -5,53 +5,117 @@ using namespace std;
MqttAdapter_tests_a_compA::MqttAdapter_tests_a_compA()
{
}
void MqttAdapter_tests_a_compA::init(tests_a_compA *comp)
{
// Initialize component
this->component = comp;
// Initialize connect options
mqtt::connect_options connOpts;
connOpts.set_keep_alive_interval(20);
connOpts.set_clean_session(true);
// Intitialize callback, subscriber and publisher
_clockSubscriber = new mqtt::client(SERVER_ADDRESS, SUB_ID);
_callback = new Callback(*_clockSubscriber, comp);
_echoPublisher = new mqtt::client(SERVER_ADDRESS, PUB_ID);
_clockSubscriberQ = new mqtt::client(SERVER_ADDRESS, SUB_IDQ);
_callbackQ = new CallbackQ(*_clockSubscriberQ, &(comp->mqttInQ));
_echoPublisherQ = new mqtt::client(SERVER_ADDRESS, PUB_IDQ);
_clockSubscriberN = new mqtt::client(SERVER_ADDRESS, SUB_IDN);
_callbackN = new CallbackN(*_clockSubscriberN, &(comp->mqttInN));
_echoPublisherN = new mqtt::client(SERVER_ADDRESS, PUB_IDN);
_clockSubscriberZ = new mqtt::client(SERVER_ADDRESS, SUB_IDZ);
_callbackZ = new CallbackZ(*_clockSubscriberZ, &(comp->mqttInZ));
_echoPublisherZ = new mqtt::client(SERVER_ADDRESS, PUB_IDZ);
_clockSubscriberB = new mqtt::client(SERVER_ADDRESS, SUB_IDB);
_callbackB = new CallbackB(*_clockSubscriberB, &(comp->mqttInB));
_echoPublisherB = new mqtt::client(SERVER_ADDRESS, PUB_IDB);
// Connect subscriber, publisher and subscribe to the topic
try {
_clockSubscriber->set_callback(*_callback);
_clockSubscriber->connect(connOpts);
_echoPublisher->connect(connOpts);
_clockSubscriber->subscribe(TOPIC, 1);
_clockSubscriberQ->set_callback(*_callbackQ);
_clockSubscriberQ->connect(connOpts);
_echoPublisherQ->connect(connOpts);
_clockSubscriberQ->subscribe(TOPICQ, 1);
_clockSubscriberN->set_callback(*_callbackN);
_clockSubscriberN->connect(connOpts);
_echoPublisherN->connect(connOpts);
_clockSubscriberN->subscribe(TOPICN, 1);
_clockSubscriberZ->set_callback(*_callbackZ);
_clockSubscriberZ->connect(connOpts);
_echoPublisherZ->connect(connOpts);
_clockSubscriberZ->subscribe(TOPICZ, 1);
_clockSubscriberB->set_callback(*_callbackB);
_clockSubscriberB->connect(connOpts);
_echoPublisherB->connect(connOpts);
_clockSubscriberB->subscribe(TOPICB, 1);
} catch (const mqtt::exception& exc) {
cerr << exc.what() << endl;
}
}
void MqttAdapter_tests_a_compA::publish_echoPublisher()
void MqttAdapter_tests_a_compA::publish_echoPublisherQ()
{
string value = to_string(component->mqttOut);
auto pubmsg = mqtt::make_message(TOPIC, value);
string value = to_string(component->mqttOutQ);
auto pubmsg = mqtt::make_message(TOPICQ, value);
try {
_echoPublisher->publish(pubmsg);
_echoPublisherQ->publish(pubmsg);
} catch (const mqtt::exception& exc) {
cerr << exc.to_string() << endl;
}
}
void MqttAdapter_tests_a_compA::tick()
void MqttAdapter_tests_a_compA::publish_echoPublisherN()
{
string value = to_string(component->mqttOutN);
auto pubmsg = mqtt::make_message(TOPICN, value);
try {
_echoPublisherN->publish(pubmsg);
} catch (const mqtt::exception& exc) {
cerr << exc.to_string() << endl;
}
}
void MqttAdapter_tests_a_compA::publish_echoPublisherZ()
{
string value = to_string(component->mqttOutZ);
auto pubmsg = mqtt::make_message(TOPICZ, value);
try {
_echoPublisherZ->publish(pubmsg);
} catch (const mqtt::exception& exc) {
cerr << exc.to_string() << endl;
}
}
void MqttAdapter_tests_a_compA::publish_echoPublisherB()
{
publish_echoPublisher();
string value = to_string(component->mqttOutB ? 1.0 : 0.0);
auto pubmsg = mqtt::make_message(TOPICB, value);
try {
_echoPublisherB->publish(pubmsg);
} catch (const mqtt::exception& exc) {
cerr << exc.to_string() << endl;
}
}
void MqttAdapter_tests_a_compA::tick()
{
publish_echoPublisherQ();
publish_echoPublisherN();
publish_echoPublisherZ();
publish_echoPublisherB();
}
/* (c) https://github.com/MontiCore/monticore */
#pragma once
#include "tests_a_compA.h"
#include "Callback.hpp"
#include "CallbackQ.hpp"
#include "CallbackN.hpp"
#include "CallbackZ.hpp"
#include "CallbackB.hpp"
#include "mqtt/client.h"
#include <iostream>
using namespace std;
class MqttAdapter_tests_a_compA {
public:
MqttAdapter_tests_a_compA();
void init(tests_a_compA* comp);
void publish_echoPublisher();
void publish_echoPublisherQ();
void publish_echoPublisherN();
void publish_echoPublisherZ();
void publish_echoPublisherB();
void tick();
private:
const string SERVER_ADDRESS = "tcp://localhost:1883";
const string PUB_ID = "publisher_cpp";
const string SUB_ID = "subscriber_cpp";
const string TOPIC = "/clock";
const string PUB_IDQ = "publisher_cppQ";
const string SUB_IDQ = "subscriber_cppQ";
const string PUB_IDN = "publisher_cppN";
const string SUB_IDN = "subscriber_cppN";
const string PUB_IDZ = "publisher_cppZ";
const string SUB_IDZ = "subscriber_cppZ";
const string PUB_IDB = "publisher_cppB";
const string SUB_IDB = "subscriber_cppB";
const string TOPICQ = "/clock";
const string TOPICN = "/clockN";
const string TOPICZ = "/clockZ";
const string TOPICB = "/clockB";
tests_a_compA* component = nullptr;
Callback* _callback = nullptr;
mqtt::client* _clockSubscriber = nullptr;
mqtt::client* _echoPublisher = nullptr;
CallbackQ* _callbackQ = nullptr;
CallbackN* _callbackN = nullptr;
CallbackZ* _callbackZ = nullptr;
CallbackB* _callbackB = nullptr;
mqtt::client* _clockSubscriberQ = nullptr;
mqtt::client* _echoPublisherQ = nullptr;
mqtt::client* _clockSubscriberN = nullptr;
mqtt::client* _echoPublisherN = nullptr;
mqtt::client* _clockSubscriberZ = nullptr;
mqtt::client* _echoPublisherZ = nullptr;
mqtt::client* _clockSubscriberB = nullptr;
mqtt::client* _echoPublisherB = nullptr;
};
......@@ -4,5 +4,8 @@
tests_a_compA::tests_a_compA(double value)
{
mqttOut = value;
mqttOutQ = value;
mqttOutN = (int) value;
mqttOutZ = (int) value;
mqttOutB = (value >= 1);
}
......@@ -9,11 +9,17 @@
using namespace std;
class tests_a_compA {
public:
tests_a_compA(double value);
double mqttIn = 0;
double mqttOut = 0;
double mqttInQ = 0;
double mqttOutQ = 0;
int mqttInN = 0;
int mqttOutN = 0;
int mqttInZ = 0;
int mqttOutZ = 0;
bool mqttInB = false;
bool mqttOutB = false;
};
#endif /* tests_a_compA_h */
......@@ -14,24 +14,24 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class GeneratorMqtt
public class GeneratorMqtt
{
private String generationTargetPath;
public void setGenerationTargetPath(String generationTargetPath) {
this.generationTargetPath = generationTargetPath.endsWith("/") ? generationTargetPath : generationTargetPath + "/";
}
public List<File> generateMqttAdapter(EMAComponentInstanceSymbol component)
public List<File> generateMqttAdapter(EMAComponentInstanceSymbol component)
{
List<File> files = new ArrayList<>();
List<String> contents = new ArrayList<String>();
List<FileWriter> frs = new ArrayList<FileWriter>();
// Create and fill model
MqttAdapterModel model = new MqttAdapterModel(component.getFullName());
model.addPorts(component.getPortInstanceList());
component.getPortArrays().forEach(port -> {
......@@ -43,10 +43,22 @@ public class GeneratorMqtt
files.add(new File(generationTargetPath+"MqttAdapter_"+model.getEscapedCompName()+".h"));
contents.add(MqttTemplates.generateMqttAdapterCPP(model));
files.add(new File(generationTargetPath+"MqttAdapter_"+model.getEscapedCompName()+".cpp"));
contents.add(MqttTemplates.generateMqttCallbackH(model));
files.add(new File(generationTargetPath+"Callback.hpp"));
contents.add(MqttTemplates.generateMqttCallbackCPP(model));
files.add(new File(generationTargetPath+"Callback.cpp"));
contents.add(MqttTemplates.generateMqttCallbackQH(model));
files.add(new File(generationTargetPath+"CallbackQ.hpp"));
contents.add(MqttTemplates.generateMqttCallbackQCPP(model));
files.add(new File(generationTargetPath+"CallbackQ.cpp"));
contents.add(MqttTemplates.generateMqttCallbackNH(model));
files.add(new File(generationTargetPath+"CallbackN.hpp"));
contents.add(MqttTemplates.generateMqttCallbackNCPP(model));
files.add(new File(generationTargetPath+"CallbackN.cpp"));
contents.add(MqttTemplates.generateMqttCallbackZH(model));
files.add(new File(generationTargetPath+"CallbackZ.hpp"));
contents.add(MqttTemplates.generateMqttCallbackZCPP(model));
files.add(new File(generationTargetPath+"CallbackZ.cpp"));
contents.add(MqttTemplates.generateMqttCallbackBH(model));
files.add(new File(generationTargetPath+"CallbackB.hpp"));
contents.add(MqttTemplates.generateMqttCallbackBCPP(model));
files.add(new File(generationTargetPath+"CallbackB.cpp"));
//If file directory does not exist, create it so files can be created
File directory = new File(generationTargetPath);
......@@ -72,67 +84,67 @@ public class GeneratorMqtt
e.printStackTrace();
}
}
files.add(generateCMake(component));
files.add(generateFindMqtt(component));
return files;