Files

152 lines
4.4 KiB
C
Raw Permalink Normal View History

2026-05-21 10:01:28 +08:00
/**
******************************************************************************
2026-05-21 12:19:01 +08:00
* @file User\App\task_ykc.c
* @author
2026-05-21 10:01:28 +08:00
* @version v0.1
2026-05-21 12:19:01 +08:00
* @date 2026-05-21
* @brief
2026-05-21 10:01:28 +08:00
******************************************************************************
*/
/* 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 :
2026-05-21 12:19:01 +08:00
* @param : none
* @retval: none
2026-05-21 10:01:28 +08:00
*/
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通道
{
2026-05-21 12:19:01 +08:00
if (pile->is_udp_online)
2026-05-21 10:01:28 +08:00
{
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
{
2026-05-21 12:19:01 +08:00
//drv_air724_query_iccid();
2026-05-21 10:01:28 +08:00
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);
}
}
/**
2026-05-21 12:19:01 +08:00
* @funNm : ykc_timer_callback_function
* @brief :
* @param : xTimer
* @retval: none
2026-05-21 10:01:28 +08:00
*/
void ykc_timer_callback_function(TimerHandle_t xTimer)
{
2026-05-21 12:19:01 +08:00
2026-05-21 10:01:28 +08:00
}