2026-06-24 17:31:17 +08:00
|
|
|
/*============================================================================*/
|
|
|
|
|
/* 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 "spi_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
|
|
|
|
|
#if 0
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
std::vector<byte_t> notifier_can0(void){
|
|
|
|
|
std::lock_guard<std::mutex> lock(g_can_mutex[0]);
|
|
|
|
|
return g_can_data[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<byte_t> notifier_can1(void){
|
|
|
|
|
std::lock_guard<std::mutex> lock(g_can_mutex[1]);
|
|
|
|
|
return g_can_data[1];
|
|
|
|
|
}
|
|
|
|
|
std::vector<byte_t> notifier_can2(void){
|
|
|
|
|
std::lock_guard<std::mutex> lock(g_can_mutex[2]);
|
|
|
|
|
return g_can_data[2];
|
|
|
|
|
}
|
|
|
|
|
std::vector<byte_t> notifier_can3(void){
|
|
|
|
|
std::lock_guard<std::mutex> lock(g_can_mutex[3]);
|
|
|
|
|
return g_can_data[3];
|
|
|
|
|
}
|
|
|
|
|
std::vector<byte_t> notifier_can4(void){
|
|
|
|
|
std::lock_guard<std::mutex> lock(g_can_mutex[4]);
|
|
|
|
|
return g_can_data[4];
|
|
|
|
|
}
|
|
|
|
|
std::vector<byte_t> notifier_can5(void){
|
|
|
|
|
std::lock_guard<std::mutex> lock(g_can_mutex[5]);
|
|
|
|
|
return g_can_data[5];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
2026-06-24 23:14:51 +08:00
|
|
|
return true;
|
2026-06-24 17:31:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// #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 spi_server_thread(my_spi_server_thread_func, nullptr);
|
|
|
|
|
|
|
|
|
|
// wait for threads stop
|
|
|
|
|
server_thread.join();
|
|
|
|
|
std::cout << "server_thread stopped." << std::endl;
|
|
|
|
|
|
|
|
|
|
spi_server_thread.join();
|
|
|
|
|
std::cout << "spi_server_thread stopped." << std::endl;
|
|
|
|
|
|
|
|
|
|
} catch (const std::system_error& e) {
|
|
|
|
|
std::cerr << "Thread creation failed: " << e.what() << std::endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|