Commit 368abea3 authored by René Schöne's avatar René Schöne
Browse files

Rename read/write to receive/send

parent 3beaeeec
......@@ -7,32 +7,32 @@ aspect Errors {
[new TreeSet<ErrorMessage>()]
root RagConnect;
ReadFromMqttDefinition contributes error("Read definition already defined for " + getToken().getName())
ReceiveFromMqttDefinition contributes error("Receive definition already defined for " + getToken().getName())
when isAlreadyDefined()
to RagConnect.errors();
ReadFromMqttDefinition contributes error("Reading target token must not be an NTA token!")
ReceiveFromMqttDefinition contributes error("Receiving target token must not be an NTA token!")
when getToken().getNTA()
to RagConnect.errors();
// if first mapping is null, then suitableDefaultMapping() == null
ReadFromMqttDefinition contributes error("No suitable default mapping found for type " +
ReceiveFromMqttDefinition contributes error("No suitable default mapping found for type " +
((getMappingList().isEmpty())
? getToken().getJavaTypeUse().prettyPrint()
: getMappingList().get(0).getFromType().prettyPrint()))
when effectiveMappings().get(0) == null
to RagConnect.errors();
ReadFromMqttDefinition contributes error("to-type of last mapping must be type of the Token!")
ReceiveFromMqttDefinition contributes error("to-type of last mapping must be type of the Token!")
when getToken().getJavaTypeUse().prettyPrint().equals(
effectiveMappings().get(effectiveMappings().size() - 1))
to RagConnect.errors();
WriteToMqttDefinition contributes error("Writing target token must be an NTA token!")
SendToMqttDefinition contributes error("Sending target token must be an NTA token!")
when !getToken().getNTA()
to RagConnect.errors();
WriteToMqttDefinition contributes error("Write definition already defined for " + getToken().getName())
SendToMqttDefinition contributes error("Send definition already defined for " + getToken().getName())
when isAlreadyDefined()
to RagConnect.errors();
......@@ -44,7 +44,7 @@ aspect Errors {
when isAlreadyDefinedAsList()
to RagConnect.errors();
DependencyDefinition contributes error("There must be a write update definition targeting " + getSource().parentTypeypeAndName() + " for dependency definition " + getID())
DependencyDefinition contributes error("There must be a send update definition targeting " + getSource().parentTypeypeAndName() + " for dependency definition " + getID())
when targetEndpointDefinition() == null
to RagConnect.errors();
}
......
//TypeComponentMustache ;
//rel TypeComponentMustache.TypeComponent -> TypeComponent ;
MRagConnect ::= ReadDefinition:MReadDefinition* WriteDefinition:MWriteDefinition* MappingDefinition:MMappingDefinition* DependencyDefinition:MDependencyDefinition* RootTypeComponent:MTypeComponent* TokenComponent:MTokenComponent*;
MRagConnect ::= ReceiveDefinition:MReceiveDefinition* SendDefinition:MSendDefinition* MappingDefinition:MMappingDefinition* DependencyDefinition:MDependencyDefinition* RootTypeComponent:MTypeComponent* TokenComponent:MTokenComponent*;
abstract MEndpointDefinition ::= InnerMappingDefinition:MInnerMappingDefinition*;
MReadDefinition : MEndpointDefinition;
MWriteDefinition : MEndpointDefinition;
MReceiveDefinition : MEndpointDefinition;
MSendDefinition : MEndpointDefinition;
MMappingDefinition;
MInnerMappingDefinition;
MDependencyDefinition;
......@@ -13,8 +13,8 @@ MTokenComponent;
rel MRagConnect.RagConnect -> RagConnect;
rel MInnerMappingDefinition.MappingDefinition -> MappingDefinition;
rel MReadDefinition.ReadFromMqttDefinition -> ReadFromMqttDefinition;
rel MWriteDefinition.WriteToMqttDefinition -> WriteToMqttDefinition;
rel MReceiveDefinition.ReceiveFromMqttDefinition -> ReceiveFromMqttDefinition;
rel MSendDefinition.SendToMqttDefinition -> SendToMqttDefinition;
rel MMappingDefinition.MappingDefinition -> MappingDefinition;
rel MDependencyDefinition.DependencyDefinition -> DependencyDefinition;
rel MTypeComponent.TypeComponent -> TypeComponent;
......
......@@ -24,25 +24,25 @@ aspect Navigation {
syn TokenEndpointDefinition EndpointDefinition.asTokenEndpointDefinition() = null;
eq TokenEndpointDefinition.asTokenEndpointDefinition() = this;
// --- isWriteToMqttDefinition ---
syn boolean EndpointDefinition.isWriteToMqttDefinition() = false;
eq WriteToMqttDefinition.isWriteToMqttDefinition() = true;
// --- isSendToMqttDefinition ---
syn boolean EndpointDefinition.isSendToMqttDefinition() = false;
eq SendToMqttDefinition.isSendToMqttDefinition() = true;
// --- asWriteToMqttDefinition ---
syn WriteToMqttDefinition EndpointDefinition.asWriteToMqttDefinition() = null;
eq WriteToMqttDefinition.asWriteToMqttDefinition() = this;
// --- asSendToMqttDefinition ---
syn SendToMqttDefinition EndpointDefinition.asSendToMqttDefinition() = null;
eq SendToMqttDefinition.asSendToMqttDefinition() = this;
// --- asReadFromMqttDefinition ---
syn ReadFromMqttDefinition EndpointDefinition.asReadFromMqttDefinition() = null;
eq ReadFromMqttDefinition.asReadFromMqttDefinition() = this;
// --- asReceiveFromMqttDefinition ---
syn ReceiveFromMqttDefinition EndpointDefinition.asReceiveFromMqttDefinition() = null;
eq ReceiveFromMqttDefinition.asReceiveFromMqttDefinition() = this;
// --- targetEndpointDefinition ---
syn WriteToMqttDefinition DependencyDefinition.targetEndpointDefinition() {
syn SendToMqttDefinition DependencyDefinition.targetEndpointDefinition() {
// resolve definition in here, as we do not need resolveMethod in any other place (yet)
for (EndpointDefinition endpointDefinition : ragconnect().getEndpointDefinitionList()) {
if (endpointDefinition.isWriteToMqttDefinition() &&
endpointDefinition.asWriteToMqttDefinition().getToken().equals(this.getTarget())) {
return endpointDefinition.asWriteToMqttDefinition();
if (endpointDefinition.isSendToMqttDefinition() &&
endpointDefinition.asSendToMqttDefinition().getToken().equals(this.getTarget())) {
return endpointDefinition.asSendToMqttDefinition();
}
}
return null;
......
......@@ -7,8 +7,8 @@ rel EndpointDefinition.Mapping* -> MappingDefinition;
abstract TokenEndpointDefinition : EndpointDefinition;
rel TokenEndpointDefinition.Token -> TokenComponent;
ReadFromMqttDefinition : TokenEndpointDefinition;
WriteToMqttDefinition : TokenEndpointDefinition;
ReceiveFromMqttDefinition : TokenEndpointDefinition;
SendToMqttDefinition : TokenEndpointDefinition;
DependencyDefinition ::= <ID>;
rel DependencyDefinition.Source <-> TokenComponent.DependencySourceDefinition*;
......
......@@ -79,23 +79,23 @@ aspect AttributesForMustache {
syn String MInnerMappingDefinition.methodName() = getMappingDefinition().methodName();
inh String MInnerMappingDefinition.inputVarName();
// --- MReadDefinition ---
eq MReadDefinition.preemptiveExpectedValue() = "get" + tokenName() + "()";
eq MReadDefinition.preemptiveReturn() = "return;";
eq MReadDefinition.endpointDef() = getReadFromMqttDefinition();
eq MReadDefinition.firstInputVarName() = "message";
// --- MReceiveDefinition ---
eq MReceiveDefinition.preemptiveExpectedValue() = "get" + tokenName() + "()";
eq MReceiveDefinition.preemptiveReturn() = "return;";
eq MReceiveDefinition.endpointDef() = getReceiveFromMqttDefinition();
eq MReceiveDefinition.firstInputVarName() = "message";
// --- MWriteDefinition ---
eq MWriteDefinition.preemptiveExpectedValue() = lastValue();
eq MWriteDefinition.preemptiveReturn() = "return false;";
eq MWriteDefinition.endpointDef() = getWriteToMqttDefinition();
eq MWriteDefinition.firstInputVarName() = "get" + tokenName() + "()";
// --- MSendDefinition ---
eq MSendDefinition.preemptiveExpectedValue() = lastValue();
eq MSendDefinition.preemptiveReturn() = "return false;";
eq MSendDefinition.endpointDef() = getSendToMqttDefinition();
eq MSendDefinition.firstInputVarName() = "get" + tokenName() + "()";
syn String MWriteDefinition.writeTopic() = getWriteToMqttDefinition().writeTopic();
syn String MWriteDefinition.lastValue() = getWriteToMqttDefinition().lastValue();
syn String MWriteDefinition.updateMethod() = getWriteToMqttDefinition().updateMethod();
syn String MWriteDefinition.writeMethod() = getWriteToMqttDefinition().writeMethod();
syn String MWriteDefinition.tokenResetMethod() = getWriteToMqttDefinition().tokenResetMethod();
syn String MSendDefinition.sendTopic() = getSendToMqttDefinition().sendTopic();
syn String MSendDefinition.lastValue() = getSendToMqttDefinition().lastValue();
syn String MSendDefinition.updateMethod() = getSendToMqttDefinition().updateMethod();
syn String MSendDefinition.writeMethod() = getSendToMqttDefinition().writeMethod();
syn String MSendDefinition.tokenResetMethod() = getSendToMqttDefinition().tokenResetMethod();
// --- MMappingDefinition ---
syn String MMappingDefinition.toType() = getMappingDefinition().getToType().prettyPrint();
......@@ -130,10 +130,10 @@ aspect AttributesForMustache {
MRagConnect result = new MRagConnect();
result.setRagConnect(this);
for (EndpointDefinition def : getEndpointDefinitionList()) {
if (def.isWriteToMqttDefinition()) {
result.addWriteDefinition(def.asWriteToMqttDefinition().toMustache());
if (def.isSendToMqttDefinition()) {
result.addSendDefinition(def.asSendToMqttDefinition().toMustache());
} else {
result.addReadDefinition(def.asReadFromMqttDefinition().toMustache());
result.addReceiveDefinition(def.asReceiveFromMqttDefinition().toMustache());
}
}
for (MappingDefinition def : allMappingDefinitions()) {
......@@ -163,15 +163,15 @@ aspect AttributesForMustache {
addInnerMappingDefinition(inner);
}
}
syn lazy MReadDefinition ReadFromMqttDefinition.toMustache() {
MReadDefinition result = new MReadDefinition();
result.setReadFromMqttDefinition(this);
syn lazy MReceiveDefinition ReceiveFromMqttDefinition.toMustache() {
MReceiveDefinition result = new MReceiveDefinition();
result.setReceiveFromMqttDefinition(this);
result.addInnerMappings();
return result;
}
syn lazy MWriteDefinition WriteToMqttDefinition.toMustache() {
MWriteDefinition result = new MWriteDefinition();
result.setWriteToMqttDefinition(this);
syn lazy MSendDefinition SendToMqttDefinition.toMustache() {
MSendDefinition result = new MSendDefinition();
result.setSendToMqttDefinition(this);
result.addInnerMappings();
return result;
}
......@@ -206,11 +206,11 @@ aspect AspectGeneration {
syn String TokenComponent.externalName() = getName();
syn String TokenEndpointDefinition.connectMethod() = "connect" + getToken().getName();
syn String WriteToMqttDefinition.writeTopic() = "_topic_" + getToken().getName();
syn String WriteToMqttDefinition.lastValue() = "_lastValue" + getToken().getName();
syn String WriteToMqttDefinition.updateMethod() = "_update_" + getToken().getName();
syn String WriteToMqttDefinition.writeMethod() = "_writeLastValue_" + getToken().getName();
syn String WriteToMqttDefinition.tokenResetMethod() = "get" + getToken().getName() + "_reset";
syn String SendToMqttDefinition.sendTopic() = "_topic_" + getToken().getName();
syn String SendToMqttDefinition.lastValue() = "_lastValue" + getToken().getName();
syn String SendToMqttDefinition.updateMethod() = "_update_" + getToken().getName();
syn String SendToMqttDefinition.writeMethod() = "_writeLastValue_" + getToken().getName();
syn String SendToMqttDefinition.tokenResetMethod() = "get" + getToken().getName() + "_reset";
syn String MappingDefinition.methodName() = "_apply_" + getID();
syn String DependencyDefinition.dependencyMethod() = "add" +
Character.toUpperCase(getID().charAt(0)) +
......
......@@ -106,7 +106,7 @@ aspect DefaultMappings {
aspect Mappings {
// --- effectiveMappings ---
syn java.util.List<MappingDefinition> EndpointDefinition.effectiveMappings();
eq ReadFromMqttDefinition.effectiveMappings() {
eq ReceiveFromMqttDefinition.effectiveMappings() {
// if there is a first mapping, check if its input type is byte[].
// or if no mappings are specified.
// then prepend the suitable default mapping
......@@ -120,7 +120,7 @@ aspect Mappings {
}
return result;
}
eq WriteToMqttDefinition.effectiveMappings() {
eq SendToMqttDefinition.effectiveMappings() {
// if there is a mapping, check if the output type of the last mapping is byte[].
// or if no mappings are specified.
// then append the suitable default mapping
......@@ -160,7 +160,7 @@ aspect Mappings {
// --- suitableDefaultMapping ---
syn DefaultMappingDefinition EndpointDefinition.suitableDefaultMapping();
eq ReadFromMqttDefinition.suitableDefaultMapping() {
eq ReceiveFromMqttDefinition.suitableDefaultMapping() {
String typeName = getMappingList().isEmpty() ?
getToken().getJavaTypeUse().getName() :
getMappingList().get(0).getFromType().prettyPrint();
......@@ -181,7 +181,7 @@ aspect Mappings {
default: return null;
}
}
eq WriteToMqttDefinition.suitableDefaultMapping() {
eq SendToMqttDefinition.suitableDefaultMapping() {
String typeName = getMappingList().isEmpty() ?
getToken().getJavaTypeUse().getName() :
getMappingList().get(getMappingList().size() - 1).getFromType().prettyPrint();
......
......@@ -13,30 +13,30 @@ RagConnect ragconnect
:} ;
EndpointDefinition endpoint_definition
= READ ID.type_name DOT ID.token_name SCOL
= RECEIVE ID.type_name DOT ID.token_name SCOL
{:
ReadFromMqttDefinition result = new ReadFromMqttDefinition();
ReceiveFromMqttDefinition result = new ReceiveFromMqttDefinition();
result.setToken(TokenComponent.createRef(type_name + "." + token_name));
return result;
:}
| READ ID.type_name DOT ID.token_name USING string_list.mapping_defs SCOL
| RECEIVE ID.type_name DOT ID.token_name USING string_list.mapping_defs SCOL
{:
ReadFromMqttDefinition result = new ReadFromMqttDefinition();
ReceiveFromMqttDefinition result = new ReceiveFromMqttDefinition();
result.setToken(TokenComponent.createRef(type_name + "." + token_name));
for (String mapping_def : makeMappingDefs(mapping_defs)) {
result.addMapping(MappingDefinition.createRef(mapping_def));
}
return result;
:}
| WRITE ID.type_name DOT ID.token_name SCOL
| SEND ID.type_name DOT ID.token_name SCOL
{:
WriteToMqttDefinition result = new WriteToMqttDefinition();
SendToMqttDefinition result = new SendToMqttDefinition();
result.setToken(TokenComponent.createRef(type_name + "." + token_name));
return result;
:}
| WRITE ID.type_name DOT ID.token_name USING string_list.mapping_defs SCOL
| SEND ID.type_name DOT ID.token_name USING string_list.mapping_defs SCOL
{:
WriteToMqttDefinition result = new WriteToMqttDefinition();
SendToMqttDefinition result = new SendToMqttDefinition();
result.setToken(TokenComponent.createRef(type_name + "." + token_name));
for (String mapping_def : makeMappingDefs(mapping_defs)) {
result.addMapping(MappingDefinition.createRef(mapping_def));
......
"read" { yybegin(DECLARATION); return sym(Terminals.READ); }
"write" { yybegin(DECLARATION); return sym(Terminals.WRITE); }
"receive" { yybegin(DECLARATION); return sym(Terminals.RECEIVE); }
"send" { yybegin(DECLARATION); return sym(Terminals.SEND); }
"using" { return sym(Terminals.USING); }
"canDependOn" { return sym(Terminals.CAN_DEPEND_ON); }
"maps" { return sym(Terminals.MAPS); }
......
......@@ -77,9 +77,9 @@ public class Compiler extends AbstractCompiler {
}
for (GrammarFile grammarFile : ragConnect.getProgram().getGrammarFileList()) {
Path outputFile = getConfiguration().outputDir().toPath().resolve(grammarFile.getFileName());
writeToFile(outputFile, grammarFile.generateAbstractGrammar());
sendToFile(outputFile, grammarFile.generateAbstractGrammar());
}
writeToFile(getConfiguration().outputDir().toPath().resolve("RagConnect.jadd"), ragConnect.generateAspect(optionRootNode.value()));
sendToFile(getConfiguration().outputDir().toPath().resolve("RagConnect.jadd"), ragConnect.generateAspect(optionRootNode.value()));
return 0;
}
......@@ -118,7 +118,7 @@ public class Compiler extends AbstractCompiler {
System.out.println(message);
}
private void writeToFile(Path path, String str) throws CompilerException {
private void sendToFile(Path path, String str) throws CompilerException {
try (BufferedWriter writer = Files.newBufferedWriter(path)) {
writer.append(str);
} catch (Exception e) {
......
......@@ -123,11 +123,11 @@ public class SimpleMain {
" ;");
model.addMappingDefinition(mappingDefinition);
ReadFromMqttDefinition readFromMqttDefinition = new ReadFromMqttDefinition();
readFromMqttDefinition.setAlwaysApply(false);
readFromMqttDefinition.setToken(TokenComponent.createRef("Link.CurrentPosition"));
readFromMqttDefinition.addMapping(mappingDefinition);
model.addEndpointDefinition(readFromMqttDefinition);
ReceiveFromMqttDefinition receiveFromMqttDefinition = new ReceiveFromMqttDefinition();
receiveFromMqttDefinition.setAlwaysApply(false);
receiveFromMqttDefinition.setToken(TokenComponent.createRef("Link.CurrentPosition"));
receiveFromMqttDefinition.addMapping(mappingDefinition);
model.addEndpointDefinition(receiveFromMqttDefinition);
model.treeResolveAll();
for (ErrorMessage error : model.errors()) {
......
{{> mqtt}}
aspect ROS2RAG {
{{#ReadDefinitions}}
{{> readDefinition}}
{{/ReadDefinitions}}
{{#ReceiveDefinitions}}
{{> receiveDefinition}}
{{/ReceiveDefinitions}}
{{#WriteDefinitions}}
{{> writeDefinition}}
{{/WriteDefinitions}}
{{#SendDefinitions}}
{{> sendDefinition}}
{{/SendDefinitions}}
{{#MappingDefinitions}}
{{> mappingDefinition}}
......
......@@ -2,7 +2,7 @@
{{mqttHandlerAttribute}}().newConnection(topic, message -> {
{{> mappingApplication}}
{{#loggingEnabledForReads}}
System.out.println("[Read] " + topic + " -> {{tokenName}} = " + {{lastResult}});{{!lastResult has to be a new attribute}}
System.out.println("[Receive] " + topic + " -> {{tokenName}} = " + {{lastResult}});{{!lastResult has to be a new attribute}}
{{/loggingEnabledForReads}}
set{{tokenName}}({{lastResult}});
});
......
private String {{parentTypeName}}.{{writeTopic}} = null;
private String {{parentTypeName}}.{{sendTopic}} = null;
private byte[] {{parentTypeName}}.{{lastValue}} = null;
public void {{parentTypeName}}.{{connectMethod}}(String topic, boolean writeCurrentValue) {
{{writeTopic}} = topic;
{{sendTopic}} = topic;
{{updateMethod}}();
if (writeCurrentValue) {
{{writeMethod}}();
......@@ -18,7 +18,7 @@
protected void {{parentTypeName}}.{{writeMethod}}() {
{{#loggingEnabledForWrites}}
System.out.println("[Write] {{tokenName}} = " + get{{tokenName}}() + " -> " + {{writeTopic}});
System.out.println("[Send] {{tokenName}} = " + get{{tokenName}}() + " -> " + {{sendTopic}});
{{/loggingEnabledForWrites}}
{{mqttHandlerAttribute}}().publish({{writeTopic}}, {{lastValue}});
{{mqttHandlerAttribute}}().publish({{sendTopic}}, {{lastValue}});
}
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