Modem.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. #include "includes.h"
  2. SUT_MODEM_AT_MSG sutAtm,sutAtmPro;
  3. unsigned char ModemVer[15];
  4. void ModemPinConfig(void)
  5. {
  6. GPIO_InitTypeDef GPIO_InitStructure;
  7. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
  8. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  9. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  10. GPIO_InitStructure.GPIO_Pin = MODEM_RESET_PIN;
  11. GPIO_Init(MODEM_RESET_PORT, &GPIO_InitStructure);
  12. GPIO_InitStructure.GPIO_Pin = MODEM_PWREN_PIN;
  13. GPIO_Init(MODEM_PWREN_PORT, &GPIO_InitStructure);
  14. //MODEM DATE or UPDATE
  15. GPIO_InitStructure.GPIO_Pin = MODEM_UPDATE_PIN;
  16. GPIO_Init(MODEM_UPDATE_PORT, &GPIO_InitStructure);
  17. MODEM_UPDATE_LOW;
  18. MODEM_RESET_LOW;
  19. }
  20. void ModemSendAt(char *p){
  21. unsigned short len;
  22. len=strlen(p);
  23. Uart2Send((unsigned char *)p,len);
  24. }
  25. /************************************************************************************
  26. *
  27. *************************************************************************************/
  28. void ModemSendData(unsigned char *pData,unsigned short datalen)
  29. {
  30. Uart2Send(pData,datalen);
  31. }
  32. void ModemVersionGet(char *msg)
  33. {//InnerVersion: LLA0029_0016_1.0.57_L0901_EFS2.6
  34. char j,bufTemp[30],version[10],type,countFlag;
  35. if(0==ModemStrCmp(msg,"InnerVersion:")){
  36. countFlag=0;
  37. for(j=0;j<strlen(msg);j++){
  38. if(msg[j] == '_'){
  39. countFlag++;
  40. if(countFlag == 1){
  41. version[0] = msg[j+3];
  42. version[1] = msg[j+4];
  43. }else if(countFlag == 3){
  44. version[2] = msg[j+2];
  45. version[3] = msg[j+3];
  46. version[4] = msg[j+4];
  47. version[5] = msg[j+5];
  48. version[6] = 0;
  49. snprintf(bufTemp, sizeof(bufTemp), "ModemVer:%s",version);
  50. SlwTrace(INF, bufTemp, 1);
  51. g_iModemVer=atoi(version);
  52. }
  53. }
  54. }
  55. }
  56. }
  57. void SetDefaultSpkMic(void){
  58. char sendInfo[40];
  59. snprintf(sendInfo, sizeof(sendInfo), "at+syscmd=start_pcm volume ");
  60. if(1) strcat(sendInfo, "7 7\r\n");//这里1根据实际参数替换吧
  61. else strcat(sendInfo, "7 5\r\n");
  62. ModemSendAt(sendInfo);
  63. }
  64. char IMEI[18]={0};
  65. char *getIMEI(void){return IMEI;}
  66. void ModemGetIMEI(char *msg){
  67. //+LSHIMEI:862015039899963
  68. ReplaceStrWithN(msg);
  69. strncpy(IMEI, msg+9, sizeof(IMEI));
  70. printf("IMEI:%s\r\n",IMEI);
  71. }
  72. void ModemGetTime(char *msg)
  73. {
  74. USER_RTC_DEF tmpTime;
  75. //+CCLK: "20/07/03,09:18:32+32"
  76. ReplaceStrWithN(msg);
  77. tmpTime.year=atoi(&msg[8]);
  78. tmpTime.month=atoi(&msg[11]);
  79. tmpTime.day=atoi(&msg[14]);
  80. tmpTime.hour=atoi(&msg[17]);
  81. tmpTime.min=atoi(&msg[20]);
  82. tmpTime.second=atoi(&msg[23]);
  83. RTC_UserSetTime(tmpTime);
  84. printf("\r\nNewTime:%02d-%02d-%02d %02d:%02d:%02d\r\n",
  85. tmpTime.year,tmpTime.month,tmpTime.day,
  86. tmpTime.hour,tmpTime.min,tmpTime.second);
  87. }
  88. char CCID[21]={0};
  89. char *getICCID(void){return CCID;}
  90. void ModemGetICCID(char *msg){
  91. char bufTemp[3],info[20];
  92. //+CCID: 89860316452001903429
  93. memcpy(CCID, &msg[7], sizeof(CCID));
  94. CCID[20]=0;
  95. bufTemp[0] = CCID[4];
  96. bufTemp[1] = CCID[5];
  97. bufTemp[2] = 0;
  98. switch(atoi(bufTemp))
  99. {
  100. case 1:
  101. case 6:
  102. case 9:thisYunYingShang = CHINA_UNICOM;
  103. snprintf(info,sizeof(info), "CHINA_UNICOM]");
  104. break;
  105. case 0:
  106. case 2:
  107. case 4:
  108. case 7:thisYunYingShang = CHINA_MOBILE;
  109. snprintf(info,sizeof(info), "CHINA_MOBILE]");
  110. break;
  111. case 3:
  112. case 8:
  113. case 11:thisYunYingShang = CHINA_TELECOM;
  114. snprintf(info,sizeof(info), "CHINA_TELECOM]");
  115. break;
  116. default:snprintf(info,sizeof(info), "UNKNOW-ICCID]");
  117. break;
  118. }
  119. printf("ICCID:%s %s\r\n", CCID, info);
  120. }
  121. void ModemSetPocPara(char *msg,int len){
  122. //+POC:0200000069643D313030303031343031343B69703D3138332E3133312E31332E31303B7077643D3135303034343739303438383931343B646F6D61696E3D7777772E6869676F73706F632E636F6D3B
  123. //id=1000014014;ip=183.131.13.10;pwd=150044790488914;domain=www.higospoc.com;
  124. char buf[40];
  125. char buf1[100];
  126. char idFlag=0;
  127. char ipFlag=0;
  128. char pwdFlag=0;
  129. char domainFlag=0;
  130. char enableChangeIp=1;
  131. msg[len-3]=0;
  132. len=AsciiHexStringToHexBytes(&msg[13], msg);
  133. msg[len]=0;
  134. //找id
  135. len=GetParaFromStr(msg,"id",buf);
  136. snprintf(buf1, sizeof(buf1),"%lu",sutProductPara.PSN);
  137. if(0!=strcmp(buf1, buf)) idFlag=1;;
  138. // //找ip
  139. // len=GetParaFromStr(msg,"ip",buf);
  140. // snprintf(buf1, sizeof(buf1), "%s", getPIPAddr());
  141. // if(0!=strcmp(buf1, buf)) ipFlag=1;
  142. //找pwd
  143. len=GetParaFromStr(msg,"pwd",buf);
  144. snprintf(buf1, sizeof(buf1), "%s",DEV_HARDID);
  145. if(0!=strcmp(buf1, buf)) pwdFlag=1;
  146. //找domain
  147. switch(newPara.serList.defaultuse)
  148. {
  149. case SER_HZ:
  150. case SER_SD:
  151. case SER_US:
  152. break;
  153. case SER_IP:
  154. case SER_JIQUN:
  155. if(newPara.serList.defaultuse==SER_IP)snprintf(buf1, sizeof(buf1), "%s",newPara.serList.ipFenFa);
  156. else if(newPara.serList.defaultuse==SER_JIQUN)snprintf(buf1, sizeof(buf1), "%s",newPara.serList.jiqun);
  157. len=GetParaFromStr(msg,"domain",buf); //domain
  158. if(0!=strcmp(buf1, buf)) domainFlag=1;
  159. //modify by wjl 0609
  160. //但使用集群或者IP分发的时候,保证不去更新ip即可
  161. enableChangeIp=0;
  162. break;
  163. }
  164. //找ip
  165. if(enableChangeIp!=0){//modify by wjl 0609
  166. len=GetParaFromStr(msg,"ip",buf);
  167. snprintf(buf1, sizeof(buf1), "%s", getPIPAddr());
  168. if(0!=strcmp(buf1, buf)) ipFlag=1;
  169. }
  170. if(idFlag == 0 && ipFlag==0 && pwdFlag==0&&domainFlag==0) {
  171. SlwTrace(INF,"POC still",1);
  172. return;
  173. }
  174. RESET_ALL:
  175. ModemSendAt("AT+POC=010000");
  176. //更新id
  177. if(idFlag != 0){
  178. snprintf(buf, sizeof(buf),"id=%lu;",sutProductPara.PSN);
  179. AscStrToHexStr(buf,buf1);
  180. ModemSendAt(buf1);
  181. }
  182. //更新ip
  183. if(enableChangeIp!=0){//modify by wjl 0609
  184. //if(ipFlag != 0){
  185. snprintf(buf, sizeof(buf), "ip=%s;", getPIPAddr());
  186. AscStrToHexStr(buf,buf1);
  187. ModemSendAt(buf1);
  188. //}
  189. }
  190. //更新pwd
  191. // if(pwdFlag != 0){
  192. snprintf(buf, sizeof(buf), "pwd=%s;",DEV_HARDID);
  193. AscStrToHexStr(buf,buf1);
  194. ModemSendAt(buf1);
  195. //}
  196. if(newPara.serList.defaultuse==SER_IP)snprintf(buf, sizeof(buf), "domain=%s;",newPara.serList.ipFenFa);
  197. else if(newPara.serList.defaultuse==SER_JIQUN)snprintf(buf, sizeof(buf), "domain=%s;",newPara.serList.jiqun);
  198. else{
  199. snprintf(buf, sizeof(buf), "domain=;");
  200. AscStrToHexStr(buf,buf1);
  201. }
  202. AscStrToHexStr(buf,buf1);
  203. ModemSendAt(buf1);
  204. ModemSendAt("\r\n");
  205. SlwTrace(INF,"Rst_POCPara",1);
  206. }
  207. void MeSpeak(ENCODE_DEF type, char *voice)
  208. {
  209. char buf[20];//
  210. SpeakerCtrl(1);//wjl
  211. snprintf(buf, sizeof(buf), "AT+LSHTTS=%d,\"",type);
  212. ModemSendAt(buf);
  213. ModemSendAt(voice);
  214. // if(ENCODE_UNICODEBigend==type)
  215. // else TTSdaxieguibi(voice);
  216. ModemSendAt("\"\r\n");
  217. sutPocStatus.TTS=1;
  218. }
  219. void ModemApnConfig(void)
  220. {
  221. char needAuthLogin=0;
  222. char buf[100];
  223. char buf2[80];
  224. char i,t;
  225. char ApnSetFlag=0;
  226. char *apnName=newPara.apnList.apnList[newPara.apnList.defaultuse].account;
  227. char *apnPass=newPara.apnList.apnList[newPara.apnList.defaultuse].pass;
  228. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  229. snprintf(buf, sizeof(buf), "Accessp:");
  230. if(apnName[0] ==0 ||
  231. apnPass[0] ==0)
  232. {//名称或密码为空不配置,因为模块不支持
  233. strcat(buf, "unsupport-Empty");
  234. }else
  235. {
  236. snprintf(buf2, sizeof(buf2),"AT+CSTT=\"%s\",\"%s\",\"%s\"\r\n",newPara.apnList.APN_Name,apnName,apnPass);
  237. ModemSendAt(buf2);
  238. snprintf(buf2, sizeof(buf2), "%s,%s,%s",newPara.apnList.APN_Name,apnName,apnPass);
  239. strcat(buf,buf2);
  240. needAuthLogin=1;
  241. }
  242. SlwTrace(INF, buf,1);
  243. if(needAuthLogin != 0){
  244. //认证
  245. snprintf(buf, sizeof(buf),"AUTH-LOGIN:");
  246. switch(newPara.authType){
  247. case AUTH_LOGIN_PAP:strcat(buf, "PAP");
  248. case AUTH_LOGIN_CHAP:strcat(buf, "CHAP");
  249. snprintf(buf2, sizeof(buf2),"AT+CGAUTH=1,%d,%s,%s\r\n",newPara.authType,apnName,apnPass);
  250. ModemSendAt(buf2);
  251. SlwTrace(INF,buf2,0);
  252. break;
  253. case AUTH_LOGIN_NONE:strcat(buf, "NONE");
  254. break;
  255. default:strcat(buf, " Do nothing");
  256. break;
  257. }
  258. SlwTrace(INF,buf, 1);
  259. // ModemSendAt(buf2);
  260. // SlwTrace(INF,buf2,0);
  261. __nop();__nop();
  262. SlwTrace(INF,"AuthLogin Done",1);
  263. }
  264. }
  265. //////////////////////////////////////////
  266. void getModemModule(char *msg){
  267. memcpy(ModemVer,msg,strlen(msg)-2);
  268. SlwTrace(INF, msg,0);
  269. }
  270. void getModemVersion(char *msg){
  271. short j;
  272. char countFlag,version[10];
  273. SlwTrace(INF, msg, 0);
  274. countFlag=0;
  275. for(j=0;j<strlen(msg);j++){
  276. if(msg[j] == '_'){
  277. countFlag++;
  278. if(countFlag == 1){
  279. version[0] = msg[j+3];
  280. version[1] = msg[j+4];
  281. }else if(countFlag == 3)
  282. {
  283. version[2] = msg[j+2];
  284. version[3] = msg[j+3];
  285. version[4] = msg[j+4];
  286. version[5] = msg[j+5];
  287. version[6] = 0;
  288. g_iModemVer=atoi(version);
  289. printf("ModemVer:%d\r\n",g_iModemVer);
  290. }
  291. }
  292. }
  293. }
  294. //AT+POC=version
  295. //+POC:BROAD-3.0.7-20200812-release
  296. void getPocVersion(char *msg,HGS_POC_DEF type){
  297. int i,j,len,ver;
  298. char bufTemp[40];
  299. len = strlen(msg);
  300. j=0;
  301. for(i=0;i<len;i++){
  302. if(msg[i] == '\r'){
  303. bufTemp[j]=0;
  304. strncpy(g_iPocVer,bufTemp,sizeof(g_iPocVer));
  305. //ver=atoi(bufTemp);
  306. snprintf(bufTemp, sizeof(bufTemp),"POCver:%s<->%s", bufTemp,msg);
  307. SlwTrace(INF, bufTemp,0);
  308. // g_iPocVer=ver;
  309. return;
  310. }else if(msg[i] >= '0' && msg[i] <= '9') bufTemp[j++]=msg[i];
  311. }
  312. }
  313. void CheckPocType(void)
  314. {
  315. hgs_poc_type=POC_OWN;//默认是西安的,然后通过POC版本号来判断是西安的还是自研的POC
  316. }
  317. void ModemOwnPocSet(void)
  318. {
  319. if(hgs_poc_type != POC_OWN) return;
  320. ModemSendAt("AT+POC=3000000100\r\n");//GBK
  321. __nop();__nop();
  322. ModemSendAt("AT+POC=030000\r\n");//启动登陆,POC默认打开的
  323. __nop();__nop();
  324. }
  325. void getPocCode(char *msg){
  326. if(msg[14]=='0') sutPocStatus.codeType=0;
  327. else sutPocStatus.codeType=1;
  328. printf("PocCode:%d\r\n", sutPocStatus.codeType);
  329. }
  330. //total 成员总数
  331. //一次获取个数最多5个,取决于显示条目个数
  332. //前提是要使用简短模式
  333. char SimpleUserInfoScan(uint8_t firstIn,uint8_t direction)
  334. {
  335. static char first=1;
  336. static unsigned char machine;
  337. static unsigned int timer;
  338. char buf[40];//30
  339. char ret =0;
  340. if(firstIn && first){
  341. sutPocStatus.handleIndex=0;//当前页
  342. machine=0;
  343. first=0;
  344. ret=0;
  345. }
  346. switch(machine){
  347. case 0:
  348. //ShowMessageBox("请稍候...");
  349. if(sutUIstatus.Status==UIS_MENU_GROUP_SEL){
  350. if(hgs_poc_type==POC_BND) snprintf(buf, sizeof(buf),"AT+POC=groupnum\r\n");//先更新总数
  351. else snprintf(buf, sizeof(buf),"AT+POC=3D0000\r\n");//先更新总数
  352. }
  353. else {
  354. if(hgs_poc_type==POC_BND)snprintf(buf, sizeof(buf),"AT+POC=membernum,%d\r\n",sutPocStatus.LocalGroup.ID);//先更新总数
  355. else snprintf(buf, sizeof(buf),"AT+POC=3E0000\r\n");//先更新总数
  356. }
  357. ModemSendAt(buf);
  358. SlwTrace(INF,buf,0);
  359. sutPocStatus.ListUpdate=0;
  360. sutPocStatus.ListFillIndex=0;
  361. uTimerStart(&timer, 500);//500
  362. machine=1;
  363. break;
  364. case 1:
  365. if(sutPocStatus.ListUpdate || uTimerExpired(&timer) ){
  366. if(sutPocStatus.ListCurOnlineNum<=0){
  367. sutPocStatus.ListFillIndex=0;
  368. printf("sutPocStatus.ListUpdate==%d,ListCurOnlineNum==%d\r\n",sutPocStatus.ListUpdate,sutPocStatus.ListCurOnlineNum);
  369. goto QUIT_FUNCTION;
  370. }
  371. machine=2;
  372. }
  373. break;
  374. case 2:
  375. /*
  376. 第一次进来不操作页数
  377. 后续判定sutPocStatus.handleIndex 页是否合法
  378. 注意处理临界值 5的倍数
  379. */
  380. if(firstIn!=1){
  381. if(direction==1){
  382. sutPocStatus.handleIndex ++;
  383. if(sutPocStatus.handleIndex>sutPocStatus.ListCurOnlineNum/5){
  384. sutPocStatus.handleIndex=0;
  385. }
  386. if(sutPocStatus.ListCurOnlineNum%5==0){
  387. if(sutPocStatus.handleIndex==sutPocStatus.ListCurOnlineNum/5)sutPocStatus.handleIndex=0;
  388. }
  389. }
  390. else {
  391. if(sutPocStatus.handleIndex>0)sutPocStatus.handleIndex--;
  392. else if(sutPocStatus.handleIndex==0){
  393. if(sutPocStatus.ListCurOnlineNum%5==0)sutPocStatus.handleIndex=(sutPocStatus.ListCurOnlineNum/5)-1;
  394. else sutPocStatus.handleIndex=sutPocStatus.ListCurOnlineNum/5;
  395. printf("sutPocStatus.ListCurOnlineNum===%d,sutPocStatus.handleIndex==%d\r\n",sutPocStatus.ListCurOnlineNum,sutPocStatus.handleIndex);
  396. }
  397. }
  398. }
  399. /*
  400. 下面操作只决定 预读值sutPocStatus.ExceptionReadNum
  401. */
  402. if((sutPocStatus.handleIndex+1)*5 >sutPocStatus.ListCurOnlineNum){ //超过 首页 +1
  403. snprintf(buf, sizeof(buf), "over:%d",sutPocStatus.handleIndex);
  404. SlwTrace(INF, buf, 1);
  405. if(sutPocStatus.ListCurOnlineNum%5==0)sutPocStatus.ExceptionReadNum=5;
  406. else sutPocStatus.ExceptionReadNum=sutPocStatus.ListCurOnlineNum%5;
  407. } else{
  408. sutPocStatus.ExceptionReadNum=5; //普通情况 5个
  409. }
  410. sutPocStatus.ListFillIndex=0;
  411. machine=3;
  412. break;
  413. case 3:
  414. sutPocStatus.ListGetOneFlag=0; //起始 //个数//5个
  415. if(sutUIstatus.Status==UIS_MENU_GROUP_SEL){
  416. if(hgs_poc_type==POC_BND) snprintf(buf, sizeof(buf),"AT+POC=groups,%d+1,5\r\n",sutPocStatus.handleIndex*5);//先更新总数
  417. else snprintf(buf, sizeof(buf), "AT+POC=1D0000%04x0005\r\n",sutPocStatus.handleIndex*5);
  418. }
  419. else {
  420. if(hgs_poc_type==POC_BND) snprintf(buf, sizeof(buf),"AT+POC=members,%d,%d+1,5\r\n",sutPocStatus.LocalGroup.ID,sutPocStatus.handleIndex*5);
  421. else snprintf(buf, sizeof(buf), "AT+POC=1E0000%04x0005\r\n",sutPocStatus.handleIndex*5);
  422. }
  423. ModemSendAt(buf);
  424. SlwTrace(INF, buf,0);
  425. uTimerStart(&timer, 200);
  426. machine=4;
  427. break;
  428. case 4:
  429. if(sutPocStatus.ListGetOneFlag){//获取成功
  430. machine=5;
  431. }
  432. if(uTimerExpired(&timer)){
  433. machine=5;//超时了,结束
  434. }
  435. break;
  436. case 5:
  437. //最终成功读了多少个回来,存在sutPocStatus.FillUserIndex中
  438. QUIT_FUNCTION:
  439. first=1;
  440. GuiClearRect(0, 40, LCD_WIDTH-1, LCD_HEIGHT-32);
  441. machine=0;//
  442. return 1;
  443. break;
  444. }
  445. return ret;
  446. }