app.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  1. #include "includes.h"
  2. #include "osi_api.h"
  3. #define APP_IDLE_TIME 3 //如果POC已休眿APP没有操作一定秒数后休眠
  4. int keyNum=0;
  5. APP_DEF sutApp;
  6. void plusKeyNum(void){
  7. keyNum++;
  8. }
  9. static void appDataInit(void){
  10. memset((unsigned char *)&sutApp, 0, sizeof(APP_DEF));
  11. sutApp.updateStatusBar=1;
  12. sutApp.g_iBAT=-1;
  13. sutApp.copstype=-1;
  14. sutApp.pcant=4;
  15. sutApp.enableKey=1;
  16. appSleepCtl(ASLEEP_POC, 1);
  17. appSleepCtl(ASLEEP_LCD, 1);
  18. readInfoNow();
  19. sysIniRead();
  20. ReadXbFile();
  21. ReadLeaderFile();
  22. #ifdef ENABLE_DEBUG
  23. takeNoteOfSerType();
  24. #endif
  25. }
  26. void dataInit(void){
  27. appDataInit();
  28. pocDataInit();
  29. gpsDataInit();
  30. uiDataInit();
  31. }
  32. static void ledsProCtl(void){
  33. if(sutApp.gtMode!=0) return;
  34. if(0==sutPocStatus.logined) uioStatusSet(UIO_INDOFFLINE);
  35. else if(sutPocStatus.spk>0)uioStatusSet(UIO_INDRX);
  36. else if(sutPocStatus.mic>0 )uioStatusSet(UIO_INDTX);
  37. else uioStatusSet(UIO_INDONLINE);
  38. }
  39. static void adcRead(unsigned int interval);
  40. char isKeyPress(void){
  41. if(keyNum) return keyNum--;
  42. else return 0;
  43. }
  44. /*APP休眠处理接口
  45. ctlType, 操作对象
  46. status,操作值,0 清除 else 设置
  47. */
  48. void appSleepCtl(ASLEEP_ENUM ctlType, char status){
  49. if(status==0) sutApp.appSleepStatus &= ~(1<<ctlType);
  50. else sutApp.appSleepStatus |= 1<<ctlType;
  51. }
  52. /*APP休眠状态接叿*/
  53. char isAppSleepReady(void){
  54. if(sutApp.appSleepStatus==0) return 1;
  55. else return 0;
  56. }
  57. /*获取指定休眠控制成员锁定的状怿
  58. 0 未锁宿否则锁定,锁定即可以休眠
  59. */
  60. char getAppObjStatus(ASLEEP_ENUM ctlType){
  61. if(sutApp.appSleepStatus & (1<<ctlType)) return 1;
  62. else return 0;
  63. }
  64. /*检测是否APP可以休眠操作*/
  65. char isSleepReady(void){
  66. static unsigned int idleCnt=0;
  67. #ifdef DISABLE_SLEEP
  68. return 0;//不休眿
  69. #endif
  70. if(isAppSleepReady()==0){
  71. idleCnt=0;
  72. return 0;
  73. }
  74. if(++idleCnt>=(APP_IDLE_TIME*1000/APP_SUB_DIV_TIME)){
  75. idleCnt=0;
  76. return 1;
  77. }else return 0;
  78. }
  79. void usbCmdHandler(const char *data,unsigned int length){
  80. static char buf[256];
  81. static int len=0;
  82. static char lach;
  83. char ch;
  84. int i;
  85. if(sutApp.authReady==0){
  86. authRecvPro(data, length);
  87. return;
  88. }
  89. for(i=0;i<length;i++){
  90. ch=data[i];
  91. if(len<sizeof(buf)-1) buf[len++]=ch;
  92. else{
  93. MSG_WARN(1, "USB Buf Over");
  94. len=0;
  95. buf[len++]=ch;
  96. }
  97. if(lach=='\r' && ch=='\n'){
  98. buf[len]=0;
  99. cmdSetting(buf);
  100. len=0;
  101. }
  102. lach=ch;
  103. }
  104. }
  105. static void pttHandler(char type, char ctl){
  106. #if 1//主PTT, 耳机PTT以及组合PTT都可以触发,即矩阵驱动时,任何一个按下如果没发请麦,则发请麦,只要有一个放开,则直接发放麦指令。因为组合按放后,放开,只有一个放开键值出来
  107. static char micPttPressed=0;
  108. static char pttPressed=0;
  109. static char maxPressed=0;
  110. if(type==0){//ptt
  111. if(ctl==0){//free
  112. pttPressed=0;
  113. }else{//press
  114. pttPressed=1;
  115. }
  116. }else if(type==1){//mic ptt
  117. if(ctl==0){//free
  118. micPttPressed=0;
  119. }else{//press
  120. micPttPressed=1;
  121. }
  122. }else if(type==2){//mic ptt
  123. if(ctl==0){//free
  124. maxPressed=0;
  125. }else{//press
  126. maxPressed=1;
  127. }
  128. }else return;
  129. if(ctl==0){//free
  130. if(pttPressed==0 || micPttPressed==0 || maxPressed==0){
  131. sutApp.pttReq=0;
  132. pttPressed=0;micPttPressed=0;maxPressed=0;
  133. msgAtSend("AT+POC=0C0000\r\n");
  134. sutPocStatus.PaDlyStart=1;
  135. paControl(true);
  136. }
  137. }else{//press
  138. if(pttPressed || micPttPressed || maxPressed){
  139. if(sutApp.pttReq==0){
  140. sutApp.pttReq=1;
  141. if(sutPocStatus.LeaderCmd!=0)return;//被 摇晕和摇毙
  142. msgAtSend("AT+POC=0B0000\r\n");
  143. if(newPara.gpsEnable&&sutGpsInfo.isGpsValid){
  144. if(newPara.Xinbiao_SendMode==0||newPara.Xinbiao_SendMode==2)XinbiaoPackSend(NULLCMD);
  145. }
  146. sutPocStatus.PaDlyStart=1;
  147. paControl(true);
  148. }
  149. }
  150. }
  151. #else
  152. static char micPttPressed=0;
  153. static char pttPressed=0;
  154. char needSend=0;
  155. char mic_spk;
  156. if(type==0){//ptt
  157. if(ctl==0){//放开
  158. if(micPttPressed==0){
  159. needSend=1;mic_spk=0;
  160. }
  161. pttPressed=0;
  162. }else{//按下
  163. if(pttPressed==0 && micPttPressed==0){
  164. needSend=1;mic_spk=1;
  165. }
  166. pttPressed=1;
  167. }
  168. }else if(type==1){//mic ptt
  169. if(ctl==0){//放开
  170. if(pttPressed==0){
  171. needSend=1;mic_spk=0;
  172. }
  173. micPttPressed=0;
  174. }else{//按下
  175. if(pttPressed==0 && micPttPressed==0){
  176. needSend=1;mic_spk=1;
  177. }
  178. micPttPressed=1;
  179. }
  180. }
  181. if(needSend!=0){
  182. if(mic_spk==0) msgAtSend("AT+POC=0C0000\r\n");
  183. else msgAtSend("AT+POC=0B0000\r\n");
  184. }
  185. #endif
  186. }
  187. /*打印键信恿*/
  188. const char freeSeg[]="Free";
  189. const char pressSeg[]="Press";
  190. void showKeyMessage(unsigned short key,unsigned char status){
  191. char buf[50]="[Key_";
  192. switch(key){
  193. case MKEY_VALUE_F2: strcat(buf, "F2]");break;
  194. case MKEY_VALUE_F1: strcat(buf, "F1]");break;
  195. case MKEY_VALUE_PTT: strcat(buf, "PTT]");break;
  196. case MKEY_VALUE_MENU: strcat(buf, "MENU]");break;
  197. case MKEY_VALUE_UP: strcat(buf, "UP]");break;
  198. case MKEY_VALUE_DOWN: strcat(buf, "DOWN]");break;
  199. case MKEY_VALUE_ESC: strcat(buf, "ESC]");break;
  200. case MKEY_VALUE_CB_GT: strcat(buf, "CB_GT]");break;
  201. case MKEY_VALUE_CB_IP: strcat(buf, "CB_IP]");break;
  202. case MKEY_VALUE_MIC_PTT: strcat(buf, "MIC_PTT]");break;
  203. case MKEY_VALUE_CB_PTT: strcat(buf, "MAX_PTT]");break;
  204. default: return;
  205. }
  206. if(status==0) strcat(buf, freeSeg);
  207. else strcat(buf, pressSeg);
  208. MSG_INFO(1,buf);
  209. }
  210. /*
  211. 龙尚矩阵驱动有一个问题:先按A不放,检测到A按下,再按B不放,检测到B按下,同时放开,概率只检测到B放开,A没检测到
  212. 规避方式:键值发生变化时,如果上次的键值大于等于2,直接清掉键值。
  213. */
  214. void assistantCheck(unsigned short key){
  215. unsigned int i,j,w;
  216. static unsigned short lkey=0;
  217. if(lkey==key) return;
  218. j=0;
  219. for(i=0;i<16;i++){//上次键值置位的个数
  220. if(lkey & (1<<i)) j++;
  221. }
  222. w=0;
  223. for(i=0;i<16;i++){//本次键值置位的个数
  224. if(key & (1<<i)) w++;
  225. }
  226. if(j>=2 && j>w){//上一次至少两个键按下,现在发生变化,至少一个键放开了,全键清除
  227. lkey=0;
  228. clearKeyValue();
  229. }
  230. lkey=key;
  231. }
  232. unsigned char keyInArow=0;
  233. void keyCheck(unsigned short keyStatus){
  234. static unsigned short lkey=0;
  235. static unsigned char keyCtl=0,keyCnt=0;
  236. unsigned char keyType,needSendKey=0;
  237. assistantCheck(keyStatus);
  238. if(keyStatus==KS_ALL_IDLE){
  239. keyType=0;
  240. if(keyCtl==1){
  241. keyCtl=0;
  242. needSendKey=1;
  243. }
  244. }else{
  245. keyType=1;
  246. if(lkey != keyStatus) keyCtl=0;//值变匿
  247. if(keyCtl==0){
  248. lkey=keyStatus;
  249. keyCtl=1;
  250. keyCnt=0;
  251. needSendKey=1;
  252. }else if(keyInArow!=0){//是否输出持续倿
  253. if(++keyCnt>=(1000/KEY_TIMER_TICK)){//每秒产生持续倿
  254. keyCnt=0;
  255. needSendKey=1;
  256. }
  257. }
  258. }
  259. if(needSendKey){
  260. if(sutApp.enableKey!=0)//延时期间不检测按锿
  261. keySendEvent(lkey,keyType);
  262. }
  263. }
  264. bool lcdBackLightStatus=false;
  265. void pwrDetRead(char type){
  266. static char cnt=0;
  267. if(type==0){
  268. cnt++;
  269. if(cnt==3){
  270. sutApp.waitEscReleased=1;
  271. uISetNextStatus(UIS_MENU_SHUT_PWR);
  272. }
  273. }else{
  274. sutApp.waitEscReleased=0;
  275. cnt=0;
  276. }
  277. #if 0
  278. if(sutUIstatus.Status == UIS_MENU_SHUT_PWR) return;//关机界面不处理
  279. if(type==0) return;//放开时处理
  280. //处理按顶部键切换UI
  281. uiTimeOutToStandby(1,APP_SUB_DIV_TIME);
  282. //处理按顶部键切换背光
  283. if(sutUIstatus.Status != UIS_STANDBY) return;//待机页面时才反转背光
  284. if(lcdBackLightStatus==false) backLightReset();
  285. else lcdBackLightApi(0);
  286. #endif
  287. }
  288. void lcdBackLightApi(char value){
  289. CTL_LCD_BL(value);
  290. if(value==0) lcdBackLightStatus=false;
  291. else lcdBackLightStatus=true;
  292. }
  293. static void lockProcess(void){
  294. if(sutApp.keyLock==0){
  295. sutApp.keyLock=1;
  296. appSleepCtl(ASLEEP_GGROUP, 0);
  297. appSleepCtl(ASLEEP_GUSER, 0);
  298. uISetNextStatus(UIS_STANDBY);
  299. }else{
  300. sutApp.keyLock=0;
  301. sutApp.lockShow=0;
  302. }
  303. }
  304. void keyToneStart(void){
  305. if(newPara.KeySound==0) return;
  306. sutPocStatus.beep=1;
  307. paControl(true);
  308. if(ToneThreadPtr!=NULL)threadSendEvent(ToneThreadPtr,OHPOC_EVENT_MAIN,NULL,NULL,NULL);//0702
  309. }
  310. void quickUiSwitch(int uistatus){
  311. if(true==isUiSwitchReady()) return;
  312. uISetNextStatus(uistatus);
  313. getStackStruct()->FastUiChange=1;
  314. }
  315. /*进入GT模式*/
  316. static void enterGTMode(void){
  317. sutApp.gtMode=1;
  318. uioStatusSet(UIO_INDGT);
  319. paControl(true);//GT下常开喇叭
  320. LSAPI_OSI_ThreadSleep(200);
  321. MSG_WARN(1, "Enter GT Mode");
  322. }
  323. void micPttHandler(char status){
  324. keySendEvent(MKEY_VALUE_MIC_PTT,status);
  325. }
  326. void quickUiSel(char func01_02){
  327. switch(func01_02){
  328. case 0:
  329. quickUiSwitch(UIS_MENU_BLE_ENABLE);
  330. break;
  331. case 1:
  332. quickUiSwitch(UIS_MENU_XINBIAO_SENDMODE);
  333. break;
  334. case 2:
  335. quickUiSwitch(UIS_MENU_XINBIAO_INFO);
  336. break;
  337. case 3:
  338. quickUiSwitch(UIS_MENU_GROUP_SEL);
  339. break;
  340. case 4:
  341. quickUiSwitch(UIS_MENU_USER_SEL);
  342. break;
  343. case 5:
  344. quickUiSwitch(UIS_MENU_FRIEND_SEL);
  345. break;
  346. }
  347. }
  348. void keyHandler(unsigned short key,unsigned char status){//普通按键值处琿
  349. static unsigned char debugcnt=0;
  350. static unsigned char gtModeCnt=0;
  351. static unsigned char lockCnt=0;
  352. if(newPara.lockType!=0){
  353. if(sutApp.keyLock!=0 &&(MKEY_VALUE_MENU!=key)){
  354. sutApp.lockShow=1;
  355. return;
  356. }
  357. }else{
  358. if(sutApp.keyLock!=0 && (MKEY_VALUE_DOWN==key || MKEY_VALUE_ESC==key)){
  359. sutApp.lockShow=1;
  360. return;
  361. }
  362. }
  363. showKeyMessage(key,status);
  364. //MSG_INFO(1,"key========%d",key);
  365. if(status==0){//key free
  366. switch(key){
  367. case MKEY_VALUE_MIC_PTT:
  368. pttHandler(0,0);
  369. break;
  370. case MKEY_VALUE_PTT:
  371. pttHandler(1,0);
  372. break;
  373. case MKEY_VALUE_CB_PTT:
  374. pttHandler(2,0);
  375. break;
  376. case MKEY_VALUE_ESC:
  377. pwrDetRead(1);
  378. break;
  379. case MKEY_VALUE_UP:
  380. //if(sutApp.key_f1_cnt==1 && sutUIstatus.Status!=UIS_MENU_SYS_SERVERPASS) sutApp.voluemUpdate=1;
  381. sutApp.key_f1_cnt=0;
  382. break;
  383. case MKEY_VALUE_DOWN:
  384. //if(sutApp.key_f2_cnt==1 && sutUIstatus.Status!=UIS_MENU_SYS_SERVERPASS) sutApp.voluemUpdate=2;
  385. sutApp.key_f2_cnt=0;
  386. break;
  387. case MKEY_VALUE_CB_GT:
  388. gtModeCnt=0;
  389. break;
  390. case MKEY_VALUE_MENU:
  391. if(sutApp.keyLock != 0 && lockCnt==1)//实际无法实现锁短按一下,因为按下去键值就被使用了,不过锁键盘后,都是在待机界面,不影响
  392. sutApp.lockShow=1;
  393. lockCnt=0;
  394. break;
  395. case MKEY_VALUE_CB_IP:
  396. debugcnt=0;
  397. break;
  398. default:
  399. break;
  400. }
  401. sutApp.timeOutCnt=0;
  402. keyInArow=0;
  403. appSleepCtl(ASLEEP_MKEY, 0);
  404. }else{//key press
  405. if(key!=MKEY_VALUE_MIC_PTT &&key!=MKEY_VALUE_PTT && key!=MKEY_VALUE_CB_GT) keyToneStart();
  406. backLightReset();//其它所有键都点亮(接口里面有调阻止休眠接口)
  407. appSleepCtl(ASLEEP_MKEY, 1);
  408. keyNum++;
  409. switch(key){
  410. case MKEY_VALUE_MIC_PTT:
  411. pttHandler(0,1);
  412. break;
  413. case MKEY_VALUE_PTT:
  414. pttHandler(1,1);
  415. break;
  416. case MKEY_VALUE_CB_PTT:
  417. pttHandler(2,1);
  418. break;
  419. case MKEY_VALUE_ESC:
  420. keyInArow=1;
  421. pwrDetRead(0);
  422. break;
  423. case MKEY_VALUE_UP:
  424. keyInArow=1;
  425. sutApp.key_f1_cnt++;
  426. if(sutApp.keyLock==0){
  427. if(sutApp.key_f1_cnt==3) {
  428. quickUiSel(newPara.sidekey01_func);
  429. }
  430. }else if(sutApp.key_f1_cnt!=1) sutApp.lockShow=1;
  431. break;
  432. case MKEY_VALUE_DOWN:
  433. keyInArow=1;
  434. sutApp.key_f2_cnt++;
  435. if(sutApp.keyLock==0){
  436. if(sutApp.key_f2_cnt==3) {
  437. quickUiSel(newPara.sidekey02_func);
  438. }
  439. }else if(sutApp.key_f2_cnt!=1) sutApp.lockShow=1;
  440. break;
  441. case MKEY_VALUE_CB_GT:
  442. keyInArow=1;
  443. gtModeCnt++;
  444. if(sutApp.keyLock==0){
  445. if(gtModeCnt==3){
  446. if(sutApp.gtMode==0){
  447. enterGTMode();
  448. }
  449. }
  450. }else sutApp.lockShow=1;
  451. break;
  452. case MKEY_VALUE_CB_IP:
  453. keyInArow=1;
  454. if(++debugcnt==10) uISetNextStatus(UIS_DEBUG);
  455. break;
  456. case MKEY_VALUE_MENU:
  457. keyInArow=1;
  458. if(++lockCnt==30) lockProcess();
  459. break;
  460. default:
  461. break;
  462. }
  463. }
  464. }
  465. unsigned char encodeDirection=ENCODE_IDLE;
  466. unsigned char getEncodeStatus(void){
  467. unsigned char tmp=encodeDirection;
  468. if(encodeDirection!=ENCODE_IDLE) encodeDirection=ENCODE_IDLE;
  469. return tmp;
  470. }
  471. #define PROCESS_ENCODE_TIME//是否要延时连续处理旋钮键值
  472. void encodeHandler(unsigned char encode){
  473. #ifdef PROCESS_ENCODE_TIME
  474. static int64_t lastTimeMs=0;
  475. int64_t timems=LSAPI_OSI_UpTime();
  476. //添加下延时,0.5秒处理一次
  477. if(timems-lastTimeMs<100) goto ENCODE_END;
  478. lastTimeMs=timems;
  479. #endif
  480. //处理键值
  481. if(encode==ENCODE_SHUN) MSG_INFO(1, "[Encode]:shun");
  482. else if(encode==ENCODE_NI) MSG_INFO(1, "[Encode]:ni");
  483. plusKeyNum();
  484. backLightReset();
  485. tryWakeupApp();
  486. sutApp.timeOutCnt=0;
  487. // if(sutUIstatus.Status==UIS_STANDBY){
  488. // sutApp.groupKeyType=1;
  489. // quickUiSwitch(UIS_MENU_GROUP_SEL);
  490. // }else{
  491. // encodeDirection=encode;
  492. // }
  493. if(encode==ENCODE_SHUN){
  494. sutApp.voluemUpdate=1;
  495. }else if(encode==ENCODE_NI){
  496. sutApp.voluemUpdate=2;
  497. }
  498. #ifdef PROCESS_ENCODE_TIME
  499. ENCODE_END:
  500. #endif
  501. encodeReleased();
  502. }
  503. /////////////////////////////事件发送接叿//////////////////////////
  504. void threadSendEvent(LSAPI_OSI_Thread_t *threadID, unsigned int id, unsigned int param1,unsigned int param2,unsigned int param3){
  505. LSAPI_OSI_Event_t pEventSend;
  506. pEventSend.id=id;
  507. pEventSend.param1=param1;
  508. pEventSend.param2=param2;
  509. pEventSend.param3=param3;
  510. osiEventTrySend(threadID,&pEventSend,0);
  511. }
  512. //////////////////////////////其它处理接口//////////////////////////
  513. static void adcRead(unsigned int interval){
  514. static unsigned char earStatus=0xff;
  515. int32_t chargeVol;
  516. static unsigned short cnt=0,lcnt=0;
  517. static unsigned int laSiVbat;
  518. unsigned int adcValueTmp;
  519. if(++cnt<(1000/interval)) return;//1秒读一次ADC即可
  520. cnt=0;
  521. LSAPI_SYS_BattGetVol(&adcValueTmp);
  522. sutApp.g_iBAT=adcValueTmp/10;
  523. if(sutApp.g_iBAT == laSiVbat){
  524. laSiVbat=sutApp.g_iBAT;
  525. if(sutApp.g_iBAT<=MIN_PWR_LEVEL){
  526. MSG_WARN(1,"Low power:%d", lcnt++);
  527. if(lcnt>=10){
  528. MSG_INFO(1, "Low power ,shut");
  529. sutApp.lowPwrMsg=1;
  530. appSleepCtl(ASLEEP_PWR, 1);
  531. }
  532. }else lcnt=0;
  533. }
  534. //读取充电/耳机接入状态 //不知道为啥是LSAPI_Device_ADC_CHANNEL_3,而不是LSAPI_Device_ADC_CHANNEL_1
  535. chargeVol=LSAPI_Device_AdcGetChannelVolt(LSAPI_Device_ADC_CHANNEL_3, LSAPI_Device_ADC_SCALE_3V233);
  536. if(chargeVol<=2000){//�,没在充电
  537. //tmpEar=0;
  538. sutApp.chargeStatus=0;
  539. }else{//正在充电
  540. //tmpEar=1;
  541. sutApp.chargeStatus=1;
  542. }
  543. }
  544. /*处理UI操作*/
  545. static void uiProcess(unsigned int exeInterval){
  546. static int cnt=0;
  547. if(getAppObjStatus(ASLEEP_PWR) != 0) return;//关机后,不切换菜单,只显示关机
  548. uiLoop(exeInterval);
  549. uiResponse(exeInterval);
  550. }
  551. /*触发关机操作*/
  552. static void pwrShutPro(void){
  553. static char shutFlag=0;
  554. if(getAppObjStatus(ASLEEP_PWR) == 0) return;
  555. lcdBackLightApi(1);
  556. msgAtSend("AT+CFUN=0\r\n");
  557. if(shutFlag==0){
  558. //显示关机界面
  559. if(sutApp.lowPwrMsg==0) guiShowMessageBox("正在关机");
  560. else guiShowMessageBox("低压关机");
  561. shutFlag=1;
  562. LSAPI_OSI_ThreadSleep(1000);
  563. guiShowBmp(0,0,"BYEBYE.bmp");
  564. LSAPI_OSI_ThreadSleep(1000);
  565. }
  566. MSG_INFO(1, "Normal PwrOff");
  567. //msgAtSend("AT+TRB=1\r\n");//normal power off 当前固件先不发模块关机指令,否则断电再上电有可能是起不来皿
  568. //LSAPI_OSI_ThreadSleep(1000);//一秒后释放电源锿防止软关机不成功
  569. lcdBackLightApi(0);
  570. MSG_INFO(1, "Release pwr");
  571. guiFillRect(0,0,GLCD_WIDTH-1,GLCD_HEIGHT-1,guiGetBackColor());//防止下次开机能看到残留
  572. msgAtSend("AT+CPOF\r\n");//软件关机模块
  573. LSAPI_OSI_ThreadSleep(100);
  574. CTL_POWER_HOLD(false);
  575. }
  576. static void NoteCheck(int interval){
  577. int dlyMs;
  578. if(sutApp.lowPwrWarn!=0){
  579. sutApp.lowPwrCnt += interval;
  580. if(sutPocStatus.spk==0 && sutPocStatus.mic==0){//对计状态下不播放请充电
  581. if(sutApp.lowPwrCnt>=WARN_TTS_INTERVAL){
  582. sutApp.lowPwrCnt=0;
  583. ttsPlay(ENCODE_USER_GBK, "C7EBB3E4B5E7");
  584. }
  585. }
  586. }
  587. }
  588. void AntModeRun(void){
  589. #ifdef ENABLE_ANT_MODE
  590. guiShowMessageBox("调天线模式");
  591. for(;;){
  592. LSAPI_OSI_ThreadSleep(2000);
  593. }
  594. #endif
  595. }
  596. void ShouHuProcess(int interva)
  597. {
  598. static char nRet=0;
  599. static char regcnt=0;
  600. //static int LastAtt_state=0;
  601. int tmepAtt_state=0;
  602. static int cnt=0;
  603. if(sutApp.gtMode==1||sutApp.cardStatus==0)return;
  604. if(++cnt<(1000/interva)) return;
  605. cnt=0;
  606. nRet=LSAPI_NET_GetGprsAttState(&tmepAtt_state);
  607. if(nRet!=0){
  608. MSG_WARN(1,"Get REG status failed");
  609. return;
  610. }
  611. if(tmepAtt_state!=1){
  612. //if(LastAtt_state!=tmepAtt_state)MSG_WARN(1,"REG off");
  613. if(regcnt==60){
  614. MSG_WARN(1,"!!!!CFUN=0");
  615. msgAtSend("AT+CFUN=0\r\n");
  616. }else if(regcnt>=61){
  617. MSG_WARN(1,"!!!!CFUN=1");
  618. msgAtSend("AT+CFUN=1\r\n");
  619. regcnt=0;
  620. }
  621. ++regcnt;
  622. }else {
  623. regcnt=0;
  624. }
  625. }
  626. void Ear_Judge(){
  627. LSAPI_HeadSetStatus_t status;
  628. status= LSAPI_Device_HeadSetGetStatus();//0628
  629. if(status == LSAPI_HEADSET_DISCONNECT)
  630. {
  631. MSG_INFO(1,"headset_disconnect");
  632. handsetStatusOutput(1);
  633. }
  634. else if(status == LSAPI_HEADSET_CONNECT)
  635. {
  636. MSG_INFO(1," headset_connect");
  637. handsetStatusOutput(0);
  638. }
  639. else
  640. {
  641. MSG_INFO(1,"unknow state");
  642. }
  643. }
  644. //30秒 无人呼叫自动退出单呼
  645. void AutoExitDanhu(int interva)
  646. {
  647. static int cnt=0;
  648. unsigned char buf[40];
  649. if(sutPocStatus.danHuStatus==0)return;
  650. if(sutPocStatus.mic||sutPocStatus.spk){
  651. cnt=0;
  652. return;
  653. }
  654. if(++cnt<(30*1000/interva)) return;
  655. cnt=0;
  656. snprintf(buf, sizeof(buf),"AT+POC=090000%08x\r\n",sutPocStatus.LocalGroup.ID);
  657. msgAtSend(buf);
  658. }
  659. #define APP_NEED_SLEEP OSI_MAKE_TAG('S', 'E', 'L', 'P')
  660. void ls_suspend(void *ctx, osiSuspendMode_t mode)
  661. {
  662. MSG_INFO(1,"\n\r ls_suspend mode:%d\n",mode);
  663. }
  664. void ls_resume(void *ctx, osiSuspendMode_t mode, uint32_t source)
  665. {
  666. MSG_INFO(1,"\n\r ls_resume mode:%d,source:%d\n",mode,source);
  667. }
  668. osiPmSourceOps_t sleep_ops =
  669. {
  670. ls_suspend,
  671. ls_resume,
  672. NULL,
  673. NULL
  674. };
  675. static void paProCtl(void);
  676. static void subTimerCtl(unsigned char sleep_or_not);
  677. static void configureVoiceParam(void);
  678. void SecProcess(int interva)
  679. {
  680. static int cnt=0;
  681. if(sutApp.gtMode!=0) return;
  682. if(++cnt<(5*1000/interva)) return; // 5秒拿一次GPS数据
  683. cnt=0;
  684. if(sutGpsInfo.g_GpsEnable)msgAtSend("AT+GPSRD=\"ALL\"\r\n");
  685. }
  686. void appRun(void){
  687. char cnt=0;
  688. char buf[20];
  689. LSAPI_OSI_Event_t event={0};
  690. osiPmSource_t*App_osiPmSource_t=NULL;
  691. App_osiPmSource_t=osiPmSourceCreate(APP_NEED_SLEEP, &sleep_ops, NULL);
  692. osiPmWakeLock(App_osiPmSource_t); //拿住资源不让系统休眠
  693. //等待lcd初始化完房
  694. MSG_INFO(1, "wait lcd init");
  695. while(sutApp.guiStatus==0){LSAPI_OSI_ThreadSleep(50);}//是否检测超时?
  696. AntModeRun();
  697. localAuthNow();
  698. //等待poc启动完成
  699. MSG_INFO(1, "lcd init done, wait poc start");
  700. while(sutApp.pocInitStatus==0){
  701. msgAtSend("ATE0\r\n");
  702. LSAPI_OSI_ThreadSleep(1000);
  703. }//是否检测超时?
  704. MSG_INFO(1, "app loop start");
  705. msgAtSend("AT+AUDCH=0,0\r\n");//此机型只使用主通道
  706. Ear_Judge();
  707. //设置一下TTS语音速度
  708. msgAtSend("AT+LSHTTSPARAM=3000,106,100\r\n");//设置TTS参数
  709. msgAtSend("ATI\r\n");//查询模块版本
  710. msgAtSend("AT+SIMCROSS?\r\n");
  711. LSAPI_OSI_ThreadSleep(1000);
  712. msgAtSend("AT+POC=2500000150\r\n"); //tone音量
  713. msgAtSend("AT+POC=4500000064\r\n"); //对讲音量
  714. #ifdef CONFIG_AUDIO_AFTER_INIT
  715. configureVoiceParam();
  716. #else
  717. for(cnt=0;cnt<5;cnt++){
  718. configureVoiceParam();
  719. LSAPI_OSI_ThreadSleep(100);
  720. sutApp.audioReconfig=2;
  721. msgAtSend("AT+CACCP=0,0,1,\"\"\r\n");//检测mic是否被mute掉了
  722. LSAPI_OSI_ThreadSleep(200);
  723. if(sutApp.audioReconfig==0) break;
  724. }
  725. #endif
  726. adcRead(APP_SUB_DIV_TIME);//在开机播放前设置下SPK
  727. splVolumeSet(newPara.spkVol*10);//更新音量
  728. backLightReset();
  729. if(newPara.ttsMessage[0]!=0){
  730. if(newPara.ttsCodeType==0){
  731. ttsPlay(ENCODE_USER_UNICODE_BE, newPara.ttsMessage);
  732. }else if(newPara.ttsCodeType==1) ttsPlay(ENCODE_USER_GBK, newPara.ttsMessage);
  733. else MSG_INFO(1, "ttsCodeType:%d not support", newPara.ttsCodeType);
  734. }else MSG_INFO(1, "tts null");
  735. //检测卡是否存在
  736. while(sutApp.cardStatus==0){
  737. msgAtSend("AT+CPIN?\r\n");
  738. LSAPI_OSI_ThreadSleep(1000);
  739. if(++cnt>=10){
  740. MSG_INFO(1, "Check card timeout");
  741. break;
  742. }
  743. }
  744. msgAtSend("AT+POC=000000010101\r\n");
  745. pwrModeSetCmd(newPara.pwrMode);//心跳间隔 ZZD_PWRMODE
  746. ModemSetZZDPocPara();
  747. snprintf(buf,sizeof(buf),"AT+POC=3000%02d01\r\n",newPara.Poc_sound+1);
  748. msgAtSend(buf);
  749. //BLE_Open();//d 打开蓝牙
  750. osiPmWakeUnlock(App_osiPmSource_t);
  751. for(;;){
  752. #ifdef CONFIG_AUDIO_AFTER_INIT
  753. audioParaCheck();
  754. #endif
  755. volUpdateNeed();
  756. ledsProCtl();
  757. adcRead(APP_SUB_DIV_TIME);
  758. uiProcess(APP_SUB_DIV_TIME);
  759. AutoExitDanhu(APP_SUB_DIV_TIME);
  760. ShouHuProcess(APP_SUB_DIV_TIME);
  761. pocProCtl(APP_SUB_DIV_TIME);
  762. NoteCheck(APP_SUB_DIV_TIME);
  763. //uiTimeOutToStandby(0, APP_SUB_DIV_TIME);
  764. HookGroupUserInfo();
  765. HookVolToutCheck();
  766. SecProcess(APP_SUB_DIV_TIME);
  767. Ble_handler(APP_SUB_DIV_TIME);
  768. Xinbiao_handler(APP_SUB_DIV_TIME);
  769. GpsInternalChange(APP_SUB_DIV_TIME);
  770. //IncomingSMS();
  771. LogoutOutTimeCheck(APP_SUB_DIV_TIME);
  772. if(isSleepReady()==0) LSAPI_OSI_ThreadSleep(APP_TASK_SLEEP_TIME);
  773. else if(sutApp.gtMode==0){//正常模式下可以休眿
  774. MSG_WARN(1, "APP SLEEP");
  775. // uiTimeOutToStandby(1, APP_SUB_DIV_TIME);
  776. stopKeyTimer();
  777. subTimerCtl(1);//切换为休眠状态定时器
  778. sutApp.appStatus=1;
  779. redLedCtl(false);//休眠后保证灯没亮,否则有可能灯亮10ms,按理10ms后灯能灭,然后10ms时休眠了,应用就短时间内不会灭灯
  780. greenLedCtl(false);//休眠后保证灯没亮
  781. sutApp.updateStatusBar=1;
  782. LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);
  783. LSAPI_OSI_ThreadSleep(150);//添加这个后,休眠时按键或被呼叫或本机呼叫,tone音能是完整的
  784. lcdDrv_Init(1);//深度休眠唤醒后重新初始化SPI-LCD
  785. if(sutApp.lcdDlyLightUp){
  786. sutApp.lcdDlyLightUp=0;
  787. lcdBackLightApi(1);
  788. }
  789. sutApp.forceUiFlash=1;
  790. sutApp.appStatus=0;
  791. subTimerCtl(0);//切换为唤醒状态定时器
  792. MSG_WARN(1, "APP WAKEUP");
  793. }
  794. //检测是否关机,这里要放在唤醒后操作
  795. pwrShutPro();
  796. }
  797. }
  798. unsigned int subTimerInterval=100;//定时器定时的时间
  799. LSAPI_OSI_Timer_t *pSubtimer_t = NULL;
  800. /*
  801. 为了做低功耗,此定时器在休眠时,设置为长时间定旿
  802. 非休眠时,设置为短时间定旿
  803. sleep_or_not:0 未休眠, else 休眠
  804. */
  805. static void subTimerCtl(unsigned char sleep_or_not){
  806. if(NULL==pSubtimer_t){
  807. MSG_WARN(1, "subTimer null");
  808. return;
  809. }
  810. LSAPI_OSI_TimerStop(pSubtimer_t);
  811. //打开定时噿
  812. if(sleep_or_not==0) subTimerInterval=100;//未休眠时_00ms
  813. else subTimerInterval=5000;//休眠旿5000ms
  814. LSAPI_OSI_TimerStart(pSubtimer_t,subTimerInterval);
  815. }
  816. static void subTimeroutcallback(void *param){
  817. unsigned int *dlyTime=(unsigned int *)param;
  818. //处理灯的显示
  819. uioProctl(*dlyTime);
  820. //控制功放的关闿
  821. paProCtl();
  822. if(NULL!=pSubtimer_t) LSAPI_OSI_TimerStart(pSubtimer_t,subTimerInterval);
  823. }
  824. void subTask(void *param){
  825. LSAPI_OSI_Event_t event={0};
  826. if(NULL==pSubtimer_t) pSubtimer_t = LSAPI_OSI_TimerCreate(LSAPI_OSI_ThreadCurrent(), subTimeroutcallback, (void *)&subTimerInterval);
  827. if(NULL==pSubtimer_t) MSG_WARN(1,"sub timer init failed");
  828. else LSAPI_OSI_TimerStart(pSubtimer_t,subTimerInterval);
  829. for(;;){LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);}
  830. }
  831. static void paProCtl(void){
  832. //会被定时调用
  833. static char PaDlyCnt=0;
  834. if(sutPocStatus.PaDlyStart==1){
  835. if(++PaDlyCnt<30)return; //3
  836. }
  837. if(sutPocStatus.TTS!=0) return;
  838. if(sutPocStatus.spk!=0) return;
  839. if(sutPocStatus.TONE!=0) return;
  840. if(sutPocStatus.beep!=0) return;
  841. if(sutApp.gtMode!=0) return;
  842. PaDlyCnt=0;
  843. sutPocStatus.PaDlyStart=0;
  844. paControl(false);
  845. //MSG_INFO(1,"spk off");
  846. }
  847. void tryWakeupApp(void){
  848. if(sutApp.appStatus!=0){
  849. if(mainThreadPtr!=NULL){
  850. threadSendEvent(mainThreadPtr,OHPOC_EVENT_MAIN,NULL,NULL,NULL);
  851. }
  852. }
  853. }
  854. void ttsPlay(ENCODE_USER_ENUM type, char *tts){
  855. char buf[120];
  856. MSG_INFO(1, "tts Play:%d,%s",type,tts);
  857. //sutPocStatus.TTS=1;
  858. paControl(true);
  859. snprintf(buf, sizeof(buf), "AT+POC=770000%02d%s\r\n", type,tts);
  860. msgAtSend(buf);
  861. }
  862. /*背光时间到,熄灭*/
  863. void backLightCb(void *param){
  864. if(sutPocStatus.firstLogin==0) return;//未登录过,不灭屏
  865. if(newPara.lcdParaList[newPara.lcdParaDefaultIndex]==0) return;//常亮
  866. lcdBackLightApi(0);
  867. appSleepCtl(ASLEEP_LCD, 0);//可以休眠
  868. }
  869. /*点亮背光*/
  870. void backLightReset(void){
  871. unsigned short tmp;
  872. appSleepCtl(ASLEEP_LCD, 1);//不让休眠
  873. tmp=newPara.lcdParaList[newPara.lcdParaDefaultIndex];
  874. if(sutApp.appStatus==0) lcdBackLightApi(1);//未休眠时,直接点亮
  875. else sutApp.lcdDlyLightUp=1;//休眠时不马上亮亮,会在LCD初始化完后点亮
  876. startBackLightTimer(tmp*1000);
  877. }
  878. void sysPwrLock(void){
  879. sutApp.pwrLock=1;
  880. }
  881. void sysPwrRlease(void){
  882. sutApp.pwrLock=0;
  883. }
  884. //"3132" --> 0x31,0x32
  885. void StrAsciiToHex(char *src, unsigned char *des){
  886. unsigned char temp[2],i;
  887. if(strlen(src)%2) return;
  888. while(0!=*src)
  889. {
  890. for(i=0;i<2;i++)
  891. {
  892. temp[i] = *src++;
  893. if(temp[i] >= '0' && temp[i] <= '9') temp[i] -= 0x30;
  894. else if(temp[i] >= 'A' && temp[i] <= 'F') temp[i] -= 0x37;
  895. else temp[i] -= 0x57;
  896. }
  897. temp[0] <<= 4;
  898. temp[0] &= 0xf0;
  899. *des++=temp[0]|temp[1];
  900. }
  901. *des=0;
  902. }
  903. void splVolumeSet(unsigned char level){
  904. char info[30];
  905. snprintf(info, sizeof(info), "AT+CLVL=%d\r\nAT+CRSL=%d\r\n", level,level);
  906. msgAtSend(info);
  907. MSG_INFO(1,"SPK_VOL:%d",level);
  908. }
  909. const unsigned char spkGainTable[SPK_GAIN_NUM];
  910. const unsigned char spkGainTable[SPK_GAIN_NUM]={
  911. 24,32,40,48,56,64,72,80
  912. };
  913. /*调节音量,刷新音量进度条*/
  914. void volAdjAction(char direction,unsigned char UIStatus){
  915. const unsigned char spkVolTable[MAX_SPK_VOL+1]={0,10,20,30,40,50,60,70,80,90,100};//不接耳机时喇叭音
  916. unsigned char vol;
  917. if(sutApp.earLev==0){//不接耳机
  918. if(direction==0){
  919. if(newPara.spkVol<MAX_SPK_VOL) newPara.spkVol++;
  920. else goto FLASH;
  921. }else{
  922. if(newPara.spkVol>0) newPara.spkVol--;
  923. else goto FLASH;
  924. }
  925. vol=spkVolTable[newPara.spkVol];
  926. splVolumeSet(vol);
  927. }else{//接了耳机
  928. if(direction==0){
  929. if(newPara.spkGain<SPK_GAIN_NUM) newPara.spkGain++;
  930. else goto FLASH;
  931. }else{
  932. if(newPara.spkGain>0) newPara.spkGain--;
  933. else goto FLASH;
  934. }
  935. if(newPara.spkGain==0) vol=0;
  936. else vol=spkGainTable[newPara.spkGain-1];
  937. splVolumeSet(vol);
  938. vol=newPara.spkGain;
  939. }
  940. sysIniSave("adjvol");
  941. //刷新进度条
  942. FLASH:
  943. if(sutApp.earLev==0) vol=newPara.spkVol;
  944. else vol=newPara.spkGain;
  945. if(UIS_STANDBY==UIStatus)
  946. volUiFlash(vol);
  947. }
  948. void volUpdateNeed(void){
  949. if(sutApp.voluemUpdate==0) return;
  950. if(sutApp.voluemUpdate==1) volAdjAction(0, sutUIstatus.Status);
  951. else if(sutApp.voluemUpdate==2) volAdjAction(1, sutUIstatus.Status);
  952. sutApp.voluemUpdate=0;
  953. }
  954. void VolSpkUpdate(void){
  955. char cmd[30];
  956. unsigned char volLev;
  957. if(sutApp.earLev==0){//耳机拔掉后,恢复正常的SPK增益
  958. volLev=newPara.spkVol*10;
  959. }else{//耳机接入,应用特定值
  960. if(newPara.spkGain>=SPK_GAIN_NUM) volLev=SPK_GAIN_DEFAULT;
  961. else volLev=newPara.spkGain;
  962. if(volLev>0) volLev=spkGainTable[newPara.spkGain-1];
  963. }
  964. splVolumeSet(volLev);
  965. }
  966. //对都使用主音频通道设计来说,耳机模式时,需要按比例降低输入输出增益
  967. const unsigned short micGainTable[MIC_GAIN_NUM][2]={
  968. {2,6},{2,10},{3,10},{4,10},{5,10},{6,10},{6,13}
  969. };
  970. void VolMicUpdate(void){
  971. #if 1
  972. char cmd[50];
  973. unsigned char hana,lana,hadc,ladc;
  974. if(sutApp.earLev==0){//耳机拔掉,恢复正常MIC增益
  975. hana=sutApp.mic_ana>>8;
  976. lana=sutApp.mic_ana;
  977. hadc=sutApp.mic_adc>>8;
  978. ladc=sutApp.mic_adc;
  979. }else{//耳机接入
  980. hana=micGainTable[newPara.micGain][0]>>8;
  981. lana=micGainTable[newPara.micGain][0];
  982. hadc=micGainTable[newPara.micGain][1]>>8;
  983. ladc=micGainTable[newPara.micGain][1];
  984. }
  985. snprintf(cmd, sizeof(cmd), "AT+CACCP=0,0,0,\"%02x%02x%02x%02x\"\r\n",lana,hana,ladc,hadc);
  986. msgAtSend(cmd);
  987. #else
  988. unsigned char tableIndex;
  989. char cmd[50];
  990. int vol=newPara.spkVol*10;
  991. splVolumeSet(vol);
  992. if(sutApp.earLev==0){//耳机拔掉,恢复正常MIC增益
  993. tableIndex=newPara.micGain_onspk;
  994. //msgAtSend("AT+CACCP=0,0,0,\"04000a00\"\r\n");
  995. }else{//耳机接入
  996. tableIndex=newPara.micGain_onear;
  997. //msgAtSend("AT+CACCP=0,0,0,\"02000f00\"\r\n");
  998. }
  999. if(tableIndex>=MIC_GAIN_NUM){
  1000. MSG_WARN(1, "Index invalid:%d", tableIndex);
  1001. return;
  1002. }
  1003. snprintf(cmd, sizeof(cmd), "AT+CACCP=0,0,0,\"%02x00%02x00\"\r\n", micGainTable[tableIndex][0],micGainTable[tableIndex][1]);
  1004. msgAtSend(cmd);
  1005. #endif
  1006. }
  1007. //开机配置设定好的模块音频参数文件
  1008. #define READ_PER_SIZE 400 //每次从Bin文件读取最多400字节来发送,AT时长度翻倍
  1009. static void configureVoiceParam(void){
  1010. //const char *confiFile="ZT-MINI101HGS.bin";
  1011. const char *confiFile="ZT-MINI201-202HGS-20210703.bin";
  1012. unsigned char sendbuf[40+2*400];//AT+CAIET=0,0,9600,400,""
  1013. unsigned char *dataPtr=sendbuf+sizeof(sendbuf)-READ_PER_SIZE;
  1014. char buf[3];
  1015. char status=0;
  1016. int fd,offset,readsize,i;
  1017. LSAPI_FS_Stat_info_t pBuf;
  1018. MSG_INFO(1, "config audio file'%s'",confiFile);
  1019. fd=LSAPI_FS_Open(confiFile, LSAPI_FS_O_RDONLY,0x0);
  1020. if(fd>0){
  1021. memset(&pBuf,0,sizeof(pBuf));
  1022. LSAPI_FS_Fstat(fd,&pBuf);
  1023. offset=0;
  1024. LSAPI_FS_Seek(fd, offset, LSAPI_FS_SEEK_SET);
  1025. while(offset<pBuf.st_size){
  1026. readsize=pBuf.st_size-offset;
  1027. if(readsize>400) readsize=400;
  1028. readsize=LSAPI_FS_Read(fd, dataPtr, readsize);
  1029. if(readsize==0) break;
  1030. else if(readsize<0){
  1031. status=1;
  1032. break;
  1033. }
  1034. sprintf(sendbuf, "AT+CAIET=0,0,%d,%d,\"", offset, readsize);
  1035. for(i=0;i<readsize;i++){
  1036. sprintf(buf, "%02x", dataPtr[i]);
  1037. strcat(sendbuf, buf);
  1038. }
  1039. strcat(sendbuf,"\"\r\n");
  1040. msgAtSend(sendbuf);
  1041. offset += readsize;
  1042. LSAPI_OSI_ThreadSleep(10);
  1043. }
  1044. LSAPI_FS_Close(fd);
  1045. if(status==0) MSG_INFO(1, "config audio file succ:%d",offset);
  1046. else MSG_ERR(1, "config audio failed %d",status);
  1047. }else MSG_ERR(1, "'%s' open failed",confiFile);
  1048. if(status==0){//配置成功后,回读一下默认的Mic,这个值在不接耳机时是固定值
  1049. LSAPI_OSI_ThreadSleep(50);
  1050. msgAtSend("AT+CACCP=0,0,1,\"\"\r\n");
  1051. LSAPI_OSI_ThreadSleep(50);
  1052. }else{
  1053. //如果配置失败了,直接使用默认值
  1054. sutApp.mic_ana=4;
  1055. sutApp.mic_adc=4;//12;
  1056. }
  1057. VolMicUpdate();
  1058. }
  1059. //+CACCP:
  1060. //+CACCP: "04000C00" ana=0x0004 adc=0x000c
  1061. void proCaccpMsg(char *msg){
  1062. char tmp[10],*pName;
  1063. char i=0,j=0;
  1064. if(msg[0]=='"'){
  1065. memcpy(tmp+j, msg+7,2);j += 2;
  1066. memcpy(tmp+j, msg+5,2);j += 2;
  1067. memcpy(tmp+j, msg+3,2);j += 2;
  1068. memcpy(tmp+j, msg+1,2);j += 2;
  1069. tmp[j]=0;//000C0004
  1070. sutApp.mic_ana=strtol(tmp+4, &pName,16);
  1071. tmp[4]=0;
  1072. sutApp.mic_adc=strtol(tmp, &pName,16);
  1073. }
  1074. }
  1075. void audioParaCheck(void){
  1076. if(sutApp.audioReconfig==0) return;
  1077. sutApp.audioReconfig=0;
  1078. configureVoiceParam();
  1079. }