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

Merge branch '18-fix-subscribers-publishers-someip-2' into 'master'

Resolve "Fix Subscribers/Publishers(SomeIP)"

Closes #18

See merge request !7
parents 00c16ca6 abafe36a
Pipeline #188875 passed with stages
in 1 minute and 49 seconds
......@@ -49,6 +49,66 @@ public class SomeIPAdapterModel {
outgoing = outgoing.stream().filter(fc -> fc.isSomeIPPort()).filter(fc -> fc.isOutgoing()).collect(Collectors.toList());
}
public int getServiceId(EMAPortInstanceSymbol p)
{
Optional<MiddlewareSymbol> symbol = p.getMiddlewareSymbol();
if(symbol.isPresent() && symbol.get().isKindOf(SomeIPConnectionKind.INSTANCE))
{
SomeIPConnectionSymbol sym = (SomeIPConnectionSymbol) symbol.get();
int serviceID = sym.getserviceID().isPresent()?sym.getserviceID().get():-1;
return serviceID;
}
return -1;
}
public int getInstanceId(EMAPortInstanceSymbol p)
{
Optional<MiddlewareSymbol> symbol = p.getMiddlewareSymbol();
if(symbol.isPresent() && symbol.get().isKindOf(SomeIPConnectionKind.INSTANCE))
{
SomeIPConnectionSymbol sym = (SomeIPConnectionSymbol) symbol.get();
int instanceID = sym.getinstanceID().isPresent()?sym.getinstanceID().get():-1;
return instanceID;
}
return -1;
}
public int getEventGroupId(EMAPortInstanceSymbol p)
{
Optional<MiddlewareSymbol> symbol = p.getMiddlewareSymbol();
if(symbol.isPresent() && symbol.get().isKindOf(SomeIPConnectionKind.INSTANCE))
{
SomeIPConnectionSymbol sym = (SomeIPConnectionSymbol) symbol.get();
int eventgroupID = sym.geteventgroupID().isPresent()?sym.geteventgroupID().get():-1;
return eventgroupID;
}
return -1;
}
public int getEventId(EMAPortInstanceSymbol p)
{
Optional<MiddlewareSymbol> symbol = p.getMiddlewareSymbol();
if(symbol.isPresent() && symbol.get().isKindOf(SomeIPConnectionKind.INSTANCE))
{
SomeIPConnectionSymbol sym = (SomeIPConnectionSymbol) symbol.get();
int eventID = 0;//sym.geteventID().isPresent()?sym.geteventID().get():-1;
return eventID;
}
return -1;
}
public int getMethodId(EMAPortInstanceSymbol p)
{
Optional<MiddlewareSymbol> symbol = p.getMiddlewareSymbol();
if(symbol.isPresent() && symbol.get().isKindOf(SomeIPConnectionKind.INSTANCE))
{
SomeIPConnectionSymbol sym = (SomeIPConnectionSymbol) symbol.get();
int methodID = 0;//sym.getmethodID().isPresent()?sym.getmethodID().get():-1;
return methodID;
}
return -1;
}
// Parse through component to find information about its ports
public void addPortsDesc(Collection<EMAPortInstanceSymbol> ports)
{
......
......@@ -3,141 +3,138 @@
#include "<@m.mwIdent/>Adapter_${model.getEscapedCompName()}.h"
<@m.mwIdent/>Adapter_${model.getEscapedCompName()}::<@m.mwIdent/>Adapter_${model.getEscapedCompName()}() : public IAdapter_${model.getEscapedCompName()} {
//choose random ids
in1_service_id = 11;
in1_instance_id = 12;
in1_method_id = 13;
in1_event_id = 14;
in1_eventgroup_id = 15;
in2_service_id = 21;
in2_instance_id = 22;
in2_method_id = 23;
in2_event_id = 24;
in2_eventgroup_id = 25;
out1_service_id = 111;
out1_instance_id = 112;
out1_method_id = 113;
out1_event_id = 114;
out1_eventgroup_id = 115;
out2_service_id = 121;
out2_instance_id = 122;
out2_method_id = 123;
out2_event_id = 124;
out2_eventgroup_id = 125;
}
void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::init(${model.getEscapedCompName()} *comp) {
// Initialize component
this->component = comp;
// Intitialize subscriber for in1
in1_Subscriber = vsomeip::runtime::get()->create_application("Subscriber");
in1_Subscriber->init();
in1_Subscriber->request_service(in1_service_id, in1_instance_id);
in1_Subscriber->register_message_handler(in1_service_id, in1_instance_id, in1_method_id, std::bind(&SomeIPAdapter_${model.getEscapedCompName()}::on_message_in1, this, std::placeholders::_1));
// Subscribe
std::set<vsomeip::eventgroup_t> in1_event_group;
in1_event_group.insert(in1_eventgroup_id);
in1_Subscriber->request_event(in1_service_id, in1_instance_id, in1_event_id, in1_event_group, true);
in1_Subscriber->subscribe(in1_service_id, in1_instance_id, in1_eventgroup_id);
in1_Subscriber->start();
// Intitialize subscriber for in2
in2_Subscriber = vsomeip::runtime::get()->create_application("Subscriber");
in2_Subscriber->init();
in2_Subscriber->request_service(in2_service_id, in2_instance_id);
in2_Subscriber->register_message_handler(in2_service_id, in2_instance_id, in2_method_id, std::bind(&SomeIPAdapter_${model.getEscapedCompName()}::on_message_in2, this, std::placeholders::_1));
// Subscribe
std::set<vsomeip::eventgroup_t> in2_event_group;
in2_event_group.insert(in2_eventgroup_id);
in2_Subscriber->request_event(in2_service_id, in2_instance_id, in2_event_id, in2_event_group, true);
in2_Subscriber->subscribe(in2_service_id, in2_instance_id, in2_eventgroup_id);
in2_Subscriber->start();
// Intitialize Publisher for out1
out1_Publisher = vsomeip::runtime::get()->create_application("Publisher");
out1_Publisher->init();
out1_Publisher->offer_service(out1_service_id, out1_instance_id);
out1_Publisher->start();
// Intitialize Publisher for out2
out2_Publisher = vsomeip::runtime::get()->create_application("Publisher");
out2_Publisher->init();
out2_Publisher->offer_service(out2_service_id, out2_instance_id);
out2_Publisher->start();
// Intitialize Subscriber
<#list model.getIncomingPorts() as sub>
${sub.getName()}_Subscriber = vsomeip::runtime::get()->create_application("Subscriber ${sub.getName()}");
if (!${sub.getName()}_Subscriber->init()) {
std::cerr << "Couldn't initialize Subscriber ${sub.getName()}" << std::endl;
}
${sub.getName()}_Subscriber->register_availability_handler(${model.getServiceId(sub)}, ${model.getInstanceId(sub)}, std::bind(&SomeIPAdapter_${model.getEscapedCompName()}::on_availability_${sub.getName()}, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
${sub.getName()}_Subscriber->request_service(${model.getServiceId(sub)}, ${model.getInstanceId(sub)});
${sub.getName()}_Subscriber->register_message_handler(${model.getServiceId(sub)}, ${model.getInstanceId(sub)}, ${model.getMethodId(sub)}, std::bind(&SomeIPAdapter_${model.getEscapedCompName()}::on_message_${sub.getName()}, this, std::placeholders::_1));
std::thread sender_${sub.getName()}(std::bind(&SomeIPAdapter_${model.getEscapedCompName()}::run_${sub.getName()}, this));
${sub.getName()}_Subscriber->start();
</#list>
// Intitialize Publisher
<#list model.getOutgoingPorts() as pub>
${pub.getName()}_Publisher = vsomeip::runtime::get()->create_application("Publisher ${pub.getName()}");
if (!${pub.getName()}_Publisher->init()) {
std::cerr << "Couldn't initialize Publisher ${pub.getName()}" << std::endl;
}
${pub.getName()}_Publisher->offer_service(${model.getServiceId(pub)}, ${model.getInstanceId(pub)});
${pub.getName()}_Publisher->start();
</#list>
}
void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::on_message_in1(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->in1 = 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;
<#list model.getIncomingPorts() as sub>
void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::run_${sub.getName()}() {
std::unique_lock<std::mutex> its_lock(mutex_${sub.getName()});
condition_${sub.getName()}.wait(its_lock);
std::set<vsomeip::eventgroup_t> event_group;
event_group.insert(${model.getEventGroupId(sub)});
${sub.getName()}_Subscriber->request_event(${model.getServiceId(sub)}, ${model.getInstanceId(sub)}, ${model.getEventId(sub)}, event_group, true);
${sub.getName()}_Subscriber->subscribe(${model.getServiceId(sub)}, ${model.getInstanceId(sub)}, ${model.getEventGroupId(sub)});
}
void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::on_message_in2(const std::shared_ptr<vsomeip::message> &_request) {
void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::on_message_${sub.getName()}(const std::shared_ptr<vsomeip::message> &_message) {
//read received message
std::shared_ptr<vsomeip::payload> its_payload = _request->get_payload();
std::shared_ptr<vsomeip::payload> its_payload = _message->get_payload();
vsomeip::length_t l = its_payload->get_length();
double dataFromMessage = *((double*)its_payload->get_data());
component->in2 = dataFromMessage;
<#switch sub.getTypeReference().getName()>
<#case "Q">
// double
component->${sub.getName()} = dataFromMessage;
<#break>
<#case "N">
//int
component->${sub.getName()} = (int) round(dataFromMessage);
<#break>
<#case "Z">
//int
component->${sub.getName()} = (int) round(dataFromMessage);
<#break>
<#case "B">
//bool
component->${sub.getName()} = (dataFromMessage > 1.0e-10);
<#break>
<#default>
//error
</#switch>
//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;
std::cout << "SERVICE ${sub.getName()}: Received message from ["
<< std::setw(4) << std::setfill('0') << std::hex << _message->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex << _message->get_session() << "]: "
<< dataFromMessage << std::endl;
}
void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::publishout1_Publisher()
{
//Read data from component
double d = component->out1;
//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> out1_event_group;
out1_event_group.insert(out1_eventgroup_id);
out1_Publisher->offer_event(out1_service_id, out1_instance_id, out1_event_id, out1_event_group, true);
out1_Publisher->notify(out1_service_id, out1_instance_id, out1_event_id, payload);
void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::on_availability_${sub.getName()}(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available) {
std::cout << "Service ["
<< std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance
<< "] is "
<< (_is_available ? "available." : "NOT available.")
<< std::endl;
condition_${sub.getName()}.notify_one();
}
</#list>
void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::publishout2_Publisher()
{
//Read data from component
double d = component->out2;
//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);
<#list model.getOutgoingPorts() as pub>
void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::publish${pub.getName()}_Publisher()
{
//Read data from component
<#switch pub.getTypeReference().getName()>
<#case "Q">
// double
double d = component->${pub.getName()};
<#break>
<#case "N">
//int
double d = 1.0 * component->${pub.getName()};
<#break>
<#case "Z">
//int
double d = 1.0 * component->${pub.getName()};
<#break>
<#case "B">
//bool
double d = component->${pub.getName()} ? 1.0 : 0.0;
<#break>
<#default>
//error
</#switch>
const vsomeip::byte_t its_data[] = { (uint8_t) d };
std::shared_ptr<vsomeip::payload> payload = vsomeip::runtime::get()->create_payload();
payload->set_data(its_data, sizeof(its_data));
//Publish
std::set<vsomeip::eventgroup_t> out2_event_group;
out2_event_group.insert(out2_eventgroup_id);
out2_Publisher->offer_event(out2_service_id, out2_instance_id, out2_event_id, out2_event_group, true);
out2_Publisher->notify(out2_service_id, out2_instance_id, out2_event_id, payload);
std::set<vsomeip::eventgroup_t> event_group;
event_group.insert(${model.getEventGroupId(pub)});
${pub.getName()}_Publisher->offer_event(${model.getServiceId(pub)}, ${model.getInstanceId(pub)}, ${model.getEventId(pub)}, event_group, true);
${pub.getName()}_Publisher->notify(${model.getServiceId(pub)}, ${model.getInstanceId(pub)}, ${model.getEventId(pub)}, payload);
}
</#list>
void <@m.mwIdent/>Adapter_${model.getEscapedCompName()}::tick()
{
publishout1_Publisher();
publishout2_Publisher();
<#list model.getOutgoingPorts() as pub>
publish${pub.getName()}_Publisher();
</#list>
}
......@@ -3,7 +3,6 @@
#pragma once
#include "${model.getEscapedCompName()}.h"
#include "IAdapter_${model.getEscapedCompName()}.h"
#include <iomanip>
#include <iostream>
#include <sstream>
......@@ -12,6 +11,7 @@
#include <thread>
#include <vsomeip/vsomeip.hpp>
#include <math.h>
using namespace std;
......@@ -23,14 +23,6 @@ public:
void init(${model.getEscapedCompName()} *comp);
void on_message_in1(const std::shared_ptr<vsomeip::message> &_request);
void on_message_in2(const std::shared_ptr<vsomeip::message> &_request);
void publishout1_Publisher();
void publishout2_Publisher();
void tick();
......@@ -38,35 +30,19 @@ private:
${model.getEscapedCompName()}* component = nullptr;
std::shared_ptr<vsomeip::application> in1_Subscriber;
std::shared_ptr<vsomeip::application> in2_Subscriber;
std::shared_ptr<vsomeip::application> out1_Publisher;
std::shared_ptr<vsomeip::application> out2_Publisher;
int in1_service_id;
int in1_instance_id;
int in1_method_id;
int in1_event_id;
int in1_eventgroup_id;
<#list model.getIncomingPorts() as sub>
std::shared_ptr<vsomeip::application> ${sub.getName()}_Subscriber;
std::mutex mutex_${sub.getName()};
std::condition_variable condition_${sub.getName()};
int in2_service_id;
int in2_instance_id;
int in2_method_id;
int in2_event_id;
int in2_eventgroup_id;
void run_${sub.getName()}();
void on_message_${sub.getName()}(const std::shared_ptr<vsomeip::message> &_message);
void on_availability_${sub.getName()}(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available);
</#list>
int out1_service_id;
int out1_instance_id;
int out1_method_id;
int out1_event_id;
int out1_eventgroup_id;
<#list model.getOutgoingPorts() as pub>
std::shared_ptr<vsomeip::application> ${pub.getName()}_Publisher;
int out2_service_id;
int out2_instance_id;
int out2_method_id;
int out2_event_id;
int out2_eventgroup_id;
void publish${pub.getName()}_Publisher();
</#list>
};
......@@ -34,7 +34,10 @@ public class AdapterGenerationTest extends AbstractSymtabTest {
generatorSomeIP.setGenerationTargetPath("./target/generated-sources/");
// Connect component's ports to topics
componentInstanceSymbol.getPortInstance("in1").orElse(null).setMiddlewareSymbol(new SomeIPConnectionSymbol(1,2,3));
componentInstanceSymbol.getPortInstance("in1").orElse(null).setMiddlewareSymbol(new SomeIPConnectionSymbol(11,12,13/*,14,15*/));
componentInstanceSymbol.getPortInstance("in2").orElse(null).setMiddlewareSymbol(new SomeIPConnectionSymbol(21,22,23/*,24,25*/));
componentInstanceSymbol.getPortInstance("out1").orElse(null).setMiddlewareSymbol(new SomeIPConnectionSymbol(111,112,113/*,114,115*/));
componentInstanceSymbol.getPortInstance("out2").orElse(null).setMiddlewareSymbol(new SomeIPConnectionSymbol(121,122,123/*,124,125*/));
List<File> files = generatorSomeIP.generateSomeIPAdapter(componentInstanceSymbol);
......
......@@ -2,142 +2,152 @@
#include "SomeIPAdapter_tests_a_compA.h"
SomeIPAdapter_tests_a_compA::SomeIPAdapter_tests_a_compA() : public IAdapter_tests_a_compA {
//choose random ids
in1_service_id = 11;
in1_instance_id = 12;
in1_method_id = 13;
in1_event_id = 14;
in1_eventgroup_id = 15;
in2_service_id = 21;
in2_instance_id = 22;
in2_method_id = 23;
in2_event_id = 24;
in2_eventgroup_id = 25;
out1_service_id = 111;
out1_instance_id = 112;
out1_method_id = 113;
out1_event_id = 114;
out1_eventgroup_id = 115;
out2_service_id = 121;
out2_instance_id = 122;
out2_method_id = 123;
out2_event_id = 124;
out2_eventgroup_id = 125;
}
void SomeIPAdapter_tests_a_compA::init(tests_a_compA *comp) {
// Initialize component
this->component = comp;
// Intitialize subscriber for in1
in1_Subscriber = vsomeip::runtime::get()->create_application("Subscriber");
in1_Subscriber->init();
in1_Subscriber->request_service(in1_service_id, in1_instance_id);
in1_Subscriber->register_message_handler(in1_service_id, in1_instance_id, in1_method_id, std::bind(&SomeIPAdapter_tests_a_compA::on_message_in1, this, std::placeholders::_1));
// Subscribe
std::set<vsomeip::eventgroup_t> in1_event_group;
in1_event_group.insert(in1_eventgroup_id);
in1_Subscriber->request_event(in1_service_id, in1_instance_id, in1_event_id, in1_event_group, true);
in1_Subscriber->subscribe(in1_service_id, in1_instance_id, in1_eventgroup_id);
in1_Subscriber->start();
// Intitialize subscriber for in2
in2_Subscriber = vsomeip::runtime::get()->create_application("Subscriber");
in2_Subscriber->init();
in2_Subscriber->request_service(in2_service_id, in2_instance_id);
in2_Subscriber->register_message_handler(in2_service_id, in2_instance_id, in2_method_id, std::bind(&SomeIPAdapter_tests_a_compA::on_message_in2, this, std::placeholders::_1));
// Subscribe
std::set<vsomeip::eventgroup_t> in2_event_group;
in2_event_group.insert(in2_eventgroup_id);
in2_Subscriber->request_event(in2_service_id, in2_instance_id, in2_event_id, in2_event_group, true);
in2_Subscriber->subscribe(in2_service_id, in2_instance_id, in2_eventgroup_id);
in2_Subscriber->start();
// Intitialize Publisher for out1
out1_Publisher = vsomeip::runtime::get()->create_application("Publisher");
out1_Publisher->init();
out1_Publisher->offer_service(out1_service_id, out1_instance_id);
out1_Publisher->start();
// Intitialize Publisher for out2
out2_Publisher = vsomeip::runtime::get()->create_application("Publisher");
out2_Publisher->init();
out2_Publisher->offer_service(out2_service_id, out2_instance_id);
out2_Publisher->start();
// Intitialize Subscriber
in1_Subscriber = vsomeip::runtime::get()->create_application("Subscriber in1");
if (!in1_Subscriber->init()) {
std::cerr << "Couldn't initialize Subscriber in1" << std::endl;
}
in1_Subscriber->register_availability_handler(11, 12, std::bind(&SomeIPAdapter_tests_a_compA::on_availability_in1, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
in1_Subscriber->request_service(11, 12);
in1_Subscriber->register_message_handler(11, 12, 0, std::bind(&SomeIPAdapter_tests_a_compA::on_message_in1, this, std::placeholders::_1));
std::thread sender_in1(std::bind(&SomeIPAdapter_tests_a_compA::run_in1, this));
in1_Subscriber->start();
in2_Subscriber = vsomeip::runtime::get()->create_application("Subscriber in2");
if (!in2_Subscriber->init()) {
std::cerr << "Couldn't initialize Subscriber in2" << std::endl;
}
in2_Subscriber->register_availability_handler(21, 22, std::bind(&SomeIPAdapter_tests_a_compA::on_availability_in2, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
in2_Subscriber->request_service(21, 22);
in2_Subscriber->register_message_handler(21, 22, 0, std::bind(&SomeIPAdapter_tests_a_compA::on_message_in2, this, std::placeholders::_1));
std::thread sender_in2(std::bind(&SomeIPAdapter_tests_a_compA::run_in2, this));
in2_Subscriber->start();
// Intitialize Publisher
out1_Publisher = vsomeip::runtime::get()->create_application("Publisher out1");
if (!out1_Publisher->init()) {
std::cerr << "Couldn't initialize Publisher out1" << std::endl;
}
out1_Publisher->offer_service(111, 112);
out1_Publisher->start();
out2_Publisher = vsomeip::runtime::get()->create_application("Publisher out2");
if (!out2_Publisher->init()) {
std::cerr << "Couldn't initialize Publisher out2" << std::endl;
}
out2_Publisher->offer_service(121, 122);
out2_Publisher->start();
}
void SomeIPAdapter_tests_a_compA::run_in1() {
std::unique_lock<std::mutex> its_lock(mutex_in1);
condition_in1.wait(its_lock);
std::set<vsomeip::eventgroup_t> event_group;
event_group.insert(13);
in1_Subscriber->request_event(11, 12, 0, event_group, true);
in1_Subscriber->subscribe(11, 12, 13);
}
void SomeIPAdapter_tests_a_compA::on_message_in1(const std::shared_ptr<vsomeip::message> &_request) {
void SomeIPAdapter_tests_a_compA::on_message_in1(const std::shared_ptr<vsomeip::message> &_message) {
//read received message
std::shared_ptr<vsomeip::payload> its_payload = _request->get_payload();
std::shared_ptr<vsomeip::payload> its_payload = _message->get_payload();
vsomeip::length_t l = its_payload->get_length();
double dataFromMessage = *((double*)its_payload->get_data());
component->in1 = 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;
std::cout << "SERVICE in1: Received message from ["
<< std::setw(4) << std::setfill('0') << std::hex << _message->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex << _message->get_session() << "]: "
<< dataFromMessage << std::endl;
}
void SomeIPAdapter_tests_a_compA::on_availability_in1(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available) {
std::cout << "Service ["
<< std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance
<< "] is "
<< (_is_available ? "available." : "NOT available.")
<< std::endl;
condition_in1.notify_one();
}
void SomeIPAdapter_tests_a_compA::run_in2() {
std::unique_lock<std::mutex> its_lock(mutex_in2);
condition_in2.wait(its_lock);
std::set<vsomeip::eventgroup_t> event_group;
event_group.insert(23);
in2_Subscriber->request_event(21, 22, 0, event_group, true);
in2_Subscriber->subscribe(21, 22, 23);
}
void SomeIPAdapter_tests_a_compA::on_message_in2(const std::shared_ptr<vsomeip::message> &_request) {
void SomeIPAdapter_tests_a_compA::on_message_in2(const std::shared_ptr<vsomeip::message> &_message) {
//read received message
std::shared_ptr<vsomeip::payload> its_payload = _request->get_payload();
std::shared_ptr<vsomeip::payload> its_payload = _message->get_payload();
vsomeip::length_t l = its_payload->get_length();
double dataFromMessage = *((double*)its_payload->get_data());
component->in2 = 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;
std::cout << "SERVICE in2: Received message from ["
<< std::setw(4) << std::setfill('0') << std::hex << _message->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex << _message->get_session() << "]: "
<< dataFromMessage << std::endl;
}
void SomeIPAdapter_tests_a_compA::on_availability_in2(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available) {
std::cout << "Service ["
<< std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance
<< "] is "
<< (_is_available ? "available." : "NOT available.")
<< std::endl;
condition_in2.notify_one();
}
void SomeIPAdapter_tests_a_compA::publishout1_Publisher()
{
//Read data from component
double d = component->out1;
//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);
const vsomeip::byte_t its_data[] = { (uint8_t) d };
std::shared_ptr<vsomeip::payload> payload = vsomeip::runtime::get()->create_payload();
payload->set_data(its_data, sizeof(its_data));
//Publish
std::set<vsomeip::eventgroup_t> out1_event_group;
out1_event_group.insert(out1_eventgroup_id);
out1_Publisher->offer_event(out1_service_id, out1_instance_id, out1_event_id, out1_event_group, true);
out1_Publisher->notify(out1_service_id, out1_instance_id, out1_event_id, payload);
std::set<vsomeip::eventgroup_t> event_group;
event_group.insert(113);
out1_Publisher->offer_event(111, 112, 0, event_group, true);
out1_Publisher->notify(111, 112, 0, payload);
}
void SomeIPAdapter_tests_a_compA::publishout2_Publisher()
{
//Read data from component