fix:删除4G模组tools目录
This commit is contained in:
@@ -9,11 +9,34 @@
|
||||
*/
|
||||
/* Includes -------------------------------------------------------------------*/
|
||||
#include "drv_init.h"
|
||||
// crc16_modbus.c
|
||||
#include <stdint.h>
|
||||
|
||||
/* code -----------------------------------------------------------------------*/
|
||||
|
||||
void send_cmd_to_air724(uint8_t *cmd, uint16_t len)
|
||||
{
|
||||
Air724_Message_Send(cmd, len);
|
||||
}
|
||||
void send_server_address_to_air724(void)
|
||||
{
|
||||
char ip[] = YKC_SERVER_IP;
|
||||
char port[6];
|
||||
sprintf(port, "%d", YKC_SERVER_PORT);
|
||||
|
||||
uint8_t len = strlen(ip) + 1 + strlen(port);
|
||||
uint8_t config_cmd[256] = {0x55, 0xAA, 0x04, 0x00, len};
|
||||
|
||||
uint8_t pos = 5;
|
||||
memcpy(&config_cmd[pos], ip, strlen(ip));
|
||||
pos += strlen(ip);
|
||||
config_cmd[pos++] = 0x00;
|
||||
memcpy(&config_cmd[pos], port, strlen(port));
|
||||
pos += strlen(port);
|
||||
config_cmd[pos++] = 0xAA;
|
||||
config_cmd[pos++] = 0x55;
|
||||
send_cmd_to_air724(config_cmd, pos);
|
||||
pos = 0;
|
||||
memset(config_cmd, 0, sizeof(config_cmd));
|
||||
}
|
||||
/**
|
||||
* @brief drv_all_Init:所有传感器、外设芯片、外部设备初始化
|
||||
*
|
||||
@@ -26,5 +49,5 @@
|
||||
|
||||
void drv_all_Init(void)
|
||||
{
|
||||
AIR724_RESET(); /* AIR724 复位 */
|
||||
AIR724_RESET(); /* AIR724 复位 */
|
||||
}
|
||||
|
||||
@@ -10,6 +10,5 @@
|
||||
/* Exported functions prototypes ------------------------------------------------------------------------*/
|
||||
void drv_all_Init(void);
|
||||
|
||||
|
||||
#endif /* __DRVINIT_H */
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ const uint8_t piles_serial[6][7] = {
|
||||
{0x88, 0x26, 0x01, 0x13, 0x12, 0x00, 0x03},
|
||||
{0x88, 0x26, 0x01, 0x13, 0x12, 0x00, 0x04},
|
||||
{0x88, 0x26, 0x01, 0x13, 0x12, 0x00, 0x05},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
/* includes ----------------------------------------------------------------------------------------------*/
|
||||
#include "global.h"
|
||||
|
||||
#define MAX_CHARGER_COUNT 6 // 充电桩数量
|
||||
#define MAX_CHARGER_COUNT 2 // 充电桩数量
|
||||
#define MAX_GUN_PER_CHARGER 2 // 每个充电桩最多枪数
|
||||
|
||||
/* 充电枪结构体*/
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
// #include "tim.h"
|
||||
|
||||
/* freeRTOS 相关 */
|
||||
#include "cmsis_os.h"
|
||||
#include "FreeRTOS.h"
|
||||
@@ -72,6 +70,9 @@
|
||||
|
||||
#define DEBUG 1 // 调试模式
|
||||
|
||||
#define YKC_SERVER_IP "121.43.69.62" // YKC 服务器 IP 地址
|
||||
#define YKC_SERVER_PORT 8767 // YKC 服务器端口号
|
||||
|
||||
/*- I/O 输出-*/
|
||||
|
||||
#define AIR724_RESET() \
|
||||
|
||||
@@ -18,6 +18,8 @@ uint8_t uart1_tx_buffer[UART1_TX_BUFFER_SIZE];
|
||||
uint8_t uart3_rx_buffer[UART3_RX_BUFFER_SIZE];
|
||||
uint8_t uart3_tx_buffer[UART3_TX_BUFFER_SIZE];
|
||||
|
||||
static SemaphoreHandle_t air724_tx_mutex = NULL;
|
||||
|
||||
/* code -----------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief fputc:printf映射
|
||||
@@ -46,7 +48,18 @@ int fputc(int ch, FILE *f)
|
||||
*/
|
||||
void Air724_Message_Send(uint8_t *data, uint16_t len)
|
||||
{
|
||||
HAL_UART_Transmit(&huart1, data, len, HAL_MAX_DELAY);
|
||||
if (air724_tx_mutex != NULL)
|
||||
{
|
||||
if (xSemaphoreTake(air724_tx_mutex, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
HAL_UART_Transmit(&huart1, data, len, HAL_MAX_DELAY);
|
||||
xSemaphoreGive(air724_tx_mutex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_UART_Transmit(&huart1, data, len, HAL_MAX_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
void Rs485_Message_Send(uint8_t *data, uint16_t len)
|
||||
@@ -68,6 +81,7 @@ void Rs485_Message_Send(uint8_t *data, uint16_t len)
|
||||
|
||||
void hal_usart_Init(void)
|
||||
{
|
||||
air724_tx_mutex = xSemaphoreCreateMutex();
|
||||
|
||||
/* 初始化串口1 */
|
||||
Air724_Message_Queue_Init(); // 初始化4G数据接收队列
|
||||
|
||||
@@ -89,7 +89,7 @@ void UDP_ParseTask_Function(void const *argument)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Missing 'code' field\r\n");
|
||||
printf("Missing 'code' field from \r\n");
|
||||
cJSON_Delete(root);
|
||||
}
|
||||
vPortFree(msg.data);
|
||||
@@ -145,9 +145,10 @@ void UDPTask_Function(void const *argument)
|
||||
{
|
||||
memcpy(msg.data, playload, playload_len);
|
||||
msg.data[playload_len] = '\0';
|
||||
// 队列满,释放数据内存
|
||||
if (xQueueSend(UDP_Message_Queue, &msg, 0) != pdPASS)
|
||||
{
|
||||
vPortFree(msg.data);
|
||||
vPortFree(msg.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,6 +179,70 @@ void local_on_cmd_callback_power_on(uint8_t stake_index, cJSON *json_pack)
|
||||
g_charger_manager.charger_piles[stake_index - 1].is_udp_online = true; // 设置桩为本地在线状态
|
||||
|
||||
cJSON *root = NULL;
|
||||
uint8_t *str = NULL;
|
||||
|
||||
root = cJSON_CreateObject();
|
||||
if (root == NULL)
|
||||
{
|
||||
printf("Failed to create JSON object for stake %d\r\n", stake_index);
|
||||
return;
|
||||
}
|
||||
|
||||
/* 添加一条字符串类型的JSON数据(添加一个链表节点) */
|
||||
cJSON_AddNumberToObject(root, "id", stake_index);
|
||||
cJSON_AddStringToObject(root, "cmd", "online");
|
||||
cJSON_AddStringToObject(root, "type", "response");
|
||||
|
||||
str = cJSON_Print(root);
|
||||
udp_send_response(stake_index, str, strlen(str));
|
||||
free(str);
|
||||
cJSON_Delete(root);
|
||||
|
||||
printf("南向:对电桩 %d 上电回复成功\r\n", stake_index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 解析充电桩心跳指令
|
||||
* @note 回复心跳应答
|
||||
* @param stake_index 桩索引
|
||||
* @param json_pack json数据包
|
||||
*/
|
||||
void local_on_cmd_callback_heartbeat_response(uint8_t stake_index, cJSON *json_pack)
|
||||
{
|
||||
if (stake_index > 6)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//心跳unpack
|
||||
|
||||
cJSON *gun_array = cJSON_GetObjectItem(json_pack, "gun");
|
||||
// 直接判断 type 字段
|
||||
if (gun_array == NULL || gun_array->type != cJSON_Array)
|
||||
{
|
||||
printf(" └── [error] 缺少 gun 数组\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int gun_count = cJSON_GetArraySize(gun_array);
|
||||
for (int i = 0; i < gun_count; i++)
|
||||
{
|
||||
cJSON *gun = cJSON_GetArrayItem(gun_array, i);
|
||||
if (!gun) continue;
|
||||
|
||||
cJSON *id = cJSON_GetObjectItem(gun, "id");
|
||||
cJSON *state = cJSON_GetObjectItem(gun, "state");
|
||||
|
||||
if (!id || !state) continue;
|
||||
|
||||
// if (id->valueint == 1) pile->gun1_state = state->valueint;
|
||||
// if (id->valueint == 2) pile->gun2_state = state->valueint;
|
||||
printf(" └── [info] 桩%d 枪%d state=%d\r\n", stake_index, id->valueint, state->valueint);
|
||||
}
|
||||
|
||||
//心跳回复组包
|
||||
cJSON *root = NULL;
|
||||
char *str = NULL;
|
||||
|
||||
root = cJSON_CreateObject();
|
||||
@@ -189,29 +254,15 @@ void local_on_cmd_callback_power_on(uint8_t stake_index, cJSON *json_pack)
|
||||
|
||||
/* 添加一条字符串类型的JSON数据(添加一个链表节点) */
|
||||
cJSON_AddNumberToObject(root, "id", stake_index);
|
||||
cJSON_AddStringToObject(root, "cmd", "power_on");
|
||||
cJSON_AddNumberToObject(root, "code", 1);
|
||||
cJSON_AddStringToObject(root, "cmd", "heartbeat");
|
||||
cJSON_AddStringToObject(root, "type", "response");
|
||||
|
||||
str = cJSON_Print(root);
|
||||
udp_send_response(stake_index, str, strlen(str));
|
||||
free(str);
|
||||
cJSON_Delete(root);
|
||||
|
||||
printf("电桩 %d 上电报文\r\n", stake_index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 解析充电桩计费模型请求指令
|
||||
* @note 获取云快充下发的计费模型,回复给充电桩
|
||||
* @param stake_index 桩索引
|
||||
* @param json_pack json数据包
|
||||
*/
|
||||
void local_on_cmd_callback_get_billing_model(uint8_t stake_index, cJSON *json_pack)
|
||||
{
|
||||
if (stake_index > 6)
|
||||
{
|
||||
return;
|
||||
}
|
||||
printf("南向:对电桩 %d 心跳回复成功\r\n", stake_index);
|
||||
|
||||
|
||||
}
|
||||
@@ -220,13 +271,17 @@ void handle_udp_downlink(uint8_t id, const char *cmd, cJSON *json_pack)
|
||||
{
|
||||
if (cmd == NULL)
|
||||
return;
|
||||
if (strcmp(cmd, "power_on") == 0)
|
||||
// 处理上电指令
|
||||
if (strcmp(cmd, "online") == 0)
|
||||
{
|
||||
printf("南向:收到电桩 %d 上电指令\r\n", id);
|
||||
local_on_cmd_callback_power_on(id, json_pack);
|
||||
}
|
||||
else if (strcmp(cmd, "get_billing_model") == 0)
|
||||
// 处理心跳指令
|
||||
else if (strcmp(cmd, "heartbeat") == 0)
|
||||
{
|
||||
local_on_cmd_callback_get_billing_model(id, json_pack);
|
||||
printf("南向:收到电桩 %d 心跳指令\r\n", id);
|
||||
local_on_cmd_callback_heartbeat_response(id, json_pack);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -45,7 +45,6 @@ void DownLinkTask_Function(void const *argument)
|
||||
while (1)
|
||||
{
|
||||
/*---------------------------------------------------获取任务运行状态---------------------------------------------------*/
|
||||
|
||||
TaskRunTimeStat.DownLinkTask.threads_runtime = GetTask_RunTime(DownLinkTaskID);
|
||||
TaskRunTimeStat.DownLinkTask.threads_counter = GetTask_Beatcnt(DownLinkTaskID);
|
||||
TaskRunTimeStat.DownLinkTask.threads_freestack = Get_Free_Stack(DownLinkTaskID);
|
||||
@@ -74,22 +73,30 @@ void DownLinkTask_Function(void const *argument)
|
||||
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");
|
||||
// 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;
|
||||
case 0x83:
|
||||
{
|
||||
if (air724_rx_msg[3] == 0x01)
|
||||
printf("4G:Socket %d 通道连接成功\r\n", air724_rx_msg[4]);
|
||||
if (air724_rx_msg[3] == 0x02)
|
||||
printf("4G:Socket %d 通道断开成功\r\n", air724_rx_msg[4]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,34 +13,6 @@
|
||||
|
||||
void HeartBeat_Sign(void);
|
||||
|
||||
/**
|
||||
* @brief 发送显示数据
|
||||
* @note 发送显示数据,包括充电桩的连接状态和工作状态
|
||||
*/
|
||||
void Send_Display_Data(void)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
char str[128];
|
||||
sprintf(str, "t1.bco=%s\xff\xff\xfft2.bco=%s\xff\xff\xfft3.bco=%s\xff\xff\xfft4.bco=%s\xff\xff\xfft5.bco=%s\xff\xff\xfft6.bco=%s\xff\xff\xff",
|
||||
g_charger_manager.charger_piles[0].is_udp_online ? "GREEN" : "RED",
|
||||
g_charger_manager.charger_piles[1].is_udp_online ? "GREEN" : "RED",
|
||||
g_charger_manager.charger_piles[2].is_udp_online ? "GREEN" : "RED",
|
||||
g_charger_manager.charger_piles[3].is_udp_online ? "GREEN" : "RED",
|
||||
g_charger_manager.charger_piles[4].is_udp_online ? "GREEN" : "RED",
|
||||
g_charger_manager.charger_piles[5].is_udp_online ? "GREEN" : "RED");
|
||||
Rs485_Message_Send(str, strlen(str));
|
||||
|
||||
sprintf(str, "t7.bco=%s\xff\xff\xfft8.bco=%s\xff\xff\xfft9.bco=%s\xff\xff\xfft10.bco=%s\xff\xff\xfft11.bco=%s\xff\xff\xfft12.bco=%s\xff\xff\xff",
|
||||
g_charger_manager.charger_piles[0].is_online ? "GREEN" : "RED",
|
||||
g_charger_manager.charger_piles[1].is_online ? "GREEN" : "RED",
|
||||
g_charger_manager.charger_piles[2].is_online ? "GREEN" : "RED",
|
||||
g_charger_manager.charger_piles[3].is_online ? "GREEN" : "RED",
|
||||
g_charger_manager.charger_piles[4].is_online ? "GREEN" : "RED",
|
||||
g_charger_manager.charger_piles[5].is_online ? "GREEN" : "RED");
|
||||
Rs485_Message_Send(str, strlen(str));
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @funNm : HeartbeatTask_Function
|
||||
@@ -69,13 +41,30 @@ void HeartbeatTask_Function(void const *argument)
|
||||
* @param : none
|
||||
* @retval: void
|
||||
*/
|
||||
static uint32_t last_heartbeat_tick[MAX_CHARGER_COUNT] = {0};
|
||||
|
||||
void HeartBeat_Sign(void)
|
||||
{
|
||||
if (g_charger_manager.charger_piles[0].is_online)
|
||||
int i;
|
||||
uint32_t now = HAL_GetTick();
|
||||
bool any_online = false;
|
||||
|
||||
/* 6路桩独立心跳,互不影响 */
|
||||
for (i = 0; i < MAX_CHARGER_COUNT; i++)
|
||||
{
|
||||
if (g_charger_manager.charger_piles[i].is_online)
|
||||
{
|
||||
any_online = true;
|
||||
if ((now - last_heartbeat_tick[i]) >= 8000)
|
||||
{
|
||||
last_heartbeat_tick[i] = now;
|
||||
charger_to_server_0X03(i + 1, 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (any_online)
|
||||
{
|
||||
RUN_EVERY(8000, tick_A, {
|
||||
charger_to_server_0X03(1, 1, 0);
|
||||
});
|
||||
RUN_EVERY(100, tick_B, {
|
||||
System_Mode_Led_Toggle();
|
||||
});
|
||||
@@ -90,7 +79,4 @@ void HeartBeat_Sign(void)
|
||||
RUN_EVERY(1000, tick_D, {
|
||||
System_Run_Led_Toggle();
|
||||
});
|
||||
RUN_EVERY(500, tick_E, {
|
||||
Send_Display_Data();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ void YkcTask_Function(void const *argument)
|
||||
{
|
||||
init_chargers(); /* 初始化桩结构体*/
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY); /* 等待桩通讯协议层完成*/
|
||||
osDelay(5000);
|
||||
// send_server_address_to_air724();
|
||||
while (1)
|
||||
{
|
||||
TaskRunTimeStat.YkcTask.threads_runtime = GetTask_RunTime(YkcTaskID);
|
||||
@@ -36,36 +38,59 @@ void YkcTask_Function(void const *argument)
|
||||
|
||||
switch (SETP)
|
||||
{
|
||||
case 0:
|
||||
case 0:
|
||||
{
|
||||
|
||||
if (g_charger_manager.charger_piles[1 - 1].is_udp_online)
|
||||
{
|
||||
uint8_t open_cmd[] = { 0x55, 0xAA, 0x3, 0x01, 0x01, 0xAA, 0x55};
|
||||
Air724_Message_Send(open_cmd, sizeof(open_cmd));
|
||||
osDelay(3000);
|
||||
SETP = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("网关:等待桩上电指令\r\n");
|
||||
osDelay(1000);
|
||||
SETP = 0;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
if (!g_charger_manager.charger_piles[1 - 1].is_online)
|
||||
{
|
||||
charger_to_server_0X01(1);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
SETP = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
if (!g_charger_manager.charger_piles[1 - 1].get_model)
|
||||
charger_to_server_0X09(1); // 桩1计费模型请求
|
||||
else
|
||||
SETP = 2;
|
||||
}
|
||||
osDelay(5000);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
if (!g_charger_manager.charger_piles[1 - 1].get_model)
|
||||
charger_to_server_0X09(1); // 桩1计费模型请求
|
||||
else
|
||||
SETP = 3;
|
||||
osDelay(3000);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
charger_to_server_0X13(1, 1); // 上传状态
|
||||
osDelay(15000);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
osDelay(2000);
|
||||
//osDelay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user