Files
BR_YKC/Core/User/Task/DatalinkTask.c
2026-03-31 15:46:04 +08:00

105 lines
3.6 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.
/**
******************************************************************************
* @file user\task\DatalinkTask.c
* @author luhuaishuai
* @version v0.1
* @date 2026-1-12
* @brief 数据链路任务,负责处理与云快充的通信
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "DataLinkTask.h"
#include "YkcTask.h"
#include "lwip/opt.h"
#include "lwip/api.h"
#include "lwip/sys.h"
#include "httpd.h"
/* typedef --------------------------------------------------------------------*/
/* variables ------------------------------------------------------------------*/
/* code -----------------------------------------------------------------------*/
/**
* @brief DownLinkTask_Function
*
* @note none
*
* @param taskID : 任务ID
*
* @retval runtime : 任务周期
*/
void DownLinkTask_Function(void const *argument)
{
uint8_t air724_rx_msg[UART1_RX_BUFFER_SIZE];
uint8_t rs485_rx_msg[UART3_RX_BUFFER_SIZE];
uint8_t *ykc_downlink_frame = NULL;
/* 等待 datalink_conn 初始化完成 */
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
/**/
while (1)
{
/*---------------------------------------------------获取任务运行状态---------------------------------------------------*/
TaskRunTimeStat.DownLinkTask.threads_runtime = GetTask_RunTime(DownLinkTaskID);
TaskRunTimeStat.DownLinkTask.threads_counter = GetTask_Beatcnt(DownLinkTaskID);
TaskRunTimeStat.DownLinkTask.threads_freestack = Get_Free_Stack(DownLinkTaskID);
if (xQueueReceive(Air724_Message_Queue, &air724_rx_msg, 10) == pdPASS)
{
if (air724_rx_msg[0] == 0x55 && air724_rx_msg[1] == 0xAA)
{
// 主指令解析
switch (air724_rx_msg[2])
{
// 云快冲下行解析
case 0x01:
{
uint8_t charger_index = air724_rx_msg[3];
uint8_t ykc_downlink_frame_len = air724_rx_msg[4];
memcpy(ykc_downlink_frame, &air724_rx_msg[5], ykc_downlink_frame_len);
SERVER_PACK frame;
frame.start_flag = ykc_downlink_frame[0];
frame.len = ykc_downlink_frame[1];
frame.serial = (ykc_downlink_frame[2] << 8) | ykc_downlink_frame[3];
frame.encrypt_flag = ykc_downlink_frame[4];
frame.frame_type = ykc_downlink_frame[5];
frame.data = (uint8_t *)pvPortMalloc(frame.len - 4);
memcpy(frame.data, ykc_downlink_frame + HEADER_LENGTH, frame.len - 4);
frame.crc = (ykc_downlink_frame[HEADER_LENGTH + frame.len] << 8) | ykc_downlink_frame[HEADER_LENGTH + frame.len + 1];
printf("Raw Bytes: ");
for (int i = 0; i < ykc_downlink_frame_len; i++)
{
printf("%02X ", ykc_downlink_frame[i]);
if ((i + 1) % 16 == 0) // 每16字节换行
{
printf("\r");
}
}
printf("\r");
handle_ykc_downlink(charger_index, &frame);
vPortFree(frame.data);
}
break;
}
}
}
if (xQueueReceive(RS485_Message_Queue, &rs485_rx_msg, 10) == pdPASS)
{
#ifdef DEBUG
printf("rs-485_rx_msg: %s", rs485_rx_msg);
#endif
}
}
}