Commit 26ca50cf authored by Alexander David Hellwig's avatar Alexander David Hellwig

Merge branch '24-feedback' into 'master'

Added Suggestions

Closes #24

See merge request !13
parents 0b4885d7 f1f3bfd2
Pipeline #188551 passed with stage
in 3 minutes and 41 seconds
......@@ -47,6 +47,10 @@ Install mosquitto and mosquitto-clients
`apt install mosquitto-clients`
Start the Mosquitto Brocker
`/etc/init.d/mosquitto start`
### Installing MQTT broker (locally on Windows)
[Download](https://mosquitto.org/files/binary/win64/mosquitto-1.6.2-install-windows-x64.exe) and install Mosquitto
......@@ -62,7 +66,7 @@ Open terminal and run
`apt install build-essential gcc make cmake git`
#### Installing PahoMQTT C library
run
run
```bash
git clone https://github.com/eclipse/paho.mqtt.c
cd paho.mqtt.c
......@@ -77,6 +81,7 @@ cd paho.mqtt.cpp
cmake -Bbuild -H. -DPAHO_WITH_SSL=OFF
sudo cmake --build build/ --target install
```
[Documentation](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/generators/emam2mqtt/-/archive/master/emam2mqtt-master.zip) of the PahoMqtt C++ library
#### Set environment variables for MQTT (optional)
additionaly, you can set the environment variables for MQTT libs and includes directory by modifying the environment file on your system
```bash
......@@ -102,6 +107,12 @@ run the demo afterwards with `./mqtt_demo`
additionaly, you can also use `mosquitto_pub` and `mosquitto_sub` commands from mosquitto broker to subscribe/publish messages
for example:
subscribe to topic **/hello** with `mosquitto_sub -t /hello` and publish a message to this topic with
subscribe to topic **/hello** with `mosquitto_sub -t /hello` and publish a message to this topic with
`mosquitto_pub -t /hello -m "hi, how are you?"`
## Tagging for Mqtt
Mqtt only needs an Topic to publish or subscribe to `{ topic = {topic} }`
For example `{topic = /echo}` for topic "/echo"
[Here](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/languages/EmbeddedMontiArc/tree/master/src/test/resources/middleware/mqtt) an Example for a Mqtt Tagging File
......@@ -7,7 +7,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-mqtt-generator</artifactId>
<version>1.4-SNAPSHOT</version>
<version>1.5-SNAPSHOT</version>
<name>emam2mqtt</name>
......
......@@ -6,6 +6,7 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instance
import de.monticore.lang.embeddedmontiarc.tagging.middleware.mqtt.MqttConnectionSymbol;
import de.monticore.lang.monticar.generator.mqtt.template.MqttAdapterModel;
import de.monticore.lang.monticar.generator.mqtt.template.MqttTemplates;
import de.monticore.lang.monticar.generator.mqtt.helper.FilesHelper;
import java.io.File;
import java.io.FileWriter;
......@@ -23,73 +24,40 @@ public class GeneratorMqtt
this.generationTargetPath = generationTargetPath.endsWith("/") ? generationTargetPath : generationTargetPath + "/";
}
public List<File> generateMqttAdapter(EMAComponentInstanceSymbol component)
{
List<File> files = new ArrayList<>();
List<String> contents = new ArrayList<String>();
List<FileWriter> frs = new ArrayList<FileWriter>();
public List<File> generateMqttAdapter(EMAComponentInstanceSymbol component) {
List<FilesHelper> generateList = new ArrayList<>();
List<File> res = new ArrayList<>();
// Create and fill model
MqttAdapterModel model = new MqttAdapterModel(component.getFullName());
model.addPorts(component.getPortInstanceList());
component.getPortArrays().forEach(port -> {
port.setMiddlewareSymbol(new MqttConnectionSymbol(port.getFullName()));
});
//Generate files and write to project
contents.add(MqttTemplates.generateMqttAdapterH(model));
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.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"));
generateList.add(new FilesHelper(new File(generationTargetPath+"MqttAdapter_"+model.getEscapedCompName()+".h"), MqttTemplates.generateMqttAdapterH(model)));
generateList.add(new FilesHelper(new File(generationTargetPath+"MqttAdapter_"+model.getEscapedCompName()+".cpp"), MqttTemplates.generateMqttAdapterCPP(model)));
generateList.add(new FilesHelper(new File(generationTargetPath+"CallbackQ.hpp"), MqttTemplates.generateMqttCallbackQH(model)));
generateList.add(new FilesHelper(new File(generationTargetPath+"CallbackQ.cpp"), MqttTemplates.generateMqttCallbackQCPP(model)));
generateList.add(new FilesHelper(new File(generationTargetPath+"CallbackN.hpp"), MqttTemplates.generateMqttCallbackNH(model)));
generateList.add(new FilesHelper(new File(generationTargetPath+"CallbackN.cpp"), MqttTemplates.generateMqttCallbackNCPP(model)));
generateList.add(new FilesHelper(new File(generationTargetPath+"CallbackZ.hpp"), MqttTemplates.generateMqttCallbackZH(model)));
generateList.add(new FilesHelper(new File(generationTargetPath+"CallbackZ.cpp"), MqttTemplates.generateMqttCallbackZCPP(model)));
generateList.add(new FilesHelper(new File(generationTargetPath+"CallbackB.hpp"), MqttTemplates.generateMqttCallbackBH(model)));
generateList.add(new FilesHelper(new File(generationTargetPath+"CallbackB.cpp"), MqttTemplates.generateMqttCallbackBCPP(model)));
//If file directory does not exist, create it so files can be created
File directory = new File(generationTargetPath);
directory.mkdirs();
for (FilesHelper filesHelper : generateList) {
createFile(filesHelper.getFile(), filesHelper.getContent());
res.add(filesHelper.getFile());
}
res.add(generateCMake(component));
res.add(generateFindMqtt(component));
try {
int counter = 0;
for (File file : files)
{
frs.add(new FileWriter(file));
frs.get(counter).write(contents.get(counter));
counter++;
}
} catch (IOException e) {
e.printStackTrace();
}finally{
//Close resources
try {
for (FileWriter fr : frs)
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
files.add(generateCMake(component));
files.add(generateFindMqtt(component));
return files;
}
return res;
}
public File generateCMake(EMAComponentInstanceSymbol component)
{
......@@ -115,12 +83,12 @@ public class GeneratorMqtt
//Generate files and write to project
String content = MqttTemplates.generateMqttFindMqtt(model);
File directory = new File(generationTargetPath+"modules/");
directory.mkdirs();
File file = new File(generationTargetPath+"modules/FindMQTT.cmake");
createFile(file, content);
return file;
......
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.generator.mqtt.helper;
import java.io.File;
public class FilesHelper {
private File file;
private String content;
public FilesHelper(File file, String content) {
this.file = file;
this.content = content;
}
public File getFile(){
return file;
}
public String getContent(){
return content;
}
}
......@@ -89,7 +89,7 @@ void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::publish_echo_${pub.getN
_pub_${pub.getName()}->publish(pubmsg);
}
catch (const exception& exc) {
catch (const mqtt::exception& exc) {
cerr << exc.to_string() << endl;
}
}
......
......@@ -73,7 +73,7 @@ void MqttAdapter_tests_a_compA::publish_echo_portC()
_pub_portC->publish(pubmsg);
}
catch (const exception& exc) {
catch (const mqtt::exception& exc) {
cerr << exc.to_string() << endl;
}
}
......@@ -86,7 +86,7 @@ void MqttAdapter_tests_a_compA::publish_echo_portD()
_pub_portD->publish(pubmsg);
}
catch (const exception& exc) {
catch (const mqtt::exception& exc) {
cerr << exc.to_string() << endl;
}
}
......@@ -99,7 +99,7 @@ void MqttAdapter_tests_a_compA::publish_echo_portF()
_pub_portF->publish(pubmsg);
}
catch (const exception& exc) {
catch (const mqtt::exception& exc) {
cerr << exc.to_string() << endl;
}
}
......@@ -112,7 +112,7 @@ void MqttAdapter_tests_a_compA::publish_echo_portH()
_pub_portH->publish(pubmsg);
}
catch (const exception& exc) {
catch (const mqtt::exception& exc) {
cerr << exc.to_string() << endl;
}
}
......@@ -125,7 +125,7 @@ void MqttAdapter_tests_a_compA::publish_echo_portJ()
_pub_portJ->publish(pubmsg);
}
catch (const exception& exc) {
catch (const mqtt::exception& exc) {
cerr << exc.to_string() << endl;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment