Files
BR_YKC/Core/User/App/task_ykc.c
2026-05-21 12:19:01 +08:00

152 lines
4.4 KiB
C
Raw Permalink 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\App\task_ykc.c
* @author 路淮
* @version v0.1
* @date 2026-05-21
* @brief 云快充平台交互主任务
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "task_ykc.h"
#include "lwip/opt.h"
#include "lwip/api.h"
#include "lwip/sys.h"
#include "usbd_cdc_if.h"
/**
* @funNm : ykc_task_function
* @brief : 云快充平台交互主任务
* @param : none
* @retval: none
*/
void ykc_task_function(void const *argument)
{
uint32_t now;
init_chargers();
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
osDelay(5000);
while (1)
{
now = HAL_GetTick();
for (int i = 0; i < g_charger_manager.charger_count; i++)
{
ChargerPile *pile = &g_charger_manager.charger_piles[i];
/* ========== 桩层初始化桩0~2通用只做一次 ========== */
if (pile->step < 3)
{
if (now < pile->step_tick)
continue;
switch (pile->step)
{
case 0: // 等待桩上电 + 连接本桩4G通道
{
if (pile->is_udp_online)
{
if (!g_air724_info.socket_connected[i])
{
drv_air724_connect_channel(i + 1);
pile->step_tick = now + 3000;
}
else
{
pile->step = 1;
pile->step_tick = now;
}
}
else
{
//drv_air724_query_iccid();
pile->step_tick = now + 1000;
}
}
break;
case 1: // 云快充登录认证
{
if (!pile->is_online)
{
charger_to_server_0X01(i + 1);
pile->step_tick = now + 5000;
}
else
{
pile->step = 2;
charger_to_server_0X05(1, i + 1);
pile->step_tick = now;
}
}
break;
case 2: // 云快充计费模型请求
{
if (!pile->get_model)
{
charger_to_server_0X09(i + 1);
pile->step_tick = now + 5000;
}
else
{
pile->step = 3;
pile->step_tick = now;
}
}
break;
}
continue;
}
/* ========== 枪层独立运行(每把枪独立状态机) ========== */
for (int g = 0; g < MAX_GUN_PER_CHARGER; g++)
{
ChargerGun *gun = &pile->guns[g];
if (now < gun->gun_step_tick)
continue;
switch (gun->gun_step)
{
case 0: // 运行时:周期上传实时数据 + 账单处理
{
charger_to_server_0X13(i + 1, g + 1);
host_computer_report_data(i + 1, g + 1);
if (gun->is_get_bill)
{
charger_to_server_0X3B(i + 1, g + 1);
charger_to_server_0X3B(i + 1, g + 1);
gun->is_get_bill = 0;
memset(gun->real_time_data.trade_serial, 0,
sizeof(gun->real_time_data.trade_serial));
}
gun->gun_step_tick = now + 5000;
}
break;
default:
break;
}
}
}
osDelay(10);
}
}
/**
* @funNm : ykc_timer_callback_function
* @brief : 云快充平台状态检查回调
* @param : xTimer 定时器句柄
* @retval: none
*/
void ykc_timer_callback_function(TimerHandle_t xTimer)
{
}