369 lines
12 KiB
C++
369 lines
12 KiB
C++
/*============================================================================*/
|
|
/* Copyright (C) huaxu (2026).
|
|
*
|
|
* All rights reserved. This software is huaxu property. Duplication
|
|
* or disclosure without huaxu written authorization is prohibited.
|
|
*
|
|
* @file your_app.cpp
|
|
* @brief main entry of your_app
|
|
* @author LiuZhimin
|
|
* @date 2026-02-24 15:20:00
|
|
*/
|
|
/*============================================================================*/
|
|
/*=======[R E V I S I O N H I S T O R Y]====================================*/
|
|
/* <VERSION> <DATE> <AUTHOR> <REVISION LOG>
|
|
* V0.0.1 20260606 Liuzhimin Initial version
|
|
*/
|
|
/*============================================================================*/
|
|
|
|
/*=======[I N C L U D E S]====================================================*/
|
|
|
|
#include <stdio.h>
|
|
#include <pthread.h>
|
|
#include <unistd.h>
|
|
|
|
#include "someip_server_cfg.hpp"
|
|
#include "someip_client_cfg.hpp"
|
|
//#include "someip_server.hpp"
|
|
#include <list>
|
|
//#include "location_mgt_api.h"
|
|
|
|
using namespace vsomeip;
|
|
/*=======[G L O B A L D A T A]==============================================*/
|
|
|
|
/*=======[M A C R O S]========================================================*/
|
|
|
|
/*=======[I N T E R N A L D A T A]==========================================*/
|
|
|
|
/*=======[L O C A L F U N C T I O N D E C L A R A T I O N S]==============*/
|
|
|
|
/*=======[L O C A L F U N C T I O N I M P L E M E N T A T I O N S]========*/
|
|
|
|
/*=======[G L O B A L F U N C T I O N I M P L E M E N T A T I O N S]======*/
|
|
// methods' data functions
|
|
std::vector<byte_t> rr_method_example1(void){
|
|
/* 1.receive this example, and add your code do your action here */
|
|
//...
|
|
|
|
/* 2.And than give response data */
|
|
std::string example_string = "Hello China.";
|
|
std::vector<byte_t> data;
|
|
data.assign(example_string.begin(),example_string.end());
|
|
return data;
|
|
}
|
|
|
|
// events' data functions
|
|
std::vector<byte_t> rr_method_example2(void){
|
|
/* 1.receive this example, and add your code do your action here */
|
|
//...
|
|
|
|
/* 2.And than give response data */
|
|
std::string example_string = "Hello GuangZhou.";
|
|
std::vector<byte_t> data;
|
|
data.assign(example_string.begin(),example_string.end());
|
|
return data;
|
|
}
|
|
|
|
std::vector<byte_t> ff_method_example1(void){
|
|
/* 1.Add your code do your action here */
|
|
//...
|
|
|
|
/* reserve,no need data to reponse*/
|
|
std::vector<byte_t> data;
|
|
return data;
|
|
}
|
|
|
|
std::vector<byte_t> ff_method_example2(void){
|
|
/* 1.Add your code do your action here */
|
|
//...
|
|
|
|
/* reserve,no need data to reponse*/
|
|
std::vector<byte_t> data;
|
|
return data;
|
|
}
|
|
|
|
std::vector<byte_t> getter_example1(void){
|
|
std::vector<byte_t> data;
|
|
/* 1.Add your code do get a feature value */
|
|
//...
|
|
|
|
/* 2.And than response value to data */
|
|
std::string example_string = "This is an getter example.";
|
|
data.assign(example_string.begin(),example_string.end());
|
|
return data;
|
|
}
|
|
|
|
std::vector<byte_t> getter_example2(void){
|
|
std::vector<byte_t> data;
|
|
/* 1.Add your code do get a feature value */
|
|
//...
|
|
|
|
/* 2.And than response value to data */
|
|
std::string example_string = "This is an getter example2.";
|
|
data.assign(example_string.begin(),example_string.end());
|
|
return data;
|
|
}
|
|
|
|
std::vector<byte_t> setter_example1(void){
|
|
std::vector<byte_t> data;
|
|
/* 1.Add your code do set a feature value */
|
|
//...
|
|
|
|
/* 2.And than response state to client */
|
|
std::string example_string = "Setter xxx is success.";
|
|
data.assign(example_string.begin(),example_string.end());
|
|
|
|
/* 3. If need, you can add your Notify response here */
|
|
// ...
|
|
return data;
|
|
}
|
|
|
|
std::vector<byte_t> setter_example2(void){
|
|
std::vector<byte_t> data;
|
|
/* 1.Add your code do set a feature value */
|
|
//...
|
|
|
|
/* 2.And than response state to client */
|
|
std::string example_string = "Setter xxx is success2.";
|
|
data.assign(example_string.begin(),example_string.end());
|
|
|
|
/* 3. If need, you can add your Notify response here */
|
|
// ...
|
|
return data;
|
|
}
|
|
|
|
std::vector<byte_t> event_example1(void){
|
|
|
|
std::vector<byte_t> data;
|
|
/* Add your handle logic here for data to notify */
|
|
// ...
|
|
|
|
std::string example_string = "info is empty.";
|
|
data.assign(example_string.begin(),example_string.end());
|
|
return data;
|
|
}
|
|
|
|
std::vector<byte_t> event_example2(void){
|
|
|
|
std::vector<byte_t> data;
|
|
/* Add your handle logic here for data to notify */
|
|
// ...
|
|
|
|
std::string example_string = "info is empty.";
|
|
data.assign(example_string.begin(),example_string.end());
|
|
return data;
|
|
}
|
|
|
|
std::vector<byte_t> notifier_example1(void){
|
|
|
|
std::vector<byte_t> data;
|
|
/* Add your handle logic here for data to notify */
|
|
// ...
|
|
|
|
std::string example_string = "info is empty.";
|
|
data.assign(example_string.begin(),example_string.end());
|
|
return data;
|
|
}
|
|
|
|
std::vector<byte_t> notifier_example2(void){
|
|
|
|
std::vector<byte_t> data;
|
|
/* Add your handle logic here for data to notify */
|
|
// ...
|
|
|
|
std::string example_string = "info is empty.";
|
|
data.assign(example_string.begin(),example_string.end());
|
|
return data;
|
|
}
|
|
|
|
bool epsilon_func(std::shared_ptr<vsomeip::payload> _old, std::shared_ptr<vsomeip::payload> _new)
|
|
{
|
|
// TODO: add your logic here to compare _old and _new
|
|
return false;
|
|
};
|
|
|
|
/* CLENT */
|
|
std::vector<byte_t> req_rr_method_example1(void)
|
|
{
|
|
static bool trrigger_method = false;
|
|
/* 1.Add your code here to give request data */
|
|
/* 1.1: data[0] is request flag : true/false */
|
|
// ...
|
|
|
|
std::vector<byte_t> data;
|
|
data.push_back(trrigger_method); /* data[0]*/
|
|
if (trrigger_method){
|
|
/* reset trrigger_method */
|
|
trrigger_method = false;
|
|
}
|
|
/* 1.2. Add your other request data to data[1]~... */
|
|
std::string example_string = "reqeust data.";
|
|
data.insert(data.end(),example_string.begin(),example_string.end());
|
|
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
std::vector<byte_t> req_ff_method_example1(void)
|
|
{
|
|
static bool trrigger_method = false;
|
|
/* 1.Add your code here to give request data */
|
|
/* 1.1: data[0] is request flag : true/false */
|
|
// ...
|
|
|
|
std::vector<byte_t> data;
|
|
data.push_back(trrigger_method); /* data[0]*/
|
|
if (trrigger_method){
|
|
/* reset trrigger_method */
|
|
trrigger_method = false;
|
|
}
|
|
/* 1.2. Add your other request data to data[1]~... */
|
|
std::string example_string = "reqeust data.";
|
|
data.insert(data.end(),example_string.begin(),example_string.end());
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
std::vector<byte_t> req_getter_example1(void)
|
|
{
|
|
static bool trrigger_method = false;
|
|
/* 1.Add your code here to give request data */
|
|
/* 1.1: data[0] is request flag : true/false */
|
|
// ...
|
|
|
|
std::vector<byte_t> data;
|
|
data.push_back(trrigger_method); /* data[0]*/
|
|
if (trrigger_method){
|
|
/* reset trrigger_method */
|
|
trrigger_method = false;
|
|
}
|
|
/* 1.2. Add your other request data to data[1]~... */
|
|
std::string example_string = "reqeust data.";
|
|
data.insert(data.end(),example_string.begin(),example_string.end());
|
|
|
|
|
|
return data;
|
|
}
|
|
std::vector<byte_t> req_setter_example1(void)
|
|
{
|
|
static bool trrigger_method = false;
|
|
/* 1.Add your code here to give request data */
|
|
/* 1.1: data[0] is request flag : true/false */
|
|
// ...
|
|
|
|
std::vector<byte_t> data;
|
|
data.push_back(trrigger_method); /* data[0]*/
|
|
if (trrigger_method){
|
|
/* reset trrigger_method */
|
|
trrigger_method = false;
|
|
}
|
|
/* 1.2. Add your other request data to data[1]~... */
|
|
std::string example_string = "reqeust data.";
|
|
data.insert(data.end(),example_string.begin(),example_string.end());
|
|
|
|
|
|
return data;
|
|
}
|
|
|
|
void msg_rr_method_example1(const std::shared_ptr<message> &_response)
|
|
{
|
|
std::shared_ptr<payload> res_payload =_response->get_payload();
|
|
someip_log_i("Received a message from Server/instance/method [0x%04x.0x%04x.0x%04x] to Client/Session [0x%04x.0x%04x].",
|
|
_response->get_service(), _response->get_instance(), _response->get_method(),
|
|
_response->get_client(), _response->get_session());
|
|
/* 1. Add your logic here to handle this response payload */
|
|
// res_payload ...
|
|
|
|
}
|
|
#if 0 /* FF-method no need massage response handler */
|
|
void msg_ff_method_example1(const std::shared_ptr<message> &_response)
|
|
{
|
|
/* nothing*/
|
|
}
|
|
#endif
|
|
void msg_getter_example1(const std::shared_ptr<message> &_response)
|
|
{
|
|
std::shared_ptr<payload> res_payload =_response->get_payload();
|
|
someip_log_i("Received a message from Server/instance/method [0x%04x.0x%04x.0x%04x] to Client/Session [0x%04x.0x%04x].",
|
|
_response->get_service(), _response->get_instance(), _response->get_method(),
|
|
_response->get_client(), _response->get_session());
|
|
/* 1. Add your logic here to handle this response payload */
|
|
// res_payload ...
|
|
|
|
|
|
}
|
|
void msg_setter_example1(const std::shared_ptr<message> &_response)
|
|
{
|
|
std::shared_ptr<payload> res_payload =_response->get_payload();
|
|
someip_log_i("Received a message from Server/instance/method [0x%04x.0x%04x.0x%04x] to Client/Session [0x%04x.0x%04x].",
|
|
_response->get_service(), _response->get_instance(), _response->get_method(),
|
|
_response->get_client(), _response->get_session());
|
|
/* 1. Add your logic here to handle this response payload */
|
|
// res_payload ...
|
|
|
|
}
|
|
void msg_event_example1(const std::shared_ptr<message> &_response)
|
|
{
|
|
std::shared_ptr<payload> res_payload =_response->get_payload();
|
|
someip_log_i("Received a message from Server/instance/event [0x%04x.0x%04x.0x%04x] to Client/Session [0x%04x.0x%04x].",
|
|
_response->get_service(), _response->get_instance(), _response->get_method(),
|
|
_response->get_client(), _response->get_session());
|
|
/* 1. Add your logic here to handle this response payload */
|
|
// res_payload ...
|
|
|
|
}
|
|
void msg_notifier_example1(const std::shared_ptr<message> &_response)
|
|
{
|
|
std::shared_ptr<payload> res_payload =_response->get_payload();
|
|
someip_log_i("Received a message from Server/instance/event [0x%04x.0x%04x.0x%04x] to Client/Session [0x%04x.0x%04x].",
|
|
_response->get_service(), _response->get_instance(), _response->get_method(),
|
|
_response->get_client(), _response->get_session());
|
|
/* 1. Add your logic here to handle this response payload */
|
|
// res_payload ...
|
|
|
|
}
|
|
|
|
// #ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
|
|
// //service *server_ptr(nullptr);
|
|
// void handle_signal(int _signal)
|
|
// {
|
|
// if (server_ptr != nullptr &&
|
|
// (_signal == SIGINT || _signal == SIGTERM
|
|
// || _signal == SIGKILL))
|
|
// server_ptr->stop();
|
|
// }
|
|
// #endif
|
|
|
|
|
|
// service server;
|
|
// someip_log_i("start someip server");
|
|
|
|
// #ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
|
|
// server_ptr = &server;
|
|
// signal(SIGINT, handle_signal);
|
|
// signal(SIGTERM, handle_signal);
|
|
// signal(SIGKILL, handle_signal);
|
|
// #endif
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
printf("start your_app\r\n");
|
|
try {
|
|
std::thread server_thread(my_someip_server_thread_func, nullptr);
|
|
std::thread client_thread(my_someip_client_thread_func, nullptr);
|
|
|
|
// wait for threads stop
|
|
server_thread.join();
|
|
std::cout << "server_thread stopped." << std::endl;
|
|
|
|
client_thread.join();
|
|
std::cout << "client_thread stopped." << std::endl;
|
|
|
|
} catch (const std::system_error& e) {
|
|
std::cerr << "Thread creation failed: " << e.what() << std::endl;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
} |