📄 de_encode.c
字号:
#include "config.h"
//将要更新的参数一起保存到tempbuff缓冲区中,并一起存入FLASH。
void update(SetupParam_Item * temp,uint8 * tempBuff)
{
uint8 * p=NULL;
INT16U len=0,moveAddr=0;
GetOmoveAddr(SETUP_PARAMS,SETUP_PARAMS_COUNT,temp->param_ID,&len,&moveAddr);
p=(uint8 *)malloc(len);
if(NULL==p) return;
memset(p,0xFF,len);
if(temp->paramValue_Len>len) temp->paramValue_Len=len;
memcpy(p,temp->pParam_Value,temp->paramValue_Len);
memcpy(tempBuff+moveAddr,p,len);
if(temp->param_ID==0x0402) //低电压门限值及采样次数时间
memcpy(Lmt_V_Time,temp->pParam_Value,sizeof(Lmt_V_Time));
else if(temp->param_ID==0x0301) //终端密码值
memcpy(Password,temp->pParam_Value,sizeof(Password));
else if(temp->param_ID==0x0209) //终端上传心跳包时间间隔
memcpy(&HeartSlot,temp->pParam_Value,sizeof(HeartSlot));
else if(temp->param_ID==0x0307) //安装调度屏标志
memcpy(&schedLCD_BuildIn_OK,temp->pParam_Value,sizeof(schedLCD_BuildIn_OK));
else if(temp->param_ID==0x0309) //休眠时间
{
uint8 buff[2];
memset(buff,0,sizeof(buff));
memcpy(buff,temp->pParam_Value,sizeof(buff));
powerdown_settime=(uint16)(buff[0]<<8)+(uint16)buff[1];
}
else if(temp->param_ID==0x030A) //关机时间
{
uint8 buff[2];
memset(buff,0,sizeof(buff));
memcpy(buff,temp->pParam_Value,sizeof(buff));
poweroff_settime=(uint16)(buff[0]<<8)+(uint16)buff[1];
}
else if(temp->param_ID==0x030B) //是否短信提醒
memcpy(&G_RestMsg,temp->pParam_Value,sizeof(G_RestMsg));
else if(temp->param_ID==0x0212) ////当前设置的工作参数
{
uint8 i=0;
memset(cfg_WorkParam.cfg_WorkParamID,0,sizeof(cfg_WorkParam.cfg_WorkParamID));
cfg_WorkParam.cfg_WorkParamID_cou=0;
for(i=0;i<temp->paramValue_Len;i+=2)
{
cfg_WorkParam.cfg_WorkParamID[i/2]=(uint16)(((temp->pParam_Value)[i])<<8)+(uint16)(temp->pParam_Value)[i+1];
cfg_WorkParam.cfg_WorkParamID_cou++;
}
}
else if(temp->param_ID==0x0303) //设置ACC累计时间
{
memcpy(Last_ACC_Mileage+5,temp->pParam_Value,4);
Rst_ACC_Mileage=1;
}
else if(temp->param_ID==0x0304) //设置累计里程
{
memcpy(Last_ACC_Mileage,temp->pParam_Value,4);
Rst_ACC_Mileage=1;
}
else if(temp->param_ID==0x0211) //盲区补传数据设置
{
uint8 i=0;
if(temp->paramValue_Len>8) temp->paramValue_Len=8;
BlindSection_Cfg=0;
for(i=0;i<temp->paramValue_Len;i++) //temp->paramValue_Len==8
BlindSection_Cfg+=(unsigned long long)(((temp->pParam_Value)[i])<<(8*(8-i-1)));
}
//主中心通讯参数被修改,则更改重连标志
if(temp->param_ID==0x0200||temp->param_ID==0x0201||temp->param_ID==0x0202||temp->param_ID==0x0205)
{
if(Reconn_Flag!=1&&First_Run_Flag==0)
{
T1MAT_Init(Fpclk*((uint32)120), 0, 1, 0, 0, 1); // 120秒钟定时
Reconn_Flag=1;
}
}
FREE(p);
}
//恢复出厂值函数
uint8 Renew_Initializers(void)
{
uint8 * tempbuff=NULL;
OSMemQuery(IntBuffer_Big,&MemInfo);
if(MemInfo.OSNFree > (uint8)(SETUP_PARAMS_DATASIZE/BlockSize_Big))
{
const uint8 pageLen=0xff;
SetupParam_Item temp;
uint8 itemp=0;
tempbuff=(INT8U *)OSMemGet(IntBuffer_Big,&err);
W25X32_READ_Semphore(GetAddr(SETUP_PARAMS_SEC,0),SETUP_PARAMS_DATASIZE,tempbuff);
// 定位终端当前积分 占用两个字节
{
uint8 buff[2];
memset(buff,0,sizeof(buff));
for(itemp=0;itemp<sizeof(buff);itemp++)
buff[itemp]=(uint8)(0000>>8*(sizeof(buff)-itemp-1));
temp.param_ID=0x0000;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//定位终端密码 111111
temp.param_ID=0x0301; //定位终端密码 111111
for(itemp=0;itemp<sizeof(Password);itemp++)
Password[itemp]=(uint8)(111111>>8*(sizeof(Password)-itemp-1));
temp.pParam_Value=Password;
temp.paramValue_Len=sizeof(Password);
update(&temp,tempbuff);
//APN CMNET
temp.param_ID=0x0200; //APN CMNET
#ifdef _TW_
temp.pParam_Value=(uint8 *)("INTERNET");
temp.paramValue_Len=strlen("INTERNET");
#else
temp.pParam_Value=(uint8 *)("CMNET");
temp.paramValue_Len=strlen("CMNET");
#endif
update(&temp,tempbuff);
//中心域名 v.cheguan.com
temp.param_ID=0x0202;
//temp.pParam_Value=(uint8 *)("v.cheguan.com");
//temp.paramValue_Len=strlen("v.cheguan.com");
temp.pParam_Value=(uint8 *)("www.gttgps.cn");
temp.paramValue_Len=strlen("www.gttgps.cn");
update(&temp,tempbuff);
//主中心IP 空
{
uint8 buff[4];
memset(buff,0,sizeof(buff));
temp.param_ID=0x0201;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//副中心IP 空
{
uint8 buff[4];
memset(buff,0,sizeof(buff));
temp.param_ID=0x0203;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//副中心域名
temp.param_ID=0x0204;
temp.pParam_Value=(uint8 *)("");
temp.paramValue_Len=strlen("");
update(&temp,tempbuff);
//端口号 2000
{
uint8 buff[2];
memset(buff,0,sizeof(buff));
for(itemp=0;itemp<sizeof(buff);itemp++)
buff[itemp]=(uint8)(9987>>8*(sizeof(buff)-itemp-1)); //buff[itemp]=(uint8)(9987>>8*(sizeof(buff)-itemp-1));//
temp.param_ID=0x0205;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//车机ID 定位终端的出厂序列号
temp.param_ID=0x0702; //终端硬件序列号 使用ASCII码表示,长度小于128个字节
temp.pParam_Value=(uint8 *)HardwareSN;
temp.paramValue_Len=strlen(HardwareSN);
update(&temp,tempbuff);
//中心下发心跳间隔 根据终端上传的心跳间隔或数据间隔
SRV_HeartSlot=120;
temp.param_ID=0x0206; //中心下发心跳间隔 120秒
temp.pParam_Value=(uint8 *)&(SRV_HeartSlot);
temp.paramValue_Len=sizeof(SRV_HeartSlot);
update(&temp,tempbuff);
//定位终端心跳间隔 40秒
HeartSlot=40;
temp.param_ID=0x0209; //定位终端心跳间隔 40秒
temp.pParam_Value=(uint8 *)&HeartSlot;
temp.paramValue_Len=sizeof(HeartSlot);
update(&temp,tempbuff);
#ifdef _TW_
temp.param_ID=0x0103; //短信中心号码 106380005668
temp.pParam_Value=(uint8 *)("+886987003204");
temp.paramValue_Len=strlen("+886987003204");
update(&temp,tempbuff);
temp.param_ID=0x0102; //短信息服务中心号 +8613800250500
temp.pParam_Value=(uint8 *)("+886987003204");
temp.paramValue_Len=strlen("+886987003204");
update(&temp,tempbuff);
temp.param_ID=0x0101; //电话复位号码 02586306763
temp.pParam_Value=(uint8 *)("+886987003204");
temp.paramValue_Len=strlen("+886987003204");
update(&temp,tempbuff);
#else
//短信中心号码 106380005668
temp.param_ID=0x0103; //短信中心号码 106380005668
temp.pParam_Value=(uint8 *)("106380005668");
temp.paramValue_Len=strlen("106380005668");
update(&temp,tempbuff);
//短信息服务中心号 +8613800250500
temp.param_ID=0x0102; //短信息服务中心号 +8613800250500
temp.pParam_Value=(uint8 *)("+8613800250500");
temp.paramValue_Len=strlen("+8613800250500");
update(&temp,tempbuff);
//电话复位号码 02586306763
temp.param_ID=0x0101; //电话复位号码 02586306763
temp.pParam_Value=(uint8 *)("02586306763");
temp.paramValue_Len=strlen("02586306763");
update(&temp,tempbuff);
#endif // end of #ifdef _TW_
//IP方式和SMS方式切换间隔 //1200s
{
uint8 buff[2];
memset(buff,0,sizeof(buff));
for(itemp=0;itemp<sizeof(buff);itemp++)
buff[itemp]=(uint8)(1200>>8*(sizeof(buff)-itemp-1));
temp.param_ID=0x020F;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//协议版本号 要求根据中心下发的主协议读取协议版本号
//求助开关触点方式 常开
//数据日志记录设置 只根据工作参数上传设置间隔存储数据
{//0x02ull:只根据工作参数上传设置间隔存储数据
uint8 buff[8];
memset(buff,0,sizeof(buff));
for(itemp=0;itemp<sizeof(buff);itemp++)
buff[itemp]=(uint8)(0x02ull>>8*(sizeof(buff)-itemp-1));
temp.param_ID=0x0210;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//盲区补传数据设置 只根据压缩数据存储
/*
{
unsigned long long iii=18446744073709551615ull;
char buff[100];
sprintf(buff,"%llu",iii);
uartWrite(UART3,(uint8 *)buff,strlen(buff),NULL); //测试
}*/
{//0x08ull://3位=1表示:根据压缩数据存储
uint8 buff[8];
memset(buff,0,sizeof(buff));
for(itemp=0;itemp<sizeof(buff);itemp++)
buff[itemp]=(uint8)(0x08ull>>8*(sizeof(buff)-itemp-1));
temp.param_ID=0x0211;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//上传工作参数 默认只上传油位电压值工作参数(以压缩方式上传)
{
uint8 buff[2];
memset(buff,0,sizeof(buff));
for(itemp=0;itemp<sizeof(buff);itemp++)
buff[itemp]=(uint8)(0x0102>>8*(sizeof(buff)-itemp-1));
temp.param_ID=0x0212;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//休眠时间 0
{
uint8 buff[2];
memset(buff,0,sizeof(buff));
for(itemp=0;itemp<sizeof(buff);itemp++)
buff[itemp]=(uint8)(0>>8*(sizeof(buff)-itemp-1));
temp.param_ID=0x0309;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//关机时间 0
{
uint8 buff[2];
memset(buff,0,sizeof(buff));
for(itemp=0;itemp<sizeof(buff);itemp++)
buff[itemp]=(uint8)(0>>8*(sizeof(buff)-itemp-1));
temp.param_ID=0x030A;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//超速报警 255-255
{
uint8 buff[2];
memset(buff,0,sizeof(buff));
for(itemp=0;itemp<sizeof(buff);itemp++)
buff[itemp]=(uint8)(0xffff>>8*(sizeof(buff)-itemp-1));
temp.param_ID=0x0400;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//低速报警 255-255
{
uint8 buff[2];
memset(buff,0,sizeof(buff));
for(itemp=0;itemp<sizeof(buff);itemp++)
buff[itemp]=(uint8)(0xffff>>8*(sizeof(buff)-itemp-1));
temp.param_ID=0x0401;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//低压报警 255-255
{
uint8 buff[2];
memset(buff,0,sizeof(buff));
for(itemp=0;itemp<sizeof(buff);itemp++)
buff[itemp]=(uint8)(0xffff>>8*(sizeof(buff)-itemp-1));
temp.param_ID=0x0402;
temp.pParam_Value=buff;
temp.paramValue_Len=sizeof(buff);
update(&temp,tempbuff);
}
//IP重发次数 2
{
uint8 tempValue=2;
temp.param_ID=0x020B;
temp.pParam_Value=&tempValue;
temp.paramValue_Len=sizeof(tempValue);
update(&temp,tempbuff);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -