1408 lines
34 KiB
C
1408 lines
34 KiB
C
/**
|
||
******************************************************************************
|
||
* @file MBO26A.c
|
||
* @author
|
||
* @version
|
||
* @date
|
||
* @brief
|
||
******************************************************************************
|
||
* @attention
|
||
*
|
||
*
|
||
******************************************************************************
|
||
*/
|
||
|
||
/* Includes ------------------------------------------------------------------*/
|
||
#include "stm32f10x.h"
|
||
#include "global.h"
|
||
#include "string.h"
|
||
#include <stdarg.h>
|
||
#include <stdio.h>
|
||
|
||
|
||
//固定值
|
||
const char* Status[2] = {"false", "true"}; //0对应false, 1对应true
|
||
|
||
//在global.c赋值,或在被写入后更新
|
||
char BMS_SN[10]; //9Byte
|
||
char PACK_SN[16]; //1~15Byte
|
||
char FirmwareVersion[11];//"4.00.00.00" 7~10Byte
|
||
char HardwareVersion[6]; //"6.3.L" 5Byte
|
||
char ScreenVersion[6]; //"03513" 5Byte
|
||
|
||
|
||
//读写参数功能相关
|
||
char params_str[600]; //原始数据字符串
|
||
|
||
const char* putSrvc_reply_namestr; //写服务的名字字符串
|
||
const char* putSrvc_reply_str; //写服务的字符串格式
|
||
uint8_t putSrvc_reply_flg; //写服务回复标志 接收到ID号,就要以ID号的格式返回
|
||
|
||
const char* setPara_reply_name[SETPARA_SUM]; //写属性的名字字符串
|
||
uint16_t setPara_reply_temp[SETPARA_SUM]; //写属性的数值
|
||
uint8_t setPara_reply_pm[SETPARA_SUM]; //数值的正负 0:正数 1:负数 2:true 3:false
|
||
uint8_t setPara_reply_flg; //写属性回复标志 1:回复成功 0xAA:设备无所有要写的属性 0xBB:值不在范围,设备拒绝执行
|
||
uint8_t setPara_reply_num; //写属性回复个数
|
||
|
||
const char* getPara_reply_name[GETPARA_SUM]; //读属性的名字字符串
|
||
uint16_t getPara_reply_temp[GETPARA_SUM]; //读属性的数值
|
||
uint8_t getPara_reply_pm[GETPARA_SUM]; //数值的正负 0:正数 1:负数 2:true 3:false
|
||
uint8_t getPara_reply_flg; //读属性回复标志 1:回复成功 0xAA:设备无所有要读的属性
|
||
uint8_t getPara_reply_num; //读属性回复个数
|
||
|
||
uint8_t protocol_reply_flg; //协议在回复内容里的标志
|
||
uint8_t protocol_reply_index; //协议在回复内容里的位置
|
||
|
||
|
||
#if BLE_Conn
|
||
//通用定义
|
||
#define PIN_BLE_RST GPIO_Pin_12 //PC12 0:不做处理 1:蓝牙复位
|
||
|
||
#define BLE_UART UART4
|
||
#define BLE_Send BLE_printf
|
||
|
||
#define BLE_MON_CNT 6000 //6000*10ms = 60s
|
||
#define BLE_RX_BUF_LEN 256 //接收的最大长度,实际244Byte
|
||
#define BLE_TX_BUF_LEN 256 //发送的最大长度,实际244Byte
|
||
#define BLE_ORDER_LEN 256 //回复指令的缓冲区的最大长度
|
||
|
||
#define SETPARA_SUM 34 //可写参数总个数
|
||
#define GETPARA_SUM 34 //可读参数总个数
|
||
|
||
char BLE_Rx_Buf[BLE_RX_BUF_LEN];
|
||
char BLE_Tx_Buf[BLE_TX_BUF_LEN];
|
||
char BLE_buffer[BLE_ORDER_LEN];
|
||
|
||
uint16_t BLE_Rx_BufIndex;
|
||
uint16_t BLE_Moni_Count;
|
||
|
||
|
||
//状态/保护/报警的字符串:false/true
|
||
//固定发:
|
||
//状态
|
||
const char* BLE_ChargeStatus_str;
|
||
const char* BLE_DischargeStatus_str;
|
||
const char* BLE_PreChargeStatus_str;
|
||
const char* BLE_ChgMosStatus_str;
|
||
const char* BLE_DsgMosStatus_str;
|
||
const char* BLE_PchgMosStatus_str;
|
||
const char* BLE_ChgLimitStatus_str;
|
||
const char* BLE_BalanceStatus_str;
|
||
//出现才发:
|
||
uint8_t BLE_SendFlag; //bit0:发特殊状态 bit1:发保护 bit2:发报警
|
||
uint8_t BLE_SendFlag_old; //已发出则对应bit置1
|
||
//特殊状态
|
||
uint8_t BLE_SendStatus[9]; //出现则赋值1,否则赋值0
|
||
//保护
|
||
uint8_t BLE_SendProtect_Vol[6];
|
||
uint8_t BLE_SendProtect_Cur[5];
|
||
uint8_t BLE_SendProtect_Temp[12];
|
||
//报警
|
||
uint8_t BLE_SendWarning_Vol[4];
|
||
uint8_t BLE_SendWarning_Cur[2];
|
||
uint8_t BLE_SendWarning_Temp[12];
|
||
|
||
|
||
uint8_t BLE_READYflag; //蓝牙模块准备就绪的标志
|
||
uint8_t BLE_READYcount; //开机后最久等待3s,一直不收到也READY
|
||
|
||
uint8_t BLE_Onflag; //蓝牙成功连接的标志
|
||
|
||
uint8_t BLE_status; //执行内容 0:持续上报[属性]
|
||
uint8_t BLE_step; //执行步骤 0:第一部分 1:第二部分 ……
|
||
|
||
uint8_t BLE_Check_Flag; //蓝牙无设备连接时,在主程序里定时检查蓝牙
|
||
|
||
uint8_t BLE_RST_Flag; //蓝牙无响应的重启标志
|
||
uint8_t BLE_RST_count; //重启的等待计数
|
||
|
||
|
||
//BLE专用的printf函数
|
||
int BLE_printf(const char *fmt, ...)
|
||
{
|
||
va_list args;
|
||
va_start(args, fmt);
|
||
int len = vsnprintf(BLE_Tx_Buf, sizeof(BLE_Tx_Buf), fmt, args);
|
||
va_end(args);
|
||
|
||
for(int i = 0; i < len; i++)
|
||
{
|
||
while(!(UART4->SR & USART_SR_TXE)); // 等待发送完成
|
||
UART4->DR = BLE_Tx_Buf[i];
|
||
}
|
||
|
||
return len;
|
||
}
|
||
|
||
//相关引脚初始化
|
||
void BLE_IO_Init(void)
|
||
{
|
||
//初始化引脚
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE);
|
||
|
||
GPIO_InitStructure.GPIO_Pin = PIN_BLE_RST; //蓝牙复位控制引脚
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||
|
||
GPIO_ResetBits(GPIOC, PIN_BLE_RST); //蓝牙复位控制脚,默认关闭状态
|
||
}
|
||
|
||
//开机
|
||
void BLE_Open(void)
|
||
{
|
||
//预留
|
||
}
|
||
|
||
//关机
|
||
void BLE_Close(void)
|
||
{
|
||
//预留
|
||
}
|
||
|
||
//复位
|
||
void BLE_Reset(void)
|
||
{
|
||
//发软件重启AT指令
|
||
BLE_Send("AT+REBOOT=1\r\n");
|
||
|
||
BLE_READYflag = 1;
|
||
BLE_READYcount = 0;
|
||
}
|
||
|
||
//清空标志
|
||
void BLE_ClearFlg(void)
|
||
{
|
||
BLE_Onflag = 0;
|
||
|
||
BLE_status = 0;
|
||
BLE_step = 0;
|
||
|
||
setPara_reply_flg = 0;
|
||
getPara_reply_flg = 0;
|
||
}
|
||
|
||
//清空接收缓冲区
|
||
void BLE_ClearBuf(void)
|
||
{
|
||
BLE_Rx_BufIndex = 0;
|
||
memset(BLE_Rx_Buf, 0, BLE_RX_BUF_LEN);
|
||
}
|
||
|
||
//初始化通讯
|
||
void BLE_Init(void)
|
||
{
|
||
BLE_ClearFlg();
|
||
BLE_ClearBuf();
|
||
|
||
BLE_Moni_Count = BLE_MON_CNT;
|
||
if(BLE_READYflag == 0)
|
||
{
|
||
uf_UART4_Init(9600);
|
||
}
|
||
else
|
||
{
|
||
uf_UART4_Init(115200);
|
||
}
|
||
}
|
||
|
||
//一定时间没有连接任何设备,初始化通讯,并再次更新名称
|
||
void BLE_TIM_Moni(void)
|
||
{
|
||
if(BLE_Onflag == 0) //未连接蓝牙
|
||
{
|
||
BLE_Moni_Count--;
|
||
if(BLE_Moni_Count == 0)
|
||
{
|
||
BLE_Init();
|
||
BLE_Check_Flag = 1;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
BLE_Moni_Count = BLE_MON_CNT;
|
||
}
|
||
}
|
||
|
||
//设置蓝牙模块波特率
|
||
void BLE_SetBaud( u32 bound )
|
||
{
|
||
BLE_Send("AT+UART=5\r\n");
|
||
delay_ms(50);
|
||
uf_UART4_Init(115200);
|
||
}
|
||
|
||
//检测蓝牙名称是否和SN号一致,不一致则修改
|
||
void BLE_CheckName(void)
|
||
{
|
||
BLE_ClearBuf();
|
||
|
||
//询问蓝牙名称
|
||
BLE_Send("AT+NAME?\r\n");
|
||
delay_ms(100);
|
||
|
||
//收到回复
|
||
if(strstr(BLE_Rx_Buf, "+NAME:"))
|
||
{
|
||
//名称有误,发送修改名称的AT指令
|
||
if((strstr(BLE_Rx_Buf, "Ricn_") == 0) || (strstr(BLE_Rx_Buf, BMS_SN) == 0))
|
||
{
|
||
BLE_ClearBuf();
|
||
|
||
//BLE_Send("AT+NAME=Ricn_052200021");
|
||
BLE_Send("AT+NAME=Ricn_%s\r\n", BMS_SN);
|
||
delay_ms(50);
|
||
|
||
BLE_Reset(); //重启以启用该名称
|
||
}
|
||
}
|
||
else
|
||
{
|
||
BLE_RST_count++;
|
||
if(BLE_RST_count > 3) //3min
|
||
{
|
||
BLE_RST_Flag = 1;
|
||
}
|
||
}
|
||
}
|
||
|
||
//写SN号时,直接同步修改蓝牙名称
|
||
void BLE_WriteName(void)
|
||
{
|
||
//检查一遍名称,不同就执行写入
|
||
BLE_CheckName();
|
||
}
|
||
|
||
//蓝牙写指令
|
||
void BLE_PUTSRVC(void)
|
||
{
|
||
if(strstr(BLE_Rx_Buf, "\"data\":{") && strstr(BLE_Rx_Buf, "}}"))
|
||
{
|
||
uint8_t len = 0; //字符串长度
|
||
|
||
//获取原始数据,包括'{''}'
|
||
const char* paramsKey = "\"data\":";
|
||
char* paramsStart = strstr(BLE_Rx_Buf, paramsKey); paramsStart += strlen(paramsKey);
|
||
char* paramsEnd = strchr(paramsStart, '}');
|
||
len = paramsEnd - paramsStart;
|
||
if(len > sizeof(params_str)-2) //防溢出
|
||
{
|
||
len = sizeof(params_str)-2;
|
||
}
|
||
strncpy(params_str, paramsStart, len);
|
||
params_str[len] = '}';
|
||
params_str[len+1] = '\0';
|
||
|
||
|
||
if(strstr(params_str, "\"PutForceOn\""))
|
||
{
|
||
putSrvc_reply_flg = 1;
|
||
putSrvc_reply_namestr = "\"PutForceOn\"";
|
||
|
||
if(strstr(params_str, "\"open\""))
|
||
{
|
||
//当前总体和单体欠压的报警/保护位都置0
|
||
bmsMem.bStatus1 &= ~0x0202;
|
||
bmsMem.bStatus3 &= ~0x0A00;
|
||
//状态置1,更新计时起点
|
||
bmsMem.balanceStatus |= 0x0020;
|
||
if(LSEErrFlag!=1)
|
||
{
|
||
uvofftimecount = RTC_GetCounter();
|
||
uvofftime = 300;
|
||
}
|
||
else
|
||
{
|
||
uvoff_Moni_Count = UVOff_MON_CNT;
|
||
}
|
||
|
||
putSrvc_reply_str = "\"open\"";
|
||
}
|
||
else if(strstr(params_str, "\"close\""))
|
||
{
|
||
bmsMem.balanceStatus &= 0xffdf;
|
||
|
||
putSrvc_reply_str = "\"close\"";
|
||
}
|
||
else
|
||
{
|
||
putSrvc_reply_flg = 0xBB; //设备拒绝执行(内容有误)
|
||
}
|
||
}
|
||
else
|
||
{
|
||
putSrvc_reply_flg = 0xAA; //设备无该属性
|
||
}
|
||
}
|
||
else
|
||
{
|
||
putSrvc_reply_flg = 0xBB; //设备拒绝执行
|
||
}
|
||
}
|
||
|
||
//蓝牙写参数
|
||
void BLE_SETPARA(void)
|
||
{
|
||
if(strstr(BLE_Rx_Buf, "\"data\":{") && strstr(BLE_Rx_Buf, "}}"))
|
||
{
|
||
char para_str[6]; //0~65535 或 -32768~32767
|
||
uint8_t len = 0; //字符串长度
|
||
uint16_t temp; //无符号过程量
|
||
|
||
//获取原始数据,包括'{''}'
|
||
const char* paramsKey = "\"data\":";
|
||
char* paramsStart = strstr(BLE_Rx_Buf, paramsKey); paramsStart += strlen(paramsKey);
|
||
char* paramsEnd = strchr(paramsStart, '}');
|
||
len = paramsEnd - paramsStart;
|
||
if(len > sizeof(params_str)-2) //防溢出
|
||
{
|
||
len = sizeof(params_str)-2;
|
||
}
|
||
strncpy(params_str, paramsStart, len);
|
||
params_str[len] = '}';
|
||
params_str[len+1] = '\0';
|
||
|
||
|
||
//识别存在的参数,并给予对应值
|
||
setPara_reply_num = 0;
|
||
|
||
if(strstr(params_str, "\"Protocol\"")) //写协议
|
||
{
|
||
//获取参数值
|
||
len = GetStr("\"Protocol\":", ',', '}', params_str, para_str);
|
||
sscanf(para_str, "%hu", &temp);
|
||
|
||
//符合范围的放入
|
||
if(((int)temp >= 0) && (temp <= ProtocolSum) && (len > 0)) //0~38
|
||
{
|
||
protocol = temp;
|
||
|
||
EEPROM_WrMulByte(EE_PROTOCOL,&protocol);
|
||
delay_ms(5);
|
||
uf_CAN1_Init();//CAN的波特率更新
|
||
//SCR_DispProcotol(); //屏幕显示更新
|
||
|
||
protocol_reply_flg = 1;
|
||
protocol_reply_index = setPara_reply_num;
|
||
|
||
//准备回复
|
||
setPara_reply_name[setPara_reply_num] = "Protocol";
|
||
setPara_reply_temp[setPara_reply_num] = temp;
|
||
setPara_reply_num++;
|
||
}
|
||
else
|
||
{
|
||
setPara_reply_flg = 0xBB; //参数值超出范围,设备拒绝执行
|
||
}
|
||
}
|
||
|
||
if(setPara_reply_num > 0)
|
||
{
|
||
setPara_reply_flg = 1; //正常回复
|
||
}
|
||
else if(setPara_reply_flg != 0xBB) //无任何符合的值&不是因为参数不符合范围
|
||
{
|
||
setPara_reply_flg = 0xAA; //设备无该属性
|
||
}
|
||
}
|
||
else
|
||
{
|
||
setPara_reply_flg = 0xBB; //设备拒绝执行
|
||
}
|
||
}
|
||
|
||
//蓝牙读参数
|
||
void BLE_GETPARA(void)
|
||
{
|
||
if(strstr(BLE_Rx_Buf, "\"params\":[") && strstr(BLE_Rx_Buf, "]}"))
|
||
{
|
||
uint16_t len = 0; //字符串长度
|
||
|
||
//获取原始数据
|
||
const char* paramsKey = "\"params\":[";
|
||
char* paramsStart = strstr(BLE_Rx_Buf, paramsKey); paramsStart += strlen(paramsKey);
|
||
char* paramsEnd = strchr(paramsStart, ']');
|
||
len = paramsEnd - paramsStart;
|
||
if(len > sizeof(params_str)-1) //防溢出
|
||
{
|
||
len = sizeof(params_str)-1;
|
||
}
|
||
strncpy(params_str, paramsStart, len);
|
||
params_str[len] = '\0';
|
||
|
||
//识别存在的参数,并给予对应值
|
||
getPara_reply_num = 0;
|
||
|
||
if(strstr(params_str, "\"Protocol\"")) //读协议
|
||
{
|
||
protocol_reply_flg = 1;
|
||
protocol_reply_index = getPara_reply_num;
|
||
|
||
//准备回复
|
||
getPara_reply_name[getPara_reply_num] = "Protocol";
|
||
getPara_reply_temp[getPara_reply_num] = protocol;
|
||
getPara_reply_num++;
|
||
}
|
||
|
||
if(getPara_reply_num > 0)
|
||
{
|
||
getPara_reply_flg = 1; //回复
|
||
}
|
||
else //无任何符合的值
|
||
{
|
||
getPara_reply_flg = 0xAA; //设备无该属性
|
||
}
|
||
}
|
||
else
|
||
{
|
||
getPara_reply_flg = 0xBB; //设备拒绝执行
|
||
}
|
||
}
|
||
|
||
//接收数据,在串口中断执行
|
||
void BLE_IT_Receive(void)
|
||
{
|
||
uint8_t received_byte = USART_ReceiveData(BLE_UART);
|
||
|
||
if(BLE_Rx_BufIndex < BLE_RX_BUF_LEN - 1)
|
||
{
|
||
BLE_Rx_Buf[BLE_Rx_BufIndex] = received_byte;
|
||
BLE_Rx_BufIndex++;
|
||
}
|
||
else
|
||
{
|
||
BLE_ClearBuf();
|
||
}
|
||
}
|
||
|
||
//处理数据,接收报文识别后执行
|
||
//波特率115200
|
||
void BLE_IT_Update(void)
|
||
{
|
||
if(BLE_READYflag == 0)
|
||
{
|
||
if(strstr(BLE_Rx_Buf, "+READY")) //上电后,需收到+READY<CR><LF>后才能执行指令
|
||
{
|
||
BLE_READYcount = 0;
|
||
BLE_READYflag = 1;
|
||
|
||
BLE_SetBaud(115200); //设置蓝牙模块波特率
|
||
BLE_CheckName(); //检查蓝牙名称是否和SN号一致
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(strstr(BLE_Rx_Buf, "+CONNECTED")) //连上蓝牙
|
||
{
|
||
BLE_ClearBuf();
|
||
|
||
BLE_Onflag = 1;
|
||
BLE_status = 0; //从上报[属性]开始
|
||
}
|
||
if(strstr(BLE_Rx_Buf, "+DISCONN")) //断开蓝牙
|
||
{
|
||
BLE_ClearBuf();
|
||
|
||
BLE_Onflag = 0;
|
||
}
|
||
|
||
if(BLE_Onflag == 1)
|
||
{
|
||
if(strstr(BLE_Rx_Buf,"\"dataType\":\"0x03\"")) //收到"0x03"开始解析数据 写指令
|
||
{
|
||
BLE_status = 1;
|
||
BLE_PUTSRVC();
|
||
|
||
BLE_ClearBuf();
|
||
}
|
||
else if(strstr(BLE_Rx_Buf,"\"dataType\":\"0x04\"")) //收到"0x04"开始解析数据 写参数
|
||
{
|
||
BLE_status = 2;
|
||
BLE_SETPARA();
|
||
|
||
BLE_ClearBuf();
|
||
}
|
||
else if(strstr(BLE_Rx_Buf,"\"dataType\":\"0x05\"")) //收到"0x05"开始解析数据 读参数
|
||
{
|
||
BLE_status = 3;
|
||
BLE_GETPARA();
|
||
|
||
BLE_ClearBuf();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//根据当前已知信息,选择接下来要执行的指令,0.1s执行1次
|
||
void BLE_IQ_Update(void)
|
||
{
|
||
if(BLE_READYflag == 0)
|
||
{
|
||
BLE_READYcount++;
|
||
if(BLE_READYcount > 3*20) //延时判断3s
|
||
{
|
||
BLE_READYcount = 0;
|
||
BLE_READYflag = 1;
|
||
|
||
BLE_SetBaud(115200); //设置蓝牙模块波特率
|
||
BLE_CheckName(); //检查蓝牙名称是否和SN号一致
|
||
}
|
||
}
|
||
else if(BLE_Onflag == 1) //已连接
|
||
{
|
||
if(BLE_status == 0) //正常上报采集数据
|
||
{
|
||
BLE_step++;
|
||
|
||
if(BLE_step == 3) //状态:固定发送
|
||
{
|
||
//更新true/false
|
||
BLE_ChargeStatus_str = Status[ChargeStatus];
|
||
BLE_DischargeStatus_str = Status[DischargeStatus];
|
||
BLE_PreChargeStatus_str = Status[PreChargeStatus];
|
||
BLE_ChgMosStatus_str = Status[ChgMosStatus];
|
||
BLE_DsgMosStatus_str = Status[DsgMosStatus];
|
||
BLE_PchgMosStatus_str = Status[PchgMosStatus];
|
||
BLE_ChgLimitStatus_str = Status[ChgLimitStatus];
|
||
BLE_BalanceStatus_str = Status[BalanceStatus];
|
||
}
|
||
else if(BLE_step == 8) //特殊状态:当前存在任一状态才发送
|
||
{
|
||
if(((bmsMem.bStatus2 & 0x00C0) != 0) || ((bmsMem.temperaStatus & 0x0080) != 0) || ((bmsMem.balanceStatus & 0x07E0) != 0))
|
||
{
|
||
BLE_SendFlag |= BIT0;
|
||
|
||
//更新1:true/0:false
|
||
BLE_SendStatus[0] = LockOCC;
|
||
BLE_SendStatus[1] = LockOCD1;
|
||
BLE_SendStatus[2] = LockOCD2;
|
||
BLE_SendStatus[3] = LockSP;
|
||
BLE_SendStatus[4] = LockSC;
|
||
BLE_SendStatus[5] = ChgMosFault;
|
||
BLE_SendStatus[6] = DsgMosFault;
|
||
BLE_SendStatus[7] = DOStatus;
|
||
BLE_SendStatus[8] = ForceOffUV;
|
||
}
|
||
else
|
||
{
|
||
BLE_SendFlag &= ~BIT0;
|
||
}
|
||
|
||
//if(((bmsMem.bStatus1 & 0x077f) != 0) || ((bmsMem.bStatus2 & 0x00ff) !=0) || ((bmsMem.bStatus3 & 0x0008) !=0) || ((bmsMem.temperaStatus & 0x0f7f) !=0))
|
||
if(((bmsMem.bStatus1 & 0x077f) != 0) || ((bmsMem.bStatus2 & 0x00f0) !=0) || ((bmsMem.bStatus3 & 0x0008) !=0) || ((bmsMem.temperaStatus & 0x0070) !=0))
|
||
{
|
||
BLE_SendFlag |= BIT1;
|
||
|
||
//更新1:true/0:false
|
||
BLE_SendProtect_Vol[0] = PackOV;
|
||
BLE_SendProtect_Vol[1] = PackUV;
|
||
BLE_SendProtect_Vol[2] = CellOV;
|
||
BLE_SendProtect_Vol[3] = CellUV;
|
||
BLE_SendProtect_Vol[4] = PF;
|
||
BLE_SendProtect_Vol[5] = L0V;
|
||
|
||
BLE_SendProtect_Cur[0] = OCC;
|
||
BLE_SendProtect_Cur[1] = OCD1;
|
||
BLE_SendProtect_Cur[2] = OCD2;
|
||
BLE_SendProtect_Cur[3] = SP;
|
||
BLE_SendProtect_Cur[4] = SC;
|
||
}
|
||
else
|
||
{
|
||
BLE_SendFlag &= ~BIT1;
|
||
}
|
||
|
||
if(((bmsMem.bStatus2 & 0x000f) !=0) || ((bmsMem.temperaStatus & 0x0f0f) !=0))
|
||
{
|
||
BLE_SendFlag |= BIT2;
|
||
|
||
//更新1:true/0:false
|
||
BLE_SendProtect_Temp[0] = McuOTC;
|
||
BLE_SendProtect_Temp[1] = McuOTD;
|
||
BLE_SendProtect_Temp[2] = McuUTC;
|
||
BLE_SendProtect_Temp[3] = McuUTD;
|
||
BLE_SendProtect_Temp[4] = AmbientOTC;
|
||
BLE_SendProtect_Temp[5] = AmbientOTD;
|
||
BLE_SendProtect_Temp[6] = AmbientUTC;
|
||
BLE_SendProtect_Temp[7] = AmbientUTD;
|
||
BLE_SendProtect_Temp[8] = MosOTC;
|
||
BLE_SendProtect_Temp[9] = MosOTD;
|
||
BLE_SendProtect_Temp[10] = MosUTC;
|
||
BLE_SendProtect_Temp[11] = MosUTD;
|
||
}
|
||
else
|
||
{
|
||
BLE_SendFlag &= ~BIT2;
|
||
}
|
||
|
||
//if(((bmsMem.bStatus2 & 0xff00) !=0) || ((bmsMem.bStatus3 & 0x3f00) !=0) || ((bmsMem.temperaStatus & 0xf000) !=0))
|
||
if((bmsMem.bStatus3 & 0x3f00) !=0)
|
||
{
|
||
BLE_SendFlag |= BIT3;
|
||
|
||
//更新1:true/0:false
|
||
BLE_SendWarning_Vol[0] = PackOVWarning;
|
||
BLE_SendWarning_Vol[1] = PackUVWarning;
|
||
BLE_SendWarning_Vol[2] = CellOVWarning;
|
||
BLE_SendWarning_Vol[3] = CellUVWarning;
|
||
|
||
BLE_SendWarning_Cur[0] = OCCWarning;
|
||
BLE_SendWarning_Cur[1] = OCDWarning;
|
||
}
|
||
else
|
||
{
|
||
BLE_SendFlag &= ~BIT3;
|
||
}
|
||
|
||
if(((bmsMem.bStatus2 & 0xff00) !=0) || ((bmsMem.temperaStatus & 0xf000) !=0))
|
||
{
|
||
BLE_SendFlag |= BIT4;
|
||
|
||
//更新1:true/0:false
|
||
BLE_SendWarning_Temp[0] = McuOTCWarning;
|
||
BLE_SendWarning_Temp[1] = McuOTDWarning;
|
||
BLE_SendWarning_Temp[2] = McuUTCWarning;
|
||
BLE_SendWarning_Temp[3] = McuUTDWarning;
|
||
BLE_SendWarning_Temp[4] = AmbientOTCWarning;
|
||
BLE_SendWarning_Temp[5] = AmbientOTDWarning;
|
||
BLE_SendWarning_Temp[6] = AmbientUTCWarning;
|
||
BLE_SendWarning_Temp[7] = AmbientUTDWarning;
|
||
BLE_SendWarning_Temp[8] = MosOTCWarning;
|
||
BLE_SendWarning_Temp[9] = MosOTDWarning;
|
||
BLE_SendWarning_Temp[10] = MosUTCWarning;
|
||
BLE_SendWarning_Temp[11] = MosUTDWarning;
|
||
}
|
||
else
|
||
{
|
||
BLE_SendFlag &= ~BIT4;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//该函数用于发送报文,0.1s执行1次
|
||
void BLE_IQ_Transmit(void)
|
||
{
|
||
// BLE_Rx_BufIndex = 0;
|
||
// memset(BLE_Rx_Buf, 0, BLE_RX_BUF_LEN); //填入前先清空
|
||
// memset(BLE_Tx_Buf, 0, BLE_TX_BUF_LEN);
|
||
|
||
/*未连接,定时检查*/
|
||
if(BLE_Onflag == 0)
|
||
{
|
||
//定时询问蓝牙名称
|
||
if(BLE_Check_Flag == 1)
|
||
{
|
||
BLE_Check_Flag = 0;
|
||
BLE_CheckName();
|
||
}
|
||
//询问持续无回复,尝试重启
|
||
else if(BLE_RST_Flag == 1)
|
||
{
|
||
BLE_RST_Flag = 0;
|
||
BLE_Reset();
|
||
}
|
||
}
|
||
/*连接上了才会传数据*/
|
||
else
|
||
{
|
||
/*定时上报[属性],每段不超过512字节*/
|
||
if(BLE_status == 0)
|
||
{
|
||
if(BLE_step == 1)
|
||
{
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//第一帧
|
||
//开头 25
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x01\",");
|
||
BLE_Send("\"data\":");
|
||
//内容 130
|
||
BLE_Send("{"); //1
|
||
BLE_Send("\"BmsSN\":\"%s\",", BMS_SN); //5+4 + 9+2
|
||
BLE_Send("\"PackSN\":\"%s\",", PACK_SN); //6+4 + 15+2
|
||
if(ScreenVersion[0] == 0)
|
||
{
|
||
BLE_Send("\"FirmwareVersion\":\"%s\",", FirmwareVersion); //15+4 + 11+2
|
||
BLE_Send("\"HardwareVersion\":\"%s\"}", HardwareVersion); //15+4 + 5+2
|
||
}
|
||
else
|
||
{
|
||
BLE_Send("\"FirmwareVersion\":\"%s\",", FirmwareVersion); //15+4 + 11+2
|
||
BLE_Send("\"HardwareVersion\":\"%s\",", HardwareVersion); //15+4 + 5+2
|
||
BLE_Send("\"ScreenVersion\":\"%s\"}", ScreenVersion); //13+4 + 5+2
|
||
}
|
||
//结尾 1
|
||
BLE_Send("}");
|
||
}
|
||
else if(BLE_step == 2)
|
||
{
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//第二帧
|
||
//开头 25
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x01\",");
|
||
BLE_Send("\"data\":");
|
||
//内容 167
|
||
BLE_Send("{"); //1
|
||
BLE_Send("\"PackVol\":%u,", bmsMem.packVoltage); //7+4 + 10
|
||
BLE_Send("\"PackCur\":%d,", bmsMem.packCurrent); //7+4 + 10
|
||
BLE_Send("\"VolMax\":%d,", cellVoltageMax); //6+4 + 5
|
||
BLE_Send("\"VolMin\":%d,", cellVoltageMin); //6+4 + 5
|
||
BLE_Send("\"VolMaxIndex\":%u,", bmsMem.cellVoltageMaxIndex); //11+4 + 2
|
||
BLE_Send("\"VolMinIndex\":%u,", bmsMem.cellVoltageMinIndex); //11+4 + 2
|
||
BLE_Send("\"FCC\":%u,", bmsMem.ncc/3600); //3+4 + 7
|
||
BLE_Send("\"RCC\":%u,", bmsMem.rcc/3600); //3+4 + 7
|
||
BLE_Send("\"SOC\":%u,", bmsMem.soc); //3+4 + 3
|
||
BLE_Send("\"SOH\":%u,", bmsMem.soh); //3+4 + 3
|
||
BLE_Send("\"CYC\":%u}", bmsMem.cycleCount); //3+4 + 5
|
||
//结尾 1
|
||
BLE_Send("}");
|
||
}
|
||
else if(BLE_step == 3)
|
||
{
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//第四帧
|
||
//开头 25
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x01\",");
|
||
BLE_Send("\"data\":");
|
||
//内容 137
|
||
BLE_Send("{"); //1
|
||
BLE_Send("\"CellVol1\":%d,", cellVol[0]); //8+4 + 5
|
||
BLE_Send("\"CellVol2\":%d,", cellVol[1]); //8+4 + 5
|
||
BLE_Send("\"CellVol3\":%d,", cellVol[2]); //8+4 + 5
|
||
BLE_Send("\"CellVol4\":%d,", cellVol[3]); //8+4 + 5
|
||
BLE_Send("\"CellVol5\":%d,", cellVol[4]); //8+4 + 5
|
||
BLE_Send("\"CellVol6\":%d,", cellVol[5]); //8+4 + 5
|
||
BLE_Send("\"CellVol7\":%d,", cellVol[6]); //8+4 + 5
|
||
BLE_Send("\"CellVol8\":%d}", cellVol[7]); //8+4 + 5
|
||
//结尾 1
|
||
BLE_Send("}");
|
||
}
|
||
else if(BLE_step == 4)
|
||
{
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//第五帧
|
||
//开头 25
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x01\",");
|
||
BLE_Send("\"data\":");
|
||
//内容 144
|
||
BLE_Send("{"); //1
|
||
BLE_Send("\"CellVol9\":%d,", cellVol[8]); //8+4 + 5
|
||
BLE_Send("\"CellVol10\":%d,", cellVol[9]); //9+4 + 5
|
||
BLE_Send("\"CellVol11\":%d,", cellVol[10]); //9+4 + 5
|
||
BLE_Send("\"CellVol12\":%d,", cellVol[11]); //9+4 + 5
|
||
BLE_Send("\"CellVol13\":%d,", cellVol[12]); //9+4 + 5
|
||
BLE_Send("\"CellVol14\":%d,", cellVol[13]); //9+4 + 5
|
||
BLE_Send("\"CellVol15\":%d,", cellVol[14]); //9+4 + 5
|
||
BLE_Send("\"CellVol16\":%d}", cellVol[15]); //9+4 + 5
|
||
//结尾 1
|
||
BLE_Send("}");
|
||
}
|
||
else if(BLE_step == 5)
|
||
{
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//第五帧
|
||
//开头 25
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x01\",");
|
||
BLE_Send("\"data\":");
|
||
//内容 73
|
||
BLE_Send("{"); //1
|
||
BLE_Send("\"CellVol17\":%d,", cellVol[16]); //9+4 + 5
|
||
BLE_Send("\"CellVol18\":%d,", cellVol[17]); //9+4 + 5
|
||
BLE_Send("\"CellVol19\":%d,", cellVol[18]); //9+4 + 5
|
||
BLE_Send("\"CellVol20\":%d}", cellVol[19]); //9+4 + 5
|
||
//结尾 1
|
||
BLE_Send("}");
|
||
}
|
||
else if(BLE_step == 6)
|
||
{
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//第六帧
|
||
//开头 25
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x01\",");
|
||
BLE_Send("\"data\":");
|
||
//内容 111
|
||
BLE_Send("{"); //1
|
||
BLE_Send("\"MosT1\":%.1f,", (float)(bmsMem.afe_T1-2731)/10); //5+4 + 5
|
||
BLE_Send("\"MosT2\":%.1f,", (float)(bmsMem.afe_T2-2731)/10); //5+4 + 5
|
||
BLE_Send("\"AmbientT\":%.1f,", (float)(bmsMem.afe_T3-2731)/10); //8+4 + 5
|
||
BLE_Send("\"BatteryT1\":%.1f,", (float)(bmsMem.mcu_T1-2731)/10); //9+4 + 5
|
||
BLE_Send("\"BatteryT2\":%.1f,", (float)(bmsMem.mcu_T2-2731)/10); //9+4 + 5
|
||
BLE_Send("\"BatteryT3\":%.1f,", (float)(bmsMem.mcu_T3-2731)/10); //9+4 + 5
|
||
BLE_Send("\"BatteryT4\":%.1f}", (float)(bmsMem.mcu_T4-2731)/10); //9+4 + 5
|
||
//结尾 1
|
||
BLE_Send("}");
|
||
}
|
||
else if(BLE_step == 7)
|
||
{
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//第三帧
|
||
//开头 25
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x01\",");
|
||
BLE_Send("\"data\":");
|
||
//内容 179
|
||
BLE_Send("{"); //1
|
||
BLE_Send("\"ChargeStatus\":%s,", BLE_ChargeStatus_str); //12+4 + 5
|
||
BLE_Send("\"DischargeStatus\":%s,", BLE_DischargeStatus_str); //15+4 + 5
|
||
BLE_Send("\"PreChargeStatus\":%s,", BLE_PreChargeStatus_str); //15+4 + 5
|
||
BLE_Send("\"ChgMosStatus\":%s,", BLE_ChgMosStatus_str); //12+4 + 5
|
||
BLE_Send("\"DsgMosStatus\":%s,", BLE_DsgMosStatus_str); //12+4 + 5
|
||
BLE_Send("\"PchgMosStatus\":%s,", BLE_PchgMosStatus_str); //13+4 + 5
|
||
BLE_Send("\"ChgLimitStatus\":%s,", BLE_ChgLimitStatus_str); //14+4 + 5
|
||
BLE_Send("\"BalanceStatus\":%s}", BLE_BalanceStatus_str); //13+4 + 5
|
||
//结尾 1
|
||
BLE_Send("}");
|
||
}
|
||
else if((BLE_step >= 8) && (BLE_step <= 21))
|
||
{
|
||
if(((BLE_SendFlag & BIT0) != 0) && ((BLE_SendFlag_old & BIT0) == 0))
|
||
{
|
||
uint8_t firstflag = 0; //当出现过第1个上传状态后置1
|
||
|
||
BLE_SendFlag_old |= BIT0;
|
||
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//存在才发,第一帧
|
||
//开头
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x01\",");
|
||
BLE_Send("\"data\":");
|
||
//内容
|
||
BLE_Send("{");
|
||
//特殊状态
|
||
if(BLE_SendStatus[0] != 0)
|
||
{
|
||
BLE_Send("\"LockOCC\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendStatus[1] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"LockOCD1\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendStatus[2] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"LockOCD2\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendStatus[3] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"LockSP\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendStatus[4] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"LockSC\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendStatus[5] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"ChgMosFault\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendStatus[6] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"DsgMosFault\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendStatus[7] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"DOStatus\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendStatus[8] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"ForceOffUV\":true");
|
||
firstflag = 1;
|
||
}
|
||
BLE_Send("}");
|
||
//结尾
|
||
BLE_Send("}");
|
||
}
|
||
else if(((BLE_SendFlag & BIT1) != 0) && ((BLE_SendFlag_old & BIT1) == 0))
|
||
{
|
||
uint8_t firstflag = 0; //当出现过第1个上传状态后置1
|
||
|
||
BLE_SendFlag_old |= BIT1;
|
||
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//存在才发,第三帧
|
||
//开头
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x01\",");
|
||
BLE_Send("\"data\":");
|
||
//内容
|
||
BLE_Send("{");
|
||
//电压保护
|
||
if(BLE_SendProtect_Vol[0] != 0)
|
||
{
|
||
BLE_Send("\"PackOV\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Vol[1] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"PackUV\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Vol[2] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"CellOV\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Vol[3] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"CellUV\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Vol[4] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"PF\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Vol[5] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"L0V\":true");
|
||
firstflag = 1;
|
||
}
|
||
//电流保护
|
||
if(BLE_SendProtect_Cur[0] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"OCC\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Cur[1] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"OCD1\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Cur[2] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"OCD2\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Cur[3] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"SP\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Cur[4] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"SC\":true");
|
||
firstflag = 1;
|
||
}
|
||
BLE_Send("}");
|
||
//结尾
|
||
BLE_Send("}");
|
||
}
|
||
else if(((BLE_SendFlag & BIT2) != 0) && ((BLE_SendFlag_old & BIT2) == 0))
|
||
{
|
||
uint8_t firstflag = 0; //当出现过第1个上传状态后置1
|
||
|
||
BLE_SendFlag_old |= BIT2;
|
||
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//存在才发,第三帧
|
||
//开头
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x01\",");
|
||
BLE_Send("\"data\":");
|
||
//内容
|
||
BLE_Send("{");
|
||
//温度保护
|
||
if(BLE_SendProtect_Temp[0] != 0)
|
||
{
|
||
BLE_Send("\"McuOTC\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Temp[1] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"McuOTD\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Temp[2] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"McuUTC\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Temp[3] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"McuUTD\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Temp[4] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"AmbientOTC\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Temp[5] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"AmbientOTD\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Temp[6] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"AmbientUTC\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Temp[7] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"AmbientUTD\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Temp[8] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"MosOTC\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendProtect_Temp[9] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"MosOTD\":true");
|
||
firstflag = 1;
|
||
}
|
||
//if(BLE_SendProtect_Temp[10] != 0)
|
||
//{
|
||
// if(firstflag == 1) BLE_Send(",");
|
||
// BLE_Send("\"MosUTC\":true");
|
||
// firstflag = 1;
|
||
//}
|
||
//if(BLE_SendProtect_Temp[11] != 0)
|
||
//{
|
||
// if(firstflag == 1) BLE_Send(",");
|
||
// BLE_Send("\"MosUTD\":true");
|
||
// firstflag = 1;
|
||
//}
|
||
BLE_Send("}");
|
||
//结尾
|
||
BLE_Send("}");
|
||
}
|
||
else if(((BLE_SendFlag & BIT3) != 0) && ((BLE_SendFlag_old & BIT3) == 0))
|
||
{
|
||
uint8_t firstflag = 0; //当出现过第1个上传状态后置1
|
||
|
||
BLE_SendFlag_old |= BIT3;
|
||
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//存在才发,第五帧
|
||
//开头
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x01\",");
|
||
BLE_Send("\"data\":");
|
||
//内容
|
||
BLE_Send("{");
|
||
//电压报警
|
||
if(BLE_SendWarning_Vol[0] != 0)
|
||
{
|
||
BLE_Send("\"PackOVWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Vol[1] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"PackUVWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Vol[2] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"CellOVWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Vol[3] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"CellUVWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
//电流报警
|
||
if(BLE_SendWarning_Cur[0] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"OCCWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Cur[1] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"OCDWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
BLE_Send("}");
|
||
//结尾
|
||
BLE_Send("}");
|
||
}
|
||
else if(((BLE_SendFlag & BIT4) != 0) && ((BLE_SendFlag_old & BIT4) == 0))
|
||
{
|
||
uint8_t firstflag = 0; //当出现过第1个上传状态后置1
|
||
|
||
BLE_SendFlag_old |= BIT4;
|
||
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//存在才发,第五帧
|
||
//开头
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x01\",");
|
||
BLE_Send("\"data\":");
|
||
//内容
|
||
BLE_Send("{");
|
||
//温度报警
|
||
if(BLE_SendWarning_Temp[0] != 0)
|
||
{
|
||
BLE_Send("\"McuOTCWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Temp[1] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"McuOTDWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Temp[2] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"McuUTCWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Temp[3] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"McuUTDWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Temp[4] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"AmbientOTCWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Temp[5] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"AmbientOTDWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Temp[6] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"AmbientUTCWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Temp[7] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"AmbientUTDWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Temp[8] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"MosOTCWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
if(BLE_SendWarning_Temp[9] != 0)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"MosOTDWarning\":true");
|
||
firstflag = 1;
|
||
}
|
||
//if(BLE_SendWarning_Temp[10] != 0)
|
||
//{
|
||
// if(firstflag == 1) BLE_Send(",");
|
||
// BLE_Send("\"MosUTCWarning\":true");
|
||
// firstflag = 1;
|
||
//}
|
||
//if(BLE_SendWarning_Temp[11] != 0)
|
||
//{
|
||
// if(firstflag == 1) BLE_Send(",");
|
||
// BLE_Send("\"MosUTDWarning\":true");
|
||
// firstflag = 1;
|
||
//}
|
||
BLE_Send("}");
|
||
//结尾
|
||
BLE_Send("}");
|
||
}
|
||
}
|
||
|
||
//每0.05s发送一次,1s后从头开始
|
||
if(BLE_step >= 21)
|
||
{
|
||
BLE_step = 0;
|
||
BLE_SendFlag = 0; //可选输出项清零
|
||
BLE_SendFlag_old = 0; //下一次继续输出
|
||
}
|
||
}
|
||
else if(BLE_status == 1) //回复写指令操作
|
||
{
|
||
BLE_status = 0; //回复后恢复正常状态
|
||
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//开头
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x03\",");
|
||
//内容
|
||
if(putSrvc_reply_flg == 1) //正确
|
||
{
|
||
BLE_Send("\"code\":0,");
|
||
BLE_Send("\"data\":");
|
||
|
||
BLE_Send("{");
|
||
BLE_Send("%s:%s", putSrvc_reply_namestr, putSrvc_reply_str);
|
||
BLE_Send("}");
|
||
}
|
||
else if(putSrvc_reply_flg == 0xAA) //错误-设备无该属性
|
||
{
|
||
BLE_Send("\"code\":6411");
|
||
}
|
||
else if(putSrvc_reply_flg == 0xBB) //错误-设备拒绝执行
|
||
{
|
||
BLE_Send("\"code\":6405");
|
||
}
|
||
//结尾
|
||
BLE_Send("}");
|
||
}
|
||
else if(BLE_status == 2) //回复写数据操作
|
||
{
|
||
BLE_status = 0; //回复后恢复正常状态
|
||
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//开头
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x04\",");
|
||
//内容
|
||
if(setPara_reply_flg == 1) //正确
|
||
{
|
||
uint8_t i;
|
||
uint8_t firstflag = 0; //当出现过第1个上传状态后置1
|
||
|
||
BLE_Send("\"code\":0,");
|
||
BLE_Send("\"set_num\":%hu,", setPara_reply_num);
|
||
BLE_Send("\"data\":");
|
||
|
||
BLE_Send("{");
|
||
for(i=0;i<setPara_reply_num;i++)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"%s\":%hu", setPara_reply_name[i], setPara_reply_temp[i]);
|
||
firstflag = 1;
|
||
|
||
if((protocol_reply_flg == 1) && (i == protocol_reply_index)) //回复协议时,同步回复协议名称
|
||
{
|
||
protocol_reply_flg = 0;
|
||
BLE_Send(",");
|
||
BLE_Send("\"ProtocolName\":");
|
||
if(protocol == 0)
|
||
{
|
||
BLE_Send("null", protocolStrings[protocol-1]);
|
||
}
|
||
else
|
||
{
|
||
BLE_Send("\"%s\"", protocolStrings[protocol-1]);
|
||
}
|
||
}
|
||
}
|
||
BLE_Send("}");
|
||
}
|
||
else if(setPara_reply_flg == 0xAA) //错误-设备无该属性
|
||
{
|
||
BLE_Send("\"code\":6411");
|
||
}
|
||
else if(setPara_reply_flg == 0xBB) //错误-设备拒绝执行
|
||
{
|
||
BLE_Send("\"code\":6405");
|
||
}
|
||
//结尾
|
||
BLE_Send("}");
|
||
}
|
||
else if(BLE_status == 3) //回复读数据操作
|
||
{
|
||
BLE_status = 0; //回复后恢复正常状态
|
||
|
||
//上报内容 %u:unsigned int %d:int %s:char
|
||
//开头
|
||
BLE_Send("{");
|
||
BLE_Send("\"dataType\":\"0x05\",");
|
||
//内容
|
||
if(getPara_reply_flg == 1) //正确
|
||
{
|
||
uint8_t i;
|
||
uint8_t firstflag = 0; //当出现过第1个上传状态后置1
|
||
|
||
BLE_Send("\"code\":0,");
|
||
BLE_Send("\"get_num\":%hu,", getPara_reply_num);
|
||
BLE_Send("\"data\":");
|
||
|
||
BLE_Send("{");
|
||
for(i=0;i<getPara_reply_num;i++)
|
||
{
|
||
if(firstflag == 1) BLE_Send(",");
|
||
BLE_Send("\"%s\":%hu", getPara_reply_name[i], getPara_reply_temp[i]);
|
||
firstflag = 1;
|
||
|
||
if((protocol_reply_flg == 1) && (i == protocol_reply_index)) //回复协议时,同步回复协议名称
|
||
{
|
||
protocol_reply_flg = 0;
|
||
BLE_Send(",");
|
||
BLE_Send("\"ProtocolName\":");
|
||
if(protocol == 0)
|
||
{
|
||
BLE_Send("null", protocolStrings[protocol-1]);
|
||
}
|
||
else
|
||
{
|
||
BLE_Send("\"%s\"", protocolStrings[protocol-1]);
|
||
}
|
||
}
|
||
}
|
||
BLE_Send("}");
|
||
}
|
||
else if(getPara_reply_flg == 0xAA) //错误-设备无该属性
|
||
{
|
||
BLE_Send("\"code\":6411");
|
||
}
|
||
else if(getPara_reply_flg == 0xBB) //错误-设备拒绝执行
|
||
{
|
||
BLE_Send("\"code\":6405");
|
||
}
|
||
//结尾
|
||
BLE_Send("}");
|
||
}
|
||
}
|
||
}
|
||
#endif
|
||
|