Modem.c 13 KB

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