工程提交

This commit is contained in:
2026-03-31 15:46:04 +08:00
parent 75f512a5b4
commit da4e944bca
2841 changed files with 4822938 additions and 1 deletions

View File

@@ -0,0 +1,46 @@
#include "g_dcpile.h"
/*全局充电桩管理器*/
ChargerManager g_charger_manager = {0};
/*充电桩序列号*/
const uint8_t piles_serial[6][7] = {
{0x32, 0x01, 0x06, 0x01, 0x11, 0x15, 0x58},
{0x32, 0x01, 0x06, 0x01, 0x11, 0x16, 0x54},
{0x88, 0x26, 0x01, 0x13, 0x12, 0x00, 0x01},
{0x88, 0x26, 0x01, 0x13, 0x12, 0x00, 0x02},
{0x88, 0x26, 0x01, 0x13, 0x12, 0x00, 0x03},
{0x88, 0x26, 0x01, 0x13, 0x12, 0x00, 0x04},
{0x88, 0x26, 0x01, 0x13, 0x12, 0x00, 0x05},
};
/**
* @brief 初始化充电桩管理器
* @note 初始化充电桩管理器,设置充电桩数量和每个充电桩的初始状态
*/
void init_chargers(void) {
g_charger_manager.charger_count = 6;
for (int i = 0; i < g_charger_manager.charger_count; i++) {
ChargerPile *ctx = &g_charger_manager.charger_piles[i];
memcpy(ctx->login_info.charger_serial, piles_serial[i], 7);
ctx->get_model = false;
ctx->is_udp_online = false;
ctx->login_info.charger_type = CHARGER_TYPE_DC;
ctx->login_info.gun_num = 2;
ctx->login_info.protocol_ver = 0x10; // V1.6
strcpy((char*)ctx->login_info.software_ver, "V4.1.50");
ctx->login_info.net_conn_type = 0; // SIM
memset(ctx->login_info.sim, 0, 10);
ctx->login_info.tele_factory = 0x00; // 移动
// 初始化枪
for (int g = 0; g < ctx->login_info.gun_num && g < MAX_GUN_PER_CHARGER; g++) {
ctx->guns[g].gun_index = g + 1;
ctx->guns[g].status = 0; // 正常
}
}
}

View File

@@ -0,0 +1,47 @@
#ifndef __DC_PILE_H
#define __DC_PILE_H
/* includes ----------------------------------------------------------------------------------------------*/
#include "global.h"
#define MAX_CHARGER_COUNT 6 // 充电桩数量
#define MAX_GUN_PER_CHARGER 2 // 每个充电桩最多枪数
/* 充电枪结构体*/
typedef struct
{
uint8_t gun_index; // 枪索引
bool is_changing; // 是否正在充电
bool is_plugged; // 是否已插入枪
bool is_gun_returned; // 是否已返回枪
uint8_t status; // 状态
PACK_DATA_0X13 real_time_data; // 实时数据
} ChargerGun;
/* 单个充电桩结构体*/
typedef struct
{
PACK_DATA_0X01 login_info;
bool is_online; //云快充是否连接
bool is_udp_online; //是否本地在线
bool get_model;
uint16_t last_heartbeat_time; // 最后一次心跳时间
ChargerGun guns[MAX_GUN_PER_CHARGER]; // 充电枪数组
} ChargerPile;
/*全局充电桩管理结构体*/
typedef struct
{
uint8_t charger_count; // 桩索引
ChargerPile charger_piles[MAX_CHARGER_COUNT]; // 充电桩数组
FEE_MODEL fee_model_global ; //全局计费模型
} ChargerManager;
extern ChargerManager g_charger_manager;
void init_chargers(void); //初始化全局充电桩
#endif /* __DC_PILE_H */

28
Core/User/Global/g_init.c Normal file
View File

@@ -0,0 +1,28 @@
/**
******************************************************************************
* @file user\global\g_init.c
* @author luhuaishuai
* @version v0.1
* @date 2026-1-12
* @brief Briefly describe the function of your function
******************************************************************************
*/
#include "g_init.h"
/* Includes -------------------------------------------------------------------*/
#include "drv_init.h"
#include "_hal_init.h"
/**
* @brief 初始化全局系统
* @note 初始化全局系统包括HAL层和驱动层的初始化
*/
void g_Init(void)
{
_hal_all_Init();
drv_all_Init();
}

13
Core/User/Global/g_init.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef __GINIT_H
#define __GINIT_H
/* Exported functions prototypes ------------------------------------------------------------------------*/
void g_Init(void);
#endif /* __GINIT_H */

View File

@@ -0,0 +1,91 @@
/**
******************************************************************************
* @file user\global\g_runtime.c
* @author luhuaishuai
* @version v0.1
* @date 2026-1-12
* @brief Briefly describe the function of your function
******************************************************************************
*/
/* Includes -------------------------------------------------------------------*/
#include "g_runtime.h"
/* variables ------------------------------------------------------------------*/
TaskRunTimeTypeDef TaskRunTimeStat;
/* code -----------------------------------------------------------------------*/
/**
* @brief GetRunTime计算线程运行间隔时间
*
* @note none
*
* @param taskID : 任务ID
*
* @retval runtime : 任务周期
*/
uint32_t GetTask_RunTime(uint8_t taskID)
{
static uint32_t lasttime[Task_combined] = {0};
uint32_t runtime = 0;
uint32_t curtime = HAL_GetTick();
runtime = curtime - lasttime[taskID]; //计算线程运行间隔时间 runtime运行一次
lasttime[taskID] = curtime;
return runtime;
}
/**
* @brief GetTask_Beatcnt线程运行计数,用于判断线程是否在运行
*
* @note none
*
* @param taskID : 任务ID
*
* @retval beatcnt[taskID] : 线程运行计数
*/
uint32_t GetTask_Beatcnt(uint8_t taskID)
{
static uint8_t beatcnt[Task_combined] = {0};
beatcnt[taskID]++;
if(beatcnt[taskID] >= 10)
{
beatcnt[taskID] = 0;
}
return beatcnt[taskID];
}
/**
* @brief Get_Free_Stack获取剩余任务栈大小
*
* @note none
*
* @param taskID : 任务ID
*
* @retval free_stack[taskID] : 剩余任务栈大小
*/
uint32_t Get_Free_Stack(uint8_t taskID)
{
static uint32_t free_stack[Task_combined] = {0};
free_stack[taskID] = uxTaskGetStackHighWaterMark(NULL);
return free_stack[taskID];
}

View File

@@ -0,0 +1,59 @@
#ifndef __GRUNTIME_H
#define __GRUNTIME_H
/* includes ----------------------------------------------------------------------------------------------*/
#include "global.h"
/* macro ------------------------------------------------------------------------------------------------*/
#define Task_combined 8
/* struct ------------------------------------------------------------------------------------------------*/
typedef struct TaskRunTime
{
uint32_t threads_runtime; // 运行时间
uint32_t threads_counter; // 任务计数
uint32_t threads_freestack; // 剩余栈空间
} TaskRunTime;
enum Task_ID
{
HeartBeatTaskID = 0,
DownLinkTaskID,
UPLinkTaskID,
YkcTaskID,
};
typedef struct TaskRunTimeTypeDef
{
TaskRunTime HeartBeatTask;
TaskRunTime DownLinkTask;
TaskRunTime UPLinkTask;
TaskRunTime YkcTask;
} TaskRunTimeTypeDef;
/* Exported functions prototypes ------------------------------------------------------------------------*/
uint32_t GetTask_RunTime(uint8_t taskID);
uint32_t GetTask_Beatcnt(uint8_t taskID);
uint32_t Get_Free_Stack(uint8_t taskID);
/* Exported constants -----------------------------------------------------------------------------------*/
extern TaskRunTimeTypeDef TaskRunTimeStat;
#endif /* __GRUNTIME_H */

119
Core/User/Global/global.h Normal file
View File

@@ -0,0 +1,119 @@
/**
******************************************************************************
* @file user\global\global.h
* @author liangky
* @version v0.1
* @date 2023-10-11
* @brief Briefly describe the function of your function
******************************************************************************
*/
#ifndef __GLOBAL_H
#define __GLOBAL_H
/* Private includes ----------------------------------------------------------*/
/* C 语言标准库 */
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
#include <time.h>
/* CubeMX生成 */
#include "main.h"
// #include "iwdg.h"
#include "usart.h"
#include "gpio.h"
// #include "tim.h"
/* freeRTOS 相关 */
#include "cmsis_os.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "event_groups.h"
#include "stream_buffer.h"
/* Os */
#include "os_task.h"
#include "os_queue.h"
#include "os_semaphore.h"
/* GL */
#include "g_runtime.h"
#include "server_to_charger.h"
#include "g_dcpile.h"
/* _hal */
#include "_hal_usart.h"
/* driver */
#include "cJSON.h"
#include "server_common.h"
#include "charger_to_server.h"
/* macro ------------------------------------------------------------------------------------------------*/
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE 0
#define PI 3.1415926f
#define SOFTWARE_VERSION "JSBRv1.2" // 软件版本
#define YKC_VERSION 0x10 // YKC 协议版本 v1.6
#define NET_CONN_TYPE 0 // 0: 4G, 1: LAN
#define DEBUG 1 // 调试模式
/*- I/O 输出-*/
#define AIR724_RESET() \
do \
{ \
HAL_GPIO_WritePin(AIR724_REWST_GPIO_Port, AIR724_REWST_Pin, GPIO_PIN_SET); \
uint32_t i = 60000000; \
while (i--) \
__nop; \
HAL_GPIO_WritePin(AIR724_REWST_GPIO_Port, AIR724_REWST_Pin, GPIO_PIN_RESET); \
} while (0) /* System Run Led */
#define RS485_EN(x) \
do \
{ \
x ? HAL_GPIO_WritePin(RS485_EN_GPIO_Port, RS485_EN_Pin, GPIO_PIN_SET) : HAL_GPIO_WritePin(RS485_EN_GPIO_Port, RS485_EN_Pin, GPIO_PIN_RESET); \
} while (0) /* RS485 EN Led */
#define System_Mode_Led(x) \
do \
{ \
x ? HAL_GPIO_WritePin(System_Mode_Led_GPIO_Port, System_Mode_Led_Pin, GPIO_PIN_SET) : HAL_GPIO_WritePin(System_Mode_Led_GPIO_Port, System_Mode_Led_Pin, GPIO_PIN_RESET); \
} while (0) /* System Run Led */
#define System_Mode_Led_Toggle() HAL_GPIO_TogglePin(System_Mode_Led_GPIO_Port, System_Mode_Led_Pin)
#define System_Run_Led(x) \
do \
{ \
x ? HAL_GPIO_WritePin(System_Run_Led_GPIO_Port, System_Run_Led_Pin, GPIO_PIN_SET) : HAL_GPIO_WritePin(System_Run_Led_GPIO_Port, System_Run_Led_Pin, GPIO_PIN_RESET); \
} while (0) /* System Run Led */
#define System_Run_Led_Toggle() HAL_GPIO_TogglePin(System_Run_Led_GPIO_Port, System_Run_Led_Pin) /* System Run Led */
#define YT8512_RST(x) \
do \
{ \
x ? HAL_GPIO_WritePin(YT8512_RST_GPIO_Port, YT8512_RST_Pin, GPIO_PIN_SET) : HAL_GPIO_WritePin(YT8512_RST_GPIO_Port, YT8512_RST_Pin, GPIO_PIN_RESET); \
} while (0) /* System Run Led */
/*- I/O 输入-*/
#define get_sys_time_msec() HAL_GetTick()
#define CONSTRAIN(x, max, min) (x > max ? max : (x < min ? min : x))
#endif /* __GLOBAL_H */