#ifndef __USART_H #define __USART_H //#include #include "stdio.h" #include "sys.h" #define USART_REC_LEN 200 //定义最大接收字节数 200 #define EN_USART1_RX 1 //使能(1)/禁止(0)串口1接收 #define USART2_REC_LEN 254 // 250 //定义最大接收字节数 200 #define EN_USART2_RX 1 //使能(1)/禁止(0)串口2接收 #define USART3_REC_LEN 200 //定义最大接收字节数 200 #define EN_USART3_RX 1 //使能(1)/禁止(0)串口3接收 #define UART4_REC_LEN 200 //定义最大接收字节数 200 #define EN_UART4_RX 1 //使能(1)/禁止(0)串口4接收 #define UART5_REC_LEN 200 //定义最大接收字节数 200 #define EN_UART5_RX 1 //使能(1)/禁止(0)串口5接收 extern u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 extern u16 USART_RX_STA; //接收状态标记 //如果想串口中断接收,请不要注释以下宏定义 extern u8 USART2_RX_BUF[USART2_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 extern u16 USART2_RX_STA; //接收状态标记 extern u8 USART2_RX_FLAG; void RS232_Uart2_Write(uint8_t* buff, int length) ; extern u8 USART3_RX_BUF[USART3_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 extern u16 USART3_RX_STA; //接收状态标记 extern u8 USART3_RX_FLAG; extern u16 USART3_RX_LEN; void RS232_Uart3_Write(uint8_t* buff, int length) ; void RS232_Uart4_Write(uint8_t* buff, int length) ; extern u8 UART4_RX_BUF[UART4_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 extern u16 UART4_RX_STA; //接收状态标记 extern u8 UART4_RX_FLAG; void RS232_Uart4_Write(uint8_t* buff, int length) ; extern u16 UART5_RX_STA; //接收状态标记 extern u8 UART5_RX_FLAG; extern u16 UART5_RX_LEN; //接收长度 extern u8 UART5_RX_BUF[UART5_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节. ////extern u8 UpdToutCnt; void uart_init(u32 bound); void uart2_init(u32 bound); void uart3_init(u32 bound); void uart4_init(u32 bound); void uart5_init(u32 bound); void debugdataprocess(u8 *data,u16 len); void Delupdtcnt(void); u16 Getupdtcnt(void); #include "stm32f10x.h" #include #define MAX_PARAM 4 typedef struct { uint8_t paranum; uint8_t cmdlen; uint8_t *cmd; uint8_t *param[MAX_PARAM]; uint8_t paramlen[MAX_PARAM]; }SH_CMD; typedef enum { SHELL_USER, // 用户级 SHELL_TEST, // 测试工程级别 SHELL_RD, // 研发级别 } e_cmdtype; typedef struct { uint8_t shelltype; char *command; void (*cmdfunc)(void); }SHELLMAP; #define USART_BUFFER_SIZE 128 #define USART_BUFFER_TX_SIZE 64 typedef struct { uint8_t Link_status; uint8_t recvFlag; uint8_t recvLength; uint8_t sendLength; uint8_t recvBuffer[USART_BUFFER_SIZE]; uint8_t sendBuffer[USART_BUFFER_TX_SIZE]; }UsartObj; void RS232_Blue_Write(uint8_t* buff, int length) ; void Blue_Receive_Parser(void); void Blue_Query_Version(void); void Blue_Connect_State(void); void Blue_Name_Cfg(uint8_t *data); void Blue_Name_Query(void); void Blue_Query_UART_Cfg(void); typedef enum { BLUE_IDLE = 0, BLUE_CONFIG, BLUE_PREPARE, BLUE_LINK_STATUE, BLUE_LINK_CONNECTING, BLUE_LINK_CONNECTED, BLUE_END }BLueProcessState; typedef enum { BLUE_REGISTERED= 0, BLUE_LOGIN, BLUE_WECHATAPPLET_ONLINE, BLUE_WECHATAPPLET_OFFLINE, BLUE_WECHATAPPLET_UPDATA, BLUE_END_OVER }BLueDataProcessState; typedef struct { uint8_t State; uint8_t Link_status; uint8_t ConnectServerState; uint8_t *recvBuffer; uint16_t recvLength; uint16_t sendLength; uint8_t *sendBuffer; uint8_t connetcOvertimeFlag; uint8_t ReciveDataOvertimeFlag; }BlueManage_t; void BluetoothProcess(void); void BluetoothConnectProcess(void); #define D_DP_FrameStart1 0xA5 /* 帧头 1 */ #define D_DP_FrameStart2 0x5A /* 帧头 2 */ #define D_DP_Device 0x20 //0x10 /* 指定地址写寄存器数据 */ #define D_DP_CtrlRead 0x81 /* 指定地址读寄存器数据 */ #define D_DP_DataWirte 0x82 /* 指定地址开始写入数据串到变量存储区 */ #define D_DP_DataRead 0x83 /* 从变量存储区指定地址开始读入RD_LEN长度数据 */ #define D_DP_CurveWirte 0x84 /* 写曲线缓冲区数据 */ #pragma pack(1) typedef struct { uint16_t address; // 寄存器地址 uint16_t len; uint8_t device; uint16_t cmd; uint8_t ucDataSpace[350]; // 数据域 // 128 512 uint16_t crc; } DP_FrameBluetooth_t; #pragma pack() typedef struct { uint8_t addr; uint8_t len; uint8_t *param; }HMI_DW_BLUE; //发送枚举类型 typedef enum { BLUE_Registered = 0, //充电桩主动发送 BLUE_Login, // BLUE_BootNotification, BLUE_DataTransfer_ChargeHost, //充电桩主动发送数据监控中心 BLUE_DiagnosticsStatusNotification, BLUE_FirmwareStatusNotification, BLUE_Heartbeat, BLUE_StartTransaction, BLUE_StatusNotification, BLUE_StopTransaction, OCPP_CallError_Send }BLUE_SendHandleState; extern BlueManage_t BluetoothInfo; extern uint8_t SocCalculateCharging(void); typedef struct { uint8_t paramaddr; uint8_t paramlen; uint8_t *paramData; }SysparamTable_t; /* 电池组 bms0 信息 */ #pragma pack (1) /*指定按1字节对齐*/ typedef struct { // byte 0-1-2 uint16_t BattCellVoltage ; // 0.001V 电池电压 uint8_t Celltemp ; //电池温度 }cellbat_info_t; typedef union { uint8_t stats[8]; struct { //byte0 // byte1 uint16_t BatMaNegRlySts :2; //电池主负继电器 uint16_t BatMaPosRlySts :2; //电池包主正继电器 uint16_t BatPrechrgRlySts :2; //电池包预充继电器状态 uint16_t BatHvIntlkSts :2; //电池包高压互锁 uint16_t BatFuSts:1; //电池包保险 0正常 1熔断 uint16_t BatHeRlySts:2; //电池包加热继电器状态 uint16_t BatHeSts:2; //电池包加热状态 uint16_t Prechrgsts:1; //电池预充状态 uint16_t reserve:2; // byte3-4-5-6 uint16_t Batfaultnum :16; //故障个数 uint16_t BatTalVolSts :16; //故障码 // byte7 uint8_t BatAvgCelVolSts:2; //电池包单体电压告警 uint8_t BatAvgTolVolSts:2; //电池包单体电压告警 uint8_t BatChrgCurSts:1; //电池充电电流状态 uint8_t BatDischrgCurSts:1; //放电电流 uint8_t BatIslateSts:1; //电池包绝缘 uint8_t BatInCANBsErrFlt:1; //can总线异常 // byte8 uint8_t BatTempSensFlt:1;//电池包温度 uint8_t BatCurSensFlt:1; //电池包电流传感器 uint8_t BatCelVolSensFlt:1; //单体电压传感器异常 uint8_t BalanceSts:2;//均衡 uint8_t reserv3:3; }bits; }bms_state_info_t; typedef struct { uint8_t BatManuSpecCode[4]; //协议适配车类型 uint8_t BatManuversionNo[4]; //bms协议 uint32_t VehOdo ; //车辆行驶例程 uint8_t CDUType; //产品类型代码 //充电信息 uint16_t ChrgVolRqst ;//充电电压请求 uint16_t ChrgCurRqst ;//充电电流请求 uint16_t BatIslatRes ; //绝缘值 kΩ uint8_t BatSOH ; uint8_t BatSOC; uint16_t BatEnrgAvail ; //电池包剩余电量 0.1kw uint16_t BatEnrgRated ; //电池额定电量 0.1kw uint16_t BatChrgTims; uint8_t BatPlsChrgPowAvail; //脉冲充电功率有效 uint8_t BatPlsDischrgPowAvail;//脉冲放电功率有效 uint16_t BatVolRated ; //电池额定电压 0.1V //单节电池温度信息 与电池电压信息 cellbat_info_t cellbat_data[40]; //各种继电器状态等信息 bms_state_info_t bms_state_info; }bmsblue_datainfo_t; #pragma pack() extern bmsblue_datainfo_t bluebms_datainfo; extern void BMS_UpdataACKInfo(void); extern void BMS_VersionInfo(void); extern void UpdataDebugInfoToServer(uint8_t *data,uint8_t len); extern void BMS_ChargingDataInfo(void); extern void bat_temp_Info(void); extern void bat_Cell_Vol_Info(void); extern void bat_state_code(void); #endif