L 1 "..\user\src\gps2.c" N N/************** 思科尔特协议不用了************ N#include "stm32f10x.h" N#include "stm32f10x_conf.h" N N#include "usart.h" N#include "delay.h" N#include "485.h" N N#include "stdio.h" N#include "string.h" N N#include "gpsnet.h" N#include "flash.h" N#include "gpioinit.h" N#include "datahand.h" N#include "IIc.h" N#include "Jdy_19.h" N#include "iobind.h" N N#include "gps2.h" N#include "SH367309.h" N N N//定义全局变量 NRev_Gps Rev_GpsUsart1 = {0}; //接收串口下传的数据 N Ngpss_datas gps_datas = {0}; //GPS相关内容 N Nextern uint16_t crc_16(uint8_t *data, uint16_t len); Nextern unsigned short rjbb; Nextern unsigned short cellnumber; N N Nvoid Send_Gps2(u8 bmsnum,u8 orde,u8 state,u8 *buff,u16 len) N{ N u16 crc_data = 0; N u8 sendbuf[150] = {0}; N data_Gps data_frame = {0}; N N data_frame.Framehand = GPSFRAME_HAND; //帧头 N data_frame.ModeType = GPSMOD_TYPE; //模块类别 N data_frame.ModeNum = bmsnum; //模块序号 N data_frame.Len_L = (u8)len; //报文长度低字节 N data_frame.Len_H = (u8)(len >> 8); //报文长度高字节 N orde |= 0x80; N data_frame.Commond = orde; //命令 N data_frame.ModeWord = state; //模块工作状态 N memcpy(data_frame.Data,buff,len); //数据体 N crc_data = crc_16(&data_frame.ModeType,len + 6); N data_frame.CRC_L = crc_data; N data_frame.CRC_H = crc_data >> 8; N N sendbuf[0] = data_frame.Framehand; N sendbuf[1] = data_frame.ModeType; N sendbuf[2] = data_frame.ModeNum; N sendbuf[3] = data_frame.Len_L; N sendbuf[4] = data_frame.Len_H; N sendbuf[5] = data_frame.Commond; N sendbuf[6] = data_frame.ModeWord; N memcpy(&sendbuf[7],data_frame.Data,len); N N sendbuf[7+len] = data_frame.CRC_L; N sendbuf[8+len] = data_frame.CRC_H; N N //发送数据 N Send_TString_GPS(sendbuf,(u16)(9 + len)); N} N Nvoid gpsdecodea_22222(void) N{ N u8 bmsnum = 0; //BMS序号 N u8 orde = 0; //命令字 N u8 state = 0; //模块工作状态 N u16 data_len = 0; //数据体长度 N u16 crc_data = 0; //CRC校验码 N u16 i = 0; N u16 j = 0; N u32 temp_32 = 0; N N u8 sendbuffer[130] = {0}; //发送数据缓存 N u16 send_len = 0; //数据域长度 N N //接收一帧报文成功 N if(Rev_GpsUsart1.gps_Rev_startss == 1) N { N Rev_GpsUsart1.gps_Rev_startss = 0; //清除标志位 N N data_len = (u16)(Rev_GpsUsart1.gps_Rev_bufss[3] | (Rev_GpsUsart1.gps_Rev_bufss[4] << 8)); //获取数据体长度 N N crc_data = crc_16(&Rev_GpsUsart1.gps_Rev_bufss[1],data_len + 6); //获取CRC校验码 N N tX_bit |= 0x01;//--------------------- N N //条件约束 N if((Rev_GpsUsart1.gps_Rev_bufss[data_len + 7] == (u8)crc_data) && (Rev_GpsUsart1.gps_Rev_bufss[data_len + 8] == (u8)(crc_data >> 8))) N { N //获取模块序号 N bmsnum = Rev_GpsUsart1.gps_Rev_bufss[2]; N //获取命令字 N orde = Rev_GpsUsart1.gps_Rev_bufss[5]; N //获取模块工作状态 N state = Rev_GpsUsart1.gps_Rev_bufss[6]; N switch(orde) N { N case GPSCOMMOND_0x30: //信息查询 N { N s16 tmp[3]={0}; N s16 tmp2[3]={0}; N u8 tmpmaxnum=0; N u8 tmpminnum=0; N memset(gps_datas.data_Querysss.data,0,120); N for(i=0;i> 8; N N gps_datas.data_Querysss.data_Query.tmp_2_l = Bms_tt_data.Anal_quanuion.Anal_quan.Ambi_Tmp * 10; //温度2 N gps_datas.data_Querysss.data_Query.tmp_2_h = (Bms_tt_data.Anal_quanuion.Anal_quan.Ambi_Tmp * 10) >> 8; N N gps_datas.data_Querysss.data_Query.tmp_3_l = Bms_tt_data.Anal_quanuion.Anal_quan.Card_Tmp * 10; //温度3 N gps_datas.data_Querysss.data_Query.tmp_3_h = (Bms_tt_data.Anal_quanuion.Anal_quan.Card_Tmp * 10) >> 8; N N gps_datas.data_Querysss.data_Query.mostmp_l = Bms_tt_data.Anal_quanuion.Anal_quan.Card_Tmp * 10; //mos管温度 N gps_datas.data_Querysss.data_Query.mostmp_h = (Bms_tt_data.Anal_quanuion.Anal_quan.Card_Tmp * 10) >> 8; N N gps_datas.data_Querysss.data_Query.tmp_5_l = 0xD0; //温度5 N gps_datas.data_Querysss.data_Query.tmp_5_h = 0x07; N N gps_datas.data_Querysss.data_Query.tmp_6_l = 0xD0; //温度6 N gps_datas.data_Querysss.data_Query.tmp_6_h = 0x07; N N gps_datas.data_Querysss.data_Query.tmp_7_l = 0xD0; //温度7 N gps_datas.data_Querysss.data_Query.tmp_7_h = 0x07; N N gps_datas.data_Querysss.data_Query.tmp_8_l = 0xD0; //温度8 N gps_datas.data_Querysss.data_Query.tmp_8_h = 0x07; N N /////////////////////////////////////////////////////////////////////////////////////////////////////// N tmp[0] = Bms_tt_data.Anal_quanuion.Anal_quan.Cores_Tmp * 10; N tmp[1] = Bms_tt_data.Anal_quanuion.Anal_quan.Ambi_Tmp * 10; N tmp[2] = Bms_tt_data.Anal_quanuion.Anal_quan.Card_Tmp * 10; N memcpy(tmp2,tmp,6); N N for(i=0; i<3-1; i++) //大到小比较大小 N { N for(j=0; j<3-1-i; j++) N { N if(tmp2[j] > tmp2[j+1]) N { N u16 temp = tmp2[j+1]; N tmp2[j+1] = tmp2[j]; N tmp2[j] = temp; N } N } N } N N for(i=0; i<3; i++) //取最大序号 N { N if(tmp2[3-1] == tmp[i]) N { N tmpmaxnum = i; N break; N } N } N N for(i=0; i<3; i++) //取最小序号 N { N if(tmp2[0] == tmp[i]) N { N tmpminnum = i; N break; N } N } N ////////////////////////////////////////////////// N N gps_datas.data_Querysss.data_Query.maxtmp_l = tmp2[3-1]; //最高温度低字节 最高温度高字节 N gps_datas.data_Querysss.data_Query.maxtmp_h = tmp2[3-1] >> 8; N N gps_datas.data_Querysss.data_Query.maxtmpnum = tmpmaxnum; //最高温度序号 N N gps_datas.data_Querysss.data_Query.mintmp_l = tmp2[0]; //最低温度低字节 N gps_datas.data_Querysss.data_Query.mintmp_h = tmp2[0] >> 8; N N gps_datas.data_Querysss.data_Query.mintmpnum = tmpminnum; //最低温度序号 N N gps_datas.data_Querysss.data_Query.Singmaxvol_l = cell_vol_max; //单体最高电压 N gps_datas.data_Querysss.data_Query.Singmaxvol_h = cell_vol_max >> 8; N N gps_datas.data_Querysss.data_Query.Singminvol_l = cell_vol_min; //单体最低电压 N gps_datas.data_Querysss.data_Query.Singminvol_h = cell_vol_min >> 8; N N gps_datas.data_Querysss.data_Query.SumVol_1 = (gps_data.Rev_data.CellZvol * 10); //电池总电压 N gps_datas.data_Querysss.data_Query.SumVol_2 = (gps_data.Rev_data.CellZvol * 10) >> 8; N gps_datas.data_Querysss.data_Query.SumVol_3 = (gps_data.Rev_data.CellZvol * 10) >> 16; N gps_datas.data_Querysss.data_Query.SumVol_4 = (gps_data.Rev_data.CellZvol * 10) >> 24; N N gps_datas.data_Querysss.data_Query.SumCurr_1 = ((10000 - gps_data.Rev_data.Currdata) * 10); //电池组电流 N gps_datas.data_Querysss.data_Query.SumCurr_2 = ((10000 - gps_data.Rev_data.Currdata) * 10) >> 8; N gps_datas.data_Querysss.data_Query.SumCurr_3 = ((10000 - gps_data.Rev_data.Currdata) * 10) >> 16; N gps_datas.data_Querysss.data_Query.SumCurr_4 = ((10000 - gps_data.Rev_data.Currdata) * 10) >> 24; N N gps_datas.data_Querysss.data_Query.eQl_l = (gps_data.Rev_data.Bms_rl / 10); //额定容量 N gps_datas.data_Querysss.data_Query.eQl_h = (gps_data.Rev_data.Bms_rl / 10) >> 8; N N gps_datas.data_Querysss.data_Query.SOC_l = (Cell_Soc * 10); //额定容量 N gps_datas.data_Querysss.data_Query.SOC_h = (Cell_Soc * 10)>> 8; N N gps_datas.data_Querysss.data_Query.CellXHnum_l = gps_data.Rev_data.Cellusnum; //电池使用循环次数 N gps_datas.data_Querysss.data_Query.CellXHnum_h = gps_data.Rev_data.Cellusnum >> 8; N N gps_datas.data_Querysss.data_Query.rjbb_l = rjbb; //软件版本号 N gps_datas.data_Querysss.data_Query.rjbb_h = rjbb >> 8; N N gps_datas.data_Querysss.data_Query.cellnum_l = cellnumber; //电池序列号 N gps_datas.data_Querysss.data_Query.cellnum_h = cellnumber >> 8; N N ////////////////////////////////////////////////////////////////////////////////////////////// N N gps_datas.data_Querysss.data_Query.BMSerro_1 = 0x00; N gps_datas.data_Querysss.data_Query.BMSerro_2 = 0x00; N gps_datas.data_Querysss.data_Query.BMSerro_3 = 0x00; N gps_datas.data_Querysss.data_Query.BMSerro_4 = 0x00; N if(HitFlag == 1) N { N if(Hitsturt & (1 << 10)) //单体过压 N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<0); //超压 N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<0); N N if(Hitsturt & (1 << 11)) //单体欠压 N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<1); //欠压 N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<1); N N ///////////////////////////////////////////////////////// N if(Hitsturt & (1 << 6)) //放电过流 N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<6); N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<6); N N if(Hitsturt & (1 << 5)) //充电过流 N gps_datas.data_Querysss.data_Query.BMSerro_2 |= (1<<0); N else N gps_datas.data_Querysss.data_Query.BMSerro_2 &= ~(1<<0); N N if(Hitsturt & (1 << 0)) //容量过低 N gps_datas.data_Querysss.data_Query.BMSerro_2 |= (1<<1); N else N gps_datas.data_Querysss.data_Query.BMSerro_2 &= ~(1<<1); N N if(Hitsturt & (1 << 7)) //电芯压差 N gps_datas.data_Querysss.data_Query.BMSerro_2 |= (1<<4); N else N gps_datas.data_Querysss.data_Query.BMSerro_2 &= ~(1<<4); N N if(Hitsturt & (1 << 1)) //MOS管过温 N gps_datas.data_Querysss.data_Query.BMSerro_2 |= (1<<5); N else N gps_datas.data_Querysss.data_Query.BMSerro_2 &= ~(1<<5); N HitFlag = 0; //上报后清除 N } N else N { N if(gps_data.Rev_data.CellhitData & (1 << 10)) //单体过压 N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<0); //超压 N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<0); N N if(gps_data.Rev_data.CellhitData & (1 << 11)) //单体欠压 N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<1); //欠压 N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<1); N N if(gps_data.Rev_data.CellhitData & (1 << 6)) //放电过流 N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<6); N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<6); N N if(gps_data.Rev_data.CellhitData & (1 << 5)) //充电过流 N gps_datas.data_Querysss.data_Query.BMSerro_2 |= (1<<0); N else N gps_datas.data_Querysss.data_Query.BMSerro_2 &= ~(1<<0); N N if(gps_data.Rev_data.CellhitData & (1 << 0)) //容量过低 N gps_datas.data_Querysss.data_Query.BMSerro_2 |= (1<<1); N else N gps_datas.data_Querysss.data_Query.BMSerro_2 &= ~(1<<1); N N if(gps_data.Rev_data.CellhitData & (1 << 7)) //电芯压差 N gps_datas.data_Querysss.data_Query.BMSerro_2 |= (1<<4); N else N gps_datas.data_Querysss.data_Query.BMSerro_2 &= ~(1<<4); N N if(gps_data.Rev_data.CellhitData & (1 << 1)) //MOS管过温 N gps_datas.data_Querysss.data_Query.BMSerro_2 |= (1<<5); N else N gps_datas.data_Querysss.data_Query.BMSerro_2 &= ~(1<<5); N } N if(HitFlag_22 == 1) N { N if(Hitsturt_22 & (1 << 0)) N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<2); //放电超温 N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<2); N N if(Hitsturt_22 & (1 << 1)) N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<3); //放电低温 N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<3); N N if(Hitsturt_22 & (1 << 2)) N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<4); //充电超温 N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<4); N N if(Hitsturt_22 & (1 << 3)) N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<5); //充电低温 N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<5); N HitFlag_22 = 0; N } N else N { N ///////////////////////////////////////////////////////// N N if(Bms_tt_data.Kaiguan[6]) N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<2); //放电超温 N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<2); N N if(Bms_tt_data.Kaiguan[8]) N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<3); //放电低温 N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<3); N N if(Bms_tt_data.Kaiguan[5]) N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<4); //充电超温 N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<4); N N if(Bms_tt_data.Kaiguan[7]) N gps_datas.data_Querysss.data_Query.BMSerro_1 |= (1<<5); //充电低温 N else N gps_datas.data_Querysss.data_Query.BMSerro_1 &= ~(1<<5); N } N N temp_32 = (data_309_B.RAM_Revdata.Balanceh_l.datas << data_309_A.EEPROMRevdata.Sconf1.datas) | data_309_A.RAM_Revdata.Balanceh_l.datas; N N gps_datas.data_Querysss.data_Query.jhnum_1 = temp_32; //均衡通道 N gps_datas.data_Querysss.data_Query.jhnum_2 = temp_32 >> 8; N gps_datas.data_Querysss.data_Query.jhnum_3 = temp_32 >> 16; N gps_datas.data_Querysss.data_Query.jhnum_4 = temp_32 >> 24; N N gps_datas.data_Querysss.data_Query.maxsingnum = cellmaxnum; //最高单体序号 N gps_datas.data_Querysss.data_Query.minsingnum = cellminnum; //最低单体序号 N N if(CH_MCU_Flag == 0) /////////////// N gps_datas.data_Querysss.data_Query.ChgMOS = 1; // 充电MOS管状态 N else N gps_datas.data_Querysss.data_Query.ChgMOS = 0; // N if(DS_MCU_Flag == 0) /////////////// N gps_datas.data_Querysss.data_Query.OutMOS = 1; // 放电MOS管状态 N else N gps_datas.data_Querysss.data_Query.OutMOS = 0; // N N readdata_485(); N send_len = 120; N memcpy(sendbuffer,gps_datas.data_Querysss.data,send_len); N Send_Gps2(bmsnum,orde,state,sendbuffer,send_len); N N } N break; N case GPSCOMMOND_0x40: //参数读取 N { N gps_datas.data_RevWritesss.data_RevWrite.Overvol_l = gps_data.RevWrite_data.SingvolG; N gps_datas.data_RevWritesss.data_RevWrite.Overvol_h = gps_data.RevWrite_data.SingvolG >> 8; N N gps_datas.data_RevWritesss.data_RevWrite.Overvoltime = gps_data.RevWrite_data.SingvolGtime; N N gps_datas.data_RevWritesss.data_RevWrite.Qvol_l = gps_data.RevWrite_data.SingvolQ; N gps_datas.data_RevWritesss.data_RevWrite.Qvol_h = gps_data.RevWrite_data.SingvolQ >> 8; N N gps_datas.data_RevWritesss.data_RevWrite.Qvoltime = gps_data.RevWrite_data.SingvolQtime; N N gps_datas.data_RevWritesss.data_RevWrite.JHON_Vol_l = gps_data.RevWrite_data.Equalivol; N gps_datas.data_RevWritesss.data_RevWrite.JHON_Vol_h = gps_data.RevWrite_data.Equalivol >> 8; N N gps_datas.data_RevWritesss.data_RevWrite.JHON_yc_l = gps_data.RevWrite_data.Equalivolcc; N gps_datas.data_RevWritesss.data_RevWrite.JhON_yc_h = gps_data.RevWrite_data.Equalivolcc >> 8; N N gps_datas.data_RevWritesss.data_RevWrite.cyzuz_l = 0xFF; N gps_datas.data_RevWritesss.data_RevWrite.cyzuz_h = 0xFF; N N gps_datas.data_RevWritesss.data_RevWrite.OutcurrG_l = gps_data.RevWrite_data.OutcurrG * (400/6.1); N gps_datas.data_RevWritesss.data_RevWrite.OutcurrG_h = (u16)(gps_data.RevWrite_data.OutcurrG * (400/6.1))>> 8; N N gps_datas.data_RevWritesss.data_RevWrite.Outcurrtime_l = gps_data.RevWrite_data.OutcurrGtime * 1000; N gps_datas.data_RevWritesss.data_RevWrite.Outcurrtime_h = (gps_data.RevWrite_data.OutcurrGtime * 1000)>> 8; N N gps_datas.data_RevWritesss.data_RevWrite.Outdl_l = (u8) (80 * (400/6.1)); N gps_datas.data_RevWritesss.data_RevWrite.Outdl_h = (u16)(80 * (400/6.1)) >> 8; N gps_datas.data_RevWritesss.data_RevWrite.Outdltime_l = (u8)512; N gps_datas.data_RevWritesss.data_RevWrite.Outdltime_h = (u8)((u16)(512) >> 8); N N gps_datas.data_RevWritesss.data_RevWrite.ChgcurrG_l = gps_data.RevWrite_data.ChgcurrG * (400/6.1); N gps_datas.data_RevWritesss.data_RevWrite.ChgcurrG_h = (u16)(gps_data.RevWrite_data.ChgcurrG * (400/6.1)) >> 8; N N gps_datas.data_RevWritesss.data_RevWrite.Chgcurrtime = gps_data.RevWrite_data.ChgcurrGtime; N /////////////////////////////////////////////////////////////////////////////////////////////////// N gps_datas.data_RevWritesss.data_RevWrite.OutCtmp_l = gps_data.RevWrite_data.CellOutTmpG * 10; N gps_datas.data_RevWritesss.data_RevWrite.OutCtmp_h = (gps_data.RevWrite_data.CellOutTmpG * 10)>> 8; N N gps_datas.data_RevWritesss.data_RevWrite.OutCHtmp_l = gps_data.RevWrite_data.CellOutTmpGH * 10; N gps_datas.data_RevWritesss.data_RevWrite.OutCHtmp_h = (gps_data.RevWrite_data.CellOutTmpGH * 10)>> 8; N N gps_datas.data_RevWritesss.data_RevWrite.OutDtmp_l = gps_data.RevWrite_data.OutTmpD * 10; N gps_datas.data_RevWritesss.data_RevWrite.OutDtmp_h = (gps_data.RevWrite_data.OutTmpD * 10)>> 8; N N gps_datas.data_RevWritesss.data_RevWrite.OutDHtmp_l = gps_data.RevWrite_data.OutTmpDH * 10; N gps_datas.data_RevWritesss.data_RevWrite.OutDHtmp_h = (gps_data.RevWrite_data.OutTmpDH * 10)>> 8; N //////////////////////////////////////////////////////////////////////////////////////////////// N gps_datas.data_RevWritesss.data_RevWrite.ChgCtmp_l = gps_data.RevWrite_data.CellChgTmpG * 10; N gps_datas.data_RevWritesss.data_RevWrite.ChgCtmp_h = (gps_data.RevWrite_data.CellChgTmpG * 10)>> 8; N N gps_datas.data_RevWritesss.data_RevWrite.ChgCHtmp_l = gps_data.RevWrite_data.CellChgTmpGH * 10; N gps_datas.data_RevWritesss.data_RevWrite.ChgCHtmp_h = (gps_data.RevWrite_data.CellChgTmpGH * 10)>> 8; N N gps_datas.data_RevWritesss.data_RevWrite.ChgDtmp_l = gps_data.RevWrite_data.ChgTmpD * 10; N gps_datas.data_RevWritesss.data_RevWrite.ChgDtmp_h = (gps_data.RevWrite_data.ChgTmpD * 10)>> 8; N N gps_datas.data_RevWritesss.data_RevWrite.ChgDHtmp_l = gps_data.RevWrite_data.ChgTmpDH * 10; N gps_datas.data_RevWritesss.data_RevWrite.ChgDHtmp_h = (gps_data.RevWrite_data.ChgTmpDH * 10)>> 8; N /////////////////////////////////////////////////////////////////////////////////////////////////// N gps_datas.data_RevWritesss.data_RevWrite.SjRL_l = gps_data.RevWrite_data.CellRl * 10; N gps_datas.data_RevWritesss.data_RevWrite.SjRL_h = (gps_data.RevWrite_data.CellRl * 10)>> 8; N N gps_datas.data_RevWritesss.data_RevWrite.SyRL_l = Cell_Soc * 10; N gps_datas.data_RevWritesss.data_RevWrite.SyRL_h = (Cell_Soc * 10)>> 8; N N gps_datas.data_RevWritesss.data_RevWrite.FCC_l = 0; N gps_datas.data_RevWritesss.data_RevWrite.FCC_h = 0; N N gps_datas.data_RevWritesss.data_RevWrite.Statebit = 0; N N gps_datas.data_RevWritesss.data_RevWrite.bhrl = gps_data.RevWrite_data.DRLNum; N N gps_datas.data_RevWritesss.data_RevWrite.znum = gps_data.RevWrite_data.Cellnum; N N gps_datas.data_RevWritesss.data_RevWrite.RSNS_VALUE = 0; N N gps_datas.data_RevWritesss.data_RevWrite.CvolH_l = gps_data.RevWrite_data.SingvolGH; N gps_datas.data_RevWritesss.data_RevWrite.CvolH_h = gps_data.RevWrite_data.SingvolGH >> 8; N N gps_datas.data_RevWritesss.data_RevWrite.QvolH_l = gps_data.RevWrite_data.SingvolQH; N gps_datas.data_RevWritesss.data_RevWrite.QvolH_h = gps_data.RevWrite_data.SingvolQH >> 8; N N gps_datas.data_RevWritesss.data_RevWrite.CBvol_l = (u8)3000; N gps_datas.data_RevWritesss.data_RevWrite.CBvol_h = (u8)((u16)(3000) >> 8); N N gps_datas.data_RevWritesss.data_RevWrite.Sleeptime_l = gps_data.RevWrite_data.SleepTime; N gps_datas.data_RevWritesss.data_RevWrite.Sleeptime_h = gps_data.RevWrite_data.SleepTime >> 8; N N gps_datas.data_RevWritesss.data_RevWrite.HXCurr_l = (u8)2; N gps_datas.data_RevWritesss.data_RevWrite.HXCurr_h = (u8)((u16)(2) >> 8); N N gps_datas.data_RevWritesss.data_RevWrite.erGcurr_l = (u8)80 * (400/6.1); N gps_datas.data_RevWritesss.data_RevWrite.erGcurr_h = (u8)((u16)(80 * (400/6.1)) >> 8); N N gps_datas.data_RevWritesss.data_RevWrite.erGcurrtime_l = (u8)500; N gps_datas.data_RevWritesss.data_RevWrite.erGcurrtimr_h = (u8)((u16)(500) >> 8); N N gps_datas.data_RevWritesss.data_RevWrite.ChgGcurr = gps_data.RevWrite_data.ChgcurrGtime; N N gps_datas.data_RevWritesss.data_RevWrite.AFE1 = 11; N N gps_datas.data_RevWritesss.data_RevWrite.AFE2 = gps_data.RevWrite_data.Cellnum - 11; N N if(gps_data.RevWrite_data.Celltype == 0) N gps_datas.data_RevWritesss.data_RevWrite.celltype = 1; N else if(gps_data.RevWrite_data.Celltype == 1) N gps_datas.data_RevWritesss.data_RevWrite.celltype = 0; N else N gps_datas.data_RevWritesss.data_RevWrite.celltype = gps_data.RevWrite_data.Celltype; N N gps_datas.data_RevWritesss.data_RevWrite.MOSCtmp_l = gps_data.RevWrite_data.PowTmp * 10; N gps_datas.data_RevWritesss.data_RevWrite.MOSCtmp_h = (gps_data.RevWrite_data.PowTmp * 10)>> 8; N N gps_datas.data_RevWritesss.data_RevWrite.MOSCHtmp_l = gps_data.RevWrite_data.PowTmpH * 10; N gps_datas.data_RevWritesss.data_RevWrite.MOSCHtmp_h = (gps_data.RevWrite_data.PowTmpH * 10)>> 8; N N gps_datas.data_RevWritesss.data_RevWrite.LDcurr_l = (u8)30; N gps_datas.data_RevWritesss.data_RevWrite.LDcurr_h = (u8)((u16)(30) >> 8); N N gps_datas.data_RevWritesss.data_RevWrite.SleepLDcurr_l = (u8)10; N gps_datas.data_RevWritesss.data_RevWrite.SleepLDcurr_h = (u8)((u16)(10) >> 8);; N N readdata_485(); N send_len = 75; N memcpy(sendbuffer,gps_datas.data_RevWritesss.data,send_len); N N Send_Gps2(bmsnum,orde,state,sendbuffer,send_len); N N } N break; N case GPSCOMMOND_0x41: //参数下发 N { N u8 CelltypeLast = 0; N u8 CellnumLast = 0; N memcpy(gps_datas.data_RevWritesss.data,&Rev_GpsUsart1.gps_Rev_bufss[7],75); N N gps_data.RevWrite_data.SingvolG = (gps_datas.data_RevWritesss.data_RevWrite.Overvol_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.Overvol_l; N N gps_data.RevWrite_data.SingvolGtime = gps_datas.data_RevWritesss.data_RevWrite.Overvoltime; N N gps_data.RevWrite_data.SingvolQ = (gps_datas.data_RevWritesss.data_RevWrite.Qvol_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.Qvol_l; N N gps_data.RevWrite_data.SingvolQtime = gps_datas.data_RevWritesss.data_RevWrite.Qvoltime; N N gps_data.RevWrite_data.Equalivol = (gps_datas.data_RevWritesss.data_RevWrite.JHON_Vol_h << 8)| gps_datas.data_RevWritesss.data_RevWrite.JHON_Vol_l; N N gps_data.RevWrite_data.Equalivolcc = (gps_datas.data_RevWritesss.data_RevWrite.JhON_yc_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.JHON_yc_l; N N gps_data.RevWrite_data.OutcurrG = ((gps_datas.data_RevWritesss.data_RevWrite.OutcurrG_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.OutcurrG_l) / 10; N N gps_data.RevWrite_data.OutcurrGtime = ((gps_datas.data_RevWritesss.data_RevWrite.Outcurrtime_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.Outcurrtime_l) / 1000; N N gps_data.RevWrite_data.ChgcurrG = ((gps_datas.data_RevWritesss.data_RevWrite.ChgcurrG_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.ChgcurrG_l) / 10; N N gps_data.RevWrite_data.ChgcurrGtime = gps_datas.data_RevWritesss.data_RevWrite.Chgcurrtime; N /////////////////////////////////////////////////////////////////////////////////////////////////// N gps_data.RevWrite_data.CellOutTmpG = ((gps_datas.data_RevWritesss.data_RevWrite.OutCtmp_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.OutCtmp_l) / 10; N N gps_data.RevWrite_data.CellOutTmpGH = ((gps_datas.data_RevWritesss.data_RevWrite.OutCHtmp_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.OutCHtmp_l) / 10; N N gps_data.RevWrite_data.OutTmpD = (s16)((gps_datas.data_RevWritesss.data_RevWrite.OutDtmp_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.OutDtmp_l) / 10; N N gps_data.RevWrite_data.OutTmpDH = (s16)((gps_datas.data_RevWritesss.data_RevWrite.OutDHtmp_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.OutDHtmp_l) / 10; N //////////////////////////////////////////////////////////////////////////////////////////////// N gps_data.RevWrite_data.CellChgTmpG = ((gps_datas.data_RevWritesss.data_RevWrite.ChgCtmp_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.ChgCtmp_l) / 10; N N gps_data.RevWrite_data.CellChgTmpGH = ((gps_datas.data_RevWritesss.data_RevWrite.ChgCHtmp_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.ChgCHtmp_l) / 10; N N gps_data.RevWrite_data.ChgTmpD = (s16)((gps_datas.data_RevWritesss.data_RevWrite.ChgDtmp_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.ChgDtmp_l) / 10; N N gps_data.RevWrite_data.ChgTmpDH = (s16)((gps_datas.data_RevWritesss.data_RevWrite.ChgDHtmp_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.ChgDHtmp_l) / 10; N /////////////////////////////////////////////////////////////////////////////////////////////////// N if(gps_data.RevWrite_data.CellRl != (((gps_datas.data_RevWritesss.data_RevWrite.SjRL_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.SjRL_l) / 10)) N { N SOCinit = 0; N SOCinit_bit = 0; N } N gps_data.RevWrite_data.CellRl = ((gps_datas.data_RevWritesss.data_RevWrite.SjRL_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.SjRL_l) / 10; N //添加实际容量约束 N if(gps_data.RevWrite_data.Reali_Q > gps_data.RevWrite_data.CellRl) N gps_data.RevWrite_data.Reali_Q = gps_data.RevWrite_data.CellRl; N N N gps_data.RevWrite_data.DRLNum = gps_datas.data_RevWritesss.data_RevWrite.bhrl; N N CellnumLast = gps_datas.data_RevWritesss.data_RevWrite.znum; ///////////////// N N gps_data.RevWrite_data.SingvolGH = (gps_datas.data_RevWritesss.data_RevWrite.CvolH_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.CvolH_l; N N gps_data.RevWrite_data.SingvolQH = (gps_datas.data_RevWritesss.data_RevWrite.QvolH_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.QvolH_l; N N gps_data.RevWrite_data.SleepTime = (gps_datas.data_RevWritesss.data_RevWrite.Sleeptime_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.Sleeptime_l; N N gps_data.RevWrite_data.ChgcurrGtime = gps_datas.data_RevWritesss.data_RevWrite.ChgGcurr; N N if(gps_datas.data_RevWritesss.data_RevWrite.celltype == 0) N CelltypeLast = 1; //////////////////电池类型 N else if(gps_datas.data_RevWritesss.data_RevWrite.celltype == 1) N CelltypeLast = 0; N else N CelltypeLast = gps_datas.data_RevWritesss.data_RevWrite.celltype; N N gps_data.RevWrite_data.PowTmp = ((gps_datas.data_RevWritesss.data_RevWrite.MOSCtmp_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.MOSCtmp_l) / 10; N N gps_data.RevWrite_data.PowTmpH = ((gps_datas.data_RevWritesss.data_RevWrite.MOSCHtmp_h << 8) | gps_datas.data_RevWritesss.data_RevWrite.MOSCHtmp_l) / 10; N N N //////////////////////////////////////////////////////////////////// N if(gps_data.RevWrite_data.Celltype != CelltypeLast) N { N SOCinit_bit = 0; N if(CelltypeLast == 0) //铁锂 N { N gps_data.RevWrite_data.SingvolG = 3650; N gps_data.RevWrite_data.SingvolGtime = 2; N gps_data.RevWrite_data.SingvolGH = 3600; N gps_data.RevWrite_data.SingvolQ = 2300; N gps_data.RevWrite_data.SingvolQtime = 2; N gps_data.RevWrite_data.SingvolQH = 2400; N gps_data.RevWrite_data.ChgcurrG = 20; N gps_data.RevWrite_data.ChgcurrGtime = 4; N gps_data.RevWrite_data.OutcurrG = 50; N gps_data.RevWrite_data.OutcurrGtime = 8; N gps_data.RevWrite_data.CellXyc = 1000; N gps_data.RevWrite_data.Equalivol = 3300; N gps_data.RevWrite_data.Equalivolcc = 5; N } N else if(CelltypeLast == 1) //三元 N { N gps_data.RevWrite_data.SingvolG = 4250; N gps_data.RevWrite_data.SingvolGtime = 2; N gps_data.RevWrite_data.SingvolGH = 4200; N gps_data.RevWrite_data.SingvolQ = 2800; N gps_data.RevWrite_data.SingvolQtime = 2; N gps_data.RevWrite_data.SingvolQH = 2900; N gps_data.RevWrite_data.ChgcurrG = 20; N gps_data.RevWrite_data.ChgcurrGtime = 4; N gps_data.RevWrite_data.OutcurrG = 50; N gps_data.RevWrite_data.OutcurrGtime = 8; N gps_data.RevWrite_data.CellXyc = 1000; N gps_data.RevWrite_data.Equalivol = 3600; N gps_data.RevWrite_data.Equalivolcc = 5; N } N else if(CelltypeLast == 2) //钛酸锂 N { N gps_data.RevWrite_data.SingvolG = 2300; N gps_data.RevWrite_data.SingvolGtime = 2; N gps_data.RevWrite_data.SingvolGH = 2250; N gps_data.RevWrite_data.SingvolQ = 1500; N gps_data.RevWrite_data.SingvolQtime = 2; N gps_data.RevWrite_data.SingvolQH = 1600; N gps_data.RevWrite_data.ChgcurrG = 20; N gps_data.RevWrite_data.ChgcurrGtime = 4; N gps_data.RevWrite_data.OutcurrG = 50; N gps_data.RevWrite_data.OutcurrGtime = 8; N gps_data.RevWrite_data.CellXyc = 1000; N gps_data.RevWrite_data.Equalivol = 2000; N gps_data.RevWrite_data.Equalivolcc = 5; N } N } N N if(gps_data.RevWrite_data.Cellnum != CellnumLast) N { N gps_data.RevWrite_data.ZvolG = gps_data.RevWrite_data.SingvolG / 10.0 * CellnumLast; N gps_data.RevWrite_data.ZvolQ = gps_data.RevWrite_data.SingvolQ / 10.0 * CellnumLast; N } N N readdata_485(); N gps_data.RevWrite_data.Celltype = CelltypeLast; N gps_data.RevWrite_data.Cellnum = CellnumLast; N N //存储数据 N flash_write_sys_flag_ALL(); N N //数据返回 N memset(sendbuffer,0,75); N send_len = 0; N //发送数据 N Send_Gps2(bmsnum,orde,state,sendbuffer,send_len); N N } N break; N case GPSCOMMOND_0x50: //恢复出厂设置 N { N flash_write_sys_flag_ALL_Init(); N N memset(sendbuffer,0,75); N send_len = 0; N //发送数据 N Send_Gps2(bmsnum,orde,state,sendbuffer,send_len); N// __set_PRIMASK(1); N// NVIC_SystemReset(); //重启系统 N } N break; N case GPSCOMMOND_0x51: //配置新地址 N { N memset(sendbuffer,0,75); N send_len = 0; N //发送数据 N Send_Gps2(bmsnum,orde,state,sendbuffer,send_len); N } N break; N case GPSCOMMOND_0x62: //电流校准 N gps_data.RevWrite_data.CurrjzONOFF = Rev_GpsUsart1.gps_Rev_bufss[6]; N gps_data.RevWrite_data.CurrJZ = (Rev_GpsUsart1.gps_Rev_bufss[7] | (Rev_GpsUsart1.gps_Rev_bufss[8] << 8) | (Rev_GpsUsart1.gps_Rev_bufss[9] << 16) | (Rev_GpsUsart1.gps_Rev_bufss[10] << 24)); N N memset(sendbuffer,0,4); N memcpy(sendbuffer,&Rev_GpsUsart1.gps_Rev_bufss[7],4); N send_len = 4; N //发送数据 N Send_Gps2(bmsnum,orde,state,sendbuffer,send_len); N break; N case GPSCOMMOND_0x63: //获取UUID N memcpy(sendbuffer,&UUID,12); N send_len = 12; N //发送数据 N Send_Gps2(bmsnum,orde,state,sendbuffer,send_len); N break; N case GPSCOMMOND_0x22: //关闭电源 N { N u32 data = 0; N data = (Rev_GpsUsart1.gps_Rev_bufss[7] | (Rev_GpsUsart1.gps_Rev_bufss[8] << 8) | (Rev_GpsUsart1.gps_Rev_bufss[9] << 16) | (Rev_GpsUsart1.gps_Rev_bufss[10] << 24)); N if(data == 0) //打开放电MOS管 N { N Out_Lock = 0; N if(OutMos_bit == 0) N { N RESETIO(DS_M); N Free309DSGMos(); N OutMos_bit = 0; N } N else N { N if(Out_flag == 0) N { N RESETIO(DS_M); N Free309DSGMos(); N OutMos_bit = 0; N } N } N } N else N { N Out_Lock = 1; N SETIO(DS_M); //关闭放电MOS管 N Shut309DSGMos(); N OutMos_bit = 1; N } N flash_write_sys_flag(40); N } N break; N case GPSCOMMOND_0x23: //关闭电源 N { N u32 data = 0; N data = (Rev_GpsUsart1.gps_Rev_bufss[7] | (Rev_GpsUsart1.gps_Rev_bufss[8] << 8) | (Rev_GpsUsart1.gps_Rev_bufss[9] << 16) | (Rev_GpsUsart1.gps_Rev_bufss[10] << 24)); N if(data == 0) //打开充电MOS管 N { N Chg_Lock = 0; N if(ChgMos_bit == 0) N { N RESETIO(CH_M); N Free309CHGMos(); N ChgMos_bit = 0; N } N else N { N if(Chg_Flag == 0) //判断是否有故障 N { N RESETIO(CH_M); N Free309CHGMos(); N ChgMos_bit = 0; N } N } N } N else //关闭充电MOS管 N { N Chg_Lock = 1; N SETIO(CH_M); N Shut309CHGMos(); N ChgMos_bit = 1; N } N flash_write_sys_flag(39); N } N break; N default: N break; N } N } N readdata_485(); N memset(Rev_GpsUsart1.gps_Rev_bufss,0,100); N Uart1Flag_GPS = 0; N } N} N******************/ N