app.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. #include "includes.h"
  2. #include "lsapi_tts.h"
  3. #include "osi_api.h"
  4. //#define ANT_TEST
  5. #define APP_IDLE_TIME 3 //如果POC已休眿APP没有操作一定秒数后休眠
  6. int keyNum=0;
  7. APP_DEF sutApp;
  8. static void appDataInit(void){
  9. memset((unsigned char *)&sutApp, 0, sizeof(APP_DEF));
  10. sutApp.pcant=4;
  11. sutApp.enableKey=1;
  12. //appSleepCtl(ASLEEP_POC, 1);
  13. appSleepCtl(ASLEEP_LCD, 1);
  14. readInfoNow();
  15. sysIniRead();
  16. }
  17. void dataInit(void){
  18. appDataInit();
  19. pocDataInit();
  20. gpsDataInit();
  21. uiDataInit();
  22. }
  23. static void ledsProCtl(void){
  24. if(sutApp.gtMode!=0) return;
  25. if(0==sutPocStatus.logined) uioStatusSet(UIO_INDOFFLINE);
  26. else if(sutPocStatus.spk>0)uioStatusSet(UIO_INDRX);
  27. else if(sutPocStatus.mic>0 )uioStatusSet(UIO_INDTX);
  28. else uioStatusSet(UIO_INDONLINE);
  29. }
  30. static void KeyToneDly();
  31. static void adcRead(unsigned int interval);
  32. char isKeyPress(void){
  33. if(keyNum) return keyNum--;
  34. else return 0;
  35. }
  36. /*APP休眠处理接口
  37. ctlType, 操作对象
  38. status,操作值,0 清除 else 设置
  39. */
  40. void appSleepCtl(ASLEEP_ENUM ctlType, char status){
  41. if(status==0) sutApp.appSleepStatus &= ~(1<<ctlType);
  42. else sutApp.appSleepStatus |= 1<<ctlType;
  43. }
  44. /*APP休眠状态接叿*/
  45. char isAppSleepReady(void){
  46. if(sutApp.appSleepStatus==0) return 1;
  47. else return 0;
  48. }
  49. /*获取指定休眠控制成员锁定的状怿
  50. 0 未锁宿否则锁定,锁定即可以休眠
  51. */
  52. char getAppObjStatus(ASLEEP_ENUM ctlType){
  53. if(sutApp.appSleepStatus & (1<<ctlType)) return 1;
  54. else return 0;
  55. }
  56. /*检测是否APP可以休眠操作*/
  57. char isSleepReady(void){
  58. static unsigned int idleCnt=0;
  59. #ifdef DISABLE_SLEEP
  60. return 0;//不休眿
  61. #endif
  62. if(isAppSleepReady()==0){
  63. idleCnt=0;
  64. return 0;
  65. }
  66. if(++idleCnt>=(APP_IDLE_TIME*1000/APP_SUB_DIV_TIME)){
  67. idleCnt=0;
  68. return 1;
  69. }else return 0;
  70. }
  71. void usbCmdHandler(const char *data,unsigned int length){
  72. static char buf[256];
  73. static int len=0;
  74. static char lach;
  75. char ch;
  76. int i;
  77. if(sutApp.authReady==0){
  78. authRecvPro(data, length);
  79. return;
  80. }
  81. for(i=0;i<length;i++){
  82. ch=data[i];
  83. if(len<sizeof(buf)-1) buf[len++]=ch;
  84. else{
  85. len=0;
  86. buf[len++]=ch;
  87. }
  88. if(lach=='\r' && ch=='\n'){
  89. buf[len]=0;
  90. cmdSetting(buf);
  91. len=0;
  92. }
  93. lach=ch;
  94. }
  95. }
  96. static char micPttPressed=0;
  97. static char pttPressed=0;
  98. static void pttHandler(char type, char ctl){
  99. char needSend=0;
  100. char mic_spk;
  101. if(type==0){//ptt
  102. if(ctl==0){//放开
  103. if(micPttPressed==0){
  104. needSend=1;mic_spk=0;
  105. }
  106. pttPressed=0;
  107. }else{//按下
  108. if(pttPressed==0 && micPttPressed==0){
  109. needSend=1;mic_spk=1;
  110. }
  111. pttPressed=1;
  112. }
  113. }else{//mic ptt
  114. if(ctl==0){//放开
  115. if(pttPressed==0){
  116. needSend=1;mic_spk=0;
  117. }
  118. micPttPressed=0;
  119. }else{//按下
  120. if(pttPressed==0 && micPttPressed==0){
  121. needSend=1;mic_spk=1;
  122. }
  123. micPttPressed=1;
  124. }
  125. }
  126. if(needSend!=0){
  127. if(mic_spk==0) {
  128. msgAtSend("AT+POC=0C0000\r\n");
  129. sutPocStatus.prePtt=0;
  130. }
  131. else {
  132. sutPocStatus.prePtt=1;
  133. keyToneStart(1);
  134. // //特殊处理
  135. // if(sutPocStatus.TTS)return;
  136. // sutPocStatus.beep=1;
  137. // MSG_INFO(1, "=========prePtt==========");
  138. // paControl(true);
  139. // if(ToneThreadPtr!=NULL)threadSendEvent(ToneThreadPtr,OHPOC_EVENT_MAIN,NULL,NULL,NULL);//0702
  140. //msgAtSend("AT+POC=0B0000\r\n");
  141. }
  142. }
  143. }
  144. /*打印键信恿*/
  145. const char freeSeg[]="Free";
  146. const char pressSeg[]="Press";
  147. void showKeyMessage(unsigned short key,unsigned char status){
  148. char buf[50]="[Key_";
  149. //MSG_INFO(1, "key====%08x",key);
  150. switch(key){
  151. case MKEY_VALUE_F2: strcat(buf, "F2]");break;
  152. case MKEY_VALUE_F1: strcat(buf, "F1]");break;
  153. case MKEY_VALUE_PTT: strcat(buf, "PTT]");break;
  154. case MKEY_VALUE_MENU: strcat(buf, "MENU]");break;
  155. case MKEY_VALUE_UP: strcat(buf, "UP]");break;
  156. case MKEY_VALUE_DOWN: strcat(buf, "DOWN]");break;
  157. case MKEY_VALUE_ESC: strcat(buf, "ESC]");break;
  158. case MKEY_VALUE_PWR: strcat(buf, "PWR]");break;
  159. case MKEY_VALUE_CB_GT: strcat(buf, "CB_GT]");break;
  160. case MKEY_VALUE_CB_IP: strcat(buf, "CB_IP]");break;
  161. case MKEY_VALUE_MIC_PTT: strcat(buf, "MIC_PTT]");break;
  162. default:return;
  163. }
  164. if(status==0) strcat(buf, freeSeg);
  165. else strcat(buf, pressSeg);
  166. MSG_INFO(1,buf);
  167. }
  168. unsigned char keyInArow=0;
  169. void keyCheck(unsigned short keyStatus){
  170. static unsigned short lkey=0;
  171. static unsigned char keyCtl=0,keyCnt=0;
  172. unsigned char keyType,needSendKey=0;
  173. if(keyStatus==KS_ALL_IDLE){
  174. keyType=0;
  175. if(keyCtl==1){
  176. keyCtl=0;
  177. needSendKey=1;
  178. }
  179. }else{
  180. keyType=1;
  181. if(lkey != keyStatus) keyCtl=0;//值变匿
  182. if(keyCtl==0){
  183. lkey=keyStatus;
  184. keyCtl=1;
  185. keyCnt=0;
  186. needSendKey=1;
  187. }else if(keyInArow!=0){//是否输出持续倿
  188. if(++keyCnt>=(1000/KEY_TIMER_TICK)){//每秒产生持续倿
  189. keyCnt=0;
  190. needSendKey=1;
  191. }
  192. }
  193. }
  194. if(needSendKey){
  195. if(sutApp.enableKey!=0)//延时期间不检测按锿
  196. keySendEvent(lkey,keyType);
  197. }
  198. }
  199. void pwrDetRead(char type){
  200. static char cnt=0;
  201. if(type==0){
  202. if(++cnt>=5){
  203. MSG_INFO(1, "Power is off!");
  204. appSleepCtl(ASLEEP_PWR, 1);
  205. }
  206. }else{
  207. cnt=0;
  208. }
  209. }
  210. static void lockProcess(void){
  211. if(sutApp.keyLock==0){
  212. sutApp.keyLock=1;
  213. appSleepCtl(ASLEEP_GGROUP, 0);
  214. appSleepCtl(ASLEEP_GUSER, 0);
  215. uISetNextStatus(UIS_STANDBY);
  216. }else{
  217. sutApp.keyLock=0;
  218. sutApp.lockShow=0;
  219. }
  220. }
  221. //key:1 跳过
  222. void keyToneStart(char type){
  223. //return;
  224. if(newPara.KeySound==0&&type==0) return;
  225. if(sutPocStatus.TTS)return;
  226. if(type==2)sutPocStatus.beep=2;
  227. else sutPocStatus.beep=1;
  228. paControl(true);
  229. MSG_INFO(1, "Ptt:%d\r\n",sutPocStatus.PttFail);
  230. if(ToneThreadPtr!=NULL)threadSendEvent(ToneThreadPtr,OHPOC_EVENT_MAIN,NULL,NULL,NULL);//0702
  231. }
  232. void quickUiSwitch(int uistatus){
  233. uISetNextStatus(uistatus);
  234. getStackStruct()->FastUiChange=1;
  235. }
  236. /*进入GT模式*/
  237. static void enterGTMode(void){
  238. #ifndef ENABLE_PWM_BEEP
  239. msgAtSend("AT+TONES=1\r\n");
  240. #endif
  241. sutApp.gtMode=1;
  242. uioStatusSet(UIO_INDGT);
  243. paControl(true);//GT下常开喇叭
  244. #ifdef ENABLE_PWM_BEEP
  245. pwmBeepStart(868,50);
  246. LSAPI_OSI_ThreadSleep(100);
  247. pwmBeepStart(500,50);
  248. LSAPI_OSI_ThreadSleep(100);
  249. pwmBeepStart(868,50);
  250. #else
  251. msgAtSend("AT+TONE\r\n");
  252. LSAPI_OSI_ThreadSleep(200);
  253. msgAtSend("AT+TONE\r\n");
  254. #endif
  255. MSG_WARN(1, "Enter GT Mode");
  256. }
  257. void micPttHandler(char status){
  258. keySendEvent(MKEY_VALUE_MIC_PTT,status);
  259. }
  260. void keyHandler(unsigned short key,unsigned char status){//普通按键值处琿
  261. static unsigned char gtModeCnt=0;
  262. static unsigned char lockCnt=0;
  263. if(sutApp.keyLock!=0 && MKEY_VALUE_ESC!=key){
  264. sutApp.lockShow=1;
  265. return;
  266. }
  267. showKeyMessage(key,status);
  268. if(status==0){//key free
  269. switch(key){
  270. case MKEY_VALUE_MIC_PTT:
  271. pttHandler(0,0);
  272. break;
  273. case MKEY_VALUE_PTT:
  274. pttHandler(1,0);
  275. break;
  276. case MKEY_VALUE_PWR:
  277. //pwrDetRead(1);
  278. break;
  279. case MKEY_VALUE_ESC:
  280. //sutApp.LightStatus=1;
  281. pwrDetRead(1);
  282. lockCnt=0;
  283. if(sutUIstatus.Status==UIS_STANDBY){
  284. if(sutApp.LightStatus==0){
  285. if(!sutApp.cardStatus)return;
  286. if(lockCnt>1)return;
  287. if(sutPocStatus.danHuStatus)return;
  288. if(sutApp.MenuToStandby){
  289. sutApp.MenuToStandby=0;
  290. return;
  291. }
  292. startBackLightTimer(100);
  293. sutApp.LightStatus=1;
  294. }else {
  295. tryWakeupApp();
  296. backLightReset();
  297. sutApp.LightStatus=0;
  298. }
  299. }
  300. break;
  301. case MKEY_VALUE_F1:
  302. if(sutApp.key_f1_cnt==1 && sutUIstatus.Status!=UIS_MENU_SYS_SERVERPASS) sutApp.voluemUpdate=1;
  303. sutApp.key_f1_cnt=0;
  304. break;
  305. case MKEY_VALUE_F2:
  306. if(sutApp.key_f2_cnt==1 && sutUIstatus.Status!=UIS_MENU_SYS_SERVERPASS) sutApp.voluemUpdate=2;
  307. sutApp.key_f2_cnt=0;
  308. break;
  309. case MKEY_VALUE_CB_GT:
  310. gtModeCnt=0;
  311. break;
  312. default:
  313. break;
  314. }
  315. keyInArow=0;
  316. appSleepCtl(ASLEEP_MKEY, 0);
  317. }else{//key press
  318. //if(key!=MKEY_VALUE_PTT && key!=MKEY_VALUE_CB_GT&&key!=MKEY_VALUE_MIC_PTT) keyToneStart();
  319. if(key!=MKEY_VALUE_PTT && key!=MKEY_VALUE_CB_GT&&key!=MKEY_VALUE_MIC_PTT) keyToneStart(0);
  320. backLightReset();
  321. appSleepCtl(ASLEEP_MKEY, 1);
  322. keyNum++;
  323. switch(key){
  324. case MKEY_VALUE_MIC_PTT:
  325. pttHandler(0,1);
  326. break;
  327. case MKEY_VALUE_PTT:
  328. pttHandler(1,1);
  329. break;
  330. case MKEY_VALUE_PWR:
  331. keyInArow=1;
  332. //pwrDetRead(0);
  333. break;
  334. case MKEY_VALUE_ESC:
  335. keyInArow=1;
  336. lockCnt++;
  337. if(lockCnt==3){
  338. keyToneStart(0);
  339. // lockProcess(); //舍弃加锁功能
  340. }
  341. pwrDetRead(0);
  342. break;
  343. case MKEY_VALUE_F1:
  344. //sutApp.key_f1_cnt++;
  345. keyInArow=1;
  346. if(++sutApp.key_f1_cnt==3) quickUiSwitch(UIS_MENU_INFO_SEL);
  347. break;
  348. case MKEY_VALUE_F2:
  349. keyInArow=1;
  350. if(++sutApp.key_f2_cnt==3) quickUiSwitch(UIS_MENU_SYS_SIM);
  351. break;
  352. case MKEY_VALUE_CB_GT:
  353. keyInArow=1;
  354. if(++gtModeCnt==3){
  355. if(sutApp.gtMode==0){
  356. enterGTMode();
  357. }
  358. }
  359. break;
  360. case MKEY_VALUE_CB_IP:
  361. keyInArow=1;
  362. break;
  363. default:
  364. break;
  365. }
  366. }
  367. }
  368. /////////////////////////////事件发送接叿//////////////////////////
  369. void threadSendEvent(LSAPI_OSI_Thread_t *threadID, unsigned int id, unsigned int param1,unsigned int param2,unsigned int param3){
  370. LSAPI_OSI_Event_t pEventSend;
  371. pEventSend.id=id;
  372. pEventSend.param1=param1;
  373. pEventSend.param2=param2;
  374. pEventSend.param3=param3;
  375. osiEventTrySend(threadID,&pEventSend,0);
  376. }
  377. //////////////////////////////其它处理接口//////////////////////////
  378. static void adcRead(unsigned int interval){
  379. static unsigned int siVbat=0,laSiVbat;
  380. static unsigned char MIC_ptt=0;
  381. static unsigned char LastMIC_ptt=0;
  382. static unsigned short cnt=0,lcnt=0;
  383. unsigned int adcValueTmp;
  384. if(++cnt<(1000/interval)) return;//1秒读一次ADC即可
  385. cnt=0;
  386. LSAPI_SYS_BattGetVol(&adcValueTmp);
  387. //MSG_WARN(1,"Low power:%d mv",adcValueTmp/10 );
  388. if(sutApp.g_iBAT<=MIN_PWR_LEVEL){
  389. MSG_WARN(1,"Low power:%d", lcnt++);
  390. if(lcnt>=10){
  391. MSG_INFO(1, "Low power ,shut");
  392. sutApp.lowPwrMsg=1;
  393. appSleepCtl(ASLEEP_PWR, 1);
  394. }
  395. }else lcnt=0;
  396. sutApp.g_iBAT=adcValueTmp/10;
  397. if(sutApp.g_iBAT != laSiVbat){
  398. laSiVbat=sutApp.g_iBAT;
  399. }
  400. /* ***************EAR PTTdet ADC**************************/
  401. //通道3 范围3V
  402. if(LSAPI_Device_AdcGetChannelVolt(3,3)<1000)MIC_ptt=1;
  403. else MIC_ptt=0;
  404. if(LastMIC_ptt!=MIC_ptt){
  405. if(MIC_ptt==1)micPttHandler(1);
  406. else micPttHandler(0);
  407. LastMIC_ptt=MIC_ptt;
  408. }
  409. //MSG_WARN(1,"Low power:%d mv", LSAPI_Device_AdcGetChannelVolt(3,3));
  410. /******************************判断TTS 是否结束************************************************/
  411. if(false==LSAPI_TTS_IsPlaying())sutPocStatus.TTS=0;
  412. /**********************应用播放TONE2秒后关闭喇叭************************************/
  413. KeyToneDly();
  414. }
  415. /*处理UI操作*/
  416. static void uiProcess(unsigned int exeInterval){
  417. if(getAppObjStatus(ASLEEP_PWR) != 0) return;//关机后,不切换菜单,只显示关机页靿
  418. uiLoop(exeInterval);
  419. uiResponse(exeInterval);
  420. }
  421. /*触发关机操作*/
  422. static void pwrShutPro(void){
  423. static char shutFlag=0;
  424. if(getAppObjStatus(ASLEEP_PWR) == 0) return;
  425. CTL_LCD_BL(1);
  426. //msgAtSend("AT+POC=050000\r\n");
  427. msgToModem("AT+CFUN=0\r\n");
  428. if(shutFlag==0){
  429. //显示关机界面
  430. if(sutApp.lowPwrMsg==0){
  431. guiShowMessageBox("正在关机");
  432. }else guiShowMessageBox("低压关机");
  433. shutFlag=1;
  434. LSAPI_OSI_ThreadSleep(1000);
  435. }
  436. MSG_INFO(1, "Normal PwrOff");
  437. //msgAtSend("AT+TRB=1\r\n");//normal power off 当前固件先不发模块关机指令,否则断电再上电有可能是起不来皿
  438. //LSAPI_OSI_ThreadSleep(1000);//一秒后释放电源锿防止软关机不成功
  439. CTL_LCD_BL(0);
  440. MSG_INFO(1, "Release pwr");
  441. guiFillRect(0,0,GLCD_WIDTH-1,GLCD_HEIGHT-1,guiGetBackColor());//防止下次开机能看到残留
  442. CTL_POWER_HOLD(0);
  443. msgToModem("AT+CPOF\r\n");//软件关机模块
  444. LSAPI_OSI_ThreadSleep(100);
  445. }
  446. static void NoteCheck(int interval){
  447. int dlyMs;
  448. const char *lowVbat="E8AFB7E58585E794B5";
  449. char ttsbuf[40];
  450. StrAsciiToHex(lowVbat,ttsbuf);
  451. if(sutApp.lowPwrWarn!=0){
  452. sutApp.lowPwrCnt += interval;
  453. if(sutApp.lowPwrCnt>=WARN_TTS_INTERVAL){
  454. sutApp.lowPwrCnt=0;
  455. //broad_play_tts(ttsbuf,true);
  456. }
  457. }
  458. }
  459. void AntModeRun(void){
  460. #ifdef ENABLE_ANT_MODE
  461. guiShowMessageBox("调天线模式");
  462. for(;;){
  463. LSAPI_OSI_ThreadSleep(2000);
  464. }
  465. #endif
  466. }
  467. static void paProCtl(void);
  468. static void subTimerCtl(unsigned char sleep_or_not);
  469. static void startPocLogin(void){
  470. if(sutApp.startPoc==0) return;
  471. MSG_INFO(1, "Start poc");
  472. sutApp.startPoc=0;
  473. msgAtSend("AT+POC=0000000001\r\n");//打开对讲,关闭POC播放TTS //msgAtSend("AT+POC=0000000101\r\n");
  474. }
  475. void pocSetDomain(void){//设置域名前缀
  476. // const char platform[]="platform2";
  477. // const char pFormatMark[]="chn-gwsd-";
  478. char info[100]="AT+POC=120000";
  479. char tbuf[50];
  480. char* platform=0;
  481. char* pFormatMark=0;
  482. platform=sutApp.UserInfo.platform;
  483. pFormatMark=sutApp.UserInfo.pFormatMark;
  484. snprintf(tbuf, sizeof(tbuf), "%s,%s", platform,pFormatMark);
  485. AscStrTurnHexStr(tbuf, info+strlen(info));
  486. strcat(info, "00\r\n");
  487. msgAtSend(info);
  488. MSG_INFO(0, "**%s",info);
  489. }
  490. void ShouHuProcess(int interva)
  491. {
  492. static char nRet=0;
  493. static char regcnt=0;
  494. //static int LastAtt_state=0;
  495. int tmepAtt_state=0;
  496. static int cnt=0;
  497. if(sutApp.gtMode!=0)return;
  498. if(++cnt<(1000/interva)) return;
  499. cnt=0;
  500. nRet=LSAPI_NET_GetGprsAttState(&tmepAtt_state);
  501. if(nRet!=0){
  502. MSG_WARN(1,"Get REG status failed");
  503. return;
  504. }
  505. if(tmepAtt_state!=1){
  506. //if(LastAtt_state!=tmepAtt_state)MSG_WARN(1,"REG off");
  507. if(regcnt==60){
  508. MSG_WARN(1,"!!!!CFUN=0");
  509. msgAtSend("AT+CFUN=0\r\n");
  510. backLightReset();
  511. sutPocStatus.firstLogin=0;
  512. }else if(regcnt>=61){
  513. MSG_WARN(1,"!!!!CFUN=1");
  514. msgAtSend("AT+CFUN=1\r\n");
  515. regcnt=0;
  516. }
  517. ++regcnt;
  518. }else {
  519. regcnt=0;
  520. }
  521. }
  522. #define APP_NEED_SLEEP OSI_MAKE_TAG('S', 'E', 'L', 'P')
  523. void ls_suspend(void *ctx, osiSuspendMode_t mode)
  524. {
  525. MSG_INFO(1,"\n\r ls_suspend mode:%d\n",mode);
  526. }
  527. void ls_resume(void *ctx, osiSuspendMode_t mode, uint32_t source)
  528. {
  529. MSG_INFO(1,"\n\r ls_resume mode:%d,source:%d\n",mode,source);
  530. }
  531. osiPmSourceOps_t sleep_ops =
  532. {
  533. ls_suspend,
  534. ls_resume,
  535. NULL,
  536. NULL
  537. };
  538. void appRun(void){
  539. char cnt=0;
  540. char printfbuf[20]={0};
  541. LSAPI_OSI_Event_t event={0};
  542. osiPmSource_t*App_osiPmSource_t=NULL;
  543. App_osiPmSource_t=osiPmSourceCreate(APP_NEED_SLEEP, &sleep_ops, NULL);
  544. osiPmWakeLock(App_osiPmSource_t); //拿住资源不让系统休眠
  545. //等待lcd初始化完房
  546. MSG_INFO(1, "wait lcd init");
  547. while(sutApp.guiStatus==0){LSAPI_OSI_ThreadSleep(50);}//是否检测超时?
  548. AntModeRun();
  549. localAuthNow();
  550. while(sutApp.pocInitStatus==0){
  551. msgAtSend("AT+POC=version\r\n");//发指令后等待POC启动
  552. LSAPI_OSI_ThreadSleep(1000);
  553. }//是否检测超时?
  554. msgToModem("AT+SIMCROSS?\r\n");
  555. adcRead(APP_SUB_DIV_TIME);//在开机播放前设置下SPK
  556. backLightReset();
  557. //LSAPI_TTS_Play
  558. msgToModem("ATI\r\n");
  559. while(sutApp.Get_MicLv==0){
  560. msgToModem("AT+CACCP=0,0,1,\"\"\r\n");
  561. LSAPI_OSI_ThreadSleep(1000);
  562. if(++cnt>=5){
  563. MSG_INFO(1, "get MicLv timeout");
  564. break;
  565. }
  566. }
  567. msgToModem("AT+GMR\r\n");//查询模块版本
  568. while(sutApp.pocParaDone==0){
  569. msgAtSend("AT+POC=020000\r\n");
  570. LSAPI_OSI_ThreadSleep(1000);
  571. if(++cnt>=5){
  572. MSG_INFO(1, "read pocPara erro");
  573. break;
  574. }
  575. }
  576. pwrModeSetCmd(newPara.pwrMode);//设置功耗模式
  577. voiceModeSet(newPara.voiceSel);//设置音质
  578. while(sutApp.startPoc==1){
  579. LSAPI_OSI_ThreadSleep(1000);
  580. startPocLogin();
  581. }
  582. while(sutApp.cardStatus==0){
  583. //msgToModem("AT+CCID\r\n");
  584. msgToModem("AT+CPIN?\r\n");
  585. LSAPI_OSI_ThreadSleep(1000);
  586. if(++cnt>=10){
  587. MSG_INFO(1, "Check card timeout");
  588. if(newPara.ChangeCard==0){
  589. MSG_INFO(1, "REsel card ");
  590. newPara.ChangeCard=1;
  591. snprintf(printfbuf, sizeof(printfbuf), "AT+SIMCROSS=%d\r\n",sutApp.simSel);
  592. msgToModem(printfbuf);
  593. MSG_INFO(1, printfbuf);
  594. guiShowMessageBox("正在切卡");
  595. sysIniSave();
  596. LSAPI_OSI_ThreadSleep(1000);
  597. msgToModem("AT+TRB\r\n");
  598. LSAPI_OSI_ThreadSleep(1000);
  599. while(1);
  600. }
  601. break;
  602. }
  603. }
  604. newPara.ChangeCard=0;
  605. sysIniSave();
  606. //msgAtSend("AT+POC=7B00000064\r\n");
  607. msgToModem("ATE0\r\n");
  608. msgToModem("AT+AUDCH=0,0\r\n");//TEST 因为模块默认 通道为2,0
  609. pocSetDomain();
  610. //msgAtSend("AT+POC=0000000101\r\n");
  611. //osiPmWakeUnlock(App_osiPmSource_t);
  612. for(;;){
  613. // MS5700_Networking(APP_SUB_DIV_TIME); //网络监测
  614. // Domain_Process(APP_SUB_DIV_TIME); //
  615. // FOTA_Process(APP_SUB_DIV_TIME);
  616. volUpdateNeed();
  617. ledsProCtl();
  618. adcRead(APP_SUB_DIV_TIME);
  619. uiProcess(APP_SUB_DIV_TIME);
  620. if(GPS_HADRENABLE==1){
  621. gpsProCtl(APP_SUB_DIV_TIME);
  622. GpsInternalChange(APP_SUB_DIV_TIME);
  623. }
  624. #ifndef ANT_TEST
  625. pocProCtl(APP_SUB_DIV_TIME);
  626. #endif
  627. NoteCheck(APP_SUB_DIV_TIME);
  628. //GpsInternalChange(APP_SUB_DIV_TIME);
  629. ShouHuProcess(APP_SUB_DIV_TIME);
  630. //HookGroupUserInfo();
  631. HookVolToutCheck();
  632. //IncomingSMS();
  633. if(isSleepReady()==0) LSAPI_OSI_ThreadSleep(APP_TASK_SLEEP_TIME);
  634. else if(sutApp.gtMode==0){//正常模式下可以休眿
  635. MSG_WARN(1, "APP SLEEP");
  636. stopKeyTimer();
  637. subTimerCtl(1);//切换为休眠状态定时器
  638. sutApp.appStatus=1;
  639. redLedCtl(false);//休眠后保证灯没亮,否则有可能灯亮10ms,按理10ms后灯能灭,然后10ms时休眠了,应用就短时间内不会灭灯
  640. greenLedCtl(false);//休眠后保证灯没亮
  641. LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);
  642. lcdDrv_Init(1);//深度休眠唤醒后重新初始化SPI-LCD
  643. if(sutApp.lcdDlyLightUp){
  644. sutApp.lcdDlyLightUp=0;
  645. CTL_LCD_BL(1);
  646. }
  647. sutApp.forceUiFlash=1;
  648. sutApp.appStatus=0;
  649. subTimerCtl(0);//切换为唤醒状态定时器
  650. MSG_WARN(1, "APP WAKEUP");
  651. }
  652. //检测是否关机,这里要放在唤醒后操作
  653. pwrShutPro();
  654. }
  655. }
  656. unsigned int subTimerInterval=100;//定时器定时的时间
  657. LSAPI_OSI_Timer_t *pSubtimer_t = NULL;
  658. /*
  659. 为了做低功耗,此定时器在休眠时,设置为长时间定旿
  660. 非休眠时,设置为短时间定旿
  661. sleep_or_not:0 未休眠, else 休眠
  662. */
  663. static void subTimerCtl(unsigned char sleep_or_not){
  664. if(NULL==pSubtimer_t){
  665. MSG_WARN(1, "subTimer null");
  666. return;
  667. }
  668. LSAPI_OSI_TimerStop(pSubtimer_t);
  669. //打开定时噿
  670. if(sleep_or_not==0) subTimerInterval=100;//未休眠时_00ms
  671. else subTimerInterval=5000;//休眠旿5000ms
  672. LSAPI_OSI_TimerStart(pSubtimer_t,subTimerInterval);
  673. }
  674. static void subTimeroutcallback(void *param){
  675. unsigned int *dlyTime=(unsigned int *)param;
  676. //处理灯的显示
  677. uioProctl(*dlyTime);
  678. //控制功放的关闿
  679. paProCtl();
  680. if(NULL!=pSubtimer_t) LSAPI_OSI_TimerStart(pSubtimer_t,subTimerInterval);
  681. }
  682. void subTask(void *param){
  683. LSAPI_OSI_Event_t event={0};
  684. if(NULL==pSubtimer_t) pSubtimer_t = LSAPI_OSI_TimerCreate(LSAPI_OSI_ThreadCurrent(), subTimeroutcallback, (void *)&subTimerInterval);
  685. if(NULL==pSubtimer_t) MSG_WARN(1,"sub timer init failed");
  686. else LSAPI_OSI_TimerStart(pSubtimer_t,subTimerInterval);
  687. for(;;){LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);}
  688. }
  689. static void paProCtl(void){
  690. //会被定时调用
  691. if(sutPocStatus.TTS!=0) return;
  692. if(sutPocStatus.spk!=0) return;
  693. if(sutPocStatus.TONE!=0) return;
  694. if(sutPocStatus.beep!=0) return;
  695. if(sutApp.gtMode!=0) return;
  696. paControl(false); //测试版本
  697. //MSG_INFO(1,"spk off");
  698. }
  699. void tryWakeupApp(void){
  700. if(sutApp.appStatus!=0){
  701. if(mainThreadPtr!=NULL){
  702. threadSendEvent(mainThreadPtr,OHPOC_EVENT_MAIN,NULL,NULL,NULL);
  703. }
  704. }
  705. }
  706. void ttsPlay(ENCODE_USER_ENUM type, char *tts){
  707. int len,i;
  708. char ttsMessage[20*4];
  709. char Playbuf[100]={0};
  710. unsigned char codeType=ENCODE_USER_GBK;
  711. if(newPara.ttsMessage[0]==0) return;
  712. len=strlen(newPara.ttsMessage);
  713. len = len+(8-len%8);//
  714. MSG_INFO(1,"tts->");
  715. if(type==ENCODE_USER_UNICODE_BE)
  716. {
  717. codeType=LSAPI_TTS_UNICODE_BIG;
  718. for(i=0;i<len;i+=4){
  719. ttsMessage[i]=newPara.ttsMessage[i];
  720. ttsMessage[i+1]=newPara.ttsMessage[i+1];
  721. ttsMessage[i+2]=newPara.ttsMessage[i+2];
  722. ttsMessage[i+3]=newPara.ttsMessage[i+3];
  723. MSG_INFO(0,"%c",ttsMessage[i]);
  724. MSG_INFO(0,"%c",ttsMessage[i+1]);
  725. MSG_INFO(0,"%c",ttsMessage[i+2]);
  726. MSG_INFO(0,"%c",ttsMessage[i+3]);
  727. }
  728. ttsMessage[len-1]=0;
  729. StrAsciiToHex(ttsMessage,Playbuf);
  730. //MSG_INFO(1,"");
  731. }else if(type==ENCODE_USER_GBK) {
  732. codeType=LSAPI_TTS_GBK;
  733. //StrAsciiToHex(newPara.ttsMessage,Playbuf);
  734. StrAsciiToHex(tts,Playbuf);
  735. MSG_INFO(1, "tts Play:%d,%s",codeType,tts);
  736. }else if(type==ENCODE_USER_ASCII){
  737. codeType=LSAPI_TTS_GBK;
  738. strncpy(Playbuf, tts, strlen(tts));
  739. }
  740. paControl(true);
  741. sutPocStatus.TTS=1;
  742. // OEM_TTS_Spk(int type, char * atxt);
  743. LSAPI_TTS_Play(Playbuf,strlen(Playbuf),codeType);
  744. }
  745. /*背光时间到,熄灭*/
  746. void backLightCb(void *param){
  747. if(sutPocStatus.firstLogin==0) return;//未登录过,不灭屏
  748. if(newPara.lcdParaList[newPara.lcdParaDefaultIndex]==0) return;//常亮
  749. CTL_LCD_BL(0);
  750. sutApp.LightStatus=1;
  751. appSleepCtl(ASLEEP_LCD, 0);//可以休眠
  752. //osiPmWakeLock(App_osiPmSource_t);
  753. }
  754. /*点亮背光*/
  755. void backLightReset(void){
  756. unsigned short tmp;
  757. appSleepCtl(ASLEEP_LCD, 1);//不让休眠
  758. tmp=newPara.lcdParaList[newPara.lcdParaDefaultIndex];
  759. if(sutApp.appStatus==0) CTL_LCD_BL(1);//未休眠时,直接点亮
  760. else sutApp.lcdDlyLightUp=1;//休眠时不马上亮亮,会在LCD初始化完后点亮
  761. startBackLightTimer(tmp*1000);
  762. }
  763. void sysPwrLock(void){
  764. sutApp.pwrLock=1;
  765. }
  766. void sysPwrRlease(void){
  767. sutApp.pwrLock=0;
  768. }
  769. //"3132" --> 0x31,0x32
  770. void StrAsciiToHex(char *src, unsigned char *des){
  771. unsigned char temp[2],i;
  772. if(strlen(src)%2) return;
  773. while(0!=*src)
  774. {
  775. for(i=0;i<2;i++)
  776. {
  777. temp[i] = *src++;
  778. if(temp[i] >= '0' && temp[i] <= '9') temp[i] -= 0x30;
  779. else if(temp[i] >= 'A' && temp[i] <= 'F') temp[i] -= 0x37;
  780. else temp[i] -= 0x57;
  781. }
  782. temp[0] <<= 4;
  783. temp[0] &= 0xf0;
  784. *des++=temp[0]|temp[1];
  785. }
  786. *des=0;
  787. }
  788. void splVolumeSet(unsigned char level){
  789. char info[30];
  790. #ifdef ANT_TEST
  791. return;
  792. #endif
  793. // memset(info, 0, sizeof(info));
  794. snprintf(info, sizeof(info), "AT+CLVL=%d\r\n", level);
  795. msgToModem(info);
  796. snprintf(info, sizeof(info), "AT+CRSL=%d\r\n", level);
  797. msgToModem(info);
  798. //// broad_set_vol(BND_VOICE, level/10);
  799. // broad_set_vol(BND_TTS, level/12);//10
  800. // broad_set_vol(BND_TONE, level/12);
  801. //MSG_INFO(1,"#############################################");
  802. }
  803. /*调节音量,刷新音量进度条*/
  804. /*调节音量,刷新音量进度条*/
  805. void volAdjAction(char direction,unsigned char UIStatus){
  806. int vol;
  807. #ifdef ANT_TEST
  808. return;
  809. #endif
  810. if(direction==0){
  811. if(newPara.spkVol<MAX_SPK_VOL) newPara.spkVol++;
  812. else goto FLASH;
  813. }else{
  814. if(newPara.spkVol>0) newPara.spkVol--;
  815. else goto FLASH;
  816. }
  817. splVolumeSet(newPara.spkVol*10);
  818. MSG_INFO(1,"SPK_VOL:%d",newPara.spkVol*10);
  819. // vol=broad_get_vol(BND_VOICE);
  820. // MSG_INFO(1,"voice_VO1L:%d",vol);
  821. // vol=broad_get_vol(BND_TTS);
  822. // MSG_INFO(1,"tts_VOL2:%d",vol);
  823. // vol=broad_get_vol(BND_TONE);
  824. // MSG_INFO(1,"tone_VOL3:%d",vol);
  825. sysIniSave();
  826. //刷新进度条
  827. FLASH:
  828. if(UIS_STANDBY==UIStatus)volUiFlash(newPara.spkVol);
  829. }
  830. void volUpdateNeed(void){
  831. if(sutApp.voluemUpdate==0) return;
  832. if(sutApp.voluemUpdate==1) volAdjAction(0, sutUIstatus.Status);
  833. else if(sutApp.voluemUpdate==2) volAdjAction(1, sutUIstatus.Status);
  834. sutApp.voluemUpdate=0;
  835. }
  836. /*
  837. //对都使用主音频通道设计来说,耳机模式时,需要按比例降低输入输出增益
  838. unsigned char micGainTable[MIC_GAIN_NUM][2]={
  839. {3,10},{4,2},{4,10},{5,2},{5,10},{6,2},{6,10}
  840. };
  841. void VolMicUpdate(void){
  842. unsigned char tableIndex;
  843. char cmd[50];
  844. int vol=newPara.spkVol*10;
  845. splVolumeSet(vol);
  846. if(sutApp.earLev==0){//耳机拔掉,恢复正常MIC增益
  847. tableIndex=newPara.micGain_onspk;
  848. //msgAtSend("AT+CACCP=0,0,0,\"04000a00\"\r\n");
  849. }else{//耳机接入
  850. tableIndex=newPara.micGain_onear;
  851. //msgAtSend("AT+CACCP=0,0,0,\"02000f00\"\r\n");
  852. }
  853. if(tableIndex>=MIC_GAIN_NUM){
  854. MSG_WARN(1, "Index invalid:%d", tableIndex);
  855. return;
  856. }
  857. snprintf(cmd, sizeof(cmd), "AT+CACCP=0,0,0,\"%02x00%02x00\"\r\n", micGainTable[tableIndex][0],micGainTable[tableIndex][1]);
  858. msgAtSend(cmd);
  859. }
  860. */
  861. static void KeyToneDly()
  862. {
  863. static unsigned char Cnt=0;
  864. if(sutPocStatus.beep){
  865. if(++Cnt>1){
  866. Cnt=0;
  867. sutPocStatus.beep=0;
  868. }
  869. }else Cnt=0;
  870. }