Files
2026-08-25 17:30:40 +08:00

1005 lines
25 KiB
C

/**
******************************************************************************
* @file YiBang.c
* @author
* @version
* @date
* @brief
******************************************************************************
* @attention
*
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "global.h"
#include "string.h"
#include <stdarg.h>
#include <stdio.h>
#if WIFI_Conn
//通用定义
#define PIN_WIFI_RST GPIO_Pin_2 //PC2 0:不做处理 1:WIFI复位
#define WIFI_UART UART4
#define WIFI_Send WIFI_printf
#define WIFI_MON_CNT 6000 //6000*10ms = 60s
#define WIFI_RX_BUF_LEN 512 //接收的最大长度
#define WIFI_TX_BUF_LEN 128 //发送的最大长度
#define WIFI_ORDER_LEN 128 //回复指令的缓冲区的最大长度
char WIFI_Rx_Buf[WIFI_RX_BUF_LEN];
char WIFI_Tx_Buf[WIFI_TX_BUF_LEN];
char WIFI_buffer[WIFI_ORDER_LEN];
uint16_t WIFI_Rx_BufIndex;
uint16_t WIFI_Moni_Count;
//状态/保护/报警的字符串:false/true
//固定发:
//状态
const char* WIFI_ChargeStatus_str;
const char* WIFI_DischargeStatus_str;
const char* WIFI_PreChargeStatus_str;
const char* WIFI_ChgMosStatus_str;
const char* WIFI_DsgMosStatus_str;
const char* WIFI_PchgMosStatus_str;
const char* WIFI_ChgLimitStatus_str;
const char* WIFI_BalanceStatus_str;
//出现才发:
uint8_t WIFI_SendFlag; //bit0:发特殊状态 bit1:发保护 bit2:发报警
//特殊状态
uint8_t WIFI_SendStatus[9]; //出现则赋值1,否则赋值0
//保护
uint8_t WIFI_SendProtect_Vol[6];
uint8_t WIFI_SendProtect_Cur[5];
uint8_t WIFI_SendProtect_Temp[12];
//报警
uint8_t WIFI_SendWarning_Vol[4];
uint8_t WIFI_SendWarning_Cur[2];
uint8_t WIFI_SendWarning_Temp[12];
uint8_t WIFI_01_RxFlg; //WIFI收到请求采集数据的标志
uint8_t WIFI_04_RxFlg; //WIFI收到请求写参数的标志
uint8_t WIFI_05_RxFlg; //WIFI收到请求读参数的标志
uint8_t WIFI_01_TxStep; //执行步骤 0:第一部分 1:第二部分 ……
//WIFI专用的printf函数
int WIFI_printf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
int len = vsnprintf(WIFI_Tx_Buf, sizeof(WIFI_Tx_Buf), fmt, args);
va_end(args);
for(int i = 0; i < len; i++)
{
while(!(UART4->SR & USART_SR_TXE)); // 等待发送完成
UART4->DR = WIFI_Tx_Buf[i];
}
return len;
}
//相关引脚初始化
void WIFI_IO_Init(void)
{
//初始化引脚
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE);
GPIO_InitStructure.GPIO_Pin = PIN_WIFI_RST; //WIFI复位控制引脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_ResetBits(GPIOC, PIN_WIFI_RST); //WIFI复位控制脚,默认关闭状态
}
//开机
void WIFI_Open(void)
{
//预留
}
//关机
void WIFI_Close(void)
{
//预留
}
//复位
void WIFI_Reset(void)
{
// GPIO_ResetBits(GPIOC, PIN_WIFI_RST);
// delay_ms(200);
// GPIO_SetBits(GPIOC, PIN_WIFI_RST);
// delay_ms(200);
// GPIO_ResetBits(GPIOC, PIN_WIFI_RST);
}
//清空标志
void WIFI_ClearFlg(void)
{
WIFI_01_RxFlg = 0;
WIFI_04_RxFlg = 0;
WIFI_05_RxFlg = 0;
WIFI_01_TxStep = 0;
setPara_reply_flg = 0;
getPara_reply_flg = 0;
}
//清空接收缓冲区
void WIFI_ClearBuf(void)
{
WIFI_Rx_BufIndex = 0;
memset(WIFI_Rx_Buf, 0, WIFI_RX_BUF_LEN);
}
//初始化通讯
void WIFI_Init(void)
{
WIFI_ClearFlg();
WIFI_ClearBuf();
WIFI_Moni_Count = WIFI_MON_CNT;
uf_UART4_Init(115200);
}
//一定时间没有连接任何设备,初始化通讯,并再次更新名称
void WIFI_TIM_Moni(void)
{
WIFI_Moni_Count--;
if(WIFI_Moni_Count == 0)
{
WIFI_Init();
}
}
//WIFI写参数
void WIFI_SETPARA(void)
{
if(strstr(WIFI_Rx_Buf, "\"data\":{") && strstr(WIFI_Rx_Buf, "}}"))
{
char para_str[6]; //0~65535 或 -32768~32767
uint8_t len = 0; //字符串长度
uint16_t temp; //无符号过程量
//获取原始数据,包括'{''}'
const char* paramsKey = "\"data\":";
char* paramsStart = strstr(WIFI_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; //设备拒绝执行
}
}
//WIFI读参数
void WIFI_GETPARA(void)
{
if(strstr(WIFI_Rx_Buf, "\"params\":[") && strstr(WIFI_Rx_Buf, "]}"))
{
uint16_t len = 0; //字符串长度
//获取原始数据
const char* paramsKey = "\"params\":[";
char* paramsStart = strstr(WIFI_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 WIFI_IT_Receive(void)
{
uint8_t received_byte = USART_ReceiveData(WIFI_UART);
if(WIFI_Rx_BufIndex < WIFI_RX_BUF_LEN - 1)
{
WIFI_Rx_Buf[WIFI_Rx_BufIndex] = received_byte;
WIFI_Rx_BufIndex++;
}
else
{
WIFI_ClearBuf();
}
//更新计时
WIFI_Moni_Count = WIFI_MON_CNT;
}
//处理数据,接收报文识别后执行
//波特率115200
void WIFI_IT_Update(void)
{
if(strstr(WIFI_Rx_Buf,"\"dataType\":\"0x01\"")) //收到"0x01"发送采集数据
{
WIFI_01_RxFlg = 1;
WIFI_ClearBuf();
}
else if(strstr(WIFI_Rx_Buf,"\"dataType\":\"0x04\"")) //收到"0x04"开始解析数据 写参数
{
WIFI_SETPARA();
WIFI_04_RxFlg = 1;
WIFI_ClearBuf();
}
else if(strstr(WIFI_Rx_Buf,"\"dataType\":\"0x05\"")) //收到"0x05"开始解析数据 读参数
{
WIFI_GETPARA();
WIFI_05_RxFlg = 1;
WIFI_ClearBuf();
}
}
//根据当前已知信息,选择接下来要执行的指令,0.1s执行1次
void WIFI_IQ_Update(void)
{
if(WIFI_01_RxFlg == 1) //WIFI请求采集数据
{
WIFI_01_TxStep++;
if(WIFI_01_TxStep == 1) //状态:固定发送
{
//更新true/false
WIFI_ChargeStatus_str = Status[ChargeStatus];
WIFI_DischargeStatus_str = Status[DischargeStatus];
WIFI_PreChargeStatus_str = Status[PreChargeStatus];
WIFI_ChgMosStatus_str = Status[ChgMosStatus];
WIFI_DsgMosStatus_str = Status[DsgMosStatus];
WIFI_PchgMosStatus_str = Status[PchgMosStatus];
WIFI_ChgLimitStatus_str = Status[ChgLimitStatus];
WIFI_BalanceStatus_str = Status[BalanceStatus];
}
else if(WIFI_01_TxStep == 3) //特殊状态:当前存在任一状态才发送
{
if(((bmsMem.bStatus2 & 0x00C0) != 0) || ((bmsMem.temperaStatus & 0x0080) != 0) || ((bmsMem.balanceStatus & 0x07E0) != 0))
{
WIFI_SendFlag |= BIT0;
//更新1:true/0:false
WIFI_SendStatus[0] = LockOCC;
WIFI_SendStatus[1] = LockOCD1;
WIFI_SendStatus[2] = LockOCD2;
WIFI_SendStatus[3] = LockSP;
WIFI_SendStatus[4] = LockSC;
WIFI_SendStatus[5] = ChgMosFault;
WIFI_SendStatus[6] = DsgMosFault;
WIFI_SendStatus[7] = DOStatus;
WIFI_SendStatus[8] = ForceOffUV;
}
else
{
WIFI_SendFlag &= ~BIT0;
}
}
else if(WIFI_01_TxStep == 4) //保护:当前存在任一状态才发送
{
if(((bmsMem.bStatus1 & 0x077f) != 0) || ((bmsMem.bStatus2 & 0x00ff) !=0) || ((bmsMem.bStatus3 & 0x0008) !=0) || ((bmsMem.temperaStatus & 0x0f7f) !=0))
{
WIFI_SendFlag |= BIT1;
//更新1:true/0:false
WIFI_SendProtect_Vol[0] = PackOV;
WIFI_SendProtect_Vol[1] = PackUV;
WIFI_SendProtect_Vol[2] = CellOV;
WIFI_SendProtect_Vol[3] = CellUV;
WIFI_SendProtect_Vol[4] = PF;
WIFI_SendProtect_Vol[5] = L0V;
WIFI_SendProtect_Cur[0] = OCC;
WIFI_SendProtect_Cur[1] = OCD1;
WIFI_SendProtect_Cur[2] = OCD2;
WIFI_SendProtect_Cur[3] = SP;
WIFI_SendProtect_Cur[4] = SC;
WIFI_SendProtect_Temp[0] = McuOTC;
WIFI_SendProtect_Temp[1] = McuOTD;
WIFI_SendProtect_Temp[2] = McuUTC;
WIFI_SendProtect_Temp[3] = McuUTD;
WIFI_SendProtect_Temp[4] = AmbientOTC;
WIFI_SendProtect_Temp[5] = AmbientOTD;
WIFI_SendProtect_Temp[6] = AmbientUTC;
WIFI_SendProtect_Temp[7] = AmbientUTD;
WIFI_SendProtect_Temp[8] = MosOTC;
WIFI_SendProtect_Temp[9] = MosOTD;
WIFI_SendProtect_Temp[10] = MosUTC;
WIFI_SendProtect_Temp[11] = MosUTD;
}
else
{
WIFI_SendFlag &= ~BIT1;
}
}
else if(WIFI_01_TxStep == 5) //报警:当前存在任一状态才发送
{
if(((bmsMem.bStatus2 & 0xff00) !=0) || ((bmsMem.bStatus3 & 0x3f00) !=0) || ((bmsMem.temperaStatus & 0xf000) !=0))
{
WIFI_SendFlag |= BIT2;
//更新1:true/0:false
WIFI_SendWarning_Vol[0] = PackOVWarning;
WIFI_SendWarning_Vol[1] = PackUVWarning;
WIFI_SendWarning_Vol[2] = CellOVWarning;
WIFI_SendWarning_Vol[3] = CellUVWarning;
WIFI_SendWarning_Cur[0] = OCCWarning;
WIFI_SendWarning_Cur[1] = OCDWarning;
WIFI_SendWarning_Temp[0] = McuOTCWarning;
WIFI_SendWarning_Temp[1] = McuOTDWarning;
WIFI_SendWarning_Temp[2] = McuUTCWarning;
WIFI_SendWarning_Temp[3] = McuUTDWarning;
WIFI_SendWarning_Temp[4] = AmbientOTCWarning;
WIFI_SendWarning_Temp[5] = AmbientOTDWarning;
WIFI_SendWarning_Temp[6] = AmbientUTCWarning;
WIFI_SendWarning_Temp[7] = AmbientUTDWarning;
WIFI_SendWarning_Temp[8] = MosOTCWarning;
WIFI_SendWarning_Temp[9] = MosOTDWarning;
WIFI_SendWarning_Temp[10] = MosUTCWarning;
WIFI_SendWarning_Temp[11] = MosUTDWarning;
}
else
{
WIFI_SendFlag &= ~BIT2;
}
}
}
}
//该函数用于发送报文,0.1s执行1次
void WIFI_IQ_Transmit(void)
{
// WIFI_Rx_BufIndex = 0;
// memset(WIFI_Rx_Buf, 0, WIFI_RX_BUF_LEN); //填入前先清空
// memset(WIFI_Tx_Buf, 0, WIFI_TX_BUF_LEN);
if(WIFI_01_RxFlg == 1) //WIFI请求采集数据
{
if(WIFI_01_TxStep == 1)
{
//上报内容 %u:unsigned int %d:int %s:char
//第一帧
//开头
WIFI_Send("{");
WIFI_Send("\"dataType\":\"0x01\",");
WIFI_Send("\"data\":");
//内容
WIFI_Send("{");
WIFI_Send("\"BmsSN\":\"%s\",", BMS_SN);
WIFI_Send("\"PackSN\":\"%s\",", PACK_SN);
WIFI_Send("\"FirmwareVersion\":\"%s\",", FirmwareVersion);
WIFI_Send("\"HardwareVersion\":\"%s\",", HardwareVersion);
if(ScreenVersion[0] != 0)
{
WIFI_Send("\"ScreenVersion\":\"%s\",", ScreenVersion);
}
WIFI_Send("\"FCC\":%u,", bmsMem.ncc/3600);
WIFI_Send("\"RCC\":%u,", bmsMem.rcc/3600);
WIFI_Send("\"SOC\":%u,", bmsMem.soc);
WIFI_Send("\"SOH\":%u,", bmsMem.soh);
WIFI_Send("\"CYC\":%u,", bmsMem.cycleCount);
WIFI_Send("\"ChargeStatus\":%s,", WIFI_ChargeStatus_str);
WIFI_Send("\"DischargeStatus\":%s,", WIFI_DischargeStatus_str);
WIFI_Send("\"PreChargeStatus\":%s,", WIFI_PreChargeStatus_str);
WIFI_Send("\"ChgMosStatus\":%s,", WIFI_ChgMosStatus_str);
WIFI_Send("\"DsgMosStatus\":%s,", WIFI_DsgMosStatus_str);
WIFI_Send("\"PchgMosStatus\":%s,", WIFI_PchgMosStatus_str);
WIFI_Send("\"ChgLimitStatus\":%s,", WIFI_ChgLimitStatus_str);
WIFI_Send("\"BalanceStatus\":%s}", WIFI_BalanceStatus_str);
//结尾
WIFI_Send("}");
}
else if(WIFI_01_TxStep == 2)
{
//上报内容 %u:unsigned int %d:int %s:char
//第一帧
//开头
WIFI_Send("{");
WIFI_Send("\"dataType\":\"0x01\",");
WIFI_Send("\"data\":");
//内容
WIFI_Send("{");
WIFI_Send("\"CellVol1\":%d,", cellVol[0]);
WIFI_Send("\"CellVol2\":%d,", cellVol[1]);
WIFI_Send("\"CellVol3\":%d,", cellVol[2]);
WIFI_Send("\"CellVol4\":%d,", cellVol[3]);
WIFI_Send("\"CellVol5\":%d,", cellVol[4]);
WIFI_Send("\"CellVol6\":%d,", cellVol[5]);
WIFI_Send("\"CellVol7\":%d,", cellVol[6]);
WIFI_Send("\"CellVol8\":%d,", cellVol[7]);
WIFI_Send("\"CellVol9\":%d,", cellVol[8]);
WIFI_Send("\"CellVol10\":%d,", cellVol[9]);
WIFI_Send("\"CellVol11\":%d,", cellVol[10]);
WIFI_Send("\"CellVol12\":%d,", cellVol[11]);
WIFI_Send("\"CellVol13\":%d,", cellVol[12]);
WIFI_Send("\"CellVol14\":%d,", cellVol[13]);
WIFI_Send("\"CellVol15\":%d,", cellVol[14]);
WIFI_Send("\"CellVol16\":%d,", cellVol[15]);
WIFI_Send("\"CellVol17\":%d,", cellVol[16]);
WIFI_Send("\"CellVol18\":%d,", cellVol[17]);
WIFI_Send("\"CellVol19\":%d,", cellVol[18]);
WIFI_Send("\"CellVol20\":%d,", cellVol[19]);
WIFI_Send("\"PackVol\":%u,", bmsMem.packVoltage);
WIFI_Send("\"PackCur\":%d,", bmsMem.packCurrent);
WIFI_Send("\"VolMax\":%d,", cellVoltageMax);
WIFI_Send("\"VolMin\":%d,", cellVoltageMin);
WIFI_Send("\"VolMaxIndex\":%u,", bmsMem.cellVoltageMaxIndex);
WIFI_Send("\"VolMinIndex\":%u,", bmsMem.cellVoltageMinIndex);
WIFI_Send("\"MosT1\":%.1f,", (float)(bmsMem.afe_T1-2731)/10);
WIFI_Send("\"MosT2\":%.1f,", (float)(bmsMem.afe_T2-2731)/10);
WIFI_Send("\"AmbientT\":%.1f,", (float)(bmsMem.afe_T3-2731)/10);
WIFI_Send("\"BatteryT1\":%.1f,", (float)(bmsMem.mcu_T1-2731)/10);
WIFI_Send("\"BatteryT2\":%.1f,", (float)(bmsMem.mcu_T2-2731)/10);
WIFI_Send("\"BatteryT3\":%.1f,", (float)(bmsMem.mcu_T3-2731)/10);
WIFI_Send("\"BatteryT4\":%.1f}", (float)(bmsMem.mcu_T4-2731)/10);
//结尾
WIFI_Send("}");
}
else if((WIFI_01_TxStep == 3) & ((WIFI_SendFlag & BIT0) != 0))
{
uint8_t firstflag = 0; //当出现过第1个上传状态后置1
//上报内容 %u:unsigned int %d:int %s:char
//第三帧
//开头
WIFI_Send("{");
WIFI_Send("\"dataType\":\"0x01\",");
WIFI_Send("\"data\":");
//内容
WIFI_Send("{");
//特殊状态
if(WIFI_SendStatus[0] != 0)
{
WIFI_Send("\"LockOCC\":true");
firstflag = 1;
}
if(WIFI_SendStatus[1] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"LockOCD1\":true");
firstflag = 1;
}
if(WIFI_SendStatus[2] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"LockOCD2\":true");
firstflag = 1;
}
if(WIFI_SendStatus[3] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"LockSP\":true");
firstflag = 1;
}
if(WIFI_SendStatus[4] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"LockSC\":true");
firstflag = 1;
}
if(WIFI_SendStatus[5] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"ChgMosFault\":true");
firstflag = 1;
}
if(WIFI_SendStatus[6] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"DsgMosFault\":true");
firstflag = 1;
}
if(WIFI_SendStatus[7] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"DOStatus\":true");
firstflag = 1;
}
if(WIFI_SendStatus[8] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"ForceOffUV\":true");
firstflag = 1;
}
WIFI_Send("}");
//结尾
WIFI_Send("}");
}
else if((WIFI_01_TxStep == 4) & ((WIFI_SendFlag & BIT1) != 0))
{
uint8_t firstflag = 0; //当出现过第1个上传状态后置1
//上报内容 %u:unsigned int %d:int %s:char
//第三帧
//开头
WIFI_Send("{");
WIFI_Send("\"dataType\":\"0x01\",");
WIFI_Send("\"data\":");
//内容
WIFI_Send("{");
//电压保护
if(WIFI_SendProtect_Vol[0] != 0)
{
WIFI_Send("\"PackOV\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Vol[1] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"PackUV\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Vol[2] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"CellOV\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Vol[3] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"CellUV\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Vol[4] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"PF\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Vol[5] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"L0V\":true");
firstflag = 1;
}
//电流保护
if(WIFI_SendProtect_Cur[0] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"OCC\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Cur[1] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"OCD1\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Cur[2] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"OCD2\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Cur[3] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"SP\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Cur[4] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"SC\":true");
firstflag = 1;
}
//温度保护
if(WIFI_SendProtect_Temp[0] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"McuOTC\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Temp[1] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"McuOTD\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Temp[2] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"McuUTC\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Temp[3] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"McuUTD\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Temp[4] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"AmbientOTC\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Temp[5] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"AmbientOTD\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Temp[6] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"AmbientUTC\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Temp[7] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"AmbientUTD\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Temp[8] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"MosOTC\":true");
firstflag = 1;
}
if(WIFI_SendProtect_Temp[9] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"MosOTD\":true");
firstflag = 1;
}
// if(WIFI_SendProtect_Temp[10] != 0)
// {
// if(firstflag == 1) WIFI_Send(",");
// WIFI_Send("\"MosUTC\":true");
// firstflag = 1;
// }
// if(WIFI_SendProtect_Temp[11] != 0)
// {
// if(firstflag == 1) WIFI_Send(",");
// WIFI_Send("\"MosUTD\":true");
// firstflag = 1;
// }
WIFI_Send("}");
//结尾
WIFI_Send("}");
}
else if((WIFI_01_TxStep == 5) & ((WIFI_SendFlag & BIT2) != 0))
{
uint8_t firstflag = 0; //当出现过第1个上传状态后置1
//上报内容 %u:unsigned int %d:int %s:char
//第三帧
//开头
WIFI_Send("{");
WIFI_Send("\"dataType\":\"0x01\",");
WIFI_Send("\"data\":");
//内容
WIFI_Send("{");
//电压报警
if(WIFI_SendWarning_Vol[0] != 0)
{
WIFI_Send("\"PackOVWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Vol[1] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"PackUVWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Vol[2] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"CellOVWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Vol[3] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"CellUVWarning\":true");
firstflag = 1;
}
//电流报警
if(WIFI_SendWarning_Cur[0] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"OCCWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Cur[1] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"OCDWarning\":true");
firstflag = 1;
}
//温度报警
if(WIFI_SendWarning_Temp[0] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"McuOTCWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Temp[1] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"McuOTDWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Temp[2] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"McuUTCWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Temp[3] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"McuUTDWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Temp[4] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"AmbientOTCWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Temp[5] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"AmbientOTDWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Temp[6] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"AmbientUTCWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Temp[7] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"AmbientUTDWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Temp[8] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"MosOTCWarning\":true");
firstflag = 1;
}
if(WIFI_SendWarning_Temp[9] != 0)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_Send("\"MosOTDWarning\":true");
firstflag = 1;
}
// if(WIFI_SendWarning_Temp[10] != 0)
// {
// if(firstflag == 1) WIFI_Send(",");
// WIFI_Send("\"MosUTCWarning\":true");
// firstflag = 1;
// }
// if(WIFI_SendWarning_Temp[11] != 0)
// {
// if(firstflag == 1) WIFI_Send(",");
// WIFI_Send("\"MosUTDWarning\":true");
// firstflag = 1;
// }
WIFI_Send("}");
//结尾
WIFI_Send("}");
}
//每0.1s发送一帧
else if(WIFI_01_TxStep >= 10)
{
WIFI_01_RxFlg = 0;
WIFI_01_TxStep = 0;
}
}
else if(WIFI_04_RxFlg == 1) //回复写数据操作
{
WIFI_04_RxFlg = 0; //回复后恢复正常状态
//上报内容 %u:unsigned int %d:int %s:char
//开头
WIFI_Send("{");
WIFI_Send("\"dataType\":\"0x04\",");
//内容
if(setPara_reply_flg == 1) //正确
{
uint8_t i;
uint8_t firstflag = 0; //当出现过第1个上传状态后置1
WIFI_Send("\"code\":0,");
WIFI_Send("\"set_num\":%hu,", setPara_reply_num);
WIFI_Send("\"data\":");
WIFI_Send("{");
for(i=0;i<setPara_reply_num;i++)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_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;
WIFI_Send(",");
WIFI_Send("\"ProtocolName\":");
if(protocol == 0)
{
WIFI_Send("null", protocolStrings[protocol-1]);
}
else
{
WIFI_Send("\"%s\"", protocolStrings[protocol-1]);
}
}
}
WIFI_Send("}");
}
else if(setPara_reply_flg == 0xAA) //错误-设备无该属性
{
WIFI_Send("\"code\":6411");
}
else if(setPara_reply_flg == 0xBB) //错误-设备拒绝执行
{
WIFI_Send("\"code\":6405");
}
//结尾
WIFI_Send("}");
}
else if(WIFI_05_RxFlg == 1) //回复读数据操作
{
WIFI_05_RxFlg = 0; //回复后恢复正常状态
//上报内容 %u:unsigned int %d:int %s:char
//开头
WIFI_Send("{");
WIFI_Send("\"dataType\":\"0x05\",");
//内容
if(getPara_reply_flg == 1) //正确
{
uint8_t i;
uint8_t firstflag = 0; //当出现过第1个上传状态后置1
WIFI_Send("\"code\":0,");
WIFI_Send("\"get_num\":%hu,", getPara_reply_num);
WIFI_Send("\"data\":");
WIFI_Send("{");
for(i=0;i<getPara_reply_num;i++)
{
if(firstflag == 1) WIFI_Send(",");
WIFI_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;
WIFI_Send(",");
WIFI_Send("\"ProtocolName\":");
if(protocol == 0)
{
WIFI_Send("null", protocolStrings[protocol-1]);
}
else
{
WIFI_Send("\"%s\"", protocolStrings[protocol-1]);
}
}
}
WIFI_Send("}");
}
else if(getPara_reply_flg == 0xAA) //错误-设备无该属性
{
WIFI_Send("\"code\":6411");
}
else if(getPara_reply_flg == 0xBB) //错误-设备拒绝执行
{
WIFI_Send("\"code\":6405");
}
//结尾
WIFI_Send("}");
}
}
#endif