xingan.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  1. /***************************************************************************
  2. *
  3. ****************************************************************************/
  4. #include <string.h>
  5. #include "xingan.h"
  6. #define PIN_CONTROL_OIL 10
  7. #define PIN_CONTROL_ACC 44
  8. XINGAN_INFO_STRUCT g_xingan_info = {0};
  9. extern XINGAN_GPS_INFO_STRUCT g_xingan_gps_info;
  10. uint32_t XinganSendData(byte* data, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type);
  11. byte *XinganCreateSeqnum(byte*dest, byte* src, byte len);
  12. uint32_t XinganSavePara();
  13. static BOOL g_IsPasswordOK = U8_TRUE;
  14. static BOOL g_isLoad = U8_FALSE;
  15. BOOL GetAccStat()
  16. {
  17. // byte acc_stat = ol_handle_io(PIN_CONTROL_ACC, 0, 0, OA_IO_PULL_UP_EN );
  18. // if(acc_stat == 0) //低电平代表ACC开启
  19. // {
  20. //ACC开
  21. // return TRUE;
  22. // }
  23. // else
  24. // {
  25. //ACC关
  26. return U8_FALSE;
  27. // }
  28. }
  29. static BOOL GetHighSensor1Stat()
  30. {
  31. //自定义1路高传感器状态为低
  32. return U8_FALSE;
  33. //自定义1路高传感器状态为高
  34. // return TRUE;
  35. }
  36. static BOOL GetHighSensor2Stat()
  37. {
  38. //自定义1路高传感器状态为低
  39. return U8_FALSE;
  40. //自定义1路高传感器状态为高
  41. // return TRUE;
  42. }
  43. static BOOL GetLowSensor1Stat()
  44. {
  45. //自定义1路高传感器状态为低
  46. return U8_FALSE;
  47. //自定义1路高传感器状态为高
  48. // return TRUE;
  49. }
  50. static BOOL GetLowSensor2Stat()
  51. {
  52. //自定义1路高传感器状态为低
  53. return U8_FALSE;
  54. //自定义1路高传感器状态为高
  55. // return TRUE;
  56. }
  57. static BOOL GetOilWayStat()
  58. {
  59. return g_xingan_info.IsOpenOilWay;
  60. }
  61. static BOOL GetLoginStat()
  62. {
  63. return g_xingan_info.IsXinganLogin;
  64. }
  65. static BOOL GetWarningStat()
  66. {
  67. return g_xingan_info.isOpenWarning;
  68. }
  69. static BOOL GetRobWarningStat()
  70. {
  71. return g_xingan_info.RobWarning;
  72. }
  73. BOOL GetHighSpeedWarningStat()
  74. {
  75. //正常
  76. //ol_debug("highSpeed = %d, speed=%d", g_xingan_info.highSpeed, HEX_2_INT32(g_xingan_gps_info.speed));
  77. if(g_xingan_info.highSpeed > HEX_2_INT32(g_xingan_gps_info.speed))
  78. {
  79. return U8_FALSE;
  80. }
  81. else
  82. {
  83. //没有设置超速报警值
  84. if(g_xingan_info.highSpeed == 0)
  85. {
  86. return U8_FALSE;
  87. }
  88. //超速
  89. return U8_TRUE;
  90. }
  91. }
  92. static BOOL GetStopTimeoutStat()
  93. {
  94. //停车未超时
  95. return U8_FALSE;
  96. //停车超时
  97. // return TRUE;
  98. }
  99. //电子围栏
  100. static BOOL GooutOfRegion()
  101. {
  102. //正常
  103. return U8_FALSE;
  104. //驶出区域
  105. // return TRUE;
  106. }
  107. //驶入
  108. static BOOL ComeintoRegion()
  109. {
  110. //正常
  111. return U8_FALSE;
  112. //驶入区域
  113. // return TRUE;
  114. }
  115. static BOOL PasswordIsOK()
  116. {
  117. //正常
  118. if(g_IsPasswordOK == U8_FALSE)
  119. {
  120. return U8_FALSE;
  121. }
  122. else
  123. {
  124. return U8_TRUE;
  125. }
  126. }
  127. static BOOL GprsIsLogin()
  128. {
  129. //未登陆
  130. if(g_xingan_info.IsGprsLogin == U8_FALSE)
  131. {
  132. return U8_FALSE;
  133. }
  134. else
  135. {
  136. //已经登陆
  137. return U8_TRUE;
  138. }
  139. }
  140. static BOOL PppIsOK()
  141. {
  142. //PPP未拨号成功
  143. if(g_xingan_info.IsPppOpen == U8_FALSE)
  144. {
  145. return U8_FALSE;
  146. }
  147. else
  148. {
  149. //PPP已经拨号成功
  150. return U8_TRUE;
  151. }
  152. }
  153. static BOOL CenterNeedSendCmd21()
  154. {
  155. //不需要下发21命令
  156. if(g_xingan_info.CenterNeedSendCmd21==U8_FALSE)
  157. {
  158. return U8_FALSE;
  159. }
  160. else
  161. {
  162. //需要下发21命令
  163. return U8_TRUE;
  164. }
  165. }
  166. static BOOL IsHandleOK()
  167. {
  168. //手柄接入
  169. return U8_TRUE;
  170. //手柄未接入
  171. // return FALSE;
  172. }
  173. static BOOL IsLcdOK()
  174. {
  175. //LCD显示屏接入
  176. return U8_TRUE;
  177. //LCD显示屏未接入
  178. // return FALSE;
  179. }
  180. //图像采集器接入
  181. static BOOL IsImageCollectorOK()
  182. {
  183. //图像采集器接入
  184. return U8_TRUE;
  185. //图像采集器未接入
  186. // return FALSE;
  187. }
  188. static BOOL IsFareMeterOK()
  189. {
  190. //计价器接入
  191. return U8_TRUE;
  192. //计价器未接入
  193. // return FALSE;
  194. }
  195. //语音波号器接入
  196. static BOOL IsVoiceDialerOK()
  197. {
  198. //语音波号器接入
  199. return U8_TRUE;
  200. //语音波号器未接入
  201. // return FALSE;
  202. }
  203. static BOOL IsForbiddenDialCall()
  204. {
  205. //未禁止打出
  206. return U8_FALSE;
  207. //禁止打出
  208. // return TRUE;
  209. }
  210. //禁止打入
  211. static BOOL IsForbiddenReceiveCall()
  212. {
  213. //未禁止打入
  214. return U8_FALSE;
  215. //禁止打入
  216. // return TRUE;
  217. }
  218. //禁止呼叫
  219. static BOOL IsForbiddenAllCalls()
  220. {
  221. //未禁止呼叫
  222. return U8_FALSE;
  223. //禁止呼叫
  224. // return TRUE;
  225. }
  226. byte CheckXinganPacket(byte* buf, uint32_t len)
  227. {
  228. uint32_t i;
  229. byte val = 0x00;
  230. for(i=0;i<len;i++)
  231. {
  232. val ^= buf[i];
  233. }
  234. return val;
  235. }
  236. uint32_t CreateXinganPacket(byte* buf, uint32_t buf_len, byte* data, uint32_t data_len)
  237. {
  238. uint32_t i=0;
  239. for(i=0;i<XINGAN_PACKET_HEAD_LEN;i++)
  240. {
  241. buf[i] = XINGAN_PACKET_HEAD;
  242. }
  243. memcpy(&buf[i], data, data_len);
  244. i+= data_len;
  245. //校验
  246. buf[i] = CheckXinganPacket(buf, i);
  247. i++;
  248. buf[i] = XINGAN_PACKET_END;
  249. i++;
  250. return i;
  251. }
  252. uint32_t Xingan_GetPosInfo1(byte* data, uint32_t len)
  253. {
  254. memset(data, 0, len);
  255. data[0] = g_xingan_gps_info.year;
  256. data[1] = g_xingan_gps_info.month;
  257. data[2] = g_xingan_gps_info.day;
  258. data[3] = g_xingan_gps_info.hour;
  259. data[4] = g_xingan_gps_info.minu;
  260. data[5] = g_xingan_gps_info.sec;
  261. data[6] = (g_xingan_gps_info.latitue>>24)&0xFF;
  262. data[7] = (g_xingan_gps_info.latitue>>16)&0xFF;
  263. data[8] = (g_xingan_gps_info.latitue>>8)&0xFF;
  264. data[9] = (g_xingan_gps_info.latitue)&0xFF;
  265. data[10] = (g_xingan_gps_info.longitue>>24)&0xFF;
  266. data[11] = (g_xingan_gps_info.longitue>>16)&0xFF;
  267. data[12] = (g_xingan_gps_info.longitue>>8)&0xFF;
  268. data[13] = (g_xingan_gps_info.longitue)&0xFF;
  269. data[14] = (g_xingan_gps_info.speed>>8)&0xFF;
  270. data[15] = (g_xingan_gps_info.speed)&0xFF;
  271. data[16] = (g_xingan_gps_info.aspect>>8)&0xFF;
  272. data[17] = (g_xingan_gps_info.aspect)&0xFF;
  273. //st;
  274. if(g_xingan_gps_info.isGpsValid)
  275. {
  276. data[18] |= (0x01<<7);
  277. }
  278. if(g_xingan_gps_info.errorReason == 0x00)
  279. {
  280. data[18] |= (0x01<<6);
  281. data[18] |= (0x01<<5);
  282. }
  283. else if(g_xingan_gps_info.errorReason == 0x01)//:GPS天线短路
  284. {
  285. data[18] |= (0x01<<6);
  286. }
  287. else if(g_xingan_gps_info.errorReason == 0x02)//:GPS天线开路;
  288. {
  289. data[18] |= (0x01<<5);
  290. }
  291. else if(g_xingan_gps_info.errorReason == 0x03) //0x03:GPS模块故障
  292. {
  293. }
  294. if(g_xingan_info.MainPowerStat ==0 )//主电源正常
  295. {
  296. data[18] |= (0x01<<4);
  297. data[18] |= (0x01<<3);
  298. }
  299. else if(g_xingan_info.MainPowerStat == 1)//主电源掉电
  300. {
  301. data[18] |= (0x01<<4);
  302. }
  303. else if(g_xingan_info.MainPowerStat == 2 || g_xingan_info.MainPowerStat ==3)//主电源过高或过低
  304. {
  305. data[18] |= (0x01<<3);
  306. }
  307. //里程数
  308. data[19] = (g_xingan_info.StatisticsMile>>16)&0xFF;
  309. data[20] = (g_xingan_info.StatisticsMile>>8)&0xFF;
  310. data[21] = (g_xingan_info.StatisticsMile)&0xFF;
  311. //St1:
  312. if(GetAccStat() == U8_FALSE)//ACC关
  313. {
  314. data[22] |= (0x01<<7);
  315. }
  316. if(GetHighSensor1Stat() == U8_FALSE)//自定义1路高传感器状态为低
  317. {
  318. data[22] |= (0x01<<6);
  319. }
  320. if(GetHighSensor2Stat() == U8_FALSE)//自定义2路高传感器状态为低
  321. {
  322. data[22] |= (0x01<<5);
  323. }
  324. if(GetLowSensor1Stat() == U8_TRUE)//自定义1路低传感器状态为高
  325. {
  326. data[22] |= (0x01<<4);
  327. }
  328. if(GetLowSensor2Stat()== U8_TRUE)//自定义2路低传感器状态为高
  329. {
  330. data[22] |= (0x01<<3);
  331. }
  332. if(GetOilWayStat()== U8_TRUE)//油路正常
  333. {
  334. data[22] |= (0x01<<2);
  335. }
  336. if(GetLoginStat() == U8_FALSE)//没有登签
  337. {
  338. data[22] |= (0x01<<1);
  339. }
  340. if(GetWarningStat() == U8_FALSE)//未设防
  341. {
  342. data[22] |= (0x01);
  343. }
  344. //st2:
  345. if(GetRobWarningStat()== U8_FALSE)//不为劫警报警
  346. {
  347. data[23] |= (0x01<<7);
  348. }
  349. if(GetHighSpeedWarningStat()== U8_FALSE)//不为超速报警
  350. {
  351. data[23] |= (0x01<<6);
  352. }
  353. if(GetStopTimeoutStat()== U8_FALSE)//不为停车超长报警
  354. {
  355. data[23] |= (0x01<<5);
  356. }
  357. if(GooutOfRegion()== U8_FALSE)//不为驶出区域报警
  358. {
  359. data[23] |= (0x01<<4);
  360. }
  361. if(ComeintoRegion()==U8_FALSE)//不为驶入区域报警
  362. {
  363. data[23] |= (0x01<<3);
  364. }
  365. if(PasswordIsOK()== U8_TRUE)//不为看车密码错误报警
  366. {
  367. data[23] |= (0x01<<2);
  368. }
  369. if(GprsIsLogin() == U8_FALSE)//不为GPRS已上线
  370. {
  371. data[23] |= (0x01<<1);
  372. }
  373. if(PppIsOK() == U8_FALSE)//不为终端拨号成功
  374. {
  375. data[23] |= (0x01);
  376. }
  377. //st3:
  378. if(GprsIsLogin() == U8_FALSE)//GPRS未注册
  379. {
  380. data[24] |= (0x01<<7);
  381. }
  382. if(CenterNeedSendCmd21() == U8_TRUE)//中心应下发21指令
  383. {
  384. data[24] |= (0x01<<6);
  385. }
  386. if(g_xingan_info.SendMode == XINGAN_PACKET_SEND_TCP)//TCP通讯方式
  387. {
  388. data[24] |= (0x01<<5);
  389. }
  390. //:CSQ信号状态0-31
  391. data[24] += g_xingan_info.CsqVal;
  392. //st4
  393. if(IsHandleOK()== U8_TRUE)//手柄接入
  394. {
  395. data[25] |= (0x01<<7);
  396. }
  397. if(IsLcdOK() == U8_TRUE)//LCD显示屏接入
  398. {
  399. data[25] |= (0x01<<6);
  400. }
  401. if(IsImageCollectorOK()== U8_TRUE)//图像采集器接入
  402. {
  403. data[25] |= (0x01<<5);
  404. }
  405. if(IsFareMeterOK()== U8_TRUE)//计价器接入
  406. {
  407. data[25] |= (0x01<<4);
  408. }
  409. if(IsVoiceDialerOK()==U8_TRUE)//语音波号器接入
  410. {
  411. data[25] |= (0x01<<3);
  412. }
  413. if(IsForbiddenDialCall()==U8_TRUE)//禁止打出
  414. {
  415. data[25] |= (0x01<<2);
  416. }
  417. if(IsForbiddenReceiveCall()==U8_TRUE)//禁止打入
  418. {
  419. data[25] |= (0x01<<1);
  420. }
  421. if(IsForbiddenAllCalls()==U8_TRUE)//禁止通话
  422. {
  423. data[25] |= (0x01);
  424. }
  425. //v1v2v3v4:终端设置状态
  426. //V1V2:定时发送时间
  427. data[26] = (g_xingan_info.timeout>>8)&0xFF;
  428. data[27] = (g_xingan_info.timeout)&0xFF;
  429. //V3: 停车设置时间
  430. data[28]= g_xingan_info.StopTimeout&0xFF;
  431. //V4: 超速设置时间
  432. data[29]= g_xingan_info.highSpeed;
  433. //V5; 电子围栏设置个数
  434. data[30]= g_xingan_info.ElectronicFenceNum;
  435. //V6: 登签
  436. data[31] = GetLoginStat();
  437. //: 定时发送图片的时间
  438. data[32] = 0;//
  439. //: 中心下发的主命令
  440. data[33]= g_xingan_info.CenterSendCmd;
  441. return 34;
  442. }
  443. uint32_t Xingan_GetPosInfo2(byte* data, uint32_t len)
  444. {
  445. memset(data, 0, len);
  446. data[0] = g_xingan_gps_info.year;
  447. data[1] = g_xingan_gps_info.month;
  448. data[2] = g_xingan_gps_info.day;
  449. data[3] = g_xingan_gps_info.hour;
  450. data[4] = g_xingan_gps_info.minu;
  451. data[5] = g_xingan_gps_info.sec;
  452. data[6] = g_xingan_gps_info.longitue>>24;
  453. data[7] = g_xingan_gps_info.longitue>>16;
  454. data[8] = g_xingan_gps_info.longitue>>8;
  455. data[9] = g_xingan_gps_info.longitue;
  456. data[10] = g_xingan_gps_info.latitue>>24;
  457. data[11] = g_xingan_gps_info.latitue>>16;
  458. data[12] = g_xingan_gps_info.latitue>>8;
  459. data[13] = g_xingan_gps_info.latitue;
  460. data[14] = g_xingan_gps_info.speed>>8;
  461. data[15] = g_xingan_gps_info.speed;
  462. data[16] = g_xingan_gps_info.aspect>>8;
  463. data[17] = g_xingan_gps_info.aspect;
  464. //st
  465. data[18] = g_xingan_gps_info.isGpsValid;
  466. //空重载状态:表示范围:0-1采用压缩BCD编码.
  467. // 1 表示重载 0 表示空载
  468. data[19]= g_isLoad;
  469. //登退签状态:表示范围:0-1采用压缩BCD编码。
  470. // 1 表示登签 0 表示退签
  471. data[20] = GetLoginStat();
  472. return 21;
  473. }
  474. uint32_t Xingan_GetSeqNum(byte* Seqnum, uint32_t len)
  475. {
  476. byte* seqnum = XinganCreateSeqnum(Seqnum, g_xingan_info.XINGAN_SEQNUM, XINGAN_SEQUENCE_NUMBER_LEN*2);
  477. //memcpy(Seqnum, XINGAN_SEQNUM, XINGAN_SEQUENCE_NUMBER_LEN);
  478. //ol_debug("ID=%s\r\n",g_xingan_info.XINGAN_SEQNUM);
  479. return XINGAN_SEQUENCE_NUMBER_LEN;
  480. }
  481. uint32_t Process_XinganCenter_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  482. {
  483. byte *data = g_xingan_info.TmpBuf;
  484. uint32_t i=0;
  485. uint32_t cmd_len=0;
  486. data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
  487. //len
  488. data[i++] = 0;
  489. data[i++] = 0x28;
  490. //获取序列
  491. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  492. //获取位置信息
  493. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  494. //返回响应
  495. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  496. return XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  497. }
  498. uint32_t Process_XinganCenterGetPosTimerout(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  499. {
  500. //跳过终端序列号4 bytes
  501. //获取时间
  502. g_xingan_info.timeout = buf[4]*256 + buf[5];
  503. //ol_start_AppTimer( XINGAN_SENDBACK_TIMER, g_xingan_info.timeout * KAL_TICKS_1_SEC);
  504. len = Process_XinganCenter_rsp(buf, len, type);
  505. return len;
  506. }
  507. uint32_t Process_XinganCenterGetPosLenout(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  508. {
  509. //跳过终端序列号4 bytes
  510. //获取距离
  511. g_xingan_info.lenout = buf[4]*256 + buf[5];
  512. g_xingan_info.lenout /= 1000;//转换为公里
  513. //开始统计距离
  514. //g_xingan_len_info.len = 0;
  515. //memcpy(&g_xingan_len_info.g_xingan_gps_prev_info, &g_xingan_gps_info, sizeof(XINGAN_GPS_INFO_STRUCT));
  516. //g_xingan_len_info.isGpsValid = FALSE;
  517. len = Process_XinganCenter_rsp(buf, len, type);
  518. return len;
  519. }
  520. uint32_t Process_XinganClientConnectReq(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  521. {
  522. byte *data = g_xingan_info.TmpBuf;
  523. uint32_t i=0;
  524. uint32_t cmd_len =0;
  525. data[i++] = XINGAN_PACKET_CLIENT_CMD_CONNECT;
  526. //len
  527. data[i++] = 0;
  528. data[i++] = 0x07;
  529. //获取序列
  530. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  531. //预留
  532. data[i++] = 0x00;
  533. //返回响应
  534. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  535. return XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  536. }
  537. uint32_t Process_XinganClientSendPosData(byte* buf, uint32_t len,XINGAN_PACKET_SEND_MODE_ENUM type)
  538. {
  539. byte *data = g_xingan_info.TmpBuf;
  540. uint32_t i=0;
  541. uint32_t cmd_len=sizeof(g_xingan_info.TmpBuf);
  542. data[i++] = XINGAN_PACKET_CLIENT_SEND_POS_DATA;
  543. //len
  544. data[i++] = 0;
  545. data[i++] = 0x28;
  546. //获取序列
  547. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  548. i += Xingan_GetPosInfo1(&data[i], cmd_len);
  549. //返回响应
  550. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  551. return XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  552. }
  553. //非法启动
  554. static BOOL IsIllegalStart()
  555. {
  556. //正常启动
  557. return U8_FALSE;
  558. //非法启动
  559. // return TRUE;
  560. }
  561. //非法打开
  562. static BOOL IsIllegalOPenDoor()
  563. {
  564. //正常打开
  565. return U8_FALSE;
  566. //非法打开
  567. // return TRUE;
  568. }
  569. //拖车报警
  570. static BOOL IsDragCar()
  571. {
  572. //正常
  573. return U8_FALSE;
  574. //拖车报警
  575. // return TRUE;
  576. }
  577. //应急报警
  578. static BOOL IsEmergencyAlarm()
  579. {
  580. //正常
  581. return U8_FALSE;
  582. //应急报警
  583. // return TRUE;
  584. }
  585. uint32_t Process_XinganClientSendWarnData(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  586. {
  587. byte *data = g_xingan_info.TmpBuf;
  588. uint32_t i=0;
  589. uint32_t cmd_len;
  590. data[i++] = XINGAN_PACKET_CLIENT_CMD_SEND_WARNING_DATA;
  591. //len
  592. data[i++] = 0;
  593. data[i++] = 0x23;
  594. //获取序列
  595. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  596. //21字节的位置数据2
  597. i += Xingan_GetPosInfo2(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  598. //3字节报警状态
  599. if(ComeintoRegion()==U8_TRUE)//入区域报警
  600. {
  601. data[i] |= (0x01<<7);
  602. }
  603. if(GooutOfRegion()==U8_TRUE)//出区域报警
  604. {
  605. data[i] |= (0x01<<6);
  606. }
  607. if(0)//自定义低
  608. {
  609. data[i] |= (0x01<<2);
  610. }
  611. if(0)//自定义高
  612. {
  613. data[i] |= (0x01<<1);
  614. }
  615. if(IsIllegalStart()== U8_TRUE)//非法启动
  616. {
  617. data[i] |= (0x01<<1);
  618. }
  619. i++;
  620. if(IsIllegalOPenDoor() == U8_TRUE)//非法开门
  621. {
  622. data[i] |= (0x01<<7);
  623. }
  624. if(IsDragCar()==U8_TRUE)//拖车报警
  625. {
  626. data[i] |= (0x01<<6);
  627. }
  628. if(0)//震动报警
  629. {
  630. data[i] |= (0x01<<5);
  631. }
  632. if(0)//网关报警
  633. {
  634. data[i] |= (0x01<<4);
  635. }
  636. if(0)//断电报警
  637. {
  638. data[i] |= (0x01<<3);
  639. }
  640. if(GetStopTimeoutStat()==U8_TRUE)//停车报警(停车超时)
  641. {
  642. data[i] |= (0x01<<2);
  643. }
  644. if(GetHighSpeedWarningStat()==U8_TRUE)//超速报警
  645. {
  646. data[i] |= (0x01<<1);
  647. }
  648. if(IsEmergencyAlarm()==U8_TRUE)//应急报警
  649. {
  650. data[i] |= (0x01<<1);
  651. }
  652. i++;
  653. if(0)//怠速报警(新增)即停车未熄火
  654. {
  655. data[i] |= (0x01<<7);
  656. }
  657. if(0)//疲劳驾驶(新增)
  658. {
  659. data[i] |= (0x01<<6);
  660. }
  661. if(0)//停车状态(新增)
  662. {
  663. data[i] |= (0x01<<5);
  664. }
  665. //5字节报警参数
  666. i++;
  667. if(ComeintoRegion()==U8_TRUE
  668. || GooutOfRegion() == U8_TRUE)
  669. {
  670. //报警参数的第一个字节表示进出区域编号
  671. data[i] = 0;//;g_RegionCode;
  672. }
  673. i++;
  674. if(GetAccStat() == U8_FALSE)//ACC关
  675. {//报警参数的第二个字节第一位为ACC状态
  676. data[i] |= (0x01<<0);
  677. }
  678. i++;
  679. data[i];//第三字节
  680. i++;
  681. data[i];//第四字节
  682. i++;
  683. data[i];//第五字节
  684. i++;
  685. //返回响应
  686. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  687. return XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  688. }
  689. uint32_t Process_XinganCenterGetPos_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  690. {
  691. byte *data = g_xingan_info.TmpBuf;
  692. uint32_t i=0;
  693. uint32_t packet_len =0;
  694. data[i++] = XINGAN_PACKET_CENTER_CMD_GET_POS_RSP;
  695. //len
  696. data[i++] = 0;
  697. data[i++] = 0x28;
  698. //获取序列
  699. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  700. //获取位置信息
  701. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  702. //返回响应
  703. packet_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  704. return XinganSendData(g_xingan_info.SendBuf, packet_len, type);
  705. }
  706. uint32_t Process_XinganCenterGetStat_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
  707. {
  708. byte *data = g_xingan_info.TmpBuf;
  709. uint32_t i=0;
  710. uint32_t cmd_len =0;
  711. data[i++] = XINGAN_PACKET_CENTER_CMD_GET_STAT_RSP;
  712. //len
  713. data[i++] = 0;
  714. data[i++] = 0x28;
  715. //获取序列
  716. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  717. //获取位置信息
  718. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  719. //返回响应
  720. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  721. return XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  722. }
  723. uint32_t Process_XinganClient_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  724. {
  725. //ol_debug("222 g_xingan_info.IsXinganLogin =%d\r\n", g_xingan_info.IsXinganLogin );
  726. g_xingan_info.IsXinganLogin = U8_TRUE;
  727. return XINGAN_PACKET_OK;
  728. }
  729. uint32_t Process_XinganCenterReset_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
  730. {
  731. byte *data = g_xingan_info.TmpBuf;
  732. uint32_t i=0;
  733. uint32_t cmd_len=0;
  734. data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
  735. //len
  736. data[i++] = 0;
  737. data[i++] = 0x28;
  738. //获取序列
  739. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  740. //获取位置信息
  741. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  742. //返回响应
  743. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  744. XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  745. //关机复位...
  746. // ol_atcmd_begin(); //Will begin sending
  747. // ol_atcmd_sendstr("AT+ZPWROFF\r\n",strlen("AT+ZPWROFF\r\n"));
  748. // ol_atcmd_end();
  749. return XINGAN_PACKET_OK;
  750. }
  751. uint32_t Process_XinganCenterDefaultSet_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
  752. {
  753. byte *data = g_xingan_info.TmpBuf;
  754. uint32_t i=0;
  755. uint32_t cmd_len=0;
  756. data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
  757. //len
  758. data[i++] = 0;
  759. data[i++] = 0x28;
  760. //获取序列
  761. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  762. //获取位置信息
  763. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  764. //返回响应
  765. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  766. // XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  767. //恢复出厂设置
  768. //......
  769. return XINGAN_PACKET_OK;
  770. }
  771. uint32_t Process_XinganCenterCloseWarning_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
  772. {
  773. byte *data = g_xingan_info.TmpBuf;
  774. uint32_t i=0;
  775. uint32_t cmd_len=0;
  776. data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
  777. //len
  778. data[i++] = 0;
  779. data[i++] = 0x28;
  780. //获取序列
  781. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  782. //获取位置信息
  783. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  784. //返回响应
  785. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  786. XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  787. g_xingan_info.isOpenWarning = U8_FALSE;
  788. g_xingan_info.RobWarning = U8_FALSE;
  789. return XINGAN_PACKET_OK;
  790. }
  791. uint32_t Process_XinganCenterOpenOilWay_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
  792. {
  793. byte *data = g_xingan_info.TmpBuf;
  794. uint32_t i=0;
  795. uint32_t cmd_len=0;
  796. data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
  797. //len
  798. data[i++] = 0;
  799. data[i++] = 0x28;
  800. //获取序列
  801. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  802. //获取位置信息
  803. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  804. //返回响应
  805. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  806. XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  807. #ifdef __XINGAN_SMS_TEST__
  808. // test send open oil
  809. if(GetAccStat()== TRUE)
  810. XinganSendData("open oil ACC CLOSE", strlen("open oil ACC CLOSE"), XINGAN_PACKET_SEND_SMS);
  811. else
  812. XinganSendData("open oil ACC OPEN", strlen("open oil ACC OPEN"), XINGAN_PACKET_SEND_SMS);
  813. #endif
  814. {
  815. // ol_handle_io(PIN_CONTROL_OIL, 1, 0, OA_IO_PULL_IGNORE );
  816. g_xingan_info.IsOpenOilWay = U8_TRUE;
  817. #if 0
  818. //ol_debug("Call Num:%s", telnum);
  819. //拨打电话号码
  820. strcat((char*)g_xingan_info.TmpBuf, "ATD");
  821. //strcat((char*)g_xingan_info.TmpBuf, (char*)telnum);
  822. strcat((char*)g_xingan_info.TmpBuf, "13360518728");
  823. strcat((char*)g_xingan_info.TmpBuf, ";\r\n");
  824. // ol_atcmd_begin(); //Will begin sending
  825. // ol_atcmd_sendstr((char*)g_xingan_info.TmpBuf,strlen((char*)g_xingan_info.TmpBuf));
  826. // ol_atcmd_end();
  827. #endif
  828. }
  829. return XINGAN_PACKET_OK;
  830. }
  831. uint32_t Process_XinganCenterCloseOilWay_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
  832. {
  833. byte *data = g_xingan_info.TmpBuf;
  834. uint32_t i=0;
  835. uint32_t cmd_len=0;
  836. data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
  837. //len
  838. data[i++] = 0;
  839. data[i++] = 0x28;
  840. //获取序列
  841. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  842. //获取位置信息
  843. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  844. //返回响应
  845. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  846. XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  847. // test send close oil
  848. #ifdef __XINGAN_SMS_TEST__
  849. if(GetAccStat()== TRUE)
  850. XinganSendData("close oil ACC CLOSE ", strlen("close oil ACC CLOSE"), XINGAN_PACKET_SEND_SMS);
  851. else
  852. XinganSendData("close oil ACC OPEN", strlen("close oil ACC OPEN"), XINGAN_PACKET_SEND_SMS);
  853. #endif
  854. {
  855. // ol_handle_io(PIN_CONTROL_OIL, 1, 1, OA_IO_PULL_IGNORE );
  856. g_xingan_info.IsOpenOilWay = U8_FALSE;
  857. }
  858. return XINGAN_PACKET_OK;
  859. }
  860. uint32_t Process_XinganCenterGetVer_rsp(byte* buf, uint32_t len , XINGAN_PACKET_SEND_MODE_ENUM type)
  861. {
  862. uint32_t i=0;
  863. uint32_t cmd_len=0;
  864. uint32_t rsp_len = 0;
  865. byte *data = g_xingan_info.TmpBuf;
  866. memset(g_xingan_info.RecvBuf, 0, sizeof(g_xingan_info.RecvBuf));
  867. // ol_atcmd_begin(); //Will begin sending
  868. // ol_atcmd_sendstr("AT+ZVERS\r\n",strlen("AT+ZVERS\r\n"));
  869. // ol_atcmd_wait((char*)g_xingan_info.RecvBuf,&rsp_len,"+ZVERS:",KAL_TICKS_1_SEC);
  870. // ol_atcmd_end();
  871. data[i++] = XINGAN_PACKET_CENTER_CMD_GET_VER_RSP;
  872. //len
  873. data[i++] = 0;
  874. data[i++] = 6 + (rsp_len );
  875. //获取序列
  876. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  877. //获取软件版本号
  878. memcpy(&data[i], &g_xingan_info.RecvBuf[0], rsp_len);
  879. i += rsp_len;
  880. //返回响应
  881. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  882. XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  883. return XINGAN_PACKET_OK;
  884. }
  885. uint32_t Process_XinganCenterDialCall_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  886. {
  887. byte *data = g_xingan_info.TmpBuf;
  888. uint32_t i=0;
  889. uint32_t cmd_len=0;
  890. data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
  891. //len
  892. data[i++] = 0;
  893. data[i++] = 0x28;
  894. //获取序列
  895. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  896. //获取位置信息
  897. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  898. //返回响应
  899. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  900. XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  901. {
  902. byte telnum[21] = {0};
  903. memset(g_xingan_info.TmpBuf,0,sizeof(g_xingan_info.TmpBuf));
  904. //(1)跳过4字节中断序列号
  905. buf = &buf[4];
  906. len = len -4;
  907. //(2)解析号码
  908. for ( i=0; i<sizeof(telnum);)
  909. {
  910. char val1 = (buf[i/2] & 0xf0) >> 4;
  911. char val2 = (buf[i/2] & 0x0f);
  912. if(val1 > 0x0a)
  913. {
  914. break;
  915. }
  916. telnum[i++] = val1 + 0x30;
  917. if(val2 > 0x0a)
  918. {
  919. break;
  920. }
  921. telnum[i++] = val2+ 0x30;
  922. }
  923. // ol_debug("Call Num:%s\r\n", telnum);
  924. //拨打电话号码
  925. strcat((char*)g_xingan_info.TmpBuf, "ATD");
  926. strcat((char*)g_xingan_info.TmpBuf, (char*)telnum);
  927. //strcat((char*)g_xingan_info.TmpBuf, "13360518728");
  928. strcat((char*)g_xingan_info.TmpBuf, ";\r\n");
  929. // ol_atcmd_begin(); //Will begin sending
  930. // ol_atcmd_sendstr((char*)g_xingan_info.TmpBuf,strlen((char*)g_xingan_info.TmpBuf));
  931. // ol_atcmd_end();
  932. }
  933. return XINGAN_PACKET_OK;
  934. }
  935. uint32_t Process_XinganCenterHighSpeedWarning_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  936. {
  937. byte *data = g_xingan_info.TmpBuf;
  938. uint32_t i=0;
  939. uint32_t cmd_len=0;
  940. data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
  941. //len
  942. data[i++] = 0;
  943. data[i++] = 0x28;
  944. //获取序列
  945. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  946. //获取位置信息
  947. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  948. //返回响应
  949. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  950. XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  951. //skip seqnum 4bytes
  952. g_xingan_info.highSpeed = buf[4];
  953. return XINGAN_PACKET_OK;
  954. }
  955. uint32_t Process_XinganCenterStatisticsMile_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  956. {
  957. byte *data = g_xingan_info.TmpBuf;
  958. uint32_t i=0;
  959. uint32_t cmd_len=0;
  960. data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
  961. //len
  962. data[i++] = 0;
  963. data[i++] = 0x28;
  964. //获取序列
  965. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  966. //获取位置信息
  967. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  968. //返回响应
  969. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  970. XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  971. //开始统计
  972. g_xingan_info.StatisticsMile = 0;
  973. return XINGAN_PACKET_OK;
  974. }
  975. uint32_t Process_XinganCenterIPport_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  976. {
  977. byte *data = g_xingan_info.TmpBuf;
  978. uint32_t i=0;
  979. uint32_t cmd_len=0;
  980. data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
  981. //len
  982. data[i++] = 0;
  983. data[i++] = 0x28;
  984. // ol_debug("Process_XinganCenterIPport_rsp\r\n");
  985. //获取序列
  986. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  987. //获取位置信息
  988. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  989. //返回响应
  990. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  991. XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  992. {
  993. uint32_t rsp_len;
  994. int ret;
  995. int j=0;
  996. //去掉IP端口中的引号
  997. memset(g_xingan_info.TmpBuf,0,sizeof(g_xingan_info.TmpBuf));
  998. memset(g_xingan_info.UdpIpPort,0,sizeof(g_xingan_info.UdpIpPort));
  999. for(i=4; i<len;i++)
  1000. {
  1001. if(buf[i] != '\"')
  1002. {
  1003. g_xingan_info.UdpIpPort[j++] = buf[i];
  1004. }
  1005. }
  1006. //保存UDPIP和端口
  1007. //XinganSavePara();
  1008. //关闭socket
  1009. // ol_atcmd_sendstr("AT+ZIPCLOSEU=1\r\n",strlen("AT+ZIPCLOSEU=1\r\n"));
  1010. // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_2_SEC_2);
  1011. if(ret !=0)
  1012. {
  1013. ;
  1014. }
  1015. //重新打开socket
  1016. memset(g_xingan_info.TmpBuf,0,sizeof(g_xingan_info.TmpBuf));
  1017. strcat((char*)g_xingan_info.TmpBuf, "AT+ZIPSETUPU=0,");
  1018. strcat((char*)g_xingan_info.TmpBuf, (char*)g_xingan_info.UdpIpPort);
  1019. strcat((char*)g_xingan_info.TmpBuf, "\r\n");
  1020. // ol_atcmd_sendstr((char*)g_xingan_info.TmpBuf, strlen((char*)g_xingan_info.TmpBuf));
  1021. // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_3_SEC);
  1022. if(ret !=0)
  1023. {
  1024. ;
  1025. }
  1026. }
  1027. return XINGAN_PACKET_OK;
  1028. }
  1029. uint32_t Process_XinganCenterApn_rsp(byte* buf, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  1030. {
  1031. byte *data = g_xingan_info.TmpBuf;
  1032. uint32_t i=0;
  1033. uint32_t cmd_len=0;
  1034. data[i++] = XINGAN_PACKET_CENTER_CMD_COMMON_RSP;
  1035. //len
  1036. data[i++] = 0;
  1037. data[i++] = 0x28;
  1038. //获取序列
  1039. i += Xingan_GetSeqNum(&data[i], XINGAN_SEQUENCE_NUMBER_LEN);
  1040. //获取位置信息
  1041. i += Xingan_GetPosInfo1(&data[i], sizeof(g_xingan_info.TmpBuf)-i);
  1042. //返回响应
  1043. cmd_len = CreateXinganPacket(g_xingan_info.SendBuf, XINGAN_PACKET_MAX_LEN, data, i);
  1044. XinganSendData(g_xingan_info.SendBuf, cmd_len, type);
  1045. //修改APN
  1046. {
  1047. uint32_t rsp_len;
  1048. int zpnum_len = 0;
  1049. int i=0;
  1050. int ret;
  1051. //关闭SOCKET
  1052. memset(g_xingan_info.TmpBuf, 0, sizeof(g_xingan_info.TmpBuf));
  1053. // ol_atcmd_sendstr("AT+ZIPCLOSEU=1\r\n",strlen("AT+ZIPCLOSEU=1\r\n"));
  1054. // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_2_SEC_2);
  1055. if(ret !=0)
  1056. {
  1057. ;
  1058. }
  1059. //关闭PPP
  1060. memset(g_xingan_info.TmpBuf, 0, sizeof(g_xingan_info.TmpBuf));
  1061. // ol_atcmd_sendstr("AT+ZPPPCLOSE\r\n",strlen("AT+ZPPPCLOSE\r\n"));
  1062. // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_30_SEC);
  1063. if(ret !=0)
  1064. {
  1065. ;
  1066. }
  1067. //设置ZPNUM
  1068. memset(g_xingan_info.TmpBuf,0,sizeof(g_xingan_info.TmpBuf));
  1069. strcat((char*)g_xingan_info.TmpBuf, "AT+ZPNUM=");
  1070. zpnum_len = strlen((char*)g_xingan_info.TmpBuf);
  1071. buf = &buf[4]; //skip seqnum 4 bytes
  1072. for(i=0;i< (len -4);i++)
  1073. {
  1074. if(buf[i] == ',')
  1075. {
  1076. g_xingan_info.TmpBuf[zpnum_len++] = '\"';
  1077. g_xingan_info.TmpBuf[zpnum_len++] = ',';
  1078. g_xingan_info.TmpBuf[zpnum_len++] = '\"';
  1079. }
  1080. else
  1081. {
  1082. g_xingan_info.TmpBuf[zpnum_len++] = buf[i];
  1083. }
  1084. }
  1085. strcat((char*)g_xingan_info.TmpBuf, "\r\n");
  1086. // ol_atcmd_sendstr((char*)g_xingan_info.TmpBuf, strlen((char*)g_xingan_info.TmpBuf));
  1087. // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_30_SEC);
  1088. if(ret !=0)
  1089. {
  1090. ;
  1091. }
  1092. //重新打开ZPPPOPEN
  1093. // ol_atcmd_sendstr("AT+ZPPPOPEN\r\n", strlen("AT+ZPPPOPEN\r\n"));
  1094. // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_1_MIN);
  1095. if(ret !=0)
  1096. {
  1097. ;
  1098. }
  1099. //重新打开UDP SOCKET
  1100. memset(g_xingan_info.TmpBuf,0,sizeof(g_xingan_info.TmpBuf));
  1101. strcat((char*)g_xingan_info.TmpBuf, "AT+ZIPSETUPU=0,");
  1102. strcat((char*)g_xingan_info.TmpBuf, (char*)g_xingan_info.UdpIpPort);
  1103. strcat((char*)g_xingan_info.TmpBuf, "\r\n");
  1104. // ol_atcmd_sendstr((char*)g_xingan_info.TmpBuf, strlen((char*)g_xingan_info.TmpBuf));
  1105. // ret = ol_atcmd_wait((char*)g_xingan_info.TmpBuf,&rsp_len,"OK",KAL_TICKS_30_SEC);
  1106. // if(ret !=0)
  1107. // {
  1108. // ;
  1109. // }
  1110. }
  1111. return XINGAN_PACKET_OK;
  1112. }
  1113. XinganCmd_struct XinganCmd_info[] =
  1114. {
  1115. {XINGAN_PACKET_CENTER_CMD_GET_POS, Process_XinganCenterGetPos_rsp},
  1116. {XINGAN_PACKET_CENTER_CMD_GET_STAT, Process_XinganCenterGetStat_rsp},
  1117. {XINGAN_PACKET_CENTER_CMD_RESET, Process_XinganCenterReset_rsp},
  1118. {XINGAN_PACKET_CENTER_CMD_DEFAULT_SET, Process_XinganCenterDefaultSet_rsp},
  1119. {XINGAN_PACKET_CENTER_CMD_GET_POS_TIMEOUT, Process_XinganCenterGetPosTimerout},
  1120. {XINGAN_PACKET_CENTER_CMD_GET_POS_LENOUT, Process_XinganCenterGetPosLenout},
  1121. {XINGAN_PACKET_CENTER_CMD_CLOSE_WARNING, Process_XinganCenterCloseWarning_rsp},
  1122. {XINGAN_PACKET_CENTER_CMD_OPEN_OIL_WAY, Process_XinganCenterOpenOilWay_rsp},
  1123. {XINGAN_PACKET_CENTER_CMD_CLOSE_OIL_WAY, Process_XinganCenterCloseOilWay_rsp},
  1124. {XINGAN_PACKET_CENTER_CMD_GET_VER, Process_XinganCenterGetVer_rsp},
  1125. {XINGAN_PACKET_CENTER_CMD_DIAL_CALL, Process_XinganCenterDialCall_rsp} ,
  1126. {XINGAN_PACKET_CENTER_CMD_HIGH_SPEED_WARNING, Process_XinganCenterHighSpeedWarning_rsp},
  1127. {XINGAN_PACKET_CENTER_CMD_STATISTICS_MILE, Process_XinganCenterStatisticsMile_rsp},
  1128. {XINGAN_PACKET_CENTER_CMD_UDP_IPPORT, Process_XinganCenterIPport_rsp},
  1129. {XINGAN_PACKET_CENTER_CMD_APN, Process_XinganCenterApn_rsp},
  1130. {XINGAN_PACKET_CLIENT_CMD_COMMON_RSP, Process_XinganClient_rsp},
  1131. {XINGAN_PACKET_CLIENT_CMD_CONNECT, Process_XinganClientConnectReq},
  1132. {XINGAN_PACKET_CLIENT_SEND_POS_DATA, Process_XinganClientSendPosData},
  1133. {XINGAN_PACKET_CLIENT_CMD_SEND_WARNING_DATA, Process_XinganClientSendWarnData},
  1134. };
  1135. Xingan_process_packet GetXinganProcessFun(uint32_t Cmd)
  1136. {
  1137. uint32_t j;
  1138. for(j=0;j<sizeof(XinganCmd_info)/sizeof(XinganCmd_struct);j++)
  1139. {
  1140. if(Cmd == XinganCmd_info[j].cmd)
  1141. {
  1142. return XinganCmd_info[j].process_packet;
  1143. }
  1144. }
  1145. return NULL;
  1146. }
  1147. uint32_t ParseXinganPacket(byte* buf, uint32_t buf_len, XINGAN_PACKET_SEND_MODE_ENUM type )
  1148. {
  1149. uint32_t i=0;
  1150. uint32_t Cmd = 0;
  1151. uint32_t cmd_len = 0;
  1152. Xingan_process_packet ProcessFun;
  1153. //判断数据包的包头是否正确
  1154. for(i=0;i<XINGAN_PACKET_HEAD_LEN;i++)
  1155. {
  1156. if(buf[i] != XINGAN_PACKET_HEAD)
  1157. {
  1158. return XINGAN_PACKET_ERROR;
  1159. }
  1160. }
  1161. //判断数据包的校验是否正确
  1162. if(buf[buf_len-2] != CheckXinganPacket(buf,buf_len-2))
  1163. {
  1164. return XINGAN_PACKET_ERROR;
  1165. }
  1166. //判断数据包的结尾是否正确
  1167. if(buf[buf_len-1] != XINGAN_PACKET_END)
  1168. {
  1169. return XINGAN_PACKET_ERROR;
  1170. }
  1171. //解析当前命令
  1172. Cmd = buf[i++];
  1173. g_xingan_info.CenterSendCmd = Cmd;
  1174. //获取数据包的长度
  1175. cmd_len = (buf[i++]<<8);
  1176. cmd_len += buf[i++];
  1177. // ol_debug("ParseXinganPacket cmd=%02X\r\n", Cmd);
  1178. ProcessFun = GetXinganProcessFun(Cmd);
  1179. if(ProcessFun !=NULL)
  1180. {
  1181. ProcessFun(&buf[i], cmd_len - 2 , type);
  1182. }
  1183. return XINGAN_PACKET_OK;
  1184. }
  1185. static uint32 g_TimerFlag = 0;
  1186. BOOL XinganSetBit(byte bit, BOOL val)
  1187. {
  1188. if(bit >= 32)
  1189. {
  1190. return U8_FALSE;
  1191. }
  1192. if(val == U8_TRUE)
  1193. {
  1194. g_TimerFlag |= (0x01<< bit);
  1195. }
  1196. else
  1197. {
  1198. g_TimerFlag &= ~(0x01<<bit);
  1199. }
  1200. return U8_TRUE;
  1201. }
  1202. BOOL XinganGetBit(byte bit)
  1203. {
  1204. if( bit >= 32 )
  1205. {
  1206. return U8_FALSE;
  1207. }
  1208. if ( (g_TimerFlag & (0x01<<bit)) == ( 0xFFFFFFFF & (0x01<<bit)))
  1209. {
  1210. return U8_TRUE;
  1211. }
  1212. else
  1213. {
  1214. return U8_FALSE;
  1215. }
  1216. }
  1217. //生成终端序列号
  1218. byte *XinganCreateSeqnum(byte*dest, byte* src, byte len)
  1219. {
  1220. byte tmp1[4]={0};
  1221. int i=0;
  1222. int j=0;
  1223. if(len != 8)
  1224. return NULL;
  1225. for(i=0;i<len;)
  1226. {
  1227. if(src[i] > '9' || src[i] < '0')
  1228. return NULL;
  1229. tmp1[j] = src[i++] - '0';
  1230. tmp1[j] = (tmp1[j]*10) + src[i++] - '0';
  1231. j++;
  1232. }
  1233. #if 0
  1234. tmp1[0] = 0x51;
  1235. tmp1[1] = 0xD2;
  1236. tmp1[2] = 0xD3;
  1237. tmp1[3] = 0x54;
  1238. #else
  1239. tmp1[1] += 0x80;
  1240. tmp1[2] += 0x80;
  1241. #endif
  1242. memcpy(dest, tmp1, XINGAN_SEQUENCE_NUMBER_LEN);
  1243. return dest;
  1244. }
  1245. #define XINGAN_PARA_FILE "xingan_para.txt"
  1246. uint32_t XinganReadPara(void)
  1247. {
  1248. #if 1
  1249. int len = 0;
  1250. memset(g_xingan_info.TmpBuf, 0, sizeof(g_xingan_info.TmpBuf));
  1251. // len = ol_file_read(XINGAN_PARA_FILE, (char*)g_xingan_info.TmpBuf, 0);
  1252. if(len != 0xFFFFFFFF && len > XINGAN_SEQUENCE_NUMBER_LEN)
  1253. {
  1254. // memcpy(g_xingan_info.XINGAN_SEQNUM, g_xingan_info.TmpBuf, XINGAN_SEQUENCE_NUMBER_LEN);
  1255. // memcpy(g_xingan_info.UdpIpPort, & g_xingan_info.TmpBuf[XINGAN_SEQUENCE_NUMBER_LEN], len - XINGAN_SEQUENCE_NUMBER_LEN);
  1256. return XINGAN_PACKET_OK;
  1257. }
  1258. return XINGAN_PACKET_ERROR;
  1259. #else
  1260. uint32_t rsp_len;
  1261. static char buf_t[16];
  1262. int ret = 0;
  1263. memset(buf_t,0,sizeof(buf_t));
  1264. // ol_atcmd_begin();
  1265. // ol_atcmd_sendstr("AT+GSN\r\n",strlen("AT+GSN\r\n"));
  1266. // ret = ol_atcmd_wait(buf_t,&rsp_len,"\r\n",200);
  1267. if(ret == 0)
  1268. {
  1269. memcpy(g_xingan_info.XINGAN_SEQNUM, buf_t+7, XINGAN_SEQUENCE_NUMBER_LEN);
  1270. }
  1271. // ol_atcmd_end();//发送结束
  1272. return XINGAN_PACKET_OK;
  1273. #endif
  1274. }
  1275. uint32_t XinganSavePara()
  1276. {
  1277. #if 1
  1278. int len = 0;
  1279. //保存终端序列号
  1280. memcpy(g_xingan_info.TmpBuf, g_xingan_info.XINGAN_SEQNUM, XINGAN_SEQUENCE_NUMBER_LEN*2);
  1281. //保存UDP IP PORT
  1282. len = strlen((char*)g_xingan_info.UdpIpPort);
  1283. memcpy(&g_xingan_info.TmpBuf[XINGAN_SEQUENCE_NUMBER_LEN] ,g_xingan_info.UdpIpPort, len);
  1284. len += XINGAN_SEQUENCE_NUMBER_LEN;
  1285. // ol_file_write(XINGAN_PARA_FILE, (char*)g_xingan_info.TmpBuf, len, 0);
  1286. #endif
  1287. return XINGAN_PACKET_OK;
  1288. }
  1289. typedef struct xingan_tmp_buf_struct
  1290. {
  1291. byte buf[50];
  1292. uint32_t len;
  1293. }xingan_tmp_buf_struct;
  1294. //static uint32_t xingan_tmp_buf_count = 0;
  1295. //static xingan_tmp_buf_struct xingan_tmp_buf[1500] = {0};
  1296. uint32_t XinganSendData(byte* data, uint32_t len, XINGAN_PACKET_SEND_MODE_ENUM type)
  1297. {
  1298. byte cmd[32]={0};
  1299. byte buf[20]={0};
  1300. int ret = 0;
  1301. uint32_t rsp_len;
  1302. int i = 0;
  1303. // ol_atcmd_begin(); //Will begin sending
  1304. if(type == XINGAN_PACKET_SEND_UDP)
  1305. {
  1306. // if ( g_xingan_info.IsPppOpen == TRUE && xingan_tmp_buf_count != 0)
  1307. // {
  1308. // while(xingan_tmp_buf_count >0)
  1309. // {
  1310. // sprintf((char*)cmd, "AT+ZIPSENDU=0,%d\r\n", len);
  1311. // //ol_atcmd_sendstr((char*)cmd,strlen((char*)cmd));
  1312. //
  1313. // //ret = ol_atcmd_wait((char*)buf,&rsp_len,">",KAL_TICKS_30_SEC);
  1314. // if(ret !=0)
  1315. // {
  1316. // goto ERROR;
  1317. // }
  1318. //
  1319. // //ol_atcmd_sendstr((char*)xingan_tmp_buf[xingan_tmp_buf_count-1].buf,xingan_tmp_buf[xingan_tmp_buf_count-1].len);
  1320. // //ret = ol_atcmd_wait((char*)buf,&rsp_len,"+ZIPSENDU:OK",KAL_TICKS_30_SEC);
  1321. // if(ret !=0)
  1322. // {
  1323. // goto ERROR;
  1324. // }
  1325. //
  1326. // xingan_tmp_buf_count --;
  1327. // }
  1328. // }
  1329. // else if(g_xingan_info.IsPppOpen == FALSE)
  1330. // {
  1331. // memcpy(xingan_tmp_buf[xingan_tmp_buf_count].buf, data, len);
  1332. // xingan_tmp_buf[xingan_tmp_buf_count].len = len;
  1333. // xingan_tmp_buf_count++;
  1334. // }
  1335. // else
  1336. // {
  1337. // //ol_debug("Will send AT cmd,len = %d \r\n", len);
  1338. //
  1339. // sprintf((char*)cmd, "AT+ZIPSENDU=0,%d\r\n", len);
  1340. // //ol_atcmd_sendstr((char*)cmd,strlen((char*)cmd));
  1341. //
  1342. // //ret = ol_atcmd_wait((char*)buf,&rsp_len,">",KAL_TICKS_30_SEC);
  1343. // if(ret !=0)
  1344. // {
  1345. // goto ERROR;
  1346. // }
  1347. // //ol_atcmd_sendstr((char*)data,len);
  1348. //
  1349. // //ol_debug("Will send AT cmd3 \r\n");
  1350. //
  1351. // }
  1352. }
  1353. else if(type == XINGAN_PACKET_SEND_TCP)
  1354. {
  1355. sprintf((char*)cmd, "AT+ZIPSEND=0,%d\r\n", len);
  1356. //ol_atcmd_sendstr((char*)cmd,strlen((char*)cmd));
  1357. // ret = ol_atcmd_wait((char*)buf,&rsp_len,">",KAL_TICKS_30_SEC);
  1358. if(ret !=0)
  1359. {
  1360. goto ERROR;
  1361. }
  1362. //ol_atcmd_sendstr((char*)data,len);
  1363. }
  1364. else if(type == XINGAN_PACKET_SEND_SMS)
  1365. {
  1366. //sprintf((char*)cmd, "AT+CMGS=\"%s\"\r", (char*)g_xingan_info.PhoneNum);
  1367. //ol_atcmd_sendstr((char*)cmd,strlen((char*)cmd));
  1368. //ret = ol_atcmd_wait((char*)buf,&rsp_len,">",KAL_TICKS_30_SEC);
  1369. //if(ret !=0)
  1370. // {
  1371. // goto ERROR;
  1372. // }
  1373. //发送短信结束符0x1A
  1374. // cmd[0] = 0x1A;
  1375. //ol_atcmd_sendstr((char*)data,len);
  1376. // ol_atcmd_sendstr((char*)cmd,1);
  1377. }
  1378. //ret = ol_atcmd_wait((char*)buf,&rsp_len,"OK",KAL_TICKS_1_MIN);
  1379. if(ret != 0)
  1380. {
  1381. goto ERROR;
  1382. }
  1383. // ol_atcmd_end();//发送结束
  1384. return XINGAN_PACKET_OK;
  1385. ERROR:
  1386. // ol_atcmd_end();//发送结束
  1387. return XINGAN_PACKET_ERROR;
  1388. }
  1389. void XinganInfoInit(void)
  1390. {
  1391. g_xingan_info.CsqVal = 31;
  1392. g_xingan_info.CenterNeedSendCmd21 = U8_TRUE;
  1393. g_xingan_info.isOpenWarning= U8_TRUE;
  1394. g_xingan_info.IsOpenOilWay = U8_TRUE;
  1395. g_xingan_info.SendMode = XINGAN_PACKET_SEND_TCP;
  1396. g_xingan_info.highSpeed = 0;
  1397. g_xingan_info.timeout = 30;
  1398. g_xingan_info.StatisticsMile =0;
  1399. g_xingan_info.RobWarning = U8_FALSE;
  1400. g_xingan_info.StopTimeout = 0;
  1401. g_xingan_info.lenout =0;
  1402. g_xingan_info.IsGprsLogin = U8_FALSE;
  1403. g_xingan_info.IsPppOpen = U8_FALSE;
  1404. g_xingan_info.ElectronicFenceNum=0;
  1405. g_xingan_info.MainPowerStat = 0;
  1406. //XinganReadPara();
  1407. strcpy((char*)g_xingan_info.XINGAN_SEQNUM,"82838485");
  1408. //if(g_xingan_info.UdpIpPort[0] == '\0')
  1409. // {
  1410. //strcpy((char*)g_xingan_info.UdpIpPort, "60.191.49.126,8127"); //启程后台
  1411. // strcpy((char*)g_xingan_info.UdpIpPort, "60.175.226.20,8127"); //est
  1412. // }
  1413. // if(g_xingan_info.PhoneNum[0] == '\0')
  1414. // {
  1415. // strcpy((char*)g_xingan_info.PhoneNum, "13360518728");
  1416. // }
  1417. //ol_debug("seqnum :%s", g_xingan_info.XINGAN_SEQNUM);
  1418. //ol_debug("udp ip port :%s", g_xingan_info.UdpIpPort);
  1419. }