Commit 88107927 authored by Jean Meurice's avatar Jean Meurice
Browse files

Tweaks

parent b5570de1
Pipeline #472446 failed with stage
in 8 minutes and 52 seconds
......@@ -10,7 +10,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-generator</artifactId>
<version>0.4.6</version>
<version>0.4.8</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
......
......@@ -41,7 +41,7 @@ public final class TypesGeneratorCPP {
} else if (s instanceof EnumDeclarationSymbol) {
processEnum((EnumDeclarationSymbol) s);
} else {
Log.warn("unknown type symbol: " + s.getFullName());
//Log.warn("unknown type symbol: " + s.getFullName());
}
}
......
......@@ -70,14 +70,17 @@ public class AdapterGenerator {
addFileDependencySharedCpp("json.cpp");
addFileDependencySharedCpp("printf.h");
addFileDependencySharedCpp("printf.cpp");
addFileDependencySharedCpp("err_out/err_out.h");
addFileDependencySharedCpp("err_out/standalone_err_out.cpp");
// TODO "intermediate target" with serialization code ?
cmake.addCMakeCommandEnd("# A static library around the root EMA component with JSON/Binary serialization functions.");
cmake.addCMakeCommandEnd("add_library("+targetNameWithSerialization+" STATIC program.cpp buffer.cpp json.cpp printf.cpp)");
cmake.addCMakeCommandEnd("add_library("+targetNameWithSerialization+" STATIC program.cpp buffer.cpp json.cpp printf.cpp err_out/standalone_err_out.cpp)");
cmake.addCMakeCommandEnd("target_include_directories("+targetNameWithSerialization+" PUBLIC ${INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})");
//cmake.addCMakeCommandEnd("target_link_libraries("+targetNameWithSerialization+" PUBLIC ${LIBS} -static-libgcc -static-libstdc++)");
cmake.addCMakeCommandEnd("target_link_libraries("+targetNameWithSerialization+" PRIVATE ${LIBS})");
cmake.addCMakeCommandEnd("target_compile_features("+targetNameWithSerialization+" PUBLIC cxx_std_11)");
cmake.addCMakeCommandEnd("set_target_properties("+targetNameWithSerialization+" PROPERTIES LINKER_LANGUAGE CXX POSITION_INDEPENDENT_CODE ON)");
cmake.addCMakeCommandEnd("");
cmake.addCMakeCommandEnd("");
......@@ -110,6 +113,9 @@ public class AdapterGenerator {
cmake.addCMakeCommandEnd("# ServerAdapter for the EMA component");
cmake.addCMakeCommandEnd("add_executable("+targetNameServer+" server_adapter.cpp network.cpp)");
cmake.addCMakeCommandEnd("target_link_libraries("+targetNameServer+" PUBLIC "+targetNameWithSerialization+")");
cmake.addCMakeCommandEnd("if (CMAKE_HOST_WIN32)");
cmake.addCMakeCommandEnd(" target_link_libraries("+targetNameServer+" PUBLIC ws2_32)");
cmake.addCMakeCommandEnd("endif()");
cmake.addCMakeCommandEnd("");
}
......
......@@ -25,7 +25,7 @@ public class JsonSerializationGenerator extends SerializationGenerator {
b.a(indent, "auto it = as.begin();");
b.a(indent, "auto end = as.end();");
b.a(indent, "if (!(it != end)) {");
b.a(indent, " cerr << \"Expected IP entry in array\" << endl;");
b.a(indent, " throw_error(\"ParsingError\", \"Expected IP entry in array\");");
b.a(indent, " break;");
b.a(indent, "}");
b.a(indent, "auto ip = reader.get_string().get_json_string();");
......@@ -34,7 +34,7 @@ public class JsonSerializationGenerator extends SerializationGenerator {
b.a(indent, "auto &target = program_instance.%s[id];", sockInf.input_name);
b.a(indent, "++it;");
b.a(indent, "if (!(it != end)) {");
b.a(indent, " cerr << \"Expected IP entry in array\" << endl;");
b.a(indent, " throw_error(\"ParsingError\", \"Expected IP entry in array\");");
b.a(indent, " break;");
b.a(indent, "}");
generateSetter(((SimplePacketType) portInfo.data_type).getPayloadType(), indent, 1, "target");
......@@ -79,13 +79,13 @@ public class JsonSerializationGenerator extends SerializationGenerator {
case N: {
String varName = String.format("res%d", depth);
b.a(indent, "auto %s = reader.get_long();", varName);
b.a(indent, "if (%s < 0) { %s = 0; } //TODO as error?", varName, varName);
b.a(indent, "if (%s < 0) { %s = 0; throw_error(\"ParsingError\", \"Received negative natural number (N).\"); }", varName, varName);
b.a(indent, "%s = %s;", varReference, varName);
} break;
case N1: {
String varName = String.format("res%d", depth);
b.a(indent, "auto %s = reader.get_long();", varName);
b.a(indent, "if (%s < 1) { %s = 0; } //TODO as error?", varName, varName);
b.a(indent, "if (%s < 1) { %s = 0; throw_error(\"ParsingError\", \"Received natural number <= 0 (N1).\");}", varName, varName);
b.a(indent, "%s = %s;", varReference, varName);
} break;
case C: {
......@@ -93,10 +93,10 @@ public class JsonSerializationGenerator extends SerializationGenerator {
b.a(indent, "int %s = 0;", i);
b.a(indent, "for (auto t : reader.stream_array()) {" );
b.a(indent, " if (%s == 0) %s = reader.get_double();", i, varReference);
b.a(indent, " else if (%s == 1) {} // TODO UPDATE\n", i); // TODO handle correct Complex native type
b.a(indent, " else {} // TODO error?" );
b.a(indent, " else if (%s == 1) {throw_error(\"ParsingError\", \"Unimplemented complex number\");}\n", i); // TODO handle correct Complex native type
b.a(indent, " else { throw_error(\"ParsingError\", \"Too much entries in the received complex number JSON serialization.\"); }" );
b.a(indent, " ++%s;", i);
b.a(indent, "} if (%s < 2) {} // TODO error?", i);
b.a(indent, "} if (%s < 2) { throw_error(\"ParsingError\", \"Missing entries in the received complex number JSON serialization.\"); }", i);
} break;
case BOOLEAN:
b.a(indent, "%s = reader.get_bool();", varReference);
......@@ -108,18 +108,18 @@ public class JsonSerializationGenerator extends SerializationGenerator {
b.a(indent, "int %s = 0;", i);
b.a(indent, "for (auto t : reader.stream_array()) {" );
b.a(indent, " if (%s < 2) %s(%s) = reader.get_double();", i, varReference, i);
b.a(indent, " else {} // TODO error?" );
b.a(indent, " else { throw_error(\"ParsingError\", \"Too much entries in the received VEC2 JSON serialization.\"); }");
b.a(indent, " ++%s;", i);
b.a(indent, "} if (%s < 2) {} // TODO error?", i);
b.a(indent, "} if (%s < 2) { throw_error(\"ParsingError\", \"Missing entries in the received VEC2 JSON serialization.\"); }", i);
} break;
case VEC3: {
String i = String.format("i%d", depth);
b.a(indent, "int %s = 0;", i);
b.a(indent, "for (auto t : reader.stream_array()) {" );
b.a(indent, " if (%s < 3) %s(%s) = reader.get_double();", i, varReference, i);
b.a(indent, " else {} // TODO error?" );
b.a(indent, " else { throw_error(\"ParsingError\", \"Too much entries in the received VEC3 JSON serialization.\"); }");
b.a(indent, " ++%s;", i);
b.a(indent, "} if (%s < 3) {} // TODO error?", i);
b.a(indent, "} if (%s < 3) { throw_error(\"ParsingError\", \"Missing entries in the received VEC3 JSON serialization.\"); }",i);
} break;
default:
throw new IllegalArgumentException("Missing case");
......@@ -129,15 +129,21 @@ public class JsonSerializationGenerator extends SerializationGenerator {
int newIndent = indent + 1;
int size = vt.getSize();
String i = String.format("i%d", depth);
String first = String.format("first%d", depth);
String ref = String.format("res%d", depth);
b.a(indent, "int %s = 0;", i);
b.a(indent, "bool %s = true;", first);
b.a(indent, "for (auto t : reader.stream_array()) {" );
b.a(indent, " if (%s >= %d) { break; /*TODO error?*/}", i, size);
b.a(indent, " if (%s) {", first);
b.a(indent, " %s = false;", first);
b.a(indent, " if (reader.get_long() != %s) { throw_error(\"ParsingError\", \"Size given in serialized VectorType array does not match the expected vector length.\"); break; }", size);
b.a(indent, " continue;");
b.a(indent, " } else if (%s >= %d) { throw_error(\"ParsingError\", \"Too much entries in the received Vector JSON serialization.\"); break; }", i, size);
b.a(indent, " auto &%s = %s(%s);", ref, varReference, i);
generateSetter(vt.getBaseType(), newIndent, depth+1, ref);
b.a(indent, " ++%s;", i);
b.a(indent, "} if (%s < %d) {} // TODO error?", i, size);
b.a(indent, "} if (%s < %d) { throw_error(\"ParsingError\", \"Missing entries in the received Vector JSON serialization.\"); }", i, size);
} else if (type instanceof MatrixType) {
MatrixType vt = (MatrixType)type;
int newIndent = indent + 2;
......@@ -150,16 +156,16 @@ public class JsonSerializationGenerator extends SerializationGenerator {
b.a(indent, "int %s = 0;", i);
b.a(indent, "for (auto t : reader.stream_array()) {" );
b.a(indent, " if (%s >= %d) { break; /*TODO error?*/}", i, rows);
b.a(indent, " if (%s >= %d) { throw_error(\"ParsingError\", \"Too much rows in the received Matrix JSON serialization.\"); break; }", i, rows);
b.a(indent, " int %s = 0;", j);
b.a(indent, " for (auto u : reader.stream_array()) {" );
b.a(indent, " if (%s >= %d) { break; /*TODO error?*/}", j, cols);
b.a(indent, " if (%s >= %d) { throw_error(\"ParsingError\", \"Too much columns in the received Matrix JSON serialization.\"); break; }", j, cols);
b.a(indent, " auto &%s = %s(%s, %s);", ref, varReference, i, j);
generateSetter(vt.getBaseType(), newIndent, depth+1, ref);
b.a(indent, " ++%s;", j);
b.a(indent, " } if (%s < %d) {} // TODO error?", j, cols);
b.a(indent, " } if (%s < %d) { throw_error(\"ParsingError\", \"Missing entries in a column of the received Matrix JSON serialization.\"); } ", j, cols);
b.a(indent, " ++%s;", i);
b.a(indent, "} if (%s < %d) {} // TODO error?", i, cols);
b.a(indent, "} if (%s < %d) {throw_error(\"ParsingError\", \"Missing rows in the received Matrix JSON serialization.\");}", i, cols);
} else if (type instanceof DynVectorType) {
System.out.println("Unimplemented: DynVectorType set_port case.");
......@@ -182,11 +188,11 @@ public class JsonSerializationGenerator extends SerializationGenerator {
b.a(indent, "if (%s != %s) {", it, end);
generateSetter(st.getFieldType(i), newIndent, depth+1, String.format("%s.%s", varReference, fieldName));
b.a(indent, " %s++;", it);
b.a(indent, "} else {/*TODO error?*/}" );
b.a(indent, " ++%s;", it);
b.a(indent, "} else { throw_error(\"ParsingError\", \"Missing entries in the received Struct JSON serialization.\"); }" );
}
b.a(indent, "if (%s != %s) {/*TODO error?*/}", it, end);
b.a(indent, "if (%s != %s) { throw_error(\"ParsingError\", \"Too much entries in the received Struct JSON serialization.\"); }", it, end);
} else if (type instanceof EnumType) {
EnumType et = (EnumType)type;
......@@ -207,7 +213,7 @@ public class JsonSerializationGenerator extends SerializationGenerator {
elseS = "else ";
}
b.a(indent, "else {/*TODO error?*/}");
b.a(indent, "else { throw_error(\"ParsingError\", \"Unknown ENUM variant received in the JSON serialization.\"); }");
} else {
throw new IllegalArgumentException("Missing case");
......@@ -258,6 +264,7 @@ public class JsonSerializationGenerator extends SerializationGenerator {
String ref = String.format("res%d", depth);
b.a(indent, "writer.start_array();" );
b.a(indent, "writer.write_value(%s);", size);
b.a(indent, "for (int %s=0; %s < %d; ++%s) {", i, i, size, i);
b.a(indent, " auto &%s = %s(%s);", ref, varReference, i);
generateGetter(vt.getBaseType(), newIndent, depth+1, ref);
......@@ -285,7 +292,7 @@ public class JsonSerializationGenerator extends SerializationGenerator {
b.a(indent, "}" );
b.a(indent, "writer.end_array();" );
}else if (type instanceof DynVectorType) {
} else if (type instanceof DynVectorType) {
System.out.println("Unimplemented: DynVectorType get_port case.");
//throw new IllegalArgumentException("Unimplemented");
} else if (type instanceof StructType) {
......
......@@ -4,9 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import de.monticore.lang.monticar.generator.cpp.dynamic_interface.ProgramInterfaceResolver.SocketInfo;
import de.rwth.montisim.commons.dynamicinterface.*;
import de.rwth.montisim.commons.dynamicinterface.PortInformation.PortDirection;
import de.rwth.montisim.commons.dynamicinterface.PortInformation.PortType;
import de.rwth.montisim.commons.utils.json.SerializationException;
......
Subproject commit 5b49cc13ecccb22cbdd41a33787e7b7583781e8a
Subproject commit 78259f1d7d61e05c89995bf2637dec24d51b8529
......@@ -2,6 +2,7 @@
#include "./${mainModelName}.h"
#include <exception>
#include "err_out/err_out.h"
static constexpr auto N_TO_N_BROADCAST_ADDR = "ff02::2";
static constexpr auto N_TO_N_PREFIX = "2::";
......
......@@ -82,7 +82,8 @@ void SimulationSession::run() {
reset = false;
packet_in.receive();
if (packet_in.id == PACKET_INIT){
init(packet_in.getReader());
auto br = packet_in.getReader();
init(br);
} else {
throw AdapterException("Expected INIT packet, but got: id=" + to_string(packet_in.id) + " length=" + to_string(packet_in.size));
}
......@@ -110,9 +111,10 @@ void SimulationSession::run() {
is_json_comm = true;
autopilot::set_port_json(packet_in.getReader().read_u16(), packet_in.getPayload()+2);
break;
case PACKET_RUN_CYCLE:
run_cycle(packet_in.getReader());
break;
case PACKET_RUN_CYCLE: {
auto br = packet_in.getReader();
run_cycle(br);
} break;
case PACKET_REF_ID: // Ignore in direct server mode
break;
default:
......
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