Commit d20b02e1 authored by Alexander David Hellwig's avatar Alexander David Hellwig

Merge branch '16-add-basic-adapter-generation' into 'master'

Resolve "Add basic Adapter Generation"

See merge request !2
parents 508982a2 998c4a13
Pipeline #160489 passed with stages
in 1 minute and 33 seconds
stages:
- linux
- project
- adapter
BranchJobLinux:
stage: linux
BranchJobProject:
stage: project
image: registry.git.rwth-aachen.de/monticore/embeddedmontiarc/generators/emam2someip
script:
- mvn clean install -s settings.xml
except:
- master
BranchJobAdapter:
stage: adapter
image: registry.git.rwth-aachen.de/monticore/embeddedmontiarc/generators/emam2someip
script:
- cd someip_adapter
- cmake .
- make
except:
- master
# Use an official Python runtime as a parent image
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get -y install build-essential
RUN apt-get -y install cmake
RUN apt-get -y install libboost-system1.58-dev libboost-thread1.58-dev libboost-log1.58-dev
RUN apt-get update \
&& apt-get -y install openjdk-8-jdk \
&& rm -rf /var/lib/apt/lists/*
......@@ -17,25 +9,20 @@ ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV PATH $JAVA_HOME/bin:$PATH
RUN apt-get update
RUN apt-get -y install maven
RUN apt-get -y install git
RUN mkdir /usr/src/emam2someip
RUN apt-get update && apt-get -y install \
build-essential \
cmake \
libboost-system1.58-dev libboost-thread1.58-dev libboost-log1.58-dev \
maven \
git
WORKDIR /usr/src/emam2someip
#clone and build vsomeip
RUN git clone https://github.com/GENIVI/vsomeip.git
#copy example
COPY . /usr/src/emam2someip
WORKDIR /usr/src/emam2someip/vsomeip
RUN mkdir /usr/src/emam2someip/vsomeip/build
WORKDIR /usr/src/emam2someip/vsomeip/build
RUN cmake ..
......@@ -48,10 +35,14 @@ WORKDIR /usr/src/emam2someip/vsomeip
RUN rm -rf build
#copy example and adapter
COPY . /usr/src/emam2someip
#build example
WORKDIR /usr/src/emam2someip/example/build
RUN cmake ..
RUN make
WORKDIR /usr/src/emam2someip/
......@@ -10,6 +10,8 @@
#define SAMPLE_SERVICE_ID 0x1234
#define SAMPLE_INSTANCE_ID 0x5678
#define SAMPLE_METHOD_ID 0x0421
#define SAMPLE_EVENT_ID 0x2345
#define SAMPLE_EVENTGROUP_ID 0x1456
std::shared_ptr< vsomeip::application > app;
std::mutex mutex;
......@@ -19,39 +21,24 @@ void run() {
std::unique_lock<std::mutex> its_lock(mutex);
condition.wait(its_lock);
std::shared_ptr< vsomeip::message > request;
request = vsomeip::runtime::get()->create_request();
request->set_service(SAMPLE_SERVICE_ID);
request->set_instance(SAMPLE_INSTANCE_ID);
request->set_method(SAMPLE_METHOD_ID);
double d = 2.5;
uint8_t *byteArray = (uint8_t*)&d;
vsomeip::byte_t *p;
p = byteArray;
std::shared_ptr< vsomeip::payload > its_payload = vsomeip::runtime::get()->create_payload(p,8);
request->set_payload(its_payload);
app->send(request, true);
std::set<vsomeip::eventgroup_t> its_groups;
its_groups.insert(SAMPLE_EVENTGROUP_ID);
app->request_event(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENT_ID, its_groups, true);
app->subscribe(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENTGROUP_ID);
}
void on_message(const std::shared_ptr<vsomeip::message> &_response) {
void on_message(const std::shared_ptr<vsomeip::message> &_request) {
std::shared_ptr<vsomeip::payload> its_payload = _response->get_payload();
vsomeip::length_t l = its_payload->get_length();
std::shared_ptr<vsomeip::payload> its_payload = _request->get_payload();
vsomeip::length_t l = its_payload->get_length();
double final = *((double*)its_payload->get_data());
// Get payload
std::stringstream ss;
for (vsomeip::length_t i=0; i<l; i++) {
ss << std::setw(2) << std::setfill('0') << std::hex
<< (int)*(its_payload->get_data()+i) << " ";
}
std::cout << "CLIENT: Received message with Client/Session ["
<< std::setw(4) << std::setfill('0') << std::hex << _response->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex << _response->get_session() << "] "
<< ss.str() << std::endl;
std::cout << "SERVICE: Received message from ["
<< std::setw(4) << std::setfill('0') << std::hex << _request->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex << _request->get_session() << "]: "
<< final << std::endl;
}
void on_availability(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available) {
......@@ -65,11 +52,14 @@ void on_availability(vsomeip::service_t _service, vsomeip::instance_t _instance,
int main() {
app = vsomeip::runtime::get()->create_application("Subscriber");
app = vsomeip::runtime::get()->create_application("Hello");
app->init();
app->register_availability_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, on_availability);
app->request_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
app->register_message_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID, on_message);
app->register_message_handler(vsomeip::ANY_SERVICE, vsomeip::ANY_INSTANCE, vsomeip::ANY_METHOD, on_message);
std::thread sender(run);
app->start();
}
......@@ -7,6 +7,8 @@
#define SAMPLE_SERVICE_ID 0x1234
#define SAMPLE_INSTANCE_ID 0x5678
#define SAMPLE_METHOD_ID 0x0421
#define SAMPLE_EVENT_ID 0x2345
#define SAMPLE_EVENTGROUP_ID 0x1456
std::shared_ptr<vsomeip::application> app;
......@@ -17,7 +19,7 @@ void on_message(const std::shared_ptr<vsomeip::message> &_request) {
double final = *((double*)its_payload->get_data());
std::cout << "SERVICE: Received message with Client/Session ["
std::cout << "SERVICE: Received message from ["
<< std::setw(4) << std::setfill('0') << std::hex << _request->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex << _request->get_session() << "]: "
<< final << std::endl;
......@@ -28,6 +30,21 @@ int main() {
app = vsomeip::runtime::get()->create_application("Publisher");
app->init();
app->register_message_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID, on_message);
double d = 2.5;
uint8_t *byteArray = (uint8_t*)&d;
vsomeip::byte_t *p;
p = byteArray;
std::shared_ptr< vsomeip::payload > its_payload = vsomeip::runtime::get()->create_payload(p,8);
std::set<vsomeip::eventgroup_t> its_groups;
its_groups.insert(SAMPLE_EVENTGROUP_ID);
app->offer_event(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENT_ID, its_groups, true);
app->notify(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENT_ID, its_payload);
app->offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
app->start();
}
# Setting cmake version
cmake_minimum_required (VERSION 2.8)
# Using C++ version 11 with threads for compiling
set (CMAKE_CXX_FLAGS "-g -std=c++0x")
# Find packages and include directories
find_package (vsomeip 2.10.0 REQUIRED)
find_package( Boost 1.55 COMPONENTS system thread log REQUIRED )
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)
......@@ -6,6 +6,8 @@
#define SAMPLE_EVENT_ID 0x2345
#define SAMPLE_EVENTGROUP_ID 0x1456
tests_a_compA* component;
std::shared_ptr<vsomeip::application> _clockSubscriber;
std::shared_ptr<vsomeip::application> _echoPublisher;
......@@ -14,14 +16,15 @@ SomeipAdapter_tests_a_compA::SomeipAdapter_tests_a_compA() {}
void SomeipAdapter_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->register_availability_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, on_availability);
_clockSubscriber->request_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
_clockSubscriber->register_message_handler(vsomeip::ANY_SERVICE, vsomeip::ANY_INSTANCE, vsomeip::ANY_METHOD, on_message);
std::unique_lock<std::mutex> its_lock(mutex);
_clockSubscriber->register_message_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID, std::bind(&SomeipAdapter_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);
......@@ -29,6 +32,13 @@ void SomeipAdapter_tests_a_compA::init(tests_a_compA *comp)
_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 SomeipAdapter_tests_a_compA::on_message(const std::shared_ptr<vsomeip::message> &_request) {
......@@ -36,46 +46,38 @@ void SomeipAdapter_tests_a_compA::on_message(const std::shared_ptr<vsomeip::mess
std::shared_ptr<vsomeip::payload> its_payload = _request->get_payload();
vsomeip::length_t l = its_payload->get_length();
double final = *((double*)its_payload->get_data());
double dataFromMessage = *((double*)its_payload->get_data());
component->rosIn = dataFromMessage;
std::cout << "SERVICE: Received message with Client/Session ["
std::cout << "SERVICE: Received message from ["
<< std::setw(4) << std::setfill('0') << std::hex << _request->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex << _request->get_session() << "]: "
<< final << std::endl;
}
void SomeipAdapter_tests_a_compA::on_availability(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available) {
std::cout << "CLIENT: Service ["
<< std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance
<< "] is "
<< (_is_available ? "available." : "NOT available.")
<< std::endl;
<< dataFromMessage << std::endl;
}
void SomeipAdapter_tests_a_compA::publish_echoPublisher()
{
_echoPublisher = vsomeip::runtime::get()->create_application("Publisher");
_echoPublisher->init();
//app->register_message_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID, on_message);
double d = component->rosOut;
uint8_t *byteArray = (uint8_t*)&d;
vsomeip::byte_t *p;
p = byteArray;
std::shared_ptr< vsomeip::payload > payload = vsomeip::runtime::get()->create_payload(p,8);
double d = 2.5;
uint8_t *byteArray = (uint8_t*)&d;
vsomeip::byte_t *p;
p = byteArray;
std::shared_ptr< vsomeip::payload > its_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, its_payload);
_echoPublisher->offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
_echoPublisher->start();
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 SomeipAdapter_tests_a_compA::tick()
{
publish_echoPublisher();
}
......@@ -23,9 +23,7 @@ public:
void tick();
static void on_message(const std::shared_ptr<vsomeip::message> &_response);
static void on_availability(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available);
void on_message(const std::shared_ptr<vsomeip::message> &_response);
private:
......
#ifndef tests_a_compA_h
#define tests_a_compA_h
#include <iostream>
using namespace std;
class tests_a_compA {
public:
double rosIn = 2.5;
double rosOut = 3.14;
};
#endif /* tests_a_compA_h */
......@@ -9,7 +9,7 @@
<version>1.0-SNAPSHOT</version>
<name>emam2someip</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
......@@ -46,6 +46,13 @@
<dependencies>
<dependency>
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc</artifactId>
<!-- or newer version -->
<version>0.1.11-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>de.se_rwth.commons</groupId>
<artifactId>se-commons-logging</artifactId>
......@@ -117,7 +124,7 @@
<target>${java.version}</target>
</configuration>
</plugin>
<!-- Test coverage -->
<plugin>
<groupId>org.jacoco</groupId>
......@@ -203,5 +210,5 @@
<url>https://nexus.se.rwth-aachen.de/content/repositories/embeddedmontiarc-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
# Setting cmake version
cmake_minimum_required (VERSION 3.12)
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")
# Setting project name and description
project(SomeipAdapter VERSION 1.0
DESCRIPTION "Someip adapter"
LANGUAGES CXX)
# Find packages and include directories
# 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})
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)
export(TARGETS SomeIPAdapter_tests_a_compA FILE SomeIPAdapter_tests_a_compA.cmake)
#include "SomeIPAdapter_tests_a_compA.h"
SomeIPAdapter_tests_a_compA::SomeIPAdapter_tests_a_compA() {
//choose random ids
service_id = 1;
instance_id = 2;
method_id = 3;
event_id = 4;
eventgroup_id = 5;
}
SomeIPAdapter_tests_a_compA::SomeIPAdapter_tests_a_compA(int service_id, int instance_id, int method_id, int event_id, int eventgroup_id) {
this->service_id = service_id;
this->instance_id = instance_id;
this->method_id = method_id;
this->event_id = event_id;
this->eventgroup_id = eventgroup_id;
}
void SomeIPAdapter_tests_a_compA::init(tests_a_compA *comp) {
// Initialize component
this->component = comp;
// Intitialize subscriber
_clockSubscriber = vsomeip::runtime::get()->create_application("Subscriber");
_clockSubscriber->init();
_clockSubscriber->request_service(service_id, instance_id);
_clockSubscriber->register_message_handler(service_id, instance_id, method_id, std::bind(&SomeIPAdapter_tests_a_compA::on_message, this, std::placeholders::_1));
// Subscribe
std::set<vsomeip::eventgroup_t> event_group;
event_group.insert(eventgroup_id);
_clockSubscriber->request_event(service_id, instance_id, event_id, event_group, true);
_clockSubscriber->subscribe(service_id, instance_id, eventgroup_id);
_clockSubscriber->start();
// Intitialize Publisher
_echoPublisher = vsomeip::runtime::get()->create_application("Publisher");
_echoPublisher->init();
_echoPublisher->offer_service(service_id, instance_id);
_echoPublisher->start();
}
void SomeIPAdapter_tests_a_compA::on_message(const std::shared_ptr<vsomeip::message> &_request) {
//read received message
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->someIPIn = dataFromMessage;
//print data to std out
std::cout << "SERVICE: Received message from ["
<< std::setw(4) << std::setfill('0') << std::hex << _request->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex << _request->get_session() << "]: "
<< dataFromMessage << std::endl;
}
void SomeIPAdapter_tests_a_compA::publish_echoPublisher()
{
//Read data from component
double d = component->someIPOut;
//Create message
uint8_t *byteArray = (uint8_t*)&d;
vsomeip::byte_t *p;
p = byteArray;
std::shared_ptr< vsomeip::payload > payload = vsomeip::runtime::get()->create_payload(p,8);
//Publish
std::set<vsomeip::eventgroup_t> event_group;
event_group.insert(eventgroup_id);
_echoPublisher->offer_event(service_id, instance_id, event_id, event_group, true);
_echoPublisher->notify(service_id, instance_id, event_id, payload);
}
void SomeIPAdapter_tests_a_compA::tick()
{
publish_echoPublisher();
}
#pragma once
#include "tests_a_compA.h"
#include <iomanip>
#include <iostream>
#include <sstream>
#include <condition_variable>
#include <thread>
#include <vsomeip/vsomeip.hpp>
using namespace std;
class SomeIPAdapter_tests_a_compA {
public:
SomeIPAdapter_tests_a_compA();
SomeIPAdapter_tests_a_compA(int service_id, int instance_id, int method_id, int event_id, int eventgroup_id);
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;
std::shared_ptr<vsomeip::application> _clockSubscriber;
std::shared_ptr<vsomeip::application> _echoPublisher;
int service_id;
int instance_id;
int method_id;
int event_id;
int eventgroup_id;
};
#include <stdio.h>
#include "tests_a_compA.h"
tests_a_compA::tests_a_compA(double value)
{
someIPOut = value;
}
......@@ -6,10 +6,11 @@
using namespace std;
class tests_a_compA {
public:
double rosIn = 0;
double rosOut = 0;
tests_a_compA(double value);
double someIPIn = 2.5;
double someIPOut = 3.14;
};
#endif /* tests_a_compA_h */
package de.monticore.lang.monticar.generator.someip;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAPortInstanceSymbol;
//import de.monticore.lang.embeddedmontiarc.tagging.middleware.someip.SomeIPConnectionSymbol;
import de.monticore.lang.monticar.generator.someip.template.SomeIPAdapterModel;
import de.monticore.lang.monticar.generator.someip.template.SomeIPTemplates;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class GeneratorSomeIP {
List<File> generateSomeIPAdapter(EMAComponentInstanceSymbol component) {
List<File> files = new ArrayList<>();
List<String> contents = new ArrayList<String>();
List<FileWriter> frs = new ArrayList<FileWriter>();
// Create and fill model
SomeIPAdapterModel model = new SomeIPAdapterModel(component.getFullName());
model.addPorts(component.getPortInstanceList());
//Generate files and write to project
contents.add(SomeIPTemplates.generateSomeIPAdapterH(model));