poc.c 21 KB

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