CELIS/SYSTEM/usart/usart.c

4304 lines
125 KiB
C
Raw Normal View History

2024-08-09 06:24:48 +00:00
#include "sys.h"
#include "usart.h"
#include "led.h"
#include "can.h"
#include "string.h"
#include "adc.h"
#include "dc300.h"
#include "KC.h"
#include "kC_Features.h"
#include "Flash_StorageData.h"
//////////////////////////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>ucos,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>.
#if SYSTEM_SUPPORT_UCOS
#include "includes.h" //ucos ʹ<><CAB9>
#endif
//////////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD><><D6A7>printf<74><66><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫѡ<D2AA><D1A1>use MicroLIB
#if 1
#pragma import(__use_no_semihosting)
//<2F><>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>֧<EFBFBD>ֺ<EFBFBD><D6BA><EFBFBD>
struct __FILE
{
int handle;
};
FILE __stdout;
//<2F><><EFBFBD><EFBFBD>_sys_exit()<29>Ա<EFBFBD><D4B1><EFBFBD>ʹ<EFBFBD>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD>ģʽ
_sys_exit(int x)
{
x = x;
}
#include "sd.h"
//<2F>ض<EFBFBD><D8B6><EFBFBD>fputc<74><63><EFBFBD><EFBFBD>
int fputc(int ch, FILE *f)
{
static u8 debug_info[250]={0};
static u8 debug_count ;
static uint32_t timer = 0;
/* <20><>Printf<74><66><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
USART_SendData(UART4, (unsigned char) ch);
while (!(UART4->SR & USART_FLAG_TXE));
if(SysParaPileD.Debug_Page_function ==1)//<2F><><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD>
{
if(BluetoothInfo.ConnectServerState == BLUE_WECHATAPPLET_ONLINE)
{
if(debug_count < 150 )
{
debug_info[debug_count++] = ch;
}
else
{
UpdataDebugInfoToServer(debug_info,debug_count);
BluetoothInfo.connetcOvertimeFlag++;
debug_count =0;
}
}
else
{
SysParaPileD.Debug_Page_function =0;
}
}
return ch;
}
#endif
uint8_t stopChargeReason =0;
/*ʹ<><CAB9>microLib<69>ķ<EFBFBD><C4B7><EFBFBD>*/
/*
int fputc(int ch, FILE *f)
{
USART_SendData(USART1, (uint8_t) ch);
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) {}
return ch;
}
int GetKey (void) {
while (!(USART1->SR & USART_FLAG_RXNE));
return ((int)(USART1->DR & 0x1FF));
}
*/
// SAMPLE: '1','2','3','4' -----> 1234
uint32_t StringToInt(uint8_t *sptr, uint8_t len);
static uint8_t ShellCommad(void);
void ResetShell(void);
void UART4SendByte(unsigned char Byte);
void UpdProcess(u8 type,u8 *Pdata, u16 length);
typedef struct _UpdInfo
{
u8 FileType ;
u8 FileVer ;
u32 FileTotalByte ;
u16 FileCrc ;
u32 FileTotalPag ;
u16 FilePaglen ;
u32 RecePagNum ;
u32 ReceBakPagNum ;
u32 CurrByteLen ;
u16 FlashBakPage ;
u32 CurrBakByteLen ;
}UpdInfo_s;
UpdInfo_s UpdHead;
#define UpdBaseAddr 0x8026000 //// 152k
#define UpdInfoAddr 0x8025800 //// 150k
#define UpdDataFlag 0x11223344 //// 150k
u8 GprsCommGetAscMSB (u8 uHex )
{
uHex = uHex >> 4 ;
if (uHex > 9 ) //A~F
{
return (uHex + 0x37) ;
}
else //0~9
{
return (uHex + 0x30) ;
}
}
u8 GprsCommGetAscLSB (u8 uHex )
{
uHex &= 0X0F ;
if (uHex > 9 ) //A~F
{
return (uHex + 0x37) ;
}
else //0~9
{
return (uHex + 0x30) ;
}
}
void debugdataprocess(u8 *data,u16 len)
{
u16 i;
u8 *ptr;
u8 hdata,ldata;
UART4SendByte('\r');
UART4SendByte('\n');
ptr = data;
for(i = 0; i < len ; i++){
hdata = GprsCommGetAscMSB(*ptr);
ldata = GprsCommGetAscLSB(*ptr);
UART4SendByte(hdata);
UART4SendByte(ldata);
ptr++;
}
UART4SendByte('\r');
UART4SendByte('\n');
}
#if EN_USART1_RX //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>˽<EFBFBD><CBBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>1<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ע<><D7A2>,<2C><>ȡUSARTx->SR<53>ܱ<EFBFBD><DCB1><EFBFBD>Ī<EFBFBD><C4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
u8 USART_RX_BUF[USART_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD>.
//<2F><><EFBFBD><EFBFBD>״̬
//bit15<31><35> <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
//bit14<31><34> <09><><EFBFBD>յ<EFBFBD>0x0d
//bit13~0<><30> <09><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>Ŀ
u16 USART_RX_STA=0; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
void uart_init(u32 bound){
//GPIO<49>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE); //ʹ<><CAB9>USART1<54><31>GPIOAʱ<41><CAB1>
//USART1_TX PA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART1_RX PA.10
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// GPIO_Init(GPIOA, &GPIO_InitStructure);
//Usart1 NVIC <20><><EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
NVIC_Init(&NVIC_InitStructure); //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
//USART <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_InitStructure.USART_BaudRate = bound;//һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//<2F>ֳ<EFBFBD>Ϊ8λ<38><CEBB><EFBFBD>ݸ<EFBFBD>ʽ
USART_InitStructure.USART_StopBits = USART_StopBits_1;//һ<><D2BB>ֹͣλ
USART_InitStructure.USART_Parity = USART_Parity_No;//<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//<2F><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //<2F>շ<EFBFBD>ģʽ
USART_Init(USART1, &USART_InitStructure); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
USART_Cmd(USART1, ENABLE); //ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>
}
void USART1_IRQHandler(void) //<2F><><EFBFBD><EFBFBD>1<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
u8 Res;
#ifdef OS_TICKS_PER_SEC //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><CBB5>Ҫʹ<D2AA><CAB9>ucosII<49><49>.
OSIntEnter();
#endif
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>(<28><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD>0x0d 0x0a<30><61>β)
{
Res =USART_ReceiveData(USART1);//(USART1->DR); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if((USART_RX_STA&0x8000)==0)//<2F><><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>
{
if(USART_RX_STA&0x4000)//<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>0x0d
{
if(Res!=0x0a)USART_RX_STA=0;//<2F><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD>,<2C><><EFBFBD>¿<EFBFBD>ʼ
else USART_RX_STA|=0x8000; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
else //<2F><>û<EFBFBD>յ<EFBFBD>0X0D
{
if(Res==0x0d)USART_RX_STA|=0x4000;
else
{
USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ;
USART_RX_STA++;
if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>,<2C><><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
}
}
}
}
#ifdef OS_TICKS_PER_SEC //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><CBB5>Ҫʹ<D2AA><CAB9>ucosII<49><49>.
OSIntExit();
#endif
}
#endif
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////USART2,PD5<44><35>PD6/////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
#if EN_USART2_RX //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>˽<EFBFBD><CBBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>2<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ע<><D7A2>,<2C><>ȡUSARTx->SR<53>ܱ<EFBFBD><DCB1><EFBFBD>Ī<EFBFBD><C4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
u8 USART2_RX_BUF[USART2_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART2_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD>.
//<2F><><EFBFBD><EFBFBD>״̬
//bit15<31><35> <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
//bit14<31><34> <09><><EFBFBD>յ<EFBFBD>0x0d
//bit13~0<><30> <09><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>Ŀ
u16 USART2_RX_STA = 0; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
u8 USART2_RX_FLAG = 0;
void USART2SendByte(unsigned char Byte)
{
USART_SendData(USART2, Byte);
while (!(USART2->SR & USART_FLAG_TXE));
}
void RS232_Uart2_Write(uint8_t* buff, int length)
{
int i = 0;
for(i =0;i<length;i++)
{
USART2SendByte(buff[i]);
}
}
void uart2_init(u32 bound){
//GPIO<49>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //ʹ<><CAB9>GPIODʱ<44><CAB1>
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //ʹ<><CAB9>USART2ʱ<32><CAB1>
// GPIO_PinRemapConfig(GPIO_Remap_USART2,ENABLE);
//USART2_TX PA.2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PD.2
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART2_RX PA.3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Usart2 NVIC <20><><EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
NVIC_Init(&NVIC_InitStructure); //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
//USART <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_InitStructure.USART_BaudRate = bound;//һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//<2F>ֳ<EFBFBD>Ϊ8λ<38><CEBB><EFBFBD>ݸ<EFBFBD>ʽ
USART_InitStructure.USART_StopBits = USART_StopBits_1;//һ<><D2BB>ֹͣλ
USART_InitStructure.USART_Parity = USART_Parity_No;//<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//<2F><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //<2F>շ<EFBFBD>ģʽ
USART_Init(USART2, &USART_InitStructure); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
/* Enable USART2 */
// USART_Cmd(USART2, ENABLE);
// USART_ITConfig(USART2, USART_IT_TC, ENABLE);
USART_ITConfig(USART2, USART_IT_IDLE, ENABLE);
USART_Cmd(USART2, ENABLE); //ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>
USART_ClearFlag(USART2,USART_FLAG_TXE);
}
void USART2_IRQHandler(void) //<2F><><EFBFBD><EFBFBD>2<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
uint8_t ch;
static u8 index =0;
if(USART_GetITStatus(USART2,USART_IT_RXNE)!= RESET)
{
ch = USART_ReceiveData(USART2);
if(USART2_RX_STA<USART2_REC_LEN)
USART2_RX_BUF[USART2_RX_STA++] = ch;
else
USART2_RX_STA =0;
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
}
if(USART_GetITStatus(USART2, USART_IT_IDLE) != RESET) //<2F><><EFBFBD>տ<EFBFBD><D5BF><EFBFBD><EFBFBD>ж<EFBFBD>
{
USART_ReceiveData(USART2);
USART2_RX_FLAG=1;
// memset(recvnetBuffer,0,NET_BUF_SIZE);
USART_ClearITPendingBit(USART2,USART_IT_IDLE);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
if(USART_GetITStatus(USART2, USART_IT_TC) != RESET)
{
USART_ClearITPendingBit(USART2,USART_IT_TC);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
if (USART_GetFlagStatus(USART2,USART_FLAG_ORE)==SET)
{
USART_ClearFlag(USART2,USART_FLAG_ORE); //<2F><>SR
USART_ReceiveData(USART2); //<2F><>DR
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
if (USART_GetFlagStatus(USART2,USART_FLAG_NE)==SET)
{
USART_ClearFlag(USART2,USART_FLAG_NE); //<2F><>SR
USART_ReceiveData(USART2); //<2F><>DR
}
//֡<><D6A1><EFBFBD><EFBFBD>
if (USART_GetFlagStatus(USART2,USART_FLAG_FE)==SET)
{
USART_ClearFlag(USART2,USART_FLAG_FE); //<2F><>SR
USART_ReceiveData(USART2); //<2F><>DR
}
}
#endif
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////USART3,PB10<31><30>PB11///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
#if EN_USART3_RX //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>˽<EFBFBD><CBBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>1<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ע<><D7A2>,<2C><>ȡUSARTx->SR<53>ܱ<EFBFBD><DCB1><EFBFBD>Ī<EFBFBD><C4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
u8 USART3_RX_BUF[USART3_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD>.
//<2F><><EFBFBD><EFBFBD>״̬
//bit15<31><35> <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
//bit14<31><34> <09><><EFBFBD>յ<EFBFBD>0x0d
//bit13~0<><30> <09><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>Ŀ
u16 USART3_RX_STA=0; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
u8 USART3_RX_FLAG=0;
u16 USART3_RX_LEN=0; //<2F><><EFBFBD>ճ<EFBFBD><D5B3><EFBFBD>
void uart3_init(u32 bound){
//GPIO<49>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE); //ʹ<><CAB9>USART3<54><33>GPIOE,Bʱ<42><CAB1>
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); //ʹ<><CAB9>USART3ʱ<33><CAB1>
// GPIO_PinRemapConfig(GPIO_FullRemap_USART3,ENABLE);
//USART3_TX PB.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PB.10
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART3_RX PB.11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOB, &GPIO_InitStructure);
//Usart3 NVIC <20><><EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
NVIC_Init(&NVIC_InitStructure); //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
//USART <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_InitStructure.USART_BaudRate = bound;//һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//<2F>ֳ<EFBFBD>Ϊ8λ<38><CEBB><EFBFBD>ݸ<EFBFBD>ʽ
USART_InitStructure.USART_StopBits = USART_StopBits_1;//һ<><D2BB>ֹͣλ
USART_InitStructure.USART_Parity = USART_Parity_No;//<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//<2F><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //<2F>շ<EFBFBD>ģʽ
USART_Init(USART3, &USART_InitStructure); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_Cmd(USART3, ENABLE); //ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
// USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART3, USART_IT_TC, ENABLE);
USART_ITConfig(USART3, USART_IT_IDLE, ENABLE);
}
void USART3SendByte(unsigned char Byte)
{
USART_SendData(USART3, Byte);
while (!(USART3->SR & USART_FLAG_TXE));
}
void RS232_Uart3_Write(uint8_t* buff, int length)
{
int i = 0;
for(i =0;i<length;i++)
{
USART3SendByte(buff[i]);
}
}
void USART3_IRQHandler(void) //<2F><><EFBFBD><EFBFBD>3<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
u8 Res;
static u8 index =0;
if(USART_GetITStatus(USART3,USART_IT_RXNE)!= RESET)
{
Res =USART_ReceiveData(USART3);//(USART1->DR); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(USART3_RX_LEN<USART3_REC_LEN)
USART3_RX_BUF[USART3_RX_LEN++] = Res;
else
USART3_RX_LEN =0;
USART3_RX_STA = 0;
USART3_RX_FLAG = 0;
USART_ClearITPendingBit(USART3,USART_IT_RXNE);
}
if(USART_GetITStatus(USART3, USART_IT_IDLE) != RESET) //<2F><><EFBFBD>տ<EFBFBD><D5BF><EFBFBD><EFBFBD>ж<EFBFBD>
{
USART_ReceiveData(USART3);
USART3_RX_FLAG = 1;
USART_ClearITPendingBit(USART3,USART_IT_IDLE);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
if(USART_GetITStatus(USART3, USART_IT_TC) != RESET)
{
USART_ClearITPendingBit(USART3,USART_IT_TC);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
if (USART_GetFlagStatus(USART3,USART_FLAG_ORE)==SET)
{
USART_ClearFlag(USART3,USART_FLAG_ORE); //<2F><>SR
USART_ReceiveData(USART3); //<2F><>DR
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
if (USART_GetFlagStatus(USART3,USART_FLAG_NE)==SET)
{
USART_ClearFlag(USART3,USART_FLAG_NE); //<2F><>SR
USART_ReceiveData(USART3); //<2F><>DR
}
//֡<><D6A1><EFBFBD><EFBFBD>
if (USART_GetFlagStatus(USART3,USART_FLAG_FE)==SET)
{
USART_ClearFlag(USART3,USART_FLAG_FE); //<2F><>SR
USART_ReceiveData(USART3); //<2F><>DR
}
// if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>(<28><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD>0x0d 0x0a<30><61>β)
// {
// Res =USART_ReceiveData(USART3);//(USART1->DR); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// }
}
#endif
#if EN_UART4_RX //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>˽<EFBFBD><CBBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>1<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ע<><D7A2>,<2C><>ȡUSARTx->SR<53>ܱ<EFBFBD><DCB1><EFBFBD>Ī<EFBFBD><C4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
u8 UART4_RX_BUF[UART4_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>UART4_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD>.
//<2F><><EFBFBD><EFBFBD>״̬
//bit15<31><35> <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
//bit14<31><34> <09><><EFBFBD>յ<EFBFBD>0x0d
//bit13~0<><30> <09><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>Ŀ
u16 UART4_RX_STA=0; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
u8 UART4_RX_FLAG;
u16 UART4_RX_LEN=0; //<2F><><EFBFBD>ճ<EFBFBD><D5B3><EFBFBD>
void UART4SendByte(unsigned char Byte)
{
USART_SendData(UART4, Byte);
while (!(UART4->SR & USART_FLAG_TXE));
}
void RS232_Uart4_Write(uint8_t* buff, int length)
{
int i = 0;
for(i =0;i<length;i++)
{
UART4SendByte(buff[i]);
}
// UART4SendByte(0x0D);
// UART4SendByte(0x0A);
}
void uart4_init(u32 bound){
//GPIO<49>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE); //ʹ<><CAB9>GPIOCʱ<43><CAB1>
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); //ʹ<><CAB9>UART4ʱ<34><CAB1>
//UART4_TX PC.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PC.10
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOC, &GPIO_InitStructure);
//UART4_RX PC.11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPU;// GPIO_Mode_IN_FLOATING;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOC, &GPIO_InitStructure);
//Uart4 NVIC <20><><EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
NVIC_Init(&NVIC_InitStructure); //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
//USART <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_InitStructure.USART_BaudRate = bound;//һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//<2F>ֳ<EFBFBD>Ϊ8λ<38><CEBB><EFBFBD>ݸ<EFBFBD>ʽ
USART_InitStructure.USART_StopBits = USART_StopBits_1;//һ<><D2BB>ֹͣλ
USART_InitStructure.USART_Parity = USART_Parity_No;//<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//<2F><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //<2F>շ<EFBFBD>ģʽ
USART_Init(UART4, &USART_InitStructure); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_Cmd(UART4, ENABLE); //ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
USART_ITConfig(UART4, USART_IT_TC, ENABLE);
USART_ITConfig(UART4, USART_IT_IDLE, ENABLE);
}
void UART4_IRQHandler(void) //<2F><><EFBFBD><EFBFBD>4<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
u8 Res;
static u8 index = 0;
if (USART_GetITStatus(UART4, USART_IT_RXNE)!= RESET)
{
Res =USART_ReceiveData(UART4);//(USART1->DR); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(UART4_RX_LEN<UART4_REC_LEN)
UART4_RX_BUF[UART4_RX_LEN++] = Res;
else
UART4_RX_LEN =0;
if (Res == 0x0A) { // Shell<6C><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ShellCommad();
ResetShell();
return;
}
USART_ClearITPendingBit(UART4,USART_IT_RXNE);
}
if(USART_GetITStatus(UART4, USART_IT_IDLE) != RESET) //<2F><><EFBFBD>տ<EFBFBD><D5BF><EFBFBD><EFBFBD>ж<EFBFBD>
{
ResetShell();
USART_ReceiveData(UART4);
USART_ClearITPendingBit(UART4,USART_IT_IDLE);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
if (USART_GetITStatus(UART4, USART_IT_TXE)!= RESET)
{
USART_ClearITPendingBit(UART4,USART_IT_TXE);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
if(USART_GetITStatus(UART4, USART_IT_TC) != RESET)
{
USART_ClearITPendingBit(UART4,USART_IT_TC);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
if (USART_GetFlagStatus(UART4,USART_FLAG_ORE)==SET)
{
USART_ClearFlag(UART4,USART_FLAG_ORE); //<2F><>SR
USART_ReceiveData(UART4); //<2F><>DR
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
if (USART_GetFlagStatus(UART4,USART_FLAG_NE)==SET)
{
USART_ClearFlag(UART4,USART_FLAG_NE); //<2F><>SR
USART_ReceiveData(UART4); //<2F><>DR
}
//֡<><D6A1><EFBFBD><EFBFBD>
if (USART_GetFlagStatus(UART4,USART_FLAG_FE)==SET)
{
USART_ClearFlag(UART4,USART_FLAG_FE); //<2F><>SR
USART_ReceiveData(UART4); //<2F><>DR
}
}
#endif
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////UART5,PC12<31><32>PD2/////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
#if EN_UART5_RX //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>˽<EFBFBD><CBBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>״̬
//bit15<31><35> <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
//bit14<31><34> <09><><EFBFBD>յ<EFBFBD>0x0d
//bit13~0<><30> <09><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>Ŀ
u16 UART5_RX_STA=0; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
u8 UART5_RX_FLAG=0;
u16 UART5_RX_LEN=0; //<2F><><EFBFBD>ճ<EFBFBD><D5B3><EFBFBD>
u8 UART5_RX_BUF[UART5_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD>.
void uart5_init(u32 bound){
//GPIO<49>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD, ENABLE); //ʹ<><CAB9>USART1<54><31>GPIOC,Dʱ<44><CAB1>
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); //ʹ<><CAB9>UART5ʱ<35><CAB1>
//UART5_TX PC.12
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //PC.12
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOC, &GPIO_InitStructure);
//UART5_RX PD.2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOD, &GPIO_InitStructure);
//Usart1 NVIC <20><><EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
NVIC_Init(&NVIC_InitStructure); //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD>
//USART <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_InitStructure.USART_BaudRate = bound;//һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//<2F>ֳ<EFBFBD>Ϊ8λ<38><CEBB><EFBFBD>ݸ<EFBFBD>ʽ
USART_InitStructure.USART_StopBits = USART_StopBits_1;//һ<><D2BB>ֹͣλ
USART_InitStructure.USART_Parity = USART_Parity_No;//<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>λ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//<2F><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //<2F>շ<EFBFBD>ģʽ
USART_Init(UART5, &USART_InitStructure); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
USART_ITConfig(UART5, USART_IT_IDLE, ENABLE);//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
USART_Cmd(UART5, ENABLE); //ʹ<>ܴ<EFBFBD><DCB4><EFBFBD>
}
void USART5SendByte(unsigned char Byte)
{
USART_SendData(UART5, Byte);
while (!(UART5->SR & USART_FLAG_TXE));
}
void RS232_Uart5_Write(uint8_t* buff, int length)
{
int i = 0;
for(i =0;i<length;i++)
{
USART5SendByte(buff[i]);
}
}
void UART5_IRQHandler(void) //<2F><><EFBFBD><EFBFBD>1<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
u8 Res;
static u8 index =0;
if(USART_GetITStatus(UART5,USART_IT_RXNE)!= RESET)
{
Res =USART_ReceiveData(UART5);//(USART1->DR); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(UART5_RX_LEN<UART5_REC_LEN)
UART5_RX_BUF[UART5_RX_LEN++] = Res;
else
UART5_RX_LEN =0;
UART5_RX_STA = 0;
UART5_RX_FLAG = 0;
USART_ClearITPendingBit(UART5,USART_IT_RXNE);
}
if(USART_GetITStatus(UART5, USART_IT_IDLE) != RESET) //<2F><><EFBFBD>տ<EFBFBD><D5BF><EFBFBD><EFBFBD>ж<EFBFBD>
{
USART_ReceiveData(UART5);
UART5_RX_FLAG = 1;
USART_ClearITPendingBit(UART5,USART_IT_IDLE);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
if(USART_GetITStatus(UART5, USART_IT_TC) != RESET)
{
USART_ClearITPendingBit(UART5,USART_IT_TC);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
if (USART_GetFlagStatus(UART5,USART_FLAG_ORE)==SET)
{
USART_ClearFlag(UART5,USART_FLAG_ORE); //<2F><>SR
USART_ReceiveData(UART5); //<2F><>DR
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
if (USART_GetFlagStatus(UART5,USART_FLAG_NE)==SET)
{
USART_ClearFlag(UART5,USART_FLAG_NE); //<2F><>SR
USART_ReceiveData(UART5); //<2F><>DR
}
//֡<><D6A1><EFBFBD><EFBFBD>
if (USART_GetFlagStatus(UART5,USART_FLAG_FE)==SET)
{
USART_ClearFlag(UART5,USART_FLAG_FE); //<2F><>SR
USART_ReceiveData(UART5); //<2F><>DR
}
}
static DP_FrameBluetooth_t Blue_Send_Package;
uint8_t DP_PackageWriteDataFrame(DP_FrameBluetooth_t *pPara, uint8_t *pBuf, uint16_t *ucDatalen);
void Bluetooth_DCDC_Data(void);
void BMS_StatusMessage(void);
void BMS_ChargeInfo(void);
void ResetShell(void)
{
UART4_RX_LEN =0;
}
SH_CMD incmd;
void cmd_ADPrint(void);
void cmd_PhoneTest(void);
void cmd_TT(void);
void cmd_SetAPNUser(void);
void cmd_SetAPNPassword(void);
void cmd_DecodeUniquID(void);
void cmd_SetSW(void);
static uint8_t ParseCommandParam(void);
//extern CanRxMsg testBMSCAN1Msg;
//extern CanRxMsg testBMSCAN2Msg;
//extern CanTxMsg testBMSCAN2MsgTx;
uint8_t DC_Power_ManualTest_Flag =0;
extern dcdownload_t FDCPowerDownLoadInfo; //<2F><><EFBFBD>صĽṹ<C4BD><E1B9B9>
void cmd_ONDCDCPrint(void)
{
}
void cmd_OFFDCDCPrint(void)
{
}
void cmd_DecodeUniquID(void)
{
NVIC_SystemReset();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ\r\n");
}
void cmd_cansend(void)
{
static uint16_t i =0;
if(i == 0)
{
i = 1;
CLOSE_AUXI_BOOT();
CLOSE_HV_RELAY();
printf("<EFBFBD>رո<EFBFBD>ѹģ<EFBFBD><EFBFBD>\r\n");
}
else
{
i = 0;
OPEN_AUXI_BOOT();
OPEN_HV_RELAY();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹģ<EFBFBD><EFBFBD>\r\n");
}
}
void cmd_OFF(void)
{
static uint16_t i =0;
if(i == 0)
{
i = 1;
CLOSE_DC_RELAY();
printf("<EFBFBD>ر<EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD><EFBFBD><EFBFBD>\r\n");
}
else
{
i = 0;
OPEN_DC_RELAY();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD><EFBFBD><EFBFBD>\r\n");
}
}
void cmd_AC_RealyI(void)
{
static uint16_t i =0;
if(i == 0)
{
i = 1;
CLOSE_AC_RELAY();
printf("<EFBFBD>رս<EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD><EFBFBD><EFBFBD>\r\n");
}
else
{
i = 0;
OPEN_AC_RELAY();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD><EFBFBD><EFBFBD>\r\n");
}
}
void cmd_Realy400(void)
{
static uint16_t i =0;
if(i == 0)
{
i = 1;
CLOSE_AUXI_BOOT();
printf("<EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD>ѹģ<EFBFBD><EFBFBD>\r\n");
}
else
{
i = 0;
OPEN_AUXI_BOOT();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹģ<EFBFBD><EFBFBD>\r\n");
}
}
void cmd_CC1CP(void)
{
static uint16_t i =0;
if(i == 0)
{
i = 1;
CLOSE_CC1_CP_RELAY();
printf("<EFBFBD>ر<EFBFBD>CC1CP\r\n");
}
else
{
i = 0;
OPEN_CC1_CP_RELAY();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>CC1CP\r\n");
}
}
void cmd_CC2CC(void)
{
static uint16_t i =0;
if(i == 0)
{
i = 1;
CLOSE_CC2_CC_RELAY();
printf("<EFBFBD>ر<EFBFBD>CC2_CC\r\n");
}
else
{
i = 0;
OPEN_CC2_CC_RELAY();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>CC2_CC\r\n");
}
}
void cmd_ACTemp(void)
{
static uint16_t i =0;
if(i == 0)
{
i = 1;
CLOSE_GUN_TEMP_RELAY();
printf("<EFBFBD>ر<EFBFBD>DC<EFBFBD>¶ȼ̵<EFBFBD><EFBFBD><EFBFBD>\r\n");
}
else
{
i = 0;
OPEN_GUN_TEMP_RELAY();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>DC<EFBFBD>¶ȼ̵<EFBFBD><EFBFBD><EFBFBD>\r\n");
}
}
void Read_Flash_SN()
{
printf("Order_Code ");
RS232_Uart4_Write(Storage_Param.Order_Code,Order_CodeLEN);
printf("\r\n");
}
void OPEN_DEBUG()
{
static uint16_t i =0;
if(i == 0)
{
i = 1;
CDZ_SYS.work_pattern = 0;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ģʽ\r\n");
}
else
{
i = 0;
CDZ_SYS.work_pattern = 1;
printf("<EFBFBD>ر<EFBFBD><EFBFBD>ϻ<EFBFBD>ģʽ\r\n");
}
}
void GET_SN()
{
if(strstr((char *)incmd.cmd,"Order_Code")!=NULL)
{
Save_Order_Code(incmd.param[0],incmd.paramlen[0]-2);//ȥ<><C8A5>/r/n
}
if(strstr((char *)incmd.cmd,"Set_SN")!=NULL)
{
Save_Product_Code(incmd.param[0],incmd.paramlen[0]*4+3);//4<><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD><EFBFBD>ո<EFBFBD>
}
}
static const SHELLMAP shellmap[] =
{
{SHELL_TEST,"SET", cmd_ADPrint}, //
{SHELL_TEST,"ONDCDC", cmd_ONDCDCPrint}, //
{SHELL_TEST,"OFFDCDC", cmd_OFFDCDCPrint}, //
{SHELL_TEST,"READMASS", cmd_PhoneTest}, //
{SHELL_TEST,"TESTBMS",cmd_TT},//
{SHELL_TEST,"SETAPNUSER",cmd_SetAPNUser}, //
{SHELL_TEST,"SETAPNPWD",cmd_SetAPNPassword}, //
{SHELL_TEST,"Reset",cmd_DecodeUniquID}, //
{SHELL_TEST,"KC56",cmd_cansend},
{SHELL_TEST,"DCcut",cmd_OFF} ,
{SHELL_TEST,"ACcut",cmd_AC_RealyI},
{SHELL_TEST,"RealyHigh400",cmd_Realy400},
{SHELL_TEST,"CC1CPRealy",cmd_CC1CP},
{SHELL_TEST,"CC2CCRealy",cmd_CC2CC},
{SHELL_TEST,"GUNTempRealy",cmd_ACTemp},
{SHELL_TEST,"AC_rEOPEN",KC_ACtEXT_Open},
{SHELL_TEST,"AC_rEcLOSE",KC_ACtEXT_Close},
{SHELL_TEST,"ACRelayON",OPEN_12VPowerRealy},
{SHELL_TEST,"ACRelayOFF",CLOSE_12VPowerRealy},
{SHELL_TEST,"Read_OrderCode",Read_Flash_SN},
{SHELL_TEST,"Open_Debug",OPEN_DEBUG},
};
uint16_t indexflag = 0;
static uint8_t ShellCommad(void)
{
uint16_t i;
void (*cmdfunc)(void);
if (ParseCommandParam() == 0) return 0;
GET_SN();
//UpCaseChar(incmd.cmd,incmd.cmdlen);
for (indexflag=0;indexflag<sizeof(shellmap)/sizeof(SHELLMAP);indexflag++)
{
//S_DEBUGF("<22><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>:%m\n",shellmap[i].command,strlen(shellmap[i].command));
// if (incmd.cmdlen != strlen(shellmap[i].command)) continue;
if (strstr(incmd.cmd,shellmap[indexflag].command))
// if (memcmp(incmd.cmd,shellmap[i].command,incmd.cmdlen) == 0)
{
cmdfunc = shellmap[indexflag].cmdfunc;
if (cmdfunc != NULL) {
// printf(" >ִ<><D6B4>ָ<EFBFBD><D6B8>:%s...\n",incmd.cmd,incmd.cmdlen);
(*cmdfunc)();
}
return 1;
}
}
// printf("An unrecognized CMD !\n");
return 0;
}
uint8_t SemiHexToChar(uint8_t sbyte)
{
sbyte &= 0x0F;
if (sbyte < 0x0A) return (sbyte + '0');
else return (sbyte - 0x0A + 'A');
}
uint8_t CharToSemiHex(uint8_t schar)
{
if (schar >= '0' && schar <= '9') return (schar - '0');
else if (schar >= 'A' && schar <= 'F') return (schar - 'A' + 0x0A);
else if (schar >= 'a' && schar <= 'f') return (schar - 'a' + 0x0A);
else return 0;
}
uint8_t IsHexChar (uint8_t schar)
{
if (((schar >= '0') && (schar <= '9'))
|| ((schar >= 'A') && (schar <= 'F'))
|| ((schar >= 'a') && (schar <= 'f'))){
return TRUE;
}
return FALSE;
}
// SAMPLE: '1','2','3','4' -----> 1234
uint32_t StringToInt(uint8_t *sptr, uint8_t len)
{
uint32_t result;
result = 0;
for (; len > 0; len--) {
if (IsHexChar(*sptr)){
result = result * 10 + CharToSemiHex(*sptr++);
}
}
return result;
}
void cmd_ADPrint(void)
{
}
void cmd_PhoneTest(void)
{
}
void cmd_TT(void)
{
}
void cmd_SetAPNUser(void)
{
}
void cmd_SetAPNPassword(void)
{
}
/******************************************************************************************
FOR TEST SYSPARA , delet before release
******************************************************************************************/
uint16_t KeyLocation(uint8_t *sptr, char key, uint8_t keyindex,uint16_t limit)
{
uint16_t loc;
loc = 0;
for (;;) {
if (*sptr++ == key) {
if (keyindex == 1) break;
else keyindex--;
}
if (limit == 0) break;
else loc++;
limit--;
}
return loc;
}
static uint8_t ParseCommandParam(void)
{
uint16_t inlen,index,tlen;
uint8_t cnt;
inlen = UART4_RX_LEN;
//if (inlen == 0) return false;
cnt = 1;
incmd.cmd = UART4_RX_BUF;
incmd.paranum = 0;
index = KeyLocation(UART4_RX_BUF,' ',cnt,inlen);
incmd.cmdlen = index;
// printf("inout cmd:%s\n",incmd.cmd);
if (index == inlen) {
return 1;
}
cnt++;
while (index != inlen) {
if (UART4_RX_BUF[index] == ' ') {
index++;
} else {
tlen = index;
incmd.param[incmd.paranum] = &UART4_RX_BUF[index];
index = KeyLocation(UART4_RX_BUF,' ',cnt,inlen);
//if (index != inlen) {
incmd.paramlen[incmd.paranum] = index - tlen;
printf("%d param:%s\n",incmd.paranum,incmd.param[incmd.paranum]);
incmd.paranum++;
if (incmd.paranum >= MAX_PARAM) break;
cnt++;
}
}
return 1;
}
/* Table of CRC values for high<67>Corder byte */
static uint8_t const auchCRCHi[] =
{
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81,
0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01,
0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01,
0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,
0x40
} ;
/* Table of CRC values for low<6F>Corder byte */
static const char auchCRCLo[] =
{
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4,
0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD,
0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7,
0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,
0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE,
0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2,
0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,
0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB,
0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91,
0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88,
0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80,
0x40
} ;
uint16_t BlueCRC16(uint8_t *puchMsg, uint16_t usDataLen)
{
uint8_t uchCRCHi = 0xFF ; /* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>*/
uint8_t uchCRCLo = 0xFF ; /* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>*/
uint8_t uIndex ; /*<2A><>CRC<52><43>*/
while (usDataLen--) /*ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>*/
{
uIndex = uchCRCHi ^ *puchMsg++ ; /*<2A><><EFBFBD><EFBFBD>CRC */
uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex] ;
uchCRCLo = auchCRCLo[uIndex] ;
}
return (uchCRCHi << 8 | uchCRCLo) ;
}
#if 0
uint16_t Blue3CRC16(uint8_t *puchMsg, uint16_t usDataLen,u16 predata)
{
uint8_t uchCRCHi = 0xFF ; /* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>*/
uint8_t uchCRCLo = 0xFF ; /* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>*/
uint8_t uIndex ; /*<2A><>CRC<52><43>*/
#if 1
uchCRCHi = predata >>8;
uchCRCLo = predata & 0xff ;
#else
uchCRCLo = predata >>8;
uchCRCHi = predata & 0xff ;
#endif
while (usDataLen--) /*ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>*/
{
uIndex = uchCRCHi ^ *puchMsg++ ; /*<2A><><EFBFBD><EFBFBD>CRC */
uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex] ;
uchCRCLo = auchCRCLo[uIndex] ;
}
return (uchCRCHi << 8 | uchCRCLo) ;
}
#endif
uint16_t Blue2CRC16(uint8_t *puchMsg, uint16_t usDataLen,u16 predata)
{
uint8_t uchCRCHi = 0xFF ; /* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>*/
uint8_t uchCRCLo = 0xFF ; /* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>*/
uint8_t uIndex ; /*<2A><>CRC<52><43>*/
#if 1
uchCRCHi = predata >>8;
uchCRCLo = predata & 0xff ;
#else
uchCRCLo = predata >>8;
uchCRCHi = predata & 0xff ;
#endif
while (usDataLen--) /*ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>*/
{
uIndex = uchCRCHi ^ *puchMsg++ ; /*<2A><><EFBFBD><EFBFBD>CRC */
uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex] ;
uchCRCLo = auchCRCLo[uIndex] ;
}
return (uchCRCHi << 8 | uchCRCLo) ;
}
#if 0
const static unsigned short crc16L[] =
{
0x0000, 0xC0C1, 0xC181, 0x0140,
0xC301, 0x03C0, 0x0280, 0xC241,
0xC601, 0x06C0, 0x0780, 0xC741,
0x0500, 0xC5C1, 0xC481, 0x0440,
};
const static unsigned short crc16H[] =
{
0x0000, 0xCC01, 0xD801, 0x1400,
0xF001, 0x3C00, 0x2800, 0xE401,
0xA001, 0x6C00, 0x7800, 0xB401,
0x5000, 0x9C01, 0x8801, 0x4400,
};
unsigned short CRC16_Modbus(unsigned short BreakPoint, unsigned char *Buffer, unsigned int Length)
{
unsigned short CRCValue;
unsigned char Dat;
CRCValue = BreakPoint;
while (Length--)
{
Dat = *Buffer++;
Dat ^= CRCValue;
CRCValue >>= 8;
CRCValue ^= crc16L[Dat & 0x0F];
CRCValue ^= crc16H[(Dat>>4) & 0x0F];
}
return CRCValue;
}
#endif
#if 0
unsigned short CRC16_Modbus(unsigned short BreakPoint, unsigned char *Buffer, unsigned int Length)
{
unsigned short CRCValue;
unsigned char Dat;
CRCValue = BreakPoint;
while (Length--)
{
Dat = *Buffer++;
Dat ^= CRCValue;
CRCValue >>= 8;
CRCValue ^= crc16L[Dat & 0x0F];
CRCValue ^= crc16H[(Dat>>4) & 0x0F];
}
return CRCValue;
}
#endif
/*-----------------------usart 2 Blue State----------------------------*/
BlueManage_t BluetoothInfo;
void USART2_BLUR_Config(void)
{
}
/*<2A><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>*/
void RS232_Blue_Write(uint8_t* buff, int length)
{
int i = 0;
for(i =0;i<length;i++)
{
USART2SendByte(buff[i]);
}
USART2SendByte('\r');
USART2SendByte('\n');
for(i =0;i<length;i++)
{
UART4SendByte(buff[i]);
}
// UART4SendByte('\r');
// UART4SendByte('\n');
}
void RS232_Blue_DataWrite(uint8_t* buff, int length)
{
int i = 0;
// if(BluetoothInfo.ConnectServerState == BLUE_WECHATAPPLET_ONLINE)
// {
//
//
// printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: \r\n");
// }
for(i =0;i<length;i++)
{
USART2SendByte(buff[i]);
}
}
/***********************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>******************************/
/* LCD<43><44><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
typedef struct LCD_FramePara__
{
uint8_t ucLen; //<2F>ܳ<EFBFBD><DCB3><EFBFBD>(<28><>ȥͷ<C8A5>ֽ<EFBFBD>)
uint16_t iAddress; // <09>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
uint8_t ucFunCode; // <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t ucRegLen; // <09>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t ucDataSpace[200]; // <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}LCD_DP_Frame;
LCD_DP_Frame Lcd_Rev_Data;
static const uint8_t FRAME_REV_HEAD[] = {0xA5,0x5A};
static uint8_t chk_receivehead(uint8_t ch)
{
static uint8_t revhead[2] ={0};
revhead[0] = revhead[1];
revhead[1] = ch;
if (memcmp(revhead,FRAME_REV_HEAD,sizeof(revhead)) == 0) {
memset(revhead,0,sizeof(revhead));
return TRUE;
} else {
return FALSE;
}
}
uint8_t CheckSum(uint8_t *data,uint16_t len)
{
uint16_t i =0;
uint8_t sum;
for(i=0;i<len;i++)
{
sum+=*(data++);
}
return sum;
}
static uint8_t SocCalculateOver(void)
{
// uint8_t i,j;
// calibration_t temp;
// if(SocCalculate.index >CALIBRATION_NUM)SocCalculate.index =CALIBRATION_NUM;
// for(j=0;j<SocCalculate.index-1;j++)//<2F><><EFBFBD><EFBFBD>
// {
// for(i=0;i<SocCalculate.index-j-1;i++)
// {
// if(SocCalculate.data[i].startVolt > SocCalculate.data[i+1].startVolt)
// {
// temp = SocCalculate.data[i]; //<2F><>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// SocCalculate.data[i] = SocCalculate.data[i+1];
// SocCalculate.data[i+1] = temp;
// }
// }
// }
// //<2F><><EFBFBD><EFBFBD>Ȩֵ
// for(i=0;i<SocCalculate.index;i++)
// {
// SocCalculate.data[i].endVolt = SocCalculate.data[i+1].startVolt;
// SocCalculate.data[i].endSoc = SocCalculate.data[i+1].startSoc;
// SocCalculate.data[i].weight = (SocCalculate.data[i].endSoc-SocCalculate.data[i].startSoc)/
// (SocCalculate.data[i].endVolt-SocCalculate.data[i].startVolt);
// }
// //д<><D0B4><EFBFBD>ڴ<EFBFBD>
// SocCalculate.CalibrationEnable =1;
// SocCalculate.checksum = CheckSum(&SocCalculate.CalibrationEnable,sizeof(Compensation_t)-1);
// SysWriteSocParm();
return 0;
}
uint8_t SocCalculateCharging(void)
{
uint8_t i,j;
calibration_t temp;
if(SocCalculate.CalibrationEnable !=1)return 0;
if(SocCalculate.index >CALIBRATION_NUM)SocCalculate.index =CALIBRATION_NUM;
#if 0
for(i=0;i<SysParaPileD.SocCalculate.index;i++)
{
if(SysParaPileD.SocCalculate.data[i].startVolt > SysParaPileD.SocCalculate.data[i+1].startVolt)
{
temp = SysParaPileD.SocCalculate.data[i]; //<2F><>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SysParaPileD.SocCalculate.data[i] = SysParaPileD.SocCalculate.data[i+1];
SysParaPileD.SocCalculate.data[i+1] = temp;
}
}
#endif
// //<2F><><EFBFBD><EFBFBD>Ȩֵ
// for(i=0;i<SocCalculate.index;i++)
// {
// if(i==0)
// {
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>soc<6F>ĵ<EFBFBD>ѹ--
// if(Sample_DataS.BAT_Voltage < SocCalculate.data[0].startVolt)
// {
// return 2;//<2F><>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><E3B7A8><EFBFBD><EFBFBD>
// }
// }
//
// //else
// {
// if((Sample_DataS.BAT_Voltage >= SocCalculate.data[i].startVolt)\
// &&(Sample_DataS.BAT_Voltage < SocCalculate.data[i].endVolt))
// {
//
// Bms_BatChargeRealInfo.uBatCurSOC = SocCalculate.data[i].startSoc+
// (Sample_DataS.BAT_Voltage-SocCalculate.data[i].startVolt)*SocCalculate.data[i].weight;;
// return 1 ;
// }
// }
// }
// //д<><D0B4><EFBFBD>ڴ
// if(i==SocCalculate.index)
// {
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>soc<6F>ĵ<EFBFBD>ѹ--
// if(Sample_DataS.BAT_Voltage > SocCalculate.data[i].startVolt)
// {
// return 2;//<2F><>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><E3B7A8><EFBFBD><EFBFBD>
// }
// }
return 0;
}
uint16_t udatatemp =0;
typedef struct
{
uint16_t BmsMaxVolt; //<2F><><EFBFBD>ض<D8B6><EEB6A8>ѹ==<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ BatMaxTotalChargeVol
uint16_t BmsMaxCurrent;
uint16_t TotalVoltage;//<2F><><EFBFBD>ض<D8B6><EEB6A8>ѹ
uint16_t TotalCapacity; //<2F><><EFBFBD>ض<D8B6><EEB6A8><EFBFBD><EFBFBD>
uint16_t BatMaxChargeCur;
uint16_t uBatMaxEnergy; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16_t BatMaxTotalChargeVol; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD>ѹ
uint16_t fTotalBatVol;
//ע<><D7A2><EFBFBD><EFBFBD>
uint16_t BmRequireVolt;
uint16_t BmsRequireCurrent;
uint16_t StopVoltage;
uint16_t RequirePower; //<2F><EFBFBD><E3B9A6>ʱ<EFBFBD>Դ˱<D4B4><CBB1><EFBFBD>Ϊ<EFBFBD><CEAA>
uint16_t OverPower;
uint8_t tricklepower; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t tricklecurrent; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint16_t BatMaxChargeVol; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ(0.00~24.00V) 0.01V
uint16_t BatRatedVoltage; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<D8B6><EEB6A8>ѹ 0.1V
uint8_t uBatMaxTempPlus50; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(-50~200<30><30>)
uint8_t uBatMinTempPlus50; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//DCDC<44><43><EFBFBD><EFBFBD>
uint8_t DCMaxPower;
}s_data_temp_t;
s_data_temp_t sysparamdata;
void updata_param(void)
{
sysparamdata.BmsMaxVolt = SysParaPileD.BmsMaxVolt/10;
sysparamdata.BmsMaxCurrent = SysParaPileD.BmsMaxCurrent/10;
sysparamdata.BmRequireVolt = SysParaPileD.BmRequireVolt/10;
sysparamdata.OverPower =SysParaPileD.OverPower/10;
sysparamdata.StopVoltage =SysParaPileD.StopVoltage/10;
sysparamdata.BmsRequireCurrent=SysParaPileD.BmsRequireCurrent/10;
sysparamdata.tricklepower =SysParaPileD.tricklepower/10;
sysparamdata.tricklecurrent = SysParaPileD.tricklecurrent/10;
sysparamdata.RequirePower =SysParaPileD.RequirePower/10;
sysparamdata.BatMaxChargeVol =SysParaPileD.BatMaxChargeVol/10;
sysparamdata.BatRatedVoltage= SysParaPileD.BatRatedVoltage/10;
sysparamdata.BatMaxChargeVol=SysParaPileD.BatMaxChargeVol/10;
sysparamdata.uBatMinTempPlus50=SysParaPileD.uBatMinTempPlus50-50;
sysparamdata.uBatMaxTempPlus50=SysParaPileD.uBatMaxTempPlus50-50;
sysparamdata.DCMaxPower=SysParaPileD.DCMaxPower;
}
static SysparamTable_t paramTable[] =
{
{0x02,1,(uint8_t *)&udatatemp},
{0x01,1,(uint8_t *)&udatatemp},
{0x03,1,(uint8_t *)&udatatemp},
{0x05,16,(uint8_t *)SysParaPileD.bluetooth_passward},
{0x04,16,(uint8_t *)SysParaPileD.bluetooth_name},
{0x06 ,2,(uint8_t *)&SysParaPileD.OverTempValue},//<2F>¶ȱ<C2B6><C8B1><EFBFBD>ֵ
{0x07 ,2,(uint8_t *)&SysParaPileD.HeartBeatTime},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
{0x08 ,1,(uint8_t *)&SysParaPileD.ProtocolType},//<2F><><EFBFBD>Ϲ<EFBFBD><CFB9><EFBFBD>Э<EFBFBD><D0AD>
{0x09 ,16,(uint8_t *)SysParaPileD.sn},//<2F><><EFBFBD><EFBFBD>SN<53><4E>
{0x0A ,1,(uint8_t *)&SysParaPileD.QuickChargeEnable},//<2F><><EFBFBD>߿<EFBFBD><DFBF><EFBFBD>ʹ<EFBFBD><CAB9>
{0x0F ,1,(uint8_t *)&SysParaPileD.tricklecurrent},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{0x0E ,1,(uint8_t *)&SysParaPileD.tricklepower},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E7B9A6>
{0x0D ,1,(uint8_t *)&SysParaPileD.trickleChargingSoc},//<2F><><EFBFBD><EFBFBD>soc
{0x0C ,1,(uint8_t *)&SysParaPileD.trickleChargingSocEnable},//<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
{0x0B ,1,(uint8_t *)&udatatemp},
{0x13,2,(uint8_t *)&SysParaPileD.BmsMaxCurrent},//<2F><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>
{0x12 ,2,(uint8_t *)&SysParaPileD.BmsMaxVolt},//<2F><><EFBFBD>õ<EFBFBD>ѹ
{0x11 ,2,(uint8_t *)&SysParaPileD.BmsRequireCurrent},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{0x10 ,2,(uint8_t *)&SysParaPileD.BmRequireVolt},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
{0x14,2,(uint8_t *)&udatatemp},//soc
// {0x15,2,(uint8_t *)&Sample_DataS.BAT_B_Reverse_Voltage},//<2F><>ǰ<EFBFBD><C7B0><EFBFBD>ص<EFBFBD>ѹ
{0x16,2,(uint8_t *)&SysParaPileD.uBatMaxEnergy},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// {0x17,4,(uint8_t *)&Bms_BatInfo.ucBmsVersion},//soc
{0x18,1,(uint8_t *)&SysParaPileD.ucBatType},//<2F><>ǰ<EFBFBD><C7B0><EFBFBD>ص<EFBFBD>ѹ
// {0x19,4,(uint8_t *)&Bms_BatInfo.ucProductName},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// {0x1A,3,(uint8_t *)&Bms_BatInfo.uProductYear},
// {0x1B,17,(uint8_t *)&SysParaPileD.VehichleInfo},
// {0x1C,8,(uint8_t *)&Bms_BatInfo.ucSoftwareVersion},
{0x1F,1,(uint8_t *)&sysparamdata.RequirePower},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{0x1E,1,(uint8_t *)&sysparamdata.OverPower},//<2F><><EFBFBD>߹<EFBFBD><DFB9><EFBFBD>
{0x1D,1,(uint8_t *)&SysParaPileD.ChargingMode},// <20><><EFBFBD><EFBFBD>ģʽ <20><><EFBFBD><EFBFBD> <20><EFBFBD><E3B9A6>
{0x20,1, (uint8_t *)&sysparamdata.BatRatedVoltage}, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB6A8>ѹ
{0x21 ,1,(uint8_t *)&sysparamdata.BatMaxChargeVol},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
{0x22 ,1,(uint8_t *)&SysParaPileD.BatCount},//<2F><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{0x24 ,2,(uint8_t *)&SysParaPileD.BmsMaxVolt},//ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
{0x23 ,2,(uint8_t *)&SysParaPileD.TotalCapacity},//ϵͳ<CFB5><EFBFBD><EEB6A8><EFBFBD><EFBFBD>
{0x27 ,1,(uint8_t *)&SysParaPileD.ucBatType},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{0x26 ,1,(uint8_t *)&sysparamdata.uBatMinTempPlus50},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{0x25 ,1,(uint8_t *)&sysparamdata.uBatMaxTempPlus50},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{0x28 ,2,(uint8_t *)&SysParaPileD.TotalVoltage},//ϵͳ<CFB5><EFBFBD><EEB6A8>ѹ
{0x29 ,1,(uint8_t *)&SysParaPileD.RequireVoltageDifference},//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʵ<EFBFBD>ѹ ѹ<><D1B9>
{0x2A ,2,(uint8_t *)&SysParaPileD.SimulatedCurrentBatVolt},//ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD>ѹ
{0x2B ,1,(uint8_t *)&SysParaPileD.Debug_Page_function},//<2F><><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//===========================================================
{0x30 ,2,(uint8_t *)&SysParaPileD.uBatMaxEnergy},//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{0x31 ,2,(uint8_t *)&sysparamdata.StopVoltage},//ͣ<><CDA3><EFBFBD><EFBFBD>ѹ
{0x32 ,1,(uint8_t *)&SysParaPileD.OverTempValue[0]},//<2F><EFBFBD>̽ͷ1
{0x33 ,1,(uint8_t *)&SysParaPileD.OverTempValue[1]},//<2F><EFBFBD>̽ͷ1
{0x34 ,1,(uint8_t *)&SysParaPileD.OverTempValue[2]},//<2F><EFBFBD>̽ͷ2
{0x35 ,1,(uint8_t *)&SysParaPileD.SignalLossFlag},//<2F>źŶ<C5BA>ʧ
{0x36 ,10,(uint8_t *)SysParaPileD.VehichleInfo},//<2F><><EFBFBD><EFBFBD>VIN
{0x37 ,7,(uint8_t *)&SysParaPileD.VehichleInfo[10]},//<2F><><EFBFBD><EFBFBD>VIN
//---------------------------------DCBMS------------------------------
{0x50 ,1,(uint8_t *)&SysParaPileD.WorkModel},
{0x51 ,2,(uint8_t *)&SysParaPileD.DCRequireVolt},
{0x52 ,2,(uint8_t *)&SysParaPileD.DCRequireCurrent},
{0x53 ,1,(uint8_t *)&SysParaPileD.DCMaxPower},
{0x54 ,1,(uint8_t *)&SysParaPileD.DC_InductanceTemp},
{0x55 ,1,(uint8_t *)&SysParaPileD.DC_IGBTTemp},
{0x56 ,2,(uint8_t *)&SysParaPileD.DCMaxVolt},
{0x57 ,2,(uint8_t *)&SysParaPileD.DCMaxCurrent},
{0x58 ,1,(uint8_t *)&SysParaPileD.CapacitanceTemp1},
{0x59 ,1,(uint8_t *)&SysParaPileD.DCBoxTemp2},
{0x5A ,1,(uint8_t *)&SysParaPileD.DoubleBatteryMode},
{0x60 ,1,(uint8_t *)&SysParaPileD.VIN_Enable},
{0x61 ,1,(uint8_t *)&SysParaPileD.BlueSignalLoss},
{0x62 ,1,(uint8_t *)&SysParaPileD.ChargeMode},
{0x63 ,2,(uint8_t *)&SysParaPileD.ChargeParam}, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{0x65 ,1,(uint8_t *)&SysParaPileD.HighVoltageModule}, //<2F><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3> 1<><31> 0<><30>
{0x66 ,1,(uint8_t *)&SysParaPileD.HighVoltageOffset}, //<2F><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3> У׼
{0x6D ,1,(uint8_t *)&SysParaPileD.SocSimulaType},//SOC<4F><43><EFBFBD>ʽ 1-can<61><6E>ȡ 2-socģ<63><C4A3> 3-SOCУ׼
{0x6E ,2,(uint8_t *)&SysParaPileD.SocSimulaMaxVolt},//SOCģ<43><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹȡ 2-socģ<63><C4A3> 3-SOCУ׼
{0x6F ,2,(uint8_t *)&SysParaPileD.SocSimulaMinVolt},//SOCģ<43><C4A3><EFBFBD><EFBFBD>С<EFBFBD><D0A1>ѹ-socģ<63><C4A3> 3-SOCУ׼
{0x70 ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[0]},
{0x71 ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[1]},
{0x72 ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[2]},
{0x73 ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[3]},
{0x74 ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[4]},
{0x75 ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[5]},
{0x76 ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[6]},
{0x77 ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[7]},
{0x78 ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[8]},
{0x79 ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[9]},
{0x7A ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[10]},
{0x7B ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[11]},
{0x7C ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[12]},
{0x7D ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[13]},
{0x7E ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[14]},
{0x7F ,2,(uint8_t *)&SysParaPileD.SocCalibrationVolt[15]},
{0x80 ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[0]},
{0x81 ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[1]},
{0x82 ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[2]},
{0x83 ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[3]},
{0x84 ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[4]},
{0x85 ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[5]},
{0x86 ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[6]},
{0x87 ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[7]},
{0x88 ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[8]},
{0x89 ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[9]},
{0x8A ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[10]},
{0x8B ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[11]},
{0x8C ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[12]},
{0x8D ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[13]},
{0x8E ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[14]},
{0x8F ,2,(uint8_t *)&SysParaPileD.SocCalibrationData[15]},
};
//u8 GetBnum[4];
void BMS_Updata2ACKInfo(void)
{
//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
static uint32_t timer,bagcnt = 0;
static uint32_t flag = 0;
static uint8_t start_soc = 0;
uint8_t ucComBuf[128];
uint16_t ucLen,data = 0;
Blue_Send_Package.cmd = 0x1021;
//bagcnt ++;
//Blue_Send_Package.ucDataSpace[0]=0x55;
//Blue_Send_Package.ucDataSpace[1]=0xaa;
Blue_Send_Package.ucDataSpace[0]=UpdHead.RecePagNum & 0xff;
Blue_Send_Package.ucDataSpace[1]=(UpdHead.RecePagNum >> 8) & 0xff;
Blue_Send_Package.ucDataSpace[2]=(UpdHead.RecePagNum >> 16) & 0xff;
Blue_Send_Package.ucDataSpace[3]=(UpdHead.RecePagNum >> 24) & 0xff;
Blue_Send_Package.len =4;
BluetoothInfo.connetcOvertimeFlag++;
printf("\n\rshengjiyingda \n\r");
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
debugdataprocess(&Blue_Send_Package.ucDataSpace[0],4);
}
extern record_t ChargeRecordInfo;
uint8_t paramnumcount = 0;
uint8_t ServerStop_ChargeFlag = 0;
uint8_t ServerSet_CmdFlag = 0;
u8 upddatabuf[300];
u16 updtcnt = 0;
u16 Getupdtcnt(void)
{
return updtcnt;
}
void Delupdtcnt(void)
{
if(updtcnt)
updtcnt --;
}
void sHandleParsePkg(void *pkg)
{
uint8_t addrparam,paramdata,i,j,paramnum,cnt,err_cnt = 0;
uint16_t data,Vcrc,Dcrc;
uint8_t ucComBuf[64]={0};
uint16_t ucLen = 0,QQ1Crc = 0xffff,H1crc;
u32 addr,readval;
u32 *Upddata; //// u32 Upddata;
u8 *pdata;
u16 updlen,Qcmd;
DP_FrameBluetooth_t *Blue_pkg =pkg;
BluetoothInfo.connetcOvertimeFlag = 0;
#if 1
if((Blue_pkg->cmd == 0x8020) || (Blue_pkg->cmd == 0x8021))
{
pdata = (u8 *)pkg;
updlen = Blue_pkg->len;
Qcmd = Blue_pkg->cmd;
if(Blue_pkg->len <= 300)
memcpy(upddatabuf,Blue_pkg->ucDataSpace,(Blue_pkg->len));
debugdataprocess(upddatabuf,updlen);
Dcrc = pdata[updlen - 1] <<8 | pdata[updlen - 2] ;
Vcrc = BlueCRC16(pdata, (updlen - 2));
printf("\n\rDcrc %0x,Vcrc %0x\n\r",Dcrc,Vcrc);
if(Dcrc != Vcrc)
{
printf("\n\r (Dcrc != Vcrc) return!!!!!\n\r");
return;
}
BluetoothInfo.ReciveDataOvertimeFlag = 0;
UpdProcess((Qcmd - 0x8020),upddatabuf,updlen);
updtcnt = 100;
BluetoothInfo.ConnectServerState = BLUE_WECHATAPPLET_UPDATA; //<2F><><EFBFBD><EFBFBD>
return;
}
#endif
switch(Blue_pkg->cmd)
{
case 0x8000: //ע<><D7A2><EFBFBD><EFBFBD>
case 0x0080: //ע<><D7A2><EFBFBD><EFBFBD>
if(Blue_pkg->ucDataSpace[0]==1)
{
BluetoothInfo.ConnectServerState = BLUE_LOGIN; //ע<><D7A2><EFBFBD>ɹ<EFBFBD>
SysParaPileD.registeredFlag = 1;
memset(SysParaPileD.registeredCode,0,sizeof(SysParaPileD.registeredCode));
memcpy( SysParaPileD.registeredCode,&Blue_pkg->ucDataSpace[1],8);
//д<><D0B4>flash<73><68><EFBFBD><EFBFBD>
BluetoothInfo.ConnectServerState = BLUE_LOGIN;
SysStoreSysParmflag =1;
printf("registered successed,Code %s\n\r",SysParaPileD.registeredCode);
}
else
{
printf("registered failed\n\r");
}
break;
case 0x8001: //<2F><>¼<EFBFBD><C2BC>
case 0x0180: //<2F><>¼<EFBFBD><C2BC>
if(Blue_pkg->ucDataSpace[0]==1)
{
//<2F><>½<EFBFBD>ɹ<EFBFBD>
BluetoothInfo.ConnectServerState = BLUE_WECHATAPPLET_ONLINE;
printf("Login Successed\n\r");
}
else
{
printf("Login Failed\n\r");
}
break;
case 0x8002: //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case 0x0280: //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("heart count %d\n\r",Blue_pkg->ucDataSpace[0]);
memcpy(&ChargeRecordInfo.date,&Blue_pkg->ucDataSpace[2],7) ;
break;
case 0x8003: //<2F><>ǰ״̬<D7B4><CCAC>
case 0x0380: //<2F><>ǰ״̬<D7B4><CCAC>
printf("receive state data \n\r");
break;
case 0x8004: //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case 0x0480: //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("receive charge data \n\r");
printf("charge %s\n\r",Blue_pkg->ucDataSpace[1] == 1 ? "Enable":"Disable");
if(Blue_pkg->ucDataSpace[1] == 0 )
{
ServerStop_ChargeFlag = 1;
if(stopChargeReason == 0)stopChargeReason = 4;//С<><D0A1><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
}
break;
case 0x8005: //<2F><><EFBFBD>ð<EFBFBD>
case 0x0580: //<2F><><EFBFBD>ð<EFBFBD>
ServerSet_CmdFlag = 1;
if(Blue_pkg->ucDataSpace[0] == 0)
printf("param read\n\r" );
else
printf("param write\n\r");
if(Blue_pkg->ucDataSpace[0] == 1 )
{
addrparam = Blue_pkg->ucDataSpace[1];
printf("param addr %x\n\r",addrparam);
if( addrparam == 0x01 )
{
if(Blue_pkg->ucDataSpace[2] == 0)
{
// g_ChargeStep = CC_CHARGE_END;
ServerStop_ChargeFlag = 1;
if(stopChargeReason == 0)stopChargeReason = 4;//С<><D0A1><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
}
printf("charging %s\n\r",Blue_pkg->ucDataSpace[2] == 1 ? "enable":"disable");
}
if( addrparam == 0x02 )
{
if(Blue_pkg->ucDataSpace[2] == 1)
{
printf("close relay\n\r");
// DC_CONTACTOR_KC4(1);
}
else
{
printf("open relay\n\r");
// DC_CONTACTOR_KC4(0);
}
}
if( addrparam == 0x04 )
{
data =strlen(&Blue_pkg->ucDataSpace[2]);
if(data < sizeof(SysParaPileD.bluetooth_name))
{
memcpy(SysParaPileD.bluetooth_name,&Blue_pkg->ucDataSpace[2],data);
printf("bluetooth name %s\n\r",&Blue_pkg->ucDataSpace[2]);
SysStoreSysParmflag =1;
}
else
{
printf("bluetooth name mistake %s\n\r",&Blue_pkg->ucDataSpace[2]);
}
}
if( addrparam == 0x07 )
{
data =Blue_pkg->ucDataSpace[2] ;
printf("Heart Beat Time %d sec\n\r",data);
SysParaPileD.HeartBeatTime = data;
SysStoreSysParmflag =1;
}
if( addrparam == 0x06)//<2F>¶ȱ<C2B6><C8B1><EFBFBD>ֵ
{
data =Blue_pkg->ucDataSpace[2] ;
printf("OverTempValue %d \n\r",data);
SysParaPileD.OverTempValue[0] = data;
SysParaPileD.OverTempValue[1] = data;
SysParaPileD.OverTempValue[2] = data;
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x08 )
{
data =Blue_pkg->ucDataSpace[2];
// if(data ==BMS_PROTOCAL_GB2015)
// {
// SysParaPileD.ProtocolType= BMS_PROTOCAL_GB2015;
// printf("BMS PROTOCAL GB2015\n\r");
//
// }
// else
// {
//// SysParaPileD.ProtocolType= BMS_PROTOCAL_GB2011;
// printf("BMS PROTOCAL GB2011\n\r");
// }
SysStoreSysParmflag =1;
}
if( addrparam == 0x09 )
{
data =strlen(&Blue_pkg->ucDataSpace[2]);
if(data < sizeof(SysParaPileD.sn))
{
memcpy(SysParaPileD.sn,&Blue_pkg->ucDataSpace[2],data);
printf("SysParaPileD.sn:%s\n\r",&Blue_pkg->ucDataSpace[2]);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
else
{
printf("SysParaPileD.sn fault %s\n\r",&Blue_pkg->ucDataSpace[2]);
}
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x0A )
{
data =Blue_pkg->ucDataSpace[2];
if(data ==1)
{
SysParaPileD.QuickChargeEnable= 1;
printf("Quick Charge Enable\n\r");
}
else
{
SysParaPileD.QuickChargeEnable= 0;
printf("Quick Charge Enable\n\r");
}
SysStoreSysParmflag =1;
}
if( addrparam == 0x0B ) //<2F><><EFBFBD>ص<EFBFBD>ǰSOC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
data =Blue_pkg->ucDataSpace[2] ;
// if(data ==1) //<2F><><EFBFBD><EFBFBD>socУ׼
// {
// memset((char *)&SocCalculate,0,sizeof(SocCalculate));
// SocCalculate.CalibrationEnable =0;
// SysWriteSocParm();
// printf("\n\rsoc<6F><63><EFBFBD><EFBFBD>У׼\n\r");
// }
// else if(data ==2) //socУ׼<D0A3><D7BC><EFBFBD><EFBFBD>
// {
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//// SocCalculateOver();
//// SysWriteSocParm();
// printf("\n\rsoc<6F><63><EFBFBD><EFBFBD>У׼<D0A3><D7BC><EFBFBD><EFBFBD>\n\r");
// }
}
if( addrparam == 0x0C) //<2F><><EFBFBD>ص<EFBFBD>ǰSOC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
data =Blue_pkg->ucDataSpace[2] ;
if(data ==1) //<2F><><EFBFBD><EFBFBD>socУ׼
{
SysParaPileD.trickleChargingSocEnable =1;
printf("trickle Charging Soc Enable 1\n\r");
}
else
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SysParaPileD.trickleChargingSocEnable =0;
printf("trickle Charging Soc Enable 0\n\r");
}
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x0D) //<2F><><EFBFBD>ص<EFBFBD>ǰSOC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
data =Blue_pkg->ucDataSpace[2] ;
if(data < 100) //<2F><><EFBFBD><EFBFBD>socУ׼
{
SysParaPileD.trickleChargingSoc =data;
printf("trickleChargingSoc%d\n\r",data);
}
else
{
printf("trickleChargingSoc 90\n\r");
SysParaPileD.trickleChargingSoc =90;
}
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x0E )
{
data =Blue_pkg->ucDataSpace[2];
printf("trickle power %d.%dkw\n\r",data/10,data%10);
SysParaPileD.tricklepower= data;
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x0F )
{
data =Blue_pkg->ucDataSpace[2];
printf("trickle current%dA\n\r",data);
SysParaPileD.tricklecurrent= data*10;
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x10 )
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
printf("BmsMaxVolt%d \n\r",data);
if(data*10 < SysParaPileD.BmsMaxVolt)
{
SysParaPileD.BmRequireVolt = data*10;
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
else
{
printf("%d BmsMaxVolt %d faild\n\r",data*10,SysParaPileD.BmsMaxVolt);
SysParaPileD.BmRequireVolt = SysParaPileD.BmsMaxVolt-20;
printf("BmRequireVolt %d \n\r",SysParaPileD.BmRequireVolt/10);
}
}
if( addrparam == 0x11 )
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
printf("BmsMaxCurrent %d \n\r",data);
if(data*10 < SysParaPileD.BmsMaxCurrent)
{
SysParaPileD.BmsRequireCurrent = data*10;
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
else
{
printf("req %d over max %d \n\r",data*10,SysParaPileD.BmsMaxCurrent);
}
}
if( addrparam == 0x12 )
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
printf("BmsMaxVolt %d \n\r",data);
SysParaPileD.BmsMaxVolt = data*10;
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x13 )
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
printf("BmsMaxCurrent%d \n\r",data);
SysParaPileD.BmsMaxCurrent = data*10;
// if(SysParaPileD.BmsMaxCurrent >BAT_MAX_CHARGE_CUR)SysParaPileD.BmsMaxCurrent = BAT_MAX_CHARGE_CUR;
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x14 ) //<2F><><EFBFBD>ص<EFBFBD>ǰSOC --<2D><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>soc
{
data =Blue_pkg->ucDataSpace[2];
printf("setting soc(%d)\n\r",data);
// printf("BAT_Voltage %d\n\r",(uint16_t)Sample_DataS.BAT_Voltage);
if(SocCalculate.index >CALIBRATION_NUM)SocCalculate.index =CALIBRATION_NUM;
// SocCalculate.data[SocCalculate.index].startVolt = Sample_DataS.BAT_Voltage;
SocCalculate.data[SocCalculate.index].startSoc = data;
SocCalculate.index++;
}
if( addrparam == 0x16 )
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.uBatMaxEnergy = data;
printf("uBatMaxEnergy %d.%d\n\r",data/10,data%10);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x1D ) // <20><><EFBFBD><EFBFBD>ģʽ <20><><EFBFBD><EFBFBD> <20><EFBFBD><E3B9A6>
{
data = Blue_pkg->ucDataSpace[2] ;
if(data ==1 || data ==2)
{
SysParaPileD.ChargingMode = data;
printf("ChargingMode:%s \n\r",data==1?"CC":"CV");
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
else
printf("ChargingMode Fault\n\r");
}
if( addrparam == 0x1E ) //<2F><><EFBFBD>߹<EFBFBD><DFB9><EFBFBD>
{
data = Blue_pkg->ucDataSpace[2] ;
SysParaPileD.OverPower = data*10;
printf("OverPower :%d.%dkwh\n\r",SysParaPileD.OverPower /10,SysParaPileD.OverPower %10 );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x1F ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
data = Blue_pkg->ucDataSpace[2] ;
if(SysParaPileD.RequirePower > SysParaPileD.OverPower )
{
printf("RequirePower %d kw OverPower :%dkw,fault\n\r",SysParaPileD.RequirePower /10,SysParaPileD.OverPower /10 );
SysParaPileD.RequirePower = SysParaPileD.OverPower-10;
printf("RequirePower %d kw \n\r",SysParaPileD.RequirePower /10);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
else
{
SysParaPileD.RequirePower = data*10;
printf("RequirePower :%d.%dkwh\n\r",SysParaPileD.RequirePower /10,SysParaPileD.RequirePower %10 );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
if( addrparam == 0x20 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB6A8>ѹ
{
data = Blue_pkg->ucDataSpace[2] ;
SysParaPileD.BatRatedVoltage = data*10;
printf("BatRatedVoltage :%d.%dV\n\r",SysParaPileD.BatRatedVoltage /100,SysParaPileD.BatRatedVoltage %100 );
// SysWriteSysParm();
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ(0.00~24.00V) 0.01V
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<D8B6><EEB6A8>ѹ 0.1V
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//soc<6F><63><EFBFBD><EFBFBD> ʹ<><CAB9>
//<2F><><EFBFBD><EFBFBD>soc<6F><63><EFBFBD><EFBFBD>ֵ
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( addrparam == 0x21 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
{
data = Blue_pkg->ucDataSpace[2] ;
SysParaPileD.BatMaxChargeVol = data*10;
printf("BatMaxChargeVol :%d.%dV\n\r",SysParaPileD.BatMaxChargeVol /100,SysParaPileD.BatMaxChargeVol %100 );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x22 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
data = Blue_pkg->ucDataSpace[2] ;
SysParaPileD.BatCount = data;
printf("BatCount :%d\n\r",SysParaPileD.BatCount );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x23 ) //ϵͳ<CFB5><EFBFBD><EEB6A8><EFBFBD><EFBFBD>
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.TotalCapacity = data;
printf("TotalCapacity :%d.%dAH\n\r",SysParaPileD.TotalCapacity/10,SysParaPileD.TotalCapacity%10);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x24 ) //ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.BmsMaxVolt = data;
printf("BmsMaxVolt:%d.%dv\n\r",SysParaPileD.BmsMaxVolt/10, SysParaPileD.BmsMaxVolt%10);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x25 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
data = Blue_pkg->ucDataSpace[2] ;
printf("uBatMaxTempPlus50 :%d \n\r", data );
SysParaPileD.uBatMaxTempPlus50 = data+50;
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x26 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
data = Blue_pkg->ucDataSpace[2] ;
printf("uBatMinTempPlus50 :%d \n\r",data );
SysParaPileD.uBatMinTempPlus50 = data+50;
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x27 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
data = Blue_pkg->ucDataSpace[2] ;
SysParaPileD.ucBatType = data;
if(data==1)
printf("ucBatType:Ǧ<><C7A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \n\r" );
if(data==2)
printf("ucBatType:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \n\r" );
if(data==3)
printf("ucBatType:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFAEB5><EFBFBD> \n\r" );
if(data==4)
printf("ucBatType:<3A><><EFBFBD><EFBFBD><EFBFBD><EFAEB5><EFBFBD> \n\r" );
if(data==5)
printf("ucBatType:<3A><><EFBFBD><EFBFBD><EFBFBD><EFAEB5><EFBFBD> \n\r" );
if(data==6)
printf("ucBatType:<3A><>Ԫ﮵<D4AA><EFAEB5><EFBFBD> \n\r" );
if(data==7)
printf("ucBatType:<3A>ۺ<EFBFBD><DBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD> \n\r" );
if(data==8)
printf("ucBatType:<3A><><EFBFBD><EFBFBD><EFBFBD><EFAEB5><EFBFBD> \n\r" );
if(data==0xff)
printf("ucBatType:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \n\r" );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x28) //ϵͳ<CFB5><EFBFBD><EEB6A8>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.TotalVoltage = data;
printf("TotalVoltage:%d \n\r",SysParaPileD.TotalVoltage /10 );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x29) //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʵ<EFBFBD>ѹ ѹ<><D1B9>
{
data = Blue_pkg->ucDataSpace[2] ;
if((data>=10)&&(data <=100))
{
SysParaPileD.RequireVoltageDifference = data;
printf("RequireVoltageDifference(%d)V \n\r",SysParaPileD.RequireVoltageDifference);
}
else
{
printf(" (%d)V over range \n\r",data);
SysParaPileD.RequireVoltageDifference = 0;
}
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x2A )
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
if((data >=1000) && (data<=3500))
{
SysParaPileD.SimulatedCurrentBatVolt = data;
printf("SimulatedCurrentBatVolt %dV\n\r",SysParaPileD.SimulatedCurrentBatVolt/10);
}
else
{
printf("SimulatedCurrentBatVolt %dV--100-350V\n\r",data);
}
SysStoreSysParmflag =1;
}
if( addrparam == 0x2B) // <20><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
{
data = Blue_pkg->ucDataSpace[2] ;
if(data==1)
SysParaPileD.Debug_Page_function = data;
else
SysParaPileD.Debug_Page_function =0;
printf("%s Debug_Page_function \n\r",SysParaPileD.Debug_Page_function==1?"OPEN":"CLOSE" );
SysStoreSysParmflag =1;
}
if( addrparam == 0x30 ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.uBatMaxEnergy = data;
printf("uBatMaxEnergy %d .%d \n\r",SysParaPileD.uBatMaxEnergy/10 ,SysParaPileD.uBatMaxEnergy%10 );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x31 ) //ͣ<><CDA3><EFBFBD><EFBFBD>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.StopVoltage = data*10;
printf("StopVoltage :%d.%d V \n\r",SysParaPileD.StopVoltage/10,SysParaPileD.StopVoltage%10 );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x32) //ͣ<><CDA3><EFBFBD><EFBFBD>--<2D><><EFBFBD><EFBFBD>
{
data = Blue_pkg->ucDataSpace[2] ;
SysParaPileD.OverTempValue[0] = data;
printf("OverTemp0Value:%d \n\r",SysParaPileD.OverTempValue[0] );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x33) //
{
data = Blue_pkg->ucDataSpace[2] ;
SysParaPileD.OverTempValue[1] = data;
printf("OverTemp1Value:%d \n\r",SysParaPileD.OverTempValue[1] );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x34) //
{
data = Blue_pkg->ucDataSpace[2] ;
SysParaPileD.OverTempValue[2] = data;
printf("OverTemp2Value:%d \n\r",SysParaPileD.OverTempValue[2] );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x35) //
{
data = Blue_pkg->ucDataSpace[2] ;
if(data==1)
SysParaPileD.SignalLossFlag = data;
else
SysParaPileD.SignalLossFlag =0;
printf("SignalLossFlag %s \n\r",SysParaPileD.SignalLossFlag==1?"Enable":"Disable" );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x36) //
{
// data =strlen(&Blue_pkg->ucDataSpace[2]);
// if(data <= sizeof(SysParaPileD.VehichleInfo))
// if(data <= 10)
{
memset(SysParaPileD.VehichleInfo,0,sizeof(SysParaPileD.VehichleInfo));
memcpy(SysParaPileD.VehichleInfo,&Blue_pkg->ucDataSpace[2],10);
printf("VehichleInfo(0-9):%s\n\r",&Blue_pkg->ucDataSpace[2]);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
// else
// {
// printf("\n\r<><72><EFBFBD><EFBFBD>VIN<49><4E><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>%s\n\r",&Blue_pkg->ucDataSpace[2]);
// }
// SysWriteSysParm();
}
if( addrparam == 0x37) //
{
// data =strlen(&Blue_pkg->ucDataSpace[2]);
// if(data <= sizeof(SysParaPileD.VehichleInfo))
{
// memset(SysParaPileD.VehichleInfo,0,sizeof(SysParaPileD.VehichleInfo));
memcpy(&SysParaPileD.VehichleInfo[10],&Blue_pkg->ucDataSpace[2],7);
printf("VehichleInfo VIN(10-17):%s\n\r",&Blue_pkg->ucDataSpace[2]);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
// else
// {
// printf("\n\r<><72><EFBFBD><EFBFBD>VIN<49><4E><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>%s\n\r",&Blue_pkg->ucDataSpace[2]);
// }
// SysWriteSysParm();
}
//---------------------------------DCBMS------------------------------
if( addrparam == 0x50) // רҵ<D7A8><D2B5><EFBFBD><EFBFBD>ģʽ
{
data = Blue_pkg->ucDataSpace[2] ;
if(data==1)
SysParaPileD.WorkModel = data;
else
SysParaPileD.WorkModel =0;
printf("WorkModel %s \n\r",SysParaPileD.WorkModel==1?"professional":"easy" );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x51) // DC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
if(data >= 48 && data <300)
SysParaPileD.DCRequireVolt = data*10;
else
{
printf("DCRequireVolt %d:Over(48-300) \n\r",data );
}
printf("DCRequireVolt:%d.%d V \n\r",SysParaPileD.DCRequireVolt/10,SysParaPileD.DCRequireVolt%10 );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x52) // DC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
if(data > 10 && data <100)
SysParaPileD.DCRequireCurrent = data*10;
else
{
printf("DCRequireCurrent%dA:Over(10-100A) \n\r",data );
}
printf("DCRequireCurrent%dA \n\r",SysParaPileD.DCRequireCurrent/10,SysParaPileD.DCRequireCurrent%10 );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x53) // DC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
data = Blue_pkg->ucDataSpace[2] ;
if(data > 10 && data <150)
SysParaPileD.DCMaxPower = data;
else
{
printf("DCMaxPower%d :Over(1-15k) \n\r",data );
}
printf("DCMaxPower:%d.%d kw \n\r",SysParaPileD.DCMaxPower/10,SysParaPileD.DCMaxPower%10 );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
/**************DC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>******************/
if( addrparam == 0x54) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> --
{
data = Blue_pkg->ucDataSpace[2] ;
SysParaPileD.DC_InductanceTemp = data;
printf("DC_InductanceTemp %d \n\r",SysParaPileD.DC_InductanceTemp);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x55) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> --
{
data = Blue_pkg->ucDataSpace[2] ;
SysParaPileD.DC_IGBTTemp = data;
printf("DC_IGBTTemp %d \n\r",SysParaPileD.DC_IGBTTemp);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x56) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ--
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
if(data >= 48 && data <250)
SysParaPileD.DCMaxVolt = data*10;
else
{
printf("DCMaxVolt %dV:Over(48-200V) \n\r",data );
}
printf("DC DCMaxVolt:%d.%d V \n\r",SysParaPileD.DCMaxVolt/10,SysParaPileD.DCMaxVolt%10 );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x57) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>--
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
if(data >= 20 && data <110)
SysParaPileD.DCMaxCurrent = data*10;
else
{
printf("DC DCMaxCurrent%d:Over(20-110) \n\r",data );
}
printf("DC DCMaxCurrent:%d.%d A \n\r",SysParaPileD.DCMaxCurrent/10,SysParaPileD.DCMaxCurrent%10 );
SysStoreSysParmflag =1;
}
if( addrparam == 0x58) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> --
{
data = Blue_pkg->ucDataSpace[2] ;
if(data <150 )
SysParaPileD.CapacitanceTemp1 = data;
printf("CapacitanceTemp1 %d \n\r",SysParaPileD.CapacitanceTemp1);
SysStoreSysParmflag =1;
}
if( addrparam == 0x59) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> --
{
data = Blue_pkg->ucDataSpace[2] ;
if(data <150 )
SysParaPileD.DCBoxTemp2 = data;
printf("DCBoxTemp2 %d \n\r",SysParaPileD.DCBoxTemp2);
SysStoreSysParmflag =1;
}
if( addrparam == 0x5A)
{
data = Blue_pkg->ucDataSpace[2] ;
if(data==1)
SysParaPileD.DoubleBatteryMode = data;
else
SysParaPileD.DoubleBatteryMode =0;
printf("DoubleBatteryMode %s\n\r",SysParaPileD.DoubleBatteryMode==1?"Enable":"Disable" );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x60) // <20>豸VIN<49><4E><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
{
data = Blue_pkg->ucDataSpace[2] ;
if(data==1)
SysParaPileD.VIN_Enable = data;
else
SysParaPileD.VIN_Enable =0;
printf("VIN Trans %s\n\r",SysParaPileD.VIN_Enable==1?"Enable":"Disable" );
SysStoreSysParmflag =1;
}
if( addrparam == 0x61) // <20>źŶ<C5BA>ʧ
{
data = Blue_pkg->ucDataSpace[2] ;
if(data==1)
SysParaPileD.BlueSignalLoss = data;
else
SysParaPileD.BlueSignalLoss =0;
printf("BlueSignalLoss%s\n\r",SysParaPileD.BlueSignalLoss==1?"Enable":"Disable" );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x62) // <20><><EFBFBD>ʽ
{
data = Blue_pkg->ucDataSpace[2] ;
if(data<=3)
SysParaPileD.ChargeMode = data;
else
SysParaPileD.ChargeMode =0;
if(SysParaPileD.ChargeMode==1)
printf("ChargeMode--kwh\n\r" );
if(SysParaPileD.ChargeMode==2)
printf("ChargeMode--time\n\r" );
if(SysParaPileD.ChargeMode==3)
printf("ChargeMode--SOC\n\r" );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x63) // <20><>ֵ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
if(SysParaPileD.ChargeMode==1)
{
printf("ChargeMode-kwh(%d)\n\r",data );
}
if(SysParaPileD.ChargeMode==2)
{
printf("ChargeMode-time(%d)\n\r",data );
}
if(SysParaPileD.ChargeMode==3)
{
printf("ChargeMode-SOC(%d)\n\r",data );
}
SysParaPileD.ChargeParam = data;
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x64) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
SysStoreSysParmflag =1;
// SysWriteSysParm();
}
if( addrparam == 0x65) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹģ<D1B9><EFBFBD><E9BFAA>
{
data = Blue_pkg->ucDataSpace[2] ;
if(data==1)
SysParaPileD.HighVoltageModule = data;
else
SysParaPileD.HighVoltageModule =0;
printf("high voltage module %s\n\r",SysParaPileD.HighVoltageModule==1?"Enable":"Disable" );
SysStoreSysParmflag =1;
// SysWriteSysParm();
}
// if( addrparam == 0x66) //
// {
// data = Blue_pkg->ucDataSpace[2] ;
// if(data==1)
// SysParaPileD.HighVoltageOffset = data;
// else
// SysParaPileD.HighVoltageOffset =0;
// printf("\n\r<>źŶ<C5BA>ʧ %s \n\r",SysParaPileD.HighVoltageOffset==1?"ʹ<><CAB9>":"<22><>ֹ" );
//
// SysWriteSysParm();
// }
if( addrparam == 0x6D) // SOC<4F><43><EFBFBD>ʽ
{
data = Blue_pkg->ucDataSpace[2] ;
if(data==1)
{
SysParaPileD.SocSimulaType = 1;
printf("SocSimulaType-1\n\r" );
}
if(data==2)
{
SysParaPileD.SocSimulaType = 2;
printf("SocSimulaType-2\n\r" );
}
if(data==3)
{
SysParaPileD.SocSimulaType = 3;
printf("SocSimulaType-3\n\r" );
}
//SOC<4F><43><EFBFBD>ʽ 1-can<61><6E>ȡ 2-socģ<63><C4A3> 3-SOCУ׼
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x6E) // SOCģ<43><C4A3><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocSimulaMaxVolt = data;
if(data > 200 && data < 760 )
SysParaPileD.BmsMaxVolt = data*10;
printf("\n\r SocSimulaMaxVolt %d V \n\r",SysParaPileD.SocSimulaMaxVolt );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x6F) // SOCģ<43><C4A3><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
if(data > 200 && data < 760 )
SysParaPileD.TotalVoltage = data*10;
SysParaPileD.SocSimulaMinVolt = data;
printf("\n\r SocSimulaMinVolt %d V \n\r",SysParaPileD.SocSimulaMinVolt );
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x70) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[0] = data;
printf("\n\r SocCalibrationVolt %d (0.1)V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x71) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[1] = data;
printf("\n\r SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x72) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[2] = data;
printf("\n\r SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x73) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[3] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x74) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[4] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x75) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[5] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x76) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[6] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x77) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[7] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x78) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[8] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x79) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[9] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x7A) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[10] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x7B) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[11] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x7C) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[12] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x7D) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[13] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x7E) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[14] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x7F) // socУ׼<D0A3><D7BC>ѹ
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationVolt[15] = data;
printf("SocCalibrationVolt %d V \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x80) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[0] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x81) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[1] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x82) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[2] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x83) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[3] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x84) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[4] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x85) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[5] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x86) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[6] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x87) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[7] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x88) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[8] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x89) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[9] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x8A) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[10] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x8B) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[11] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x8C) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[12] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x8D) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[13] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x8E) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[14] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
if( addrparam == 0x8F) // socУ׼
{
data = Blue_pkg->ucDataSpace[3] <<8 | Blue_pkg->ucDataSpace[2] ;
SysParaPileD.SocCalibrationData[15] = data;
printf("SocCalibration %d \n\r",data);
// SysWriteSysParm();
SysStoreSysParmflag =1;
}
}
else if(Blue_pkg->ucDataSpace[0] == 0) //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
{
paramnum =Blue_pkg->ucDataSpace[1];
printf("Read param num %d\n\r",paramnum);
paramnumcount = paramnum;
if( 13 == paramnumcount)
{
paramnumcount = 0;
Blue_Send_Package.len =0;
}
Blue_Send_Package.len =0;
// addrparam = Blue_pkg->ucDataSpace[1];
updata_param();
for(i =0;i<paramnum;i++) //ѭ<><D1AD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EBB3A4>
{
addrparam =Blue_pkg->ucDataSpace[2+i];
for(j =0;j<sizeof(paramTable)/sizeof(paramTable[0]);j++)
{
if(addrparam == paramTable[j].paramaddr)
{
printf("read param addr 0x%x param len %d\n\r",addrparam,paramTable[j].paramlen);
memcpy((uint8_t *)&Blue_Send_Package.ucDataSpace[2+paramnum+Blue_Send_Package.len],(uint8_t *)paramTable[j].paramData,paramTable[j].paramlen);
Blue_Send_Package.len +=paramTable[j].paramlen;
}
}
}
Blue_Send_Package.len +=(2+paramnum);
Blue_Send_Package.cmd = 0x1005;
Blue_Send_Package.ucDataSpace[0]=Blue_pkg->ucDataSpace[0] ;
Blue_Send_Package.ucDataSpace[1]= paramnum;
for(i =0;i<paramnum;i++) //ѭ<><D1AD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EBB3A4>
{
Blue_Send_Package.ucDataSpace[2+i] = Blue_pkg->ucDataSpace[2+i];
}
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
}
break;
case 0x8006: //<2F><><EFBFBD>ð<EFBFBD>
case 0x0680: //<2F><><EFBFBD>ð<EFBFBD>
if(Blue_pkg->ucDataSpace[0] == 1 )
{
SysParaPileD.Recordindex = 0;
memset(SysParaPileD.chargeRecord,0,sizeof(SysParaPileD.chargeRecord));
SysWriteSysParm();
printf("Receive records ack\n\r");
}
break;
case 0x8007: //DCDC״̬<D7B4><CCAC><EFBFBD><EFBFBD>
case 0x0780: //DCDC״̬<D7B4><CCAC><EFBFBD><EFBFBD>
printf("Receive DCDC state ack\n\r");
// printf("\n\r<><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s\n\r",Blue_pkg->ucDataSpace[1] == 1 ? "<22><><EFBFBD><EFBFBD>":"<22><>ֹ");
// if(Blue_pkg->ucDataSpace[1] == 0 )
// {
// ServerStop_ChargeFlag = 1;
// }
break;
case 0x8008: //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case 0x0880: //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("Receive DCDC state ack\n\r");
break;
case 0x8009: //<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case 0x0980:
printf("Receive DCDC state ack\n\r");
break;
case 0x800A: //<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
case 0x800D: //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("Receive DEBUG DCDC ack\n\r");
BluetoothInfo.connetcOvertimeFlag =0;
break;
case 0x0A80:
printf("Receive DCDC state ack\n\r");
break;
case 0x8020: //<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
case 0x2080:
break;
case 0x8021: //<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
case 0x2180:
break;
default:
break;
}
}
void UpdProcess(u8 type,u8 *Pdata, u16 length) // type 0 upd head get,,,, 1 ture upd data get
{
u32 addr,readval;
u32 *Upddata;
u8 *pdata;
u8 i,cnt,err_cnt = 0;
static u16 QQCrc = 0xffff,TCrc = 0xffff;
u16 Hcrc;
static u8 failfg = 0;
IWDG_Feed();
if(type == 0){
UpdHead.FileType = Pdata[4];
UpdHead.FileVer = Pdata[5];
UpdHead.FileTotalByte = Pdata[6] <<24 | Pdata[7] <<16 | Pdata[8] <<8 | Pdata[9];
UpdHead.FileCrc = Pdata[11] <<8 | Pdata[10];
UpdHead.FileTotalPag = Pdata[15] <<24 | Pdata[14] <<16 | Pdata[13] <<8 | Pdata[12];
UpdHead.FilePaglen = Pdata[17] <<8 | Pdata[16];
UpdHead.ReceBakPagNum = 0xffffffff;
UpdHead.CurrByteLen = 0;
UpdHead.CurrBakByteLen = 0;
UpdHead.FlashBakPage = 0xffff;
failfg = 0;
printf("\r\n666Upd--type:%d ,ver:%d,Tbyte:%d, Crc:%d,Pag:%d,Plen:%d\r\n",UpdHead.FileType,UpdHead.FileVer,UpdHead.FileTotalByte,UpdHead.FileCrc,UpdHead.FileTotalPag,UpdHead.FilePaglen);
printf("\r\n777Upd--type:%0x ,ver:%0x,Tbyte:%0x, Crc:%0x,Pag:%0x,Plen:%0x\r\n",UpdHead.FileType,UpdHead.FileVer,UpdHead.FileTotalByte,UpdHead.FileCrc,UpdHead.FileTotalPag,UpdHead.FilePaglen);
BMS_UpdataACKInfo();
}
else if(type == 1){
if(failfg)
return;
UpdHead.RecePagNum = Pdata[3] <<24 | Pdata[2] <<16 | Pdata[1] <<8 | Pdata[0];
BMS_Updata2ACKInfo();
IWDG_Feed();
printf("\n\rCurr Bag:%d, len %d\n\r",UpdHead.RecePagNum,length);
if(UpdHead.ReceBakPagNum != UpdHead.RecePagNum){
UpdHead.ReceBakPagNum = UpdHead.RecePagNum;
UpdHead.CurrByteLen += length - 13;////Blue_pkg->len - 13;
printf("Write-addr: sector %d,,offset %d ,reclen %0d\r\n",UpdHead.CurrByteLen / 2048,UpdHead.CurrByteLen % 2048,UpdHead.CurrByteLen);
FLASH_Unlock();
if(UpdHead.FlashBakPage != (UpdHead.CurrByteLen / 2048)){
UpdHead.FlashBakPage = UpdHead.CurrByteLen / 2048;
addr = (UpdBaseAddr + UpdHead.CurrByteLen) & 0xfffff800;
printf("44Curr Erase--addr: %0x\r\n",addr);
FLASH_ErasePage(addr);
}
Upddata = (u32 *)&Pdata[4];
cnt = (length - 13) / 4;
if((length - 13) % 4){
printf("\n\rlast-----bag!!!!!!!\n\r");
memset((u8 *)&Pdata[length - 9],3,0xff);
cnt ++;
}
addr = (UpdBaseAddr + UpdHead.CurrBakByteLen);
UpdHead.CurrBakByteLen = UpdHead.CurrByteLen;
for(i = 0; i < cnt ; i++){
err_cnt = 0;
while (1)
{
if (FLASH_ProgramWord(addr, Upddata[i]) == 4)break; //// FLASH_COMPLETE 4
else err_cnt++;
if (err_cnt >= 3){
printf("!22!!!!!!!!!Write-Fail-addr: %0x\r\n",addr);
failfg = 1;
return;
}
}
readval = *(__IO uint32_t *)addr;
if((i < 1) || (i >= (cnt - 1))){
printf("addr %0x,,Write %0x,,read %0x\r\n",addr,Upddata[i],readval);
}
if(readval != Upddata[i]){
printf("\n\r readval != Upddata[i])!!!!!\n\r");
printf("addr %0x,,Write %0x,,read %0x\r\n",addr,Upddata[i],readval);
failfg = 1;
return;
}
addr += 4;
if(err_cnt >= 3)
break;
}
#if 1
IWDG_Feed();
TCrc = Blue2CRC16(&Pdata[4],(length - 13),TCrc);
printf("122UpdHead.FileCrc=%0x,TCrc=%0x\r\n",UpdHead.FileCrc,TCrc);
#endif
IWDG_Feed();
if(UpdHead.RecePagNum == UpdHead.FileTotalPag){
if(UpdHead.FileCrc != TCrc){
printf("UpdHead.FileCrc != TCrc !!! return!\r\n");
return;
}
err_cnt = 0;
printf("!!!upd-info!! Write-totpag %d \r\n",UpdHead.FileTotalPag);
FLASH_ErasePage(UpdInfoAddr);
while (1)
{
if (FLASH_ProgramWord(UpdInfoAddr, UpdDataFlag) == 4)break; //// FLASH_COMPLETE 4
else err_cnt++;
if (err_cnt >= 3){
printf("UpdDataFlag! Write-Fail-addr: %0x\r\n",UpdInfoAddr);
break;
}
}
readval = *(__IO uint32_t *)UpdInfoAddr;
printf("addr %0x,,Write %0x,,read %0x\r\n",UpdInfoAddr,UpdDataFlag,readval);
if(UpdDataFlag != readval){
failfg = 1;
return;
}
err_cnt = 0;
while (1)
{
if (FLASH_ProgramWord(UpdInfoAddr + 4, UpdHead.FileTotalByte) == 4)break; //// FLASH_COMPLETE 4
else err_cnt++;
if (err_cnt >= 3){
printf("!!!upd-info!! Write-Fail-addr: %0x\r\n",UpdInfoAddr + 4);
break;
}
}
readval = *(__IO uint32_t *)(UpdInfoAddr + 4);
printf("1addr %0x,,Write %0x,,read %0x\r\n",(UpdInfoAddr + 4),UpdHead.FileTotalByte,readval);
if(UpdHead.FileTotalByte != readval){
failfg = 1;
return;
}
IWDG_Feed();
BMS_Updata2ACKInfo();
printf("22upd-all write OOKK!!restart!!!!!!!!!!!\r\n");
NVIC_SystemReset();
while(1);
}
FLASH_Lock();
}
IWDG_Feed();
}
}
static void Blue_Data_Parser(uint8_t *data, uint16_t length)
{
DP_FrameBluetooth_t *pkg = (DP_FrameBluetooth_t *)data;
// uint8_t i = 0;
// uint8_t ucLen; //<2F>ܳ<EFBFBD><DCB3><EFBFBD>(<28><>ȥͷ<C8A5>ֽ<EFBFBD>)
// uint16_t crc,crc2= 0;
if(pkg->address ==0x5AA5)
{
sHandleParsePkg(pkg);
}
}
#define BLUE_IDLE_ACK "AT+OK\r\n"
#define BLUE_PREPARE_ACK "AT+OK\r\n+256000,3,0,0"
#define BLUE_PREPARE_ACK2 "AT+OK\r\n0303"
#define BLUE_CONFIG_ACK "AT+OK\r\nBlue_303\r\n"
#define BLUE_CONNECT_ACK "AT+OK\r\n01\r\n"
#include <string.h>
void Blue_Receive_Parser(void)
{
if(USART2_RX_FLAG ==1)
{
// printf("%s\n\r",USART2_RX_BUF);
switch(BluetoothInfo.State)
{
case BLUE_IDLE:
if(memcmp(USART2_RX_BUF, BLUE_IDLE_ACK, 7)==0)
{
BluetoothInfo.State =BLUE_PREPARE;
}
break;
case BLUE_PREPARE:
if(memcmp(USART2_RX_BUF, BLUE_PREPARE_ACK2, 10)==0)
{
BluetoothInfo.State =BLUE_CONFIG;
}
break;
case BLUE_CONFIG:
if(strstr((char *)USART2_RX_BUF,(char *)SysParaPileD.bluetooth_name)!=0)
{
BluetoothInfo.State =BLUE_LINK_CONNECTING;
}
break;
case BLUE_LINK_CONNECTING:
if(memcmp(USART2_RX_BUF, BLUE_CONNECT_ACK, 11)==0)
{
BluetoothInfo.State =BLUE_LINK_CONNECTED;
}
break;
case BLUE_LINK_CONNECTED:
BluetoothInfo.recvBuffer = USART2_RX_BUF;
BluetoothInfo.recvLength = USART2_RX_STA;
Blue_Data_Parser(USART2_RX_BUF, USART2_RX_STA);
break;
}
USART2_RX_FLAG = 0;
USART2_RX_STA =0;
memset(USART2_RX_BUF,0,USART_BUFFER_SIZE);
}
}
void Blue_Set_Name(uint8_t *data, uint16_t length)
{
RS232_Blue_Write(data,length);
}
void Blue_AT_Init(void)
{
RS232_Blue_Write("AT",2);
}
void Blue_Query_Version(void)
{
RS232_Blue_Write("AT+VERION=?",strlen("AT+VERION=?"));
}
void Blue_Name_Cfg(uint8_t *data)
{
uint8_t buffer[30]={0};
memset(buffer,0,sizeof(buffer));
sprintf((char *)&buffer[0],"AT+NAME=%s",data);
RS232_Blue_Write(buffer,strlen((char *)buffer));
}
void Blue_Name_Query(void)
{
RS232_Blue_Write("AT+NAME=?",strlen("AT+NAME=?"));
}
void Blue_Connect_State(void)
{
RS232_Blue_Write("AT+STATE=?",strlen("AT+STATE=?"));
}
void Blue_Query_UART_Cfg(void)
{
RS232_Blue_Write("AT+UART_CFG=?",strlen("AT+UART_CFG=?"));
}
/*********************************************************************************
* Description : <EFBFBD><EFBFBD><EFBFBD>еȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ǹ<EFBFBD>š<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǹ<EFBFBD><EFBFBD>
**********************************************************************************/
void Bluetooth_Switch_IDLE(void)
{
Blue_AT_Init();
}
void Bluetooth_Switch_PREPARE(void)
{
static uint8_t step;
static uint32_t timer;
if(TickOut(&timer, 1000)==TRUE)
{
if(step == 0)
{
Blue_Query_Version();
step =1;
}
else if(step == 1)
{
Blue_Query_UART_Cfg();
step =0;
}
TickOut(&timer, 0);
}
}
void Bluetooth_Switch_Config(void)
{
static uint8_t step;
static uint32_t timer;
if(TickOut(&timer, 1000)==TRUE)
{
if(step == 0)
{
step =1;
}
else if(step == 1)
{
// Blue_Name_Cfg("Blue_HaiDun");
Blue_Name_Cfg(SysParaPileD.bluetooth_name);
step =2;
}
else if(step == 2)
{
Blue_Name_Query();
step =0;
}
TickOut(&timer, 0);
}
}
void Bluetooth_Switch_Connecting(void)
{
static uint32_t timer;
if(TickOut(&timer, 3000)==TRUE)
{
Blue_Connect_State();
TickOut(&timer, 0);
}
}
void Bluetooth_Data_Send(uint8_t *data,uint8_t len)
{
RS232_Blue_DataWrite(data,len);
}
uint8_t DP_PackageWriteDataFrame(DP_FrameBluetooth_t *pPara, uint8_t *pBuf, uint16_t *ucDatalen)
{
uint8_t iCount = 0;
uint16_t crc,i = 0;
uint16_t len = 0;
if ((pPara == NULL) || (pBuf == NULL))
return FALSE;
len = pPara->len+25;
/* <20><><EFBFBD><EFBFBD>վ<EFBFBD>Ź<EFBFBD><C5B9><EFBFBD><EFBFBD><EFBFBD> */
pBuf[iCount++] = D_DP_FrameStart1;
pBuf[iCount++] = D_DP_FrameStart2;
pBuf[iCount++] =len &0xff;
pBuf[iCount++] = (len>>8)&0xff;
pBuf[iCount++] = D_DP_Device;
memcpy(pBuf+iCount, SysParaPileD.sn, 16);
iCount = iCount + 16;
pBuf[iCount++] = pPara->cmd &0xff;
pBuf[iCount++] = ( pPara->cmd>>8)&0xff;
if( pPara->len >= 2)
{
memcpy(pBuf + iCount, pPara->ucDataSpace, pPara->len);
iCount = iCount + pPara->len;
}
/*<2A><><EFBFBD><EFBFBD>CRC*/
crc = BlueCRC16(pBuf, iCount);
/*<2A><><EFBFBD><EFBFBD>CRC*/
pBuf[iCount++] = crc & 0xff ;
pBuf[iCount++] = (crc >> 8) & 0xff;
Bluetooth_Data_Send(pBuf, iCount);
return TRUE;
}
void Bluetooth_Registered(void);
void Bluetooth_Login(void);
void Bluetooth_HeartBeat(void);
void BluetoothDataProcess(void);
void Bluetooth_chargeRecord(void);
void BluetoothConnectProcess(void)
{
switch(BluetoothInfo.State)
{
case BLUE_IDLE:
{
Bluetooth_Switch_IDLE();
break;
}
case BLUE_PREPARE:
{
Bluetooth_Switch_PREPARE();
break;
}
case BLUE_CONFIG:
{
Bluetooth_Switch_Config();
break;
}
case BLUE_LINK_CONNECTING:
{
Bluetooth_Switch_Connecting();
if( SysParaPileD.registeredFlag ==0)
BluetoothInfo.ConnectServerState = BLUE_REGISTERED;
else if( SysParaPileD.registeredFlag ==1)
BluetoothInfo.ConnectServerState = BLUE_LOGIN;
break;
}
case BLUE_LINK_CONNECTED:
{
BluetoothDataProcess();
break;
}
case BLUE_END:
{
break;
}
default:
break;
}//end switch
}
bmsblue_datainfo_t bluebms_datainfo;
void BluetoothDataProcess(void)
{
static uint16_t iCount = 0;
static uint32_t timer = 0;
static uint16_t timerout = 1000;
if(SysParaPileD.Debug_Page_function ==1)
{
if(BluetoothInfo.connetcOvertimeFlag >=10)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
{
SysParaPileD.Debug_Page_function = 0;
}
return;
}
else
timerout =1000;
if(BluetoothInfo.connetcOvertimeFlag >20)
{
if( SysParaPileD.registeredFlag ==0)
BluetoothInfo.ConnectServerState = BLUE_REGISTERED;
else if( SysParaPileD.registeredFlag ==1)
BluetoothInfo.ConnectServerState = BLUE_LOGIN;
}
switch(BluetoothInfo.ConnectServerState)
{
case BLUE_REGISTERED:
{
Bluetooth_Registered();
break;
}
case BLUE_LOGIN:
{
Bluetooth_Login();
SysParaPileD.Debug_Page_function =0;
break;
}
case BLUE_WECHATAPPLET_ONLINE:
{
if(TickOut( &timer,timerout)==TRUE)
{
iCount++;
if(iCount >9)iCount=0;
TickOut( &timer,0);
if(iCount == 0)
{
Bluetooth_HeartBeat();
}
else if(iCount == 1)
{
BMS_ChargeInfo();
}
else if(iCount == 2)
{
BMS_StatusMessage();
}
else if(iCount == 3)
{
// BMS_UpdataACKInfo();
}
else if(iCount == 4)
{
Bluetooth_DCDC_Data();
}
else if(iCount == 5)
{
BMS_VersionInfo();
}
else if(iCount == 6)
{
BMS_ChargingDataInfo();
}
else if(iCount == 7)
{
bat_temp_Info();
}
else if(iCount == 8)
{
bat_Cell_Vol_Info();
}
else if(iCount == 9)
{
bat_state_code();
}
}
break;
}
case BLUE_WECHATAPPLET_OFFLINE:
{
break;
}
case BLUE_WECHATAPPLET_UPDATA:
{
if(BluetoothInfo.ReciveDataOvertimeFlag++ >20)
{
BluetoothInfo.State=BLUE_IDLE;
if( SysParaPileD.registeredFlag ==0)
BluetoothInfo.ConnectServerState = BLUE_REGISTERED;
else if( SysParaPileD.registeredFlag ==1)
BluetoothInfo.ConnectServerState = BLUE_LOGIN;
}
break;
}
case BLUE_LINK_CONNECTED:
{
// Bluetooth_Data_Send("87654321", 8);
break;
}
case BLUE_END:
{
break;
}
default:
break;
}//end switch
}
extern uint16_t WuLingBatMaxchargcur;
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> Bluetooth_Registered
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>״ε<EFBFBD>¼<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>ȡ<EFBFBD>Ͱ<EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void Bluetooth_Registered(void)
{
//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
static uint32_t timer;
uint8_t ucComBuf[64];
uint16_t ucLen = 0;
if(TickOut(&timer, 5000)==TRUE)
{
Blue_Send_Package.cmd = 0x1000;
Blue_Send_Package.len = 0;
printf("Send Registered data\n\r");
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
TickOut(&timer, 0);
}
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> Bluetooth_Login
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>¼ʱ<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD>š<EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void Bluetooth_Login(void)
{
//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
static uint32_t timer;
uint8_t ucComBuf[64];
uint16_t ucLen = 0;
if(TickOut(&timer, 3000)==TRUE)
{
Blue_Send_Package.cmd = 0x1001;
//ע<><D7A2><EFBFBD><EFBFBD>
printf("send Login data\r\n");
memcpy(&Blue_Send_Package.ucDataSpace[0], SysParaPileD.registeredCode, 8);
memcpy(&Blue_Send_Package.ucDataSpace[8], ApplicationVersion, 8);
Blue_Send_Package.len =16;
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
TickOut(&timer, 0);
}
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> Bluetooth_HeartBeat
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD>Զ<EFBFBD>Ű<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD>°<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>0x8005<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void Bluetooth_HeartBeat(void)
{
//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
static uint32_t timer;
static uint32_t heartbeat = 0;
uint8_t ucComBuf[128];
uint16_t ucLen = 0;
// if( ServerSet_CmdFlag == 1)
{
// Blue_Send_Package.cmd = 0x1002;
// heartbeat++;
// Blue_Send_Package.ucDataSpace[0]=heartbeat&0xff;
// Blue_Send_Package.ucDataSpace[1]=(heartbeat>>8)&0xff;;
// //memcpy(&Blue_Send_Package.ucDataSpace[1],&SysTime,sizeof(SysTime));
//// Blue_Send_Package.ucDataSpace[2]=bmsProtocalType; // bmsЭ<73><D0AD>
// Blue_Send_Package.ucDataSpace[2]=SysParaPileD.ProtocolType; // bmsЭ<73><D0AD>
// Blue_Send_Package.ucDataSpace[3]=(CDZ_ChargeInfo.ChargeOutMaxVoltage/10)&0xff;
// Blue_Send_Package.ucDataSpace[4]=((CDZ_ChargeInfo.ChargeOutMaxVoltage/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[5]=(CDZ_ChargeInfo.ChargeOutMinVoltage/10)&0xff;
// Blue_Send_Package.ucDataSpace[6]=((CDZ_ChargeInfo.ChargeOutMinVoltage/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[7]=(CDZ_ChargeInfo.ChargeOutMaxCurrent/10)&0xff;
// Blue_Send_Package.ucDataSpace[8]=((CDZ_ChargeInfo.ChargeOutMaxCurrent/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[9]=(CDZ_ChargeInfo.ChargeOutMinCurrent/10)&0xff;
// Blue_Send_Package.ucDataSpace[10]=((CDZ_ChargeInfo.ChargeOutMinCurrent/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[11]=SysParaPileD.ChargingMode; // 1--<2D><EFBFBD><E3B9A6> 2-<2D><><EFBFBD><EFBFBD>
// Blue_Send_Package.ucDataSpace[12]=(SysParaPileD.OverPower/10 ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// Blue_Send_Package.ucDataSpace[13]=(SysParaPileD.uBatMaxEnergy)&0xff;
// Blue_Send_Package.ucDataSpace[14]=(SysParaPileD.uBatMaxEnergy>>8)&0xff;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// Blue_Send_Package.ucDataSpace[15]=(SysParaPileD.StopVoltage/10)&0xff;
// Blue_Send_Package.ucDataSpace[16]=((SysParaPileD.StopVoltage/10)>>8)&0xff;//ͣ<><CDA3><EFBFBD><EFBFBD>ѹ
//
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ(0.00~24.00V) 0.01V
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<D8B6><EEB6A8>ѹ 0.1V
// Blue_Send_Package.ucDataSpace[17]=((SysParaPileD.BatRatedVoltage/10))&0xff;
// //Blue_Send_Package.ucDataSpace[18]=((SysParaPileD.BatRatedVoltage/10)>>8)&0xff;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// Blue_Send_Package.ucDataSpace[18]=(SysParaPileD.BatMaxChargeVol/10)&0xff;
// //Blue_Send_Package.ucDataSpace[20]=((SysParaPileD.BatMaxChargeVol/10)>>8)&0xff;//ͣ<><CDA3><EFBFBD><EFBFBD>ѹ
// // <20><EFBFBD><EEB6A8><EFBFBD><EFBFBD>ѹ
// // <20><EFBFBD><EEB6A8><EFBFBD><EFBFBD>
// Blue_Send_Package.ucDataSpace[19]=(SysParaPileD.TotalVoltage)&0xff;
// Blue_Send_Package.ucDataSpace[20]=((SysParaPileD.TotalVoltage)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[21]=(SysParaPileD.TotalCapacity)&0xff;
// Blue_Send_Package.ucDataSpace[22]=((SysParaPileD.TotalCapacity)>>8)&0xff;
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// Blue_Send_Package.ucDataSpace[23]=(SysParaPileD.BmsMaxVolt)&0xff;
// Blue_Send_Package.ucDataSpace[24]=((SysParaPileD.BmsMaxVolt)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[25]=SysParaPileD.ucBatType;
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// //soc<6F><63><EFBFBD><EFBFBD> ʹ<><CAB9>
// //<2F><><EFBFBD><EFBFBD>soc<6F><63><EFBFBD><EFBFBD>ֵ
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// Blue_Send_Package.ucDataSpace[26]=(SysParaPileD.trickleChargingSocEnable)&0xff;
// Blue_Send_Package.ucDataSpace[27]=(SysParaPileD.trickleChargingSoc)&0xff;
// Blue_Send_Package.ucDataSpace[28]=(SysParaPileD.tricklepower/10)&0xff;
// Blue_Send_Package.ucDataSpace[29]=(SysParaPileD.tricklecurrent/10)&0xff;
// Blue_Send_Package.ucDataSpace[30]=(SysParaPileD.uBatMaxTempPlus50-50)&0xff;
// Blue_Send_Package.ucDataSpace[31]=(SysParaPileD.uBatMinTempPlus50-50)&0xff;
// Blue_Send_Package.ucDataSpace[32]=(SysParaPileD.BatCount)&0xff;
// Blue_Send_Package.ucDataSpace[33]=(SysParaPileD.OverTempValue[0])&0xff;
// Blue_Send_Package.ucDataSpace[34]=(SysParaPileD.OverTempValue[1])&0xff;
// Blue_Send_Package.ucDataSpace[35]=(SysParaPileD.OverTempValue[2])&0xff;
// Blue_Send_Package.ucDataSpace[36]=(SysParaPileD.QuickChargeEnable)&0xff;
// Blue_Send_Package.ucDataSpace[37]=bmsProtocalType; // bmsЭ<73><D0AD>
// Blue_Send_Package.ucDataSpace[38]=(SysParaPileD.RequirePower/10 ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// Blue_Send_Package.ucDataSpace[39]=(SysParaPileD.SignalLossFlag ); // <20>źŶ<C5BA>ʧ
// Blue_Send_Package.ucDataSpace[40]=(SysParaPileD.RequireVoltageDifference); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9>ʵ<EFBFBD>ʲ<EFBFBD><CAB2><EFBFBD>
// //<2F><>ѹ<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
// memcpy(&Blue_Send_Package.ucDataSpace[41],SysParaPileD.VehichleInfo,17);
//<2F><><EFBFBD><EFBFBD>VIN<49>ϴ<EFBFBD>
//Blue_Send_Package.ucDataSpace[34]=((SysParaPileD.tricklepower/10)>>8)&0xff;
//Blue_Send_Package.ucDataSpace[35]=((SysParaPileD.tricklecurrent/10)>>8)&0xff;
printf("send heartbeat data \n\r");
Blue_Send_Package.len = 58;//41+17;
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
BluetoothInfo.connetcOvertimeFlag++;
TickOut(&timer, 0);
}
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> BMS_StatusMessage
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD>״̬
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void BMS_StatusMessage(void)
{
//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
static uint32_t timer;
static uint32_t heartbeat = 0;
uint8_t ucComBuf[128];
uint16_t ucLen = 0;
// if(TickOut(&timer, 1000)==TRUE)
{
Blue_Send_Package.cmd = 0x1003;
// Blue_Send_Package.ucDataSpace[0]= 0;
// if(g_ChargeStep == CC_CHARGE_IDLE)
// Blue_Send_Package.ucDataSpace[1]=2;
// else if(g_ChargeStep == CC_CHARGE_READY)
// Blue_Send_Package.ucDataSpace[1]=2;
// else if(g_ChargeStep == CC_CHARGE_START)
// Blue_Send_Package.ucDataSpace[1]=2;
// else if(g_ChargeStep == CC_CHARGE_ING)
// Blue_Send_Package.ucDataSpace[1]=3;
// else if(g_ChargeStep == CC_CHARGE_END)
// Blue_Send_Package.ucDataSpace[1]=4;
//
//
// if(g_ChargeStep == CC_CHARGE_IDLE)
// Blue_Send_Package.ucDataSpace[2]=1;
// else if(g_ChargeStep == CC_CHARGE_READY)
// Blue_Send_Package.ucDataSpace[2]=1;
// else if(g_ChargeStep == CC_CHARGE_START)
// Blue_Send_Package.ucDataSpace[2]=3;
// else if(g_ChargeStep == CC_CHARGE_ING)
// Blue_Send_Package.ucDataSpace[2]=4;
// else if(g_ChargeStep == CC_CHARGE_END)
// Blue_Send_Package.ucDataSpace[2]=5;
//
Blue_Send_Package.ucDataSpace[3]=stopChargeReason;
Blue_Send_Package.len =4;
BluetoothInfo.connetcOvertimeFlag++;
printf("send state data \n\r");
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
TickOut(&timer, 0);
}
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> BMS_StatusMessage
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׮<EFBFBD>ĵ<EFBFBD>ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void BMS_ChargeInfo(void)//<2F><><EFBFBD><EFBFBD>׮״̬<D7B4><CCAC><EFBFBD><EFBFBD>
{
//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
static uint32_t timer;
static uint32_t flag = 0;
static uint8_t start_soc = 0;
uint8_t ucComBuf[128];
uint16_t ucLen,data = 0;
// if(ServerSet_CmdFlag == 1)
{
Blue_Send_Package.cmd = 0x1004;
// if(ServerSet_CmdFlag == 1)ServerSet_CmdFlag =0;
// if(flag == 0)
// {
// start_soc = Bms_BatChargeRealInfo.uBatCurSOC;
// flag =1;
// }
// Blue_Send_Package.ucDataSpace[0]=(CDZ_ChargeInfo.ChargeOutMaxVoltage/10)&0xff;
// Blue_Send_Package.ucDataSpace[1]=((CDZ_ChargeInfo.ChargeOutMaxVoltage/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[2]=(CDZ_ChargeInfo.ChargeOutMinVoltage/10)&0xff;
// Blue_Send_Package.ucDataSpace[3]=((CDZ_ChargeInfo.ChargeOutMinVoltage/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[4]=(CDZ_ChargeInfo.ChargeOutMaxCurrent/10)&0xff;
// Blue_Send_Package.ucDataSpace[5]=((CDZ_ChargeInfo.ChargeOutMaxCurrent/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[6]=(CDZ_ChargeInfo.ChargeOutMinCurrent/10)&0xff;
// Blue_Send_Package.ucDataSpace[7]=((CDZ_ChargeInfo.ChargeOutMinCurrent/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[8]=( CDZ_ChargeInfo.ChargeOutVoltage/10)&0xff;
// Blue_Send_Package.ucDataSpace[9]=(( CDZ_ChargeInfo.ChargeOutVoltage/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[10]=(Bms_BatChargeRealInfo.BatRealCur/10)&0xff;
// Blue_Send_Package.ucDataSpace[11]=((Bms_BatChargeRealInfo.BatRealCur/10)>>8)&0xff;
// //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//
// Blue_Send_Package.ucDataSpace[12]=((uint16_t)(CDZ_ChargeInfo.ChargeEnergyTotal))&0xff;
// Blue_Send_Package.ucDataSpace[13]=(((uint16_t)(CDZ_ChargeInfo.ChargeEnergyTotal))>>8)&0xff;
// //<2F><><EFBFBD><EFBFBD>ʱsoc , <20><>ǰsoc
// if(Bms_BatChargeRealObdBatCurSOC <= 100 && Bms_BatChargeRealObdBatCurSOC >0)
// Blue_Send_Package.ucDataSpace[14]=Bms_BatChargeRealObdBatCurSOC;
// else
// Blue_Send_Package.ucDataSpace[14]=Bms_BatChargeRealInfo.uBatCurSOC;
// Blue_Send_Package.ucDataSpace[15]=start_soc;
// if((Sample_DataS.Tempreture[0]> 1)&&(Sample_DataS.Tempreture[0]<100))
// Blue_Send_Package.ucDataSpace[16]= Sample_DataS.Tempreture[0];
// else
// Blue_Send_Package.ucDataSpace[16]= 0;
// if((Sample_DataS.Tempreture[1] > 1)&&(Sample_DataS.Tempreture[1]<100))
// Blue_Send_Package.ucDataSpace[17]= Sample_DataS.Tempreture[1];
// else
// Blue_Send_Package.ucDataSpace[17]= 0;
// if((Sample_DataS.Tempreture[2] > 1)&&(Sample_DataS.Tempreture[2]<100))
// Blue_Send_Package.ucDataSpace[18]= Sample_DataS.Tempreture[2];
// else
// Blue_Send_Package.ucDataSpace[18]= 0;
// //Blue_Send_Package.ucDataSpace[16]=Sample_DataS.Tempreture[0];
// //Blue_Send_Package.ucDataSpace[17]=Sample_DataS.Tempreture[1];
// //Blue_Send_Package.ucDataSpace[18]=Sample_DataS.Tempreture[2];
// Blue_Send_Package.ucDataSpace[19]= (SysParaPileD.BmsMaxVolt/10)&0xff;
// Blue_Send_Package.ucDataSpace[20]= ((SysParaPileD.BmsMaxVolt/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[21]=(SysParaPileD.BmsMaxCurrent/10)&0xff;
// Blue_Send_Package.ucDataSpace[22]= ((SysParaPileD.BmsMaxCurrent/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[23]=(SysParaPileD.BmRequireVolt/10) &0xff;
// Blue_Send_Package.ucDataSpace[24]= ((SysParaPileD.BmRequireVolt/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[25]=(SysParaPileD.BmsRequireCurrent/10) &0xff;
// Blue_Send_Package.ucDataSpace[26]= ((SysParaPileD.BmsRequireCurrent/10)>>8)&0xff;
// Blue_Send_Package.ucDataSpace[27]= Bms_BatChargeRealInfo.contactorState;
//
// Blue_Send_Package.ucDataSpace[28]= CDZ_ChargeInfo.ChargeTimeTotal &0xff; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
// Blue_Send_Package.ucDataSpace[29]= ((CDZ_ChargeInfo.ChargeTimeTotal)>>8)&0xff; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
//
//// if( CDZ_ChargeInfo.ChargeTime >60)
//// {
//// Blue_Send_Package.ucDataSpace[28]= CDZ_ChargeInfo.ChargeTime &0xff; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
//// Blue_Send_Package.ucDataSpace[29]= ((CDZ_ChargeInfo.ChargeTime)>>8)&0xff; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
//// }
//// else
//// {
//// Blue_Send_Package.ucDataSpace[28]= ChargeRecordInfo.chargingtime &0xff; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
//// Blue_Send_Package.ucDataSpace[29]= ((ChargeRecordInfo.chargingtime)>>8)&0xff; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
//// }
// if(WuLingBatteryInfo.bms29A.bits.BatTalVolSm > 400)
// data = WuLingBatteryInfo.bms29A.bits.BatTalVolSm; // ͨ<>ŵĵ<C5B5>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>DCDC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
// else
// {
//
// if(ModuleInfo.state == POWER_ON)
// {
// data = ModuleInfo.current_volt; // ͨ<>ŵĵ<C5B5>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>DCDC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
// }
// else
// data = ModuleInfo.sample_bat_volt;
// }
// Blue_Send_Package.ucDataSpace[30]=(data/10)&0xff;
// Blue_Send_Package.ucDataSpace[31]=((data/10)>>8)&0xff;
Blue_Send_Package.len =32;
BluetoothInfo.connetcOvertimeFlag++;
printf("send Charge data\n\r");
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
TickOut(&timer, 0);
}
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> BMS_SetDataAck
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void BMS_SetDataAck(void)
{
//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
static uint32_t timer;
static uint32_t flag = 0;
static uint8_t start_soc = 0;
uint8_t ucComBuf[64];
uint16_t ucLen = 0;
Blue_Send_Package.cmd = 0x1005;
// Blue_Send_Package.ucDataSpace[17]=Sample_DataS.Tempreture[1];
// Blue_Send_Package.ucDataSpace[18]=Sample_DataS.Tempreture[2];
Blue_Send_Package.len =19;
BluetoothInfo.connetcOvertimeFlag++;
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> Bluetooth_chargeRecord
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>¼ʱ<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD>š<EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void Bluetooth_chargeRecord(void)
{
uint8_t i = 0;
uint8_t ucComBuf[128];
uint16_t ucLen = 0;
if(SysParaPileD.Recordindex < RECORD_NUM)
{
Blue_Send_Package.cmd = 0x1006;
Blue_Send_Package.ucDataSpace[0]=SysParaPileD.Recordindex;
for(i=0;i<SysParaPileD.Recordindex;i++)
{
// Blue_Send_Package.ucDataSpace[1+i*10] = i;
memcpy((uint8_t *)&Blue_Send_Package.ucDataSpace[1+i*11],(uint8_t *)&SysParaPileD.chargeRecord[i].date[0],11);
}
printf("send chargeRecord data\n\r");
Blue_Send_Package.len = SysParaPileD.Recordindex*11+1;//41+17;
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
BluetoothInfo.connetcOvertimeFlag++;
}
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> Bluetooth_DCDC_Data
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void Bluetooth_DCDC_Data(void)//ģ<><C4A3>״̬<D7B4><CCAC>Ϣ
{
//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
static uint32_t timer;
static uint32_t heartbeat = 0;
uint8_t ucComBuf[128];
uint16_t ucLen = 0;
uint16_t power = 0;
// if(SysParaPileD.WorkModel == 0)return;
// if(TickOut(&timer, 1000*3 )==TRUE)
{
Blue_Send_Package.cmd = 0x1007;
power = ModuleInfo.current_volt * ModuleInfo.current_curr/10000;
Blue_Send_Package.ucDataSpace[0]=(u8)(ModuleInfo.current_volt);
Blue_Send_Package.ucDataSpace[1]=(u8)((ModuleInfo.current_volt)>>8);
Blue_Send_Package.ucDataSpace[2]=ModuleInfo.current_curr;
Blue_Send_Package.ucDataSpace[3]=(ModuleInfo.current_curr)>>8;
Blue_Send_Package.ucDataSpace[4]=power&0xff;
Blue_Send_Package.ucDataSpace[5]=(ModuleInfo.Inductance_Temp) ;
Blue_Send_Package.ucDataSpace[6]=(ModuleInfo.Modul_Temp);
Blue_Send_Package.ucDataSpace[7]=32;
Blue_Send_Package.ucDataSpace[8]=95;
Blue_Send_Package.ucDataSpace[9]=ModuleInfo.state;
Blue_Send_Package.ucDataSpace[10]=ModuleInfo.faultcode&0xff;
Blue_Send_Package.ucDataSpace[11]=(ModuleInfo.faultcode)>>8;
Blue_Send_Package.ucDataSpace[12]=ModuleInfo.state;
Blue_Send_Package.ucDataSpace[13]=(u8)(ModuleInfo.target_volt);
Blue_Send_Package.ucDataSpace[14]=(u8)((ModuleInfo.target_volt)>>8);
Blue_Send_Package.ucDataSpace[15]=ModuleInfo.target_curr;
Blue_Send_Package.ucDataSpace[16]=(ModuleInfo.target_curr)>>8;
Blue_Send_Package.ucDataSpace[17]=(u8)(ModuleInfo.over_volt);
Blue_Send_Package.ucDataSpace[18]=(u8)((ModuleInfo.over_volt)>>8);
Blue_Send_Package.ucDataSpace[19]=ModuleInfo.over_curr;
Blue_Send_Package.ucDataSpace[20]=(ModuleInfo.over_curr)>>8;
Blue_Send_Package.ucDataSpace[21]=(ModuleInfo.max_power);
Blue_Send_Package.ucDataSpace[22]=(ModuleInfo.currentadjust);
Blue_Send_Package.ucDataSpace[23]=(ModuleInfo.currentadjust>>8)&0xff;
Blue_Send_Package.ucDataSpace[24]=(ModuleInfo.temp3);
Blue_Send_Package.ucDataSpace[25]=(ModuleInfo.temp4);
printf("send DCDC data\n\r");
Blue_Send_Package.len = 26;//41+17;
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
BluetoothInfo.connetcOvertimeFlag++;
TickOut(&timer, 0);
}
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> BMS_VersionInfo
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ذ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void BMS_VersionInfo(void)//<2F><><EFBFBD>ذ汾<D8B0><E6B1BE>Ϣ
{
static uint32_t flag = 0;
static uint8_t start_soc = 0;
uint8_t ucComBuf[128];
uint16_t ucLen,data = 0;
Blue_Send_Package.cmd = 0x1008;
memcpy(bluebms_datainfo.BatManuSpecCode,"S201",sizeof(bluebms_datainfo.BatManuSpecCode));
memcpy(bluebms_datainfo.BatManuversionNo,"WLING",sizeof(bluebms_datainfo.BatManuversionNo));
memcpy(&Blue_Send_Package.ucDataSpace[0],bluebms_datainfo.BatManuSpecCode,sizeof(bluebms_datainfo.BatManuSpecCode));
memcpy(&Blue_Send_Package.ucDataSpace[4],bluebms_datainfo.BatManuversionNo,sizeof(bluebms_datainfo.BatManuversionNo));
//0x0: 2kwOBC 0x1:3.3kwOBC 0x2:6.6kwOBC 0x3:2kwOBC+1.5kwDC/DC
//0x4: 6.6kwOBC+1.5kwDC/DC 0x5: 6.6kwOBC+1.5kwDC/DC+2kwDC/AC 0x6: 6.6kwOBC+1.5kwDC/DC+PDU
//0x7: 6.6kwOBC+2kwDC/DC+PDU 0x8: 6.6kwOBC+1.5kwDC/DC+2kwDC/AC+PDU
//0x9: 1.5kwOBC+0.8kwDC/DC++PDU 0xA: 2kwOBC+1kwDC/DC++PDU"
// bluebms_datainfo.CDUType = WuLingBatteryInfo.bms5C1.bits.CDUType;
//
// bluebms_datainfo.VehOdo = WuLingBatteryInfo.bms120.bits.VehOdo;
Blue_Send_Package.ucDataSpace[8]=(bluebms_datainfo.VehOdo)&0xff;
Blue_Send_Package.ucDataSpace[9]=(bluebms_datainfo.VehOdo>>8)&0xff;
Blue_Send_Package.ucDataSpace[10]=(bluebms_datainfo.VehOdo>>16)&0xff;
Blue_Send_Package.ucDataSpace[11]=(bluebms_datainfo.VehOdo>>24)&0xff;
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Blue_Send_Package.ucDataSpace[12]= bluebms_datainfo.CDUType;
Blue_Send_Package.len =13;
BluetoothInfo.connetcOvertimeFlag++;
printf("send bms version\n\r");
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> BMS_VersionInfo
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void BMS_ChargingDataInfo(void)//<2F><><EFBFBD>س<EFBFBD><D8B3><EFBFBD>״̬<D7B4><CCAC>Ϣ
{
static uint32_t flag = 0;
static uint8_t start_soc = 0;
uint8_t ucComBuf[128];
uint16_t ucLen,data = 0;
Blue_Send_Package.cmd = 0x1009;
// bluebms_datainfo.BatEnrgRated = WuLingBatteryInfo.bms5D6.bits.RatedEgy/10;
// bluebms_datainfo.BatVolRated = WuLingBatteryInfo.bms5D6.bits.RatedVol;
// bluebms_datainfo.ChrgVolRqst = WuLingBatteryInfo.bms284.bits.bmsChrgVolRqst;
// bluebms_datainfo.ChrgCurRqst = WuLingBatteryInfo.maxchargcur;
// bluebms_datainfo.BatIslatRes = WuLingBatteryInfo.bms287.bits.BatIslatRes;
// bluebms_datainfo.BatSOC = WuLingBatteryInfo.bms297.bits.BatSOC;
// bluebms_datainfo.BatSOH = WuLingBatteryInfo.bms297.bits.BatSOH;
// bluebms_datainfo.BatEnrgAvail = WuLingBatteryInfo.bms297.bits.BatEnrgAvail;;
// bluebms_datainfo.BatChrgTims= WuLingBatteryInfo.bms297.bits.BatChrgTims;;
// bluebms_datainfo.BatPlsChrgPowAvail = WuLingBatteryInfo.bms28B.bits.Bat10sPlsChrgPowAvail/10;
// bluebms_datainfo.BatPlsDischrgPowAvail = WuLingBatteryInfo.bms28B.bits.Bat10sPlsDischrgPowAvail/10;
// Blue_Send_Package.ucDataSpace[0]= (bluebms_datainfo.ChrgVolRqst);
// Blue_Send_Package.ucDataSpace[1]= ((bluebms_datainfo.ChrgVolRqst)>>8);
// Blue_Send_Package.ucDataSpace[2]= bluebms_datainfo.ChrgCurRqst;
// Blue_Send_Package.ucDataSpace[3]= (bluebms_datainfo.ChrgCurRqst)>>8;
// Blue_Send_Package.ucDataSpace[4]= bluebms_datainfo.BatIslatRes;
// Blue_Send_Package.ucDataSpace[5]= bluebms_datainfo.BatIslatRes>>8;
// Blue_Send_Package.ucDataSpace[6]= (bluebms_datainfo.BatSOC);
// Blue_Send_Package.ucDataSpace[7]= bluebms_datainfo.BatSOH;
// Blue_Send_Package.ucDataSpace[8]= bluebms_datainfo.BatEnrgAvail&0xff;
// Blue_Send_Package.ucDataSpace[9]= (bluebms_datainfo.BatEnrgAvail>>8)&0xff;
// Blue_Send_Package.ucDataSpace[10]= bluebms_datainfo.BatEnrgRated&0xff;
// Blue_Send_Package.ucDataSpace[11]= (bluebms_datainfo.BatEnrgRated>>8)&0xff;
// Blue_Send_Package.ucDataSpace[12]= bluebms_datainfo.BatChrgTims&0xff;
// Blue_Send_Package.ucDataSpace[13]= (bluebms_datainfo.BatChrgTims>>8)&0xff;
// Blue_Send_Package.ucDataSpace[14]= bluebms_datainfo.BatPlsChrgPowAvail&0xff;
// Blue_Send_Package.ucDataSpace[15]= (bluebms_datainfo.BatPlsDischrgPowAvail)&0xff;
// Blue_Send_Package.ucDataSpace[16]= bluebms_datainfo.BatVolRated&0xff;
// Blue_Send_Package.ucDataSpace[17]= (bluebms_datainfo.BatVolRated>>8)&0xff;
Blue_Send_Package.len =18;
BluetoothInfo.connetcOvertimeFlag++;
printf("Send ChargingData \n\r");
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> BMS_VersionInfo
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void bat_temp_Info(void)//<2F><><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><C2B6><EFBFBD>Ϣ
{
static uint32_t flag = 0;
static uint8_t start_soc = 0;
uint8_t ucComBuf[128];
uint16_t ucLen,data,i = 0;
Blue_Send_Package.cmd = 0x100A;
// for(i=0;i<40;i++)
// {
// bluebms_datainfo.cellbat_data[i].Celltemp = 0xff;
// }
// for(i=0;i<8;i++)
// {
// bluebms_datainfo.cellbat_data[i].Celltemp = WuLingBatteryInfo.bms5C6.BatCelTemp1[i]+40;
// }
// for(i=0;i<8;i++)
// {
// bluebms_datainfo.cellbat_data[i+8].Celltemp = WuLingBatteryInfo.bms5C7.BatCelTemp9[i]+40;
// }
// for(i=0;i<8;i++)
// {
// bluebms_datainfo.cellbat_data[i+16].Celltemp = WuLingBatteryInfo.bms5C8.BatCelTemp17[i]+40;
// }
for(i=0;i<40;i++)
{
// bluebms_datainfo.cellbat_data[i].Celltemp = 65;
Blue_Send_Package.ucDataSpace[i]= (bluebms_datainfo.cellbat_data[i].Celltemp);
}
Blue_Send_Package.len =40;
BluetoothInfo.connetcOvertimeFlag++;
printf("Send cell temp \n\r");
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> BMS_VersionInfo
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD>ص<EFBFBD>ѹ<EFBFBD><EFBFBD>Ϣ
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void bat_Cell_Vol_Info(void)//
{
static uint32_t flag = 0;
static uint8_t start_soc = 0;
uint8_t ucComBuf[128];
uint16_t ucLen,data,i = 0;
Blue_Send_Package.cmd = 0x100B;
for(i=0;i<40;i++)
{
// bluebms_datainfo.cellbat_data[i].BattCellVoltage = 3329;
// bluebms_datainfo.cellbat_data[i].BattCellVoltage = WuLingBatteryInfo.cell_batt_info[i].bits.BattCellVoltage;
// Blue_Send_Package.ucDataSpace[i*2]= (bluebms_datainfo.cellbat_data[i].BattCellVoltage&0xff);
// Blue_Send_Package.ucDataSpace[i*2+1]= (bluebms_datainfo.cellbat_data[i].BattCellVoltage>>8)&0xff;
}
Blue_Send_Package.len =80;
BluetoothInfo.connetcOvertimeFlag++;
printf("Send cell temp \n\r");
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> BMS_VersionInfo
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD><EFBFBD><EFBFBD>״̬
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void bat_state_code(void)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
{
static uint32_t flag = 0;
static uint8_t start_soc = 0;
uint8_t ucComBuf[128];
uint16_t ucLen,data,i = 0;
Blue_Send_Package.cmd = 0x100C;
// bluebms_datainfo.bms_state_info.bits.BatMaNegRlySts = WuLingBatteryInfo.bms295.bits.BatMaNegRlySts;
// bluebms_datainfo.bms_state_info.bits.BatMaPosRlySts = WuLingBatteryInfo.bms295.bits.BatMaPosRlySts;
// bluebms_datainfo.bms_state_info.bits.BatPrechrgRlySts = WuLingBatteryInfo.bms295.bits.BatPrechrgRlySts;
// bluebms_datainfo.bms_state_info.bits.BatHvIntlkSts = WuLingBatteryInfo.bms295.bits.BatHvIntlkSts;
// bluebms_datainfo.bms_state_info.bits.BatFuSts = WuLingBatteryInfo.bms295.bits.BatFuSts;
// bluebms_datainfo.bms_state_info.bits.BatHeRlySts = WuLingBatteryInfo.bms295.bits.BatHeRlySts;
// bluebms_datainfo.bms_state_info.bits.BatHeSts = WuLingBatteryInfo.bms295.bits.BatHeSts;
// bluebms_datainfo.bms_state_info.bits.Prechrgsts = WuLingBatteryInfo.bms295.bits.Prechrgsts;
// bluebms_datainfo.bms_state_info.bits.Batfaultnum = WuLingBatteryInfo.bms289.BatOthFltNum;
// bluebms_datainfo.bms_state_info.bits.BatTalVolSts = WuLingBatteryInfo.bms289.BatOthFltList;
// bluebms_datainfo.bms_state_info.bits.BatAvgCelVolSts = WuLingBatteryInfo.bms29E.bits.BatAvgCelVolSts;
// bluebms_datainfo.bms_state_info.bits.BatAvgTolVolSts = WuLingBatteryInfo.bms29E.bits.BatTalVolSts;
// bluebms_datainfo.bms_state_info.bits.BatChrgCurSts = WuLingBatteryInfo.bms29E.bits.BatChrgCurSts;
//// bluebms_datainfo.bms_state_info.bits.BatDischrgCurSts = WuLingBatteryInfo.bms29E.bits.BatDischrgCurSts;
// bluebms_datainfo.bms_state_info.bits.BatIslateSts = WuLingBatteryInfo.bms29E.bits.BatIslateSts;
// bluebms_datainfo.bms_state_info.bits.BatInCANBsErrFlt = WuLingBatteryInfo.bms29E.bits.BatInCANBsErrFlt;
// bluebms_datainfo.bms_state_info.bits.BatTempSensFlt = WuLingBatteryInfo.bms29E.bits.BatTempSensFlt;
// bluebms_datainfo.bms_state_info.bits.BatCurSensFlt = WuLingBatteryInfo.bms29E.bits.BatCurSensFlt;
// bluebms_datainfo.bms_state_info.bits.BatCelVolSensFlt = WuLingBatteryInfo.bms29E.bits.BatCelVolSensFlt;
// bluebms_datainfo.bms_state_info.bits.BalanceSts = WuLingBatteryInfo.bms29E.bits.BalanceSts;
for(i=0;i<8;i++)
{
Blue_Send_Package.ucDataSpace[i]= bluebms_datainfo.bms_state_info.stats[i];
}
Blue_Send_Package.len =8;
BluetoothInfo.connetcOvertimeFlag++;
printf("send bms_state_info\n\r");
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
}
void BMS_UpdataACKInfo(void)
{
//<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
static uint32_t timer;
static uint32_t flag = 0;
static uint8_t start_soc = 0;
uint8_t ucComBuf[128];
uint16_t ucLen,data = 0;
Blue_Send_Package.cmd = 0x1020;
Blue_Send_Package.ucDataSpace[0]=0x55;
Blue_Send_Package.ucDataSpace[1]=0xaa;
Blue_Send_Package.len =2;
BluetoothInfo.connetcOvertimeFlag++;
printf("OTA ACK \n\r");
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
debugdataprocess(&Blue_Send_Package.ucDataSpace[0],2);
}
/**********************************************************************
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> UpdataDebugInfoToServer
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> data<EFBFBD><EFBFBD><EFBFBD><EFBFBD> len<EFBFBD>ֽ<EFBFBD>
* @ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
********************************************************************/
void UpdataDebugInfoToServer(uint8_t *data,uint8_t len)
{
uint8_t ucComBuf[255];
uint16_t ucLen,i = 0;
Blue_Send_Package.cmd = 0x100D;
memcpy(Blue_Send_Package.ucDataSpace,data,len);
Blue_Send_Package.len = len;
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
}
#endif