89 lines
2.3 KiB
C
89 lines
2.3 KiB
C
/*
|
|
*文件名称:referee_task.c
|
|
*功能描述:裁判系统链路监测与自定义UI刷新任务(100ms)
|
|
*备注:数据解析在USART6空闲中断内完成,本任务负责超时监测、心跳上报与UI周期发送
|
|
*/
|
|
#include "app_tasks.h"
|
|
#include "cmsis_os.h"
|
|
#include "bsp_usart.h"
|
|
#include "referee.h"
|
|
#include "referee_ui.h"
|
|
#include "c_comm.h"
|
|
#include "attitude.h"
|
|
#include "robot_param.h"
|
|
|
|
/*
|
|
*函数简介:按UI_SEND_HZ分频组装并发送选手端自定义UI数据
|
|
*参数说明:无
|
|
*返回类型:无
|
|
*备注:内部函数,由referee_task每100ms调用一次
|
|
*/
|
|
static void referee_ui_step(void)
|
|
{
|
|
static uint8_t ui_div = 0U;
|
|
|
|
if (++ui_div < (uint8_t)(10U / UI_SEND_HZ))
|
|
return;
|
|
ui_div = 0U;
|
|
|
|
ui_data_t ui = {0};
|
|
ui.pitch_deg = ctoc_ui_pitch_deg;
|
|
ui.yaw_deg = ctoc_gimbal_yaw;
|
|
ui.hdg_deg = att_deg_yaw;
|
|
ui.pwr_w = referee.chassis_power;
|
|
ui.pwr_limit_w = (float)referee.chassis_power_limit;
|
|
ui.buf_j = referee.buffer_energy;
|
|
ui.cap_pct = (uint8_t)(referee.buffer_energy >= 60.0f
|
|
? 100U
|
|
: (referee.buffer_energy * 100.0f / 60.0f));
|
|
ui.fric_l_rpm = ctoc_ui_fric_l_rpm;
|
|
ui.fric_r_rpm = ctoc_ui_fric_r_rpm;
|
|
ui.spin_on = ctoc_remote.spin_flag;
|
|
ui.ref_online = referee.link_status;
|
|
|
|
referee_ui_update(&ui);
|
|
}
|
|
|
|
/*
|
|
*函数简介:USART6裁判系统整帧接收回调
|
|
*参数说明:frame:接收帧数据指针
|
|
*参数说明:len:接收帧字节长度
|
|
*返回类型:无
|
|
*备注:将接收字节流喂入裁判系统解析状态机
|
|
*/
|
|
void referee_frame_callback(const uint8_t * frame, uint16_t len)
|
|
{
|
|
if (frame == NULL || len == 0U)
|
|
return;
|
|
|
|
referee_parse_bytes(frame, len);
|
|
}
|
|
|
|
/*
|
|
*函数简介:裁判系统链路超时监测与UI发送任务(100ms)
|
|
*参数说明:argument:FreeRTOS任务参数(未使用)
|
|
*返回类型:无
|
|
*备注:无
|
|
*/
|
|
void referee_task(void const * argument)
|
|
{
|
|
(void)argument;
|
|
|
|
while (!app_ready)
|
|
osDelay(2);
|
|
|
|
for (;;)
|
|
{
|
|
if (referee.link_status &&
|
|
(HAL_GetTick() - referee.last_update_tick > DEVICE_OFFLINE_TIME_MS * 10U))
|
|
{
|
|
referee.link_status = 0U;//链路超时置断线
|
|
}
|
|
|
|
referee_ui_step();
|
|
|
|
monitor_heartbeat(HB_REFEREE);
|
|
osDelay(100);
|
|
}
|
|
}
|