CommonAPI+vsomeip aarch64交叉编译整理

工程目录结构

省略了源码结构里面大部分不影响理解的目录和文件,基本上就是下载源码,创建build文件夹,在build里面cmake,make。

.
├── boost
│   └── boost_1_73_0
│   │   ├── b2
│   │   ├── bootstrap.sh
│   │   ├── build
│   │   └── project-config.jam
├── build
│   ├── HelloWorldClient_aarch64
│   ├── HelloWorldService_aarch64
│   └── Makefile
├── CMakeLists.txt
├── CommonAPI_generator
│   ├── commonapi-core-generator
│   │   └── commonapi-core-generator-linux-x86_64
│   └── commonapi-someip-generator
│       └── commonapi-someip-generator-linux-x86_64
├── CommonAPI_runtime
│   └── capicxx-core-runtime
│       ├── build
│       ├── CMakeLists.txt
│       └── src
├── CommonAPI_SOMEIP
│   └── capicxx-someip-runtime
│       ├── build
│       ├── CMakeLists.txt
│       └── src
├── CommonAPI_third_party
│   ├── boost_1_73_0
│   │   ├── include
│   │   └── lib
│   ├── CommonAPI_runtime
│   │   ├── include
│   │   └── lib
│   ├── CommonAPI_SOMEIP
│   │   ├── include
│   │   └── lib
│   ├── libdlt
│   │   ├── libdlt.so -> libdlt.so.2
│   │   ├── libdlt.so.2 -> libdlt.so.2.18.3
│   │   └── libdlt.so.2.18.3
│   └── vsomeip
│       ├── etc
│       ├── include
│       └── lib
├── dlt-daemon
│   └── dlt-daemon
│       ├── build
│       ├── CMakeLists.txt
│       └── src
├── fidl
│   ├── HelloWorld.fdepl
│   └── HelloWorld.fidl
├── src
│   ├── HelloWorldClient.cpp
│   ├── HelloWorldService.cpp
│   ├── HelloWorldStubImpl.cpp
│   └── HelloWorldStubImpl.hpp
├── src-gen
│   └── v1
│       └── commonapi
├── toolchain.cmake
└── vsomeip
    └── vsomeip
        ├── build
        ├── CMakeLists.txt
        ├── documentation
        └── implementation

源码下载

自己创建一个空的文件夹作为工程根目录,然后按照下面的顺序创建就可得到第一章中的目录结构。

1、CommonAPI_runtime :

mkdir CommonAPI_runtime
cd CommonAPI_runtime/
git clone https://github.com/GENIVI/capicxx-core-runtime.git

 2、dlt-daemon :

mkdir dlt-daemon
cd dlt-daemon
git clone https://github.com/COVESA/dlt-daemon.git

3、CommonAPI_SOMEIP

mkdir CommonAPI_SOMEIP
cd CommonAPI_SOMEIP/
git clone https://github.com/GENIVI/capicxx-someip-runtime.git

4、vsomeip

mkdir vsomeip
cd vsomeip/
git clone https://github.com/COVESA/vsomeip.git

5、boost

mkdir boost
cd boost
wget https://sourceforge.net/projects/boost/files/boost/1.73.0/boost_1_73_0.tar.gz/download -O boost_1_73_0.tar.gz
tar zxf boost_1_73_0.tar.gz

6、CommonAPI_generator

mkdir CommonAPI_generator
cd CommonAPI_generator
mkdir commonapi-core-generator
cd commonapi-core-generator
wget https://github.com/COVESA/capicxx-core-tools/releases/download/3.2.14/commonapi_core_generator.zip
unzip commonapi_core_generator.zip
chmod +x ./commonapi-core-generator-linux-x86_64
cd ..
mkdir commonapi-someip-generator/
cd commonapi-someip-generator/
wget https://github.com/COVESA/capicxx-someip-tools/releases/download/3.2.14/commonapi_someip_generator.zip
unzip commonapi_someip_generator.zip 
chmod +x ./commonapi-someip-generator-linux-x86_64

工程构建

先创建一个toolchain.cmake

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER /opt/aarch64-linux-gnu_sdk-buildroot/bin/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /opt/aarch64-linux-gnu_sdk-buildroot/bin/aarch64-linux-gnu-g++)

set (CMAKE_C_FLAGS "--sysroot=/opt/aarch64-linux-gnu_sdk-buildroot/aarch64-linux-gnu/sysroot/")
set (CMAKE_CXX_FLAGS "--sysroot=/opt/aarch64-linux-gnu_sdk-buildroot/aarch64-linux-gnu/sysroot/")

 1、 dlt-daemon : path_to_your_project改成自己的路径,绝对路径

cd dlt-daemon/dlt-daemon
mkdir build/install -p
cd build/
cmake .. -DCMAKE_INSTALL_PREFIX=install -DCMAKE_TOOLCHAIN_FILE=path_to_your_project/toolchain.cmake
make -j4 install

2、CommonAPI_runtime :

先要编辑一下CMakeLists.txt,添加一下pkgconfig查找路径。在115行之后,注意把path_to_your_project改成自己的路径。

FIND_PACKAGE(PkgConfig)
#添加下面这行
set(ENV{PKG_CONFIG_PATH} "path_to_your_project/dlt-daemon/dlt-daemon/build/install/lib/pkgconfig/:$ENV{PKG_CONFIG_PATH}")
#结束
pkg_check_modules(DLT "automotive-dlt >= 2.11")
cd CommonAPI_runtime/capicxx-core-runtime/
mkdir -p build/install
cd build/
cmake .. -DCMAKE_INSTALL_PREFIX=install -DCMAKE_TOOLCHAIN_FILE=path_to_your_project/toolchain.cmake
make -j4 install

 3、 boost

cd boost_1_73_0
./bootstrap.sh --show-libraries
./bootstrap.sh --with-libraries=filesystem,system,thread --with-toolset=gcc
修改project-config.jam的第12行如下:
if ! gcc in [ feature.values <toolset> ]
{
#修改下面这行
    using gcc : arm : /opt/aarch64-linux-gnu_sdk-buildroot/bin/aarch64-linux-gnu-gcc ;
#结束
}
保存退出
./b2

执行./b2之后成功的打印如下:

...updated 128 targets...


The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    /path_to_your_project/boost/boost_1_73_0

The following directory should be added to linker library paths:

    /path_to_your_project/boost/boost_1_73_0/stage/lib

 创建一个install目录,安装生成的lib和头文件

mkdir install
./b2 install --prefix=install

4、vsomeip

先要编辑一下CMakeLists.txt,添加一下pkgconfig查找路径。在203行之后,注意把path_to_your_project改成自己的路径。

find_package(PkgConfig)
#添加下面这行
set(ENV{PKG_CONFIG_PATH} "path_to_your_project/dlt-daemon/dlt-daemon/build/install/lib/pkgconfig/:$ENV{PKG_CONFIG_PATH}")
#结束
# DLT
cd vsomeip/vsomeip
mkdir -p build/install
cd build
cmake -DENABLE_SIGNAL_HANDLING=1 -DCMAKE_INSTALL_PREFIX=install -DCMAKE_TOOLCHAIN_FILE=path_to_your_project/toolchain.cmake -DBoost_DIR=absolute_path_to_your_project/boost/boost_1_73_0/install/lib/cmake/Boost-1.73.0/ ..
make -j4 install

5、CommonAPI_SOMEIP

cd CommonAPI_SOMEIP/capicxx-someip-runtime
mkdir -p build/install
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=path_to_your_project/toolchain.cmake -DCommonAPI_DIR=path_to_your_project/CommonAPI_runtime/capicxx-core-runtime/build/install/lib/cmake/CommonAPI-3.2.3 -DCMAKE_INSTALL_PREFIX=install -Dvsomeip3_DIR=path_to_your_project/vsomeip/vsomeip/build/install/lib/cmake/vsomeip3 ..
make -j4 install

测试程序

mkdir src
cd src
touch HelloWorldClient.cpp
touch HelloWorldService.cpp
touch HelloWorldStubImpl.cpp
touch HelloWorldStubImpl.hpp
cd ..
mkdir fidl
cd fidl
touch HelloWorld.fdepl
touch HelloWorld.fidl
cd ..
mkdir CommonAPI_third_party
cd CommonAPI_third_party
cp ../boost/boost_1_73_0/install ./boost_1_73_0 -parf
cp ../CommonAPI_runtime/capicxx-core-runtime/build/install ./CommonAPI_runtime -parf
mv ./CommonAPI_runtime/include/CommonAPI-3.2/CommonAPI/ ./CommonAPI_runtime/include/
cp ../CommonAPI_SOMEIP/capicxx-someip-runtime/build/install ./CommonAPI_SOMEIP -parf
mv ./CommonAPI_SOMEIP/include/CommonAPI-3.2/CommonAPI/ ./CommonAPI_SOMEIP/include/
cp ../dlt-daemon/dlt-daemon/build/install/lib/ ./libdlt -parf
cp ../vsomeip/vsomeip/build/install/ ./vsomeip -parf

HelloWorld.fidl

package commonapi

interface HelloWorld {
  version {major 1 minor 0}
  method sayHello {
    in {
      String name
    }
    out {
      String message
    }
  }
}

HelloWorld.fdepl

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 = 123
                }
}
//    define org.genivi.commonapi.someip.deployment for provider MyService {
//      instance commonapi.HelloWorld {
//              InstanceId = "test"
//              SomeIpInstanceID = 22136
//      }
//      }
define org.genivi.commonapi.someip.deployment for provider as MyService {
        instance commonapi.HelloWorld {
                InstanceId = "test"
                SomeIpInstanceID = 22136
        }
}

 HelloWorldClient.cpp

#include <iostream>
#include <string>
#include <unistd.h>
#include <CommonAPI/CommonAPI.hpp>
#include <v1/commonapi/HelloWorldProxy.hpp>


using namespace v1::commonapi;

int main(int argc, char *argv[]) {
        if (argc < 4) {
                printf("need argv[1] domain, argv[2] instance and argv[3] connection\n");
                return 0;
        }
        std::string domain = argv[1];
        std::string instance = argv[2];
        std::string connection = argv[3];
    std::shared_ptr < CommonAPI::Runtime > runtime = CommonAPI::Runtime::get();
    std::shared_ptr<HelloWorldProxy<>> myProxy =
        runtime->buildProxy<HelloWorldProxy>(domain, instance, connection);
    std::cout << "Checking availability!" << std::endl;
        while (!myProxy->isAvailable())
        usleep(10);
        std::cout << "Available..." << std::endl;

        CommonAPI::CallStatus callStatus;
        std::string returnMessage;
    std::cout << "start call sayhello" << "\n";
        myProxy->sayHello("Bob", callStatus, returnMessage);
        std::cout << "Got message: '" << returnMessage << "'\n";
        return 0;
}

 HelloWorldService.cpp

// HelloWorldService.cpp
#include <iostream>
#include <thread>
#include <CommonAPI/CommonAPI.hpp>
#include "HelloWorldStubImpl.hpp"

using namespace std;

int main(int argc, char *argv[]) {
        if (argc < 4) {
                printf("need argv[1] domain, argv[2] instance and argv[3] connection\n");
                return 0;
        }
        std::string domain = argv[1];
        std::string instance = argv[2];
        std::string connection = argv[3];
    std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::get();
    std::shared_ptr<HelloWorldStubImpl> myService = 
    std::make_shared<HelloWorldStubImpl>();
    std::cout << connection << std::endl;
    runtime->registerService(domain, instance, myService, connection);
    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;
}

 HelloWorldStubImpl.hpp

// HelloWorldStubImpl.hpp
#ifndef HELLOWORLDSTUBIMPL_H_
#define HELLOWORLDSTUBIMPL_H_

#include <CommonAPI/CommonAPI.hpp>
#include <v1/commonapi/HelloWorldStub.hpp>

class HelloWorldStubImpl: public v1::commonapi::HelloWorldStub {
public:
    HelloWorldStubImpl();
    ~HelloWorldStubImpl();
    const CommonAPI::Version& getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> _client) override {

    }
    v1::commonapi::HelloWorldStubRemoteEvent* initStubAdapter(const std::shared_ptr<v1::commonapi::HelloWorldStubAdapter> &_stubAdapter) override {

    }
    void sayHello(const std::shared_ptr<CommonAPI::ClientId> _client,
        std::string _name, sayHelloReply_t _return);
};
#endif /* HELLOWORLDSTUBIMPL_H_ */

 HelloWorldStubImpl.cpp

// HelloWorldStubImpl.cpp
#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());
};

1、用CommonAPI_generator生成桩函数定义的文件。文件会生成在src-gen目录下

path_to_your_project/CommonAPI_generator/commonapi-core-generator/commonapi-core-generator-linux-x86_64 ./fidl/HelloWorld.fidl
path_to_your_project/CommonAPI_generator/commonapi-someip-generator/commonapi-someip-generator-linux-x86_64 -ll verbose ./fidl/HelloWorld.fdepl

 2、CMakeLists.txt

cmake_minimum_required(VERSION 2.8.12...3.23.0)

project(my_someip_commonapi_test)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ldl")
set(RUNTIME_PATH "CommonAPI_third_party/CommonAPI_runtime")
set(SOMEIP_PATH "CommonAPI_third_party/CommonAPI_SOMEIP")
set(VSOMEIP_PATH "CommonAPI_third_party/vsomeip")
set(BOOST_PATH "CommonAPI_third_party/boost_1_73_0/")
set(DLT_PATH "CommonAPI_third_party/libdlt")
set(executable_client HelloWorldClient_aarch64)
set(executable_server HelloWorldService_aarch64)


include_directories(
    src-gen
    src
    ${RUNTIME_PATH}/include
    ${SOMEIP_PATH}/include
    ${VSOMEIP_PATH}/include
)
link_directories(
    ${RUNTIME_PATH}/lib
    ${SOMEIP_PATH}/lib
    ${VSOMEIP_PATH}/lib
    ${BOOST_PATH}/lib
    ${DLT_PATH}
)
add_executable(${executable_client}
    src/HelloWorldClient.cpp
    src-gen/v1/commonapi/HelloWorldSomeIPProxy.cpp
    src-gen/v1/commonapi/HelloWorldSomeIPDeployment.cpp
)
target_link_libraries(${executable_client} CommonAPI CommonAPI-SomeIP vsomeip3 boost_thread dlt)

add_executable(${executable_server}
    src/HelloWorldService.cpp
    src/HelloWorldStubImpl.cpp
    src-gen/v1/commonapi/HelloWorldSomeIPStubAdapter.cpp
    src-gen/v1/commonapi/HelloWorldStub.hpp
    src-gen/v1/commonapi/HelloWorldSomeIPDeployment.cpp
)
target_link_libraries(${executable_server} CommonAPI CommonAPI-SomeIP vsomeip3 boost_thread dlt)

3、编译

mkdir build && cd build
cmake ../ -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake
make

 4、放到设备里面运行测试

把build下生成的可执行程序和CommonAPI_third_party下的几个目录里面的lib下所有so文件传到板子上去,并把路径设置到板子的LD_LIBRARY_PATH环境变量里。

注意一些配置文件内容。首先看一下dbus的本地IPC通信:

/etc/commonapi.ini

[default]
binding=dbus  // 如果使用someip可以改成someip
[logging]
console = true
file = /tmp/CommonAPISomeIP.log
dlt = false  // DLT(Diagnostic Log and Trace)
level = verbose

客户端执行

VSOMEIP_APPLICATION_NAME=service-sample ./HelloWorldClient_aarch64 local test service-sample
[CAPI][INFO] Loading configuration file /etc//commonapi-someip.ini
[CAPI][INFO] Loading configuration file '/etc/commonapi.ini'
[CAPI][INFO] Using default binding 'dbus  // SOMEIP'
[CAPI][INFO] Using default shared library folder '/usr/local/lib/commonapi'
[CAPI][DEBUG] Added address mapping: local:commonapi.HelloWorld:v1_0:test <--> [1234.5678(1.0)]
[CAPI][VERBOSE] Registering function for creating "commonapi.HelloWorld:v1_0" proxy.
[CAPI][VERBOSE] Creating proxy for "local:commonapi.HelloWorld:v1_0:test"
2022-03-15 09:47:20.810192 [info] Parsed vsomeip configuration in 0ms
2022-03-15 09:47:20.811633 [info] Configuration module loaded.
2022-03-15 09:47:20.811875 [info] Security disabled!
2022-03-15 09:47:20.812073 [info] Initializing vsomeip (3.4.10) application "service-sample".
2022-03-15 09:47:20.812928 [info] Instantiating routing manager [Host].
2022-03-15 09:47:20.814707 [info] create_routing_root: Routing root @ /tmp/vsomeip-0
2022-03-15 09:47:20.815888 [info] Service Discovery enabled. Trying to load module.
2022-03-15 09:47:20.822080 [info] Service Discovery module loaded.
2022-03-15 09:47:20.823352 [info] vsomeip tracing not enabled. . vsomeip service discovery tracing not enabled. 
2022-03-15 09:47:20.823801 [info] Application(service-sample, 0100) is initialized (11, 100).
2022-03-15 09:47:20.825670 [info] REQUEST(0100): [1234.5678:1.4294967295]
2022-03-15 09:47:20.825866 [info] Starting vsomeip application "service-sample" (0100) using 2 threads I/O nice 255
2022-03-15 09:47:20.827132 [info] create_local_server: Listening @ /tmp/vsomeip-100
2022-03-15 09:47:20.827677 [info] Client [0100] routes unicast:127.0.0.1, netmask:255.255.255.0
Checking availability!
2022-03-15 09:47:20.827913 [info] shutdown thread id from application: 0100 (service-sample) is: 7fad18f180 TID: 4030091
2022-03-15 09:47:20.828106 [info] main dispatch thread id from application: 0100 (service-sample) is: 7fad99f180 TID: 4030090
2022-03-15 09:47:20.828689 [info] Watchdog is disabled!
2022-03-15 09:47:20.831052 [info] io thread id from application: 0100 (service-sample) is: 7fae1af180 TID: 4030089
2022-03-15 09:47:20.831157 [info] io thread id from application: 0100 (service-sample) is: 7f9ffff180 TID: 4030093
2022-03-15 09:47:20.831749 [info] vSomeIP 3.4.10 | (default)
2022-03-15 09:47:20.832099 [info] Network interface "lo" state changed: up
2022-03-15 09:47:22.320551 [info] Application/Client 0101 is registering.
2022-03-15 09:47:22.322327 [info] Client [100] is connecting to [101] at /tmp/vsomeip-101
2022-03-15 09:47:22.326492 [info] REGISTERED_ACK(0101)
2022-03-15 09:47:22.327836 [info] Port configuration missing for [1234.5678]. Service is internal.
2022-03-15 09:47:22.328536 [info] OFFER(0101): [1234.5678:1.0] (true)
Available...
start call sayhello
Got message: 'Hello Bob!'
2022-03-15 09:47:22.336444 [info] RELEASE(0100): [1234.5678]
2022-03-15 09:47:22.338103 [info] Stopping vsomeip application "service-sample" (0100).
2022-03-15 09:47:22.343540 [info] Client [100] is closing connection to [101]
2022-03-15 09:47:22.343563 [info] local_uds_client_endpoint_impl::receive_cbk Error: Operation canceled
[353633.432191]~DLT~4030084~WARNING  ~Lost log messages in user buffer when exiting: 2

服务端执行:前面的VSOMEIP_APPLICATION_NAME是环境变量设置

VSOMEIP_APPLICATION_NAME=service-sample ./HelloWorldService_aarch64 local test service-sample
[CAPI][INFO] Loading configuration file /etc//commonapi-someip.ini
service-sample
[CAPI][INFO] Loading configuration file '/etc/commonapi.ini'
[CAPI][INFO] Using default binding 'dbus  // SOMEIP'
[CAPI][INFO] Using default shared library folder '/usr/local/lib/commonapi'
[CAPI][DEBUG] Added address mapping: local:commonapi.HelloWorld:v1_0:test <--> [1234.5678(1.0)]
[CAPI][INFO] Registering function for creating "commonapi.HelloWorld:v1_0" stub adapter.
[CAPI][INFO] Registering stub for "local:commonapi.HelloWorld:v1_0:test"
2022-03-15 09:47:22.304416 [info] Parsed vsomeip configuration in 0ms
2022-03-15 09:47:22.305769 [info] Configuration module loaded.
2022-03-15 09:47:22.306148 [info] Security disabled!
2022-03-15 09:47:22.306501 [info] Initializing vsomeip (3.4.10) application "service-sample".
2022-03-15 09:47:22.307181 [info] Instantiating routing manager [Proxy].
2022-03-15 09:47:22.308254 [info] Client [ffff] is connecting to [0] at /tmp/vsomeip-0
2022-03-15 09:47:22.308907 [info] vsomeip tracing not enabled. . vsomeip service discovery tracing not enabled. 
2022-03-15 09:47:22.309289 [info] Application(service-sample, ffff) is initialized (11, 100).
Successfully Registered Service!2022-03-15 09:47:22.311844 [info] Starting vsomeip application "service-sample" (ffff) using 2 threads I/O nice 255

Waiting for calls... (Abort with CTRL+C)
2022-03-15 09:47:22.314055 [info] main dispatch thread id from application: ffff (service-sample) is: 7f8f8ff180 TID: 4030137
2022-03-15 09:47:22.314452 [info] shutdown thread id from application: ffff (service-sample) is: 7f8f0ef180 TID: 4030138
2022-03-15 09:47:22.315344 [info] io thread id from application: ffff (service-sample) is: 7f9010f180 TID: 4030136
2022-03-15 09:47:22.315429 [info] io thread id from application: ffff (service-sample) is: 7f8e8df180 TID: 4030139
2022-03-15 09:47:22.318567 [info] create_local_server: Listening @ /tmp/vsomeip-101
2022-03-15 09:47:22.319203 [info] Client 101 (service-sample) successfully connected to routing  ~> registering..
2022-03-15 09:47:22.319629 [info] Registering to routing manager @ vsomeip-0
2022-03-15 09:47:22.325261 [info] Application/Client 101 (service-sample) is registered.
sayHello('Bob'): 'Hello Bob!'
2022-03-15 09:47:22.332952 [info] Client [101] is connecting to [100] at /tmp/vsomeip-100
2022-03-15 09:47:22.343887 [info] local_uds_client_endpoint_impl::receive_cbk Error: End of file
2022-03-15 09:47:22.344400 [info] Client [101] is closing connection to [100]
2022-03-15 09:47:22.344543 [info] Application/Client 101: Reconnecting to routing manager.
2022-03-15 09:47:22.344747 [info] local_uds_client_endpoint_impl::receive_cbk Error: Operation canceled
2022-03-15 09:47:23.346182 [warning] local_client_endpoint::connect: Couldn't connect to: /tmp/vsomeip-0 (No such file or directory / 2)
2022-03-15 09:47:23.346520 [info] routing_manager_client::on_disconnect: Client 0x101 calling host_->on_state with DEREGISTERED
2022-03-15 09:47:23.348022 [warning] local_client_endpoint::connect: Couldn't connect to: /tmp/vsomeip-0 (No such file or directory / 2)
2022-03-15 09:47:23.348880 [info] routing_manager_client::on_disconnect: Client 0x101 calling host_->on_state with DEREGISTERED
2022-03-15 09:47:23.350716 [warning] local_client_endpoint::connect: Couldn't connect to: /tmp/vsomeip-0 (No such file or directory / 2)
2022-03-15 09:47:23.351583 [info] routing_manager_client::on_disconnect: Client 0x101 calling host_->on_state with DEREGISTERED
2022-03-15 09:47:23.352903 [warning] local_client_endpoint::connect: Couldn't connect to: /tmp/vsomeip-0 (No such file or directory / 2)
2022-03-15 09:47:23.353769 [info] routing_manager_client::on_disconnect: Client 0x101 calling host_->on_state with DEREGISTERED
^C2022-03-15 09:47:24.207412 [info] Stopping vsomeip application "service-sample" (0101).
2022-03-15 09:47:24.213097 [info] Exiting vsomeip application...
[353634.618505]~DLT~4030132~WARNING  ~Lost log messages in user buffer when exiting: 2

 如果要用someip通信跨设备,首先修改/etc/commonapi.ini中的binding为someip

然后在客户端/etc目录创建vsomeip-client.json

{
    "unicast" : "192.168.20.41",
    "netmask" : "255.255.255.0",
    "logging" : 
    {
        "level" : "verbose",
        "console" : "true",
        "file" : { "enable" : "false", "path" : "/var/log/vsomeip.log" },
        "dlt" : "false"
    },
    "applications" :
    [
        {
            "name" : "client-sample",
            "id" : "0x1343"
        }
    ],
    "services" :                                                         
    [                                                                    
        {                             
            "service" : "0x1234",     
            "instance" : "0x5678",    
            "unicast" : "192.168.20.42",
            "unreliable" : "31000",   
            "someip-tp": {            
                "client-to-service": [                                          
                    "0x7531"                                                    
                ]                                                               
            }                                                                   
        }                                                                       
    ],    

"routing" : "client-sample",
    "service-discovery" :
    {
        "enable" : "true",
        "multicast" : "224.244.224.245",
        "port" : "30490",
        "protocol" : "udp"
    }
}

然后在服务端创建/etc/vsomeip-service.json 

{
    "unicast" : "192.168.20.42",
    "logging" :
    {
        "level" : "debug",
        "console" : "true",
        "file" : { "enable" : "false", "path" : "/var/log/vsomeip.log" },
        "dlt" : "false"
    },
    "applications" :
    [
        {
            "name" : "service-sample",
            "id" : "0x1277"
        }
    ],
        "services":
        [
                {
                        "service": "0x1234",
                        "instance": "0x5678",
                        "reliable": {
                                "port": "30509",
                                "enable-magic-cookies": "false"
                        },
                        "unreliable": "31000",

                        "someip-tp": {
                                "service-to-client": [
                                        "0x7531"
                                ]
                        }
                }
        ],
    "routing" : "service-sample",
    "service-discovery" :
    {
        "enable" : "true",
        "multicast" : "224.244.224.245",
        "port" : "30490",
        "protocol" : "udp"
    }
}

执行之前在客户端引入环境变量:

export VSOMEIP_APPLICATION_NAME=client-sample 
export VSOMEIP_CONFIGURATION=/etc/vsomeip-client.json

在服务端引入环境变量:

export VSOMEIP_APPLICATION_NAME=service-sample 
export VSOMEIP_CONFIGURATION=/etc/vsomeip-service.json

客户端执行结果

./HelloWorldClient_aarch64 local test client-sample
[CAPI][INFO] Loading configuration file /etc//commonapi-someip.ini
[CAPI][INFO] Loading configuration file '/etc/commonapi.ini'
[CAPI][INFO] Using default binding 'someip  // SOMEIP'
[CAPI][INFO] Using default shared library folder '/usr/local/lib/commonapi'
[CAPI][DEBUG] Added address mapping: local:commonapi.HelloWorld:v1_0:test <--> [1234.5678(1.0)]
[CAPI][VERBOSE] Registering function for creating "commonapi.HelloWorld:v1_0" proxy.
[CAPI][VERBOSE] Creating proxy for "local:commonapi.HelloWorld:v1_0:test"
2022-03-15 10:13:54.738366 [info] Using configuration file: "/etc/vsomeip-client.json".
2022-03-15 10:13:54.739987 [info] Parsed vsomeip configuration in 1ms
2022-03-15 10:13:54.740681 [info] Configuration module loaded.
2022-03-15 10:13:54.741072 [info] Security disabled!
2022-03-15 10:13:54.741428 [info] Initializing vsomeip (3.4.10) application "client-sample".
2022-03-15 10:13:54.742125 [info] Instantiating routing manager [Host].
2022-03-15 10:13:54.743878 [info] create_routing_root: Routing root @ /tmp/vsomeip-0
2022-03-15 10:13:54.745027 [info] Service Discovery enabled. Trying to load module.
2022-03-15 10:13:54.751094 [info] Service Discovery module loaded.
2022-03-15 10:13:54.752284 [info] vsomeip tracing not enabled. . vsomeip service discovery tracing not enabled. 
2022-03-15 10:13:54.752733 [info] Application(client-sample, 1343) is initialized (11, 100).
2022-03-15 10:13:54.754606 [info] REQUEST(1343): [1234.5678:1.4294967295]
2022-03-15 10:13:54.755081 [info] Starting vsomeip application "client-sample" (1343) using 2 threads I/O nice 255
2022-03-15 10:13:54.756431 [info] create_local_server: Listening @ /tmp/vsomeip-1343
2022-03-15 10:13:54.757178 [info] Client [1343] routes unicast:192.168.20.41, netmask:255.255.255.0
Checking availability!
2022-03-15 10:13:54.757659 [info] shutdown thread id from application: 1343 (client-sample) is: 7f9b7ef180 TID: 4046642
2022-03-15 10:13:54.757193 [info] main dispatch thread id from application: 1343 (client-sample) is: 7f9bfff180 TID: 4046641
2022-03-15 10:13:54.759567 [info] Watchdog is disabled!
2022-03-15 10:13:54.761436 [info] io thread id from application: 1343 (client-sample) is: 7fa0faf180 TID: 4046640
2022-03-15 10:13:54.761559 [info] io thread id from application: 1343 (client-sample) is: 7f9a7cf180 TID: 4046644
2022-03-15 10:13:54.763236 [info] vSomeIP 3.4.10 | (default)
2022-03-15 10:13:54.764114 [info] Network interface "eth0" state changed: up
2022-03-15 10:13:54.765791 [info] Route "default route (0.0.0.0/0) if: eth0 gw: 192.168.20.41" state changed: up
2022-03-15 10:13:54.766771 [info] udp_server_endpoint_impl: SO_RCVBUFFORCE successful.
2022-03-15 10:13:54.767267 [info] udp_server_endpoint_impl: SO_RCVBUF is: 1703936 (1703936) local port:30490
2022-03-15 10:13:54.768308 [info] SOME/IP routing ready.
2022-03-15 10:13:54.769154 [warning] Route "224.0.0.0/4 if: eth0 gw: n/a" state changed: up
2022-03-15 10:13:54.769481 [info] udp_server_endpoint_impl<multicast>: SO_RCVBUFFORCE: successful.
2022-03-15 10:13:54.770043 [info] udp_server_endpoint_impl<multicast>: SO_RCVBUF is: 1703936 (1703936) local port:30490
2022-03-15 10:13:56.228400 [info] endpoint_manager_impl::create_remote_client: 192.168.20.42:30509 reliable: 1 using local port: 0
2022-03-15 10:13:56.229333 [info] endpoint_manager_impl::create_remote_client: 192.168.20.42:31000 reliable: 0 using local port: 0
2022-03-15 10:13:56.230917 [info] udp_client_endpoint_impl::connect: SO_RCVBUFFORCE successful!
2022-03-15 10:13:56.231386 [info] udp_client_endpoint_impl::connect: SO_RCVBUF is: 1703936 (1703936) local port:0 remote:192.168.20.42:31000
Available...
start call sayhello
Got message: 'Hello Bob!'
2022-03-15 10:13:56.350465 [info] RELEASE(1343): [1234.5678]
2022-03-15 10:13:56.353143 [info] Stopping vsomeip application "client-sample" (1343).
[355227.033485]~DLT~4046635~WARNING  ~Lost log messages in user buffer when exiting: 3

服务端执行结果

 

./HelloWorldService_aarch64 local test service-sample
[CAPI][INFO] Loading configuration file /etc//commonapi-someip.ini
service-sample
[CAPI][INFO] Loading configuration file '/etc/commonapi.ini'
[CAPI][INFO] Using default binding 'someip  // SOMEIP'
[CAPI][INFO] Using default shared library folder '/usr/local/lib/commonapi'
[CAPI][DEBUG] Added address mapping: local:commonapi.HelloWorld:v1_0:test <--> [1234.5678(1.0)]
[CAPI][INFO] Registering function for creating "commonapi.HelloWorld:v1_0" stub adapter.
[CAPI][INFO] Registering stub for "local:commonapi.HelloWorld:v1_0:test"
2022-03-11 07:54:34.486013 [info] Using configuration file: "/etc/vsomeip.json".
2022-03-11 07:54:34.487955 [info] Parsed vsomeip configuration in 1ms
2022-03-11 07:54:34.488430 [info] Configuration module loaded.
2022-03-11 07:54:34.488798 [info] Security disabled!
2022-03-11 07:54:34.489151 [info] Initializing vsomeip (3.4.10) application "service-sample".
2022-03-11 07:54:34.489705 [info] Instantiating routing manager [Host].
2022-03-11 07:54:34.491942 [info] create_routing_root: Routing root @ /tmp/vsomeip-0
2022-03-11 07:54:34.493450 [info] Service Discovery enabled. Trying to load module.
2022-03-11 07:54:34.500097 [info] Service Discovery module loaded.
2022-03-11 07:54:34.501337 [info] vsomeip tracing not enabled. . vsomeip service discovery tracing not enabled. 
2022-03-11 07:54:34.501783 [info] Application(service-sample, 1277) is initialized (11, 100).
2022-03-11 07:54:34.504353 [info] Starting vsomeip application "service-sample" (1277) using 2 threads I/O nice 255
2022-03-11 07:54:34.505566 [info] create_local_server: Listening @ /tmp/vsomeip-1277
2022-03-11 07:54:34.506426 [info] Client [1277] routes unicast:192.168.20.42, netmask:255.255.255.0
2022-03-11 07:54:34.506829 [info] shutdown thread id from application: 1277 (service-sample) is: 7fa9eaf180 TID: 15652
2022-03-11 07:54:34.506391 [info] main dispatch thread id from application: 1277 (service-sample) is: 7faa6bf180 TID: 15651
2022-03-11 07:54:34.506453 [info] OFFER(1277): [1234.5678:1.0] (true)
2022-03Successfully Registered Service!-
Waiting for calls... (Abort with CTRL+C)
11 07:54:34.508859 [info] Watchdog is disabled!
2022-03-11 07:54:34.511393 [info] io thread id from application: 1277 (service-sample) is: 7faaecf180 TID: 15650
2022-03-11 07:54:34.511431 [info] io thread id from application: 1277 (service-sample) is: 7fa8e8f180 TID: 15654
2022-03-11 07:54:34.513304 [info] vSomeIP 3.4.10 | (default)
2022-03-11 07:54:34.514033 [info] Network interface "eth0" state changed: up
2022-03-11 07:54:34.515538 [info] Route "default route (0.0.0.0/0) if: eth0 gw: 192.168.20.41" state changed: up
2022-03-11 07:54:34.516547 [info] udp_server_endpoint_impl: SO_RCVBUFFORCE successful.
2022-03-11 07:54:34.516991 [info] udp_server_endpoint_impl: SO_RCVBUF is: 1703936 (1703936) local port:30490
2022-03-11 07:54:34.517580 [debug] Joining to multicast group 224.244.224.245 from 192.168.20.42
2022-03-11 07:54:34.519003 [info] udp_server_endpoint_impl<multicast>: SO_RCVBUFFORCE: successful.
2022-03-11 07:54:34.519242 [info] udp_server_endpoint_impl<multicast>: SO_RCVBUF is: 1703936 (1703936) local port:30490
2022-03-11 07:54:34.519589 [info] udp_server_endpoint_impl: SO_RCVBUFFORCE successful.
2022-03-11 07:54:34.520071 [info] udp_server_endpoint_impl: SO_RCVBUF is: 1703936 (1703936) local port:31000
2022-03-11 07:54:34.520563 [info] SOME/IP routing ready.
2022-03-11 07:54:34.521383 [warning] Route "224.0.0.0/4 if: eth0 gw: n/a" state changed: up
sayHello('Bob'): 'Hello Bob!'
^C2022-03-11 07:54:36.271409 [info] Stopping vsomeip application "service-sample" (1277).
2022-03-11 07:54:36.279721 [info] Exiting vsomeip application...
[ 1267.495521]~DLT~15645~WARNING  ~Lost log messages in user buffer when exiting: 3

注意事项总结

1、HelloWorldStubImpl.hpp里面有两个虚函数别人写的教程里都不用实现就可以,我编译的时候就提示不允许存在虚函数的类进行new创建。

2、vsomeip.json的配置方法,以及代码里面创建桩的时候提供的connection命名,参考链接1

参考链接

1、利用commonAPI + someip 在不同板子间发送数据流或文件_fidl的protocol-CSDN博客

2、boost交叉编译安装(aarch64)_boot交叉编译aarch64-CSDN博客

  • 13
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值