/* Includes ----------------------------------------------------------------- */
#include "task\user_task.h"
#include "usart.h"
#include "device\can.h" // 引入 CAN 数据结构头文件

/* Private variables -------------------------------------------------------- */
static CAN_t can; // 用于存储从消息队列获取的 CAN 数据

/* Exported functions ------------------------------------------------------- */
void Task_PC(void *argument) {
    (void)argument; // 消除未使用参数的警告
    const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_PC; // 50Hz
    uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */

    while (1) {
        tick += delay_tick; /* 计算下一个唤醒时刻 */

        // 从消息队列获取 CAN 数据
        if (osMessageQueueGet(task_runtime.msgq.can.feedback.sick, &can, NULL, 0) == osOK) {
            // 通过 USART3 发送 sick 数据数组
            HAL_UART_Transmit(&huart3, (uint8_t *)can.sick.named.sick, sizeof(can.sick.named.sick), HAL_MAX_DELAY);
            HAL_UART_Transmit(&huart2, (uint8_t *)can.sick.named.sick, sizeof(can.sick.named.sick), HAL_MAX_DELAY);
        }

        osDelayUntil(tick); /* 运行结束，等待下一次唤醒 */
    }
}