proBuBiao.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. #include "includes.h"
  2. unsigned char buBiaoSosSendNow=0;
  3. unsigned char TeminalInfoRevOK=0;
  4. unsigned char g_ucModemSentTcpCt=0;
  5. FEEDBACK_DEF sutFeed;
  6. static void buBiaoReg(unsigned char socketID);
  7. static void buBiaoAuth(unsigned char socketID);
  8. static void buBiaoLocation(unsigned char socketID);
  9. static void buBiaoTime(unsigned char socketID);
  10. static void buBiaoHeart(unsigned char socketID);
  11. static void buBiaoAck(unsigned char socketID);
  12. static void buBiaoSoS(unsigned char socketID);
  13. static void buBiaoICCID(unsigned char socketID);
  14. void buBiaoLogic(unsigned char socketID){
  15. static unsigned short tick=0;
  16. static unsigned char retry=0;
  17. static unsigned char autTick=0;
  18. static unsigned short timeReqCnt=0;
  19. static unsigned short heartTick=0;
  20. static unsigned char IccidTick=60;
  21. static unsigned short locationTick=0;
  22. static unsigned char locationHold=0;
  23. unsigned char tcpSendAlready=0;
  24. unsigned short temp;
  25. char info[30];
  26. if(buBiaoAddrChange){
  27. buBiaoAddrChange=0;
  28. SocketParaUpdate(socketID,showGIP,1395);
  29. }
  30. if(tcpSocketGetStatus(socketID)) return;
  31. if(sutGpsInfo.isGpsAuthOk==0){//未鉴权
  32. timeReqCnt=500;
  33. if(++autTick>=10){
  34. autTick=0;
  35. if(++retry>=3){//鉴权3次都没成功,注册
  36. retry=0;
  37. buBiaoReg(socketID);
  38. }else buBiaoAuth(socketID);//鉴权
  39. }
  40. return;
  41. }
  42. //已鉴权了,定时发心跳,获取时间,发送定位
  43. if(g_ucModemSentTcpCt>120){
  44. //如果发了60秒数据包都没响应,则主动关闭连接
  45. g_ucModemSentTcpCt=0;
  46. snprintf(info, sizeof(info), "AT+TCPCLOSE=%d\r\n",socketID+1);
  47. ModemSendAt(info);
  48. sutGpsInfo.isGpsAuthOk=0;
  49. return;
  50. }
  51. //发送终端信息给服务器
  52. if(++IccidTick>60&&TeminalInfoRevOK==0&& !tcpSendAlready)
  53. {
  54. IccidTick=0;
  55. tcpSendAlready=1;
  56. buBiaoICCID(socketID);
  57. }
  58. if(sutGpsInfo.isGpsValid && g_uiGpsStat){
  59. temp=GPS_TimeTable[newPara.gpsTimeIndex]*2;
  60. if(++locationTick>=temp){
  61. //定位包时间到了
  62. locationTick=0;
  63. locationHold=1;
  64. }
  65. if(locationHold && isSendDataEnable()){
  66. locationHold=0;
  67. tcpSendAlready=1;
  68. // snprintf(info, sizeof(info), "AT+GPS=\"OFF\"\r\n");
  69. // ModemSendAt(info);
  70. // SlwTrace(INF,info,0);
  71. buBiaoLocation(socketID);
  72. }
  73. }
  74. if(++timeReqCnt>=360 && !tcpSendAlready){
  75. //获取时间到了
  76. if(isSendDataEnable()){
  77. timeReqCnt=0;
  78. tcpSendAlready=1;
  79. buBiaoTime(socketID);
  80. }
  81. }
  82. if(sutFeed.feedBackStart!=0 && !tcpSendAlready){
  83. //需要主动应用服务器
  84. sutFeed.feedBackStart=0;
  85. tcpSendAlready=1;
  86. buBiaoAck(socketID);
  87. }
  88. if(buBiaoSosSendNow && !tcpSendAlready){
  89. buBiaoSosSendNow=0;
  90. tcpSendAlready=1;
  91. buBiaoSoS(socketID);
  92. }
  93. if(++heartTick>=120 && !tcpSendAlready){
  94. //发送心跳时间到了
  95. if(isSendDataEnable()){
  96. heartTick=0;
  97. buBiaoHeart(socketID);
  98. }
  99. }
  100. if(tcpSendAlready){
  101. g_ucModemSentTcpCt++;
  102. heartTick=0;//已发了其它包,心跳包重置计数
  103. }
  104. }
  105. void buBiaoDataProcess(unsigned char *pMsg, unsigned short tempLen){
  106. char buf[20];
  107. char buf2[50];
  108. char result[10];
  109. unsigned short cmd,ackCmd,smsLen;
  110. unsigned char Result,i,buBiaoResponsed;
  111. short targetIndex;
  112. SUTDS ds;
  113. USER_RTC_DEF tmpTime;
  114. cmd = (pMsg[1]<<8) | (pMsg[2]&0xff);
  115. buBiaoResponsed=1;
  116. snprintf(buf2, sizeof(buf2), "\r\ncmd=%04x", cmd);
  117. SlwTrace(INF, buf2,1);
  118. switch(cmd)
  119. {//布标命令返回
  120. case TS_TERMINAL_REGISTRATION_REPLY://终端注册应答
  121. //7E 8100 000A 000166000016 0250 0100 00 20161118165030 E07E 成功
  122. //7E 8100 0003 000166000016 0251 0100 01 A07E 已注册
  123. Result = pMsg[15];
  124. snprintf(buf2, sizeof(buf2), "\r\nresult=%02x", Result);
  125. SlwTrace(INF, buf2,1);
  126. switch(Result)
  127. {
  128. case 0://00注册成功
  129. if(0 != memcmp(newPara.authPara.authCode, pMsg+16, 7)){
  130. memcpy(newPara.authPara.authCode, pMsg+16,7);
  131. //save sys
  132. ModifyConfigureFile(0);
  133. }
  134. snprintf(result, sizeof(result), "Ok");
  135. break;
  136. case 1://01 车辆已注册
  137. snprintf(result, sizeof(result), "Car Exist");break;
  138. case 2://02 无此车辆
  139. snprintf(result, sizeof(Result), "No car");break;
  140. case 3://03 终端已经被注册
  141. snprintf(result, sizeof(result), "Device Exist");break;
  142. case 4://04 数据库无此终端
  143. snprintf(result, sizeof(result), "No Record");break;
  144. default://无效值
  145. //统称失败
  146. snprintf(result, sizeof(result), "Faile");
  147. break;
  148. }
  149. snprintf(buf2, sizeof(buf2), "\r\n[Register]%d %s", Result,result);
  150. SlwTrace(INF, buf2,1);
  151. break;
  152. case TS_TEXT_INFORMATION_ISSUED://文本下发
  153. //7E83000005000166000009000001 31323334ED7E
  154. smsLen = pMsg[3];
  155. smsLen <<= 8;
  156. smsLen &= 0xff00;
  157. smsLen |= pMsg[4];
  158. smsLen -= 1;//去掉后面较验码
  159. if(SMS_SIGNAL_LEN <= smsLen)
  160. smsLen = SMS_SIGNAL_LEN;
  161. memset(sutMess.GBKMess1, 0, sizeof(sutMess.GBKMess1));
  162. memcpy(sutMess.GBKMess1, pMsg+14, smsLen);
  163. sutMess.len = smsLen;
  164. //////////////////////////
  165. sutFeed.feedID=TS_SETTING_TERMINAL_PARAMETERS;
  166. ds.Data.ucData.b1=pMsg[11];
  167. ds.Data.ucData.b2=pMsg[12];
  168. sutFeed.feedliushuiID=ds.Data.usData;
  169. sutFeed.result=2;
  170. //////////////////////////
  171. if(sutMess.len > 0)
  172. SetGotNewMessage();
  173. break;
  174. case TS_PLATFORM_UNIVERSAL_ANSWER://通用平台应答
  175. //7E8001000500016600001602400000010201B57E
  176. //buf[0]=0x7e;
  177. //if(-1 != (targetIndex=FindTargetIndex((char *)pMsg, '\r', buf, 1,2)))
  178. targetIndex = tempLen;//这个长度是去掉了两个7E的长度
  179. {
  180. ackCmd=(pMsg[targetIndex-3]<<8) | (pMsg[targetIndex-2]&0xff);
  181. Result = pMsg[targetIndex-1];
  182. snprintf(buf2, sizeof(buf2), "\r\nLen=%d,ackCmd=%04x,result=%02x", tempLen,ackCmd,Result);
  183. SlwTrace(INF, buf2,1);
  184. switch(ackCmd)
  185. {
  186. case TS_TERMINAL_AUTHENTICATION://终端鉴权应答
  187. if(Result == 0)
  188. {//鉴权成功
  189. sutGpsInfo.isGpsAuthOk=1;
  190. snprintf(buf2, sizeof(buf2), "\r\n[ATH]Ok");
  191. enableDataSend();
  192. //TSGpsServerConect();//鉴权成功后发一包终端应答包即可以支持文本接收了
  193. }else
  194. {
  195. sutGpsInfo.isGpsAuthOk=0;
  196. snprintf(buf2, sizeof(buf2), "\r\n[ATH]Faile");
  197. }
  198. SlwTrace(INF, buf2,1);
  199. break;
  200. case TS_LOCATION_INFORMATION_REPORTING://位置包应答
  201. SlwTrace(INF, "\r\nLocation ACK",1);
  202. break;
  203. case TS_TERMINAL_HEARTBEAT://心跳应答
  204. SlwTrace(INF, "\r\nHearTick ACK",1);
  205. break;
  206. case TS_SEND_SOS_SMS://SOS应答
  207. SlwTrace(INF, "\r\nSOS ACK",1);
  208. sutPocStatus.SOS_Flag++;
  209. break;
  210. case TS_TERMINAL_ATTRIBUTEINFO_ANSWER:
  211. if(!Result) {
  212. TeminalInfoRevOK=1;
  213. SlwTrace(INF, "TerminalInfo Send OK\r\n",1);
  214. }
  215. break;
  216. }
  217. }
  218. break;
  219. case TS_PLATFORM_ATTRIBUTEINFO_ANSWER:
  220. TeminalInfoRevOK=0;
  221. break;
  222. case TS_TERMINAL_REQTIME://时间ACK
  223. //7e0f020007001899000022003a e20704130e2f02 427e
  224. SlwTrace(INF, "\r\nTimeAck",1);
  225. ds.Data.ucData.b1=pMsg[13];
  226. ds.Data.ucData.b2=pMsg[14];
  227. tmpTime.year=ds.Data.usData;
  228. tmpTime.month=pMsg[15];
  229. tmpTime.day=pMsg[16];
  230. tmpTime.hour=pMsg[17];
  231. tmpTime.min=pMsg[18];
  232. tmpTime.second=pMsg[19];
  233. RTC_UserSetTime(tmpTime);
  234. printf("\r\nNewTime:%02d-%02d-%02d %02d:%02d:%02d\r\n",
  235. tmpTime.year,tmpTime.month,tmpTime.day,
  236. tmpTime.hour,tmpTime.min,tmpTime.second);
  237. break;
  238. default:
  239. buBiaoResponsed=0;
  240. break;
  241. }
  242. g_ucModemSentTcpCt=0;
  243. /////////////处理其它类型指令
  244. }
  245. static int TSGpsPacket(unsigned char *Buffer,unsigned long PSN,unsigned short ID,unsigned char *pData,int DataLen);
  246. static void buBiaoReg(unsigned char socketID){
  247. unsigned char info[100];
  248. unsigned short PacketLen;
  249. REGISTRATION Regist;
  250. SlwTrace(INF, "buBiaoReg",1);
  251. memset((unsigned char *)&Regist, 0, sizeof(REGISTRATION));
  252. Regist.TerID[0]=(unsigned char)((sutProductPara.PSN>>24)&0xff);
  253. Regist.TerID[1]=(unsigned char)((sutProductPara.PSN>>16)&0xff);
  254. Regist.TerID[2]=(unsigned char)((sutProductPara.PSN>>8)&0xff);
  255. Regist.TerID[3]=(unsigned char)(sutProductPara.PSN&0xff);
  256. PacketLen=TSGpsPacket(info,sutProductPara.PSN,TS_TERMINAL_REGISTRATION,(unsigned char *)&Regist,sizeof(REGISTRATION));
  257. tcpSocketSendData(socketID, info, PacketLen);
  258. }
  259. static void buBiaoAuth(unsigned char socketID){
  260. unsigned char info[80];
  261. unsigned short PacketLen;
  262. SlwTrace(INF, "buBiaoAuth",1);
  263. PacketLen=TSGpsPacket(info,sutProductPara.PSN,TS_TERMINAL_AUTHENTICATION,newPara.authPara.authCode,sizeof(newPara.authPara.authCode));//实际是返回的鉴权信息
  264. tcpSocketSendData(socketID, info, PacketLen);
  265. PrintBufferData(info,PacketLen);
  266. }
  267. static void buBiaoLocation(unsigned char socketID){
  268. unsigned char info[80];
  269. unsigned short PacketLen;
  270. SUT_GPS_SEND_DATA sutGpsSendData;
  271. SlwTrace(INF, "buBiaoLocation",1);
  272. TSMakeGpsSendData(&sutGpsSendData);
  273. PacketLen=TSGpsPacket(info,sutProductPara.PSN,TS_LOCATION_INFORMATION_REPORTING,(unsigned char *)&sutGpsSendData,sizeof(SUT_GPS_SEND_DATA));
  274. tcpSocketSendData(socketID, info, PacketLen);
  275. }
  276. static void buBiaoTime(unsigned char socketID){
  277. unsigned char info[50];
  278. unsigned short PacketLen;
  279. SlwTrace(INF, "buBiaoTime",1);
  280. PacketLen=TSGpsPacket(info,sutProductPara.PSN,TS_TERMINAL_REQTIME,0,0);
  281. tcpSocketSendData(socketID, info, PacketLen);
  282. }
  283. static void buBiaoHeart(unsigned char socketID){
  284. unsigned char info[100];
  285. unsigned short PacketLen;
  286. SlwTrace(INF, "buBiaoHeart",1);
  287. PacketLen=TSGpsPacket(info,sutProductPara.PSN,TS_TERMINAL_HEARTBEAT,0,0);
  288. tcpSocketSendData(socketID, info, PacketLen);
  289. }
  290. static void buBiaoAck(unsigned char socketID){
  291. int len;
  292. unsigned char info[100];
  293. unsigned char temp[5];
  294. SUTDS ds;
  295. SlwTrace(INF, "buBiaoAck",1);
  296. memcpy(temp, (unsigned char*)&sutFeed.feedliushuiID,2);
  297. ds.Data.usData=sutFeed.feedID;
  298. temp[2] = ds.Data.ucData.b2;
  299. temp[3] = ds.Data.ucData.b1;
  300. temp[4] = sutFeed.result;
  301. len=TSGpsPacket(info,sutProductPara.PSN,TS_TERMINAL_UNIVERSAL_ANSWER,temp,sizeof(temp));
  302. tcpSocketSendData(socketID, info, len);
  303. }
  304. static void buBiaoSoS(unsigned char socketID){
  305. unsigned char info[50];
  306. unsigned short PacketLen;
  307. SlwTrace(INF, "buBiaoSoS",1);
  308. PacketLen=TSGpsPacket(info,sutProductPara.PSN,TS_SEND_SOS_SMS,0,0);
  309. tcpSocketSendData(socketID, info, PacketLen);
  310. }
  311. static void buBiaoICCID(unsigned char socketID){
  312. unsigned char info[120];
  313. unsigned char PackData[60]={0};
  314. unsigned short PacketLen;
  315. SlwTrace(INF, "buBiaoTEMINAL_INFO",1);
  316. PacketLen=TSMakeTeminalInfoData(PackData);
  317. PacketLen=TSGpsPacket(info,sutProductPara.PSN,TS_TERMINAL_ATTRIBUTEINFO_ANSWER,PackData,PacketLen);
  318. tcpSocketSendData(socketID, info, PacketLen);
  319. }
  320. static unsigned char TSGetCheckSum(unsigned char *pData,int len){
  321. int i;
  322. unsigned char sum= pData[1]; //sum=0;
  323. for(i=1;i<len-1;i++){
  324. sum=sum^pData[i+1];
  325. }
  326. return sum;
  327. }
  328. static int escapse(unsigned char *pData,int DataLen);
  329. /**********************
  330. **消息头12字节,消息体属性2个字节,这两个字节的16位。低10位是消息体长度
  331. 因此消息消息最长小于1024字节,Bit13是分包标志,看终端发到平台一个消息,可能很长,一个消息体发不完,分包发出去那么
  332. Bit12置为1,消息头长度变成16字节,消息头的后4个字节为消息包分装项内容,总共
  333. 有多少个包,这次发送的消息包是分包中的第几个消息包
  334. sutProductPara.APN
  335. **************************/
  336. static int TSGpsPacket(unsigned char *Buffer,unsigned long PSN,unsigned short ID,unsigned char *pData,int DataLen){
  337. AVL_MSG_BODY_ATTRIB msgBodyAttrib;
  338. static unsigned short liushiID=0;
  339. unsigned char *pBuf=Buffer,sum;
  340. int j,flag = 0,i=0;
  341. int talpage=1,MSnum = 0;
  342. char Psnsv[12];
  343. static unsigned short snum = 1;
  344. unsigned short Len=DataLen+6;
  345. unsigned short pageItem=DataLen+12;
  346. snprintf(Psnsv, sizeof(Psnsv),"%010u",(unsigned int)PSN);
  347. pBuf[i++]=0x7e;
  348. pBuf[i++]=(ID>>8)&0xff;
  349. pBuf[i++]=ID&0xff;
  350. //消息体属性
  351. msgBodyAttrib.EncrypType=NO_ENCRYP;//NO_ENCRYP;
  352. msgBodyAttrib.msgBodyLength=(DataLen);
  353. pBuf[i++]=msgBodyAttrib.EncrypType;
  354. pBuf[i++]=msgBodyAttrib.msgBodyLength;
  355. //SIM卡号
  356. pBuf[i++]=0; //
  357. for (j=0;j<10;j+=2) {
  358. pBuf[i++]=(Psnsv[j]<<4)|(Psnsv[j+1]&0x0F);
  359. }
  360. //消息流水号
  361. pBuf[i++] = (liushiID>>8)&0xff;
  362. pBuf[i++] = liushiID&0xff;
  363. liushiID++;
  364. if(pData!=NULL){
  365. for(j=0;j<DataLen;j++){//0
  366. pBuf[i++]= pData[j];
  367. }
  368. }
  369. sum = TSGetCheckSum(pBuf,i);
  370. pBuf[i++] = sum;
  371. //对整体数据,除sum进行转义
  372. i=escapse(&pBuf[1],i-1);//头的7E不转义
  373. i++;
  374. pBuf[i++] = 0x7e;
  375. return i;
  376. }
  377. static int escapse(unsigned char *pData,int DataLen) {
  378. unsigned char *p= (unsigned char *)malloc(DataLen * 2);
  379. unsigned char * q = p;
  380. int data_len = 0;
  381. int i;
  382. if (DataLen == 0) {
  383. return 0;
  384. }
  385. memset(p, 0, DataLen * 2);
  386. for (i = 0; i < DataLen; i ++) {
  387. if (pData[i] == 0x7d) {
  388. *q ++ = 0x7d;
  389. *q ++ = 0x01;
  390. data_len += 2;
  391. } else if (pData[i] == 0x7e) {
  392. *q ++ = 0x7d;
  393. *q ++ = 0x02;
  394. data_len += 2;
  395. } else {
  396. *q ++ = pData[i];
  397. data_len += 1;
  398. }
  399. }
  400. memcpy(pData, p, data_len);
  401. free(p);
  402. DataLen = data_len;
  403. //free(p);
  404. return DataLen;
  405. }
  406. // replace 0x7d 0x01 with 0x7d and 0x7d 0x02 with 0x7e 接收
  407. //长度不会变大,只会变小或不变
  408. int reduce(unsigned char *pData,int DataLen)
  409. {
  410. unsigned char *p = pData;
  411. int data_len=0;
  412. int i;
  413. if(DataLen==0) return 0;
  414. for(i=0;i<DataLen-1;i++)
  415. {
  416. if(pData[i] == 0x7d && pData[i+1] == 0x01)
  417. {
  418. *p++ = 0x7d;i++;
  419. }else if(pData[i] == 0x7d && pData[i+1] == 0x02)
  420. {
  421. *p++ = 0x7e;i++;
  422. }else *p++=pData[i];
  423. data_len++;
  424. }
  425. return data_len;
  426. }
  427. void TSMakeGpsSendData(SUT_GPS_SEND_DATA *sendGpsData)
  428. {
  429. char sv[17];
  430. char data[3];
  431. char buf[10];
  432. int buf1[3];
  433. int j,temp,num;
  434. char *pTemp;
  435. char WWWW[5];
  436. static int Table[4]={0};
  437. static int Table1[4]={0};
  438. sendGpsData->Time[0] = sutGpsInfo.year;
  439. sendGpsData->Time[1] = sutGpsInfo.month;
  440. sendGpsData->Time[2] = sutGpsInfo.day;
  441. sendGpsData->Time[3] = sutGpsInfo.hour;
  442. sendGpsData->Time[4] = sutGpsInfo.minu;
  443. sendGpsData->Time[5] = sutGpsInfo.sec;
  444. sendGpsData->St=0x00;
  445. sendGpsData->status=0;
  446. sendGpsData->status |=(1<<24);//b0 1 acc
  447. sendGpsData->status |=(1<<25);//b1 1 定位
  448. if(sutGpsInfo.NSFlag=='S')
  449. sendGpsData->status |=(1<<26);//b2 1 南纬
  450. if(sutGpsInfo.EWFlag=='W')
  451. sendGpsData->status |=(1<<27);//b3 1 西经
  452. sendGpsData->status |=(1<<28);//b4 1 运营
  453. sendGpsData->Mileag=((sutGpsInfo.StatisticsMile>>8)&0xFF)|(((sutGpsInfo.StatisticsMile)&0xFF)<<8);
  454. sendGpsData->SSFF=((sutGpsInfo.speed>>8)&0xFF)|(((sutGpsInfo.speed)&0xFF)<<8);
  455. sendGpsData->Acpect=sutGpsInfo.aspect;
  456. GetCoordinates(1);
  457. sendGpsData->WWWW[0] = sutGpsInfo.testWD>>24;
  458. sendGpsData->WWWW[1] = sutGpsInfo.testWD>>16;
  459. sendGpsData->WWWW[2] = sutGpsInfo.testWD>>8;
  460. sendGpsData->WWWW[3] = sutGpsInfo.testWD;
  461. sendGpsData->JJJJ[0] = sutGpsInfo.testJD>>24;
  462. sendGpsData->JJJJ[1] = sutGpsInfo.testJD>>16;
  463. sendGpsData->JJJJ[2] = sutGpsInfo.testJD>>8;
  464. sendGpsData->JJJJ[3] = sutGpsInfo.testJD;
  465. }
  466. void TSGpsDataInit(void)
  467. {
  468. memset((unsigned char *)&sutGpsInfo, 0, sizeof(SUT_GPS_INF));
  469. printf("Gpstime=%d\r\n",GPS_TimeTable[newPara.gpsTimeIndex]);
  470. }
  471. void PrintBufferData(unsigned char *data, unsigned short length)
  472. {
  473. unsigned short i;
  474. printf("Data[%d]:\r\n",length);
  475. for(i=0;i<length;i++) printf("%02x",data[i]);
  476. printf("\r\n");
  477. }
  478. char TSMakeTeminalInfoData(unsigned char *pData)
  479. {
  480. short InfoType=0x000f;
  481. char ProductId[5]={0};
  482. char TeminalModel[20]={0};
  483. char TeminalId[7]={0};
  484. char SIMICCID[10]={0};
  485. char Hardlen=1;
  486. char Firmlen=1;
  487. char buf[21]={0};
  488. char *p;
  489. char i,j;
  490. strcpy(ProductId,"HGS");
  491. snprintf(TeminalModel,sizeof(TeminalModel),"%s",PRODUCT_NAME);
  492. p=getICCID();
  493. /*
  494. //SIM卡号
  495. pBuf[i++]=0; //
  496. for (j=0;j<10;j+=2) {
  497. pBuf[i++]=(Psnsv[j]<<4)|(Psnsv[j+1]&0x0F);
  498. }
  499. */
  500. for(i=0;i<10;i++){
  501. SIMICCID[i]=(p[2*i]<<4&0xf0)|(p[2*i+1]&0x0f);
  502. }
  503. i=0;
  504. pData[i++]=InfoType;
  505. pData[i++]=InfoType>>8&0xff;
  506. for(j=0;j<5;j++)pData[i++]=ProductId[j];
  507. for(j=0;j<20;j++)pData[i++]=TeminalModel[j];
  508. for(j=0;j<7;j++)pData[i++]=TeminalId[j];
  509. for(j=0;j<10;j++)pData[i++]=SIMICCID[j];
  510. pData[i++]=Hardlen;
  511. pData[i++]=0;
  512. pData[i++]=Firmlen;
  513. pData[i++]=0;
  514. return i;
  515. }