使用了1个接收函数,本来是不用申请内存的,但是指针会变成野指针,也delete不了,free函数会出错。申请内存后不管myfree函数放在哪,运行几次后内存就是占用完,然后溢出。
[mw_shl_code=c,true]u8 RecTal=0; //数组的行
void BackstageLaunch()
{
u8 i,FrameType,ID,RFlag=0,sum=0;
u16 Len ;
u8 *p2;
// p2=mymalloc(SRAMIN,500); //申请100字节内存;
if(USATR1_RX_STA>0) //接收到一次数据了
{
// if(hbeaterrcnt) //需要检测心跳应答
// {
// if(strstr((char*)USART1_RX_BUF,"SEND OK"))hbeaterrcnt=0;//心跳正常
// }
USATR1_RX_STA--; //中断标记减1
p2=(u8*)strstr((const char*)USART1_RX_BUF_Deputy[RecTal],"+IPD");
if(p2)//接收到TCP/UDP数据
{
p2=(u8*)strstr((const char*)p2,":");
p2[0]=0;//加入结束符
memcpy(&R_VerUpdateReqUL, p2+1,32); //结构体上传数据存入发送数组中
for(i=0;i<2;i++){ VerUpdateReqUL.u8PlatformSendSequenceNumber
= R_VerUpdateReqUL.u8PlatformSendSequenceNumber ;} //平台发送序列号复制
FrameType=R_VerUpdateReqUL.u8FrameTypeIdentifier ;
switch(FrameType)
{
case 2: ID=1;break;
case 4: ID=3;break;
case 6: ID=4;break;
case 92: ID=5;break;
case 98: ID=6;break;
case 33: ID=7;break;
case 15: ID=9;break;
case 20: ID=11;break;
case 23: ID=12;break;
case 12: ID=14;break;
case 10: ID=15;break;
case 96: ID=18;break;
case 90: ID=19;break;
case 18: ID=20;break;
case 94: ID=21;break;
}
switch(ID)
{
case 1: { Len=289;memcpy(&VerUpdateInfoDL, p2+1+32,Len);break; } //消息02
case 3: { Len=14;memcpy(&SysTimingInfoDL, p2+1+32,Len);break;} //消息04 流程3
case 4: { Len=1;memcpy(&BinLogicStateOfPile, p2+1+32,Len);break; } //消息06
case 5: { Len=2;memcpy(&HeartbeatULInvlSetDL, p2+1+32,Len);break;} //消息92 流程5
case 6: { Len=0;break;} //消息98 流程6
case 7: { Len=188;memcpy(&SysParmSetReqDL, p2+1+32,Len);break;} //消息33 系统参数设置请求下行(同步) 流程7
case 9: { Len=425;memcpy(&LoginVerifResponseDL, p2+1+32,Len);break; } //消息15 流程9
case 11: { Len=417;memcpy(&StartChargingAuzDL, p2+1+32,Len);break;} //消息20 流程11
case 12: { Len=2;memcpy(&ileStatusChangeReportDL, p2+1+32,Len);break; } //消息23
case 14: { Len=18;memcpy(&AdvTermChargingDL, p2+1+32,Len);break;} //消息12 流程14
case 15: { Len=32;memcpy(&AsciiTransSerialNumber, p2+1+32,Len);break; } //消息10 独立增加
case 18: { Len=289;memcpy(&UpgradePushDL, p2+1+32,Len);break;} //消息96 流程18
case 19: { Len=0;break;} //消息90 流程19
case 20: { Len=22;memcpy(&QueryUserInfoDL, p2+1+32,Len);break; } //消息18 独立增加
case 21: { Len=167;memcpy(&TransBillConfirmDL, p2+1+32,Len);break;} //消息94 流程21
}
memcpy(&a ,p2+33+Len ,2); //结构体上传数据存入发送数组中
if(a[0]== BCC_CheckSum(p2,33+Len))RFlag=1; //CRC8校验
}
if(RecTal++>2)RecTal=0; //接收下一个数组
}
// myfree(SRAMIN,p2);
if(RFlag==1)
{
switch(ID)
{
case 1:VerRecFlag1=1;TimeFlag10S=1;break; //消息02 关闭主动发送
case 3: {
u16 i;
VerRecFlag2=1; //关闭主动发送
TimeConversion(&CP56Time2a_A2);
if(CP56Time2a_A2.minute>CP56Time2a_A1.minute) //如果分钟进位
{
i=CP56Time2a_A2.ms[1]*256+CP56Time2a_A2.ms[0]+6000-CP56Time2a_A1.ms[1]*256-CP56Time2a_A1.ms[0];
}
else
{
i=CP56Time2a_A2.ms[1]*256+CP56Time2a_A2.ms[0]-CP56Time2a_A1.ms[1]*256+CP56Time2a_A1.ms[0];
}
i=SysTimingInfoDL.CP56Time2a_B1.ms[1]*256+SysTimingInfoDL.CP56Time2a_B1.ms[0] +i;
if(i>6000)
{
calendar.sec=i-6000;
calendar.min= SysTimingInfoDL.CP56Time2a_B1.minute+1;
}
else
{
calendar.min= SysTimingInfoDL.CP56Time2a_B1.minute;
calendar.sec=i/1000;
}
calendar.min= SysTimingInfoDL.CP56Time2a_B1.minute;
calendar.sec=i/1000; //按秒记录
SysTimingInfoDLFbUL=0;
PileLunchOnly(3);break;
} //消息100
case 4: {
if( BinLogicStateOfPile==2&&VerRecFlag5==0 ){ ChangeLCD(5);VerRecFlag5=1;}
break;
} //消息06 心跳空闲切换到待机界面
case 5: {
HeartbeatULInvlSetFbUL=HeartbeatULInvlSetDL; //默认都设置为60s
PileLunchOnly(5);break;
} //消息93
case 6: {
memcpy(SysParmQueryFbUL.AsciiPliePlatformNumber ,VerUpdateReqUL.AsciiPliePlatformNumber , 20) ;
SysParmQueryFbUL.BinServerAddressType = 0; //域名
strcpy(SysParmQueryFbUL.AsciiServerAddress,"120.25.107.156"); //服务器地址
SysParmQueryFbUL.BinServerPort[0]=2816%256; //服务器端口
SysParmQueryFbUL.BinServerPort[1]=2816/256;
strcpy(SysParmQueryFbUL.AsciiPileAdminPassWord , "000000"); //桩管理密码
// memcpy(SysParmQueryFbUL.AsciiQRcodeURL ,SysParmSetReqDL.AsciiQRcodeURL , 128 ); //二维码上传对比
if(SysParmSetReqDL.BinCrtlParameter==3)SoftReset();
PileLunchOnly(6);break;
} //消息99
case 7: {
for(i=0;i<20;i++)sum += SysParmSetReqDL.AsciiPliePlatformNumber ; //全为0不变更
if(sum>0)AT24CXX_Write(PliePlatformNumberSave , SysParmSetReqDL.AsciiPliePlatformNumber , 20);//写桩编号
AT24CXX_Write(ServerAddressType , &SysParmSetReqDL.BinServerAddressType , 1); //服务器地址类型
// SysParmQueryFbUL.BinServerAddressType = SysParmSetReqDL.BinServerAddressType;
for(i=0;i<30;i++)sum += SysParmSetReqDL.AsciiServerAddress ; //全为0不变更
if(sum>0)AT24CXX_Write(ServerAddress , SysParmSetReqDL.AsciiServerAddress , 30);//写服务器地址
for(i=0;i<2;i++)sum += SysParmSetReqDL.BinServerPort ; //全为0不变更
if(sum>0)AT24CXX_Write(ServerPort , SysParmSetReqDL.BinServerPort , 2);//写服务器端口
for(i=0;i<6;i++)sum += SysParmSetReqDL.AsciiPileAdminPassWord ; //全为0不变更
if(sum>0)AT24CXX_Write(PileAdminPassWord , SysParmSetReqDL.AsciiPileAdminPassWord , 6);//写桩管理密码
for(i=0;i<128;i++)sum += SysParmSetReqDL.AsciiQRcodeURL ; //全为0不变更
if(sum>0)AT24CXX_Write(QRcodeURL , SysParmSetReqDL.AsciiQRcodeURL , 128);//写二维码url
PileLunchOnly(7);break;
} //消息34 系统参数设置反馈上行(异步)
case 9: {
char string[15]={0};
if(LoginVerifResponseDL.BinVeriResult==1)
{
ChangeLCD(20);
BinLoginVerifResponseUL=1;
VerRecFlag3=1; //关闭主动发送
}
else
{
ChangeLCD(5);
switch(LoginVerifResponseDL.BinErrorCode)
{
case 1:strcpy(string, "密码输入错误");break;
case 2:strcpy(string, "用户不存在");break;
case 3:strcpy(string, "账户冻结");break;
case 4:strcpy(string, "卡挂失");break;
case 5:strcpy(string, "其他");break;
case 6:strcpy(string, "预留");break;
case 31:strcpy(string, "非此充电桩");break;
case 32:strcpy(string, "尚有账单未结清");break;
case 33:strcpy(string, "此射频卡无订单");break;
case 40:strcpy(string, "余额不足");break;
case 41:strcpy(string, "桩已被预约");break;
case 42:strcpy(string, "资源不足");break;
case 43:strcpy(string, "系统故障");break;
}
sendAdd[0]=0x60;sendAdd[1]=0x40;
writeRegister(sendAdd,string,0,strlen((const char*)string));
BinLoginVerifResponseUL=0;
LoginVerificationFlag= 0; //登入验证清零
}
PileLunchOnly(9);
if(LoginVerifResponseDL.BinVeriResult==1)PileLunch(20) ; // 消息流程20
break;
} //消息16
case 11:{
u8 string[]="授权结果:错误";
if(StartChargingAuzDL.BinAuzResult==0) //授权结果 0:通过 1:错误
{
Status_Left=START;
if(CC==1)BinErrInfo=1;
else if(FaultInformation)BinErrInfo=2;
else if( CP_State()==12)BinErrInfo=3;
else BinErrInfo=0;
}
else if(StartChargingAuzDL.BinAuzResult==1)
{
ChangeLCD(5);
sendAdd[0]=0x60;sendAdd[1]=0x40;
writeRegister(sendAdd,string,0,14);
}
ChargingFlag = 0; //充电标识清零
PileLunchOnly(11);break;
} //消息21
case 12:{ StateChangeFlag=0; break;} //异常状态标识清零
case 14:
{
u8 strr2[]="验证失败";
if(AdvTermChargingDL.BinVerfResult==1) //平台反馈验证通过
{
if( Status_Left!=FINISH )Status_Left= UNFINISHED ; //完成充电保持状态
PileStatusChangeReportUL.BinReasonForStpCharging = 33; //用户刷卡停止充电
Charging_Left_Card(); //停止充电并结算
memset(&AdvTermChargingUL , 0 , sizeof(AdvTermChargingUL)) ; //清空消息11提前结束充电上行 结构体
}
else //验证失败
{
ChangeLCD(21);
sendAdd[0]=0x60;
sendAdd[1]=0x40;
writeRegister(sendAdd,strr2,0,8);
}
StopChargingVerificationFLag=0; //停止充电验证标识清零
PileLunchOnly(14);break;
} //消息13
case 15:{
if(AsciiTransSerialNumber==TransBillSubmissionUL.AsciiTransSerialNumber) //交易账单确认
Charge_Init(); //充电运行初始化 FREE
Charge_Left_Init(); //初始化 //读取欠压点、过压点、过流点数值、读取当前电价
ClearIdentification(); //清除标识
Status_Left=FREE;
VerRecFlag6=1; //关闭主动发送 //接收标识
break;
} //消息10
case 18:{ PileLunchOnly(18);break; } //消息97
case 19:
{
if(Status_Left==CHARGING)
{
QueryPileStaInfoFbULCharging.BinPilePhysicalState=2; //桩物理状态
QueryPileStaInfoFbULCharging.BinGunState=2-CC&0xF; //1.未连接 2.完全连接
QueryPileStaInfoFbULCharging.BinParkingSpaceOcpyState=CC+2; //1.未占用 2.已占用 3.不可信
QueryPileStaInfoFbULCharging.BinChargingTime=Charge_Left.chargeTime/60; //充电时长
QueryPileStaInfoFbULCharging.BinFaultInformation=FaultInformation; //故障信息
QueryPileStaInfoFbULCharging.BinErrorCode=0; //错误代码不用
QueryPileStaInfoFbULCharging.BinChargeAmount=Charge_Left.chargeQuantity ;
QueryPileStaInfoFbULCharging.BinOutputVoltage=Meter_Left.voltage;
QueryPileStaInfoFbULCharging.BinOutputCurrent=Meter_Left.current;
QueryPileStaInfoFbULCharging.BinAPhaseInVoltage=Meter_Left.voltage;
QueryPileStaInfoFbULCharging.BinAPhaseInCurrent=Meter_Left.current;
QueryPileStaInfoFbULCharging.BinMeterCounting=Meter_Left.quantity;
QueryPileStaInfoFbULCharging.BinGroundLockState=1; //无地锁
QueryPileStaInfoFbULCharging.BinGunReturn=CC; //充电枪状态
}
else
{
switch(Status_Left)//桩物理状态
{
case FREE: QueryPileStaInfoFbULNoCharging.BinPilePhysicalState=1;break;
case START: QueryPileStaInfoFbULNoCharging.BinPilePhysicalState=1;break;
case FAULTueryPileStaInfoFbULNoCharging.BinPilePhysicalState=3;break;
// case SERVICINGueryPileStaInfoFbULNoCharging.BinPilePhysicalState=4;break;
case FINISHueryPileStaInfoFbULNoCharging.BinPilePhysicalState=5;break;
case UNFINISHEDueryPileStaInfoFbULNoCharging.BinPilePhysicalState=6;break;
// case PAUSEueryPileStaInfoFbULNoCharging.BinPilePhysicalState=7;break;
// case TESTueryPileStaInfoFbULNoCharging.BinPilePhysicalState=8;break;
}
QueryPileStaInfoFbULNoCharging.BinGunState=2-CC&0xF; //1.未连接 2.完全连接
QueryPileStaInfoFbULNoCharging.BinParkingSpaceOcpyState=CC+2; //1.未占用 2.已占用 3.不可信
QueryPileStaInfoFbULNoCharging.BinFaultInformation=FaultInformation; //故障信息
QueryPileStaInfoFbULNoCharging.BinErrorCode=0; //错误代码不用
QueryPileStaInfoFbULNoCharging.BinMeterCounting=Meter_Left.quantity;
QueryPileStaInfoFbULNoCharging.BinGroundLockState=1; //无地锁
QueryPileStaInfoFbULNoCharging.BinGunReturn=CC; //充电枪状态
}
PileLunchOnly(19);break;
} //消息91
case 20: {
u8* str1[3]={"二维码","密码","刷卡"};
u8* str2[2]={"失败","成功"};
if(QueryUserInfoDL.BinVerfResult==1)BinLoginVerifResponseUL=1; //显示余额
else BinLoginVerifResponseUL=0;
sendAdd[0]=0x40; sendAdd[1]=0x15;
writeRegister(sendAdd,str1[QueryUserInfoDL.BinEntryMode],0,7); //登录方式
sendAdd[0]=0x63; sendAdd[1]=0x00;
writeRegister(sendAdd,QueryUserInfoDL.AsciiCardNumber,0,16); //卡号
sendAdd[0]=0x40; sendAdd[1]=0x20;
writeRegister(sendAdd,str2[QueryUserInfoDL.BinVerfResult],0,4); //验证结果
break;
} //消息18
case 21:{
char i,buf[80]={0};
ChangeLCD(25);
&
// p2=mymalloc(SRAMIN,500); //申请100字节内存;
这一句你不注释,那
p2=(u8*)strstr((const char*)USART1_RX_BUF_Deputy[RecTal],"+IPD");
就是错的
一周热门 更多>