Commit 8bf76425 authored by Alexander David Hellwig's avatar Alexander David Hellwig

Merge branch '26-feedback' into 'master'

Apply feedback

Closes #26

See merge request !8
parents 86174607 aab24a9e
Pipeline #189025 passed with stage
in 42 seconds
......@@ -10,7 +10,11 @@ Get vsomeip from: https://github.com/GENIVI/vsomeip
Build instruction and further documentation is in the readme on the site, short summary of the install instruction:
- A C++11 enabled compiler like gcc >= 4.8 is needed.
- vsomeip uses CMake as buildsystem.
- vsomeip uses Boost (boost.org), version has to be >= 1.55 and < 1.66:
- vsomeip uses Boost (boost.org), version has to be >= 1.55 and < 1.66
A README can be found here: https://docs.projects.genivi.org/vSomeIP/
The complete documentation is not online, but it can be built manually (see "Build the documentation").
#### Install SOME/IP on Linux:
......@@ -52,6 +56,14 @@ One example which uses SOME/IP can be found in the example folder. Building it w
A docker image with installed vsomeip can be found in the container registry of this project. The docker image can also be produced by using the dockerfile in the docker folder.
## Tagging for Some/IP
Some/IP needs different integer IDs to create a publish/subscribe service. In this case, we use the ServiceID, the InstanceID and the EventgroupID. These can be chosen freely.
Tagging in general: {serviceID = [serviceID], instanceID = [instanceID], eventgroupID = [eventgroupID]}
Example: {serviceID = 1, instanceID = 123, eventgroupID = 42}
## Install and use the project
The SomeIP-Adapter can be installed and used with maven and java, using the command
......@@ -59,3 +71,4 @@ The SomeIP-Adapter can be installed and used with maven and java, using the comm
mvn clean install -s settings.xml
```
The project uses Freemarker template to produce the adapter files, which are built in target/generated-sources.
......@@ -10,11 +10,12 @@ ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV PATH $JAVA_HOME/bin:$PATH
#Install cmake, boost, maven, git
#Install cmake, boost, armadillo, maven, git
RUN apt-get update && apt-get -y install \
build-essential \
cmake \
libboost-system1.58-dev libboost-thread1.58-dev libboost-log1.58-dev \
liblapack-dev libblas-dev libarmadillo-dev \
maven \
git
......
cmake_minimum_required (VERSION 2.8)
set (CMAKE_CXX_FLAGS "-g -std=c++0x")
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}
)
add_executable(publisher ../src/publisher.cpp)
target_link_libraries(publisher vsomeip ${Boost_LIBRARIES})
add_executable(subscriber ../src/subscriber.cpp)
target_link_libraries(subscriber vsomeip ${Boost_LIBRARIES})
/* (c) https://github.com/MontiCore/monticore */
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vsomeip/vsomeip.hpp>
#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;
void 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 final = *((double*)its_payload->get_data());
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;
}
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();
}
/* (c) https://github.com/MontiCore/monticore */
#include <iomanip>
#include <iostream>
#include <sstream>
#include <condition_variable>
#include <thread>
#include <vsomeip/vsomeip.hpp>
#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;
std::condition_variable condition;
void run() {
std::unique_lock<std::mutex> its_lock(mutex);
condition.wait(its_lock);
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> &_request) {
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());
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) {
std::cout << "CLIENT: Service ["
<< std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance
<< "] is "
<< (_is_available ? "available." : "NOT available.")
<< std::endl;
condition.notify_one();
}
int main() {
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(vsomeip::ANY_SERVICE, vsomeip::ANY_INSTANCE, vsomeip::ANY_METHOD, on_message);
std::thread sender(run);
app->start();
}
......@@ -7,7 +7,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-emam2someip-generator</artifactId>
<version>1.1-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
<name>emam2someip</name>
......
......@@ -3,9 +3,10 @@ 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.embeddedmontiarc.tagging.middleware.someip.SomeIPConnectionSymbol;
import de.monticore.lang.monticar.generator.someip.template.SomeIPAdapterModel;
import de.monticore.lang.monticar.generator.someip.template.SomeIPTemplates;
import de.monticore.lang.monticar.generator.someip.helper.FilesHelper;
import java.io.File;
import java.io.FileWriter;
......@@ -20,17 +21,12 @@ public class GeneratorSomeIP {
public void setGenerationTargetPath(String generationTargetPath) {
this.generationTargetPath = generationTargetPath.endsWith("/") ? generationTargetPath : generationTargetPath + "/";
File directory = new File(generationTargetPath);
directory.mkdirs();
}
public List<File> generateSomeIPAdapter(EMAComponentInstanceSymbol component) {
List<FilesHelper> generateList = new ArrayList<>();
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());
......@@ -38,32 +34,21 @@ public class GeneratorSomeIP {
model.addPorts(component.getPortInstanceList());
//Generate files and write to project
contents.add(SomeIPTemplates.generateSomeIPAdapterH(model));
files.add(new File(generationTargetPath + "SomeIPAdapter_" + model.getEscapedCompName() + ".h"));
contents.add(SomeIPTemplates.generateSomeIPAdapterCPP(model));
files.add(new File(generationTargetPath + "SomeIPAdapter_" + model.getEscapedCompName() + ".cpp"));
try {
int counter = 0;
for (File file : files)
{
frs.add(new FileWriter(file));
frs.get(counter).write(contents.get(counter));
counter++;
}
} catch (IOException e) {
e.printStackTrace();
}finally{
//Close resources
try {
for (FileWriter fr : frs)
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
files.add(generateCMake(component));
generateList.add(new FilesHelper(new File(generationTargetPath+"SomeIPAdapter_" + model.getEscapedCompName() + ".h"), SomeIPTemplates.generateSomeIPAdapterH(model)));
generateList.add(new FilesHelper(new File(generationTargetPath+"SomeIPAdapter_" + model.getEscapedCompName() + ".cpp"), SomeIPTemplates.generateSomeIPAdapterCPP(model)));
//If file directory does not exist, create it so files can be created
File directory = new File(generationTargetPath);
directory.mkdirs();
for (FilesHelper filesHelper : generateList) {
createFile(filesHelper.getFile(), filesHelper.getContent());
files.add(filesHelper.getFile());
}
files.add(generateCMake(component));
return files;
......@@ -97,8 +82,7 @@ public class GeneratorSomeIP {
return file;
}
public List<File> generatePrettyPrint(EMAComponentInstanceSymbol component)
{
public List<File> generatePrettyPrint(EMAComponentInstanceSymbol component) {
List<File> files = new ArrayList<>();
// Get info about the ports from the component
......@@ -132,8 +116,23 @@ public class GeneratorSomeIP {
return files;
}
}
private void createFile(File file, String content) {
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();
}
}
}
}
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.generator.someip.helper;
import java.io.File;
public class FilesHelper {
private File file;
private String content;
public FilesHelper(File file, String content) {
this.file = file;
this.content = content;
}
public File getFile(){
return file;
}
public String getContent(){
return content;
}
}
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