Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2SomeIP
Commits
1a4f7394
Commit
1a4f7394
authored
Jul 10, 2019
by
Markus Georg Bendel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic CMake generation
parent
ce6f2ac5
Pipeline
#159053
failed with stages
in 56 seconds
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
175 additions
and
39 deletions
+175
-39
someip_adapter/CMakeLists.txt
someip_adapter/CMakeLists.txt
+6
-5
someip_adapter/SomeIPAdapter_tests_a_compA.cpp
someip_adapter/SomeIPAdapter_tests_a_compA.cpp
+19
-19
someip_adapter/SomeIPAdapter_tests_a_compA.h
someip_adapter/SomeIPAdapter_tests_a_compA.h
+10
-10
src/main/java/de/monticore/lang/monticar/generator/someip/GeneratorSomeIP.java
...icore/lang/monticar/generator/someip/GeneratorSomeIP.java
+34
-5
src/main/java/de/monticore/lang/monticar/generator/someip/template/SomeIPAdapterModel.java
...onticar/generator/someip/template/SomeIPAdapterModel.java
+8
-0
src/main/java/de/monticore/lang/monticar/generator/someip/template/SomeIPTemplates.java
...g/monticar/generator/someip/template/SomeIPTemplates.java
+9
-0
src/main/resources/de/monticore/lang/monticar/generator/someip/template/CMakeLists.ftl
...re/lang/monticar/generator/someip/template/CMakeLists.ftl
+23
-0
src/test/java/de/monticore/lang/monticar/generator/someip/CMakeGenerationTest.java
...e/lang/monticar/generator/someip/CMakeGenerationTest.java
+44
-0
src/test/resources/results/echoCMake/CMakeLists.txt
src/test/resources/results/echoCMake/CMakeLists.txt
+22
-0
No files found.
someip_adapter/CMakeLists.txt
View file @
1a4f7394
# Setting cmake version
cmake_minimum_required
(
VERSION 2.8
)
# Using C++
version 11 with threads for compiling
# Using C++
with flags
set
(
CMAKE_CXX_FLAGS
"-g -std=c++0x"
)
# Find
packages and include directori
es
# Find
vsomeip and boost packag
es
find_package
(
vsomeip 2.10.0 REQUIRED
)
find_package
(
Boost 1.55 COMPONENTS system thread log REQUIRED
)
#include vsomeip and boost directories
include_directories
(
${
Boost_INCLUDE_DIR
}
${
VSOMEIP_INCLUDE_DIRS
}
)
# Linking libraries to target
add_library
(
Some
ip
Adapter_tests_a_compA Some
ip
Adapter_tests_a_compA.cpp
)
target_link_libraries
(
Some
ip
Adapter_tests_a_compA vsomeip
${
Boost_LIBRARIES
}
)
add_library
(
Some
IP
Adapter_tests_a_compA Some
IP
Adapter_tests_a_compA.cpp
)
target_link_libraries
(
Some
IP
Adapter_tests_a_compA vsomeip
${
Boost_LIBRARIES
}
)
# Export target to a cmake module file for outside usage
export
(
TARGETS Some
ip
Adapter_tests_a_compA FILE Some
ip
Adapter_tests_a_compA.cmake
)
export
(
TARGETS Some
IP
Adapter_tests_a_compA FILE Some
IP
Adapter_tests_a_compA.cmake
)
someip_adapter/Some
ip
Adapter_tests_a_compA.cpp
→
someip_adapter/Some
IP
Adapter_tests_a_compA.cpp
View file @
1a4f7394
#include "Some
ip
Adapter_tests_a_compA.h"
#include "Some
IP
Adapter_tests_a_compA.h"
#define SAMPLE_SERVICE_ID 0x1234
#define SAMPLE_INSTANCE_ID 0x5678
...
...
@@ -12,42 +12,42 @@ std::shared_ptr<vsomeip::application> _clockSubscriber;
std
::
shared_ptr
<
vsomeip
::
application
>
_echoPublisher
;
Some
ip
Adapter_tests_a_compA
::
Some
ip
Adapter_tests_a_compA
()
{}
Some
IP
Adapter_tests_a_compA
::
Some
IP
Adapter_tests_a_compA
()
{}
void
Some
ip
Adapter_tests_a_compA
::
init
(
tests_a_compA
*
comp
)
void
Some
IP
Adapter_tests_a_compA
::
init
(
tests_a_compA
*
comp
)
{
this
->
component
=
comp
;
_clockSubscriber
=
vsomeip
::
runtime
::
get
()
->
create_application
(
"Subscriber"
);
_clockSubscriber
->
init
();
//_clockSubscriber->register_availability_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, on_availability);
_clockSubscriber
->
request_service
(
SAMPLE_SERVICE_ID
,
SAMPLE_INSTANCE_ID
);
_clockSubscriber
->
register_message_handler
(
SAMPLE_SERVICE_ID
,
SAMPLE_INSTANCE_ID
,
SAMPLE_METHOD_ID
,
std
::
bind
(
&
Some
ip
Adapter_tests_a_compA
::
on_message
,
this
,
std
::
placeholders
::
_1
));
_clockSubscriber
->
register_message_handler
(
SAMPLE_SERVICE_ID
,
SAMPLE_INSTANCE_ID
,
SAMPLE_METHOD_ID
,
std
::
bind
(
&
Some
IP
Adapter_tests_a_compA
::
on_message
,
this
,
std
::
placeholders
::
_1
));
//_clockSubscriber->register_message_handler(vsomeip::ANY_SERVICE, vsomeip::ANY_INSTANCE, vsomeip::ANY_METHOD, std::bind(&SomeipAdapter_tests_a_compA::on_message, this, std::placeholders::_1));
std
::
set
<
vsomeip
::
eventgroup_t
>
its_groups
;
its_groups
.
insert
(
SAMPLE_EVENTGROUP_ID
);
_clockSubscriber
->
request_event
(
SAMPLE_SERVICE_ID
,
SAMPLE_INSTANCE_ID
,
SAMPLE_EVENT_ID
,
its_groups
,
true
);
_clockSubscriber
->
subscribe
(
SAMPLE_SERVICE_ID
,
SAMPLE_INSTANCE_ID
,
SAMPLE_EVENTGROUP_ID
);
_clockSubscriber
->
start
();
_echoPublisher
=
vsomeip
::
runtime
::
get
()
->
create_application
(
"Publisher"
);
_echoPublisher
->
init
();
//_echoPublisher->register_message_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID, on_message);
_echoPublisher
->
offer_service
(
SAMPLE_SERVICE_ID
,
SAMPLE_INSTANCE_ID
);
_echoPublisher
->
start
();
}
void
Some
ip
Adapter_tests_a_compA
::
on_message
(
const
std
::
shared_ptr
<
vsomeip
::
message
>
&
_request
)
{
void
Some
IP
Adapter_tests_a_compA
::
on_message
(
const
std
::
shared_ptr
<
vsomeip
::
message
>
&
_request
)
{
std
::
shared_ptr
<
vsomeip
::
payload
>
its_payload
=
_request
->
get_payload
();
vsomeip
::
length_t
l
=
its_payload
->
get_length
();
double
dataFromMessage
=
*
((
double
*
)
its_payload
->
get_data
());
component
->
rosIn
=
dataFromMessage
;
std
::
cout
<<
"SERVICE: Received message from ["
...
...
@@ -56,28 +56,28 @@ void SomeipAdapter_tests_a_compA::on_message(const std::shared_ptr<vsomeip::mess
<<
dataFromMessage
<<
std
::
endl
;
}
void
Some
ip
Adapter_tests_a_compA
::
publish_echoPublisher
()
void
Some
IP
Adapter_tests_a_compA
::
publish_echoPublisher
()
{
double
d
=
component
->
rosOut
;
uint8_t
*
byteArray
=
(
uint8_t
*
)
&
d
;
vsomeip
::
byte_t
*
p
;
p
=
byteArray
;
p
=
byteArray
;
std
::
shared_ptr
<
vsomeip
::
payload
>
payload
=
vsomeip
::
runtime
::
get
()
->
create_payload
(
p
,
8
);
//const vsomeip::byte_t its_data[] = component->rosOut; //component->rosOut
//std::shared_ptr< vsomeip::payload > payload = vsomeip::runtime::get()->create_payload();
//payload->set_data(its_data, sizeof(its_data));
std
::
set
<
vsomeip
::
eventgroup_t
>
its_groups
;
its_groups
.
insert
(
SAMPLE_EVENTGROUP_ID
);
_echoPublisher
->
offer_event
(
SAMPLE_SERVICE_ID
,
SAMPLE_INSTANCE_ID
,
SAMPLE_EVENT_ID
,
its_groups
,
true
);
_echoPublisher
->
notify
(
SAMPLE_SERVICE_ID
,
SAMPLE_INSTANCE_ID
,
SAMPLE_EVENT_ID
,
payload
);
}
void
Some
ip
Adapter_tests_a_compA
::
tick
()
void
Some
IP
Adapter_tests_a_compA
::
tick
()
{
publish_echoPublisher
();
}
someip_adapter/Some
ip
Adapter_tests_a_compA.h
→
someip_adapter/Some
IP
Adapter_tests_a_compA.h
View file @
1a4f7394
...
...
@@ -11,22 +11,22 @@
using
namespace
std
;
class
Some
ip
Adapter_tests_a_compA
{
class
Some
IP
Adapter_tests_a_compA
{
public:
Some
ip
Adapter_tests_a_compA
();
Some
IP
Adapter_tests_a_compA
();
void
init
(
tests_a_compA
*
comp
);
void
publish_echoPublisher
();
void
tick
();
void
on_message
(
const
std
::
shared_ptr
<
vsomeip
::
message
>
&
_response
);
private:
tests_a_compA
*
component
=
nullptr
;
};
src/main/java/de/monticore/lang/monticar/generator/someip/GeneratorSomeIP.java
View file @
1a4f7394
...
...
@@ -20,18 +20,18 @@ public class GeneratorSomeIP {
// Get info about the ports from the component
Collection
<
EMAPortInstanceSymbol
>
ports
=
component
.
getPortInstanceList
();
// Create and fill model
SomeIPAdapterModel
model
=
new
SomeIPAdapterModel
(
component
.
getFullName
());
model
.
addPorts
(
ports
);
//Generate files and write to project
String
content
=
SomeIPTemplates
.
generateSomeIPAdapter
(
model
);
File
file
=
new
File
(
"./target/generated-sources/ports.txt"
);
files
.
add
(
file
);
FileWriter
fr
=
null
;
try
{
fr
=
new
FileWriter
(
file
);
...
...
@@ -49,4 +49,33 @@ public class GeneratorSomeIP {
return
files
;
}
File
generateCMake
(
EMAComponentInstanceSymbol
component
)
{
// Create and fill model
SomeIPAdapterModel
model
=
new
SomeIPAdapterModel
(
component
.
getFullName
());
//Generate files and write to project
String
content
=
SomeIPTemplates
.
generateSomeIPCMakeLists
(
model
);
File
file
=
new
File
(
"./target/generated-sources/CMakeLists.txt"
);
FileWriter
fr
=
null
;
try
{
fr
=
new
FileWriter
(
file
);
fr
.
write
(
content
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
//Close resources
try
{
fr
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
file
;
}
}
src/main/java/de/monticore/lang/monticar/generator/someip/template/SomeIPAdapterModel.java
View file @
1a4f7394
...
...
@@ -22,6 +22,14 @@ public class SomeIPAdapterModel {
return
compName
;
}
public
String
getEscapedCompName
()
{
return
compName
.
replace
(
'.'
,
'_'
)
.
replace
(
'['
,
'_'
)
.
replace
(
']'
,
'_'
);
}
// Parse through component to find information about its ports
public
void
addPorts
(
Collection
<
EMAPortInstanceSymbol
>
ports
)
{
...
...
src/main/java/de/monticore/lang/monticar/generator/someip/template/SomeIPTemplates.java
View file @
1a4f7394
package
de.monticore.lang.monticar.generator.someip.template
;
import
de.se_rwth.commons.logging.Log
;
import
freemarker.template.Configuration
;
import
freemarker.template.Template
;
import
freemarker.template.TemplateException
;
...
...
@@ -14,6 +15,7 @@ import java.util.Map;
public
class
SomeIPTemplates
{
private
static
final
Template
SOMEIP_PRETTYPRINT
;
private
static
final
Template
SOMEIP_CMAKELISTS
;
// Loading .ftl files
static
{
...
...
@@ -24,6 +26,7 @@ public class SomeIPTemplates {
conf
.
setClassForTemplateLoading
(
SomeIPTemplates
.
class
,
""
);
try
{
SOMEIP_PRETTYPRINT
=
conf
.
getTemplate
(
"PrettyPrint.ftl"
);
SOMEIP_CMAKELISTS
=
conf
.
getTemplate
(
"CMakeLists.ftl"
);
}
catch
(
IOException
e
)
{
String
msg
=
"could not load template"
;
Log
.
error
(
msg
,
e
);
...
...
@@ -38,6 +41,12 @@ public class SomeIPTemplates {
}
public
static
String
generateSomeIPCMakeLists
(
SomeIPAdapterModel
model
)
{
HashMap
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"model"
,
model
);
return
generate
(
SOMEIP_CMAKELISTS
,
data
);
}
@SuppressWarnings
(
"rawtypes"
)
private
static
String
generate
(
Template
template
,
Map
dataForTemplate
)
{
Log
.
errorIfNull
(
template
);
...
...
src/main/resources/de/monticore/lang/monticar/generator/someip/template/CMakeLists.ftl
0 → 100644
View file @
1a4f7394
<#--@formatter:off-->
# Setting cmake version
cmake_minimum_required (VERSION 2.8)
# Using C++ with flags
set (CMAKE_CXX_FLAGS "-g -std=c++0x")
# Find vsomeip and boost packages
find_package (vsomeip 2.10.0 REQUIRED)
find_package( Boost 1.55 COMPONENTS system thread log REQUIRED )
#include vsomeip and boost directories
include_directories (
<#noparse>${Boost_INCLUDE_DIR}</#noparse>
<#noparse>${VSOMEIP_INCLUDE_DIRS}</#noparse>
)
# Linking libraries to target
add_library(SomeIPAdapter_${model.getEscapedCompName()} SomeIPAdapter_${model.getEscapedCompName()}.cpp)
target_link_libraries(SomeipAdapter_${model.getEscapedCompName()} vsomeip <#noparse>${Boost_LIBRARIES}</#noparse>)
# Export target to a cmake module file for outside usage
export(TARGETS SomeIPAdapter_${model.getEscapedCompName()} FILE SomeIPAdapter_${model.getEscapedCompName()}.cmake)
src/test/java/de/monticore/lang/monticar/generator/someip/CMakeGenerationTest.java
0 → 100644
View file @
1a4f7394
package
de.monticore.lang.monticar.generator.someip
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.Test
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.tagging.middleware.someip.SomeIPConnectionSymbol
;
import
de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosToEmamTagSchema
;
import
de.monticore.lang.tagging._symboltable.TaggingResolver
;
public
class
CMakeGenerationTest
extends
AbstractSymtabTest
{
@Test
public
void
testCMake
()
throws
IOException
{
TaggingResolver
taggingResolver
=
createSymTabAndTaggingResolver
(
"src/test/resources/"
);
// Ros schema is used for now
RosToEmamTagSchema
.
registerTagTypes
(
taggingResolver
);
// Create component instance and run the generator
EMAComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
EMAComponentInstanceSymbol
>
resolve
(
"tests.a.compA"
,
EMAComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentInstanceSymbol
);
GeneratorSomeIP
generatorSomeIP
=
new
GeneratorSomeIP
();
// Connect component's ports to topics
componentInstanceSymbol
.
getPortInstance
(
"portA"
).
orElse
(
null
).
setMiddlewareSymbol
(
new
SomeIPConnectionSymbol
(
1
,
2
,
3
));
List
<
File
>
files
=
new
ArrayList
<>();
files
.
add
(
generatorSomeIP
.
generateCMake
(
componentInstanceSymbol
));
testFilesAreEqual
(
files
,
"echoCMake/"
);
}
}
src/test/resources/results/echoCMake/CMakeLists.txt
0 → 100644
View file @
1a4f7394
# Setting cmake version
cmake_minimum_required
(
VERSION 2.8
)
# Using C++ with flags
set
(
CMAKE_CXX_FLAGS
"-g -std=c++0x"
)
# Find vsomeip and boost packages
find_package
(
vsomeip 2.10.0 REQUIRED
)
find_package
(
Boost 1.55 COMPONENTS system thread log REQUIRED
)
#include vsomeip and boost directories
include_directories
(
${
Boost_INCLUDE_DIR
}
${
VSOMEIP_INCLUDE_DIRS
}
)
# Linking libraries to target
add_library
(
SomeIPAdapter_tests_a_compA SomeIPAdapter_tests_a_compA.cpp
)
target_link_libraries
(
SomeIPAdapter_tests_a_compA vsomeip
${
Boost_LIBRARIES
}
)
# Export target to a cmake module file for outside usage
export
(
TARGETS SomeIPAdapter_tests_a_compA FILE SomeIPAdapter_tests_a_compA.cmake
)
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