本文档的内容参考《AP产品-Communication Manage-模块使用手册》文档和《NeuSAR工具链-配置工具-Creator使用手册》文档,在上述文档的基础上进行实例的配置和部署;本文涉及实例仅做演示用途,不做其他用途。
SOA Adapter中配置了对外提供灯光控制,车窗,后视镜相关服务。业务APP配置相应的请求服务,与SOA Adapter通信,控制灯光,车窗,后视镜。 设计了如下服务:
为服务接口准备数据类型,先配置枚举定义 GeneralConfiguration->CompuMethod右键add,命名CompuMethodLightEventType
类似的创建CompuMethodLightValueType、CompuMethodLightResultType、CompuMethodOperateCode类型如下
CommunicationManagement->ServiceInterface右键add,命名LightCtrl,并创建子节点Events,命名LightEvent,Type Tref引用数据类型LightEventType,如下
继续配置WindowFunctionCfgSomeipServiceInterfaceDeployment和MirrorPosFRStsSomeipService InterfaceDeployment节点
创建AdaptiveApplicationSwComponentType GeneralConfiguration->AdaptiveApplicationSwComponentType右键add,命名AsfNeusarSoaClient
继续创建子节点,选择RPortTrotoType,创建WindowFunctionCfg_RPort、MirrorPosFRSts_RPort、LightCtrl_RPort三个节点,引用上面配置的服务接口如下
添加启动配置 ExecutionManagement->StartupConfigSet->StartupConfigs右键add,取名AsfNeusarSoaClient
GeneralConfigurationExecutable右键add,取名AsfNeusarSoaClient,继续add子节点,选择上一步创建的AdaptiveApplicationSwComponentType节点
GeneralConfigurationProcessDesign右键add,取名AsfNeusarSoaClient,Executable选择上一步创建的节点
GeneralConfigurationProcess右键add,取名AsfNeusarSoaClient,Design和Executable Ref选择上面配置的节点,继续创建子节点StateDependentStartupConfig,选择之前配置的节点
配置InstanceToMachineMapping CommunicationManagement->SomeipServiceInstanceToMachineMapping右键add
配置ServiceInstanceToPortPrototypeMapping CommunicationManagement->ServiceInstanceToPortPrototypeMapping右键add
继续添加子节点选择FieldGetterAdapterForS2S,配置SignalMapping,填入VCU_Sample_Ctrl0_ Msg、VCU_SampleRXSig_Ctrl0_1
添加FieldSetterAdapterForS2S子节点,配置SignalMapping,填入BMS_Sample_Ctrl0_TX_1、BMS_SampleTXSig_Ctrl0_1
示例应用代码会生成至adaptive/hpc1/output/code/AsfNeusarSoaClient Soa服务进程代码会生成至adaptive/hpc1/output/code/AsfNeusarSoaServer
本实例中,AsfNeusarSoaClient为SOA Adapter提供服务的客户端应用程序,作为服务消费者,需要遵从《NeuSAR工具链-配置工具-Creator使用手册》和本实例文档的要求进行设计和开发,这里列出主要的客户端操作,仅供参考。
1)开始发现服务,并注册服务回调函数 <Name>Proxy::StartFindService:参见《AP产品-Communication Manage-模块API》
调用Proxy::StartFindService开始查找服务,MirrorPosFRStsAvailabilityCallback,LightCtrlAvailabilityCallback,WindowFunctionCfgAvailabilityCallback为查找到服务之后的回调函数。
2)实现服务回调函数 <Name>Proxy::<Name>Proxy(const HandleType &handle)、 <Name>Proxy::GetHandle()、HandleType::GetInstanceId():参见《AP产品-Communication Manage-模块API》
实现MirrorPosFRStsAvailabilityCallback函数,即查找到服务之后会调用该函数,该函数的主要目的是获取服务句柄mirrorposfrsts_proxy。
实现LightCtrlAvailabilityCallback函数,即查找到服务之后会调用该函数,该函数的主要目的是获取服务句柄lightctrl_proxy。
实现WindowFunctionCfgAvailabilityCallback函数,即查找到服务之后会调用该函数,该函数的主要目的是获取服务句柄windowfunctioncfg_proxy。 后续针对各服务接口的Method、Field都需要使用对应的<Service>_proxy作为句柄进行调用。
1)调用Method Method::operator()(input1,input2,...):参见《AP产品-Communication Manage-模块API》
上述代码块中使用了C++中的future特性,以进行异步编程,建议在用户应用程序中也做同样处理。 在这部分代码中调用SetLightModeMethodCall发送控制inMethod,inMethod设置为down,表示下调灯光。并使用future特性接收Method调用的返回值。
Field包含两部分:Notifier是由服务端发送,客户端接收的,是作为Event进行处理的,可以直接调用Event提供的接口;Getter和Setter是由客户端发送、服务端接收的,与Method处理类似。
1)如果未曾订阅过该Field-Notifier,则注册Field-Notifier接收回调函数,并请求订阅Field-Notifier Event::IsSubscribed()、Event::SetReceiveHandler、Event::Subscribe:参见《AP产品-Communication Manage-模块API》
若Field-Notifier订阅成功,客户端将会收到服务提供端发送的Field-Notifier消息,然后会自动调用注册的回调函数进行处理(回调函数即上述代码块中的ClientActivity::Receive_LightFieldNotifier_CallBack(),ClientActivity::Receive_EnRightMirrorYPosNotifier_CallBack())。
2)实现Field-Notifier接收回调函数 Event::GetFreeSampleCount()、Event::GetNewSamples:参见《AP产品-Communication Manage-模块API》 回调函数由用户根据实际业务需求进行具体的功能实现。
4)进行Field-Setter调用 Field::Set(const FieldType& value):参见《AP产品-Communication Manage-模块API》
上述代码块中使用了C++中的future特性,以进行异步编程,建议在用户应用程序中也做同样处理。 LightFieldSetter函数调用Setter方法,循环设置灯光值。 将此应用编译并部署到系统上去。
client object address 0x559c1ca3cfa0
enter ClientActivity init()
2023/10/09 15:25:26.134567 44603492 000 ECU1 SOAC INTM log info V 1 [Enabled console output.]
2023/10/09 15:25:26.134679 44603493 000 ECU1 SOAC PER- log warn V 1 [The Storage<persistency_manifest> location </opt/AsfNeusarSoaClient/shared/persistency_manifest.json> was not found. ]
2023/10/09 15:25:26.134754 44603494 001 ECU1 SOAC PER- log info V 2 [Failed to load manifest database due to: persistency_manifest]
Version: SOMEIP.1.1911.P00AP.02
2023-10-09 15:25:26.135824 [info] load_unicast_multicast_address port:30490 unicast_ip:172.30.30.30 multicast_ip=224.224.224.245
2023-10-09 15:25:26.135900 [info] set_magic_cookies_unicast_address unicast_address:127.0.0.1
2023-10-09 15:25:26.135913 [info] Parsed vsomeip configuration in 0ms
2023-10-09 15:25:26.135923 [info] Using configuration file: "../../etc/vsomeip.json".
2023-10-09 15:25:26.135934 [info] Default configuration module loaded.
2023-10-09 15:25:26.135942 [info] Initializing vsomeip application "AsfNeusarSoaClient".
2023-10-09 15:25:26.135993 [info] SOME/IP client identifier configured. Using 000a (was: 0000)
2023-10-09 15:25:26.136004 [info] Instantiating routing manager [Proxy].
2023-10-09 15:25:26.136024 [info] Client [a] is connecting to [0] at /tmp/vsomeip-0
2023-10-09 15:25:26.136041 [info] Using e2e configuration file: /etc/e2e_configuration.json
2023-10-09 15:25:26.136053 [info] E2E protection disabled.
2023-10-09 15:25:26.136076 [info] Listening at /tmp/vsomeip-a
2023-10-09 15:25:26.136084 [info] Application(AsfNeusarSoaClient, a) is initialized (11, 100).
2023-10-09 15:25:26.136124 [info] Starting vsomeip application "AsfNeusarSoaClient" using 2 threads
2023-10-09 15:25:26.136254 [info] io thread id from application: 000a (AsfNeusarSoaClient) is: 7f3a456ed700
2023-10-09 15:25:26.136358 [info] main dispatch thread id from application: 000a (AsfNeusarSoaClient) is: 7f3a44eec700
2023-10-09 15:25:26.136417 [info] Client a successfully connected to routing ~> registering..
2023-10-09 15:25:26.136496 [info] shutdown thread id from application: 000a (AsfNeusarSoaClient) is: 7f3a3ffff700
2023-10-09 15:25:26.136514 [info] io thread id from application: 000a (AsfNeusarSoaClient) is: 7f3a3f7fe700
2023-10-09 15:25:26.136619 [info] Application/Client a is registered.
2023/10/09 15:25:26.136928 44603516 000 ECU1 SOAC S2S- log info V 2 [Using s2s configuration file: /etc/s2s_config.json]
2023/10/09 15:25:26.136941 44603516 001 ECU1 SOAC S2S- log info V 2 [Begin to loading S2S configuartion /etc/s2s_config.json]
2023/10/09 15:25:26.136984 44603516 002 ECU1 SOAC S2S- log error V 2 [Loading S2S configuration Failed : /etc/s2s_config.json: cannot open file]
2023/10/09 15:25:26.136994 44603516 003 ECU1 SOAC S2S- log info V 2 [Parse S2S configuration status: 0]
2023/10/09 15:25:26.137009 44603516 000 ECU1 SOAC VSOM log debug V 1 [StartFindService IAM iam_handler_ NULL!]
2023-10-09 15:25:26.137017 [info] routing_manager_proxy::request_service service 1032 instance 1 is static Service Discovery: False
2023/10/09 15:25:26.137031 44603517 001 ECU1 SOAC VSOM log info V 4 [StartFindService RegisterFindServiceHandle service_id: 0x1032 instance_id: 0x0001]
2023/10/09 15:25:26.137047 44603517 002 ECU1 SOAC VSOM log debug V 1 [StartFindService IAM iam_handler_ NULL!]
2023-10-09 15:25:26.137053 [info] routing_manager_proxy::request_service service 2001 instance 1 is static Service Discovery: False
2023/10/09 15:25:26.137060 44603517 003 ECU1 SOAC VSOM log info V 4 [StartFindService RegisterFindServiceHandle service_id: 0x2001 instance_id: 0x0001]
2023/10/09 15:25:26.137069 44603517 004 ECU1 SOAC VSOM log debug V 1 [StartFindService IAM iam_handler_ NULL!]
2023-10-09 15:25:26.137074 [info] routing_manager_proxy::request_service service 100b instance 1 is static Service Discovery: False
2023/10/09 15:25:26.137080 44603517 005 ECU1 SOAC VSOM log info V 4 [StartFindService RegisterFindServiceHandle service_id: 0x100b instance_id: 0x0001]
Now, let's start doing something...
enter WindowFunctionCfg_act
enter MirrorPosFRSts_act
enter LightCtrl_act
2023/10/09 15:25:26.137278 44603519 006 ECU1 SOAC VSOM log debug V 6 [VSomeIPProxyFactoryImpl AvailabilityHandler available: 0 service_id: 0x1032 instance_id: 0x0001]
2023/10/09 15:25:26.137548 44603522 007 ECU1 SOAC VSOM log info V 2 [StartFindService callback the service is not available service_id: 0x1032]
[MirrorPosFRSts] Service.instance is not available: 4146.1
2023/10/09 15:25:26.137818 44603525 008 ECU1 SOAC VSOM log debug V 6 [VSomeIPProxyFactoryImpl AvailabilityHandler available: 0 service_id: 0x2001 instance_id: 0x0001]
2023/10/09 15:25:26.137925 44603526 009 ECU1 SOAC VSOM log info V 2 [StartFindService callback the service is not available service_id: 0x2001]
[LightCtrl] Service.instance is not available: 8193.1
2023/10/09 15:25:26.138143 44603528 010 ECU1 SOAC VSOM log debug V 6 [VSomeIPProxyFactoryImpl AvailabilityHandler available: 0 service_id: 0x100b instance_id: 0x0001]
2023/10/09 15:25:26.138312 44603529 011 ECU1 SOAC VSOM log info V 2 [StartFindService callback the service is not available service_id: 0x100b]
[WindowFunctionCfg] Service.instance is not available: 4107.1
2023-10-09 15:25:26.147519 [error] Have not APP unicass address and locators service:4107 _instance:1
2023-10-09 15:25:26.147528 [info] APP get_unicast_address its_unicast_address:127.0.0.1 service:100b _instance:1
2023-10-09 15:25:26.147533 [error] Have not APP unicass address and locators service:4146 _instance:1
2023-10-09 15:25:26.147535 [info] APP get_unicast_address its_unicast_address:127.0.0.1 service:1032 _instance:1
2023-10-09 15:25:26.147538 [error] Have not APP unicass address and locators service:8193 _instance:1
2023-10-09 15:25:26.147540 [info] APP get_unicast_address its_unicast_address:127.0.0.1 service:2001 _instance:1
2023-10-09 15:25:26.147634 [info] application_impl::on_availability handler _service:100b _instance:1 _is_available:true
2023-10-09 15:25:26.147662 [info] ON_AVAILABLE(000a): [100b.0001:1.1]
2023-10-09 15:25:26.147672 [info] application_impl::on_availability handler _service:1032 _instance:1 _is_available:true
2023-10-09 15:25:26.147675 [info] ON_AVAILABLE(000a): [1032.0001:1.1]
2023-10-09 15:25:26.147688 [info] application_impl::on_availability handler _service:2001 _instance:1 _is_available:true
2023-10-09 15:25:26.147701 [info] ON_AVAILABLE(000a): [2001.0001:1.1]
2023/10/09 15:25:26.147717 44603624 012 ECU1 SOAC VSOM log debug V 6 [VSomeIPProxyFactoryImpl AvailabilityHandler available: 1 service_id: 0x100b instance_id: 0x0001]
2023/10/09 15:25:26.147741 44603624 013 ECU1 SOAC VSOM log info V 4 [StartFindService callback the service is available service_id: 0x100b instance_id 0x0001]
[WindowFunctionCfg] Instance 1 is available
[WindowFunctionCfg] Created proxy from handle with instance: 1
2023/10/09 15:25:26.147775 44603624 014 ECU1 SOAC VSOM log debug V 6 [VSomeIPProxyFactoryImpl AvailabilityHandler available: 1 service_id: 0x1032 instance_id: 0x0001]
2023/10/09 15:25:26.147785 44603624 015 ECU1 SOAC VSOM log info V 4 [StartFindService callback the service is available service_id: 0x1032 instance_id 0x0001]
[MirrorPosFRSts] Instance 1 is available
[MirrorPosFRSts] Created proxy from handle with instance: 1
2023/10/09 15:25:26.147807 44603624 016 ECU1 SOAC VSOM log debug V 6 [VSomeIPProxyFactoryImpl AvailabilityHandler available: 1 service_id: 0x2001 instance_id: 0x0001]
2023/10/09 15:25:26.147816 44603625 017 ECU1 SOAC VSOM log info V 4 [StartFindService callback the service is available service_id: 0x2001 instance_id 0x0001]
[LightCtrl] Instance 1 is available
[LightCtrl] Created proxy from handle with instance: 1
enter WindowFunctionCfg_act
2023/10/09 15:25:28.137737 44623524 018 ECU1 SOAC VSOM log debug V 1 [METHOD IAM iam_handler NULL!]
2023/10/09 15:25:28.137774 44623524 019 ECU1 SOAC VSOM log debug V 6 [registerMethodHandler service_id: 0x100b instance_id: 0x0001 method_id: 0x6003]
2023-10-09 15:25:28.137792 [info] application_impl::register_message_handler _service:100b _instance:1 _method:6003
2023-10-09 15:25:28.137836 [info] Client [a] is connecting to [9] at /tmp/vsomeip-9
2023-10-09 15:25:28.137877 [warning] connection not establish, send directly return
enter MirrorPosFRSts_act
2023/10/09 15:25:28.137908 44623525 020 ECU1 SOAC VSOM log info V 6 [Set Event Receive Handler service_id: 0x1032 instance_id: 0x0001 event_id: 0x8001]
2023/10/09 15:25:28.137930 44623526 021 ECU1 SOAC VSOM log info V 6 [Subscribe service_id: 0x1032 instance_id: 0x0001 event_id: 0x8001]
2023/10/09 15:25:28.137937 44623526 022 ECU1 SOAC VSOM log info V 1 [EVENT IAM iam_handler NULL!]
2023-10-09 15:25:28.137954 [info] application_impl::register_message_handler _service:1032 _instance:1 _method:8001
2023-10-09 15:25:28.137972 [info] routing_manager_proxy::register_event service 4146 instance 1 state 0
2023-10-09 15:25:28.138007 [info] routing_manager_proxy::subscribe _eventgroup:1 _service:1032 _instance:1 is static Service Discovery: False
2023/10/09 15:25:28.138020 44623527 023 ECU1 SOAC VSOM log debug V 1 [METHOD IAM iam_handler NULL!]
2023/10/09 15:25:28.138029 44623527 024 ECU1 SOAC VSOM log debug V 6 [registerMethodHandler service_id: 0x1032 instance_id: 0x0001 method_id: 0x0001]
2023-10-09 15:25:28.138034 [info] application_impl::register_message_handler _service:1032 _instance:1 _method:1
enter LightCtrl_act
2023/10/09 15:25:28.138061 44623527 025 ECU1 SOAC VSOM log debug V 1 [METHOD IAM iam_handler NULL!]
2023/10/09 15:25:28.138070 44623527 026 ECU1 SOAC VSOM log debug V 6 [registerMethodHandler service_id: 0x2001 instance_id: 0x0001 method_id: 0x5001]
2023-10-09 15:25:28.138076 [info] application_impl::register_message_handler _service:2001 _instance:1 _method:5001
2023-10-09 15:25:28.139858 [info] SUBSCRIBE ACK(0009): [1032.0001.0001.8001]2023/10/09 15:25:28.139974 44623546 027 ECU1 SOAC VSOM log info V 11 [subscription status notify: service[ 4146 ] instance[ 1 ] event group[ 1 ] event[ 32769 status[ 0 ]]
[MirrorPosFRSts.EnRightMirrorYPos] Receive_Notifier_CallBack: 0
[MirrorPosFRSts.EnRightMirrorYPos] Receive_Notifier_CallBack: 1
[windowfunctioncfg.WindowCfg]-Setter: reset 0
[mirrorposfrsts.EnRightMirrorYPos]-Getter: Current value is { 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 }
[lightctrl.LightField]-Getter: Current value is { 0x01 }
2023/10/09 15:25:28.142358 44623570 028 ECU1 SOAC VSOM log debug V 1 [METHOD IAM iam_handler NULL!]
2023/10/09 15:25:28.142390 44623570 029 ECU1 SOAC VSOM log debug V 6 [registerMethodHandler service_id: 0x2001 instance_id: 0x0001 method_id: 0x6001]
2023-10-09 15:25:28.142419 [info] application_impl::register_message_handler _service:2001 _instance:1 _method:6001
[lightctrl.LightField]-Setter: reset 1
2023/10/09 15:25:28.143501 44623581 030 ECU1 SOAC VSOM log info V 6 [Set Event Receive Handler service_id: 0x2001 instance_id: 0x0001 event_id: 0x8001]
2023/10/09 15:25:28.143523 44623582 031 ECU1 SOAC VSOM log info V 6 [Subscribe service_id: 0x2001 instance_id: 0x0001 event_id: 0x8001]
2023/10/09 15:25:28.143530 44623582 032 ECU1 SOAC VSOM log info V 1 [EVENT IAM iam_handler NULL!]
2023-10-09 15:25:28.143561 [info] application_impl::register_message_handler _service:2001 _instance:1 _method:8001
2023-10-09 15:25:28.143574 [info] routing_manager_proxy::register_event service 8193 instance 1 state 0
2023-10-09 15:25:28.143601 [info] routing_manager_proxy::subscribe _eventgroup:1 _service:2001 _instance:1 is static Service Discovery: False
2023/10/09 15:25:28.143614 44623582 033 ECU1 SOAC VSOM log debug V 1 [METHOD IAM iam_handler NULL!]
2023/10/09 15:25:28.143625 44623583 034 ECU1 SOAC VSOM log debug V 6 [registerMethodHandler service_id: 0x2001 instance_id: 0x0001 method_id: 0x0001]
2023-10-09 15:25:28.143630 [info] application_impl::register_message_handler _service:2001 _instance:1 _method:1
METHODS: SetLightMode is calling, please wait ...
2023/10/09 15:25:28.143946 44623586 035 ECU1 SOAC VSOM log info V 11 [subscription status notify: service[ 8193 ] instance[ 1 ] event group[ 1 ] event[ 32769 status[ 0 ]]
2023-10-09 15:25:28.143966 [info] SUBSCRIBE ACK(0009): [2001.0001.0001.8001]
[lightctrl.SetLightMode]-Method_call: the result is success value:0
[LightCtrl.LightEvent] Receive_Event_CallBack: 1
[MirrorPosFRSts.EnRightMirrorYPos] Receive_Notifier_CallBack: 0
[MirrorPosFRSts.EnRightMirrorYPos] Receive_Notifier_CallBack: 1
[LightCtrl.LightEvent] Receive_Event_CallBack: 1
[MirrorPosFRSts.EnRightMirrorYPos] Receive_Notifier_CallBack: 0
[MirrorPosFRSts.EnRightMirrorYPos] Receive_Notifier_CallBack: 1
enter WindowFunctionCfg_act
2023/10/09 15:25:30.143094 44643577 036 ECU1 SOAC VSOM log debug V 1 [METHOD IAM iam_handler NULL!]
enter MirrorPosFRSts_act
2023/10/09 15:25:30.143182 44643578 037 ECU1 SOAC VSOM log debug V 1 [METHOD IAM iam_handler NULL!]
[windowfunctioncfg.WindowCfg]-Setter: reset 1
[mirrorposfrsts.EnRightMirrorYPos]-Getter: Current value is { 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 }
enter LightCtrl_act
2023/10/09 15:25:30.194070 44644087 038 ECU1 SOAC VSOM log debug V 1 [METHOD IAM iam_handler NULL!]
[lightctrl.LightField]-Getter: Current value is { 0x01 }
2023/10/09 15:25:30.195927 44644106 039 ECU1 SOAC VSOM log debug V 1 [METHOD IAM iam_handler NULL!]
[lightctrl.LightField]-Setter: reset 2
2023/10/09 15:25:30.197386 44644120 040 ECU1 SOAC VSOM log debug V 1 [METHOD IAM iam_handler NULL!]
METHODS: SetLightMode is calling, please wait ...
[lightctrl.SetLightMode]-Method_call: the result is success value:0
[LightCtrl.LightEvent] Receive_Event_CallBack: 1
[MirrorPosFRSts.EnRightMirrorYPos] Receive_Notifier_CallBack: 0
[MirrorPosFRSts.EnRightMirrorYPos] Receive_Notifier_CallBack: 1
[LightCtrl.LightEvent] Receive_Event_CallBack: 1
[MirrorPosFRSts.EnRightMirrorYPos] Receive_Notifier_CallBack: 0
[MirrorPosFRSts.EnRightMirrorYPos] Receive_Notifier_CallBack: 1