Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
E
EMAM2Cpp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
12
Issues
12
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Cpp
Commits
d7458713
Commit
d7458713
authored
Dec 17, 2020
by
Jean Meurice
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ServerAdapter: added initial program values
parent
7c55c212
Pipeline
#378671
passed with stage
in 12 minutes and 4 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
10 deletions
+111
-10
src/main/java/de/monticore/lang/monticar/generator/cpp/dynamic_interface/TcpCommunication.java
...car/generator/cpp/dynamic_interface/TcpCommunication.java
+102
-2
src/main/resources/template/dynamic_interface/server_adapter.cpp.ftl
...sources/template/dynamic_interface/server_adapter.cpp.ftl
+7
-8
src/main/resources/template/dynamic_interface/server_adapter.h.ftl
...resources/template/dynamic_interface/server_adapter.h.ftl
+2
-0
No files found.
src/main/java/de/monticore/lang/monticar/generator/cpp/dynamic_interface/TcpCommunication.java
View file @
d7458713
...
...
@@ -29,9 +29,11 @@ public class TcpCommunication {
List
<
String
>
setInputCases
=
new
ArrayList
<>();
List
<
String
>
sendOutputCalls
=
new
ArrayList
<>();
List
<
String
>
sendOutputCases
=
new
ArrayList
<>();
List
<
String
>
initDataCalls
=
new
ArrayList
<>();
int
i
=
0
;
for
(
PortInformation
portInfo
:
gen
.
programInterface
.
ports
){
initDataCalls
.
add
(
generateInitData
(
portInfo
));
if
(
portInfo
.
direction
==
PortDirection
.
INPUT
){
setInputCases
.
add
(
generateSetInputCase
(
i
,
portInfo
));
}
else
{
...
...
@@ -47,6 +49,7 @@ public class TcpCommunication {
templateData
.
put
(
"setInputCases"
,
setInputCases
);
templateData
.
put
(
"sendOutputCalls"
,
sendOutputCalls
);
templateData
.
put
(
"sendOutputCases"
,
sendOutputCases
);
templateData
.
put
(
"initDataCalls"
,
initDataCalls
);
templateData
.
put
(
"useDDC"
,
hasDDC
);
files
.
add
(
new
FileContent
(
AllTemplates
.
generate
(
AllTemplates
.
TCP_ADAPTER_H
,
templateData
),
"server_adapter.h"
));
...
...
@@ -64,7 +67,9 @@ public class TcpCommunication {
return
files
;
}
public
void
getSources
(
HashSet
<
String
>
sources
)
{
public
void
getSources
(
HashSet
<
String
>
sources
)
{
sources
.
add
(
"json.cpp"
);
sources
.
add
(
"printf.cpp"
);
sources
.
add
(
"network.cpp"
);
...
...
@@ -95,6 +100,13 @@ public class TcpCommunication {
return
b
.
getContent
();
}
private
String
generateInitData
(
PortInformation
portInfo
)
{
b
.
init
();
generateInitData
(
portInfo
.
type
,
1
,
1
,
"program_instance."
+
portInfo
.
name
);
return
b
.
getContent
();
}
private
void
generateSetter
(
DataType
type
,
int
indent
,
int
depth
,
String
varReference
){
...
...
@@ -155,13 +167,13 @@ public class TcpCommunication {
String
j
=
String
.
format
(
"j%d"
,
depth
);
String
ref
=
String
.
format
(
"res%d"
,
depth
);
b
.
a
(
indent
,
"for (int %s=0; %s < %d; ++%s) {"
,
i
,
i
,
rows
,
i
);
b
.
a
(
indent
,
" for (int %s=0; %s < %d; ++%s) {"
,
j
,
j
,
cols
,
j
);
b
.
a
(
indent
,
" auto &%s = %s(%s, %s);"
,
ref
,
varReference
,
i
,
j
);
generateSetter
(
vt
.
getBaseType
(),
newIndent
,
depth
+
1
,
ref
);
b
.
a
(
indent
,
" }"
);
b
.
a
(
indent
,
"}"
);
throw
new
IllegalArgumentException
(
"TODO read sizes first?"
);
}
else
if
(
type
instanceof
DynVectorType
)
{
System
.
out
.
println
(
"Unimplemented: DynVectorType set_port case."
);
...
...
@@ -248,6 +260,7 @@ public class TcpCommunication {
generateGetter
(
vt
.
getBaseType
(),
newIndent
,
depth
+
1
,
ref
);
b
.
a
(
indent
,
" }"
);
b
.
a
(
indent
,
"}"
);
throw
new
IllegalArgumentException
(
"TODO write sizes?"
);
}
else
if
(
type
instanceof
DynVectorType
)
{
System
.
out
.
println
(
"Unimplemented: DynVectorType get_port case."
);
...
...
@@ -274,4 +287,91 @@ public class TcpCommunication {
}
private
void
generateInitData
(
DataType
type
,
int
indent
,
int
depth
,
String
varReference
)
{
if
(
type
instanceof
BasicType
){
BasicType
t
=
(
BasicType
)
type
;
switch
(
t
.
getType
()){
case
Q:
b
.
a
(
indent
,
"%s = 0.0;"
,
varReference
);
return
;
case
Z:
case
N:
case
N1:
b
.
a
(
indent
,
"%s = 0;"
,
varReference
);
return
;
case
C:
b
.
a
(
indent
,
"%s = 0.0;"
,
varReference
);
// TODO correct complex number native case
throw
new
IllegalStateException
(
"Unimplemented"
);
case
BOOLEAN:
b
.
a
(
indent
,
"%s = false;"
,
varReference
);
return
;
case
EMPTY:
return
;
case
VEC2:
b
.
a
(
indent
,
"%s(0) = 0.0;"
,
varReference
);
b
.
a
(
indent
,
"%s(1) = 0.0;"
,
varReference
);
return
;
case
VEC3:
b
.
a
(
indent
,
"%s(0) = 0.0;"
,
varReference
);
b
.
a
(
indent
,
"%s(1) = 0.0;"
,
varReference
);
b
.
a
(
indent
,
"%s(2) = 0.0;"
,
varReference
);
return
;
default
:
throw
new
IllegalArgumentException
(
"Missing case"
);
}
}
else
if
(
type
instanceof
VectorType
)
{
VectorType
vt
=
(
VectorType
)
type
;
int
newIndent
=
indent
+
1
;
int
size
=
vt
.
getSize
();
String
iVar
=
String
.
format
(
"i%d"
,
depth
);
String
ref
=
String
.
format
(
"res%d"
,
depth
);
b
.
a
(
indent
,
"for (int %s=0; %s < %d; ++%s) {"
,
iVar
,
iVar
,
size
,
iVar
);
b
.
a
(
indent
,
" auto &%s = %s(%s);"
,
ref
,
varReference
,
iVar
);
generateInitData
(
vt
.
getBaseType
(),
newIndent
,
depth
+
1
,
ref
);
b
.
a
(
indent
,
"}"
);
}
else
if
(
type
instanceof
MatrixType
)
{
MatrixType
vt
=
(
MatrixType
)
type
;
int
newIndent
=
indent
+
2
;
int
rows
=
vt
.
getRowCount
();
int
cols
=
vt
.
getColumnCount
();
String
i
=
String
.
format
(
"i%d"
,
depth
);
String
j
=
String
.
format
(
"j%d"
,
depth
);
String
ref
=
String
.
format
(
"res%d"
,
depth
);
b
.
a
(
indent
,
"for (int %s=0; %s < %d; ++%s) {"
,
i
,
i
,
rows
,
i
);
b
.
a
(
indent
,
" for (int %s=0; %s < %d; ++%s) {"
,
j
,
j
,
cols
,
j
);
b
.
a
(
indent
,
" auto &%s = %s(%s, %s);"
,
ref
,
varReference
,
i
,
j
);
generateInitData
(
vt
.
getBaseType
(),
newIndent
,
depth
+
1
,
ref
);
b
.
a
(
indent
,
" }"
);
b
.
a
(
indent
,
"}"
);
}
else
if
(
type
instanceof
DynVectorType
)
{
System
.
out
.
println
(
"Unimplemented: DynVectorType generateInitData case."
);
//throw new IllegalArgumentException("Unimplemented");
}
else
if
(
type
instanceof
StructType
)
{
StructType
st
=
(
StructType
)
type
;
int
count
=
st
.
getFieldCount
();
for
(
int
i
=
0
;
i
<
count
;
++
i
){
String
fieldName
=
st
.
getFieldName
(
i
);
generateInitData
(
st
.
getFieldType
(
i
),
indent
,
depth
+
1
,
String
.
format
(
"%s.%s"
,
varReference
,
fieldName
));
}
}
else
if
(
type
instanceof
EnumType
)
{
EnumType
et
=
(
EnumType
)
type
;
int
variantCount
=
et
.
getVariantCount
();
if
(
variantCount
>
256
)
throw
new
IllegalArgumentException
(
"Too much Enum variants for enum "
+
et
.
getName
()+
" (TODO implement adaptive native type size)"
);
b
.
a
(
indent
,
"%s = static_cast<%s>(0);"
,
et
.
getName
());
}
else
{
throw
new
IllegalArgumentException
(
"Missing case"
);
}
}
}
src/main/resources/template/dynamic_interface/server_adapter.cpp.ftl
View file @
d7458713
...
...
@@ -159,6 +159,7 @@ void SimulationSession::init(PacketReader &init_packet) {
cout << "Running in time mode '" << mode << "'." << endl;
program_instance.init();
init_program_data();
cout << "Initialized Program." << endl;
// Sending Program Interface
...
...
@@ -173,9 +174,7 @@ void SimulationSession::set_input(PacketReader &input_packet) {
auto port_id = input_packet.read_u16();
switch (port_id) {
<#list setInputCases as setInputCase>
${setInputCase}
</#list>
<#list setInputCases as setInputCase>${setInputCase}</#list>
default:
cerr << "Invalid INPUT port ID: '"<< port_id << "'" << endl;
throw exception();
...
...
@@ -211,9 +210,7 @@ void SimulationSession::send_output(int port_id){
// Write port data
switch (port_id) {
<#list sendOutputCases as sendOutputCase>
${sendOutputCase}
</#list>
<#list sendOutputCases as sendOutputCase>${sendOutputCase}</#list>
default:
cerr << "Invalid output port ID: '"<< port_id << "'" << endl;
throw exception();
...
...
@@ -229,8 +226,10 @@ void SimulationSession::send_time(double time) {
}
// TODO: Should be handled in the component init() code
void SimulationSession::init_program_data() {
<#list initDataCalls as initDataCall>${initDataCall}</#list>
}
...
...
src/main/resources/template/dynamic_interface/server_adapter.h.ftl
View file @
d7458713
...
...
@@ -29,6 +29,8 @@ struct SimulationSession {
void run_cycle(PacketReader &run_packet);
void send_output(int port_id);
void send_time(double time);
void init_program_data();
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment