ZXPocTask.c 14 KB

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