ZXPocTask.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. #include "includes.h"
  2. SUT_POC_STATUS sutPocStatus;
  3. OS_TID idPocTask=0;
  4. //U64 stkPocTask[POC_TASK_STK_SIZE];
  5. unsigned long g_ulGroupID;
  6. unsigned char g_ucSelect=0;
  7. int g_iModemVer=0;
  8. int g_iPocVer=0;
  9. /*****************************************
  10. numb:取第几个&后的字段
  11. string:返回的字段
  12. return: 返回当前所处位置
  13. ******************************************/
  14. unsigned char StringCatByNumb(char *msg,char numb,char *string)
  15. {
  16. short i=0;
  17. short j=0;
  18. char flag=0;
  19. short Indexcnt=0;
  20. while(*msg!=0x0d && *msg!=0x0a) //0d
  21. {
  22. if(*msg=='&')
  23. {
  24. i++;
  25. if(i>numb){
  26. break;
  27. }
  28. }
  29. if(i==numb){
  30. if(flag==0){
  31. j++;
  32. Indexcnt=j;
  33. flag=1;
  34. msg++;
  35. }
  36. *string++=*msg;
  37. }
  38. msg++;
  39. j++;
  40. }
  41. *string++=0;
  42. //printf("i===%d,j====%d,numb===%d,index====%d\r\n",i,j,numb,Indexcnt);
  43. if(i<numb) return 0;
  44. return Indexcnt;
  45. }
  46. int GetUserInfo(char *msg,int MsgLen)
  47. {
  48. char name[POC_USER_NAME_LEN*2+1];
  49. unsigned int Index;
  50. unsigned short ValidDate;
  51. unsigned int id;
  52. char Stracebuf[50];
  53. //>200&用户ID&缺省群组ID&用户账号有效期&用户名称
  54. StringCatByNumb(msg,1,name);
  55. sutPocStatus.LocalUser.ID=atoi(name);
  56. Index=StringCatByNumb(msg,3,name);
  57. //printf("INDEX111111======%d\r\n",Index);
  58. //SlwTrace(INF,"/*******日期*********/",1);
  59. //SlwTrace(INF,name,1);////////////////////
  60. ValidDate=atoi(name);
  61. snprintf(Stracebuf,sizeof(Stracebuf),"有效日期为:%d.......",ValidDate);
  62. SlwTrace(INF,Stracebuf,1);
  63. Index=StringCatByNumb(msg,4,name);
  64. //printf("MSLEN===%d,index===%d\r\n",MsgLen,Index);
  65. SlwTrace(INF,name,1);
  66. //memcpy(sutPocStatus.LocalUser.name,name,MsgLen-Index-3);
  67. strcpy(sutPocStatus.LocalUser.name,name);
  68. ModemSendAT("AT+POC=508\r\n");
  69. return 0;
  70. }
  71. int GetGroupInfo(char *msg,int MsgLen)
  72. {
  73. char name[POC_USER_NAME_LEN*2+1];
  74. unsigned long id;
  75. unsigned short index;
  76. char Stracebuf[50];
  77. //>201&群组ID&在线状态&群组名称
  78. index=StringCatByNumb(msg,1,name);
  79. //SlwTrace(INF,"GROUP-----------------",1);
  80. SlwTrace(INF,name,1);
  81. sutPocStatus.LocalGroup.ID=atoi(name);
  82. //printf("groupID===============%d\r\n",sutPocStatus.LocalGroup.ID);
  83. StringCatByNumb(msg,2,name);
  84. sutPocStatus.Logined=atoi(name); // 判断是否登录
  85. sutPocStatus.FirstLogined=1;
  86. index=StringCatByNumb(msg,3,name);
  87. SlwTrace(INF,name,1);
  88. memset(sutPocStatus.LocalGroup.name,0,sizeof(sutPocStatus.LocalGroup.name));
  89. //memcpy(sutPocStatus.LocalGroup.name,name,MsgLen-index-3);
  90. strcpy(sutPocStatus.LocalGroup.name,name);
  91. //对讲状态初始化
  92. sutPocStatus.Speaker=0;
  93. sutPocStatus.PPTpress=0;
  94. SlwTrace(INF, "login ok",1);
  95. snprintf(Stracebuf,sizeof(Stracebuf),"AT+POC=522&%d&%d\r\n",(Vbat-340)*100/(430-340),g_iCSQ);
  96. ModemSendAT(Stracebuf);
  97. os_dly_wait(10);
  98. //获取模块时间
  99. ModemSendAT("AT+POC=509\r\n");
  100. return 0;
  101. }
  102. int GetMcuSpeakerInfo(char *msg,int MsgLen)
  103. {
  104. char name[POC_USER_NAME_LEN*2+1];
  105. unsigned long id;
  106. unsigned short index;
  107. char Stracebuf[50];
  108. //206&组呼&状态&主叫ID&被叫ID&主叫 用户名&被叫用户名
  109. //判断开始或结束
  110. StringCatByNumb(msg,2,name);
  111. if(atoi(name)==1){
  112. sutPocStatus.Speaker=1;
  113. if(sutUIstatus.Status!=UIS_STANDBY) sutPocStatus.PocingCnt=1;
  114. SlwTrace(INF,"开始说话----\r\n",0);
  115. //先判断类型
  116. StringCatByNumb(msg,1,name);
  117. if(atoi(name)==4)sutPocStatus.SOS_Flag=1;
  118. }else if(atoi(name)==2){
  119. StringCatByNumb(msg,1,name);
  120. if(atoi(name)==1)sutPocStatus.SOS_Flag=0;
  121. if(sutPocStatus.SOS_Flag==0)sutPocStatus.Speaker=0;
  122. sutPocStatus.PocingCnt=0;
  123. SlwTrace(INF,"结束说话----\r\n",0);
  124. //memset(sutPocStatus.Callname,0,sizeof(sutPocStatus.Callname));
  125. return 0;
  126. }
  127. //获取主叫ID
  128. StringCatByNumb(msg,3,name);
  129. sutPocStatus.CallID=atoi(name);
  130. //获取主叫用户名
  131. index=StringCatByNumb(msg,5,name);
  132. memset(sutPocStatus.Callname,0,sizeof(sutPocStatus.Callname));
  133. strcpy(sutPocStatus.Callname,name);
  134. return 0;
  135. }
  136. char ZXPocHandle(char *msg,int MsgLen)
  137. {
  138. char i,j;
  139. char cmd[4];
  140. unsigned long id;
  141. unsigned short index;
  142. char Tempbuf[100];
  143. char tempbuf[6];
  144. unsigned short cmdnum;
  145. if(*msg=='>'){
  146. for(i=0;i<3;i++) {
  147. cmd[i]=msg[i+1];
  148. }
  149. }else {
  150. for(i=0;i<3;i++) {
  151. cmd[i]=msg[i];
  152. }
  153. }
  154. cmd[3]=0;
  155. cmdnum=atoi(cmd);
  156. //printf("cmd====%d\r\n",cmdnum);
  157. switch(cmdnum){
  158. case MCU_R_APP_START_STR: //APP登录
  159. snprintf(Tempbuf,sizeof(Tempbuf),"AT+POC=504&%s&%s&%s&%s&%s&%s&%d&%d&%s\r\n",sutProductPara.PIP,sutProductPara.APNApn,sutProductPara.Net_Mode \
  160. ,sutProductPara.Language,sutProductPara.Local,sutProductPara.Channel,sutProductPara.SendToneEnadble,sutProductPara.PromptToneEnable,sutProductPara.IMEI);
  161. SlwTrace(INF,Tempbuf,1);
  162. ModemSendAT(Tempbuf);
  163. break;
  164. case MCU_R_AMP_ON_STR:
  165. sutPocStatus.TTS=1;
  166. SpeakerEnable();
  167. break;
  168. case MCU_R_AMP_OFF_STR:
  169. sutPocStatus.TTS=0;// 测试用
  170. SpeakerDisable();
  171. break;
  172. case MCU_R_GET_BATVOL_STR:
  173. //AT+POC=522&80&12
  174. //ModemSendAT("AT+POC=522&80&12\r\n");
  175. if(Vbat>435)snprintf(Tempbuf,sizeof(Tempbuf),"AT+POC=522&%d&%d\r\n",100,g_iCSQ);
  176. else if(Vbat>330)snprintf(Tempbuf,sizeof(Tempbuf),"AT+POC=522&%d&%d\r\n",(Vbat-340)*100/(430-340),g_iCSQ);
  177. ModemSendAT(Tempbuf);
  178. break;
  179. case MCU_R_PUSH_SELF_INFO_STR: // 200 用户自己的信息
  180. //>200&用户ID&缺省群组ID&用户账号有效期&用户名称
  181. GetUserInfo(msg,MsgLen);
  182. break;
  183. case MCU_R_PUSH_ONOFFLINE_STR: //201 群组,及是否在线
  184. GetGroupInfo(msg,MsgLen);
  185. break;
  186. case MCU_R_PUSH_US_STATE_STR: //204 //推送好友状态变化
  187. break;
  188. case MCU_R_PUSH_PTT_RES_STR: //205 推送PTT说话状态
  189. StringCatByNumb(msg,1,Tempbuf);
  190. if(atoi(Tempbuf)==1){
  191. if(g_usSOSCnt==3){
  192. sutPocStatus.SOS_Flag=1;
  193. }
  194. sutPocStatus.PPTpress=1;
  195. sutPocStatus.Speaker=0;
  196. }
  197. else{
  198. Pttfreeflag=0;
  199. sutPocStatus.SOS_Flag=0;
  200. sutPocStatus.PPTpress=0;
  201. }
  202. //>205&类型&被叫ID&被叫名称&状态
  203. break;
  204. case MCU_R_PUSH_SPEAK_STR: //206 //推送被叫 说话状态
  205. //206&1&1&5219878&6920&4&用户
  206. //206&组呼&状态&主叫ID&被叫ID&主叫 用户名&被叫用户名
  207. LCDTimeOut(0);
  208. //LcdSendCommand(0x29);
  209. // LCD_BL_HIGH;
  210. // LcdSleepFlag=0;
  211. sutLcdParam.OnTimeCt=0;
  212. GetMcuSpeakerInfo(msg,MsgLen);
  213. break;
  214. case MCU_R_PUSH_P2PCALL_STR : // 207 //推送单呼 主叫状态
  215. //>207&状态&被叫ID&被叫name //状态 0失败 1成功 2等待 3对方拒接 4结束
  216. index=StringCatByNumb(msg,1,Tempbuf);
  217. if(atoi(Tempbuf)==1){
  218. sutPocStatus.danHunStatus=2;
  219. UISetNextStatus(UIS_STANDBY);
  220. }
  221. else if(atoi(Tempbuf)==2){ //等待
  222. // sutPocStatus.danHunStatus=1;
  223. // GuiClearRect(0,110,160,128);
  224. }
  225. else if(atoi(Tempbuf)==0){
  226. sutPocStatus.danHunStatus=0;//单呼失败
  227. snprintf(Tempbuf,sizeof(Tempbuf),"呼叫失败");
  228. ShowMessageBox(Tempbuf);
  229. UISetNextStatus(UIS_STANDBY);
  230. }
  231. else if(atoi(Tempbuf)==3){
  232. sutPocStatus.danHunStatus=0;//单呼失败
  233. snprintf(Tempbuf,sizeof(Tempbuf),"对方拒绝接通");
  234. ShowMessageBox(Tempbuf);
  235. UISetNextStatus(UIS_STANDBY);
  236. }
  237. else if(atoi(Tempbuf)==4){
  238. sutPocStatus.Speaker=0;
  239. sutPocStatus.PPTpress=0;
  240. sutPocStatus.danHunStatus=0;//单呼结束
  241. sutPocStatus.PocingCnt=0;
  242. UISetNextStatus(UIS_STANDBY);
  243. }
  244. break;
  245. case MCU_R_PUSH_P2PBCALL_STR : //208 //推送单呼 被叫状态
  246. //>208&状态&被叫ID&被叫name //状态 1开始 2接通 3对方拒接 4结束
  247. LCDTimeOut(0);
  248. sutLcdParam.OnTimeCt=0;
  249. index=StringCatByNumb(msg,1,Tempbuf);
  250. if(atoi(Tempbuf)==2){
  251. sutPocStatus.danHunStatus=2;//单呼成功 /////////1
  252. StringCatByNumb(msg,3,Tempbuf);
  253. memset(sutPocStatus.Callname,0,sizeof(sutPocStatus.Callname));
  254. strcpy(sutPocStatus.Callname,Tempbuf);
  255. if(sutUIstatus.Status!=UIS_STANDBY) sutPocStatus.PocingCnt=1;
  256. }
  257. if(atoi(Tempbuf)==4){
  258. sutPocStatus.danHunStatus=0;//单呼结束
  259. sutPocStatus.Speaker=0;
  260. sutPocStatus.PocingCnt=0;//1
  261. if(sutUIstatus.Status==UIS_STANDBY)GuiClearAreaFixColor(100,111,60,18,OrangeColorId);
  262. }
  263. break;
  264. case MCU_R_GET_UNUM_STR: //135 //获取在线用户数量
  265. //>135&7
  266. StringCatByNumb(msg,1,Tempbuf);
  267. sutPocStatus.UserOnLineNum=atoi(Tempbuf);
  268. sutPocStatus.UserNum_Update=1;
  269. snprintf(Tempbuf, sizeof(Tempbuf), "oneLine:%d",sutPocStatus.UserOnLineNum);
  270. SlwTrace(INF,Tempbuf,1);
  271. break;
  272. case MCU_R_GET_GNUM_STR : //132 //群组数量
  273. StringCatByNumb(msg,1,Tempbuf);
  274. sutPocStatus.GroupOnLineNum=atoi(Tempbuf);
  275. sutPocStatus.GroupNum_Update=1;
  276. snprintf(Tempbuf, sizeof(Tempbuf), "onLine:%d",sutPocStatus.GroupOnLineNum);
  277. SlwTrace(INF,Tempbuf,1);
  278. break;
  279. case MCU_R_GET_REC_NUM_STR: //150 录音记录个数
  280. //>150&6805&10 recordID
  281. StringCatByNumb(msg,1,Tempbuf);
  282. id=atoi(Tempbuf);
  283. if(sutPocStatus.recordID==id){
  284. StringCatByNumb(msg,2,Tempbuf);
  285. sutPocStatus.VoiceOnLineNum=atoi(Tempbuf);
  286. sutPocStatus.VoiceNum_Update=1;
  287. snprintf(Tempbuf, sizeof(Tempbuf), "vioce onLine:%d",sutPocStatus.VoiceOnLineNum);
  288. SlwTrace(INF,Tempbuf,1);
  289. }
  290. break;
  291. case MCU_R_GET_GP_LIST_STR: //134 //群组列表
  292. //>134&个数&起始序列号&GID&名称&GID&名称
  293. //>134&1 & N &UID&Uname
  294. if(strlen(msg)<10){
  295. //规避异常
  296. break;
  297. }
  298. memset(sutPocStatus.AllGroups[sutPocStatus.FillGroupIndex].name,0,POC_GROUP_NAME_LEN);
  299. index=StringCatByNumb(msg,4,Tempbuf);
  300. //memcpy(sutPocStatus.AllGroups[sutPocStatus.FillGroupIndex].name,Tempbuf,MsgLen-index-3);
  301. //strcpy(sutPocStatus.AllGroups[sutPocStatus.FillGroupIndex].name,Tempbuf);
  302. strncpy(sutPocStatus.AllGroups[sutPocStatus.FillGroupIndex].name,Tempbuf,POC_USER_NAME_LEN);
  303. StringCatByNumb(msg,3,Tempbuf);
  304. sutPocStatus.AllGroups[sutPocStatus.FillGroupIndex].ID=atoi(Tempbuf);
  305. //sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].status=3;
  306. sutPocStatus.GetOneGroupFlag=1;
  307. break;
  308. case MCU_R_GET_LUS_LIST_STR: // 137 在线用户列表
  309. //>137&个数&起始序列号&UID&名称&UID&名称
  310. //>137&1 & N &UID&Uname
  311. if(strlen(msg)<10){
  312. //规避异常
  313. break;
  314. }
  315. memset(sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].name,0,POC_USER_NAME_LEN);
  316. memset(Tempbuf,0,sizeof(Tempbuf));
  317. index=StringCatByNumb(msg,4,Tempbuf);
  318. if(Tempbuf==0){
  319. strncpy(sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].name,"空",POC_USER_NAME_LEN);
  320. }else strncpy(sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].name,Tempbuf,POC_USER_NAME_LEN);
  321. //memcpy(sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].name,Tempbuf,MsgLen-index-3);
  322. //strcpy(sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].name,Tempbuf);
  323. StringCatByNumb(msg,3,Tempbuf);
  324. sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].ID=atoi(Tempbuf);
  325. sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].status=3;
  326. sutPocStatus.GetOneUserFlag=1;
  327. break;
  328. case MCU_R_GET_REC_LIST_STR: // 151 录音文件列表
  329. if(strlen(msg)<10||sutPocStatus.FillVoiceIndex>4){
  330. //规避异常
  331. break;
  332. }
  333. //>151&个数&起始序列&类型&时长&名字 //类型 0:呼出 1呼入
  334. memset(sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].name,0,POC_USER_NAME_LEN);
  335. index=StringCatByNumb(msg,5,Tempbuf); //7
  336. //memcpy(sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].name,Tempbuf,MsgLen-index-3);
  337. //strcpy(sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].name,Tempbuf);
  338. printf("==========FillVoiceIndex====%d======\r\n",sutPocStatus.FillVoiceIndex);
  339. strncpy(sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].name,Tempbuf,POC_USER_NAME_LEN);
  340. StringCatByNumb(msg,2,Tempbuf);
  341. sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].ID=atoi(Tempbuf);
  342. StringCatByNumb(msg,3,Tempbuf);
  343. sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].type=atoi(Tempbuf);
  344. StringCatByNumb(msg,4,Tempbuf);
  345. if(atoi(Tempbuf)/1000==0) sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].time=1;
  346. else sutPocStatus.AllVoices[sutPocStatus.FillVoiceIndex].time=atoi(Tempbuf)/1000;
  347. //sutPocStatus.AllUsers[sutPocStatus.FillUserIndex].status=3;
  348. sutPocStatus.GetOneVoiceFlag=1;
  349. break;
  350. case MCU_R_TIME_STR: //140 //网络时间
  351. //>140&2019&5&23&9&51&31
  352. StringCatByNumb(msg,4,Tempbuf);
  353. g_usModeHTime=atoi(Tempbuf); //+8
  354. StringCatByNumb(msg,5,Tempbuf);
  355. g_usModeMTime=atoi(Tempbuf);
  356. StringCatByNumb(msg,6,Tempbuf);
  357. g_usModeSTime=atoi(Tempbuf);
  358. SetTime(g_usModeHTime, g_usModeMTime, g_usModeSTime);
  359. break;
  360. case MCU_R_ENABLE_GPS_STR: // 117使能GPS 获取GPS 上传间隔
  361. // sutGpsInfo.GPS_UploadTime
  362. ///>117&5000 5000MS
  363. StringCatByNumb(msg,1,Tempbuf);
  364. sutGpsInfo.GPS_UploadTime=atoi(Tempbuf)/1000;
  365. if(sutGpsInfo.GPS_UploadTime<=0) sutGpsInfo.GPS_UploadTime=15; /// 测试用
  366. sutGpsInfo.Updata=1;
  367. g_uiGpsStat=1;
  368. break;
  369. case MCU_R_DISABLE_GPS_STR : // 118 关闭GPS
  370. sutGpsInfo.Updata=1;
  371. g_uiGpsStat=0;
  372. break;
  373. // case MCU_R_LED_STR: //set LED 110
  374. // //>110&red_mode&red_offtime&red_ontime&greed_mode&green_offtime&green_ontim
  375. //
  376. // StringCatByNumb(msg,1,Tempbuf); //red 长亮或长灭
  377. //
  378. // if(atoi(Tempbuf)==1) {
  379. // sucRedLedSleep=0;
  380. // sucRedLedFlash=1;
  381. //
  382. // }
  383. // else if(atoi(Tempbuf)==2) {
  384. // sucRedLedFlash=0;
  385. // sucRedLedSleep=1;
  386. // }
  387. // else {
  388. // StringCatByNumb(msg,2,Tempbuf);
  389. // sucRedLedSleep=atoi(Tempbuf)/100;
  390. //
  391. // StringCatByNumb(msg,2,Tempbuf);
  392. // sucRedLedFlash=atoi(Tempbuf)/100;
  393. // }
  394. // StringCatByNumb(msg,4,Tempbuf); //green
  395. //
  396. // if(atoi(Tempbuf)==1) {
  397. // sucBlueLedSleep=0;
  398. // sucBlueLedFlash=1;
  399. // }
  400. // else if(atoi(Tempbuf)==2){
  401. // sucBlueLedFlash=0;
  402. // sucBlueLedSleep=1;
  403. // }
  404. // else {
  405. // StringCatByNumb(msg,5,Tempbuf);
  406. // sucBlueLedSleep=atoi(Tempbuf)/100;
  407. // StringCatByNumb(msg,6,Tempbuf);
  408. // sucBlueLedFlash=atoi(Tempbuf)/100;
  409. // }
  410. // break;
  411. case MCU_R_VERSION_STR_STR: //获取POC 版本
  412. index=StringCatByNumb(msg,1,Tempbuf);
  413. SlwTrace(INF,Tempbuf,1);
  414. g_iPocVer=atoi(Tempbuf);
  415. break;
  416. case MCU_R_TRANS_AT_CMD_STR: //modem 要求MCU 发送AT
  417. strcpy(Tempbuf,&msg[5]);
  418. ModemSendAT(Tempbuf);
  419. break;
  420. //sutPocStatus
  421. case MCU_R_PLAY_REC_STR:
  422. StringCatByNumb(msg,2,Tempbuf);
  423. sutPocStatus.TTS= atoi(Tempbuf); //0 失败 1 正在播放 2播放结束
  424. break;
  425. default:
  426. break;
  427. }
  428. }
  429. void LoginPocInfo()
  430. {
  431. char Tempbuf[100];
  432. snprintf(Tempbuf,sizeof(Tempbuf),"AT+POC=504&%s&%s&%s&%s&%s&%s&%d&%d&%s\r\n",sutProductPara.PIP,sutProductPara.APNApn,sutProductPara.Net_Mode \
  433. ,sutProductPara.Language,sutProductPara.Local,sutProductPara.Channel,sutProductPara.SendToneEnadble,sutProductPara.PromptToneEnable,sutProductPara.IMEI);
  434. SlwTrace(INF,Tempbuf,1);
  435. ModemSendAT(Tempbuf);
  436. os_dly_wait(20);
  437. ModemSendAT(Tempbuf);
  438. }