BAIYI/SYSTEM/usart/usart.h

299 lines
7.5 KiB
C
Raw Normal View History

#ifndef __USART_H
#define __USART_H
//#include <stm32f10x_lib.h>
#include "stdio.h"
#include "sys.h"
#define USART_REC_LEN 200 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD> 200
#define EN_USART1_RX 1 //ʹ<>ܣ<EFBFBD>1<EFBFBD><31>/<2F><>ֹ<EFBFBD><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>
#define USART2_REC_LEN 254 // 250 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD> 200
#define EN_USART2_RX 1 //ʹ<>ܣ<EFBFBD>1<EFBFBD><31>/<2F><>ֹ<EFBFBD><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD>
#define USART3_REC_LEN 200 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD> 200
#define EN_USART3_RX 1 //ʹ<>ܣ<EFBFBD>1<EFBFBD><31>/<2F><>ֹ<EFBFBD><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD>
#define UART4_REC_LEN 200 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD> 200
#define EN_UART4_RX 1 //ʹ<>ܣ<EFBFBD>1<EFBFBD><31>/<2F><>ֹ<EFBFBD><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD>
#define UART5_REC_LEN 200 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD> 200
#define EN_UART5_RX 1 //ʹ<>ܣ<EFBFBD>1<EFBFBD><31>/<2F><>ֹ<EFBFBD><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><35><EFBFBD><EFBFBD>
extern u8 USART_RX_BUF[USART_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD><>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>з<EFBFBD>
extern u16 USART_RX_STA; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB4AE><EFBFBD>жϽ<D0B6><CFBD>գ<EFBFBD><D5A3>벻Ҫע<D2AA><D7A2><EFBFBD><EFBFBD><EFBFBD>º궨<C2BA><EAB6A8>
extern u8 USART2_RX_BUF[USART2_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD><>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>з<EFBFBD>
extern u16 USART2_RX_STA; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
extern u8 USART2_RX_FLAG;
void RS232_Uart2_Write(uint8_t* buff, int length) ;
extern u8 USART3_RX_BUF[USART3_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD><>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>з<EFBFBD>
extern u16 USART3_RX_STA; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
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]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD><>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>з<EFBFBD>
extern u16 UART4_RX_STA; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
extern u8 UART4_RX_FLAG;
void RS232_Uart4_Write(uint8_t* buff, int length) ;
extern u16 UART5_RX_STA; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
extern u8 UART5_RX_FLAG;
extern u16 UART5_RX_LEN; //<2F><><EFBFBD>ճ<EFBFBD><D5B3><EFBFBD>
extern u8 UART5_RX_BUF[UART5_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD>.
////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 <stdio.h>
#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, // <20>û<EFBFBD><C3BB><EFBFBD>
SHELL_TEST, // <20><><EFBFBD>Թ<EFBFBD><D4B9>̼<EFBFBD><CCBC><EFBFBD>
SHELL_RD, // <20>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD>
} 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 /* ָ<><D6B8><EFBFBD><EFBFBD>ַд<D6B7>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define D_DP_CtrlRead 0x81 /* ָ<><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define D_DP_DataWirte 0x82 /* ָ<><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼд<CABC><D0B4><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B4A2> */
#define D_DP_DataRead 0x83 /* <20>ӱ<EFBFBD><D3B1><EFBFBD><EFBFBD><EFBFBD><E6B4A2>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>RD_LEN<45><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define D_DP_CurveWirte 0x84 /* д<><D0B4><EFBFBD>߻<EFBFBD><DFBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#pragma pack(1)
typedef struct
{
uint16_t address; // <09>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
uint16_t len;
uint8_t device;
uint16_t cmd;
uint8_t ucDataSpace[350]; // <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> // 128 512
uint16_t crc;
} DP_FrameBluetooth_t;
#pragma pack()
typedef struct
{
uint8_t addr;
uint8_t len;
uint8_t *param;
}HMI_DW_BLUE;
//<2F><><EFBFBD><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
typedef enum
{
BLUE_Registered = 0,
//<2F><><EFBFBD><EFBFBD>׮<EFBFBD><D7AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BLUE_Login, //
BLUE_BootNotification,
BLUE_DataTransfer_ChargeHost, //<2F><><EFBFBD><EFBFBD>׮<EFBFBD><D7AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> bms0 <20><>Ϣ */
#pragma pack (1) /*ָ<><D6B8><EFBFBD><EFBFBD>1<EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD>*/
typedef struct
{
// byte 0-1-2
uint16_t BattCellVoltage ; // 0.001V <20><><EFBFBD>ص<EFBFBD>ѹ
uint8_t Celltemp ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}cellbat_info_t;
typedef union
{
uint8_t stats[8];
struct
{
//byte0 // byte1
uint16_t BatMaNegRlySts :2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD><CCB5><EFBFBD>
uint16_t BatMaPosRlySts :2; //<2F><><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD><CCB5><EFBFBD>
uint16_t BatPrechrgRlySts :2; //<2F><><EFBFBD>ذ<EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD>̵<EFBFBD><CCB5><EFBFBD>״̬
uint16_t BatHvIntlkSts :2; //<2F><><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>
uint16_t BatFuSts:1; //<2F><><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD><EFBFBD><EFBFBD> 0<><30><EFBFBD><EFBFBD> 1<>۶<EFBFBD>
uint16_t BatHeRlySts:2; //<2F><><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD><EFBFBD>ȼ̵<C8BC><CCB5><EFBFBD>״̬
uint16_t BatHeSts:2; //<2F><><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD><EFBFBD><EFBFBD>״̬
uint16_t Prechrgsts:1; //<2F><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4>״̬
uint16_t reserve:2;
// byte3-4-5-6
uint16_t Batfaultnum :16; //<2F><><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>
uint16_t BatTalVolSts :16; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// byte7
uint8_t BatAvgCelVolSts:2; //<2F><><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD>
uint8_t BatAvgTolVolSts:2; //<2F><><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD>
uint8_t BatChrgCurSts:1; //<2F><><EFBFBD>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
uint8_t BatDischrgCurSts:1; //<2F>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>
uint8_t BatIslateSts:1; //<2F><><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD>Ե
uint8_t BatInCANBsErrFlt:1; //can<61><6E><EFBFBD><EFBFBD><EFBFBD>
// byte8
uint8_t BatTempSensFlt:1;//<2F><><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD>
uint8_t BatCurSensFlt:1; //<2F><><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t BatCelVolSensFlt:1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t BalanceSts:2;//<2F><><EFBFBD><EFBFBD>
uint8_t reserv3:3;
}bits;
}bms_state_info_t;
typedef struct
{
uint8_t BatManuSpecCode[4]; //Э<><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4B3B5><EFBFBD><EFBFBD>
uint8_t BatManuversionNo[4]; //bmsЭ<73><D0AD>
uint32_t VehOdo ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʻ<EFBFBD><CABB><EFBFBD><EFBFBD>
uint8_t CDUType; //<2F><>Ʒ<EFBFBD><C6B7><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
uint16_t ChrgVolRqst ;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>
uint16_t ChrgCurRqst ;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16_t BatIslatRes ; //<2F><>Եֵ k<><6B>
uint8_t BatSOH ;
uint8_t BatSOC;
uint16_t BatEnrgAvail ; //<2F><><EFBFBD>ذ<EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0.1kw
uint16_t BatEnrgRated ; //<2F><><EFBFBD>ض<D8B6><EEB6A8><EFBFBD><EFBFBD> 0.1kw
uint16_t BatChrgTims;
uint8_t BatPlsChrgPowAvail; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E7B9A6><EFBFBD><EFBFBD>Ч
uint8_t BatPlsDischrgPowAvail;//<2F><><EFBFBD><EFBFBD><EFBFBD>ŵ繦<C5B5><E7B9A6><EFBFBD><EFBFBD>Ч
uint16_t BatVolRated ; //<2F><><EFBFBD>ض<D8B6><EEB6A8>ѹ 0.1V
//<2F><><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><C2B6><EFBFBD>Ϣ <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ѹ<EFBFBD><D1B9>Ϣ
cellbat_info_t cellbat_data[40];
//<2F><><EFBFBD>̵ּ<D6BC><CCB5><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>Ϣ
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