app.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. #include "includes.h"
  2. #include "lsapi_tts.h"
  3. //17903920
  4. //219782401
  5. #define APP_IDLE_TIME 3 //如果POC已休眿APP没有操作一定秒数后休眠
  6. int keyNum=0;
  7. APP_DEF sutApp;
  8. static void KeyToneDly();
  9. static void appDataInit(void){
  10. memset((unsigned char *)&sutApp, 0, sizeof(APP_DEF));
  11. sutApp.pcant=4;
  12. sutApp.enableKey=1;
  13. //appSleepCtl(ASLEEP_POC, 1);
  14. appSleepCtl(ASLEEP_LCD, 1);
  15. readInfoNow();
  16. sysIniRead();
  17. }
  18. void dataInit(void){
  19. appDataInit();
  20. pocDataInit();
  21. gpsDataInit();
  22. uiDataInit();
  23. }
  24. static void ledsProCtl(void){
  25. if(sutApp.gtMode!=0) return;
  26. if(0==sutPocStatus.logined) uioStatusSet(UIO_INDOFFLINE);
  27. else if(sutPocStatus.spk>0)uioStatusSet(UIO_INDRX);
  28. else if(sutPocStatus.mic>0 )uioStatusSet(UIO_INDTX);
  29. else uioStatusSet(UIO_INDONLINE);
  30. }
  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. #ifndef USE_BND_POC
  129. msgAtSend("AT+POC=0C0000\r\n");
  130. #else
  131. broad_speak(0);
  132. #endif
  133. }
  134. else {
  135. #ifndef USE_BND_POC
  136. msgAtSend("AT+POC=0B0000\r\n");
  137. #else
  138. broad_speak(1);
  139. #endif
  140. }
  141. }
  142. }
  143. /*打印键信恿*/
  144. const char freeSeg[]="Free";
  145. const char pressSeg[]="Press";
  146. void showKeyMessage(unsigned short key,unsigned char status){
  147. char buf[50]="[Key_";
  148. switch(key){
  149. case MKEY_VALUE_F2: strcat(buf, "F2]");break;
  150. case MKEY_VALUE_F1: strcat(buf, "F1]");break;
  151. case MKEY_VALUE_PTT: strcat(buf, "PTT]");break;
  152. case MKEY_VALUE_MENU: strcat(buf, "MENU]");break;
  153. case MKEY_VALUE_UP: strcat(buf, "UP]");break;
  154. case MKEY_VALUE_DOWN: strcat(buf, "DOWN]");break;
  155. case MKEY_VALUE_ESC: strcat(buf, "ESC]");break;
  156. case MKEY_VALUE_PWR: strcat(buf, "PWR]");break;
  157. case MKEY_VALUE_CB_GT: strcat(buf, "CB_GT]");break;
  158. case MKEY_VALUE_CB_IP: strcat(buf, "CB_IP]");break;
  159. case MKEY_VALUE_MIC_PTT: strcat(buf, "MIC_PTT]");break;
  160. default:return;
  161. }
  162. if(status==0) strcat(buf, freeSeg);
  163. else strcat(buf, pressSeg);
  164. MSG_INFO(1,buf);
  165. }
  166. unsigned char keyInArow=0;
  167. void keyCheck(unsigned short keyStatus){
  168. static unsigned short lkey=0;
  169. static unsigned char keyCtl=0,keyCnt=0;
  170. unsigned char keyType,needSendKey=0;
  171. if(keyStatus==KS_ALL_IDLE){
  172. keyType=0;
  173. if(keyCtl==1){
  174. keyCtl=0;
  175. needSendKey=1;
  176. }
  177. }else{
  178. keyType=1;
  179. if(lkey != keyStatus) keyCtl=0;//值变匿
  180. if(keyCtl==0){
  181. lkey=keyStatus;
  182. keyCtl=1;
  183. keyCnt=0;
  184. needSendKey=1;
  185. }else if(keyInArow!=0){//是否输出持续倿
  186. if(++keyCnt>=(1000/KEY_TIMER_TICK)){//每秒产生持续倿
  187. keyCnt=0;
  188. needSendKey=1;
  189. }
  190. }
  191. }
  192. if(needSendKey){
  193. if(sutApp.enableKey!=0)//延时期间不检测按锿
  194. keySendEvent(lkey,keyType);
  195. }
  196. }
  197. bool lcdBackLightStatus=false;
  198. void pwrDetRead(char type){
  199. static char cnt=0;
  200. if(type==0){
  201. cnt++;
  202. if(cnt==3)uISetNextStatus(UIS_MENU_SHUT_PWR);
  203. }else{
  204. cnt=0;
  205. }
  206. if(sutUIstatus.Status == UIS_MENU_SHUT_PWR) return;//关机界面不处理
  207. if(type==0) return;//
  208. //处理按顶部键切换UI
  209. uiTimeOutToStandby(1,APP_SUB_DIV_TIME);
  210. //处理按顶部键切换背光
  211. if(sutUIstatus.Status != UIS_STANDBY) return;//待机页面时才反转背光
  212. if(lcdBackLightStatus==false) backLightReset();
  213. else lcdBackLightApi(0);//熄屏
  214. }
  215. void lcdBackLightApi(char value){
  216. CTL_LCD_BL(value);
  217. if(value==0) lcdBackLightStatus=false;
  218. else lcdBackLightStatus=true;
  219. }
  220. static void lockProcess(void){
  221. if(sutApp.keyLock==0){
  222. sutApp.keyLock=1;
  223. appSleepCtl(ASLEEP_GGROUP, 0);
  224. appSleepCtl(ASLEEP_GUSER, 0);
  225. uISetNextStatus(UIS_STANDBY);
  226. }else{
  227. sutApp.keyLock=0;
  228. sutApp.lockShow=0;
  229. }
  230. }
  231. void keyToneStart(void){
  232. if(newPara.KeySound==0) return;
  233. sutPocStatus.beep=1;
  234. paControl(true);
  235. if(ToneThreadPtr!=NULL)threadSendEvent(ToneThreadPtr,OHPOC_EVENT_MAIN,NULL,NULL,NULL);//0702
  236. }
  237. void quickUiSwitch(int uistatus){
  238. uISetNextStatus(uistatus);
  239. getStackStruct()->FastUiChange=1;
  240. }
  241. /*进入GT模式*/
  242. static void enterGTMode(void){
  243. #ifndef ENABLE_PWM_BEEP
  244. msgAtSend("AT+TONES=1\r\n");
  245. #endif
  246. sutApp.gtMode=1;
  247. uioStatusSet(UIO_INDGT);
  248. paControl(true);//GT下常开喇叭
  249. #ifdef ENABLE_PWM_BEEP
  250. pwmBeepStart(868,50);
  251. LSAPI_OSI_ThreadSleep(100);
  252. pwmBeepStart(500,50);
  253. LSAPI_OSI_ThreadSleep(100);
  254. pwmBeepStart(868,50);
  255. #else
  256. msgAtSend("AT+TONE\r\n");
  257. LSAPI_OSI_ThreadSleep(200);
  258. msgAtSend("AT+TONE\r\n");
  259. #endif
  260. MSG_WARN(1, "Enter GT Mode");
  261. }
  262. void micPttHandler(char status){
  263. keySendEvent(MKEY_VALUE_MIC_PTT,status);
  264. }
  265. #define MKEY_VALUE_F2 (1<<MKEY_VALUE_7)
  266. #define MKEY_VALUE_F1 (1<<MKEY_VALUE_5)
  267. #define MKEY_VALUE_PTT (1<<MKEY_VALUE_1)
  268. #define MKEY_VALUE_MENU (1<<MKEY_VALUE_2)
  269. #define MKEY_VALUE_UP (1<<MKEY_VALUE_3)
  270. #define MKEY_VALUE_DOWN (1<<MKEY_VALUE_6)
  271. #define MKEY_VALUE_ESC (1<<MKEY_VALUE_4)
  272. #define MKEY_VALUE_PWR (1<<MKEY_VALUE_8)
  273. void ResetKeyValue(unsigned char *value){
  274. if(*value==1){
  275. *value=0;
  276. pttHandler(1,0);
  277. }
  278. }
  279. void keyHandler(unsigned short key,unsigned char status){//普通按键值处琿
  280. static unsigned char gtModeCnt=0;
  281. static unsigned char lockCnt=0;
  282. static unsigned char Once_PTT=0;
  283. char str[20]={0};
  284. if(sutApp.keyLock!=0 && MKEY_VALUE_ESC!=key&&MKEY_VALUE_MIC_PTT!=key&&MKEY_VALUE_PTT!=key){
  285. sutApp.lockShow=1;
  286. return;
  287. }
  288. showKeyMessage(key,status);
  289. // if(key&MKEY_VALUE_MIC_PTT||key&MKEY_VALUE_MIC_PTT)return;
  290. if(status==0){//key free
  291. switch(key){
  292. case MKEY_VALUE_MIC_PTT:
  293. pttHandler(0,0);
  294. break;
  295. case MKEY_VALUE_PTT:
  296. Once_PTT=0;
  297. pttHandler(1,0);
  298. break;
  299. case MKEY_VALUE_PWR:
  300. pwrDetRead(1);
  301. break;
  302. case MKEY_VALUE_ESC:
  303. // MSG_INFO(1,"BND -palat===%s",str);
  304. lockCnt=0;
  305. break;
  306. // case MKEY_VALUE_UP:
  307. // if(sutUIstatus.Status!=UIS_MENU_SYS_SERVERPASS) sutApp.voluemUpdate=1;
  308. // break;
  309. // case MKEY_VALUE_DOWN:
  310. // if(sutUIstatus.Status!=UIS_MENU_SYS_SERVERPASS) sutApp.voluemUpdate=2;
  311. // break;
  312. case MKEY_VALUE_F2:
  313. if(sutApp.key_f2_cnt==1) quickUiSwitch(UIS_MENU_USER_SEL);
  314. sutApp.key_f2_cnt=0;
  315. break;
  316. case MKEY_VALUE_CB_GT:
  317. gtModeCnt=0;
  318. break;
  319. default:
  320. MSG_INFO(1,"ResetKeyValue-----%08X-",key);
  321. ResetKeyValue(&Once_PTT);//HYL
  322. break;
  323. }
  324. sutApp.timeOutCnt=0;
  325. keyInArow=0;
  326. appSleepCtl(ASLEEP_MKEY, 0);
  327. }else{//key press
  328. if(key!=MKEY_VALUE_PTT&& key!=MKEY_VALUE_MIC_PTT && key!=MKEY_VALUE_CB_GT ) keyToneStart();
  329. if(MKEY_VALUE_PWR != key) backLightReset();
  330. appSleepCtl(ASLEEP_MKEY, 1);
  331. keyNum++;
  332. switch(key){
  333. case MKEY_VALUE_MIC_PTT:
  334. pttHandler(0,1);
  335. break;
  336. case MKEY_VALUE_PTT:
  337. Once_PTT=1;
  338. pttHandler(1,1);
  339. break;
  340. case MKEY_VALUE_PWR:
  341. keyInArow=1;
  342. pwrDetRead(0);
  343. break;
  344. case MKEY_VALUE_ESC:
  345. keyInArow=1;
  346. if(++lockCnt==3) lockProcess();
  347. break;
  348. case MKEY_VALUE_F1:
  349. quickUiSwitch(UIS_MENU_GROUP_SEL);
  350. break;
  351. case MKEY_VALUE_F2:
  352. keyInArow=1;
  353. if(++sutApp.key_f2_cnt==3) quickUiSwitch(UIS_MENU_SYS_SIM);
  354. break;
  355. case MKEY_VALUE_CB_GT:
  356. keyInArow=1;
  357. if(++gtModeCnt==3){
  358. if(sutApp.gtMode==0){
  359. enterGTMode();
  360. }
  361. }
  362. break;
  363. case MKEY_VALUE_CB_IP:
  364. keyInArow=1;
  365. break;
  366. case MKEY_VALUE_MENU:
  367. case MKEY_VALUE_UP:
  368. case MKEY_VALUE_DOWN:
  369. break;
  370. default:
  371. break;
  372. }
  373. }
  374. }
  375. /////////////////////////////事件发送接叿//////////////////////////
  376. void threadSendEvent(LSAPI_OSI_Thread_t *threadID, unsigned int id, unsigned int param1,unsigned int param2,unsigned int param3){
  377. LSAPI_OSI_Event_t pEventSend;
  378. pEventSend.id=id;
  379. pEventSend.param1=param1;
  380. pEventSend.param2=param2;
  381. pEventSend.param3=param3;
  382. osiEventTrySend(threadID,&pEventSend,0);
  383. }
  384. //////////////////////////////其它处理接口//////////////////////////
  385. static void adcRead(unsigned int interval){
  386. static unsigned int siVbat=0,laSiVbat;
  387. static unsigned char MIC_ptt=0;
  388. static unsigned char LastMIC_ptt=0;
  389. static unsigned short cnt=0,lcnt=0;
  390. unsigned int adcValueTmp;
  391. if(++cnt<(1000/interval)) return;//1秒读一次ADC即可
  392. cnt=0;
  393. LSAPI_SYS_BattGetVol(&adcValueTmp);
  394. //MSG_WARN(1,"Low power:%d mv",adcValueTmp/10 );
  395. if(sutApp.g_iBAT<=MIN_PWR_LEVEL){
  396. MSG_WARN(1,"Low power:%d", lcnt++);
  397. if(lcnt>=10){
  398. MSG_INFO(1, "Low power ,shut");
  399. sutApp.lowPwrMsg=1;
  400. appSleepCtl(ASLEEP_PWR, 1);
  401. }
  402. }else lcnt=0;
  403. sutApp.g_iBAT=adcValueTmp/10;
  404. if(sutApp.g_iBAT != laSiVbat){
  405. laSiVbat=sutApp.g_iBAT;
  406. }
  407. /**********************应用播放TONE2秒后关闭喇叭************************************/
  408. KeyToneDly();
  409. }
  410. /*处理UI操作*/
  411. static void uiProcess(unsigned int exeInterval){
  412. if(getAppObjStatus(ASLEEP_PWR) != 0) return;//关机后,不切换菜单,只显示关机页靿
  413. uiLoop(exeInterval);
  414. uiResponse(exeInterval);
  415. }
  416. /*触发关机操作*/
  417. static void pwrShutPro(void){
  418. static char shutFlag=0;
  419. if(getAppObjStatus(ASLEEP_PWR) == 0) return;
  420. //CTL_LCD_BL(1);
  421. lcdBackLightApi(1);
  422. msgAtSend("AT+POC=050000\r\n");
  423. msgAtSend("AT+CFUN=0\r\n");
  424. if(shutFlag==0){
  425. //显示关机界面
  426. if(sutApp.lowPwrMsg==0) guiShowMessageBox("正在关机");
  427. else guiShowMessageBox("低压关机");
  428. shutFlag=1;
  429. LSAPI_OSI_ThreadSleep(1000);
  430. }
  431. MSG_INFO(1, "Normal PwrOff");
  432. //msgAtSend("AT+TRB=1\r\n");//normal power off 当前固件先不发模块关机指令,否则断电再上电有可能是起不来皿
  433. //LSAPI_OSI_ThreadSleep(1000);//一秒后释放电源锿防止软关机不成功
  434. CTL_LCD_BL(0);
  435. MSG_INFO(1, "Release pwr");
  436. guiFillRect(0,0,GLCD_WIDTH-1,GLCD_HEIGHT-1,guiGetBackColor());//防止下次开机能看到残留
  437. CTL_POWER_HOLD(0);
  438. msgAtSend("AT+CPOF\r\n");//软件关机模块
  439. LSAPI_OSI_ThreadSleep(100);
  440. }
  441. static void NoteCheck(int interval){
  442. const char *LOWPOWERNOTE="\xE8\xAF\xB7\xE5\x85\x85\xE7\x94\xB5";
  443. if(sutApp.lowPwrWarn!=0){
  444. sutApp.lowPwrCnt += interval;
  445. if(sutApp.lowPwrCnt>=WARN_TTS_INTERVAL){
  446. sutApp.lowPwrCnt=0;
  447. //ttsPlay(ENCODE_USER_GBK, "C7EBB3E4B5E7");
  448. broad_play_tts(LOWPOWERNOTE,true);
  449. }
  450. }
  451. }
  452. void AntModeRun(void){
  453. #ifdef ENABLE_ANT_MODE
  454. guiShowMessageBox("调天线模式");
  455. for(;;){
  456. LSAPI_OSI_ThreadSleep(2000);
  457. }
  458. #endif
  459. }
  460. void Ear_Judge(){
  461. LSAPI_HeadSetStatus_t status;
  462. status= LSAPI_Device_HeadSetGetStatus();//0628
  463. if(status == LSAPI_HEADSET_DISCONNECT)
  464. {
  465. MSG_INFO(1,"headset_disconnect");
  466. handsetStatusOutput(1);
  467. }
  468. else if(status == LSAPI_HEADSET_CONNECT)
  469. {
  470. MSG_INFO(1," headset_connect");
  471. handsetStatusOutput(0);
  472. }
  473. else
  474. {
  475. MSG_INFO(1,"unknow state");
  476. }
  477. }
  478. void APP_ls_PdpActive(){
  479. LSAPI_OSI_Event_t event = {0};
  480. unsigned res = 0;
  481. uint8_t nState = 1;
  482. uint8_t nCid = 1;
  483. uint8_t nSim = 0;
  484. res = LSAPI_NET_GprsAct(nState, nCid, nSim, &event);
  485. MSG_INFO(1,"LSAPI_NET_GprsAct event.id(%d)", event.id);
  486. MSG_INFO(1,"LSAPI_NET_GprsAct res(%d)", res);
  487. if (1 == res)
  488. {
  489. MSG_INFO(1,"LSAPI_NET_GprsAct cid(%d) active succ", nCid);
  490. LSAPI_NET_GET_GprsNetIf();
  491. }
  492. else
  493. {
  494. MSG_INFO(1,"LSAPI_NET_GprsAct cid(%d) active fail", nCid);
  495. }
  496. }
  497. #define SHOUHU_CNT 5
  498. void ShouHuProcess(int interva)
  499. {
  500. static int nRet=0;
  501. static char regcnt=0;
  502. int tmepAtt_state=0;
  503. static int cnt=0;
  504. int nActstate = 0;
  505. static char lastNetif=0;
  506. char Netif=0;
  507. if(++cnt<(SHOUHU_CNT*1000/interva)) return;
  508. cnt=0;
  509. nRet=LSAPI_NET_GetGprsAttState(&tmepAtt_state);
  510. if(nRet!=0){
  511. MSG_WARN(1,"Get REG status failed");
  512. return;
  513. }
  514. ////////////////////////检测并打开PDP/////////////////////////////
  515. nRet = LSAPI_NET_GetGprsActState(&nActstate);
  516. if (nActstate != 1)
  517. {
  518. APP_ls_PdpActive();
  519. lastNetif=0;
  520. }
  521. else
  522. {
  523. if(LSAPI_NET_GET_GprsNetIf() == FALSE)
  524. {
  525. MSG_INFO(1,"sock netif failed\n");
  526. LSAPI_NET_NetIf_Create();
  527. }
  528. else
  529. {
  530. MSG_INFO(1,"sock success\n");
  531. }
  532. //MSG_INFO(1,"LS GprsActState has been ACTIVED");
  533. }
  534. if(tmepAtt_state!=1){
  535. //if(LastAtt_state!=tmepAtt_state)MSG_WARN(1,"REG off");
  536. if(regcnt==60/SHOUHU_CNT){
  537. MSG_WARN(1,"!!!!CFUN=0");
  538. msgAtSend("AT+CFUN=0\r\n");
  539. backLightReset();
  540. sutPocStatus.firstLogin=0;
  541. }else if(regcnt>=65/SHOUHU_CNT){
  542. MSG_WARN(1,"!!!!CFUN=1");
  543. msgAtSend("AT+CFUN=1\r\n");
  544. regcnt=0;
  545. }
  546. ++regcnt;
  547. sutApp.RegNetOK=0;
  548. }else {
  549. regcnt=0;
  550. sutApp.RegNetOK=1;
  551. }
  552. }
  553. void HeartTickSend(int interva)
  554. {
  555. static int cnt=0;
  556. //unsigned int HertTime=0;
  557. const char PwrList[3]={25,45,5};
  558. if(++cnt<(PwrList[newPara.pwrMode]*1000/interva)) return;
  559. cnt=0;
  560. broad_send_ping();
  561. MSG_INFO(1,"BND HeartTick");
  562. }
  563. //30秒 无人呼叫自动退出单呼
  564. void BNDAutoExitDanhu(int interva)
  565. {
  566. static int cnt=0;
  567. if(sutPocStatus.danHuStatus==0)return;
  568. if(sutPocStatus.mic||sutPocStatus.spk){
  569. cnt=0;
  570. return;
  571. }
  572. if(++cnt<(30*1000/interva)) return;
  573. cnt=0;
  574. broad_leavegroup();
  575. }
  576. //开机配置设定好的模块音频参数文件
  577. #define READ_PER_SIZE 400 //每次从Bin文件读取最多400字节来发送,AT时长度翻倍
  578. static void configureVoiceParam(void){
  579. //const char *confiFile="ZT-MINI101HGS.bin";
  580. //const char *confiFile="ZT-MINI201-202HGS-20210703.bin";
  581. const char *confiFile="Q-800KTV.bin";
  582. unsigned char sendbuf[40+2*400];//AT+CAIET=0,0,9600,400,""
  583. unsigned char *dataPtr=sendbuf+sizeof(sendbuf)-READ_PER_SIZE;
  584. char buf[3];
  585. char status=0;
  586. int fd,offset,readsize,i;
  587. LSAPI_FS_Stat_info_t pBuf;
  588. MSG_INFO(1, "config audio file'%s'",confiFile);
  589. fd=LSAPI_FS_Open(confiFile, LSAPI_FS_O_RDONLY,0x0);
  590. if(fd>0){
  591. memset(&pBuf,0,sizeof(pBuf));
  592. LSAPI_FS_Fstat(fd,&pBuf);
  593. offset=0;
  594. LSAPI_FS_Seek(fd, offset, LSAPI_FS_SEEK_SET);
  595. while(offset<pBuf.st_size){
  596. readsize=pBuf.st_size-offset;
  597. if(readsize>400) readsize=400;
  598. readsize=LSAPI_FS_Read(fd, dataPtr, readsize);
  599. if(readsize==0) break;
  600. else if(readsize<0){
  601. status=1;
  602. break;
  603. }
  604. sprintf(sendbuf, "AT+CAIET=0,0,%d,%d,\"", offset, readsize);
  605. for(i=0;i<readsize;i++){
  606. sprintf(buf, "%02x", dataPtr[i]);
  607. strcat(sendbuf, buf);
  608. }
  609. strcat(sendbuf,"\"\r\n");
  610. msgAtSend(sendbuf);
  611. offset += readsize;
  612. LSAPI_OSI_ThreadSleep(10);
  613. }
  614. LSAPI_FS_Close(fd);
  615. if(status==0) MSG_INFO(1, "config audio file succ:%d",offset);
  616. else MSG_ERR(1, "config audio failed %d",status);
  617. }else MSG_ERR(1, "'%s' open failed",confiFile);
  618. }
  619. static void paProCtl(void);
  620. static void subTimerCtl(unsigned char sleep_or_not);
  621. LSAPI_CellLocation_t nCellInfo[max_neighbor_cellbun];
  622. void LbsTask(void* param){
  623. while(1){
  624. LSAPI_OSI_ThreadSleep(5000);//1000
  625. if(sutApp.RegNetOK==0||getAppObjStatus(ASLEEP_LCD)==0)continue;//
  626. //先获取主小区信息
  627. memset(nCellInfo,0x00,sizeof(nCellInfo));
  628. LSAPI_NET_CellInfo(nCellInfo,LSAPI_pCurrCellInfo,0);
  629. }
  630. }
  631. int lib_oem_device_bts(int* mcc,int* mnc,int* lac, int* cid){
  632. int tmp_mcc = 0;
  633. int tmp_mnc = 0;
  634. int tmp_lac = 0;
  635. int tmp_cid = 0;
  636. char buf[10]={0};
  637. /*
  638. tmp_mcc |= (nCellInfo[0].sMcc[0] & 0xff) <<8;
  639. tmp_mcc |= (nCellInfo[0].sMcc[1] & 0xff) <<4;
  640. tmp_mcc |= (nCellInfo[0].sMcc[2]& 0xff);
  641. */
  642. snprintf(buf, sizeof(buf),"%d%d%d",nCellInfo[0].sMcc[0],nCellInfo[0].sMcc[1],nCellInfo[0].sMcc[2]);
  643. tmp_mcc=htoi(buf);
  644. if(tmp_mcc==0)return -1;
  645. MSG_INFO(1,"tmp_mcc==%x",tmp_mcc);
  646. tmp_mnc |= (nCellInfo[0].sMnc[0] & 0xff) <<4;
  647. tmp_mnc |= (nCellInfo[0].sMnc[1] & 0xff) ;
  648. // tmp_mnc |= (nCellInfo[0].sMnc[2]& 0xff);
  649. /*
  650. if(nCellInfo[0].sMnc[2] != 0x0F){
  651. snprintf(buf, sizeof(buf),"%d%d%d",nCellInfo[0].sMnc[0],nCellInfo[0].sMnc[1],nCellInfo[0].sMnc[2]);
  652. tmp_mnc=htoi(buf);
  653. MSG_INFO(1,"tmp_mnc==%x",tmp_mnc);
  654. }else{
  655. snprintf(buf, sizeof(buf),"%d%d",nCellInfo[0].sMnc[0],nCellInfo[0].sMnc[1]);
  656. tmp_mnc=htoi(buf);
  657. MSG_INFO(1,"tmp_mnc==%x",tmp_mnc);
  658. }
  659. // if(tmp_mnc==0)return -1;
  660. */
  661. tmp_lac=nCellInfo[0].sLac;
  662. MSG_INFO(1,"tmp_lac==%d",tmp_lac);
  663. tmp_cid=nCellInfo[0].sCellID;
  664. MSG_INFO(1,"tmp_cid==%d",tmp_cid);
  665. *mcc=tmp_mcc;
  666. *mnc=tmp_mnc;
  667. *lac= tmp_lac;
  668. *cid=tmp_cid;
  669. return 0;
  670. }
  671. void LBS_Pth()
  672. {
  673. if(NULL==LSAPI_OSI_ThreadCreate("LBS_Pth", LbsTask, NULL, LSAPI_OSI_PRIORITY_NORMAL, LBS_TASK_THREAD_STACK, 10)){
  674. MSG_INFO(1,"LBS_Pth task failed");
  675. }
  676. }
  677. void Lbs_Sendto_bnd(){
  678. if(sutApp.RegNetOK==0){
  679. //lbs vail
  680. return;
  681. }
  682. broad_request_lbs_info(GLCD_WIDTH,GLCD_HEIGHT-UI_CONTENT_SHOW_Y+8,0,0);//多下载8为了裁剪上方标签
  683. MSG_INFO(1,"get lbs_info");
  684. }
  685. /****************************复制通道0的参数到通道1中***********************/
  686. void apnCopyHandle(int dly){
  687. static unsigned short cnt=0xfff;
  688. if(sutApp.apnCopyDone!=0) return;
  689. if(++cnt<(1000/dly)) return;
  690. cnt=0;
  691. msgAtSend("AT+CGDCONT?\r\n");
  692. }
  693. #define APP_NEED_SLEEP OSI_MAKE_TAG('S', 'E', 'L', 'P')
  694. void ls_suspend(void *ctx, osiSuspendMode_t mode)
  695. {
  696. MSG_INFO(1,"\n\r ls_suspend mode:%d\n",mode);
  697. }
  698. void ls_resume(void *ctx, osiSuspendMode_t mode, uint32_t source)
  699. {
  700. MSG_INFO(1,"\n\r ls_resume mode:%d,source:%d\n",mode,source);
  701. }
  702. osiPmSourceOps_t sleep_ops =
  703. {
  704. ls_suspend,
  705. ls_resume,
  706. NULL,
  707. NULL
  708. };
  709. void appRun(void){
  710. char cnt=0;
  711. LSAPI_OSI_Event_t event={0};
  712. const char *huanying="\xE6\xAC\xA2\xE8\xBF\x8E\xE4\xBD\xBF\xE7\x94\xA8\xE5\x85\xAC\xE7\xBD\x91\xE5\xAF\xB9\xE8\xAE\xB2\xE6\x9C\xBA";
  713. osiPmSource_t*App_osiPmSource_t=NULL;
  714. App_osiPmSource_t=osiPmSourceCreate(APP_NEED_SLEEP, &sleep_ops, NULL);
  715. osiPmWakeLock(App_osiPmSource_t); //拿住资源不让系统休眠
  716. //等待lcd初始化完
  717. MSG_INFO(1, "wait lcd init");
  718. while(sutApp.guiStatus==0){LSAPI_OSI_ThreadSleep(50);}//是否检测超时?
  719. AntModeRun();
  720. localAuthNow();
  721. open_bnd_app();
  722. msgAtSend("AT+SIMCROSS?\r\n");
  723. Ear_Judge();
  724. backLightReset();
  725. //LSAPI_TTS_Play
  726. msgAtSend("ATI\r\n");
  727. configureVoiceParam();
  728. broad_play_tts(huanying,true);//播报欢迎使用
  729. while(sutApp.cardStatus==0){
  730. msgAtSend("AT+CCID\r\n");
  731. LSAPI_OSI_ThreadSleep(1000);
  732. if(++cnt>=5){
  733. MSG_INFO(1, "Check card timeout");
  734. break;
  735. }
  736. }
  737. msgAtSend("ATE0\r\n");
  738. LBS_Pth();
  739. //newPara.lcdParaDefaultIndex=4
  740. for(;;){
  741. volUpdateNeed();
  742. ledsProCtl();
  743. adcRead(APP_SUB_DIV_TIME);
  744. uiProcess(APP_SUB_DIV_TIME);
  745. //gpsProCtl(APP_SUB_DIV_TIME);
  746. pocProCtl(APP_SUB_DIV_TIME);
  747. NoteCheck(APP_SUB_DIV_TIME);
  748. uiTimeOutToStandby(0, APP_SUB_DIV_TIME);
  749. ShouHuProcess(APP_SUB_DIV_TIME);
  750. apnCopyHandle(APP_SUB_DIV_TIME);
  751. //BNDAutoExitDanhu(APP_SUB_DIV_TIME);
  752. HookGroupUserInfo();
  753. HookVolToutCheck();
  754. //IncomingSMS();
  755. if(isSleepReady()==0) LSAPI_OSI_ThreadSleep(APP_TASK_SLEEP_TIME);
  756. else if(sutApp.gtMode==0){//正常模式下可以休眿
  757. MSG_WARN(1, "APP SLEEP");
  758. osiPmWakeUnlock(App_osiPmSource_t); //释放资源
  759. uiTimeOutToStandby(1, APP_SUB_DIV_TIME);
  760. stopKeyTimer();
  761. subTimerCtl(1);//切换为休眠状态定时器
  762. sutApp.appStatus=1;
  763. redLedCtl(false);//休眠后保证灯没亮,否则有可能灯亮10ms,按理10ms后灯能灭,然后10ms时休眠了,应用就短时间内不会灭灯
  764. greenLedCtl(false);//休眠后保证灯没亮
  765. LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);
  766. osiPmWakeLock(App_osiPmSource_t);
  767. LSAPI_OSI_ThreadSleep(150);//添加这个后,休眠时按键或被呼叫或本机呼叫,tone音能是完整的
  768. lcdDrv_Init(1);//深度休眠唤醒后重新初始化SPI-LCD
  769. if(sutApp.lcdDlyLightUp){
  770. sutApp.lcdDlyLightUp=0;
  771. CTL_LCD_BL(1);
  772. }
  773. sutApp.forceUiFlash=1;
  774. sutApp.appStatus=0;
  775. subTimerCtl(0);//切换为唤醒状态定时器
  776. MSG_WARN(1, "APP WAKEUP");
  777. }
  778. //检测是否关机,这里要放在唤醒后操作
  779. pwrShutPro();
  780. }
  781. broad_free();
  782. }
  783. unsigned int subTimerInterval=100;//定时器定时的时间
  784. LSAPI_OSI_Timer_t *pSubtimer_t = NULL;
  785. /*
  786. 为了做低功耗,此定时器在休眠时,设置为长时间定旿
  787. 非休眠时,设置为短时间定旿
  788. sleep_or_not:0 未休眠, else 休眠
  789. */
  790. static void subTimerCtl(unsigned char sleep_or_not){
  791. if(NULL==pSubtimer_t){
  792. MSG_WARN(1, "subTimer null");
  793. return;
  794. }
  795. LSAPI_OSI_TimerStop(pSubtimer_t);
  796. //打开定时噿
  797. if(sleep_or_not==0) subTimerInterval=100;//未休眠时_00ms
  798. else subTimerInterval=5000;//休眠旿5000ms
  799. LSAPI_OSI_TimerStart(pSubtimer_t,subTimerInterval);
  800. }
  801. static void subTimeroutcallback(void *param){
  802. unsigned int *dlyTime=(unsigned int *)param;
  803. //处理灯的显示
  804. uioProctl(*dlyTime);
  805. //控制功放的关闿
  806. paProCtl();
  807. if(sutApp.bndPocDone==1){
  808. HeartTickSend(subTimerInterval);
  809. BNDAutoExitDanhu(subTimerInterval);
  810. }
  811. if(NULL!=pSubtimer_t) LSAPI_OSI_TimerStart(pSubtimer_t,subTimerInterval);
  812. }
  813. void subTask(void *param){
  814. LSAPI_OSI_Event_t event={0};
  815. if(NULL==pSubtimer_t) pSubtimer_t = LSAPI_OSI_TimerCreate(LSAPI_OSI_ThreadCurrent(), subTimeroutcallback, (void *)&subTimerInterval);
  816. if(NULL==pSubtimer_t) MSG_WARN(1,"sub timer init failed");
  817. else LSAPI_OSI_TimerStart(pSubtimer_t,subTimerInterval);
  818. for(;;){LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);}
  819. }
  820. static void paProCtl(void){
  821. //会被定时调用
  822. if(sutPocStatus.TTS!=0) return;
  823. if(sutPocStatus.spk!=0) return;
  824. if(sutPocStatus.TONE!=0) return;
  825. if(sutPocStatus.beep!=0) return;
  826. if(sutApp.gtMode!=0) return;
  827. paControl(false);
  828. //MSG_INFO(1,"spk off");
  829. }
  830. void tryWakeupApp(void){
  831. if(sutApp.appStatus!=0){
  832. if(mainThreadPtr!=NULL){
  833. threadSendEvent(mainThreadPtr,OHPOC_EVENT_MAIN,NULL,NULL,NULL);
  834. }
  835. }
  836. }
  837. void ttsPlay(ENCODE_USER_ENUM type, char *tts){
  838. int len,i;
  839. char ttsMessage[20*4];
  840. char Playbuf[40]={0};
  841. unsigned char codeType=ENCODE_USER_GBK;
  842. if(newPara.ttsMessage[0]==0) return;
  843. len=strlen(newPara.ttsMessage);
  844. len = len+(8-len%8);//
  845. MSG_INFO(1,"tts->");
  846. if(type==ENCODE_USER_UNICODE_BE)
  847. {
  848. codeType=LSAPI_TTS_UNICODE_BIG;
  849. for(i=0;i<len;i+=4){
  850. /*
  851. ttsMessage[i]=newPara.ttsMessage[i+2];
  852. ttsMessage[i+1]=newPara.ttsMessage[i+3];
  853. ttsMessage[i+2]=newPara.ttsMessage[i];
  854. ttsMessage[i+3]=newPara.ttsMessage[i+1];
  855. */
  856. ttsMessage[i]=newPara.ttsMessage[i];
  857. ttsMessage[i+1]=newPara.ttsMessage[i+1];
  858. ttsMessage[i+2]=newPara.ttsMessage[i+2];
  859. ttsMessage[i+3]=newPara.ttsMessage[i+3];
  860. MSG_INFO(0,"%c",ttsMessage[i]);
  861. MSG_INFO(0,"%c",ttsMessage[i+1]);
  862. MSG_INFO(0,"%c",ttsMessage[i+2]);
  863. MSG_INFO(0,"%c",ttsMessage[i+3]);
  864. }
  865. ttsMessage[len-1]=0;
  866. StrAsciiToHex(ttsMessage,Playbuf);
  867. //MSG_INFO(1,"");
  868. }else if(type==ENCODE_USER_GBK) {
  869. codeType=LSAPI_TTS_GBK;
  870. StrAsciiToHex(newPara.ttsMessage,Playbuf);
  871. MSG_INFO(1, "tts Play:%d,%s",codeType,tts);
  872. }else if(type==ENCODE_USER_ASCII){
  873. codeType=LSAPI_TTS_GBK;
  874. strncpy(Playbuf, tts, strlen(tts));
  875. }
  876. paControl(true);
  877. sutPocStatus.TTS=1;
  878. LSAPI_TTS_Play(Playbuf,strlen(Playbuf),codeType);
  879. }
  880. /*背光时间到,熄灭*/
  881. void backLightCb(void *param){
  882. if(sutPocStatus.firstLogin==0) return;//未登录过,不灭屏
  883. if(newPara.lcdParaList[newPara.lcdParaDefaultIndex]==0) return;//常亮
  884. CTL_LCD_BL(0);
  885. lcdBackLightApi(0);
  886. appSleepCtl(ASLEEP_LCD, 0);//可以休眠
  887. }
  888. /*点亮背光*/
  889. void backLightReset(void){
  890. unsigned short tmp;
  891. appSleepCtl(ASLEEP_LCD, 1);//不让休眠
  892. tmp=newPara.lcdParaList[newPara.lcdParaDefaultIndex];
  893. if(sutApp.appStatus==0) {
  894. lcdBackLightApi(1);
  895. CTL_LCD_BL(1);//未休眠时,直接点亮
  896. }else sutApp.lcdDlyLightUp=1;//休眠时不马上亮亮,会在LCD初始化完后点亮
  897. startBackLightTimer(tmp*1000);
  898. }
  899. void sysPwrLock(void){
  900. sutApp.pwrLock=1;
  901. }
  902. void sysPwrRlease(void){
  903. sutApp.pwrLock=0;
  904. }
  905. //"3132" --> 0x31,0x32
  906. void StrAsciiToHex(char *src, unsigned char *des){
  907. unsigned char temp[2],i;
  908. if(strlen(src)%2) return;
  909. while(0!=*src)
  910. {
  911. for(i=0;i<2;i++)
  912. {
  913. temp[i] = *src++;
  914. if(temp[i] >= '0' && temp[i] <= '9') temp[i] -= 0x30;
  915. else if(temp[i] >= 'A' && temp[i] <= 'F') temp[i] -= 0x37;
  916. else temp[i] -= 0x57;
  917. }
  918. temp[0] <<= 4;
  919. temp[0] &= 0xf0;
  920. *des++=temp[0]|temp[1];
  921. }
  922. *des=0;
  923. }
  924. #if(USE_PA==NEW_PA)
  925. const unsigned char spkVolTable[MAX_SPK_VOL+1]={0,20,30,40,50,60,70,80,90};//不接耳机时喇叭音
  926. #else
  927. const unsigned char spkVolTable[MAX_SPK_VOL+1]={0,10,20,30,40,50,60,70,80};//不接耳机时喇叭音
  928. #endif
  929. void spkVolumeSet(unsigned char level){
  930. char info[30];
  931. snprintf(info, sizeof(info), "AT+CLVL=%d\r\n", level);
  932. msgAtSend(info);
  933. #if(USE_PA==NEW_PA)
  934. broad_set_vol(BND_TTS, level/15);
  935. broad_set_vol(BND_TONE, level/15);
  936. #else
  937. broad_set_vol(BND_TTS, level/25);
  938. broad_set_vol(BND_TONE, level/25);
  939. #endif
  940. }
  941. /*调节音量,刷新音量进度条*/
  942. void volAdjAction(char direction,unsigned char UIStatus){
  943. int vol;
  944. if(direction==0){
  945. if(newPara.spkVol<MAX_SPK_VOL) newPara.spkVol++;
  946. else goto FLASH;
  947. }else if(direction==1){
  948. if(newPara.spkVol>0) newPara.spkVol--;
  949. else goto FLASH;
  950. }
  951. /*
  952. spkVolumeSet(newPara.spkVol*10);
  953. MSG_INFO(1,"SPK_VOL:%d",newPara.spkVol*10);
  954. */
  955. spkVolumeSet(spkVolTable[newPara.spkVol]);
  956. MSG_INFO(1,"SPK_VOL:%d",spkVolTable[newPara.spkVol]);
  957. vol=broad_get_vol(BND_VOICE);
  958. MSG_INFO(1,"voice_VO1L:%d",vol);
  959. vol=broad_get_vol(BND_TTS);
  960. MSG_INFO(1,"tts_VOL2:%d",vol);
  961. vol=broad_get_vol(BND_TONE);
  962. MSG_INFO(1,"tone_VOL3:%d",vol);
  963. sysIniSave();
  964. //刷新进度条
  965. FLASH:
  966. if(UIS_STANDBY==UIStatus)volUiFlash(newPara.spkVol);
  967. }
  968. void volUpdateNeed(void){
  969. if(sutApp.voluemUpdate==0) return;
  970. if(sutApp.voluemUpdate==1) volAdjAction(0, sutUIstatus.Status);
  971. else if(sutApp.voluemUpdate==2) volAdjAction(1, sutUIstatus.Status);
  972. sutApp.voluemUpdate=0;
  973. }
  974. static void KeyToneDly()
  975. {
  976. static unsigned char Cnt=0;
  977. if(sutPocStatus.beep){
  978. if(++Cnt>1){
  979. Cnt=0;
  980. sutPocStatus.beep=0;
  981. }
  982. }else Cnt=0;
  983. }