0
0

Auto commit from DCSP - 2026/1/9 10:43:14

This commit is contained in:
xb
2026-01-09 10:43:14 +08:00
parent 0fd98e248b
commit 10d2060201
10 changed files with 186 additions and 109 deletions

View File

@@ -15,13 +15,15 @@
using namespace std;
static std::mutex scomm_mutex;
/*
* 全局变量定义
*/
/* 串口文件描述符 */
static int fd_telecontrol = -1; /* 遥控串口 - 通信机发送给通信硬件服务化 */
static int fd_telemetry = -1; /* 遥测串口 - 通信硬件服务化发送给通信机 */
static int fd_telecontrol = -1; /* 遥控串口 - 通信机发送给通信硬件服务化(遥控上行) */
static int fd_telemetry = -1; /* 遥测串口 - 通信硬件服务化发送给通信机(遥测下行) */
/* 遥测数据缓存 */
S_Comm_telemetry_data_t S_TELE; /* 维护遥测数据缓存,供状态查询使用 */
@@ -56,7 +58,7 @@ string topic_name_tlm = "Telemetry";
const char *fastdds_dest = "Com_Service";
/* 运行控制 */
static volatile int g_running = 1;
volatile int g_running = 1;
/* 函数前向声明 */
static int process_received_data(uint8_t *data, uint16_t size);
@@ -133,12 +135,16 @@ void ComHS_telemetry_Pub(uint8_t *data, string dest, uint16_t len)
/*
* ComHS命令回调函数
*
* 接收到的遥控指令通过send_S_COMM_Cmder()函数发送给串口
* 1、当接收到的为取遥控类型,即为取遥控指令时,触发取上行遥控
* 2、当接收到的为遥控类型即为控制指令时触发向串口写入控制命令
*
*/
void command_callback(string src, string dest, string type,
string reserve1, string reserve2,
vector<uint8_t> &data)
{
std::lock_guard<std::mutex> lock(scomm_mutex);
if (S_COMM_ON_OFF != 1) {
cerr << "S_COMM not available" << endl;
return;
@@ -149,12 +155,18 @@ void command_callback(string src, string dest, string type,
return;
}
/* 直接发送给通信机 */
uint8_t *cmd_data = data.data();
uint16_t cmd_len = data.size();
if (type == "request_command" ) {
if (data.size() == 1 && data[0] == 0x00) {
Get_S_COMM_UP_CMD();
}
} else if (type == "command") {
uint8_t *cmd_data = data.data();
uint16_t cmd_len = data.size();
send_S_COMM_Cmder(cmd_data, cmd_len);
}
/* 发送控制指令 */
send_S_COMM_Cmder(cmd_data, cmd_len);
}
/*
@@ -167,6 +179,8 @@ void telemetry_callback(string src, string dest, string type,
string reserve1, string reserve2,
vector<uint8_t> &data)
{
std::lock_guard<std::mutex> lock(scomm_mutex);
if (S_COMM_ON_OFF != 1) {
cerr << "S_COMM not available" << endl;
return;
@@ -177,9 +191,9 @@ void telemetry_callback(string src, string dest, string type,
return;
}
if (type == "command" ) {
if (type == "request_telemetry" ) {
if (data.size() == 1 && data[0] == 0xFF) {
Get_S_COMM_UP_CMD();
Get_S_COMM_Telemetry_Data();
}
} else if (type == "telemetry") {
if (data.size() >= sizeof(Multi_EPDU_packet_t)) {
@@ -662,7 +676,7 @@ static int process_received_data(uint8_t *data, uint16_t size)
}
/*
* 启动SCOMM服务同步模式使用select超时
* 启动SCOMM服务
*
* @dev_telec: 遥控串口设备
* @dev_telem: 遥测串口设备
@@ -670,9 +684,6 @@ static int process_received_data(uint8_t *data, uint16_t size)
*/
void start_scomm_service(const char *dev_telec, const char *dev_telem, int baudrate)
{
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
if (scomm_uart_init(dev_telec, dev_telem, baudrate) < 0) {
S_COMM_ON_OFF = 0;
cerr << "S_COMM UART init failed" << endl;