순서
- CommonAPI C++런타임 라이브러리 작성
- 런타임라이브러리 작성
- Franca파일 작성 및 코드 생성
- 클아이언트 및 서비스 응용 프로그램 작성
- 빌드 및 실행
Dependencies
- A C++11 enabled compiler like gcc >= 4.8 is needed.
- vsomeip uses CMake as buildsystem.
- vsomeip uses Boost >= 1.55:
- JAVA JRE Runtime(Oracle JRE 참고)
Test Version
- CommonAPI runtime : 3.1.12.6
- SOME/IP runtime : 3.1.12.9
- vsomeip : 2.14.16
- libboost : 1.58
시작하기 전에
개발환경구축했는지 확인하고 하자..
1.CommonAPI C++런타임 라이브러리
$ git clone https://github.com/GENIVI/capicxx-core-runtime.git
$ cd capicxx-core-runtime
capicxx-core-runtime$ mkdir build
capicxx-core-runtime$ cd build
capicxx-core-runtime/build$ cmake ..
capicxx-core-runtime/build$ make
capicxx-core-runtime/build$ mkdir ../../COMMONAPI
capicxx-core-runtime/build$ cp -d lib* ../../COMMONAPI
capicxx-core-runtime/build$ cd ../..
2. CommonAPI SOME/IP 런타임 라이브러리 작성
$ git clone https://github.com/GENIVI/capicxx-someip-runtime.git
$ sudo apt-get install libboost-system1.55-dev libboost-thread1.55-dev libboost-log1.55-dev
:
** Package가 없다고 메세지가 나올때 "sudo apt search libboost" 명령어로 버젼을 확인후 해당버전을 인스톨한다.
$ git clone http://github.com/GENIVI/vSomeIP.git
** SOME/IP는 코어 네트워크 펑션을 사용하기 위해 표준 크로스플랫폼 C++라이브러리 Boost.Asio를 사용함으로 vsomeip라이브러리를 사용하기 전에 Boost를 시스템에 인스톨해야한다.
** vsomeip를 빌드하기 전에 2.xx 버전에서 실행한다.
vsomeip의 버젼이 3.xx버전일 경우 2.xx버젼에서 수행 하도록 한다.
$ cd vSomeIP
vSomeIP$ mkdir build
vSomeIP$ cd build
vSomeIP/build$ cmake ..
vSomeIP/build$ make
vSomeIP/build$ cp -d lib* ../../COMMONAPI
vSomeIP/build$ cd ../..
- Build CommonAPI C++ SOME/IP
$ cd capicxx-someip-runtime/
capicxx-someip-runtime$ mkdir build
capicxx-someip-runtime$ cd build
capicxx-someip-runtime/build$ cmake -DUSE_INSTALLED_COMMONAPI=OFF ..
** cmake시 vsomeip관련 오류 발생시 vsomeip의 버전 체크 필요.
**
vsomeip의 버젼이 3.xx버전일 경우 2.xx버젼에서 수행
capicxx-someip-runtime/build$ make
capicxx-someip-runtime/build$ cp -d lib* ../../COMMONAPI
capicxx-someip-runtime/build$ cd ../..
3. Franca파일 작성 및 코드 생성
프로젝트 디렉토리 생성하고 디렉토리의 하위에 fidl 디렉토리생성 및 해당 디렉토리상에 아래의 deployment specification를 작성
import "platform:/plugin/org.genivi.commonapi.someip/deployment/CommonAPI-SOMEIP_deployment_spec.fdepl"
import "HelloWorld.fidl"
define org.genivi.commonapi.someip.deployment for interface commonapi.HelloWorld {
SomeIpServiceID = 4660 method sayHello {
SomeIpMethodID = 31000
}
}
define org.genivi.commonapi.someip.deployment for provider MyService {
instance commonapi.HelloWorld {
InstanceId = "test"
SomeIpInstanceID = 22136
}
}
package commonapi
interface HelloWorld {
version {major 1 minor 0}
method sayHello {
in {
String name
}
out {
String message
}
}
}
- Get CommonAPI, SOME/IP Code Generator
$ wget https://github.com/GENIVI/capicxx-core-tools/releases/download/3.1.12.4/commonapi-generator.zip
$ wget https://github.com/GENIVI/capicxx-someip-tools/releases/download/3.1.12.2/commonapi_someip_generator.zip
$ unzip commonapi-generator.zip -d ~/commonapi-generator
$ unzip commonapi_someip_generator.zip -d ~/commonapi_someip_generator
$ chmod +x ~/commonapi-generator/commonapi-generator-linux-x86
* OS가 64bit일경우 commonapi-generator-linux-x86_64 파일에 적용
$ chmod +x ~/commonapi_someip_generator/commonapi-someip-generator-linux-x86
*
OS가 64bit일경우 commonapi-someip-generator-linux-x86_64 파일에 적용
$ mkdir hello
$ cd hello
hello$ ~/commonapi-generator/commonapi-generator/commonapi-generator-linux-x86 -sk ./fidl/HelloWorld.fidl
hello$ ~/commonapi_someip_generator/commonapi-someip-generator-linux-x86 -ll verbose /fidl/HelloWorld.fdepl
hello$ cd src-gen/v1/commonapi
hello/src-gen/v1/commonapi$ ls -la
** generator는 JAVA 머신상에서 돌아감으로 JRE가 설치되어 있어야 동작함..
설치방법 참조
4.클라이언트 및 서비스 응용프로그램 작성
- Create src and build directories
hello$ mkdir src
hello$ mkdir build
hello$ ls
>>> build cgen fidl src src-gen
hello$ cd src
src 디렉토리에 아래의 4개화일을 생성한다.
#include <iostream>
#include <string>
#include <unistd.h>
#include </CommonAPI.hpp>
#include <v1/commonapi/HelloWorldProxy.hpp>
using namespace v1_0::commonapi;
int main() {
std::shared_ptr <CommonAPI::Runtime> runtime = CommonAPI::Runtime::get();
std::shared_ptr<HelloWorldProxy<>> myProxy = runtime->buildProxy<HelloWorldProxy>("local", "test");
std::cout << "Checking availability!" << std::endl;
while (!myProxy->isAvailable())
usleep(10);
std::cout << "Available..." << std::endl;
CommonAPI::CallStatus callStatus;
std::string returnMessage;
myProxy->sayHello("Bob", callStatus, returnMessage);
std::cout << "Got message: '" << returnMessage << "'\n";
return 0;
}
#include <iostream>
#include <thread>
#include <CommonAPI/CommonAPI.hpp>
#include "HelloWorldStubImpl.hpp"
using namespace std;
int main() {
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::get();
std::shared_ptr<HelloWorldStubImpl> myService = std::make_shared<HelloWorldStubImpl>();
runtime->registerService("local", "test", myService);
std::cout << "Successfully Registered Service!" << std::endl;
while (true) {
std::cout << "Waiting for calls... (Abort with CTRL+C)" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(30));
}
return 0;
}
#ifndef HELLOWORLDSTUBIMPL_H_
#define HELLOWORLDSTUBIMPL_H_
#include <CommonAPI/CommonAPI.hpp>
#include <v1/commonapi/HelloWorldStubDefault.hpp>
class HelloWorldStubImpl: public v1_0::commonapi::HelloWorldStubDefault {
public:
HelloWorldStubImpl();
virtual ~HelloWorldStubImpl();
virtual void sayHello(const std::shared_ptr<CommonAPI::ClientId> _client, std::string _name, sayHelloReply_t _return);
};
#endif /* HELLOWORLDSTUBIMPL_H_ */
#include "HelloWorldStubImpl.hpp"
HelloWorldStubImpl::HelloWorldStubImpl() { }
HelloWorldStubImpl::~HelloWorldStubImpl() { }
void HelloWorldStubImpl::sayHello(const std::shared_ptr<CommonAPI::ClientId> _client, std::string _name, sayHelloReply_t _reply) {
std::stringstream messageStream;
messageStream << "Hello " << _name << "!";
std::cout << "sayHello('" << _name << "'): '" << messageStream.str() << "'\n";
_reply(messageStream.str());
};
5.빌드및 실행
프로젝트 디렉토리(hello)에 아래 파일을 생성한다.
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++0x")
include_directories(
src-gen
~/work2/capicxx-core-runtime/include
~/work2/capicxx-someip-runtime/include
~/work2/vSomeIP/interface
)
link_directories(
~/work2/COMMONAPI
)
add_executable(HelloWorldClient
src/HelloWorldClient.cpp
src-gen/v1/commonapi/HelloWorldSomeIPProxy.cpp
src-gen/v1/commonapi/HelloWorldSomeIPDeployment.cpp
)
target_link_libraries(HelloWorldClient CommonAPI CommonAPI-SomeIP vsomeip)
add_executable(HelloWorldService
src/HelloWorldService.cpp
src/HelloWorldStubImpl.cpp
src-gen/v1/commonapi/HelloWorldSomeIPStubAdapter.cpp
src-gen/v1/commonapi/HelloWorldStubDefault.cpp
src-gen/v1/commonapi/HelloWorldSomeIPDeployment.cpp
)
target_link_libraries(HelloWorldService CommonAPI CommonAPI-SomeIP vsomeip)
hello$ cd build
hello/build$ cmake ..
hello/build$ make
Reference
GENIVI Git hub : https://github.com/GENIVI
CommonAPI C++ SOME/IP in 10 minutes( https://at.projects.genivi.org/wiki/pages/viewpage.action?pageId=5472320 )