Modem.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. /**********************************************************************************
  2. * File Name: Modem.c
  3. * Function Describe:device for modem
  4. * Relate Module:
  5. * Explain: the modem must be using ZTE MC8332
  6. * Writer: ShiLiangWen
  7. * Date: 2015.1.20
  8. ***********************************************************************************/
  9. #define THIS_FILE_ID 2
  10. /* Includes ------------------------------------------------------------------*/
  11. #include "includes.h"
  12. //os_mbx_declare (PocMsgBox, 5); /* Declare an RTX mailbox */
  13. //_declare_box(PocMpool,sizeof(SUT_MODEM_POC_MSG),5);
  14. //SUT_SMS_PARA sutSMSpara;
  15. //os_mbx_declare (AtMsgBox, 7); /* Declare an RTX mailbox */
  16. //_declare_box(AtMpool,sizeof(SUT_MODEM_AT_MSG),7);
  17. SUT_MODEM_AT_MSG sutAtm,sutAtmPro;
  18. unsigned char g_ucModemSentTcpCt;//TCP 发送计数器
  19. unsigned char g_usModeMTime=0x00;
  20. unsigned char g_usModeSTime=0x00;
  21. unsigned char g_usModeHTime=0x00;
  22. unsigned char g_usModeYTime=0x00;//年
  23. unsigned char g_usModemTime=0x00;//月
  24. unsigned char g_usModeDTime=0x00;//日
  25. //MODEM_TYPE MODEM_TYPE;
  26. /************************************************************************************
  27. *
  28. *************************************************************************************/
  29. void ModemSendAT(char *p)
  30. {
  31. unsigned short len;
  32. len=strlen(p);
  33. RunMake(THIS_FILE_ID);
  34. #if UART2_TX_USE_DMA==0
  35. Uart2Send(p,len);
  36. #else
  37. USART2_Send(p,len);
  38. #endif
  39. }
  40. /************************************************************************************
  41. *
  42. *************************************************************************************/
  43. void ModemSendData(unsigned char *pData,unsigned short datalen)
  44. {
  45. #if UART2_TX_USE_DMA==0
  46. Uart2Send(pData,datalen);
  47. #else
  48. USART2_Send((char *)pData,datalen);
  49. #endif
  50. }
  51. /**********************************************************************************
  52. 等待模块启动完成
  53. 0:成功 -1:超时
  54. ***********************************************************************************/
  55. int WaitModemIsOpened(void)
  56. {
  57. int i;
  58. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  59. RunMake(THIS_FILE_ID);
  60. for(i=0;i<100;i++){
  61. SlwTrace(INF,"AT",1);
  62. ModemSendAT("AT\r\n");
  63. //if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&pMsg,50)){
  64. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData)))){
  65. if('O'==pMsg->MsgData[0] && 'K'==pMsg->MsgData[1]){
  66. return 0;
  67. }
  68. //free(pMsg);
  69. }else os_dly_wait(1);
  70. }
  71. return -1;
  72. }
  73. void ModemCtrlInit(void)
  74. {
  75. GPIO_InitTypeDef GPIO_InitStructure;
  76. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
  77. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  78. MODEM_DTR_HIGH;
  79. MODEM_RING_HIGH;
  80. MODEM_DSR_HIGH;
  81. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  82. GPIO_InitStructure.GPIO_Pin = MODEM_DTR_PIN;
  83. GPIO_Init(MODEM_DTR_PORT, &GPIO_InitStructure);
  84. MODEM_DTR_HIGH;
  85. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  86. GPIO_InitStructure.GPIO_Pin = MODEM_RING_PIN;
  87. GPIO_Init(MODEM_RING_PORT, &GPIO_InitStructure);
  88. MODEM_RING_HIGH;
  89. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  90. GPIO_InitStructure.GPIO_Pin = MODEM_DSR_PIN;
  91. GPIO_Init(MODEM_DSR_PORT, &GPIO_InitStructure);
  92. MODEM_DSR_HIGH;
  93. MODEM_DCD_HIGH;
  94. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  95. GPIO_InitStructure.GPIO_Pin = MODEM_DCD_PIN;
  96. GPIO_Init(MODEM_DCD_PORT, &GPIO_InitStructure);
  97. }
  98. /*************************************************************************
  99. *ModemWaitAtReady
  100. **************************************************************************/
  101. int ModemWaitAtReady(void)
  102. {
  103. int i;
  104. SUT_MODEM_AT_MSG *pMsg;
  105. for(i=0;i<20;i++){
  106. if(ModemSendAT2WaitAckMsg("AT\r\n","OK",&pMsg,100)){
  107. //_free_box(AtMpool,pMsg);
  108. return 1;
  109. }
  110. }
  111. return 0;
  112. }
  113. /*************************************************************************
  114. ModemWaitOpen
  115. 等待模块开机
  116. 通过检查模块主动上报:
  117. **************************************************************************/
  118. int ModemWaitOpen(int timeout)
  119. {
  120. //char *pAck;
  121. //SUT_MODEM_AT_MSG **pMsg;
  122. SUT_MODEM_AT_MSG *Msg;
  123. SlwTrace(DEBUG,"ModemWaitOpen",1);
  124. while(timeout--){
  125. //if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&Msg,1)){
  126. if((Msg->MsgLen = MsgQueueAccept(Msg->MsgData,sizeof(Msg->MsgData)))){
  127. SlwTrace(DEBUG,(char *)Msg->MsgData,0);
  128. // if(0==ModemStrCmp((char *)Msg->MsgData,pAck)){
  129. // *pMsg=Msg;
  130. // return 1;
  131. // }else{
  132. // _free_box(AtMpool,Msg);
  133. //}
  134. }else os_dly_wait(1);
  135. }
  136. return 1;
  137. }
  138. //模块的电源以及复位引脚的配置
  139. //这段配置要放要最开始
  140. //目的是一开机时确保模块是没有电源的
  141. //解决原来问题:当开机到模块播报“欢迎.....”时马上关机,看到屏幕灭后马上又开机,此次开机会失败
  142. void ModemPinConfig(void)
  143. {
  144. GPIO_InitTypeDef GPIO_InitStructure;
  145. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
  146. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  147. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  148. GPIO_InitStructure.GPIO_Pin = MODEM_RESET_PIN;
  149. GPIO_Init(MODEM_RESET_PORT, &GPIO_InitStructure);
  150. GPIO_InitStructure.GPIO_Pin = MODEM_PWRKEY_PIN;
  151. GPIO_Init(MODEM_PWRKEY_PORT, &GPIO_InitStructure);
  152. MODEM_RESET_HIGH;
  153. MODEM_PWRKEY_LOW;
  154. }
  155. /**********************************************************************************
  156. ModemInit
  157. 返回:1 初始化成功 0-失败
  158. ***********************************************************************************/
  159. int ModemInit(void)
  160. {
  161. RunMake(THIS_FILE_ID);
  162. MsgQueueSet();//初始化队列
  163. g_ucModemSentTcpCt=0;
  164. RunMake(THIS_FILE_ID);
  165. MODEM_RESET_HIGH;
  166. os_dly_wait(100);
  167. MODEM_RESET_LOW;
  168. MODEM_PWRKEY_HIGH;
  169. os_dly_wait(100);
  170. MODEM_PWRKEY_LOW;
  171. //等待模块开机并能接受AT命令
  172. if(WaitModemStart())return 0;
  173. return 1;
  174. //ModemGetIMEI();
  175. }
  176. char ModemLCCCheck(void)
  177. {
  178. int t,i;
  179. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  180. SlwTrace(INF, "check version type",1);
  181. for(i=0;i<100;i++)
  182. {
  183. t=50;
  184. ModemSendAT("AT+LSPOCPF?\r\n");
  185. while(t--)
  186. {
  187. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  188. {
  189. if((0==ModemStrCmp((char *)pMsg->MsgData,"ERROR"))){
  190. SlwTrace(INF, "It is not 3 in 1 version quit this check",1);
  191. return 0;
  192. }else if(0==ModemStrCmp((char *)pMsg->MsgData,"+LSPOCPF:")){//+LSPOCPF:hgs(1)
  193. //这个模块支持三合一指令,即为三合一模块版本
  194. if(pMsg->MsgData[13] == '1'){
  195. SlwTrace(INF, "It is hgs version now",1);
  196. return 0;
  197. }else{
  198. SlwTrace(INF, "Reset to hgs version and reboot",1);
  199. ModemSendAT("AT+LSPOCPF=hgs\r\n");
  200. ShowMessageBox("切换海高思版本");
  201. t=0;
  202. while(++t<50){
  203. DelayMs(2);
  204. IWDG_ReloadCounter();
  205. }
  206. return 1;
  207. }
  208. }
  209. }else
  210. os_dly_wait(1);
  211. }
  212. }
  213. SlwTrace(INF, "TimeOut",1);
  214. return 0;
  215. }
  216. /**********************************************************************************
  217. CSQ2Num
  218. ***********************************************************************************/
  219. int CSQ2Num(char *str)
  220. {
  221. int csq;
  222. csq=atoi(str);
  223. if(csq<0 || csq>99)return 99;
  224. else return csq;
  225. }
  226. /**********************************************************************************
  227. ModemStrCmp
  228. ***********************************************************************************/
  229. int ModemStrCmp(char *msg,char *str)
  230. {
  231. char *p1=str;
  232. char *p2=msg;
  233. while(*p1!=0){
  234. if(*p1!=*p2)return 1;
  235. p1++;
  236. p2++;
  237. }
  238. return 0;
  239. }
  240. /**********************************************************************************
  241. ModemWaitAckMsg
  242. Input:
  243. pATCmd--AT Command string
  244. pAck --期待回的ACK,头相同即可
  245. pMsg --实际消息内容,可能比pAck长
  246. timeout --超时,10ms为单位
  247. Output:
  248. if timeout return 0
  249. else return 1 注意,处理完消息要调用_free_box释放消息
  250. ***********************************************************************************/
  251. int ModemSendAT2WaitAckMsg(char *pATCmd,char *pAck,SUT_MODEM_AT_MSG **pMsg,int timeout)
  252. {
  253. SUT_MODEM_AT_MSG *Msg=&sutAtmPro;
  254. ModemSendAT(pATCmd);
  255. while(timeout){
  256. //if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&Msg,1)){
  257. if((Msg->MsgLen = MsgQueueAccept(Msg->MsgData,sizeof(Msg->MsgData)))){
  258. //SlwTrace(DEBUG,(char *)Msg->MsgData);
  259. if(0==ModemStrCmp((char *)Msg->MsgData,pAck)){
  260. *pMsg=Msg;
  261. return 1;
  262. }else{
  263. //_free_box(AtMpool,Msg);
  264. }
  265. }else {
  266. timeout--;
  267. os_dly_wait(1);
  268. }
  269. }
  270. return 0;
  271. }
  272. /********************************************
  273. *0x12 --> "12" --> 0x31 0x32
  274. **********************************************/
  275. void HexToAsc(unsigned char Hex,char *pAsc)
  276. {
  277. unsigned char h,l;
  278. l=Hex & 0x0f;
  279. h=Hex >> 4;
  280. if((l>=0)&&(l<=9))l += 0x30;
  281. else if((l>=10)&&(l<=15))l += ('A'-10);
  282. if((h>=0)&&(h<=9))h += 0x30;
  283. else if((h>=10)&&(h<=15))h += ('A'-10);
  284. pAsc[0]=h;
  285. pAsc[1]=l;
  286. }
  287. void HexToStr(unsigned char *HexStr,char *AscStr,unsigned short len)
  288. {
  289. int i,j=0;
  290. for(i=0;i<len;i++)
  291. {
  292. HexToAsc(HexStr[i],&AscStr[j]);
  293. j+=2;
  294. }
  295. }
  296. /***********************************************************************************
  297. *ModemSendUdpData WCDMA没有UDP指令
  298. ************************************************************************************/
  299. int ModemSendUdpData(unsigned char socket,unsigned char *pData,unsigned short len)
  300. {
  301. int i;
  302. char buf[142];
  303. char tmp[5];
  304. unsigned char temp=0;
  305. snprintf(buf, sizeof(buf),"AT+ZIPSENDU=%d,%d\r",socket,len);
  306. ModemSendAT(buf);
  307. ModemSendData(pData,len);
  308. snprintf(buf, sizeof(buf),"UdpSend[%d]",len);
  309. SlwTrace(INF,buf,1);
  310. #ifdef SLW_DEBUG
  311. if(len>45)len=45;
  312. buf[0]='>';buf[1]='>';buf[2]=0;
  313. for(i=0;i<len;i++){
  314. snprintf(tmp, sizeof(tmp),"%02x,",pData[i]);
  315. strcat(buf,tmp);
  316. }
  317. SlwTrace(DEBUG,buf,1);
  318. #endif
  319. return 0;
  320. }
  321. /***********************************************************************************
  322. *StrToNum
  323. ************************************************************************************/
  324. unsigned short StrToNum(char *str)
  325. {
  326. unsigned short num;
  327. if(str[0]>0x2f && str[0]<0x3a){
  328. if(str[1]>0x2f && str[1]<0x3a){
  329. if(str[2]>0x2f && str[2]<0x3a){
  330. if(str[3]>0x2f && str[3]<0x3a){
  331. num=1000*(str[0]-0x30);
  332. num+=100*(str[1]-0x30);
  333. num+=10*(str[2]-0x30);
  334. num+=(str[3]-0x30);
  335. }else{
  336. num=100*(str[0]-0x30);
  337. num+=10*(str[1]-0x30);
  338. num+=(str[2]-0x30);
  339. }
  340. }else{
  341. num=10*(str[0]-0x30);
  342. num+=(str[1]-0x30);
  343. }
  344. }else{
  345. num= str[0]-0x30;
  346. }
  347. }else{
  348. num=0;
  349. }
  350. return num;
  351. }
  352. /***********************************************************************************
  353. *ModemPoweroff
  354. ************************************************************************************/
  355. void ModemPoweroff(void)
  356. {
  357. ModemSendAT("AT+ZPWROFF\r\n");
  358. os_dly_wait(50);
  359. ModemSendAT("AT+ZPWROFF\r\n");
  360. IWDG_ReloadCounter();//喂狗
  361. os_dly_wait(100);
  362. IWDG_ReloadCounter();//喂狗
  363. os_dly_wait(100);
  364. IWDG_ReloadCounter();//喂狗
  365. os_dly_wait(50);
  366. IWDG_ReloadCounter();//喂狗
  367. MODEM_PWRKEY_LOW;
  368. MODEM_RESET_HIGH;
  369. os_dly_wait(10);
  370. MODEM_RESET_LOW;
  371. }
  372. /**********************************************************************************
  373. *ModemSetDTRLow
  374. ***********************************************************************************/
  375. void ModemSetDtrLow(void)
  376. {
  377. GPIO_InitTypeDef GPIO_InitStructure;
  378. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
  379. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  380. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  381. GPIO_InitStructure.GPIO_Pin = MODEM_DTR_PIN;
  382. GPIO_Init(MODEM_DTR_PORT, &GPIO_InitStructure);
  383. MODEM_DTR_LOW;
  384. }
  385. /**********************************************************************************
  386. *ModemSetRINGLow
  387. ***********************************************************************************/
  388. void ModemSetRingLow(void)
  389. {
  390. GPIO_InitTypeDef GPIO_InitStructure;
  391. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
  392. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  393. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  394. GPIO_InitStructure.GPIO_Pin = MODEM_RING_PIN;
  395. GPIO_Init(MODEM_RING_PORT, &GPIO_InitStructure);
  396. MODEM_RING_LOW;
  397. }
  398. unsigned char AsciiHexStringToHexBytes(char *src, unsigned char *des)
  399. {//"3031"-->0x30,0x31
  400. unsigned char temp[2];
  401. unsigned char i,k;
  402. int len;
  403. len=strlen(src);
  404. if(len % 2) return 0;//不能为单数
  405. for(i=0;i<len/2;i++){
  406. temp[0]=src[2*i];
  407. temp[1]=src[2*i+1];
  408. for(k=0;k<2;k++){
  409. if(temp[k] >= '0' && temp[k] <= '9') temp[k] -= 0x30;
  410. else if(temp[k] >= 'a' && temp[k] <= 'f') temp[k] -= 0x57;
  411. else if(temp[k] >= 'A' && temp[k] <= 'F') temp[k] -= 0x37;
  412. }
  413. des[i] = ((temp[0]<<4)&0xf0) | temp[1];
  414. }
  415. return i;
  416. }
  417. /*******************************************************************
  418. *ModemCheckPocParam
  419. return:
  420. 1--not same, Reset
  421. 0--same,no reset
  422. ********************************************************************/
  423. int ModemCheckPocParam(void)
  424. {
  425. int t,j;
  426. int i,len;
  427. char buf[40];
  428. char buf1[100];
  429. char idFlag=0;
  430. char ipFlag=0;
  431. char pwdFlag=0;
  432. char domainFlag=0;
  433. char enableChangeIp=1;
  434. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  435. // #error "也测试一下这个函数正常与否呗"
  436. for(i=0;i<5;i++)
  437. {
  438. ModemSendAT("AT+POC=020000\r\n");
  439. //+POC:0200000069643D313030303031343031343B69703D3138332E3133312E31332E31303B7077643D3135303034343739303438383931343B646F6D61696E3D7777772E6869676F73706F632E636F6D3B
  440. //id=1000014014;ip=183.131.13.10;pwd=150044790488914;domain=www.higospoc.com;
  441. t=50;
  442. while(t--)
  443. {
  444. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  445. {
  446. if(0==ModemStrCmp((char *)pMsg->MsgData,"+POC:02"))
  447. {
  448. pMsg->MsgData[pMsg->MsgLen-3]=0;
  449. len=AsciiHexStringToHexBytes(&pMsg->MsgData[13], pMsg->MsgData);
  450. pMsg->MsgData[len]=0;
  451. //找id
  452. len=GetParaFromStr(pMsg->MsgData,"id",buf);
  453. snprintf(buf1, sizeof(buf1),"%lu",sutProductPara.PSN);
  454. if(0!=strcmp(buf1, buf)) idFlag=1;;
  455. //找pwd
  456. len=GetParaFromStr(pMsg->MsgData,"pwd",buf);
  457. snprintf(buf1, sizeof(buf1), "%s",DEV_HARDID);
  458. if(0!=strcmp(buf1, buf)) pwdFlag=1;
  459. //找domain
  460. switch(newPara.serList.defaultuse)
  461. {
  462. case SER_HZ:
  463. case SER_SD:
  464. case SER_US:
  465. break;
  466. case SER_IP:
  467. case SER_JIQUN:
  468. if(newPara.serList.defaultuse==SER_IP)snprintf(buf1, sizeof(buf1), "%s",newPara.serList.ipFenFa);
  469. else if(newPara.serList.defaultuse==SER_JIQUN)snprintf(buf1, sizeof(buf1), "%s",newPara.serList.jiqun);
  470. len=GetParaFromStr(pMsg->MsgData,"domain",buf); //domain
  471. if(0!=strcmp(buf1, buf)) domainFlag=1;
  472. //modify by wjl 0609
  473. //但使用集群或者IP分发的时候,保证不去更新ip即可
  474. enableChangeIp=0;
  475. break;
  476. }
  477. //找ip
  478. if(enableChangeIp!=0){//modify by wjl 0609
  479. len=GetParaFromStr(pMsg->MsgData,"ip",buf);
  480. snprintf(buf1, sizeof(buf1), "%s", getPIPAddr());
  481. if(0!=strcmp(buf1, buf)) ipFlag=1;
  482. }
  483. if(idFlag == 0 && ipFlag==0 && pwdFlag==0&&domainFlag==0) return 0;
  484. RESET_ALL:
  485. ModemSendAT("AT+POC=010000");
  486. //更新id
  487. //if(idFlag != 0){
  488. snprintf(buf, sizeof(buf),"id=%lu;",sutProductPara.PSN);
  489. AscStrToHexStr(buf,buf1);
  490. ModemSendAT(buf1);
  491. //}
  492. //更新ip
  493. if(enableChangeIp!=0){//modify by wjl 0609
  494. //if(ipFlag != 0){
  495. snprintf(buf, sizeof(buf), "ip=%s;", getPIPAddr());
  496. AscStrToHexStr(buf,buf1);
  497. ModemSendAT(buf1);
  498. //}
  499. }
  500. //更新pwd
  501. //if(pwdFlag != 0){
  502. snprintf(buf, sizeof(buf), "pwd=%s;",DEV_HARDID);
  503. AscStrToHexStr(buf,buf1);
  504. ModemSendAT(buf1);
  505. //}
  506. if(newPara.serList.defaultuse==SER_IP)snprintf(buf, sizeof(buf), "domain=%s;",newPara.serList.ipFenFa);
  507. else if(newPara.serList.defaultuse==SER_JIQUN)snprintf(buf, sizeof(buf), "domain=%s;",newPara.serList.jiqun);
  508. else{
  509. snprintf(buf, sizeof(buf), "domain=;");
  510. AscStrToHexStr(buf,buf1);
  511. // ModemSendAT(buf1);
  512. // //ModemSendAT("\r\n");
  513. // return 1;
  514. }
  515. AscStrToHexStr(buf,buf1);
  516. ModemSendAT(buf1);
  517. //}
  518. ModemSendAT("\r\n");
  519. return 1;
  520. }
  521. }else os_dly_wait(1);
  522. }
  523. }
  524. return 0;
  525. }
  526. char WaitModemStart(void)
  527. {
  528. int t,i;
  529. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  530. SlwTrace(INF, "WaitModemRun:",0);
  531. for(i=0;i<100;i++)
  532. {
  533. t=50;
  534. ModemSendAT("ATE0\r\n");
  535. while(t--)
  536. {
  537. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  538. {
  539. if(0==ModemStrCmp((char *)pMsg->MsgData,"OK") ||
  540. 0==ModemStrCmp((char *)pMsg->MsgData,"+POC:START"))
  541. {
  542. SlwTrace(INF, "Runing",1);
  543. return 0;
  544. }
  545. }else
  546. os_dly_wait(1);
  547. }
  548. }
  549. SlwTrace(INF, "TimeOut",1);
  550. return 1;
  551. }
  552. void ModemInfo(void)
  553. {
  554. int t;
  555. int i,len,ver,j;
  556. char bufTemp[30],version[10],type,countFlag;
  557. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  558. RunMake(THIS_FILE_ID);
  559. ver=0;
  560. SlwTrace(INF, "[03]ModemInfo:",1);
  561. type=1;
  562. for(i=0;i<10;i++)
  563. {
  564. if(type==0) ModemSendAT("ATI\r\n");//模块型号
  565. else ModemSendAT("AT+LCTSW\r\n");//版本信息
  566. t=50;
  567. while(t--)
  568. {
  569. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  570. {
  571. if(type==0)
  572. {//Manufacturer: LONGSUNG
  573. //Model: U9507C 全网通模块版本
  574. //Model: U9507C_SXNT 单电信模块版本
  575. //Model: U9507C_SXNM 移动联通模块版本
  576. //Model: U9507C V3 全网通版本
  577. if(0==ModemStrCmp((char *)pMsg->MsgData,"Manufacturer:")) SlwTrace(INF, pMsg->MsgData, 0);
  578. else if(0==ModemStrCmp((char *)pMsg->MsgData,"Model:"))
  579. {
  580. if(0==ModemStrCmp((char *)pMsg->MsgData,"Model: U9507C V3")|| 0==ModemStrCmp((char *)pMsg->MsgData,"Model: U9507C SXNT")){
  581. //单电信
  582. support_type=ONLY_Telecom;
  583. }else if(0==ModemStrCmp((char *)pMsg->MsgData,"Model: U9507C_SXNM")|| 0==ModemStrCmp((char *)pMsg->MsgData,"Model: U9507C SXNM")){
  584. //移动联通版
  585. support_type=Mobile_unicom;
  586. }else if(0==ModemStrCmp((char *)pMsg->MsgData,"Model: U9507C POCC") ){
  587. support_type=All_Netcom;
  588. //全网通
  589. }else {
  590. //未知
  591. support_type=Un_Known;
  592. }
  593. SlwTrace(INF, pMsg->MsgData, 0);
  594. type ++;
  595. break;
  596. }
  597. }else{
  598. //SoftwareVersion: LLA0029.1.2_M005
  599. //InnerVersion: LLA0029_0016_1.0.57_L0901_EFS2.6
  600. //AP: LLA0029_0016_0.0.57_L0901_M005
  601. if(0==ModemStrCmp((char *)pMsg->MsgData,"SoftwareVersion:")) SlwTrace(INF, pMsg->MsgData, 0);
  602. else if(0==ModemStrCmp((char *)pMsg->MsgData,"AP:"))
  603. {
  604. SlwTrace(INF, pMsg->MsgData, 0);
  605. return;
  606. }
  607. else if(0==ModemStrCmp((char *)pMsg->MsgData,"InnerVersion:"))
  608. {
  609. SlwTrace(INF, pMsg->MsgData, 0);
  610. countFlag=0;
  611. for(j=0;j<strlen(pMsg->MsgData);j++)
  612. {
  613. if(pMsg->MsgData[j] == '_')
  614. {
  615. countFlag++;
  616. if(countFlag == 1)
  617. {
  618. version[0] = pMsg->MsgData[j+3];
  619. version[1] = pMsg->MsgData[j+4];
  620. }else if(countFlag == 3)
  621. {
  622. version[2] = pMsg->MsgData[j+2];
  623. version[3] = pMsg->MsgData[j+3];
  624. version[4] = pMsg->MsgData[j+4];
  625. version[5] = pMsg->MsgData[j+5];
  626. version[6] = 0;
  627. snprintf(bufTemp, sizeof(bufTemp), "[03]ModemVer:%s",version);
  628. SlwTrace(INF, bufTemp, 1);
  629. g_iModemVer=atoi(version);
  630. }
  631. }
  632. }
  633. }
  634. }
  635. }else os_dly_wait(1);
  636. }
  637. }
  638. }
  639. int ModemGetIMEI(void)
  640. {
  641. int t,j;
  642. int i,len;
  643. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  644. for(i=0;i<50;i++){
  645. ModemSendAT("AT+GSN\r\n");//0x80DA219D
  646. //862015030301209 两种情况都会返回
  647. t=50;
  648. while(t--)
  649. {
  650. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  651. {
  652. len=strlen((char *)&(pMsg->MsgData));
  653. if(0==ModemStrCmp((char *)pMsg->MsgData,"0x"))
  654. {
  655. len -=4;
  656. memcpy(DEV_HARDID, &pMsg->MsgData[2], len);
  657. if(len < sizeof(DEV_HARDID))
  658. DEV_HARDID[len]=0;
  659. return 1;
  660. }else if(len == 17)
  661. {
  662. len -= 2;
  663. memcpy(DEV_HARDID, pMsg->MsgData, len);
  664. if(len < sizeof(DEV_HARDID))
  665. DEV_HARDID[len]=0;
  666. return 2;
  667. }
  668. }else
  669. os_dly_wait(1);
  670. }
  671. }
  672. return 0;
  673. }
  674. void CheckPocType(void)
  675. {
  676. //19001 19002 19003 自研POC版本号
  677. //1184 1191 西安POC版本号
  678. hgs_poc_type=POC_XIAN;//默认是西安的,然后通过POC版本号来判断是西安的还是自研的POC
  679. if(g_iPocVer > 19000){
  680. hgs_poc_type=POC_OWN;
  681. SlwTrace(INF, "poc-own",1);
  682. }else SlwTrace(INF, "poc-xian",1);
  683. }
  684. void ModemPocVersionCheck(void)
  685. {
  686. char bufTemp[40];
  687. short t,i,len,j;
  688. int ver;
  689. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  690. for(i=0;i<5;i++)
  691. {
  692. t=50;
  693. ModemSendAT("AT+POC_VER?\r\n");
  694. while(t--)
  695. {
  696. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  697. {
  698. if(0==ModemStrCmp((char *)pMsg->MsgData,"+POC_VER:"))
  699. {
  700. len = strlen(pMsg->MsgData);
  701. j=0;
  702. for(i=0;i<len;i++)
  703. {
  704. if(pMsg->MsgData[i] == '\r')
  705. {
  706. bufTemp[j]=0;
  707. ver=atoi(bufTemp);
  708. snprintf(bufTemp, sizeof(bufTemp),"[04]POCver:%d<->%s", ver,pMsg->MsgData);
  709. SlwTrace(INF, bufTemp,0);
  710. g_iPocVer=ver;
  711. return;
  712. }else if(pMsg->MsgData[i] >= '0' && pMsg->MsgData[i] <= '9') bufTemp[j++]=pMsg->MsgData[i];
  713. }
  714. }
  715. }else
  716. os_dly_wait(1);
  717. }
  718. }
  719. snprintf(bufTemp, sizeof(bufTemp),"[04]PocVer=%d", ver);
  720. SlwTrace(INF, bufTemp, 1);
  721. }
  722. void ModemApnConfig(void)
  723. {
  724. char needAuthLogin=0;
  725. char buf[100];
  726. char buf2[80];
  727. char i,t;
  728. char ApnSetFlag=0;
  729. char *apnName=newPara.apnList.apnList[newPara.apnList.defaultuse].account;
  730. char *apnPass=newPara.apnList.apnList[newPara.apnList.defaultuse].pass;
  731. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  732. snprintf(buf, sizeof(buf), "[11]Accessp:");
  733. if(newPara.apnList.APN_Name[0]==0)
  734. {//接入点为空时不配置,因为模块不支持
  735. strcat(buf, "unsupport-Empty");
  736. }else
  737. {
  738. snprintf(buf2, sizeof(buf2), "AT+MIPPROFILE=1,\"%s\"\r\n",newPara.apnList.APN_Name);
  739. ModemSendAT(buf2);
  740. snprintf(buf2, sizeof(buf2), "%s",newPara.apnList.APN_Name);
  741. strcat(buf,buf2);
  742. }
  743. SlwTrace(INF,buf,0);
  744. snprintf(buf, sizeof(buf), ",Name-Pass:");
  745. if(apnName[0] ==0 ||
  746. apnPass[0] ==0)
  747. {//名称或密码为空不配置,因为模块不支持
  748. strcat(buf, "unsupport-Empty");
  749. }else
  750. {
  751. snprintf(buf2, sizeof(buf2),"AT^PPPCFG=\"%s\",\"%s\"\r\n",apnName,apnPass);
  752. ModemSendAT(buf2);
  753. snprintf(buf2, sizeof(buf2), "%s,%s",apnName,apnPass);
  754. strcat(buf,buf2);
  755. needAuthLogin=1;
  756. }
  757. SlwTrace(INF, buf,1);
  758. if(needAuthLogin != 0){
  759. //认证
  760. snprintf(buf, sizeof(buf),"AUTH-LOGIN:");
  761. switch(newPara.authType){
  762. case AUTH_LOGIN_PAP:strcat(buf, "PAP");
  763. snprintf(buf2, sizeof(buf2),"AT$QCPDPP=1,%d,%s,%s\r\n",newPara.authType,apnPass,apnName);
  764. break;
  765. case AUTH_LOGIN_CHAP:strcat(buf, "CHAP");
  766. case AUTH_LOGIN_NONE:strcat(buf, "NONE");
  767. default:strcat(buf, " Do nothing");
  768. snprintf(buf2, sizeof(buf2),"AT$QCPDPP=1,%d\r\n",newPara.authType);
  769. break;
  770. }
  771. SlwTrace(INF,buf, 1);
  772. ModemSendAT(buf2);
  773. SlwTrace(INF,buf2,0);
  774. os_dly_wait(20);
  775. SlwTrace(INF,"AuthLogin Done",1);
  776. }
  777. }
  778. void M9507CSendTcpData(unsigned char socket, unsigned char *pData, unsigned short len)
  779. {
  780. char buf[20];
  781. snprintf(buf, sizeof(buf), "AT+TCPSEND=%d,%d,",socket, len);
  782. ModemSendAT(buf);
  783. ModemSendData(pData, len);
  784. ModemSendAT("\r\n");
  785. }
  786. void ModemSetSpeed(void)
  787. {
  788. char i,t;
  789. int Volume;
  790. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  791. for(i=0;i<5;i++)
  792. {
  793. t=50;
  794. REGO:
  795. ModemSendAT("AT+LSHTTSSPEED?\r\n");
  796. while(t--)
  797. {
  798. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  799. {
  800. if(0==ModemStrCmp((char *)pMsg->MsgData,"+LSHTTSSPEED:"))
  801. {
  802. Volume=atoi(&pMsg->MsgData[13]);
  803. if(7000 != Volume)
  804. {
  805. ModemSendAT("AT+LSHTTSSPEED=-1,7000\r\n");
  806. os_dly_wait(1);
  807. goto REGO;
  808. }
  809. else
  810. {
  811. SlwTrace(INF, "[06]SetTTS Speed Ok",1);
  812. return;
  813. }
  814. }
  815. }else
  816. os_dly_wait(1);
  817. }
  818. }
  819. SlwTrace(INF, "[06]SetTTS Speed Failed",1);
  820. }
  821. void VolumeSet(void)
  822. {
  823. char i,t;
  824. int Volume;
  825. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  826. char sendBuf[40],readBuf[30];
  827. char target[5];
  828. snprintf(sendBuf, sizeof(sendBuf), "at+syscmd=start_pcm volume ");
  829. snprintf(readBuf, sizeof(readBuf), "at+syscmd=start_pcm volume\r\n");
  830. // if(newPara.SoundMode==0) snprintf(target, sizeof(target), "7 5");
  831. // else snprintf(target, sizeof(target), "7 7");
  832. snprintf(target, sizeof(target), "7 5");
  833. strcat(sendBuf, target);
  834. strcat(sendBuf, "\r\n");
  835. //先配置一次,再查,因为默认就查有可能是没有返回的
  836. ModemSendAT(sendBuf);//TTS 音量/ MIC 输入音量
  837. os_dly_wait(50);
  838. for(i=0;i<10;i++)
  839. {
  840. t=100;
  841. ModemSendAT(readBuf);
  842. while(t--)
  843. {
  844. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  845. {
  846. if(0==ModemStrCmp((char *)pMsg->MsgData,target))
  847. {
  848. SlwTrace(INF, "[07]Set Volume ok",1);
  849. return;
  850. }
  851. }else
  852. os_dly_wait(1);
  853. }
  854. }
  855. SlwTrace(INF, "[07]Set Volume failed",1);
  856. }
  857. void SpeakTTSVoice(void)
  858. {
  859. int len,timeout;
  860. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  861. unsigned char codeType=ENCODE_UNICODE;
  862. if(newPara.ttsMessage[0]==0) return;
  863. len=strlen(newPara.ttsMessage);
  864. len = len+(8-len%8);//8倍数
  865. timeout=len/8;//两个中文需要播报1秒算
  866. timeout *= 100;
  867. if(newPara.ttsCodeType==TTS_UNICODE) codeType=ENCODE_UNICODE;
  868. else if(newPara.ttsCodeType==TTS_GBK) codeType=ENCODE_GBK;
  869. MeSpeak(codeType, newPara.ttsMessage,0);
  870. // while(timeout--)
  871. // {
  872. // if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  873. // {
  874. // if(0==ModemStrCmp((char *)pMsg->MsgData,"+LSHTTS: END"))
  875. // {
  876. // SpeakerCtrl(0);
  877. // return;
  878. // }
  879. // }else os_dly_wait(1);
  880. // }
  881. // SpeakerCtrl(0);
  882. }
  883. void ServerTimeGet(void)
  884. {
  885. static unsigned short timeCnt=12000;
  886. if(++timeCnt < 12000) return;
  887. timeCnt=0;
  888. ModemSendAT("AT+CCLK?\r\n");
  889. }
  890. //total 成员总数
  891. //一次获取个数最多5个,取决于显示条目个数
  892. //前提是要使用简短模式
  893. void SimpleUserInfoScan(uint8_t firstIn,uint8_t direction)
  894. {
  895. uint16_t i;
  896. uint16_t timeout;
  897. char buf[30];
  898. uint16_t thisStartIndex;
  899. uint8_t readNum;
  900. static char flag;
  901. char trycnt=0;
  902. if(firstIn) sutPocStatus.handleIndex=0;
  903. ShowMessageBox("请稍候...");
  904. os_dly_wait(1);
  905. snprintf(buf, sizeof(buf),"AT+POC=0E0000%08x\r\n",sutPocStatus.LocalGroup.ID);//先更新总数
  906. ModemSendAT(buf);
  907. SlwTrace(INF,buf,0);
  908. timeout=1000;
  909. sutPocStatus.UserNum_Update=0;
  910. sutPocStatus.UserOnLineNum=0;
  911. while(timeout)
  912. {
  913. timeout--;
  914. OsDelayTime(1);
  915. if(sutPocStatus.UserNum_Update) break;
  916. if(timeout % 200 == 0)
  917. ModemSendAT(buf);
  918. }
  919. if(sutPocStatus.UserOnLineNum<=0) {
  920. sutPocStatus.FillUserIndex=0;
  921. goto QUIT_FUNCTION;
  922. }
  923. // if(sutPocStatus.handleIndex >= sutPocStatus.UserOnLineNum)
  924. // {
  925. // snprintf(buf, sizeof(buf), "over:%d",sutPocStatus.handleIndex);
  926. // SlwTrace(INF, buf, 1);
  927. // sutPocStatus.handleIndex=sutPocStatus.UserOnLineNum-1;
  928. // }
  929. if(sutPocStatus.UserOnLineNum%5==0)flag=5;
  930. else flag=sutPocStatus.UserOnLineNum%5;
  931. //然后根据最新总数来获取每个成员信息
  932. if(direction==1)//递增索引
  933. {
  934. thisStartIndex=sutPocStatus.handleIndex;
  935. if(sutPocStatus.UserOnLineNum-thisStartIndex>=5) readNum=5;
  936. else {
  937. readNum=sutPocStatus.UserOnLineNum-thisStartIndex;
  938. }
  939. }else{//递减索引
  940. thisStartIndex=sutPocStatus.handleIndex;
  941. if(sutPocStatus.handleIndex <5) //<
  942. {
  943. thisStartIndex=0;//0
  944. readNum=sutPocStatus.UserOnLineNum; //(sutPocStatus.UserOnLineNum%5)
  945. }
  946. else if(sutPocStatus.UserOnLineNum-thisStartIndex<=flag){
  947. if((sutPocStatus.UserOnLineNum%5)==0)readNum=5;
  948. else readNum=(sutPocStatus.UserOnLineNum%5); //Z
  949. //thisStartIndex=sutPocStatus.UserOnLineNum-readNum;
  950. }
  951. else
  952. {
  953. //thisStartIndex=sutPocStatus.handleIndex-5;
  954. readNum=5;
  955. }
  956. }
  957. if(readNum >= 5) readNum=5;
  958. sutPocStatus.FillUserIndex=0;
  959. for(i=thisStartIndex;i<(thisStartIndex+readNum);i++)
  960. {
  961. sutPocStatus.GetOneUserFlag=0;
  962. snprintf(buf, sizeof(buf), "AT+POC=10000021%04x\r\n",i);
  963. ModemSendAT(buf);
  964. SlwTrace(INF, buf,0);
  965. timeout=200;
  966. while(1)
  967. {
  968. OsDelayTime(1);
  969. if(sutPocStatus.GetOneUserFlag)
  970. {
  971. sutPocStatus.FillUserIndex++;
  972. break;
  973. }
  974. if(--timeout==0) break;
  975. }
  976. }
  977. if(firstIn)sutPocStatus.handleIndex=0;
  978. //最终成功读了多少个回来,存在sutPocStatus.FillUserIndex中
  979. QUIT_FUNCTION:
  980. GuiClearRect(0, 40, LCD_WIDTH-1, LCD_HEIGHT-32);
  981. }
  982. void SetModemPocSimpleMode(void)
  983. {//设置使用简短模式获取成员信息
  984. short t,i;
  985. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  986. for(i=0;i<5;i++)
  987. {
  988. t=50;
  989. ModemSendAT("AT+POC=10000020\r\n");
  990. while(t--)
  991. {
  992. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  993. {
  994. if(0==ModemStrCmp((char *)pMsg->MsgData,"+POC:10000000"))
  995. {
  996. SlwTrace(INF, "[14]SimpleMode_Ok",1);
  997. return;
  998. }
  999. }else
  1000. os_dly_wait(1);
  1001. }
  1002. }
  1003. SlwTrace(INF, "[14]SimpleMode_Tout",1);
  1004. }
  1005. char GetUniStringByID(char *HardIDString)
  1006. {//输出15个字节的字符串
  1007. unsigned char id[12];
  1008. unsigned char string[16];
  1009. long long temp;
  1010. short i;
  1011. unsigned char seed;
  1012. if(HardIDString == '\0') return 0;
  1013. GetSTM32ID(id);
  1014. printf("STM32 ID==");
  1015. for(i=0;i<12;i++)printf("%02x",id[i]);
  1016. printf("\r\n");
  1017. for(i=5;i>=0;i--){
  1018. temp <<=8;
  1019. temp |= id[i];
  1020. }
  1021. temp &= 0xffffffffffff;
  1022. printf("temp=%015llu\r\n",temp);
  1023. snprintf(string,sizeof(string),"%015llu",temp);
  1024. for(i=0;i<15;i++) HardIDString[i]=string[i];
  1025. HardIDString[15]='\0';
  1026. //snprintf(HardIDString,16,"%015llu",temp);
  1027. return 1;
  1028. }
  1029. //检查并设置POC域名
  1030. int ModemCheckFotaDomain(void)
  1031. {
  1032. #if 1
  1033. return 0;
  1034. #else
  1035. int t,j;
  1036. int i,len;
  1037. char buf1[130];
  1038. char buf2[40];
  1039. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  1040. RunMake(THIS_FILE_ID);
  1041. for(i=0;i<5;i++)
  1042. {
  1043. ModemSendAT("AT+POC=21000000\r\n");
  1044. t=50;
  1045. while(t--)
  1046. {
  1047. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  1048. {
  1049. if(0==ModemStrCmp((char *)pMsg->MsgData,"+POC:21000000"))
  1050. {
  1051. snprintf(buf2,sizeof(buf2),"%s",sutProductPara.fota_pocdomain);
  1052. //strcat(buf,buf2);
  1053. for(j=0;j<strlen(pMsg->MsgData);j++) if(pMsg->MsgData[j]== '\r') pMsg->MsgData[j] = 0;
  1054. if(0!=strcasecmp((char *)&pMsg->MsgData[13],buf2))
  1055. {
  1056. snprintf(buf1,sizeof(buf1),"AT+POC=21000001%s",buf1);
  1057. return 1;
  1058. }else return 0;
  1059. }
  1060. }else os_dly_wait(1);
  1061. }
  1062. }
  1063. return 0;
  1064. #endif
  1065. }
  1066. int htoi(char s[])
  1067. {
  1068. int i = 0;
  1069. int n = 0;
  1070. if (s[0] == '0' && (s[1]=='x' || s[1]=='X'))
  1071. {
  1072. i = 2;
  1073. }
  1074. else
  1075. {
  1076. i = 0;
  1077. }
  1078. for (; (s[i] >= '0' && s[i] <= '9') || (s[i] >= 'a' && s[i] <= 'z') || (s[i] >='A' && s[i] <= 'Z');++i)
  1079. {
  1080. if (tolower(s[i]) > '9')
  1081. {
  1082. n = 16 * n + (10 + tolower(s[i]) - 'a');
  1083. }
  1084. else
  1085. {
  1086. n = 16 * n + (tolower(s[i]) - '0');
  1087. }
  1088. }
  1089. return n;
  1090. }
  1091. int ModemSetCodec(unsigned char addr,unsigned short value)
  1092. {
  1093. int t,j;
  1094. int i,len;
  1095. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  1096. char buf[50];
  1097. for(i=0;i<10;i++){
  1098. t=50;
  1099. sprintf(buf,"AT+CODEC=3,%2x,%4x\r\n",addr,value);
  1100. ModemSendAT(buf);
  1101. while(t--)
  1102. {
  1103. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  1104. {
  1105. len=strlen((char *)&(pMsg->MsgData));
  1106. if(0==ModemStrCmp((char *)pMsg->MsgData,"OK"))
  1107. {
  1108. //SlwTrace(INF,(char *)pMsg->MsgData,1);
  1109. return 0;
  1110. }
  1111. }else os_dly_wait(1);
  1112. }
  1113. }
  1114. return addr;
  1115. }
  1116. void VolumeSetSpk(void)
  1117. {
  1118. char i,t;
  1119. int Volume;
  1120. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  1121. char sendBuf[40],readBuf[30];
  1122. char target[5];
  1123. snprintf(sendBuf,sizeof(sendBuf),"AT+LVL=4,%d\r\n",newPara.Spklv);
  1124. snprintf(readBuf,sizeof(readBuf),"+LVL:4,%d\r\n",newPara.Spklv);
  1125. SlwTrace(INF,sendBuf,0);
  1126. for(i=0;i<15;i++)
  1127. {
  1128. t=100; //100
  1129. ModemSendAT(sendBuf);//TTS 音量/ MIC 输入音量
  1130. os_dly_wait(100);
  1131. ModemSendAT("AT+LVL?\r\n");
  1132. while(t--)
  1133. {
  1134. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  1135. {
  1136. if(0==ModemStrCmp((char *)pMsg->MsgData,readBuf))
  1137. {
  1138. SlwTrace(INF, "[07-02]Set SPK ok",1);
  1139. return;
  1140. }
  1141. }else
  1142. os_dly_wait(1);
  1143. }
  1144. }
  1145. SlwTrace(INF, "[07-02]Set Volume failed",1);
  1146. }
  1147. void VolumeSetMIC(void)
  1148. {
  1149. char i,t;
  1150. char buf[40];
  1151. char readbuf[20];
  1152. int Volume;
  1153. SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
  1154. snprintf(buf,sizeof(buf),"AT+MIC=2,%d\r\n",newPara.Miclv);
  1155. snprintf(readbuf,sizeof(readbuf),"+MIC:2,%d\r\n",newPara.Miclv);
  1156. ModemSendAT(buf);//TTS 音量/ MIC 输入音量
  1157. SlwTrace(INF,buf,0);
  1158. SlwTrace(INF,readbuf,0);
  1159. for(i=0;i<15;i++)
  1160. {
  1161. t=100; //100
  1162. os_dly_wait(10);
  1163. ModemSendAT("AT+MIC?\r\n");
  1164. while(t--)
  1165. {
  1166. if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
  1167. {
  1168. if(0==ModemStrCmp((char *)pMsg->MsgData,readbuf))
  1169. {
  1170. SlwTrace(INF, "[07-03]Set MIC ok",1);
  1171. return;
  1172. }else{
  1173. if(t==0) ModemSendAT(buf);
  1174. }
  1175. }else
  1176. os_dly_wait(1);
  1177. }
  1178. }
  1179. SlwTrace(INF, "[07-03]Set MIC failed",1);
  1180. }
  1181. /***********************************************************************************/