1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729 |
- /***************************************************************************
- *
- ****************************************************************************/
- #include <string.h>
- #include "xingan.h"
- #define PIN_CONTROL_OIL 10
- #define PIN_CONTROL_ACC 44
- XINGAN_INFO_STRUCT g_xingan_info = {0};
- extern XINGAN_GPS_INFO_STRUCT g_xingan_gps_info;
- uint32_t XinganSendData(byte* data, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type);
- byte *XinganCreateSeqnum(byte*dest, byte* src, byte len);
- uint32_t XinganSavePara();
- static BOOL g_IsPasswordOK = U8_TRUE;
- static BOOL g_isLoad = U8_FALSE;
- BOOL GetAccStat()
- {
- // byte acc_stat = ol_handle_io(PIN_CONTROL_ACC, 0, 0, OA_IO_PULL_UP_EN );
- // if(acc_stat == 0) //低电平代表ACC开启
- // {
- //ACC开
- // return TRUE;
- // }
- // else
- // {
- //ACC关
- return U8_FALSE;
- // }
- }
- static BOOL GetHighSensor1Stat()
- {
- //自定义1路高传感器状态为低
- return U8_FALSE;
-
- //自定义1路高传感器状态为高
- // return TRUE;
- }
- static BOOL GetHighSensor2Stat()
- {
- //自定义1路高传感器状态为低
- return U8_FALSE;
-
- //自定义1路高传感器状态为高
- // return TRUE;
- }
- static BOOL GetLowSensor1Stat()
- {
- //自定义1路高传感器状态为低
- return U8_FALSE;
-
- //自定义1路高传感器状态为高
- // return TRUE;
- }
- static BOOL GetLowSensor2Stat()
- {
- //自定义1路高传感器状态为低
- return U8_FALSE;
-
- //自定义1路高传感器状态为高
- // return TRUE;
- }
- static BOOL GetOilWayStat()
- {
- return g_xingan_info.IsOpenOilWay;
- }
- static BOOL GetLoginStat()
- {
- return g_xingan_info.IsXinganLogin;
- }
- static BOOL GetWarningStat()
- {
- return g_xingan_info.isOpenWarning;
- }
- static BOOL GetRobWarningStat()
- {
- return g_xingan_info.RobWarning;
- }
- BOOL GetHighSpeedWarningStat()
- {
- //正常
- //ol_debug("highSpeed = %d, speed=%d", g_xingan_info.highSpeed, HEX_2_INT32(g_xingan_gps_info.speed));
- if(g_xingan_info.highSpeed > HEX_2_INT32(g_xingan_gps_info.speed))
- {
- return U8_FALSE;
- }
- else
- {
- //没有设置超速报警值
- if(g_xingan_info.highSpeed == 0)
- {
- return U8_FALSE;
- }
-
- //超速
- return U8_TRUE;
- }
- }
- static BOOL GetStopTimeoutStat()
- {
- //停车未超时
- return U8_FALSE;
-
- //停车超时
- // return TRUE;
- }
- //电子围栏
- static BOOL GooutOfRegion()
- {
- //正常
- return U8_FALSE;
- //驶出区域
- // return TRUE;
-
- }
- //驶入
- static BOOL ComeintoRegion()
- {
- //正常
- return U8_FALSE;
- //驶入区域
- // return TRUE;
-
- }
- static BOOL PasswordIsOK()
- {
- //正常
- if(g_IsPasswordOK == U8_FALSE)
- {
- return U8_FALSE;
- }
- else
- {
- return U8_TRUE;
- }
- }
- static BOOL GprsIsLogin()
- {
- //未登陆
- if(g_xingan_info.IsGprsLogin == U8_FALSE)
- {
- return U8_FALSE;
- }
- else
- {
- //已经登陆
- return U8_TRUE;
- }
- }
- static BOOL PppIsOK()
- {
- //PPP未拨号成功
- if(g_xingan_info.IsPppOpen == U8_FALSE)
- {
- return U8_FALSE;
- }
- else
- {
- //PPP已经拨号成功
- return U8_TRUE;
- }
- }
- static BOOL CenterNeedSendCmd21()
- {
- //不需要下发21命令
- if(g_xingan_info.CenterNeedSendCmd21==U8_FALSE)
- {
- return U8_FALSE;
- }
- else
- {
- //需要下发21命令
- return U8_TRUE;
- }
- }
- static BOOL IsHandleOK()
- {
- //手柄接入
- return U8_TRUE;
-
- //手柄未接入
- // return FALSE;
- }
- static BOOL IsLcdOK()
- {
- //LCD显示屏接入
- return U8_TRUE;
-
- //LCD显示屏未接入
- // return FALSE;
- }
- //图像采集器接入
- static BOOL IsImageCollectorOK()
- {
- //图像采集器接入
- return U8_TRUE;
-
- //图像采集器未接入
- // return FALSE;
- }
- static BOOL IsFareMeterOK()
- {
- //计价器接入
- return U8_TRUE;
-
- //计价器未接入
- // return FALSE;
- }
- //语音波号器接入
- static BOOL IsVoiceDialerOK()
- {
- //语音波号器接入
- return U8_TRUE;
-
- //语音波号器未接入
- // return FALSE;
- }
- static BOOL IsForbiddenDialCall()
- {
- //未禁止打出
- return U8_FALSE;
-
- //禁止打出
- // return TRUE;
- }
- //禁止打入
- static BOOL IsForbiddenReceiveCall()
- {
- //未禁止打入
- return U8_FALSE;
-
- //禁止打入
- // return TRUE;
- }
- //禁止呼叫
- static BOOL IsForbiddenAllCalls()
- {
- //未禁止呼叫
- return U8_FALSE;
-
- //禁止呼叫
- // return TRUE;
-
- }
- byte CheckXinganPacket(byte* buf, uint32_t len)
- {
- uint32_t i;
- byte val = 0x00;
- for(i=0;i<len;i++)
- {
- val ^= buf[i];
- }
-
- return val;
- }
- uint32_t CreateXinganPacket(byte* buf, uint32_t buf_len, byte* data, uint32_t data_len)
- {
- uint32_t i=0;
- for(i=0;i<XINGAN_PACKET_HEAD_LEN;i++)
- {
- buf[i] = XINGAN_PACKET_HEAD;
- }
- memcpy(&buf[i], data, data_len);
- i+= data_len;
-
- //校验
- buf[i] = CheckXinganPacket(buf, i);
- i++;
-
- buf[i] = XINGAN_PACKET_END;
- i++;
- return i;
- }
- uint32_t Xingan_GetPosInfo1(byte* data, uint32_t len)
- {
- memset(data, 0, len);
- data[0] = g_xingan_gps_info.year;
- data[1] = g_xingan_gps_info.month;
- data[2] = g_xingan_gps_info.day;
- data[3] = g_xingan_gps_info.hour;
- data[4] = g_xingan_gps_info.minu;
- data[5] = g_xingan_gps_info.sec;
-
- data[6] = (g_xingan_gps_info.latitue>>24)&0xFF;
- data[7] = (g_xingan_gps_info.latitue>>16)&0xFF;
- data[8] = (g_xingan_gps_info.latitue>>8)&0xFF;
- data[9] = (g_xingan_gps_info.latitue)&0xFF;
-
- data[10] = (g_xingan_gps_info.longitue>>24)&0xFF;
- data[11] = (g_xingan_gps_info.longitue>>16)&0xFF;
- data[12] = (g_xingan_gps_info.longitue>>8)&0xFF;
- data[13] = (g_xingan_gps_info.longitue)&0xFF;
-
- data[14] = (g_xingan_gps_info.speed>>8)&0xFF;
- data[15] = (g_xingan_gps_info.speed)&0xFF;
-
- data[16] = (g_xingan_gps_info.aspect>>8)&0xFF;
- data[17] = (g_xingan_gps_info.aspect)&0xFF;
-
- //st;
- if(g_xingan_gps_info.isGpsValid)
- {
- data[18] |= (0x01<<7);
- }
-
- if(g_xingan_gps_info.errorReason == 0x00)
- {
- data[18] |= (0x01<<6);
- data[18] |= (0x01<<5);
- }
- else if(g_xingan_gps_info.errorReason == 0x01)//:GPS天线短路
- {
- data[18] |= (0x01<<6);
- }
- else if(g_xingan_gps_info.errorReason == 0x02)//:GPS天线开路;
- {
- data[18] |= (0x01<<5);
- }
- else if(g_xingan_gps_info.errorReason == 0x03) //0x03:GPS模块故障
- {
-
- }
-
- if(g_xingan_info.MainPowerStat ==0 )//主电源正常
- {
- data[18] |= (0x01<<4);
- data[18] |= (0x01<<3);
- }
- else if(g_xingan_info.MainPowerStat == 1)//主电源掉电
- {
- data[18] |= (0x01<<4);
- }
- else if(g_xingan_info.MainPowerStat == 2 || g_xingan_info.MainPowerStat ==3)//主电源过高或过低
- {
- data[18] |= (0x01<<3);
- }
-
- //里程数
- data[19] = (g_xingan_info.StatisticsMile>>16)&0xFF;
- data[20] = (g_xingan_info.StatisticsMile>>8)&0xFF;
- data[21] = (g_xingan_info.StatisticsMile)&0xFF;
-
- //St1:
- if(GetAccStat() == U8_FALSE)//ACC关
- {
- data[22] |= (0x01<<7);
- }
- if(GetHighSensor1Stat() == U8_FALSE)//自定义1路高传感器状态为低
- {
- data[22] |= (0x01<<6);
- }
- if(GetHighSensor2Stat() == U8_FALSE)//自定义2路高传感器状态为低
- {
- data[22] |= (0x01<<5);
- }
- if(GetLowSensor1Stat() == U8_TRUE)//自定义1路低传感器状态为高
- {
- data[22] |= (0x01<<4);
- }
- if(GetLowSensor2Stat()== U8_TRUE)//自定义2路低传感器状态为高
- {
- data[22] |= (0x01<<3);
- }
-
- if(GetOilWayStat()== U8_TRUE)//油路正常
- {
- data[22] |= (0x01<<2);
- }
-
- if(GetLoginStat() == U8_FALSE)//没有登签
- {
- data[22] |= (0x01<<1);
- }
-
- if(GetWarningStat() == U8_FALSE)//未设防
- {
- data[22] |= (0x01);
- }
-
- //st2:
- if(GetRobWarningStat()== U8_FALSE)//不为劫警报警
- {
- data[23] |= (0x01<<7);
- }
-
- if(GetHighSpeedWarningStat()== U8_FALSE)//不为超速报警
- {
- data[23] |= (0x01<<6);
- }
- if(GetStopTimeoutStat()== U8_FALSE)//不为停车超长报警
- {
- data[23] |= (0x01<<5);
- }
- if(GooutOfRegion()== U8_FALSE)//不为驶出区域报警
- {
- data[23] |= (0x01<<4);
- }
- if(ComeintoRegion()==U8_FALSE)//不为驶入区域报警
- {
- data[23] |= (0x01<<3);
- }
-
- if(PasswordIsOK()== U8_TRUE)//不为看车密码错误报警
- {
- data[23] |= (0x01<<2);
- }
-
- if(GprsIsLogin() == U8_FALSE)//不为GPRS已上线
- {
- data[23] |= (0x01<<1);
- }
-
- if(PppIsOK() == U8_FALSE)//不为终端拨号成功
- {
- data[23] |= (0x01);
- }
-
- //st3:
- if(GprsIsLogin() == U8_FALSE)//GPRS未注册
- {
- data[24] |= (0x01<<7);
- }
- if(CenterNeedSendCmd21() == U8_TRUE)//中心应下发21指令
- {
- data[24] |= (0x01<<6);
- }
- if(g_xingan_info.SendMode == XINGAN_PACKET_SEND_TCP)//TCP通讯方式
- {
- data[24] |= (0x01<<5);
- }
- //:CSQ信号状态0-31
- data[24] += g_xingan_info.CsqVal;
-
- //st4
- if(IsHandleOK()== U8_TRUE)//手柄接入
- {
- data[25] |= (0x01<<7);
- }
- if(IsLcdOK() == U8_TRUE)//LCD显示屏接入
- {
- data[25] |= (0x01<<6);
- }
- if(IsImageCollectorOK()== U8_TRUE)//图像采集器接入
- {
- data[25] |= (0x01<<5);
- }
- if(IsFareMeterOK()== U8_TRUE)//计价器接入
- {
- data[25] |= (0x01<<4);
- }
- if(IsVoiceDialerOK()==U8_TRUE)//语音波号器接入
- {
- data[25] |= (0x01<<3);
- }
- if(IsForbiddenDialCall()==U8_TRUE)//禁止打出
- {
- data[25] |= (0x01<<2);
- }
- if(IsForbiddenReceiveCall()==U8_TRUE)//禁止打入
- {
- data[25] |= (0x01<<1);
- }
- if(IsForbiddenAllCalls()==U8_TRUE)//禁止通话
- {
- data[25] |= (0x01);
- }
-
- //v1v2v3v4:终端设置状态
- //V1V2:定时发送时间
- data[26] = (g_xingan_info.timeout>>8)&0xFF;
- data[27] = (g_xingan_info.timeout)&0xFF;
-
- //V3: 停车设置时间
- data[28]= g_xingan_info.StopTimeout&0xFF;
- //V4: 超速设置时间
- data[29]= g_xingan_info.highSpeed;
- //V5; 电子围栏设置个数
- data[30]= g_xingan_info.ElectronicFenceNum;
-
- //V6: 登签
- data[31] = GetLoginStat();
- //: 定时发送图片的时间
- data[32] = 0;//
- //: 中心下发的主命令
- data[33]= g_xingan_info.CenterSendCmd;
- return 34;
- }
- uint32_t Xingan_GetPosInfo2(byte* data, uint32_t len)
- {
- memset(data, 0, len);
- data[0] = g_xingan_gps_info.year;
- data[1] = g_xingan_gps_info.month;
- data[2] = g_xingan_gps_info.day;
- data[3] = g_xingan_gps_info.hour;
- data[4] = g_xingan_gps_info.minu;
- data[5] = g_xingan_gps_info.sec;
-
- data[6] = g_xingan_gps_info.longitue>>24;
- data[7] = g_xingan_gps_info.longitue>>16;
- data[8] = g_xingan_gps_info.longitue>>8;
- data[9] = g_xingan_gps_info.longitue;
-
- data[10] = g_xingan_gps_info.latitue>>24;
- data[11] = g_xingan_gps_info.latitue>>16;
- data[12] = g_xingan_gps_info.latitue>>8;
- data[13] = g_xingan_gps_info.latitue;
-
- data[14] = g_xingan_gps_info.speed>>8;
- data[15] = g_xingan_gps_info.speed;
-
- data[16] = g_xingan_gps_info.aspect>>8;
- data[17] = g_xingan_gps_info.aspect;
-
- //st
- data[18] = g_xingan_gps_info.isGpsValid;
-
- //空重载状态:表示范围:0-1采用压缩BCD编码.
- // 1 表示重载 0 表示空载
- data[19]= g_isLoad;
-
- //登退签状态:表示范围:0-1采用压缩BCD编码。
- // 1 表示登签 0 表示退签
- data[20] = GetLoginStat();
-
- return 21;
- }
- uint32_t Xingan_GetSeqNum(byte* Seqnum, uint32_t len)
- {
- byte* seqnum = XinganCreateSeqnum(Seqnum, g_xingan_info.XINGAN_SEQNUM, XINGAN_SEQUENCE_NUMBER_LEN*2);
- //memcpy(Seqnum, XINGAN_SEQNUM, XINGAN_SEQUENCE_NUMBER_LEN);
- //ol_debug("ID=%s\r\n",g_xingan_info.XINGAN_SEQNUM);
-
- return XINGAN_SEQUENCE_NUMBER_LEN;
- }
- uint32_t Process_XinganCenter_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len=0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
-
- return XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
- }
- uint32_t Process_XinganCenterGetPosTimerout(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- //跳过终端序列号4 bytes
-
- //获取时间
- g_xingan_info.timeout = buf[4]*256 + buf[5];
- //ol_start_AppTimer( XINGAN_SENDBACK_TIMER, g_xingan_info.timeout * KAL_TICKS_1_SEC);
-
- len = Process_XinganCenter_rsp(buf, len, type);
- return len;
- }
- uint32_t Process_XinganCenterGetPosLenout(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- //跳过终端序列号4 bytes
-
- //获取距离
- g_xingan_info.lenout = buf[4]*256 + buf[5];
- g_xingan_info.lenout /= 1000;//转换为公里
- //开始统计距离
- //g_xingan_len_info.len = 0;
- //memcpy(&g_xingan_len_info.g_xingan_gps_prev_info, &g_xingan_gps_info, sizeof(XINGAN_GPS_INFO_STRUCT));
- //g_xingan_len_info.isGpsValid = FALSE;
- len = Process_XinganCenter_rsp(buf, len, type);
- return len;
- }
- uint32_t Process_XinganClientConnectReq(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
- uint32_t i=0;
- uint32_t cmd_len =0;
- data[i++] = XINGAN_PACKET_CLIENT_CMD_CONNECT;
-
- //len
- data[i++] = 0;
- data[i++] = 0x07;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //预留
- data[i++] = 0x00;
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- return XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
- }
- uint32_t Process_XinganClientSendPosData(byte* buf, uint32_t len,XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
- uint32_t i=0;
- uint32_t cmd_len=sizeof(g_xingan_info.TmpBuf);
-
- data[i++] = XINGAN_PACKET_CLIENT_SEND_POS_DATA;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
- i += Xingan_GetPosInfo1(&data[i], cmd_len);
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- return XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
- }
- //非法启动
- static BOOL IsIllegalStart()
- {
- //正常启动
- return U8_FALSE;
-
- //非法启动
- // return TRUE;
-
- }
- //非法打开
- static BOOL IsIllegalOPenDoor()
- {
- //正常打开
- return U8_FALSE;
-
- //非法打开
- // return TRUE;
-
- }
- //拖车报警
- static BOOL IsDragCar()
- {
- //正常
- return U8_FALSE;
-
- //拖车报警
- // return TRUE;
-
- }
- //应急报警
- static BOOL IsEmergencyAlarm()
- {
- //正常
- return U8_FALSE;
-
- //应急报警
- // return TRUE;
-
- }
- uint32_t Process_XinganClientSendWarnData(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len;
- data[i++] = XINGAN_PACKET_CLIENT_CMD_SEND_WARNING_DATA;
- //len
- data[i++] = 0;
- data[i++] = 0x23;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //21字节的位置数据2
- i += Xingan_GetPosInfo2(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //3字节报警状态
- if(ComeintoRegion()==U8_TRUE)//入区域报警
- {
- data[i] |= (0x01<<7);
- }
- if(GooutOfRegion()==U8_TRUE)//出区域报警
- {
- data[i] |= (0x01<<6);
- }
- if(0)//自定义低
- {
- data[i] |= (0x01<<2);
- }
- if(0)//自定义高
- {
- data[i] |= (0x01<<1);
- }
- if(IsIllegalStart()== U8_TRUE)//非法启动
- {
- data[i] |= (0x01<<1);
- }
-
- i++;
- if(IsIllegalOPenDoor() == U8_TRUE)//非法开门
- {
- data[i] |= (0x01<<7);
- }
- if(IsDragCar()==U8_TRUE)//拖车报警
- {
- data[i] |= (0x01<<6);
- }
-
- if(0)//震动报警
- {
- data[i] |= (0x01<<5);
- }
- if(0)//网关报警
- {
- data[i] |= (0x01<<4);
- }
- if(0)//断电报警
- {
- data[i] |= (0x01<<3);
- }
- if(GetStopTimeoutStat()==U8_TRUE)//停车报警(停车超时)
- {
- data[i] |= (0x01<<2);
- }
- if(GetHighSpeedWarningStat()==U8_TRUE)//超速报警
- {
- data[i] |= (0x01<<1);
- }
- if(IsEmergencyAlarm()==U8_TRUE)//应急报警
- {
- data[i] |= (0x01<<1);
- }
-
- i++;
- if(0)//怠速报警(新增)即停车未熄火
- {
- data[i] |= (0x01<<7);
- }
- if(0)//疲劳驾驶(新增)
- {
- data[i] |= (0x01<<6);
- }
- if(0)//停车状态(新增)
- {
- data[i] |= (0x01<<5);
- }
-
- //5字节报警参数
- i++;
-
- if(ComeintoRegion()==U8_TRUE
- || GooutOfRegion() == U8_TRUE)
- {
- //报警参数的第一个字节表示进出区域编号
- data[i] = 0;//;g_RegionCode;
- }
- i++;
- if(GetAccStat() == U8_FALSE)//ACC关
- {//报警参数的第二个字节第一位为ACC状态
- data[i] |= (0x01<<0);
- }
- i++;
- data[i];//第三字节
- i++;
- data[i];//第四字节
- i++;
- data[i];//第五字节
- i++;
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- return XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
- }
- uint32_t Process_XinganCenterGetPos_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t packet_len =0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_GET_POS_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- packet_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- return XinganSendData(g_xingan_info.SendBuf, packet_len, type);
- }
- uint32_t Process_XinganCenterGetStat_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len =0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_GET_STAT_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- return XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
- }
- uint32_t Process_XinganClient_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- //ol_debug("222 g_xingan_info.IsXinganLogin =%d\r\n", g_xingan_info.IsXinganLogin );
- g_xingan_info.IsXinganLogin = U8_TRUE;
- return XINGAN_PACKET_OK;
- }
- uint32_t Process_XinganCenterReset_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len=0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
-
- //关机复位...
- // ol_atcmd_begin(); //Will begin sending
- // ol_atcmd_sendstr("AT+ZPWROFF\r\n",strlen("AT+ZPWROFF\r\n"));
- // ol_atcmd_end();
- return XINGAN_PACKET_OK;
- }
- uint32_t Process_XinganCenterDefaultSet_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len=0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- // XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
-
- //恢复出厂设置
- //......
-
- return XINGAN_PACKET_OK;
- }
- uint32_t Process_XinganCenterCloseWarning_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len=0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
- g_xingan_info.isOpenWarning = U8_FALSE;
- g_xingan_info.RobWarning = U8_FALSE;
- return XINGAN_PACKET_OK;
- }
- uint32_t Process_XinganCenterOpenOilWay_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len=0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
- #ifdef __XINGAN_SMS_TEST__
- // test send open oil
- if(GetAccStat()== TRUE)
- XinganSendData("open oil ACC CLOSE", strlen("open oil ACC CLOSE"), XINGAN_PACKET_SEND_SMS);
- else
- XinganSendData("open oil ACC OPEN", strlen("open oil ACC OPEN"), XINGAN_PACKET_SEND_SMS);
- #endif
- {
- // ol_handle_io(PIN_CONTROL_OIL, 1, 0, OA_IO_PULL_IGNORE );
- g_xingan_info.IsOpenOilWay = U8_TRUE;
- #if 0
- //ol_debug("Call Num:%s", telnum);
- //拨打电话号码
- strcat((char*)g_xingan_info.TmpBuf, "ATD");
- //strcat((char*)g_xingan_info.TmpBuf, (char*)telnum);
- strcat((char*)g_xingan_info.TmpBuf, "13360518728");
- strcat((char*)g_xingan_info.TmpBuf, ";\r\n");
- // ol_atcmd_begin(); //Will begin sending
- // ol_atcmd_sendstr((char*)g_xingan_info.TmpBuf,strlen((char*)g_xingan_info.TmpBuf));
- // ol_atcmd_end();
- #endif
- }
-
- return XINGAN_PACKET_OK;
- }
- uint32_t Process_XinganCenterCloseOilWay_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len=0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
- // test send close oil
- #ifdef __XINGAN_SMS_TEST__
- if(GetAccStat()== TRUE)
- XinganSendData("close oil ACC CLOSE ", strlen("close oil ACC CLOSE"), XINGAN_PACKET_SEND_SMS);
- else
- XinganSendData("close oil ACC OPEN", strlen("close oil ACC OPEN"), XINGAN_PACKET_SEND_SMS);
- #endif
- {
- // ol_handle_io(PIN_CONTROL_OIL, 1, 1, OA_IO_PULL_IGNORE );
- g_xingan_info.IsOpenOilWay = U8_FALSE;
- }
-
- return XINGAN_PACKET_OK;
- }
- uint32_t Process_XinganCenterGetVer_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- uint32_t i=0;
- uint32_t cmd_len=0;
- uint32_t rsp_len = 0;
- byte *data = g_xingan_info.TmpBuf;
-
- memset(g_xingan_info.RecvBuf, 0, sizeof(g_xingan_info.RecvBuf));
- // ol_atcmd_begin(); //Will begin sending
- // ol_atcmd_sendstr("AT+ZVERS\r\n",strlen("AT+ZVERS\r\n"));
- // ol_atcmd_wait((char*)g_xingan_info.RecvBuf,&rsp_len,"+ZVERS:",KAL_TICKS_1_SEC);
- // ol_atcmd_end();
-
- data[i++] = XINGAN_PACKET_CENTER_CMD_GET_VER_RSP;
- //len
- data[i++] = 0;
- data[i++] = 6 + (rsp_len );
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取软件版本号
- memcpy(&data[i], &g_xingan_info.RecvBuf[0], rsp_len);
- i += rsp_len;
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
- return XINGAN_PACKET_OK;
- }
- uint32_t Process_XinganCenterDialCall_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len=0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
-
- {
- byte telnum[21] = {0};
- memset(g_xingan_info.TmpBuf,0,sizeof(g_xingan_info.TmpBuf));
- //(1)跳过4字节中断序列号
- buf = &buf[4];
- len = len -4;
-
- //(2)解析号码
- for ( i=0; i<sizeof(telnum);)
- {
- char val1 = (buf[i/2] & 0xf0) >> 4;
- char val2 = (buf[i/2] & 0x0f);
- if(val1 > 0x0a)
- {
- break;
- }
- telnum[i++] = val1 + 0x30;
- if(val2 > 0x0a)
- {
- break;
- }
- telnum[i++] = val2+ 0x30;
- }
- // ol_debug("Call Num:%s\r\n", telnum);
- //拨打电话号码
- strcat((char*)g_xingan_info.TmpBuf, "ATD");
- strcat((char*)g_xingan_info.TmpBuf, (char*)telnum);
- //strcat((char*)g_xingan_info.TmpBuf, "13360518728");
- strcat((char*)g_xingan_info.TmpBuf, ";\r\n");
- // ol_atcmd_begin(); //Will begin sending
- // ol_atcmd_sendstr((char*)g_xingan_info.TmpBuf,strlen((char*)g_xingan_info.TmpBuf));
- // ol_atcmd_end();
- }
-
- return XINGAN_PACKET_OK;
- }
- uint32_t Process_XinganCenterHighSpeedWarning_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len=0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
-
- //skip seqnum 4bytes
- g_xingan_info.highSpeed = buf[4];
- return XINGAN_PACKET_OK;
- }
- uint32_t Process_XinganCenterStatisticsMile_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len=0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
-
- //开始统计
- g_xingan_info.StatisticsMile = 0;
-
- return XINGAN_PACKET_OK;
- }
- uint32_t Process_XinganCenterIPport_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len=0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
- // ol_debug("Process_XinganCenterIPport_rsp\r\n");
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
-
- {
- uint32_t rsp_len;
- int ret;
- int j=0;
- //去掉IP端口中的引号
- memset(g_xingan_info.TmpBuf,0,sizeof(g_xingan_info.TmpBuf));
- memset(g_xingan_info.UdpIpPort,0,sizeof(g_xingan_info.UdpIpPort));
- for(i=4; i<len;i++)
- {
- if(buf[i] != '\"')
- {
- g_xingan_info.UdpIpPort[j++] = buf[i];
- }
- }
-
- //保存UDPIP和端口
- //XinganSavePara();
-
- //关闭socket
- // ol_atcmd_sendstr("AT+ZIPCLOSEU=1\r\n",strlen("AT+ZIPCLOSEU=1\r\n"));
- // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_2_SEC_2);
- if(ret !=0)
- {
- ;
- }
-
- //重新打开socket
- memset(g_xingan_info.TmpBuf,0,sizeof(g_xingan_info.TmpBuf));
- strcat((char*)g_xingan_info.TmpBuf, "AT+ZIPSETUPU=0,");
- strcat((char*)g_xingan_info.TmpBuf, (char*)g_xingan_info.UdpIpPort);
- strcat((char*)g_xingan_info.TmpBuf, "\r\n");
- // ol_atcmd_sendstr((char*)g_xingan_info.TmpBuf, strlen((char*)g_xingan_info.TmpBuf));
- // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_3_SEC);
- if(ret !=0)
- {
- ;
- }
- }
-
- return XINGAN_PACKET_OK;
- }
- uint32_t Process_XinganCenterApn_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte *data = g_xingan_info.TmpBuf;
-
- uint32_t i=0;
- uint32_t cmd_len=0;
- data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
- //len
- data[i++] = 0;
- data[i++] = 0x28;
-
- //获取序列
- i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
-
- //获取位置信息
- i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
-
- //返回响应
- cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
- XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
-
- //修改APN
- {
-
- uint32_t rsp_len;
- int zpnum_len = 0;
- int i=0;
- int ret;
-
- //关闭SOCKET
- memset(g_xingan_info.TmpBuf, 0, sizeof(g_xingan_info.TmpBuf));
- // ol_atcmd_sendstr("AT+ZIPCLOSEU=1\r\n",strlen("AT+ZIPCLOSEU=1\r\n"));
-
- // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_2_SEC_2);
- if(ret !=0)
- {
- ;
- }
-
- //关闭PPP
- memset(g_xingan_info.TmpBuf, 0, sizeof(g_xingan_info.TmpBuf));
- // ol_atcmd_sendstr("AT+ZPPPCLOSE\r\n",strlen("AT+ZPPPCLOSE\r\n"));
- // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_30_SEC);
- if(ret !=0)
- {
- ;
- }
-
- //设置ZPNUM
- memset(g_xingan_info.TmpBuf,0,sizeof(g_xingan_info.TmpBuf));
- strcat((char*)g_xingan_info.TmpBuf, "AT+ZPNUM=");
-
- zpnum_len = strlen((char*)g_xingan_info.TmpBuf);
- buf = &buf[4]; //skip seqnum 4 bytes
- for(i=0;i< (len -4);i++)
- {
- if(buf[i] == ',')
- {
- g_xingan_info.TmpBuf[zpnum_len++] = '\"';
- g_xingan_info.TmpBuf[zpnum_len++] = ',';
- g_xingan_info.TmpBuf[zpnum_len++] = '\"';
- }
- else
- {
- g_xingan_info.TmpBuf[zpnum_len++] = buf[i];
- }
- }
-
- strcat((char*)g_xingan_info.TmpBuf, "\r\n");
- // ol_atcmd_sendstr((char*)g_xingan_info.TmpBuf, strlen((char*)g_xingan_info.TmpBuf));
- // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_30_SEC);
- if(ret !=0)
- {
- ;
- }
-
- //重新打开ZPPPOPEN
- // ol_atcmd_sendstr("AT+ZPPPOPEN\r\n", strlen("AT+ZPPPOPEN\r\n"));
- // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_1_MIN);
- if(ret !=0)
- {
- ;
- }
-
- //重新打开UDP SOCKET
- memset(g_xingan_info.TmpBuf,0,sizeof(g_xingan_info.TmpBuf));
- strcat((char*)g_xingan_info.TmpBuf, "AT+ZIPSETUPU=0,");
- strcat((char*)g_xingan_info.TmpBuf, (char*)g_xingan_info.UdpIpPort);
- strcat((char*)g_xingan_info.TmpBuf, "\r\n");
- // ol_atcmd_sendstr((char*)g_xingan_info.TmpBuf, strlen((char*)g_xingan_info.TmpBuf));
- // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_30_SEC);
- // if(ret !=0)
- // {
- // ;
- // }
- }
- return XINGAN_PACKET_OK;
- }
- XinganCmd_struct XinganCmd_info[] =
- {
- {XINGAN_PACKET_CENTER_CMD_GET_POS, Process_XinganCenterGetPos_rsp},
- {XINGAN_PACKET_CENTER_CMD_GET_STAT, Process_XinganCenterGetStat_rsp},
- {XINGAN_PACKET_CENTER_CMD_RESET, Process_XinganCenterReset_rsp},
- {XINGAN_PACKET_CENTER_CMD_DEFAULT_SET, Process_XinganCenterDefaultSet_rsp},
- {XINGAN_PACKET_CENTER_CMD_GET_POS_TIMEOUT, Process_XinganCenterGetPosTimerout},
- {XINGAN_PACKET_CENTER_CMD_GET_POS_LENOUT, Process_XinganCenterGetPosLenout},
- {XINGAN_PACKET_CENTER_CMD_CLOSE_WARNING, Process_XinganCenterCloseWarning_rsp},
- {XINGAN_PACKET_CENTER_CMD_OPEN_OIL_WAY, Process_XinganCenterOpenOilWay_rsp},
- {XINGAN_PACKET_CENTER_CMD_CLOSE_OIL_WAY, Process_XinganCenterCloseOilWay_rsp},
- {XINGAN_PACKET_CENTER_CMD_GET_VER, Process_XinganCenterGetVer_rsp},
- {XINGAN_PACKET_CENTER_CMD_DIAL_CALL, Process_XinganCenterDialCall_rsp} ,
- {XINGAN_PACKET_CENTER_CMD_HIGH_SPEED_WARNING, Process_XinganCenterHighSpeedWarning_rsp},
- {XINGAN_PACKET_CENTER_CMD_STATISTICS_MILE, Process_XinganCenterStatisticsMile_rsp},
- {XINGAN_PACKET_CENTER_CMD_UDP_IPPORT, Process_XinganCenterIPport_rsp},
- {XINGAN_PACKET_CENTER_CMD_APN, Process_XinganCenterApn_rsp},
-
- {XINGAN_PACKET_CLIENT_CMD_COMMON_RSP, Process_XinganClient_rsp},
-
- {XINGAN_PACKET_CLIENT_CMD_CONNECT, Process_XinganClientConnectReq},
- {XINGAN_PACKET_CLIENT_SEND_POS_DATA, Process_XinganClientSendPosData},
- {XINGAN_PACKET_CLIENT_CMD_SEND_WARNING_DATA, Process_XinganClientSendWarnData},
-
- };
- Xingan_process_packet GetXinganProcessFun(uint32_t Cmd)
- {
- uint32_t j;
- for(j=0;j<sizeof(XinganCmd_info)/sizeof(XinganCmd_struct);j++)
- {
- if(Cmd == XinganCmd_info[j].cmd)
- {
- return XinganCmd_info[j].process_packet;
- }
- }
- return NULL;
- }
- uint32_t ParseXinganPacket(byte* buf, uint32_t buf_len, XINGAN_PACKET_SEND_MODE_ENUM type )
- {
- uint32_t i=0;
- uint32_t Cmd = 0;
- uint32_t cmd_len = 0;
- Xingan_process_packet ProcessFun;
- //判断数据包的包头是否正确
- for(i=0;i<XINGAN_PACKET_HEAD_LEN;i++)
- {
- if(buf[i] != XINGAN_PACKET_HEAD)
- {
- return XINGAN_PACKET_ERROR;
- }
- }
-
- //判断数据包的校验是否正确
- if(buf[buf_len-2] != CheckXinganPacket(buf,buf_len-2))
- {
- return XINGAN_PACKET_ERROR;
- }
-
- //判断数据包的结尾是否正确
- if(buf[buf_len-1] != XINGAN_PACKET_END)
- {
- return XINGAN_PACKET_ERROR;
- }
- //解析当前命令
- Cmd = buf[i++];
- g_xingan_info.CenterSendCmd = Cmd;
-
- //获取数据包的长度
- cmd_len = (buf[i++]<<8);
- cmd_len += buf[i++];
- // ol_debug("ParseXinganPacket cmd=%02X\r\n", Cmd);
-
- ProcessFun = GetXinganProcessFun(Cmd);
- if(ProcessFun !=NULL)
- {
- ProcessFun(&buf[i], cmd_len - 2 , type);
- }
-
- return XINGAN_PACKET_OK;
- }
- static uint32 g_TimerFlag = 0;
- BOOL XinganSetBit(byte bit, BOOL val)
- {
- if(bit >= 32)
- {
- return U8_FALSE;
- }
- if(val == U8_TRUE)
- {
- g_TimerFlag |= (0x01<< bit);
- }
- else
- {
- g_TimerFlag &= ~(0x01<<bit);
- }
- return U8_TRUE;
- }
- BOOL XinganGetBit(byte bit)
- {
- if( bit >= 32 )
- {
- return U8_FALSE;
- }
- if ( (g_TimerFlag & (0x01<<bit)) == ( 0xFFFFFFFF & (0x01<<bit)))
- {
- return U8_TRUE;
- }
- else
- {
- return U8_FALSE;
- }
- }
- //生成终端序列号
- byte *XinganCreateSeqnum(byte*dest, byte* src, byte len)
- {
- byte tmp1[4]={0};
- int i=0;
- int j=0;
- if(len != 8)
- return NULL;
-
- for(i=0;i<len;)
- {
- if(src[i] > '9' || src[i] < '0')
- return NULL;
-
- tmp1[j] = src[i++] - '0';
- tmp1[j] = (tmp1[j]*10) + src[i++] - '0';
- j++;
- }
- #if 0
- tmp1[0] = 0x51;
- tmp1[1] = 0xD2;
- tmp1[2] = 0xD3;
- tmp1[3] = 0x54;
- #else
- tmp1[1] += 0x80;
- tmp1[2] += 0x80;
- #endif
- memcpy(dest, tmp1, XINGAN_SEQUENCE_NUMBER_LEN);
- return dest;
- }
- #define XINGAN_PARA_FILE "xingan_para.txt"
- uint32_t XinganReadPara(void)
- {
- #if 1
- int len = 0;
- memset(g_xingan_info.TmpBuf, 0, sizeof(g_xingan_info.TmpBuf));
- // len = ol_file_read(XINGAN_PARA_FILE, (char*)g_xingan_info.TmpBuf, 0);
- if(len != 0xFFFFFFFF && len > XINGAN_SEQUENCE_NUMBER_LEN)
- {
- // memcpy(g_xingan_info.XINGAN_SEQNUM, g_xingan_info.TmpBuf, XINGAN_SEQUENCE_NUMBER_LEN);
- // memcpy(g_xingan_info.UdpIpPort, & g_xingan_info.TmpBuf[XINGAN_SEQUENCE_NUMBER_LEN], len - XINGAN_SEQUENCE_NUMBER_LEN);
- return XINGAN_PACKET_OK;
- }
-
- return XINGAN_PACKET_ERROR;
- #else
- uint32_t rsp_len;
- static char buf_t[16];
- int ret = 0;
-
- memset(buf_t,0,sizeof(buf_t));
-
- // ol_atcmd_begin();
- // ol_atcmd_sendstr("AT+GSN\r\n",strlen("AT+GSN\r\n"));
- // ret = ol_atcmd_wait(buf_t,&rsp_len,"\r\n",200);
- if(ret == 0)
- {
-
- memcpy(g_xingan_info.XINGAN_SEQNUM, buf_t+7, XINGAN_SEQUENCE_NUMBER_LEN);
- }
- // ol_atcmd_end();//发送结束
-
- return XINGAN_PACKET_OK;
- #endif
- }
- uint32_t XinganSavePara()
- {
- #if 1
- int len = 0;
- //保存终端序列号
- memcpy(g_xingan_info.TmpBuf, g_xingan_info.XINGAN_SEQNUM, XINGAN_SEQUENCE_NUMBER_LEN*2);
-
- //保存UDP IP PORT
- len = strlen((char*)g_xingan_info.UdpIpPort);
- memcpy(&g_xingan_info.TmpBuf[XINGAN_SEQUENCE_NUMBER_LEN] ,g_xingan_info.UdpIpPort, len);
- len += XINGAN_SEQUENCE_NUMBER_LEN;
- // ol_file_write(XINGAN_PARA_FILE, (char*)g_xingan_info.TmpBuf, len, 0);
- #endif
- return XINGAN_PACKET_OK;
- }
- typedef struct xingan_tmp_buf_struct
- {
- byte buf[50];
- uint32_t len;
- }xingan_tmp_buf_struct;
- //static uint32_t xingan_tmp_buf_count = 0;
- //static xingan_tmp_buf_struct xingan_tmp_buf[1500] = {0};
- uint32_t XinganSendData(byte* data, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
- {
- byte cmd[32]={0};
- byte buf[20]={0};
- int ret = 0;
- uint32_t rsp_len;
- int i = 0;
- // ol_atcmd_begin(); //Will begin sending
- if(type == XINGAN_PACKET_SEND_UDP)
- {
- // if ( g_xingan_info.IsPppOpen == TRUE && xingan_tmp_buf_count != 0)
- // {
- // while(xingan_tmp_buf_count >0)
- // {
- // sprintf((char*)cmd, "AT+ZIPSENDU=0,%d\r\n", len);
- // //ol_atcmd_sendstr((char*)cmd,strlen((char*)cmd));
- //
- // //ret = ol_atcmd_wait((char*)buf,&rsp_len,">",KAL_TICKS_30_SEC);
- // if(ret !=0)
- // {
- // goto ERROR;
- // }
- //
- // //ol_atcmd_sendstr((char*)xingan_tmp_buf[xingan_tmp_buf_count-1].buf,xingan_tmp_buf[xingan_tmp_buf_count-1].len);
- // //ret = ol_atcmd_wait((char*)buf,&rsp_len,"+ZIPSENDU:OK",KAL_TICKS_30_SEC);
- // if(ret !=0)
- // {
- // goto ERROR;
- // }
- //
- // xingan_tmp_buf_count --;
- // }
- // }
- // else if(g_xingan_info.IsPppOpen == FALSE)
- // {
- // memcpy(xingan_tmp_buf[xingan_tmp_buf_count].buf, data, len);
- // xingan_tmp_buf[xingan_tmp_buf_count].len = len;
- // xingan_tmp_buf_count++;
- // }
- // else
- // {
- // //ol_debug("Will send AT cmd,len = %d \r\n", len);
- //
- // sprintf((char*)cmd, "AT+ZIPSENDU=0,%d\r\n", len);
- // //ol_atcmd_sendstr((char*)cmd,strlen((char*)cmd));
- //
- // //ret = ol_atcmd_wait((char*)buf,&rsp_len,">",KAL_TICKS_30_SEC);
- // if(ret !=0)
- // {
- // goto ERROR;
- // }
- // //ol_atcmd_sendstr((char*)data,len);
- //
- // //ol_debug("Will send AT cmd3 \r\n");
- //
- // }
- }
- else if(type == XINGAN_PACKET_SEND_TCP)
- {
- sprintf((char*)cmd, "AT+ZIPSEND=0,%d\r\n", len);
- //ol_atcmd_sendstr((char*)cmd,strlen((char*)cmd));
-
- // ret = ol_atcmd_wait((char*)buf,&rsp_len,">",KAL_TICKS_30_SEC);
- if(ret !=0)
- {
- goto ERROR;
- }
-
- //ol_atcmd_sendstr((char*)data,len);
- }
- else if(type == XINGAN_PACKET_SEND_SMS)
- {
- //sprintf((char*)cmd, "AT+CMGS=\"%s\"\r", (char*)g_xingan_info.PhoneNum);
- //ol_atcmd_sendstr((char*)cmd,strlen((char*)cmd));
-
- //ret = ol_atcmd_wait((char*)buf,&rsp_len,">",KAL_TICKS_30_SEC);
- //if(ret !=0)
- // {
- // goto ERROR;
- // }
-
- //发送短信结束符0x1A
- // cmd[0] = 0x1A;
- //ol_atcmd_sendstr((char*)data,len);
- // ol_atcmd_sendstr((char*)cmd,1);
- }
-
- //ret = ol_atcmd_wait((char*)buf,&rsp_len,"OK",KAL_TICKS_1_MIN);
- if(ret != 0)
- {
- goto ERROR;
- }
-
- // ol_atcmd_end();//发送结束
- return XINGAN_PACKET_OK;
-
- ERROR:
- // ol_atcmd_end();//发送结束
- return XINGAN_PACKET_ERROR;
- }
- void XinganInfoInit(void)
- {
- g_xingan_info.CsqVal = 31;
- g_xingan_info.CenterNeedSendCmd21 = U8_TRUE;
- g_xingan_info.isOpenWarning= U8_TRUE;
- g_xingan_info.IsOpenOilWay = U8_TRUE;
- g_xingan_info.SendMode = XINGAN_PACKET_SEND_TCP;
- g_xingan_info.highSpeed = 0;
- g_xingan_info.timeout = 30;
- g_xingan_info.StatisticsMile =0;
- g_xingan_info.RobWarning = U8_FALSE;
- g_xingan_info.StopTimeout = 0;
- g_xingan_info.lenout =0;
- g_xingan_info.IsGprsLogin = U8_FALSE;
- g_xingan_info.IsPppOpen = U8_FALSE;
- g_xingan_info.ElectronicFenceNum=0;
- g_xingan_info.MainPowerStat = 0;
-
-
- //XinganReadPara();
-
- strcpy((char*)g_xingan_info.XINGAN_SEQNUM,"82838485");
-
- //if(g_xingan_info.UdpIpPort[0] == '\0')
- // {
- //strcpy((char*)g_xingan_info.UdpIpPort, "60.191.49.126,8127"); //启程后台
- // strcpy((char*)g_xingan_info.UdpIpPort, "60.175.226.20,8127"); //est
- // }
-
- // if(g_xingan_info.PhoneNum[0] == '\0')
- // {
- // strcpy((char*)g_xingan_info.PhoneNum, "13360518728");
- // }
- //ol_debug("seqnum :%s", g_xingan_info.XINGAN_SEQNUM);
- //ol_debug("udp ip port :%s", g_xingan_info.UdpIpPort);
- }
|