poc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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_POC)==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. sutPocStatus.logined=0;
  224. if(0==memcmp(msg+10, "CEDECDF8C2E7C1ACBDD3",20)) sutPocStatus.PocLineOffReason=1;
  225. else if(0==memcmp(msg+10, "CEDEB7A8C1ACBDD3",16)) sutPocStatus.PocLineOffReason=2;
  226. else if(0==memcmp(msg+10, "C3BBD3D0B7FECEF1",16)) sutPocStatus.PocLineOffReason=3;
  227. else if(0==memcmp(msg+10, "B5C7C2BDCAA7B0DC",16)) sutPocStatus.PocLineOffReason=4;
  228. break;
  229. case 2:
  230. sutPocStatus.PocLineOffReason=0;
  231. len=strlen(msg+10);
  232. if(len>POC_GROUP_USER_NAME_LEN) len=POC_GROUP_USER_NAME_LEN;
  233. memcpy(Username, msg+10,len);
  234. Username[len]=0;
  235. StrAsciiToHex(Username, sutPocStatus.LocalUser.name);
  236. msg[10]=0;
  237. sutPocStatus.LocalUser.ID=strtol(&msg[2], &pName, 16);
  238. MSG_INFO(1, "Login ok");
  239. sutPocStatus.loginResult=3;
  240. break;
  241. }
  242. }
  243. /*有人说话
  244. msg:00,dddddddd(成员id),nnnnnnnn(成员名称)*/
  245. static void pro83Msg(char *msg){
  246. int len;
  247. char callerName[POC_GROUP_USER_NAME_LEN*2];
  248. backLightReset();//鏀跺埌鏈変汉璇磋瘽
  249. len=strlen(msg+10);
  250. if(len>POC_GROUP_USER_NAME_LEN) len=POC_GROUP_USER_NAME_LEN;
  251. memcpy(callerName, msg+10,len);
  252. callerName[len]=0;
  253. if(0!=memcmp(callerName, sutPocStatus.CallName,len)) StrAsciiToHex(callerName, sutPocStatus.CallName);
  254. }
  255. /*单呼响应信息
  256. msg:00,mmmmmmmmmm(单呼结果信息)
  257. BAF4BDD0B3C9B9A6 表示 呼叫成功
  258. BAF4BDD0CAA7B0DC 表示 呼叫失败
  259. CDCBB3F6C1D9CAB1BAF4BDD0 表示 退出临时呼叫
  260. C1D9CAB1BAF4BDD031BAC5BBFA 表示 临时呼叫 1 号机*/
  261. static void pro84Msg(char *msg){
  262. //unsigned char danhureport[POC_GROUP_USER_NAME_LEN+1];
  263. //StrAsciiToHex(msg+2, danhureport);
  264. ttsPlay(ENCODE_USER_GBK, msg+2);
  265. if(0==memcmp(msg+2, "C1D9CAB1", 8)) sutPocStatus.danHuStatus=1;
  266. else if(0==memcmp(msg+2, "CDCBB3F6", 8)) sutPocStatus.danHuStatus=0;
  267. else if(0==memcmp(msg+2, "BAF4BDD0B3C9B9A6", 16)) sutPocStatus.danHuStatus=1;
  268. }
  269. /*切换群组完成指令(表示已登录)
  270. msg:00,dddddddd(组id),nnnnnnnn(组名称)*/
  271. static void pro86Msg(char *msg){
  272. char buf[POC_GROUP_USER_NAME_LEN*4+40],*pName;
  273. int len,i;
  274. char GroupName[POC_GROUP_USER_NAME_LEN*2];
  275. char tmp[POC_GROUP_USER_NAME_LEN*2+20];
  276. char needTTs=0;
  277. sutPocStatus.logined=1;
  278. len=strlen(msg+10);
  279. if(len>POC_GROUP_USER_NAME_LEN) len=POC_GROUP_USER_NAME_LEN;
  280. memcpy(GroupName, msg+10,len);
  281. GroupName[len]=0;
  282. msg[10]=0;
  283. sutPocStatus.LocalGroup.ID=strtol(msg+2, &pName,16);
  284. StrAsciiToHex(GroupName, sutPocStatus.LocalGroup.name);
  285. if(sutPocStatus.firstLogin==0){
  286. snprintf(tmp, sizeof(tmp), "%s,已登陆,%s", sutPocStatus.LocalUser.name,sutPocStatus.LocalGroup.name);
  287. backLightReset();//第一次登录时,保持屏亮起来
  288. needTTs=1;
  289. }else{
  290. snprintf(tmp, sizeof(tmp), "进入,%s",sutPocStatus.LocalGroup.name);
  291. if(sutApp.groupTTSEnable!=0){
  292. needTTs=1;
  293. sutApp.groupTTSEnable=0;
  294. }
  295. }
  296. if(needTTs!=0){
  297. memset(buf, 0, sizeof(buf));
  298. for(i=0;i<strlen(tmp);i++){
  299. snprintf(GroupName, sizeof(GroupName), "%02x", tmp[i]);
  300. strcat(buf, GroupName);
  301. }
  302. ttsPlay(ENCODE_USER_GBK, buf);
  303. }
  304. sutPocStatus.danHuStatus=0;
  305. sutPocStatus.firstLogin=1;
  306. }
  307. /*查询所属群组总数的响应
  308. 发AT+POC=3D0000获得
  309. msg:000000,nnnn(所属多少个群组)*/
  310. static void pro3dMsg(char *msg){
  311. char *pName;
  312. sutPocStatus.ListCurOnlineNum=strtol(&msg[6],&pName,16);
  313. sutPocStatus.ListUpdate=1;
  314. MSG_INFO(1, "groupNum:%d", sutPocStatus.ListCurOnlineNum);
  315. }
  316. /*查询所属在线成员总数的响应
  317. 发AT+POC=3E0000获得
  318. msg:000000,nnnn(所属多少个在线成员)*/
  319. static void pro3eMsg(char *msg){
  320. char *pName;
  321. sutPocStatus.ListCurOnlineNum=strtol(&msg[6],&pName,16);
  322. sutPocStatus.ListUpdate=1;
  323. MSG_INFO(1, "userNum:%d", sutPocStatus.ListCurOnlineNum);
  324. }
  325. /*查询所在组成员信息时返回,得到在线成员总数
  326. msg:000000,nnnn(在线成员总数)*/
  327. static void pro0eMsg(char *msg){
  328. }
  329. /*定量查询所在群组中的在线成员信息响应
  330. 发AT+POC=1E0000xxxxx获得
  331. msg:010000,iiii(成员列表索引),dddddddd(成员ID),mmmmmmmm(成员名称)*/
  332. static void pro1eMsg(char *msg){
  333. char name[POC_GROUP_USER_NAME_LEN*2+1];
  334. int len;
  335. unsigned long id;
  336. char *pTemp;
  337. if(!uiAssist.status)return 1;
  338. len = strlen(&msg[18]);
  339. if(len >= POC_GROUP_USER_NAME_LEN*2) len = POC_GROUP_USER_NAME_LEN*2;
  340. memcpy(name, &msg[18], len);
  341. name[len]=0;
  342. msg[18]=0;
  343. id=strtol(&msg[10],&pTemp,16);
  344. sutPocStatus.AllUsers[sutPocStatus.ListFillIndex].ID=id;
  345. if(name[0]==0){
  346. sutPocStatus.AllUsers[sutPocStatus.ListFillIndex].name[0]=' ';
  347. sutPocStatus.AllUsers[sutPocStatus.ListFillIndex].name[1]=0;
  348. }else StrAsciiToHex(name, sutPocStatus.AllUsers[sutPocStatus.ListFillIndex].name);
  349. sutPocStatus.ListFillIndex++;
  350. if(sutPocStatus.ListFillIndex==sutPocStatus.ExceptionReadNum){
  351. sutPocStatus.ListGetOneFlag=1;
  352. sutPocStatus.ListDetailValid=1;
  353. }
  354. }
  355. /*定时查询所属组信息
  356. 发AT+POC=1D0000xxxxx获得
  357. msg:000000,iiii(组列表索引),dddddddd(组ID),nnnn(成员个数),mmmmmmmmm(名称)*/
  358. static void pro1dMsg(char *msg){
  359. unsigned short num;
  360. char name[POC_GROUP_USER_NAME_LEN*2+1];
  361. unsigned long id;
  362. unsigned short index;
  363. char *pTemp;
  364. int len;
  365. if(!uiAssist.status)return ;
  366. len = strlen(&msg[22]);//已去掉回车换行
  367. if(len >= POC_GROUP_USER_NAME_LEN*2) len = POC_GROUP_USER_NAME_LEN*2;
  368. memcpy(name, &msg[22], len);
  369. name[len]=0;
  370. msg[22]=0;
  371. num=strtol(&msg[18],&pTemp,16);
  372. msg[18]=0;
  373. id=strtol(&msg[10],&pTemp,16);
  374. sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].ID=id;
  375. sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].usernum=num;
  376. if(name[0]==0){
  377. sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].name[0]=' ';
  378. sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].name[1]=0;
  379. }else
  380. StrAsciiToHex(name, sutPocStatus.AllGroups[sutPocStatus.ListFillIndex].name);
  381. sutPocStatus.ListFillIndex++;
  382. if(sutPocStatus.ListFillIndex==sutPocStatus.ExceptionReadNum){
  383. sutPocStatus.ListGetOneFlag=1;
  384. sutPocStatus.ListDetailValid=1;
  385. }
  386. }
  387. /*
  388. +POC_VER:01027
  389. msg=01027
  390. */
  391. static void pocGetVer(char *msg){
  392. snprintf(sutApp.pocVersion, sizeof(sutApp.pocVersion), "%s",msg);
  393. }
  394. static void pocGetPpp(char *msg){
  395. if(msg[0]=='1') sutApp.pocPpp=1;
  396. else{
  397. sutApp.pocPpp=0;
  398. learnUserInfoClear();
  399. }
  400. }
  401. /*
  402. +GAUTH:AD86EBCCECC4
  403. msg=AD86EBCCECC4+回车
  404. */
  405. static void proGauthMsg(char *msg){
  406. #if 1
  407. unsigned char newAuthTable[10]={0x50,0x28,0xaf,0x6d,0x08,0x9c,0x1b,0xe4,0x23,0x77};
  408. unsigned char randBuf[100];
  409. char buf[3];
  410. int len,i,j;
  411. len=0;
  412. for(i=0;i<strlen(msg);i++){
  413. if(msg[i]=='\r' || msg[i]=='\n' || msg[i]=='\0') goto MSG_DONE;
  414. randBuf[len++]=msg[i];
  415. }
  416. MSG_DONE:
  417. //获取串并转换成16进制加密串
  418. if(len%2 || 0!=restoreDataFormatByHex(randBuf,len)){
  419. MSG_WARN(1, "auth get error");
  420. return;
  421. }
  422. len /= 2;//得到加密信息:长度为len的randBuf
  423. extCodeBuffer(randBuf, len,newAuthTable, sizeof(newAuthTable));
  424. snprintf(randBuf, sizeof(randBuf), "AT+SAUTH=");
  425. //将长度为i的tmp内存以十六进制串打包发送
  426. for(j=0;j<sizeof(newAuthTable);j++){
  427. snprintf(buf, sizeof(buf),"%02x",newAuthTable[j]);
  428. strcat(randBuf, buf);
  429. }
  430. strcat(randBuf, "\r\n");
  431. msgAtSend(randBuf);
  432. MSG_INFO(0, randBuf);
  433. #else
  434. #define FACTORY_MARK "PC-TOOL"
  435. #define MODULE_MARK "PC-TEST-TOOL"
  436. unsigned char randBuf[20];
  437. unsigned char tmp[16+16+20];
  438. unsigned char imei[20];
  439. char sendBuf[sizeof(tmp)*2+20]="AT+SAUTH=";
  440. char *fillPtr=sendBuf+9;
  441. char buf[3];
  442. char *imeiPtr;
  443. int len,i,j;
  444. len=0;
  445. for(i=0;i<strlen(msg);i++){
  446. if(msg[i]=='\r' || msg[i]=='\n' || msg[i]=='\0') goto MSG_DONE;
  447. randBuf[len++]=msg[i];
  448. }
  449. MSG_DONE:
  450. //获取串并转换成16进制加密串
  451. if(len%2 || 0!=restoreDataFormatByHex(randBuf,len)){
  452. MSG_WARN(1, "auth get error");
  453. return;
  454. }
  455. len /= 2;//得到加密信息:长度为len的randBuf
  456. //对串进行加密码,加密对像为厂商+机型+设备ID[32+32+20]
  457. imeiPtr=ohpocGetIMEI();
  458. if(NULL==imeiPtr){
  459. MSG_WARN(1, "imei is not ready");
  460. return;
  461. }
  462. MSG_INFO(1, "IMEI:%s",imeiPtr);
  463. i=strlen(imeiPtr);
  464. if(i>sizeof(imei)){
  465. MSG_ERR(1, "imei buffer overflow:%d",i);
  466. return;
  467. }
  468. memcpy(imei, imeiPtr,i);//得到IMEI数据:长度为i的imei
  469. //组织协议数据
  470. memset(tmp, 0,sizeof(tmp));
  471. memcpy(tmp,FACTORY_MARK,strlen(FACTORY_MARK));
  472. memcpy(tmp+16, MODULE_MARK,strlen(MODULE_MARK));
  473. tmp[32]=i;
  474. memcpy(tmp+33,imei,i);
  475. i=32+1+i;
  476. //使用长度为len的randBuf加密串对长度为i的tmp进行加密
  477. extCodeBuffer(randBuf, len, tmp, i);
  478. //将长度为i的tmp内存以十六进制串打包发送
  479. for(j=0;j<i;j++){
  480. snprintf(buf, sizeof(buf),"%02x",tmp[j]);
  481. *fillPtr++=buf[0];
  482. *fillPtr++=buf[1];
  483. }
  484. *fillPtr++='\r';
  485. *fillPtr++='\n';
  486. *fillPtr++='\0';
  487. msgAtSend(sendBuf);
  488. MSG_INFO(0, sendBuf);
  489. #endif
  490. }
  491. /*
  492. +NOTE:0,1
  493. msg=0,1+回车
  494. */
  495. static void proNoteMsg(char *msg){
  496. MSG_INFO(1,"authAck:%s",msg);
  497. }
  498. /*
  499. $MYSYSINFO: 4,03
  500. msg=4,03
  501. */
  502. static void proNetMode(char *msg){
  503. unsigned char netModeValue;
  504. if(msg[0]<'0' || msg[0]>'9') return;
  505. netModeValue=msg[0]-0x30;
  506. netshowvalue=netModeValue;
  507. }
  508. /*
  509. +RSIM:1
  510. msg=1/2
  511. */
  512. static void proSimMode(char *msg){
  513. unsigned char tmpSim;
  514. tmpSim=msg[0]-0x31;
  515. if(tmpSim!=0 && tmpSim!=1) return;
  516. sutApp.simSel=tmpSim;
  517. }
  518. /*
  519. +UDP:0,5,30
  520. msg=0,5,30
  521. */
  522. static void proPwrMode(char *msg){
  523. int seg1,seg2;
  524. short i;
  525. char buf[15];
  526. for(i=2;i<strlen(msg);i++){
  527. if(msg[i]==','){
  528. seg1=atoi(msg+2);
  529. seg2=atoi(msg+i+1);
  530. pwrModeAckHandler(seg1,seg2);
  531. }
  532. }
  533. }
  534. /*
  535. +FOTA:1,0
  536. +FOTA:1,XXX
  537. +FOTA:0
  538. +FOTA:1
  539. +FOTA:2
  540. msg=1,xxxx
  541. */
  542. static void proFotaMsg(char *msg){
  543. char buf[50];
  544. if(msg[1]==','){
  545. if(msg[2]=='0' && msg[3]==0){
  546. fotaMsgShow("无更新版本");
  547. fotaStepSet(4);
  548. }else{
  549. strcpy(sutApp.fotaVersion, msg+2);
  550. snprintf(buf, sizeof(buf), "是否更新到:%s",sutApp.fotaVersion);
  551. fotaMsgShow(buf);
  552. fotaStepSet(1);
  553. }
  554. }else if(msg[1]==0){
  555. if(msg[0]=='0'){
  556. fotaMsgShow("升级失败");
  557. fotaStepSet(4);
  558. }else if(msg[0]=='1') fotaMsgShow("正在下载");
  559. else if(msg[0]=='2'){
  560. fotaMsgShow("下载成功");
  561. fotaStepSet(3);
  562. }
  563. }
  564. }
  565. /*
  566. +GMR: N58-R07-STD-OE_V20-03
  567. msg= N58-R07-STD-OE_V20-03
  568. */
  569. static void proGmrMsg(char *msg){
  570. snprintf(sutApp.modemVer, sizeof(sutApp.modemVer), "%s", msg+1);
  571. }
  572. /*
  573. +SMS:1,B2E2CAD4313233
  574. msg=1,B2E2CAD4313233
  575. */
  576. static void proSmsMsg(char *msg){
  577. unsigned char smsType=msg[0]-0x30;
  578. unsigned len=strlen(msg+2);
  579. if(len%2 || 0!=restoreDataFormatByHex(msg+2,len)){
  580. MSG_WARN(1, "sms data error");
  581. return;
  582. }
  583. len /= 2;
  584. sutMess.codeType=smsType;
  585. sutSms.smsUpdate=1;
  586. memcpy(sutMess.GBKMess1+4, msg+2, len);
  587. }
  588. /*服务器报下发报警TTS,POC已播报,本信息只提示*/
  589. static void proAlarmMsg(void){
  590. }
  591. static void proPendMsg(void){
  592. MSG_INFO(1, "active auth now");
  593. msgAtSend("AT+GAUTH\r\n");//用于授权检测
  594. }
  595. static void proToneMsg(char *msg){
  596. #ifndef ENABLE_PWM_BEEP
  597. if(msg[0]=='1'){
  598. sutPocStatus.TONE=1;
  599. paControl(true);
  600. }else if(msg[0]=='0'){
  601. sutPocStatus.TONE=0;
  602. }
  603. #endif
  604. }
  605. /*
  606. +GPIP:183.131.13.10
  607. msg=183.131.13.10
  608. */
  609. static void proGPIPMsg(char *msg){
  610. if(strlen(msg)<7) return;
  611. if(strcmp(showPIP, msg)==0) return;
  612. snprintf(showPIP, sizeof(showPIP), "%s",msg);
  613. MSG_INFO(1, "updatePIP:%s", showPIP);
  614. }
  615. /*
  616. +GGIP:183.131.13.6
  617. msg=183.131.13.6
  618. */
  619. static void proGGIPMsg(char *msg){
  620. if(strlen(msg)<7) return;
  621. if(strcmp(showGIP, msg)==0) return;
  622. snprintf(showGIP, sizeof(showGIP), "%s",msg);
  623. MSG_INFO(1, "updateGIP:%s", showGIP);
  624. }
  625. /*
  626. +CSQ: 14,99
  627. msg=14,99
  628. */
  629. static void proCsqMsg(char *msg){
  630. int csq=atoi(msg);
  631. if(csq != sutApp.g_iCSQ) sutApp.g_iCSQ=csq;
  632. }