poc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. #include "includes.h"
  2. POC_DEF sutPocStatus;
  3. void pocDataInit(void){
  4. memset((unsigned char *)&sutPocStatus, 0, sizeof(POC_DEF));
  5. }
  6. /*控制查询POC设置状态
  7. dly:接口被调用的频率,单位ms*/
  8. void pocProCtl(int dly){
  9. //3秒查询一次
  10. static unsigned short cnt=0;
  11. if(sutApp.gtMode!=0) return;//GT模式后不再查询
  12. if(++cnt<(5*1000/dly)) return;
  13. cnt=0;
  14. if(getAppObjStatus(ASLEEP_LCD)==0) return;//POC休眠时,不发指令
  15. if(sutApp.pocParaDone==0) msgAtSend("AT+POC=020000\r\n");//用于检测并设置POC参数
  16. msgAtSend("AT$MYSYSINFO\r\n");//查询当前网络制式
  17. msgAtSend("AT+UDP?\r\n");//查询功耗状态
  18. msgAtSend("AT+CSQ\r\n");//查询信号强度
  19. msgAtSend("AT+GPIP?\r\nAT+GGIP?\r\n");//查询PIP,GIP
  20. //msgAtSend("AT+HEAP\r\n");
  21. }
  22. static void micPro(int mic);
  23. static void spkPro(int spk);
  24. static void pocStartMsg(void);
  25. static void pro80Msg(char *msg);
  26. static void pro81Msg(char *msg);
  27. static void pro82Msg(char *msg);
  28. static void pro83Msg(char *msg);
  29. static void pro84Msg(char *msg);
  30. static void pro86Msg(char *msg);
  31. static void pro3dMsg(char *msg);
  32. static void pro3eMsg(char *msg);
  33. static void pro0eMsg(char *msg);
  34. static void pro1eMsg(char *msg);
  35. static void pro1dMsg(char *msg);
  36. static void pocGetVer(char *msg);
  37. static void pocGetPpp(char *msg);
  38. static void proGauthMsg(char *msg);
  39. static void proNoteMsg(char *msg);
  40. static void proNetMode(char *msg);
  41. static void proSimMode(char *msg);
  42. static void proPwrMode(char *msg);
  43. static void proFotaMsg(char *msg);
  44. static void proGmrMsg(char *msg);
  45. static void proSmsMsg(char *msg);
  46. static void proAlarmMsg(void);
  47. static void proPendMsg(void);
  48. static void proToneMsg(char *msg);
  49. static void proGPIPMsg(char *msg);
  50. static void proGGIPMsg(char *msg);
  51. static void proCsqMsg(char *msg);
  52. static void proMicSpk(int mic, int spk);
  53. void cmdsProcess(char *msg, int len){//已去掉回车换行
  54. static char firstTTSEnd=1;
  55. int i;
  56. char *p,taddr[30],buf[100];
  57. if(sutApp.pocInitStatus==0) sutApp.pocInitStatus=1;
  58. if(sutApp.gtMode==0){
  59. appSleepCtl(ASLEEP_POC, 1);
  60. tryWakeupApp();
  61. MSG_INFO(1,"POC:%s",msg);
  62. if(msgCmp(msg, "+POC:SLEEP")){//POC休眠了
  63. appSleepCtl(ASLEEP_POC, 0);
  64. }else if(msgCmp(msg, "+POC:WAKEUP")){//POC唤醒了
  65. }else if(msgCmp(msg, "+POC:8B")){
  66. buf[0]=msg[7];buf[1]=msg[8];buf[2]=0;
  67. i=atoi(buf);
  68. buf[0]=msg[9];buf[1]=msg[10];buf[2]=0;
  69. proMicSpk(i, atoi(buf));
  70. //micPro(atoi(buf));
  71. //buf[0]=msg[9];buf[1]=msg[10];buf[2]=0;
  72. //spkPro(atoi(buf));
  73. }else if(msgCmp(msg, "+HTTS: END")){
  74. sutPocStatus.TTS=0;
  75. if(firstTTSEnd==1){
  76. firstTTSEnd=0;
  77. msgAtSend("AT+HTTSSPEED=1282,3000\r\n");//设置TTS音量
  78. }
  79. }else if(msgCmp(msg, "+HTTS: START")){
  80. paControl(true);
  81. sutPocStatus.TTS=1;
  82. }else if(msgCmp(msg, "+CGPS:")) proGpsMsg(msg+6);
  83. else if(msgCmp(msg, "$MYSYSINFO:")) proNetMode(msg+12);
  84. else if(msgCmp(msg, "+TONE:")) proToneMsg(msg+6);
  85. else if(msgCmp(msg, "+UDP:")) proPwrMode(msg+5);
  86. else if(msgCmp(msg, "+CSQ: ")) proCsqMsg(msg+6);
  87. else if(msgCmp(msg, "+POC:82")) pro82Msg(msg+7);
  88. else if(msgCmp(msg, "+POC:3D")) pro3dMsg(msg+7);
  89. else if(msgCmp(msg, "+POC:3E")) pro3eMsg(msg+7);
  90. else if(msgCmp(msg, "+POC:80")) pro80Msg(msg+7);
  91. else if(msgCmp(msg, "+POC:1E")) pro1eMsg(msg+7);
  92. else if(msgCmp(msg, "+POC:86")) pro86Msg(msg+7);
  93. else if(msgCmp(msg, "+POC:83")) pro83Msg(msg+7);
  94. else if(msgCmp(msg, "+POC:84")) pro84Msg(msg+7);
  95. else if(msgCmp(msg, "+POC:0E")) pro0eMsg(msg+7);
  96. else if(msgCmp(msg, "+POC:1D")) pro1dMsg(msg+7);
  97. else if(msgCmp(msg, "+POC:START")) pocStartMsg();
  98. else if(msgCmp(msg, "+POC_VER:")) pocGetVer(msg+9);
  99. else if(msgCmp(msg, "+POC_PPP:")) pocGetPpp(msg+9);
  100. else if(msgCmp(msg, "+POC:02000000")) setPocPara(msg+13,len-13);
  101. else if(msgCmp(msg, "+GAUTH:")) proGauthMsg(msg+7);
  102. else if(msgCmp(msg, "+NOTE:")) proNoteMsg(msg+6);
  103. else if(msgCmp(msg, "+RSIM:")) proSimMode(msg+6);
  104. else if(msgCmp(msg, "+FOTA:")) proFotaMsg(msg+6);
  105. else if(msgCmp(msg, "+CGPS:")) proGpsMsg(msg+6);
  106. else if(msgCmp(msg, "+GPIP:")) proGPIPMsg(msg+6);
  107. else if(msgCmp(msg, "+GGIP:")) proGGIPMsg(msg+6);
  108. else if(msgCmp(msg, "+GMR:")) proGmrMsg(msg+5);
  109. else if(msgCmp(msg, "+SMS:")) proSmsMsg(msg+5);
  110. else if(msgCmp(msg, "+ALARM")) proAlarmMsg();
  111. else if(msgCmp(msg, "+POC:PEND")) proPendMsg();
  112. else if(msgCmp(msg, "+CPIN: READY")) sutApp.cardStatus=1;
  113. else MSG_INFO(1, "skip:%d,%s", len,msg);
  114. }
  115. }
  116. //处理POC模块信息
  117. void pocCmdHandler(unsigned char *msg, int len){
  118. //有消息进来,如果不是+POC:SLEEP,POC都唤醒了
  119. static char tmp[300],ch;
  120. static int k=0;
  121. unsigned int j;
  122. if(sutApp.authReady==0) return;
  123. if(sutApp.gtMode !=0 && sutApp.gtTMode != 0){
  124. nwy_usb_serial_send(msg, len);//TM模式下直接透传
  125. return;
  126. }
  127. for(j=0;j<len;j++){//过滤
  128. if(k>=sizeof(tmp)) k=0;
  129. tmp[k++]=msg[j];
  130. if(ch=='\r' && msg[j]=='\n'){
  131. if(k!=2){
  132. //处理
  133. k -=2;tmp[k]=0;//去掉回车换行
  134. cmdsProcess(tmp,k);
  135. }
  136. k=0;
  137. }
  138. ch=msg[j];
  139. }
  140. }
  141. static void proMicSpk(int mic, int spk){
  142. if(mic==0 && spk==0){//0000
  143. if(newPara.KeySound!=0) pttBeepStart(false);
  144. sutPocStatus.spk=0;
  145. sutPocStatus.mic=0;
  146. }else if(mic==1 && spk==0){//0100
  147. if(newPara.KeySound!=0) pttBeepStart(false);
  148. sutPocStatus.mic=1;
  149. }else if(mic==0 && spk==1){//0001
  150. if(newPara.KeySound!=0) pttBeepStart(false);
  151. paControl(true);
  152. sutPocStatus.spk=1;
  153. sutPocStatus.mic=0;
  154. }else if(mic==0 && spk==13){//0013
  155. if(newPara.KeySound!=0) beepStart(TONE_SPECIAL);
  156. }
  157. }
  158. static void micPro(int mic){
  159. switch(mic){
  160. case 0://关闭mic
  161. sutPocStatus.mic=0;
  162. break;
  163. case 1://打开mic
  164. if(newPara.KeySound!=0) beepStart(TONE_NORMAL);
  165. sutPocStatus.mic=1;
  166. //sutPocStatus.spk=0;
  167. break;
  168. }
  169. }
  170. static void spkPro(int spk){
  171. switch(spk){
  172. case 0://tone音后关闭spk
  173. if(newPara.KeySound!=0) beepStart(TONE_NORMAL);
  174. sutPocStatus.spk=0;
  175. break;
  176. case 1://tone音后保持spk打开
  177. if(newPara.KeySound!=0) beepStart(TONE_NORMAL);
  178. paControl(true);
  179. sutPocStatus.spk=1;
  180. sutPocStatus.mic=0;
  181. break;
  182. case 2://播放TTS
  183. paControl(true);
  184. sutPocStatus.TTS=1;
  185. break;
  186. case 13://抢麦失败,可以tone特殊音
  187. if(newPara.KeySound!=0) beepStart(TONE_SPECIAL);
  188. break;
  189. }
  190. }
  191. /*POC已启动成功*/
  192. static void pocStartMsg(void){
  193. sutApp.pocInitStatus=1;
  194. }
  195. /*当前账号所属群组列表信息,一次性获取所有
  196. 不同应用采用不同需求指令
  197. 从不在线到登录会主动上报一次列表
  198. 发AT+POC=0D0000也会上报一次列表
  199. msg:000000,iiii(组列表索引),dddddddd(组ID),nnnn(组成员数),mmmmmm(组名称)*/
  200. static void pro80Msg(char *msg){
  201. }
  202. /*所在组成员信息列表
  203. 发AT+POC=0E0000xxxxxxxx查询
  204. msg:010000,iiii(成员列表索引),dddddddd(成员ID),mmmmmmmm(成员名称)*/
  205. static void pro81Msg(char *msg){
  206. }
  207. /*登录状态信息
  208. msg:ss(00未登录,02已登录),dddddddd(成员id),mmmmmmmm(状态信息内容)
  209. 00 CEDECDF8C2E7C1ACBDD3 表示不在线,输出信息为 无网络连接(拨号没 成功)
  210. 00 CEDEB7A8C1ACBDD3 表示不在线,输出信息为 无法连接(IP 不对或定 向卡)
  211. 00 C3BBD3D0B7FECEF1 表示不在线,输出信息为 没有服务(没注册)
  212. 00 B5C7C2BDCAA7B0DC 表示不在线,输出信息为 登陆失败(账号错误)
  213. 00 0D5CBBAC5D0C5CFA2B4EDCEF3 账号信息错误
  214. 02 0001A750 B2E2CAD431BAC5(测试 1 号),*/
  215. static void pro82Msg(char *msg){
  216. char buf[3],*pName;
  217. int type,len;
  218. char Username[POC_GROUP_USER_NAME_LEN*2];
  219. buf[0]=msg[0];buf[1]=msg[1];buf[2]=0;
  220. type=atoi(buf);
  221. switch(type){
  222. case 0:
  223. if(sutPocStatus.logined) backLightReset();
  224. sutPocStatus.logined=0;
  225. if(0==memcmp(msg+10, "CEDECDF8C2E7C1ACBDD3",20)) sutPocStatus.PocLineOffReason=1;
  226. else if(0==memcmp(msg+10, "CEDEB7A8C1ACBDD3",16)) sutPocStatus.PocLineOffReason=2;
  227. else if(0==memcmp(msg+10, "C3BBD3D0B7FECEF1",16)) sutPocStatus.PocLineOffReason=3;
  228. else if(0==memcmp(msg+10, "B5C7C2BDCAA7B0DC",16)) sutPocStatus.PocLineOffReason=4;
  229. break;
  230. case 2:
  231. sutPocStatus.PocLineOffReason=0;
  232. len=strlen(msg+10);
  233. if(len>POC_GROUP_USER_NAME_LEN) len=POC_GROUP_USER_NAME_LEN;
  234. memcpy(Username, msg+10,len);
  235. Username[len]=0;
  236. StrAsciiToHex(Username, sutPocStatus.LocalUser.name);
  237. msg[10]=0;
  238. sutPocStatus.LocalUser.ID=strtol(&msg[2], &pName, 16);
  239. MSG_INFO(1, "Login ok");
  240. sutPocStatus.loginResult=3;
  241. break;
  242. }
  243. }
  244. /*有人说话
  245. msg:00,dddddddd(成员id),nnnnnnnn(成员名称)*/
  246. static void pro83Msg(char *msg){
  247. int len;
  248. char callerName[POC_GROUP_USER_NAME_LEN*2];
  249. backLightReset();//鏀跺埌鏈変汉璇磋瘽
  250. len=strlen(msg+10);
  251. if(len>POC_GROUP_USER_NAME_LEN) len=POC_GROUP_USER_NAME_LEN;
  252. memcpy(callerName, msg+10,len);
  253. callerName[len]=0;
  254. if(0!=memcmp(callerName, sutPocStatus.CallName,len)) StrAsciiToHex(callerName, sutPocStatus.CallName);
  255. }
  256. /*单呼响应信息
  257. msg:00,mmmmmmmmmm(单呼结果信息)
  258. BAF4BDD0B3C9B9A6 表示 呼叫成功
  259. BAF4BDD0CAA7B0DC 表示 呼叫失败
  260. CDCBB3F6C1D9CAB1BAF4BDD0 表示 退出临时呼叫
  261. C1D9CAB1BAF4BDD031BAC5BBFA 表示 临时呼叫 1 号机*/
  262. static void pro84Msg(char *msg){
  263. //unsigned char danhureport[POC_GROUP_USER_NAME_LEN+1];
  264. //StrAsciiToHex(msg+2, danhureport);
  265. ttsPlay(ENCODE_USER_GBK, msg+2);
  266. if(0==memcmp(msg+2, "C1D9CAB1", 8)) sutPocStatus.danHuStatus=1;
  267. else if(0==memcmp(msg+2, "CDCBB3F6", 8)) sutPocStatus.danHuStatus=0;
  268. else if(0==memcmp(msg+2, "BAF4BDD0B3C9B9A6", 16)) sutPocStatus.danHuStatus=1;
  269. }
  270. /*切换群组完成指令(表示已登录)
  271. msg:00,dddddddd(组id),nnnnnnnn(组名称)*/
  272. static void pro86Msg(char *msg){
  273. char buf[POC_GROUP_USER_NAME_LEN*4+40],*pName;
  274. int len,i;
  275. char GroupName[POC_GROUP_USER_NAME_LEN*2];
  276. char tmp[POC_GROUP_USER_NAME_LEN*2+20];
  277. char needTTs=0;
  278. sutPocStatus.logined=1;
  279. len=strlen(msg+10);
  280. if(len>POC_GROUP_USER_NAME_LEN) len=POC_GROUP_USER_NAME_LEN;
  281. memcpy(GroupName, msg+10,len);
  282. GroupName[len]=0;
  283. msg[10]=0;
  284. sutPocStatus.LocalGroup.ID=strtol(msg+2, &pName,16);
  285. StrAsciiToHex(GroupName, sutPocStatus.LocalGroup.name);
  286. if(sutPocStatus.firstLogin==0){
  287. snprintf(tmp, sizeof(tmp), "%s,已登陆,%s", sutPocStatus.LocalUser.name,sutPocStatus.LocalGroup.name);
  288. backLightReset();//第一次登录时,保持屏亮起来
  289. needTTs=1;
  290. }else{
  291. snprintf(tmp, sizeof(tmp), "进入,%s",sutPocStatus.LocalGroup.name);
  292. if(sutApp.groupTTSEnable!=0){
  293. needTTs=1;
  294. sutApp.groupTTSEnable=0;
  295. }
  296. }
  297. if(needTTs!=0){
  298. memset(buf, 0, sizeof(buf));
  299. for(i=0;i<strlen(tmp);i++){
  300. snprintf(GroupName, sizeof(GroupName), "%02x", tmp[i]);
  301. strcat(buf, GroupName);
  302. }
  303. ttsPlay(ENCODE_USER_GBK, buf);
  304. }
  305. sutPocStatus.danHuStatus=0;
  306. sutPocStatus.firstLogin=1;
  307. }
  308. /*查询所属群组总数的响应
  309. 发AT+POC=3D0000获得
  310. msg:000000,nnnn(所属多少个群组)*/
  311. static void pro3dMsg(char *msg){
  312. char *pName;
  313. sutPocStatus.ListCurOnlineNum=strtol(&msg[6],&pName,16);
  314. sutPocStatus.ListUpdate=1;
  315. MSG_INFO(1, "groupNum:%d", sutPocStatus.ListCurOnlineNum);
  316. }
  317. /*查询所属在线成员总数的响应
  318. 发AT+POC=3E0000获得
  319. msg:000000,nnnn(所属多少个在线成员)*/
  320. static void pro3eMsg(char *msg){
  321. char *pName;
  322. sutPocStatus.ListCurOnlineNum=strtol(&msg[6],&pName,16);
  323. sutPocStatus.ListUpdate=1;
  324. MSG_INFO(1, "userNum:%d", sutPocStatus.ListCurOnlineNum);
  325. }
  326. /*查询所在组成员信息时返回,得到在线成员总数
  327. msg:000000,nnnn(在线成员总数)*/
  328. static void pro0eMsg(char *msg){
  329. }
  330. /*定量查询所在群组中的在线成员信息响应
  331. 发AT+POC=1E0000xxxxx获得
  332. msg:010000,iiii(成员列表索引),dddddddd(成员ID),mmmmmmmm(成员名称)*/
  333. static void pro1eMsg(char *msg){
  334. char name[POC_GROUP_USER_NAME_LEN*2+1];
  335. int len;
  336. unsigned long id;
  337. char *pTemp;
  338. if(!uiAssist.status)return 1;
  339. len = strlen(&msg[18]);
  340. if(len >= POC_GROUP_USER_NAME_LEN*2) len = POC_GROUP_USER_NAME_LEN*2;
  341. memcpy(name, &msg[18], len);
  342. name[len]=0;
  343. msg[18]=0;
  344. id=strtol(&msg[10],&pTemp,16);
  345. sutPocStatus.AllUsers[sutPocStatus.ListFillIndex].ID=id;
  346. if(name[0]==0){
  347. sutPocStatus.AllUsers[sutPocStatus.ListFillIndex].name[0]=' ';
  348. sutPocStatus.AllUsers[sutPocStatus.ListFillIndex].name[1]=0;
  349. }else StrAsciiToHex(name, sutPocStatus.AllUsers[sutPocStatus.ListFillIndex].name);
  350. sutPocStatus.ListFillIndex++;
  351. if(sutPocStatus.ListFillIndex==sutPocStatus.ExceptionReadNum){
  352. sutPocStatus.ListGetOneFlag=1;
  353. sutPocStatus.ListDetailValid=1;
  354. }
  355. }
  356. /*定时查询所属组信息
  357. 发AT+POC=1D0000xxxxx获得
  358. msg:000000,iiii(组列表索引),dddddddd(组ID),nnnn(成员个数),mmmmmmmmm(名称)*/
  359. static void pro1dMsg(char *msg){
  360. unsigned short num;
  361. char name[POC_GROUP_USER_NAME_LEN*2+1];
  362. unsigned long id;
  363. unsigned short index;
  364. char *pTemp;
  365. int len;
  366. if(!uiAssist.status)return ;
  367. len = strlen(&msg[22]);//已去掉回车换行
  368. if(len >= POC_GROUP_USER_NAME_LEN*2) len = POC_GROUP_USER_NAME_LEN*2;
  369. memcpy(name, &msg[22], len);
  370. name[len]=0;
  371. msg[22]=0;
  372. num=strtol(&msg[18],&pTemp,16);
  373. msg[18]=0;
  374. id=strtol(&msg[10],&pTemp,16);
  375. sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].ID=id;
  376. sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].usernum=num;
  377. if(name[0]==0){
  378. sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].name[0]=' ';
  379. sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].name[1]=0;
  380. }else
  381. StrAsciiToHex(name, sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].name);
  382. sutPocStatus.ListFillIndex++;
  383. if(sutPocStatus.ListFillIndex==sutPocStatus.ExceptionReadNum){
  384. sutPocStatus.ListGetOneFlag=1;
  385. sutPocStatus.ListDetailValid=1;
  386. }
  387. }
  388. /*
  389. +POC_VER:01027
  390. msg=01027
  391. */
  392. static void pocGetVer(char *msg){
  393. snprintf(sutApp.pocVersion, sizeof(sutApp.pocVersion), "%s",msg);
  394. }
  395. static void pocGetPpp(char *msg){
  396. if(msg[0]=='1') sutApp.pocPpp=1;
  397. else{
  398. sutApp.pocPpp=0;
  399. learnUserInfoClear();
  400. }
  401. }
  402. /*
  403. +GAUTH:AD86EBCCECC4
  404. msg=AD86EBCCECC4+回车
  405. */
  406. static void proGauthMsg(char *msg){
  407. #if 1
  408. unsigned char newAuthTable[10]={0x50,0x28,0xaf,0x6d,0x08,0x9c,0x1b,0xe4,0x23,0x77};
  409. unsigned char randBuf[100];
  410. char buf[3];
  411. int len,i,j;
  412. len=0;
  413. for(i=0;i<strlen(msg);i++){
  414. if(msg[i]=='\r' || msg[i]=='\n' || msg[i]=='\0') goto MSG_DONE;
  415. randBuf[len++]=msg[i];
  416. }
  417. MSG_DONE:
  418. //获取串并转换成16进制加密串
  419. if(len%2 || 0!=restoreDataFormatByHex(randBuf,len)){
  420. MSG_WARN(1, "auth get error");
  421. return;
  422. }
  423. len /= 2;//得到加密信息:长度为len的randBuf
  424. extCodeBuffer(randBuf, len,newAuthTable, sizeof(newAuthTable));
  425. snprintf(randBuf, sizeof(randBuf), "AT+SAUTH=");
  426. //将长度为i的tmp内存以十六进制串打包发送
  427. for(j=0;j<sizeof(newAuthTable);j++){
  428. snprintf(buf, sizeof(buf),"%02x",newAuthTable[j]);
  429. strcat(randBuf, buf);
  430. }
  431. strcat(randBuf, "\r\n");
  432. msgAtSend(randBuf);
  433. MSG_INFO(0, randBuf);
  434. #else
  435. #define FACTORY_MARK "PC-TOOL"
  436. #define MODULE_MARK "PC-TEST-TOOL"
  437. unsigned char randBuf[20];
  438. unsigned char tmp[16+16+20];
  439. unsigned char imei[20];
  440. char sendBuf[sizeof(tmp)*2+20]="AT+SAUTH=";
  441. char *fillPtr=sendBuf+9;
  442. char buf[3];
  443. char *imeiPtr;
  444. int len,i,j;
  445. len=0;
  446. for(i=0;i<strlen(msg);i++){
  447. if(msg[i]=='\r' || msg[i]=='\n' || msg[i]=='\0') goto MSG_DONE;
  448. randBuf[len++]=msg[i];
  449. }
  450. MSG_DONE:
  451. //获取串并转换成16进制加密串
  452. if(len%2 || 0!=restoreDataFormatByHex(randBuf,len)){
  453. MSG_WARN(1, "auth get error");
  454. return;
  455. }
  456. len /= 2;//得到加密信息:长度为len的randBuf
  457. //对串进行加密码,加密对像为厂商+机型+设备ID[32+32+20]
  458. imeiPtr=ohpocGetIMEI();
  459. if(NULL==imeiPtr){
  460. MSG_WARN(1, "imei is not ready");
  461. return;
  462. }
  463. MSG_INFO(1, "IMEI:%s",imeiPtr);
  464. i=strlen(imeiPtr);
  465. if(i>sizeof(imei)){
  466. MSG_ERR(1, "imei buffer overflow:%d",i);
  467. return;
  468. }
  469. memcpy(imei, imeiPtr,i);//得到IMEI数据:长度为i的imei
  470. //组织协议数据
  471. memset(tmp, 0,sizeof(tmp));
  472. memcpy(tmp,FACTORY_MARK,strlen(FACTORY_MARK));
  473. memcpy(tmp+16, MODULE_MARK,strlen(MODULE_MARK));
  474. tmp[32]=i;
  475. memcpy(tmp+33,imei,i);
  476. i=32+1+i;
  477. //使用长度为len的randBuf加密串对长度为i的tmp进行加密
  478. extCodeBuffer(randBuf, len, tmp, i);
  479. //将长度为i的tmp内存以十六进制串打包发送
  480. for(j=0;j<i;j++){
  481. snprintf(buf, sizeof(buf),"%02x",tmp[j]);
  482. *fillPtr++=buf[0];
  483. *fillPtr++=buf[1];
  484. }
  485. *fillPtr++='\r';
  486. *fillPtr++='\n';
  487. *fillPtr++='\0';
  488. msgAtSend(sendBuf);
  489. MSG_INFO(0, sendBuf);
  490. #endif
  491. }
  492. /*
  493. +NOTE:0,1
  494. msg=0,1+回车
  495. */
  496. static void proNoteMsg(char *msg){
  497. MSG_INFO(1,"authAck:%s",msg);
  498. }
  499. /*
  500. $MYSYSINFO: 4,03
  501. msg=4,03
  502. */
  503. static void proNetMode(char *msg){
  504. unsigned char netModeValue;
  505. if(msg[0]<'0' || msg[0]>'9') return;
  506. netModeValue=msg[0]-0x30;
  507. netshowvalue=netModeValue;
  508. }
  509. /*
  510. +RSIM:1
  511. msg=1/2
  512. */
  513. static void proSimMode(char *msg){
  514. unsigned char tmpSim;
  515. tmpSim=msg[0]-0x31;
  516. if(tmpSim!=0 && tmpSim!=1) return;
  517. sutApp.simSel=tmpSim;
  518. }
  519. /*
  520. +UDP:0,5,30
  521. msg=0,5,30
  522. */
  523. static void proPwrMode(char *msg){
  524. int seg1,seg2;
  525. short i;
  526. char buf[15];
  527. for(i=2;i<strlen(msg);i++){
  528. if(msg[i]==','){
  529. seg1=atoi(msg+2);
  530. seg2=atoi(msg+i+1);
  531. pwrModeAckHandler(seg1,seg2);
  532. }
  533. }
  534. }
  535. /*
  536. +FOTA:1,0
  537. +FOTA:1,XXX
  538. +FOTA:0
  539. +FOTA:1
  540. +FOTA:2
  541. msg=1,xxxx
  542. */
  543. static void proFotaMsg(char *msg){
  544. if(msg[1]==','){
  545. if(msg[2]=='0' && msg[3]==0) sutApp.fotaStatus=1;
  546. else{
  547. strcpy(sutApp.fotaVersion, msg+2);
  548. sutApp.fotaStatus=2;
  549. }
  550. }else if(msg[1]==0){
  551. if(msg[0]=='0') sutApp.fotaStatus=3;
  552. else if(msg[0]=='1') sutApp.fotaStatus=4;
  553. else if(msg[0]=='2') sutApp.fotaStatus=5;
  554. }
  555. }
  556. /*
  557. +GMR: N58-R07-STD-OE_V20-03
  558. msg= N58-R07-STD-OE_V20-03
  559. */
  560. static void proGmrMsg(char *msg){
  561. snprintf(sutApp.modemVer, sizeof(sutApp.modemVer), "%s", msg+1);
  562. }
  563. /*
  564. +SMS:1,B2E2CAD4313233
  565. msg=1,B2E2CAD4313233
  566. */
  567. static void proSmsMsg(char *msg){
  568. unsigned char smsType=msg[0]-0x30;
  569. unsigned len=strlen(msg+2);
  570. if(len%2 || 0!=restoreDataFormatByHex(msg+2,len)){
  571. MSG_WARN(1, "sms data error");
  572. return;
  573. }
  574. len /= 2;
  575. sutMess.codeType=smsType;
  576. sutSms.smsUpdate=1;
  577. memcpy(sutMess.GBKMess1+4, msg+2, len);
  578. }
  579. /*服务器报下发报警TTS,POC已播报,本信息只提示*/
  580. static void proAlarmMsg(void){
  581. }
  582. static void proPendMsg(void){
  583. MSG_INFO(1, "active auth now");
  584. msgAtSend("AT+GAUTH\r\n");//用于授权检测
  585. }
  586. static void proToneMsg(char *msg){
  587. #ifndef ENABLE_PWM_BEEP
  588. if(msg[0]=='1'){
  589. sutPocStatus.TONE=1;
  590. paControl(true);
  591. }else if(msg[0]=='0'){
  592. sutPocStatus.TONE=0;
  593. }
  594. #endif
  595. }
  596. /*
  597. +GPIP:183.131.13.10
  598. msg=183.131.13.10
  599. */
  600. static void proGPIPMsg(char *msg){
  601. if(strlen(msg)<7) return;
  602. if(strcmp(showPIP, msg)==0) return;
  603. snprintf(showPIP, sizeof(showPIP), "%s",msg);
  604. MSG_INFO(1, "updatePIP:%s", showPIP);
  605. }
  606. /*
  607. +GGIP:183.131.13.6
  608. msg=183.131.13.6
  609. */
  610. static void proGGIPMsg(char *msg){
  611. if(strlen(msg)<7) return;
  612. if(strcmp(showGIP, msg)==0) return;
  613. snprintf(showGIP, sizeof(showGIP), "%s",msg);
  614. MSG_INFO(1, "updateGIP:%s", showGIP);
  615. }
  616. /*
  617. +CSQ: 14,99
  618. msg=14,99
  619. */
  620. static void proCsqMsg(char *msg){
  621. int csq=atoi(msg);
  622. if(csq != sutApp.g_iCSQ) sutApp.g_iCSQ=csq;
  623. }