R2_CHASSIS/User/task/dr16_task.c
2025-03-19 21:09:20 +08:00

104 lines
3.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

///*
// DR16接收机通信任务支持DR16和SBUS双协议
//*/
///* Includes ----------------------------------------------------------------- */
//#include <string.h>
//#include "dr16.h"
//#include "LD_remote.h" // 新增 SBUS 支持
//#include "user_task.h"
///* Private typedef ---------------------------------------------------------- */
///* Private define ----------------------------------------------------------- */
//#define PROTOCOL_DR16 0
//#define PROTOCOL_SBUS 1
/* Private macro ------------------------------------------------------------ */
///* Private variables -------------------------------------------------------- */
//#ifdef DEBUG
//DR16_t dr16;
//CMD_RC_t cmd_rc;
//#else
//static DR16_t dr16;
//static CMD_RC_t cmd_rc;
//#endif
//static uint8_t protocol_type = PROTOCOL_DR16; // 当前协议类型
// uint8_t sbus_rx_buf[36]; // SBUS 数据缓冲区
///* Private function --------------------------------------------------------- */
///**
// * \brief 协议识别函数
// *
// * \param buf 接收到的数据缓冲区
// * \return uint8_t 协议类型PROTOCOL_DR16 或 PROTOCOL_SBUS
// */
//static uint8_t Detect_Protocol(const uint8_t *buf) {
// if (buf[0] == 0x0F && buf[24] == 0x00) { // SBUS 协议特征
// return PROTOCOL_SBUS;
// }
// return PROTOCOL_DR16; // 默认 DR16
//}
///**
// * \brief 统一回调函数
// */
//static void UART_RxCpltCallback(void) {
// if (Detect_Protocol(sbus_rx_buf) == PROTOCOL_SBUS) {
// protocol_type = PROTOCOL_SBUS;
// } else {
// protocol_type = PROTOCOL_DR16;
// }
// osThreadFlagsSet(osThreadGetId(), SIGNAL_DR16_RAW_REDY);
//}
///* Exported functions ------------------------------------------------------- */
///**
// * \brief dr16接收机任务支持DR16和SBUS双协议
// *
// * \param argument 未使用
// */
//void Task_dr16(void *argument) {
// (void)argument; /* 未使用,消除警告 */
// DR16_Init(&dr16); /* 初始化 DR16 */
// RC_New_Init(); /* 初始化 SBUS */
// while (1) {
//#ifdef DEBUG
// /* 调试信息:堆栈水位 */
// task_runtime.stack_water_mark.dr16 = osThreadGetStackSpace(osThreadGetId());
//#endif
// /* 开启 DMA 接收 */
// if (protocol_type == PROTOCOL_DR16) {
// DR16_StartDmaRecv(&dr16);
// } else {
// HAL_UARTEx_ReceiveToIdle_DMA(&huart3, sbus_rx_buf, sizeof(sbus_rx_buf));
// }
// /* 等待 DMA 完成 */
// if (DR16_WaitDmaCplt(30)) {
// if (protocol_type == PROTOCOL_DR16) {
// /* DR16 数据处理 */
// DR16_ParseRaw(&dr16);
// DR16_ParseRC(&dr16, &cmd_rc);
// } else {
// /* SBUS 数据处理 */
// const RC_Ctrl_New_t *sbus_data = RC_New_GetData();
// cmd_rc.ch_r_x = sbus_data->ch[0] / 1000.0f; // 映射到 [-1, 1]
// cmd_rc.ch_r_y = sbus_data->ch[1] / 1000.0f;
// cmd_rc.ch_l_x = sbus_data->ch[2] / 1000.0f;
// cmd_rc.ch_l_y = sbus_data->ch[3] / 1000.0f;
// }
// } else {
// /* 处理遥控器离线 */
// DR16_HandleOffline(&dr16, &cmd_rc);
// }
// /* 发送数据到消息队列 */
// osMessageQueueReset(task_runtime.msgq.cmd.raw.rc);
// osMessageQueuePut(task_runtime.msgq.cmd.raw.rc, &cmd_rc, 0, 0);
// }
//}