4304 lines
125 KiB
C
4304 lines
125 KiB
C
#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"
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//如果使用ucos,则包括下面的头文件即可.
|
||
#if SYSTEM_SUPPORT_UCOS
|
||
#include "includes.h" //ucos 使用
|
||
#endif
|
||
|
||
//////////////////////////////////////////////////////////////////
|
||
//加入以下代码,支持printf函数,而不需要选择use MicroLIB
|
||
#if 1
|
||
#pragma import(__use_no_semihosting)
|
||
//标准库需要的支持函数
|
||
struct __FILE
|
||
{
|
||
int handle;
|
||
|
||
};
|
||
|
||
FILE __stdout;
|
||
//定义_sys_exit()以避免使用半主机模式
|
||
_sys_exit(int x)
|
||
{
|
||
x = x;
|
||
}
|
||
#include "sd.h"
|
||
|
||
//重定义fputc函数
|
||
int fputc(int ch, FILE *f)
|
||
{
|
||
static u8 debug_info[250]={0};
|
||
static u8 debug_count ;
|
||
static uint32_t timer = 0;
|
||
/* 将Printf内容发往串口 */
|
||
USART_SendData(UART4, (unsigned char) ch);
|
||
while (!(UART4->SR & USART_FLAG_TXE));
|
||
|
||
if(SysParaPileD.Debug_Page_function ==1)//调试界面
|
||
{
|
||
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;
|
||
/*使用microLib的方法*/
|
||
/*
|
||
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 //如果使能了接收
|
||
//串口1中断服务程序
|
||
//注意,读取USARTx->SR能避免莫名其妙的错误
|
||
u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.
|
||
//接收状态
|
||
//bit15, 接收完成标志
|
||
//bit14, 接收到0x0d
|
||
//bit13~0, 接收到的有效字节数目
|
||
u16 USART_RX_STA=0; //接收状态标记
|
||
|
||
void uart_init(u32 bound){
|
||
//GPIO端口设置
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
USART_InitTypeDef USART_InitStructure;
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE); //使能USART1,GPIOA时钟
|
||
//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; //复用推挽输出
|
||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||
|
||
//USART1_RX PA.10
|
||
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
|
||
// GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||
|
||
//Usart1 NVIC 配置
|
||
|
||
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//抢占优先级3
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
|
||
|
||
//USART 初始化设置
|
||
|
||
USART_InitStructure.USART_BaudRate = bound;//一般设置为9600;
|
||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
|
||
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
|
||
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
|
||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
|
||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
|
||
|
||
USART_Init(USART1, &USART_InitStructure); //初始化串口
|
||
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启中断
|
||
USART_Cmd(USART1, ENABLE); //使能串口
|
||
|
||
}
|
||
|
||
void USART1_IRQHandler(void) //串口1中断服务程序
|
||
{
|
||
u8 Res;
|
||
#ifdef OS_TICKS_PER_SEC //如果时钟节拍数定义了,说明要使用ucosII了.
|
||
OSIntEnter();
|
||
#endif
|
||
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾)
|
||
{
|
||
Res =USART_ReceiveData(USART1);//(USART1->DR); //读取接收到的数据
|
||
|
||
if((USART_RX_STA&0x8000)==0)//接收未完成
|
||
{
|
||
if(USART_RX_STA&0x4000)//接收到了0x0d
|
||
{
|
||
if(Res!=0x0a)USART_RX_STA=0;//接收错误,重新开始
|
||
else USART_RX_STA|=0x8000; //接收完成了
|
||
}
|
||
else //还没收到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;//接收数据错误,重新开始接收
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#ifdef OS_TICKS_PER_SEC //如果时钟节拍数定义了,说明要使用ucosII了.
|
||
OSIntExit();
|
||
#endif
|
||
}
|
||
#endif
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//////////////////////////////////USART2,PD5、PD6/////////////////////////////////
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
|
||
#if EN_USART2_RX //如果使能了接收
|
||
//串口2中断服务程序
|
||
//注意,读取USARTx->SR能避免莫名其妙的错误
|
||
u8 USART2_RX_BUF[USART2_REC_LEN]; //接收缓冲,最大USART2_REC_LEN个字节.
|
||
//接收状态
|
||
//bit15, 接收完成标志
|
||
//bit14, 接收到0x0d
|
||
//bit13~0, 接收到的有效字节数目
|
||
u16 USART2_RX_STA = 0; //接收状态标记
|
||
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端口设置
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
USART_InitTypeDef USART_InitStructure;
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能GPIOD时钟
|
||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //使能USART2时钟
|
||
// 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; //复用推挽输出
|
||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||
|
||
//USART2_RX PA.3
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//浮空输入
|
||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||
|
||
//Usart2 NVIC 配置
|
||
|
||
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//抢占优先级3
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //子优先级3
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
|
||
|
||
//USART 初始化设置
|
||
|
||
USART_InitStructure.USART_BaudRate = bound;//一般设置为9600;
|
||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
|
||
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
|
||
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
|
||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
|
||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
|
||
|
||
USART_Init(USART2, &USART_InitStructure); //初始化串口
|
||
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//开启中断
|
||
/* Enable USART2 */
|
||
// USART_Cmd(USART2, ENABLE);
|
||
|
||
|
||
// USART_ITConfig(USART2, USART_IT_TC, ENABLE);
|
||
USART_ITConfig(USART2, USART_IT_IDLE, ENABLE);
|
||
USART_Cmd(USART2, ENABLE); //使能串口
|
||
USART_ClearFlag(USART2,USART_FLAG_TXE);
|
||
}
|
||
|
||
void USART2_IRQHandler(void) //串口2中断服务程序
|
||
{
|
||
//接收中断
|
||
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) //接收空闲中断
|
||
{
|
||
USART_ReceiveData(USART2);
|
||
USART2_RX_FLAG=1;
|
||
// memset(recvnetBuffer,0,NET_BUF_SIZE);
|
||
USART_ClearITPendingBit(USART2,USART_IT_IDLE);
|
||
}
|
||
//发送中断
|
||
if(USART_GetITStatus(USART2, USART_IT_TC) != RESET)
|
||
{
|
||
USART_ClearITPendingBit(USART2,USART_IT_TC);
|
||
}
|
||
//清除错误标志
|
||
if (USART_GetFlagStatus(USART2,USART_FLAG_ORE)==SET)
|
||
{
|
||
USART_ClearFlag(USART2,USART_FLAG_ORE); //读SR
|
||
USART_ReceiveData(USART2); //读DR
|
||
}
|
||
//噪声错误标志
|
||
if (USART_GetFlagStatus(USART2,USART_FLAG_NE)==SET)
|
||
{
|
||
USART_ClearFlag(USART2,USART_FLAG_NE); //读SR
|
||
USART_ReceiveData(USART2); //读DR
|
||
}
|
||
//帧错误
|
||
if (USART_GetFlagStatus(USART2,USART_FLAG_FE)==SET)
|
||
{
|
||
USART_ClearFlag(USART2,USART_FLAG_FE); //读SR
|
||
USART_ReceiveData(USART2); //读DR
|
||
}
|
||
}
|
||
#endif
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//////////////////////////////////USART3,PB10、PB11///////////////////////////////
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
|
||
#if EN_USART3_RX //如果使能了接收
|
||
//串口1中断服务程序
|
||
//注意,读取USARTx->SR能避免莫名其妙的错误
|
||
u8 USART3_RX_BUF[USART3_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.
|
||
//接收状态
|
||
//bit15, 接收完成标志
|
||
//bit14, 接收到0x0d
|
||
//bit13~0, 接收到的有效字节数目
|
||
u16 USART3_RX_STA=0; //接收状态标记
|
||
u8 USART3_RX_FLAG=0;
|
||
u16 USART3_RX_LEN=0; //接收长度
|
||
void uart3_init(u32 bound){
|
||
//GPIO端口设置
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
USART_InitTypeDef USART_InitStructure;
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE); //使能USART3,GPIOE,B时钟
|
||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); //使能USART3时钟
|
||
|
||
// 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; //复用推挽输出
|
||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||
|
||
//USART3_RX PB.11
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//浮空输入
|
||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||
|
||
//Usart3 NVIC 配置
|
||
|
||
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//抢占优先级3
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //子优先级3
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
|
||
|
||
//USART 初始化设置
|
||
|
||
USART_InitStructure.USART_BaudRate = bound;//一般设置为9600;
|
||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
|
||
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
|
||
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
|
||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
|
||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
|
||
|
||
USART_Init(USART3, &USART_InitStructure); //初始化串口
|
||
USART_Cmd(USART3, ENABLE); //使能串口
|
||
|
||
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//开启中断
|
||
// 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) //串口3中断服务程序
|
||
{
|
||
u8 Res;
|
||
static u8 index =0;
|
||
if(USART_GetITStatus(USART3,USART_IT_RXNE)!= RESET)
|
||
{
|
||
Res =USART_ReceiveData(USART3);//(USART1->DR); //读取接收到的数据
|
||
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) //接收空闲中断
|
||
{
|
||
USART_ReceiveData(USART3);
|
||
USART3_RX_FLAG = 1;
|
||
|
||
|
||
USART_ClearITPendingBit(USART3,USART_IT_IDLE);
|
||
}
|
||
//发送中断
|
||
if(USART_GetITStatus(USART3, USART_IT_TC) != RESET)
|
||
{
|
||
USART_ClearITPendingBit(USART3,USART_IT_TC);
|
||
}
|
||
//清除错误标志
|
||
if (USART_GetFlagStatus(USART3,USART_FLAG_ORE)==SET)
|
||
{
|
||
USART_ClearFlag(USART3,USART_FLAG_ORE); //读SR
|
||
USART_ReceiveData(USART3); //读DR
|
||
}
|
||
//噪声错误标志
|
||
if (USART_GetFlagStatus(USART3,USART_FLAG_NE)==SET)
|
||
{
|
||
USART_ClearFlag(USART3,USART_FLAG_NE); //读SR
|
||
USART_ReceiveData(USART3); //读DR
|
||
}
|
||
//帧错误
|
||
if (USART_GetFlagStatus(USART3,USART_FLAG_FE)==SET)
|
||
{
|
||
USART_ClearFlag(USART3,USART_FLAG_FE); //读SR
|
||
USART_ReceiveData(USART3); //读DR
|
||
}
|
||
// if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾)
|
||
// {
|
||
// Res =USART_ReceiveData(USART3);//(USART1->DR); //读取接收到的数据
|
||
// }
|
||
|
||
}
|
||
#endif
|
||
|
||
|
||
|
||
#if EN_UART4_RX //如果使能了接收
|
||
//串口1中断服务程序
|
||
//注意,读取USARTx->SR能避免莫名其妙的错误
|
||
u8 UART4_RX_BUF[UART4_REC_LEN]; //接收缓冲,最大UART4_REC_LEN个字节.
|
||
//接收状态
|
||
//bit15, 接收完成标志
|
||
//bit14, 接收到0x0d
|
||
//bit13~0, 接收到的有效字节数目
|
||
u16 UART4_RX_STA=0; //接收状态标记
|
||
u8 UART4_RX_FLAG;
|
||
u16 UART4_RX_LEN=0; //接收长度
|
||
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端口设置
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
USART_InitTypeDef USART_InitStructure;
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE); //使能GPIOC时钟
|
||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); //使能UART4时钟
|
||
|
||
//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; //复用推挽输出
|
||
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;//浮空输入
|
||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||
|
||
//Uart4 NVIC 配置
|
||
|
||
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//抢占优先级3
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
|
||
|
||
//USART 初始化设置
|
||
|
||
USART_InitStructure.USART_BaudRate = bound;//一般设置为9600;
|
||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
|
||
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
|
||
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
|
||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
|
||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
|
||
|
||
USART_Init(UART4, &USART_InitStructure); //初始化串口
|
||
USART_Cmd(UART4, ENABLE); //使能串口
|
||
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);//开启中断
|
||
|
||
USART_ITConfig(UART4, USART_IT_TC, ENABLE);
|
||
USART_ITConfig(UART4, USART_IT_IDLE, ENABLE);
|
||
|
||
|
||
}
|
||
|
||
|
||
void UART4_IRQHandler(void) //串口4中断服务程序
|
||
{
|
||
u8 Res;
|
||
static u8 index = 0;
|
||
if (USART_GetITStatus(UART4, USART_IT_RXNE)!= RESET)
|
||
{
|
||
Res =USART_ReceiveData(UART4);//(USART1->DR); //读取接收到的数据
|
||
if(UART4_RX_LEN<UART4_REC_LEN)
|
||
UART4_RX_BUF[UART4_RX_LEN++] = Res;
|
||
else
|
||
UART4_RX_LEN =0;
|
||
if (Res == 0x0A) { // Shell命令解析
|
||
ShellCommad();
|
||
ResetShell();
|
||
return;
|
||
}
|
||
USART_ClearITPendingBit(UART4,USART_IT_RXNE);
|
||
}
|
||
if(USART_GetITStatus(UART4, USART_IT_IDLE) != RESET) //接收空闲中断
|
||
{
|
||
|
||
ResetShell();
|
||
USART_ReceiveData(UART4);
|
||
USART_ClearITPendingBit(UART4,USART_IT_IDLE);
|
||
}
|
||
|
||
//发送中断
|
||
if (USART_GetITStatus(UART4, USART_IT_TXE)!= RESET)
|
||
{
|
||
USART_ClearITPendingBit(UART4,USART_IT_TXE);
|
||
}
|
||
//发送完成中断
|
||
if(USART_GetITStatus(UART4, USART_IT_TC) != RESET)
|
||
{
|
||
USART_ClearITPendingBit(UART4,USART_IT_TC);
|
||
}
|
||
//清除错误标志
|
||
if (USART_GetFlagStatus(UART4,USART_FLAG_ORE)==SET)
|
||
{
|
||
USART_ClearFlag(UART4,USART_FLAG_ORE); //读SR
|
||
USART_ReceiveData(UART4); //读DR
|
||
}
|
||
//噪声错误标志
|
||
if (USART_GetFlagStatus(UART4,USART_FLAG_NE)==SET)
|
||
{
|
||
USART_ClearFlag(UART4,USART_FLAG_NE); //读SR
|
||
USART_ReceiveData(UART4); //读DR
|
||
}
|
||
//帧错误
|
||
if (USART_GetFlagStatus(UART4,USART_FLAG_FE)==SET)
|
||
{
|
||
USART_ClearFlag(UART4,USART_FLAG_FE); //读SR
|
||
USART_ReceiveData(UART4); //读DR
|
||
}
|
||
}
|
||
#endif
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//////////////////////////////////UART5,PC12、PD2/////////////////////////////////
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
|
||
#if EN_UART5_RX //如果使能了接收
|
||
|
||
//接收状态
|
||
//bit15, 接收完成标志
|
||
//bit14, 接收到0x0d
|
||
//bit13~0, 接收到的有效字节数目
|
||
u16 UART5_RX_STA=0; //接收状态标记
|
||
u8 UART5_RX_FLAG=0;
|
||
u16 UART5_RX_LEN=0; //接收长度
|
||
|
||
|
||
|
||
u8 UART5_RX_BUF[UART5_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.
|
||
|
||
|
||
void uart5_init(u32 bound){
|
||
//GPIO端口设置
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
USART_InitTypeDef USART_InitStructure;
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD, ENABLE); //使能USART1,GPIOC,D时钟
|
||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); //使能UART5时钟
|
||
|
||
//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; //复用推挽输出
|
||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||
|
||
//UART5_RX PD.2
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//浮空输入
|
||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||
|
||
//Usart1 NVIC 配置
|
||
|
||
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//抢占优先级3
|
||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
|
||
|
||
//USART 初始化设置
|
||
|
||
USART_InitStructure.USART_BaudRate = bound;//一般设置为9600;
|
||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
|
||
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
|
||
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
|
||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
|
||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
|
||
|
||
USART_Init(UART5, &USART_InitStructure); //初始化串口
|
||
|
||
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);//开启中断
|
||
USART_ITConfig(UART5, USART_IT_IDLE, ENABLE);//开启中断
|
||
USART_Cmd(UART5, ENABLE); //使能串口
|
||
}
|
||
|
||
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) //串口1中断服务程序
|
||
{
|
||
u8 Res;
|
||
static u8 index =0;
|
||
if(USART_GetITStatus(UART5,USART_IT_RXNE)!= RESET)
|
||
{
|
||
Res =USART_ReceiveData(UART5);//(USART1->DR); //读取接收到的数据
|
||
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) //接收空闲中断
|
||
{
|
||
USART_ReceiveData(UART5);
|
||
UART5_RX_FLAG = 1;
|
||
|
||
|
||
USART_ClearITPendingBit(UART5,USART_IT_IDLE);
|
||
}
|
||
//发送中断
|
||
if(USART_GetITStatus(UART5, USART_IT_TC) != RESET)
|
||
{
|
||
USART_ClearITPendingBit(UART5,USART_IT_TC);
|
||
}
|
||
//清除错误标志
|
||
if (USART_GetFlagStatus(UART5,USART_FLAG_ORE)==SET)
|
||
{
|
||
USART_ClearFlag(UART5,USART_FLAG_ORE); //读SR
|
||
USART_ReceiveData(UART5); //读DR
|
||
}
|
||
//噪声错误标志
|
||
if (USART_GetFlagStatus(UART5,USART_FLAG_NE)==SET)
|
||
{
|
||
USART_ClearFlag(UART5,USART_FLAG_NE); //读SR
|
||
USART_ReceiveData(UART5); //读DR
|
||
}
|
||
//帧错误
|
||
if (USART_GetFlagStatus(UART5,USART_FLAG_FE)==SET)
|
||
{
|
||
USART_ClearFlag(UART5,USART_FLAG_FE); //读SR
|
||
USART_ReceiveData(UART5); //读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; //降载的结构体
|
||
|
||
void cmd_ONDCDCPrint(void)
|
||
{
|
||
|
||
}
|
||
|
||
void cmd_OFFDCDCPrint(void)
|
||
{
|
||
|
||
}
|
||
|
||
void cmd_DecodeUniquID(void)
|
||
{
|
||
NVIC_SystemReset();
|
||
printf("软件复位\r\n");
|
||
}
|
||
|
||
void cmd_cansend(void)
|
||
{
|
||
static uint16_t i =0;
|
||
|
||
if(i == 0)
|
||
{
|
||
i = 1;
|
||
|
||
CLOSE_AUXI_BOOT();
|
||
CLOSE_HV_RELAY();
|
||
printf("关闭高压模块\r\n");
|
||
}
|
||
else
|
||
{
|
||
i = 0;
|
||
|
||
OPEN_AUXI_BOOT();
|
||
OPEN_HV_RELAY();
|
||
printf("开启高压模块\r\n");
|
||
}
|
||
}
|
||
|
||
void cmd_OFF(void)
|
||
{
|
||
static uint16_t i =0;
|
||
|
||
if(i == 0)
|
||
{
|
||
i = 1;
|
||
|
||
CLOSE_DC_RELAY();
|
||
printf("关闭直流继电器\r\n");
|
||
}
|
||
else
|
||
{
|
||
i = 0;
|
||
|
||
OPEN_DC_RELAY();
|
||
printf("开启直流继电器\r\n");
|
||
}
|
||
|
||
}
|
||
|
||
void cmd_AC_RealyI(void)
|
||
{
|
||
static uint16_t i =0;
|
||
|
||
if(i == 0)
|
||
{
|
||
i = 1;
|
||
CLOSE_AC_RELAY();
|
||
printf("关闭交流继电器\r\n");
|
||
}
|
||
else
|
||
{
|
||
i = 0;
|
||
OPEN_AC_RELAY();
|
||
printf("开启交流继电器\r\n");
|
||
}
|
||
|
||
}
|
||
void cmd_Realy400(void)
|
||
{
|
||
static uint16_t i =0;
|
||
|
||
if(i == 0)
|
||
{
|
||
i = 1;
|
||
CLOSE_AUXI_BOOT();
|
||
printf("关闭升压模块\r\n");
|
||
}
|
||
else
|
||
{
|
||
i = 0;
|
||
OPEN_AUXI_BOOT();
|
||
printf("开启升压模块\r\n");
|
||
}
|
||
|
||
}
|
||
void cmd_CC1CP(void)
|
||
{
|
||
static uint16_t i =0;
|
||
|
||
if(i == 0)
|
||
{
|
||
i = 1;
|
||
CLOSE_CC1_CP_RELAY();
|
||
printf("关闭CC1CP\r\n");
|
||
}
|
||
else
|
||
{
|
||
i = 0;
|
||
OPEN_CC1_CP_RELAY();
|
||
printf("开启CC1CP\r\n");
|
||
}
|
||
|
||
}
|
||
void cmd_CC2CC(void)
|
||
{
|
||
static uint16_t i =0;
|
||
|
||
if(i == 0)
|
||
{
|
||
i = 1;
|
||
CLOSE_CC2_CC_RELAY();
|
||
printf("关闭CC2_CC\r\n");
|
||
}
|
||
else
|
||
{
|
||
i = 0;
|
||
OPEN_CC2_CC_RELAY();
|
||
printf("开启CC2_CC\r\n");
|
||
}
|
||
|
||
}
|
||
void cmd_ACTemp(void)
|
||
{
|
||
static uint16_t i =0;
|
||
|
||
if(i == 0)
|
||
{
|
||
i = 1;
|
||
CLOSE_GUN_TEMP_RELAY();
|
||
printf("关闭DC温度继电器\r\n");
|
||
}
|
||
else
|
||
{
|
||
i = 0;
|
||
OPEN_GUN_TEMP_RELAY();
|
||
printf("开启DC温度继电器\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("打开老化模式\r\n");
|
||
}
|
||
else
|
||
{
|
||
i = 0;
|
||
CDZ_SYS.work_pattern = 1;
|
||
printf("关闭老化模式\r\n");
|
||
}
|
||
}
|
||
|
||
void GET_SN()
|
||
{
|
||
if(strstr((char *)incmd.cmd,"Order_Code")!=NULL)
|
||
{
|
||
Save_Order_Code(incmd.param[0],incmd.paramlen[0]-2);//去掉/r/n
|
||
}
|
||
if(strstr((char *)incmd.cmd,"Set_SN")!=NULL)
|
||
{
|
||
Save_Product_Code(incmd.param[0],incmd.paramlen[0]*4+3);//4组数据+三个空格
|
||
}
|
||
}
|
||
|
||
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("当前命令:%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(" >执行指令:%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–order 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–order 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 ; /* 初始化高字节*/
|
||
uint8_t uchCRCLo = 0xFF ; /* 初始化低字节*/
|
||
uint8_t uIndex ; /*把CRC表*/
|
||
while (usDataLen--) /*通过数据缓冲器*/
|
||
{
|
||
uIndex = uchCRCHi ^ *puchMsg++ ; /*计算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 ; /* 初始化高字节*/
|
||
uint8_t uchCRCLo = 0xFF ; /* 初始化低字节*/
|
||
uint8_t uIndex ; /*把CRC表*/
|
||
|
||
#if 1
|
||
uchCRCHi = predata >>8;
|
||
uchCRCLo = predata & 0xff ;
|
||
#else
|
||
uchCRCLo = predata >>8;
|
||
uchCRCHi = predata & 0xff ;
|
||
#endif
|
||
|
||
while (usDataLen--) /*通过数据缓冲器*/
|
||
{
|
||
uIndex = uchCRCHi ^ *puchMsg++ ; /*计算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 ; /* 初始化高字节*/
|
||
uint8_t uchCRCLo = 0xFF ; /* 初始化低字节*/
|
||
uint8_t uIndex ; /*把CRC表*/
|
||
|
||
#if 1
|
||
uchCRCHi = predata >>8;
|
||
uchCRCLo = predata & 0xff ;
|
||
#else
|
||
uchCRCLo = predata >>8;
|
||
uchCRCHi = predata & 0xff ;
|
||
#endif
|
||
|
||
while (usDataLen--) /*通过数据缓冲器*/
|
||
{
|
||
uIndex = uchCRCHi ^ *puchMsg++ ; /*计算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)
|
||
{
|
||
|
||
}
|
||
|
||
|
||
/*发送一个字节数据*/
|
||
|
||
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("蓝牙数据: \r\n");
|
||
// }
|
||
for(i =0;i<length;i++)
|
||
{
|
||
USART2SendByte(buff[i]);
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/***********************蓝牙任务处理******************************/
|
||
/* LCD单条协议解析*/
|
||
typedef struct LCD_FramePara__
|
||
{
|
||
uint8_t ucLen; //总长度(除去头字节)
|
||
uint16_t iAddress; // 寄存器地址
|
||
uint8_t ucFunCode; // 功能码
|
||
uint8_t ucRegLen; // 寄存器长度
|
||
uint8_t ucDataSpace[200]; // 数据域
|
||
}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++)//排序
|
||
// {
|
||
// for(i=0;i<SocCalculate.index-j-1;i++)
|
||
// {
|
||
// if(SocCalculate.data[i].startVolt > SocCalculate.data[i+1].startVolt)
|
||
// {
|
||
// temp = SocCalculate.data[i]; //从小到大排序
|
||
// SocCalculate.data[i] = SocCalculate.data[i+1];
|
||
// SocCalculate.data[i+1] = temp;
|
||
// }
|
||
// }
|
||
// }
|
||
// //计算权值
|
||
// 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);
|
||
// }
|
||
// //写入内存
|
||
// 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]; //从小到大排序
|
||
SysParaPileD.SocCalculate.data[i] = SysParaPileD.SocCalculate.data[i+1];
|
||
SysParaPileD.SocCalculate.data[i+1] = temp;
|
||
}
|
||
}
|
||
#endif
|
||
|
||
// //计算权值
|
||
// for(i=0;i<SocCalculate.index;i++)
|
||
// {
|
||
// if(i==0)
|
||
// {
|
||
// //低于最小设置soc的电压--
|
||
// if(Sample_DataS.BAT_Voltage < SocCalculate.data[0].startVolt)
|
||
// {
|
||
// return 2;//由默认算法计算
|
||
// }
|
||
// }
|
||
//
|
||
// //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 ;
|
||
// }
|
||
// }
|
||
// }
|
||
// //写入内<E585A5>
|
||
// if(i==SocCalculate.index)
|
||
// {
|
||
// //高于最大设置soc的电压--
|
||
// if(Sample_DataS.BAT_Voltage > SocCalculate.data[i].startVolt)
|
||
// {
|
||
// return 2;//由默认算法计算
|
||
// }
|
||
// }
|
||
return 0;
|
||
}
|
||
|
||
|
||
uint16_t udatatemp =0;
|
||
|
||
typedef struct
|
||
{
|
||
uint16_t BmsMaxVolt; //电池额定电压==最大充电电压 BatMaxTotalChargeVol
|
||
uint16_t BmsMaxCurrent;
|
||
uint16_t TotalVoltage;//电池额定电压
|
||
uint16_t TotalCapacity; //电池额定容量
|
||
uint16_t BatMaxChargeCur;
|
||
uint16_t uBatMaxEnergy; //电池最大容量
|
||
uint16_t BatMaxTotalChargeVol; //电池最大充电总电压
|
||
uint16_t fTotalBatVol;
|
||
//注册码
|
||
uint16_t BmRequireVolt;
|
||
uint16_t BmsRequireCurrent;
|
||
uint16_t StopVoltage;
|
||
uint16_t RequirePower; //恒功率时以此变量为主
|
||
uint16_t OverPower;
|
||
uint8_t tricklepower; //涓流功率
|
||
uint8_t tricklecurrent; //涓流电流
|
||
uint16_t BatMaxChargeVol; //单体蓄电池最高允许充电电压(0.00~24.00V) 0.01V
|
||
uint16_t BatRatedVoltage; //单体电池额定电压 0.1V
|
||
uint8_t uBatMaxTempPlus50; //蓄电池模块最高允许的温度(-50~200℃)
|
||
uint8_t uBatMinTempPlus50; //最低温度
|
||
//DCDC功率
|
||
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},//温度保护值
|
||
{0x07 ,2,(uint8_t *)&SysParaPileD.HeartBeatTime},//心跳包时间
|
||
{0x08 ,1,(uint8_t *)&SysParaPileD.ProtocolType},//新老国标协议
|
||
|
||
{0x09 ,16,(uint8_t *)SysParaPileD.sn},//设置SN号
|
||
{0x0A ,1,(uint8_t *)&SysParaPileD.QuickChargeEnable},//离线快充使能
|
||
{0x0F ,1,(uint8_t *)&SysParaPileD.tricklecurrent},//涓流充电电流
|
||
{0x0E ,1,(uint8_t *)&SysParaPileD.tricklepower},//涓流充电功率
|
||
{0x0D ,1,(uint8_t *)&SysParaPileD.trickleChargingSoc},//涓流soc
|
||
{0x0C ,1,(uint8_t *)&SysParaPileD.trickleChargingSocEnable},//涓流使能
|
||
{0x0B ,1,(uint8_t *)&udatatemp},
|
||
{0x13,2,(uint8_t *)&SysParaPileD.BmsMaxCurrent},//设置电流
|
||
{0x12 ,2,(uint8_t *)&SysParaPileD.BmsMaxVolt},//设置电压
|
||
{0x11 ,2,(uint8_t *)&SysParaPileD.BmsRequireCurrent},//需求电流
|
||
{0x10 ,2,(uint8_t *)&SysParaPileD.BmRequireVolt},//需求电压
|
||
|
||
|
||
{0x14,2,(uint8_t *)&udatatemp},//soc
|
||
// {0x15,2,(uint8_t *)&Sample_DataS.BAT_B_Reverse_Voltage},//当前电池电压
|
||
{0x16,2,(uint8_t *)&SysParaPileD.uBatMaxEnergy},//电池最大容量
|
||
|
||
|
||
|
||
// {0x17,4,(uint8_t *)&Bms_BatInfo.ucBmsVersion},//soc
|
||
{0x18,1,(uint8_t *)&SysParaPileD.ucBatType},//当前电池电压
|
||
// {0x19,4,(uint8_t *)&Bms_BatInfo.ucProductName},//电池最大容量
|
||
|
||
// {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},//需求功率
|
||
{0x1E,1,(uint8_t *)&sysparamdata.OverPower},//最高功率
|
||
{0x1D,1,(uint8_t *)&SysParaPileD.ChargingMode},// 充电模式 恒流 恒功率
|
||
|
||
|
||
{0x20,1, (uint8_t *)&sysparamdata.BatRatedVoltage}, //单体额定电压
|
||
{0x21 ,1,(uint8_t *)&sysparamdata.BatMaxChargeVol},//单体蓄电池最高允许充电电压
|
||
|
||
{0x22 ,1,(uint8_t *)&SysParaPileD.BatCount},//电池单体数量
|
||
{0x24 ,2,(uint8_t *)&SysParaPileD.BmsMaxVolt},//系统满电电压
|
||
{0x23 ,2,(uint8_t *)&SysParaPileD.TotalCapacity},//系统额定容量
|
||
{0x27 ,1,(uint8_t *)&SysParaPileD.ucBatType},//电池类型
|
||
{0x26 ,1,(uint8_t *)&sysparamdata.uBatMinTempPlus50},//电池最低温度
|
||
{0x25 ,1,(uint8_t *)&sysparamdata.uBatMaxTempPlus50},//电池最高温度
|
||
{0x28 ,2,(uint8_t *)&SysParaPileD.TotalVoltage},//系统额定电压
|
||
{0x29 ,1,(uint8_t *)&SysParaPileD.RequireVoltageDifference},//当前需求与实际电压 压差
|
||
|
||
{0x2A ,2,(uint8_t *)&SysParaPileD.SimulatedCurrentBatVolt},//模拟电池采样电压
|
||
{0x2B ,1,(uint8_t *)&SysParaPileD.Debug_Page_function},//调试页面参数
|
||
//===========================================================
|
||
{0x30 ,2,(uint8_t *)&SysParaPileD.uBatMaxEnergy},//充电电量
|
||
{0x31 ,2,(uint8_t *)&sysparamdata.StopVoltage},//停机电压
|
||
{0x32 ,1,(uint8_t *)&SysParaPileD.OverTempValue[0]},//温度探头1
|
||
{0x33 ,1,(uint8_t *)&SysParaPileD.OverTempValue[1]},//温度探头1
|
||
{0x34 ,1,(uint8_t *)&SysParaPileD.OverTempValue[2]},//温度探头2
|
||
{0x35 ,1,(uint8_t *)&SysParaPileD.SignalLossFlag},//信号丢失
|
||
{0x36 ,10,(uint8_t *)SysParaPileD.VehichleInfo},//车辆VIN
|
||
{0x37 ,7,(uint8_t *)&SysParaPileD.VehichleInfo[10]},//车辆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}, //充电参数
|
||
{0x65 ,1,(uint8_t *)&SysParaPileD.HighVoltageModule}, //高压辅助模块 1开 0关
|
||
{0x66 ,1,(uint8_t *)&SysParaPileD.HighVoltageOffset}, //高压辅助模块 校准
|
||
|
||
{0x6D ,1,(uint8_t *)&SysParaPileD.SocSimulaType},//SOC计算方式 1-can读取 2-soc模拟 3-SOC校准
|
||
{0x6E ,2,(uint8_t *)&SysParaPileD.SocSimulaMaxVolt},//SOC模拟最大电压取 2-soc模拟 3-SOC校准
|
||
{0x6F ,2,(uint8_t *)&SysParaPileD.SocSimulaMinVolt},//SOC模拟最小电压-soc模拟 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)
|
||
{
|
||
//数据打包
|
||
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; //升级
|
||
return;
|
||
}
|
||
|
||
#endif
|
||
|
||
switch(Blue_pkg->cmd)
|
||
{
|
||
case 0x8000: //注册包
|
||
case 0x0080: //注册包
|
||
if(Blue_pkg->ucDataSpace[0]==1)
|
||
{
|
||
BluetoothInfo.ConnectServerState = BLUE_LOGIN; //注册成功
|
||
SysParaPileD.registeredFlag = 1;
|
||
memset(SysParaPileD.registeredCode,0,sizeof(SysParaPileD.registeredCode));
|
||
memcpy( SysParaPileD.registeredCode,&Blue_pkg->ucDataSpace[1],8);
|
||
//写入flash保存
|
||
BluetoothInfo.ConnectServerState = BLUE_LOGIN;
|
||
SysStoreSysParmflag =1;
|
||
printf("registered successed,Code %s\n\r",SysParaPileD.registeredCode);
|
||
}
|
||
else
|
||
{
|
||
printf("registered failed\n\r");
|
||
}
|
||
break;
|
||
case 0x8001: //登录包
|
||
case 0x0180: //登录包
|
||
if(Blue_pkg->ucDataSpace[0]==1)
|
||
{
|
||
//登陆成功
|
||
BluetoothInfo.ConnectServerState = BLUE_WECHATAPPLET_ONLINE;
|
||
printf("Login Successed\n\r");
|
||
}
|
||
else
|
||
{
|
||
printf("Login Failed\n\r");
|
||
}
|
||
break;
|
||
|
||
case 0x8002: //心跳包
|
||
case 0x0280: //心跳包
|
||
printf("heart count %d\n\r",Blue_pkg->ucDataSpace[0]);
|
||
memcpy(&ChargeRecordInfo.date,&Blue_pkg->ucDataSpace[2],7) ;
|
||
break;
|
||
|
||
case 0x8003: //当前状态包
|
||
case 0x0380: //当前状态包
|
||
printf("receive state data \n\r");
|
||
break;
|
||
|
||
case 0x8004: //允许充电
|
||
case 0x0480: //允许充电
|
||
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;//小程序停止充电
|
||
}
|
||
break;
|
||
|
||
case 0x8005: //设置包
|
||
case 0x0580: //设置包
|
||
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;//小程序停止充电
|
||
}
|
||
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)//温度保护值
|
||
{
|
||
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 ) //电池当前SOC 启动计算
|
||
{
|
||
data =Blue_pkg->ucDataSpace[2] ;
|
||
// if(data ==1) //启动soc校准
|
||
// {
|
||
// memset((char *)&SocCalculate,0,sizeof(SocCalculate));
|
||
// SocCalculate.CalibrationEnable =0;
|
||
// SysWriteSocParm();
|
||
// printf("\n\rsoc启动校准\n\r");
|
||
// }
|
||
// else if(data ==2) //soc校准完成
|
||
// {
|
||
// //排序计算保存起来
|
||
//// SocCalculateOver();
|
||
//// SysWriteSocParm();
|
||
// printf("\n\rsoc启动校准完成\n\r");
|
||
// }
|
||
|
||
}
|
||
if( addrparam == 0x0C) //电池当前SOC 启动计算
|
||
{
|
||
data =Blue_pkg->ucDataSpace[2] ;
|
||
if(data ==1) //启动soc校准
|
||
{
|
||
SysParaPileD.trickleChargingSocEnable =1;
|
||
printf("trickle Charging Soc Enable 1\n\r");
|
||
}
|
||
else
|
||
{
|
||
//排序计算保存起来
|
||
SysParaPileD.trickleChargingSocEnable =0;
|
||
printf("trickle Charging Soc Enable 0\n\r");
|
||
}
|
||
// SysWriteSysParm();
|
||
SysStoreSysParmflag =1;
|
||
}
|
||
if( addrparam == 0x0D) //电池当前SOC 启动计算
|
||
{
|
||
data =Blue_pkg->ucDataSpace[2] ;
|
||
if(data < 100) //启动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 ) //电池当前SOC --做一个数组计算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 ) // 充电模式 恒流 恒功率
|
||
{
|
||
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 ) //最高功率
|
||
{
|
||
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 ) //需求功率
|
||
{
|
||
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;
|
||
}
|
||
}
|
||
//电池相关信息
|
||
if( addrparam == 0x20 ) //单体额定电压
|
||
{
|
||
data = Blue_pkg->ucDataSpace[2] ;
|
||
SysParaPileD.BatRatedVoltage = data*10;
|
||
printf("BatRatedVoltage :%d.%dV\n\r",SysParaPileD.BatRatedVoltage /100,SysParaPileD.BatRatedVoltage %100 );
|
||
// SysWriteSysParm();
|
||
}
|
||
//单体蓄电池最高允许充电电压(0.00~24.00V) 0.01V
|
||
//单体电池额定电压 0.1V
|
||
|
||
// 满电电压
|
||
// 电池类型
|
||
//涓流功能
|
||
|
||
//soc涓流 使能
|
||
//涓流soc启动值
|
||
//涓流功率
|
||
//涓流电流
|
||
if( addrparam == 0x21 ) //单体蓄电池最高允许充电电压
|
||
{
|
||
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 ) //单体数量
|
||
{
|
||
data = Blue_pkg->ucDataSpace[2] ;
|
||
SysParaPileD.BatCount = data;
|
||
printf("BatCount :%d\n\r",SysParaPileD.BatCount );
|
||
// SysWriteSysParm();
|
||
SysStoreSysParmflag =1;
|
||
}
|
||
if( addrparam == 0x23 ) //系统额定容量
|
||
{
|
||
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 ) //系统满电电压
|
||
{
|
||
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 ) //电池最高温度
|
||
{
|
||
data = Blue_pkg->ucDataSpace[2] ;
|
||
printf("uBatMaxTempPlus50 :%d \n\r", data );
|
||
SysParaPileD.uBatMaxTempPlus50 = data+50;
|
||
// SysWriteSysParm();
|
||
SysStoreSysParmflag =1;
|
||
}
|
||
if( addrparam == 0x26 ) //电池最低温度
|
||
{
|
||
data = Blue_pkg->ucDataSpace[2] ;
|
||
printf("uBatMinTempPlus50 :%d \n\r",data );
|
||
SysParaPileD.uBatMinTempPlus50 = data+50;
|
||
// SysWriteSysParm();
|
||
SysStoreSysParmflag =1;
|
||
}
|
||
if( addrparam == 0x27 ) //电池类型
|
||
{
|
||
data = Blue_pkg->ucDataSpace[2] ;
|
||
SysParaPileD.ucBatType = data;
|
||
if(data==1)
|
||
printf("ucBatType:铅酸电池 \n\r" );
|
||
if(data==2)
|
||
printf("ucBatType:镍氢电池 \n\r" );
|
||
if(data==3)
|
||
printf("ucBatType:磷酸铁锂电池 \n\r" );
|
||
if(data==4)
|
||
printf("ucBatType:锰酸锂电池 \n\r" );
|
||
if(data==5)
|
||
printf("ucBatType:钴酸锂电池 \n\r" );
|
||
if(data==6)
|
||
printf("ucBatType:三元锂电池 \n\r" );
|
||
if(data==7)
|
||
printf("ucBatType:聚合物锂离子电池 \n\r" );
|
||
if(data==8)
|
||
printf("ucBatType:钛酸锂电池 \n\r" );
|
||
if(data==0xff)
|
||
printf("ucBatType:其他电池 \n\r" );
|
||
// SysWriteSysParm();
|
||
SysStoreSysParmflag =1;
|
||
}
|
||
if( addrparam == 0x28) //系统额定电压
|
||
{
|
||
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) //当前需求与实际电压 压差
|
||
{
|
||
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) // 调试模式打开
|
||
{
|
||
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 ) //充电电量
|
||
{
|
||
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 ) //停机电压
|
||
{
|
||
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) //停机温度--主板
|
||
{
|
||
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设置VIN长度错误%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设置VIN长度错误%s\n\r",&Blue_pkg->ucDataSpace[2]);
|
||
// }
|
||
// SysWriteSysParm();
|
||
}
|
||
|
||
//---------------------------------DCBMS------------------------------
|
||
if( addrparam == 0x50) // 专业简易模式
|
||
{
|
||
|
||
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需求电压
|
||
{
|
||
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需求电流
|
||
{
|
||
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最大功率
|
||
{
|
||
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保护条件******************/
|
||
|
||
|
||
if( addrparam == 0x54) // 电感温度 --
|
||
{
|
||
data = Blue_pkg->ucDataSpace[2] ;
|
||
|
||
SysParaPileD.DC_InductanceTemp = data;
|
||
printf("DC_InductanceTemp %d \n\r",SysParaPileD.DC_InductanceTemp);
|
||
|
||
// SysWriteSysParm();
|
||
SysStoreSysParmflag =1;
|
||
}
|
||
if( addrparam == 0x55) // 管子温度 --
|
||
{
|
||
data = Blue_pkg->ucDataSpace[2] ;
|
||
|
||
SysParaPileD.DC_IGBTTemp = data;
|
||
printf("DC_IGBTTemp %d \n\r",SysParaPileD.DC_IGBTTemp);
|
||
|
||
// SysWriteSysParm();
|
||
SysStoreSysParmflag =1;
|
||
}
|
||
if( addrparam == 0x56) // 最大电压--
|
||
{
|
||
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) // 最大电流--
|
||
{
|
||
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) // 管子温度 --
|
||
{
|
||
data = Blue_pkg->ucDataSpace[2] ;
|
||
if(data <150 )
|
||
SysParaPileD.CapacitanceTemp1 = data;
|
||
printf("CapacitanceTemp1 %d \n\r",SysParaPileD.CapacitanceTemp1);
|
||
|
||
SysStoreSysParmflag =1;
|
||
}
|
||
if( addrparam == 0x59) // 管子温度 --
|
||
{
|
||
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) // 设备VIN功能是否打开
|
||
{
|
||
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) // 信号丢失
|
||
{
|
||
|
||
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) // 充电方式
|
||
{
|
||
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) // 数值
|
||
{
|
||
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) // 涓流开关
|
||
{
|
||
|
||
|
||
SysStoreSysParmflag =1;
|
||
// SysWriteSysParm();
|
||
}
|
||
if( addrparam == 0x65) //辅助高压模块开关
|
||
{
|
||
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信号丢失 %s \n\r",SysParaPileD.HighVoltageOffset==1?"使能":"禁止" );
|
||
//
|
||
// SysWriteSysParm();
|
||
// }
|
||
if( addrparam == 0x6D) // SOC计算方式
|
||
{
|
||
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计算方式 1-can读取 2-soc模拟 3-SOC校准
|
||
// SysWriteSysParm();
|
||
SysStoreSysParmflag =1;
|
||
}
|
||
if( addrparam == 0x6E) // SOC模拟最高电压
|
||
{
|
||
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模拟最低电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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校准电压
|
||
{
|
||
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) //读取命令
|
||
{
|
||
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++) //循环读取参数地址与长度
|
||
{
|
||
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++) //循环读取参数地址与长度
|
||
{
|
||
Blue_Send_Package.ucDataSpace[2+i] = Blue_pkg->ucDataSpace[2+i];
|
||
}
|
||
DP_PackageWriteDataFrame(&Blue_Send_Package, ucComBuf, &ucLen);
|
||
}
|
||
break;
|
||
case 0x8006: //设置包
|
||
case 0x0680: //设置包
|
||
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状态报文
|
||
case 0x0780: //DCDC状态报文
|
||
printf("Receive DCDC state ack\n\r");
|
||
// printf("\n\r允许充电%s\n\r",Blue_pkg->ucDataSpace[1] == 1 ? "允许":"禁止");
|
||
// if(Blue_pkg->ucDataSpace[1] == 0 )
|
||
// {
|
||
// ServerStop_ChargeFlag = 1;
|
||
// }
|
||
break;
|
||
case 0x8008: //升级包
|
||
case 0x0880: //升级包
|
||
printf("Receive DCDC state ack\n\r");
|
||
break;
|
||
case 0x8009: //文件类型升级
|
||
case 0x0980:
|
||
printf("Receive DCDC state ack\n\r");
|
||
break;
|
||
case 0x800A: //文件内容
|
||
|
||
case 0x800D: //调试数据
|
||
printf("Receive DEBUG DCDC ack\n\r");
|
||
BluetoothInfo.connetcOvertimeFlag =0;
|
||
break;
|
||
|
||
case 0x0A80:
|
||
printf("Receive DCDC state ack\n\r");
|
||
break;
|
||
case 0x8020: //文件内容
|
||
case 0x2080:
|
||
|
||
break;
|
||
|
||
case 0x8021: //文件内容
|
||
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; //总长度(除去头字节)
|
||
// 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 : 空闲等待,判断支付方式、枪号、充电模式、弹开枪门
|
||
**********************************************************************************/
|
||
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;
|
||
/* 打包站号功能码 */
|
||
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;
|
||
}
|
||
|
||
/*计算CRC*/
|
||
crc = BlueCRC16(pBuf, iCount);
|
||
/*打包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)//计数标志
|
||
{
|
||
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;
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : Bluetooth_Registered
|
||
* @ 功能说明: 设备首次登录向小程序上报数据,用于获取和绑定注册码。
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
void Bluetooth_Registered(void)
|
||
{
|
||
//数据打包
|
||
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);
|
||
}
|
||
}
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : Bluetooth_Login
|
||
* @ 功能说明: 设备登录时向小程序上报数据,用于校验注册码和同步固件版本号。
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
void Bluetooth_Login(void)
|
||
{
|
||
//数据打包
|
||
static uint32_t timer;
|
||
uint8_t ucComBuf[64];
|
||
uint16_t ucLen = 0;
|
||
if(TickOut(&timer, 3000)==TRUE)
|
||
{
|
||
Blue_Send_Package.cmd = 0x1001;
|
||
//注册码
|
||
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);
|
||
}
|
||
}
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : Bluetooth_HeartBeat
|
||
* @ 功能说明: 设备定期向小程序上报数据,用于保持心跳连接。比亚迪远古版本从这里获取设置参数,
|
||
新版本可以使用0x8005获取设置参数后基本用不上这个报文
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
void Bluetooth_HeartBeat(void)
|
||
{
|
||
//数据打包
|
||
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协议
|
||
// Blue_Send_Package.ucDataSpace[2]=SysParaPileD.ProtocolType; // bms协议
|
||
// 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--恒功率 2-恒流
|
||
// Blue_Send_Package.ucDataSpace[12]=(SysParaPileD.OverPower/10 ); //最大功率
|
||
// Blue_Send_Package.ucDataSpace[13]=(SysParaPileD.uBatMaxEnergy)&0xff;
|
||
// Blue_Send_Package.ucDataSpace[14]=(SysParaPileD.uBatMaxEnergy>>8)&0xff;//最大电量
|
||
// Blue_Send_Package.ucDataSpace[15]=(SysParaPileD.StopVoltage/10)&0xff;
|
||
// Blue_Send_Package.ucDataSpace[16]=((SysParaPileD.StopVoltage/10)>>8)&0xff;//停机电压
|
||
//
|
||
// //单体蓄电池最高允许充电电压(0.00~24.00V) 0.01V
|
||
// //单体电池额定电压 0.1V
|
||
// Blue_Send_Package.ucDataSpace[17]=((SysParaPileD.BatRatedVoltage/10))&0xff;
|
||
// //Blue_Send_Package.ucDataSpace[18]=((SysParaPileD.BatRatedVoltage/10)>>8)&0xff;//最大电量
|
||
// Blue_Send_Package.ucDataSpace[18]=(SysParaPileD.BatMaxChargeVol/10)&0xff;
|
||
// //Blue_Send_Package.ucDataSpace[20]=((SysParaPileD.BatMaxChargeVol/10)>>8)&0xff;//停机电压
|
||
// // 额定电电压
|
||
// // 额定容量
|
||
// 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;
|
||
// // 满电电压
|
||
// // 电池类型
|
||
// Blue_Send_Package.ucDataSpace[23]=(SysParaPileD.BmsMaxVolt)&0xff;
|
||
// Blue_Send_Package.ucDataSpace[24]=((SysParaPileD.BmsMaxVolt)>>8)&0xff;
|
||
// Blue_Send_Package.ucDataSpace[25]=SysParaPileD.ucBatType;
|
||
// //涓流功能
|
||
// //soc涓流 使能
|
||
// //涓流soc启动值
|
||
// //涓流功率
|
||
// //涓流电流
|
||
// 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协议
|
||
|
||
// Blue_Send_Package.ucDataSpace[38]=(SysParaPileD.RequirePower/10 ); //需求功率
|
||
// Blue_Send_Package.ucDataSpace[39]=(SysParaPileD.SignalLossFlag ); // 信号丢失
|
||
|
||
// Blue_Send_Package.ucDataSpace[40]=(SysParaPileD.RequireVoltageDifference); //需求电压比实际采样
|
||
// //电压的差别
|
||
// memcpy(&Blue_Send_Package.ucDataSpace[41],SysParaPileD.VehichleInfo,17);
|
||
//车辆VIN上传
|
||
//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);
|
||
}
|
||
}
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : BMS_StatusMessage
|
||
* @ 功能说明: 设备定期向小程序上报数据,用于同步设备状态
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
void BMS_StatusMessage(void)
|
||
{
|
||
//数据打包
|
||
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);
|
||
}
|
||
}
|
||
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : BMS_StatusMessage
|
||
* @ 功能说明: 设备定期向小程序上报数据,用于同步充电桩的电压电流数据。
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
void BMS_ChargeInfo(void)//充电桩状态报文
|
||
{
|
||
//数据打包
|
||
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;
|
||
// //当前充电电量
|
||
//
|
||
// Blue_Send_Package.ucDataSpace[12]=((uint16_t)(CDZ_ChargeInfo.ChargeEnergyTotal))&0xff;
|
||
// Blue_Send_Package.ucDataSpace[13]=(((uint16_t)(CDZ_ChargeInfo.ChargeEnergyTotal))>>8)&0xff;
|
||
// //启动时soc , 当前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; //充电时间
|
||
// Blue_Send_Package.ucDataSpace[29]= ((CDZ_ChargeInfo.ChargeTimeTotal)>>8)&0xff; //充电时间
|
||
|
||
//
|
||
//// if( CDZ_ChargeInfo.ChargeTime >60)
|
||
//// {
|
||
//// Blue_Send_Package.ucDataSpace[28]= CDZ_ChargeInfo.ChargeTime &0xff; //充电时间
|
||
//// Blue_Send_Package.ucDataSpace[29]= ((CDZ_ChargeInfo.ChargeTime)>>8)&0xff; //充电时间
|
||
//// }
|
||
//// else
|
||
//// {
|
||
//// Blue_Send_Package.ucDataSpace[28]= ChargeRecordInfo.chargingtime &0xff; //充电时间
|
||
//// Blue_Send_Package.ucDataSpace[29]= ((ChargeRecordInfo.chargingtime)>>8)&0xff; //充电时间
|
||
//// }
|
||
|
||
|
||
|
||
// if(WuLingBatteryInfo.bms29A.bits.BatTalVolSm > 400)
|
||
// data = WuLingBatteryInfo.bms29A.bits.BatTalVolSm; // 通信的电压或者DCDC输出电压
|
||
// else
|
||
// {
|
||
//
|
||
// if(ModuleInfo.state == POWER_ON)
|
||
// {
|
||
// data = ModuleInfo.current_volt; // 通信的电压或者DCDC输出电压
|
||
// }
|
||
// 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);
|
||
}
|
||
}
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : BMS_SetDataAck
|
||
* @ 功能说明: 设备登应答内容
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
void BMS_SetDataAck(void)
|
||
{
|
||
//数据打包
|
||
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);
|
||
}
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : Bluetooth_chargeRecord
|
||
* @ 功能说明: 设备登录时向小程序上报数据,用于校验注册码和同步固件版本号。
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
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++;
|
||
}
|
||
}
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : Bluetooth_DCDC_Data
|
||
* @ 功能说明: 模块数据
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
void Bluetooth_DCDC_Data(void)//模块状态信息
|
||
{
|
||
//数据打包
|
||
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);
|
||
}
|
||
}
|
||
/**********************************************************************
|
||
* @ 函数名 : BMS_VersionInfo
|
||
* @ 功能说明: 设备定期向小程序上报数据,用于同步电池版本数据
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
void BMS_VersionInfo(void)//电池版本信息
|
||
{
|
||
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;
|
||
//当前充电电量
|
||
|
||
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);
|
||
|
||
}
|
||
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : BMS_VersionInfo
|
||
* @ 功能说明: 设备定期向小程序上报数据,用于同步电池充电数据。
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
void BMS_ChargingDataInfo(void)//电池充电状态信息
|
||
{
|
||
|
||
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);
|
||
|
||
}
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : BMS_VersionInfo
|
||
* @ 功能说明: 单节电池温度信息
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
void bat_temp_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 = 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);
|
||
|
||
}
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : BMS_VersionInfo
|
||
* @ 功能说明: 单节电池电压信息
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
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);
|
||
|
||
}
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : BMS_VersionInfo
|
||
* @ 功能说明: 电池故障状态
|
||
* @ 参数 :
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
void bat_state_code(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 = 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)
|
||
{
|
||
//数据打包
|
||
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);
|
||
|
||
|
||
}
|
||
|
||
|
||
/**********************************************************************
|
||
* @ 函数名 : UpdataDebugInfoToServer
|
||
* @ 功能说明: 调试信息报文
|
||
* @ 参数 : data数据 len字节
|
||
* @ 返回值 : 无
|
||
********************************************************************/
|
||
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
|
||
|
||
|
||
|
||
|
||
|
||
|