123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143 |
- #include "includes.h"
- #include "lsapi_tts.h"
- //17903920
- //219782401
- #define APP_IDLE_TIME 3 //如果POC已休眿APP没有操作一定秒数后休眠
- int keyNum=0;
- APP_DEF sutApp;
- static void KeyToneDly();
- static void appDataInit(void){
- memset((unsigned char *)&sutApp, 0, sizeof(APP_DEF));
- sutApp.pcant=4;
- sutApp.enableKey=1;
- //appSleepCtl(ASLEEP_POC, 1);
- appSleepCtl(ASLEEP_LCD, 1);
- readInfoNow();
- sysIniRead();
- }
- void dataInit(void){
- appDataInit();
- pocDataInit();
- gpsDataInit();
- uiDataInit();
- }
- static void ledsProCtl(void){
- if(sutApp.gtMode!=0) return;
- if(0==sutPocStatus.logined) uioStatusSet(UIO_INDOFFLINE);
- else if(sutPocStatus.spk>0)uioStatusSet(UIO_INDRX);
- else if(sutPocStatus.mic>0 )uioStatusSet(UIO_INDTX);
- else uioStatusSet(UIO_INDONLINE);
- }
- static void adcRead(unsigned int interval);
- char isKeyPress(void){
- if(keyNum) return keyNum--;
- else return 0;
- }
- /*APP休眠处理接口
- ctlType, 操作对象
- status,操作值,0 清除 else 设置
- */
- void appSleepCtl(ASLEEP_ENUM ctlType, char status){
- if(status==0) sutApp.appSleepStatus &= ~(1<<ctlType);
- else sutApp.appSleepStatus |= 1<<ctlType;
- }
- /*APP休眠状态接叿*/
- char isAppSleepReady(void){
- if(sutApp.appSleepStatus==0) return 1;
- else return 0;
- }
- /*获取指定休眠控制成员锁定的状怿
- 0 未锁宿否则锁定,锁定即可以休眠
- */
- char getAppObjStatus(ASLEEP_ENUM ctlType){
- if(sutApp.appSleepStatus & (1<<ctlType)) return 1;
- else return 0;
- }
- /*检测是否APP可以休眠操作*/
- char isSleepReady(void){
- static unsigned int idleCnt=0;
- #ifdef DISABLE_SLEEP
- return 0;//不休眿
- #endif
- if(isAppSleepReady()==0){
- idleCnt=0;
- return 0;
- }
-
- if(++idleCnt>=(APP_IDLE_TIME*1000/APP_SUB_DIV_TIME)){
- idleCnt=0;
- return 1;
- }else return 0;
- }
- void usbCmdHandler(const char *data,unsigned int length){
- static char buf[256];
- static int len=0;
- static char lach;
- char ch;
- int i;
- if(sutApp.authReady==0){
- authRecvPro(data, length);
- return;
- }
-
- for(i=0;i<length;i++){
- ch=data[i];
- if(len<sizeof(buf)-1) buf[len++]=ch;
- else{
- len=0;
- buf[len++]=ch;
- }
- if(lach=='\r' && ch=='\n'){
- buf[len]=0;
- cmdSetting(buf);
- len=0;
- }
- lach=ch;
- }
- }
- static char micPttPressed=0;
- static char pttPressed=0;
- static void pttHandler(char type, char ctl){
- char needSend=0;
- char mic_spk;
- if(type==0){//ptt
- if(ctl==0){//放开
- if(micPttPressed==0){
- needSend=1;mic_spk=0;
- }
- pttPressed=0;
- }else{//按下
- if(pttPressed==0 && micPttPressed==0){
- needSend=1;mic_spk=1;
- }
- pttPressed=1;
- }
- }else{//mic ptt
- if(ctl==0){//放开
- if(pttPressed==0){
- needSend=1;mic_spk=0;
- }
- micPttPressed=0;
- }else{//按下
- if(pttPressed==0 && micPttPressed==0){
- needSend=1;mic_spk=1;
- }
- micPttPressed=1;
- }
- }
- if(needSend!=0){
- if(mic_spk==0) {
- #ifndef USE_BND_POC
- msgAtSend("AT+POC=0C0000\r\n");
- #else
- broad_speak(0);
- #endif
- }
- else {
- #ifndef USE_BND_POC
- msgAtSend("AT+POC=0B0000\r\n");
- #else
- broad_speak(1);
- #endif
- }
- }
- }
- /*打印键信恿*/
- const char freeSeg[]="Free";
- const char pressSeg[]="Press";
- void showKeyMessage(unsigned short key,unsigned char status){
- char buf[50]="[Key_";
- switch(key){
- case MKEY_VALUE_F2: strcat(buf, "F2]");break;
- case MKEY_VALUE_F1: strcat(buf, "F1]");break;
- case MKEY_VALUE_PTT: strcat(buf, "PTT]");break;
- case MKEY_VALUE_MENU: strcat(buf, "MENU]");break;
- case MKEY_VALUE_UP: strcat(buf, "UP]");break;
- case MKEY_VALUE_DOWN: strcat(buf, "DOWN]");break;
- case MKEY_VALUE_ESC: strcat(buf, "ESC]");break;
- case MKEY_VALUE_PWR: strcat(buf, "PWR]");break;
- case MKEY_VALUE_CB_GT: strcat(buf, "CB_GT]");break;
- case MKEY_VALUE_CB_IP: strcat(buf, "CB_IP]");break;
- case MKEY_VALUE_MIC_PTT: strcat(buf, "MIC_PTT]");break;
- default:return;
- }
- if(status==0) strcat(buf, freeSeg);
- else strcat(buf, pressSeg);
- MSG_INFO(1,buf);
- }
- unsigned char keyInArow=0;
- void keyCheck(unsigned short keyStatus){
- static unsigned short lkey=0;
- static unsigned char keyCtl=0,keyCnt=0;
- unsigned char keyType,needSendKey=0;
- if(keyStatus==KS_ALL_IDLE){
- keyType=0;
- if(keyCtl==1){
- keyCtl=0;
- needSendKey=1;
- }
- }else{
- keyType=1;
- if(lkey != keyStatus) keyCtl=0;//值变匿
- if(keyCtl==0){
- lkey=keyStatus;
- keyCtl=1;
- keyCnt=0;
- needSendKey=1;
- }else if(keyInArow!=0){//是否输出持续倿
- if(++keyCnt>=(1000/KEY_TIMER_TICK)){//每秒产生持续倿
- keyCnt=0;
- needSendKey=1;
- }
- }
- }
-
- if(needSendKey){
- if(sutApp.enableKey!=0)//延时期间不检测按锿
- keySendEvent(lkey,keyType);
- }
- }
- bool lcdBackLightStatus=false;
- void pwrDetRead(char type){
- static char cnt=0;
- if(type==0){
- cnt++;
- if(cnt==3)uISetNextStatus(UIS_MENU_SHUT_PWR);
- }else{
- cnt=0;
- }
-
- if(sutUIstatus.Status == UIS_MENU_SHUT_PWR) return;//关机界面不处理
- if(type==0) return;//
- //处理按顶部键切换UI
- uiTimeOutToStandby(1,APP_SUB_DIV_TIME);
- //处理按顶部键切换背光
- if(sutUIstatus.Status != UIS_STANDBY) return;//待机页面时才反转背光
-
- if(lcdBackLightStatus==false) backLightReset();
- else lcdBackLightApi(0);//熄屏
- }
- void lcdBackLightApi(char value){
- CTL_LCD_BL(value);
- if(value==0) lcdBackLightStatus=false;
- else lcdBackLightStatus=true;
- }
- static void lockProcess(void){
- if(sutApp.keyLock==0){
- sutApp.keyLock=1;
- appSleepCtl(ASLEEP_GGROUP, 0);
- appSleepCtl(ASLEEP_GUSER, 0);
- uISetNextStatus(UIS_STANDBY);
- }else{
- sutApp.keyLock=0;
- sutApp.lockShow=0;
- }
- }
- void keyToneStart(void){
- if(newPara.KeySound==0) return;
- sutPocStatus.beep=1;
- paControl(true);
- if(ToneThreadPtr!=NULL)threadSendEvent(ToneThreadPtr,OHPOC_EVENT_MAIN,NULL,NULL,NULL);//0702
- }
- void quickUiSwitch(int uistatus){
- uISetNextStatus(uistatus);
- getStackStruct()->FastUiChange=1;
- }
- /*进入GT模式*/
- static void enterGTMode(void){
- #ifndef ENABLE_PWM_BEEP
- msgAtSend("AT+TONES=1\r\n");
- #endif
- sutApp.gtMode=1;
- uioStatusSet(UIO_INDGT);
- paControl(true);//GT下常开喇叭
- #ifdef ENABLE_PWM_BEEP
- pwmBeepStart(868,50);
- LSAPI_OSI_ThreadSleep(100);
- pwmBeepStart(500,50);
- LSAPI_OSI_ThreadSleep(100);
- pwmBeepStart(868,50);
- #else
- msgAtSend("AT+TONE\r\n");
- LSAPI_OSI_ThreadSleep(200);
- msgAtSend("AT+TONE\r\n");
- #endif
- MSG_WARN(1, "Enter GT Mode");
- }
- void micPttHandler(char status){
- keySendEvent(MKEY_VALUE_MIC_PTT,status);
- }
- #define MKEY_VALUE_F2 (1<<MKEY_VALUE_7)
- #define MKEY_VALUE_F1 (1<<MKEY_VALUE_5)
- #define MKEY_VALUE_PTT (1<<MKEY_VALUE_1)
- #define MKEY_VALUE_MENU (1<<MKEY_VALUE_2)
- #define MKEY_VALUE_UP (1<<MKEY_VALUE_3)
- #define MKEY_VALUE_DOWN (1<<MKEY_VALUE_6)
- #define MKEY_VALUE_ESC (1<<MKEY_VALUE_4)
- #define MKEY_VALUE_PWR (1<<MKEY_VALUE_8)
- void ResetKeyValue(unsigned char *value){
-
- if(*value==1){
- *value=0;
- pttHandler(1,0);
- }
- }
- void keyHandler(unsigned short key,unsigned char status){//普通按键值处琿
- static unsigned char gtModeCnt=0;
- static unsigned char lockCnt=0;
- static unsigned char Once_PTT=0;
- char str[20]={0};
-
- if(sutApp.keyLock!=0 && MKEY_VALUE_ESC!=key&&MKEY_VALUE_MIC_PTT!=key&&MKEY_VALUE_PTT!=key){
- sutApp.lockShow=1;
- return;
- }
- showKeyMessage(key,status);
-
- // if(key&MKEY_VALUE_MIC_PTT||key&MKEY_VALUE_MIC_PTT)return;
- if(status==0){//key free
- switch(key){
- case MKEY_VALUE_MIC_PTT:
- pttHandler(0,0);
- break;
- case MKEY_VALUE_PTT:
- Once_PTT=0;
- pttHandler(1,0);
- break;
- case MKEY_VALUE_PWR:
- pwrDetRead(1);
- break;
- case MKEY_VALUE_ESC:
- // MSG_INFO(1,"BND -palat===%s",str);
- lockCnt=0;
- break;
-
- // case MKEY_VALUE_UP:
- // if(sutUIstatus.Status!=UIS_MENU_SYS_SERVERPASS) sutApp.voluemUpdate=1;
- // break;
- // case MKEY_VALUE_DOWN:
- // if(sutUIstatus.Status!=UIS_MENU_SYS_SERVERPASS) sutApp.voluemUpdate=2;
- // break;
- case MKEY_VALUE_F2:
- if(sutApp.key_f2_cnt==1) quickUiSwitch(UIS_MENU_USER_SEL);
- sutApp.key_f2_cnt=0;
- break;
- case MKEY_VALUE_CB_GT:
- gtModeCnt=0;
- break;
-
- default:
- MSG_INFO(1,"ResetKeyValue-----%08X-",key);
- ResetKeyValue(&Once_PTT);//HYL
- break;
- }
- sutApp.timeOutCnt=0;
- keyInArow=0;
- appSleepCtl(ASLEEP_MKEY, 0);
-
- }else{//key press
- if(key!=MKEY_VALUE_PTT&& key!=MKEY_VALUE_MIC_PTT && key!=MKEY_VALUE_CB_GT ) keyToneStart();
-
- if(MKEY_VALUE_PWR != key) backLightReset();
- appSleepCtl(ASLEEP_MKEY, 1);
- keyNum++;
- switch(key){
- case MKEY_VALUE_MIC_PTT:
- pttHandler(0,1);
- break;
- case MKEY_VALUE_PTT:
- Once_PTT=1;
- pttHandler(1,1);
- break;
- case MKEY_VALUE_PWR:
- keyInArow=1;
- pwrDetRead(0);
- break;
- case MKEY_VALUE_ESC:
-
- keyInArow=1;
- if(++lockCnt==3) lockProcess();
- break;
- case MKEY_VALUE_F1:
- quickUiSwitch(UIS_MENU_GROUP_SEL);
- break;
- case MKEY_VALUE_F2:
- keyInArow=1;
- if(++sutApp.key_f2_cnt==3) quickUiSwitch(UIS_MENU_SYS_SIM);
- break;
- case MKEY_VALUE_CB_GT:
- keyInArow=1;
- if(++gtModeCnt==3){
- if(sutApp.gtMode==0){
- enterGTMode();
- }
- }
- break;
- case MKEY_VALUE_CB_IP:
- keyInArow=1;
- break;
- case MKEY_VALUE_MENU:
- case MKEY_VALUE_UP:
- case MKEY_VALUE_DOWN:
- break;
- default:
-
- break;
- }
- }
- }
- /////////////////////////////事件发送接叿//////////////////////////
- void threadSendEvent(LSAPI_OSI_Thread_t *threadID, unsigned int id, unsigned int param1,unsigned int param2,unsigned int param3){
- LSAPI_OSI_Event_t pEventSend;
- pEventSend.id=id;
- pEventSend.param1=param1;
- pEventSend.param2=param2;
- pEventSend.param3=param3;
- osiEventTrySend(threadID,&pEventSend,0);
- }
- //////////////////////////////其它处理接口//////////////////////////
- static void adcRead(unsigned int interval){
- static unsigned int siVbat=0,laSiVbat;
- static unsigned char MIC_ptt=0;
- static unsigned char LastMIC_ptt=0;
- static unsigned short cnt=0,lcnt=0;
- unsigned int adcValueTmp;
-
- if(++cnt<(1000/interval)) return;//1秒读一次ADC即可
- cnt=0;
-
- LSAPI_SYS_BattGetVol(&adcValueTmp);
- //MSG_WARN(1,"Low power:%d mv",adcValueTmp/10 );
- if(sutApp.g_iBAT<=MIN_PWR_LEVEL){
- MSG_WARN(1,"Low power:%d", lcnt++);
- if(lcnt>=10){
- MSG_INFO(1, "Low power ,shut");
- sutApp.lowPwrMsg=1;
- appSleepCtl(ASLEEP_PWR, 1);
- }
- }else lcnt=0;
- sutApp.g_iBAT=adcValueTmp/10;
- if(sutApp.g_iBAT != laSiVbat){
- laSiVbat=sutApp.g_iBAT;
- }
- /**********************应用播放TONE2秒后关闭喇叭************************************/
- KeyToneDly();
-
- }
- /*处理UI操作*/
- static void uiProcess(unsigned int exeInterval){
- if(getAppObjStatus(ASLEEP_PWR) != 0) return;//关机后,不切换菜单,只显示关机页靿
- uiLoop(exeInterval);
- uiResponse(exeInterval);
- }
- /*触发关机操作*/
- static void pwrShutPro(void){
- static char shutFlag=0;
- if(getAppObjStatus(ASLEEP_PWR) == 0) return;
- //CTL_LCD_BL(1);
- lcdBackLightApi(1);
- msgAtSend("AT+POC=050000\r\n");
- msgAtSend("AT+CFUN=0\r\n");
- if(shutFlag==0){
- //显示关机界面
- if(sutApp.lowPwrMsg==0) guiShowMessageBox("正在关机");
- else guiShowMessageBox("低压关机");
- shutFlag=1;
- LSAPI_OSI_ThreadSleep(1000);
- }
-
- MSG_INFO(1, "Normal PwrOff");
- //msgAtSend("AT+TRB=1\r\n");//normal power off 当前固件先不发模块关机指令,否则断电再上电有可能是起不来皿
- //LSAPI_OSI_ThreadSleep(1000);//一秒后释放电源锿防止软关机不成功
- CTL_LCD_BL(0);
- MSG_INFO(1, "Release pwr");
- guiFillRect(0,0,GLCD_WIDTH-1,GLCD_HEIGHT-1,guiGetBackColor());//防止下次开机能看到残留
- CTL_POWER_HOLD(0);
- msgAtSend("AT+CPOF\r\n");//软件关机模块
- LSAPI_OSI_ThreadSleep(100);
- }
- static void NoteCheck(int interval){
- const char *LOWPOWERNOTE="\xE8\xAF\xB7\xE5\x85\x85\xE7\x94\xB5";
- if(sutApp.lowPwrWarn!=0){
- sutApp.lowPwrCnt += interval;
-
- if(sutApp.lowPwrCnt>=WARN_TTS_INTERVAL){
- sutApp.lowPwrCnt=0;
- //ttsPlay(ENCODE_USER_GBK, "C7EBB3E4B5E7");
- broad_play_tts(LOWPOWERNOTE,true);
- }
- }
-
- }
- void AntModeRun(void){
- #ifdef ENABLE_ANT_MODE
- guiShowMessageBox("调天线模式");
- for(;;){
- LSAPI_OSI_ThreadSleep(2000);
- }
- #endif
- }
- void Ear_Judge(){
- LSAPI_HeadSetStatus_t status;
- status= LSAPI_Device_HeadSetGetStatus();//0628
-
- if(status == LSAPI_HEADSET_DISCONNECT)
- {
- MSG_INFO(1,"headset_disconnect");
- handsetStatusOutput(1);
- }
- else if(status == LSAPI_HEADSET_CONNECT)
- {
- MSG_INFO(1," headset_connect");
- handsetStatusOutput(0);
- }
- else
- {
- MSG_INFO(1,"unknow state");
- }
- }
- void APP_ls_PdpActive(){
- LSAPI_OSI_Event_t event = {0};
- unsigned res = 0;
- uint8_t nState = 1;
- uint8_t nCid = 1;
- uint8_t nSim = 0;
- res = LSAPI_NET_GprsAct(nState, nCid, nSim, &event);
- MSG_INFO(1,"LSAPI_NET_GprsAct event.id(%d)", event.id);
- MSG_INFO(1,"LSAPI_NET_GprsAct res(%d)", res);
-
- if (1 == res)
- {
- MSG_INFO(1,"LSAPI_NET_GprsAct cid(%d) active succ", nCid);
- LSAPI_NET_GET_GprsNetIf();
- }
- else
- {
- MSG_INFO(1,"LSAPI_NET_GprsAct cid(%d) active fail", nCid);
- }
- }
- #define SHOUHU_CNT 5
- void ShouHuProcess(int interva)
- {
- static int nRet=0;
- static char regcnt=0;
- int tmepAtt_state=0;
- static int cnt=0;
- int nActstate = 0;
- static char lastNetif=0;
- char Netif=0;
-
- if(++cnt<(SHOUHU_CNT*1000/interva)) return;
- cnt=0;
- nRet=LSAPI_NET_GetGprsAttState(&tmepAtt_state);
- if(nRet!=0){
- MSG_WARN(1,"Get REG status failed");
- return;
- }
- ////////////////////////检测并打开PDP/////////////////////////////
- nRet = LSAPI_NET_GetGprsActState(&nActstate);
- if (nActstate != 1)
- {
- APP_ls_PdpActive();
- lastNetif=0;
- }
- else
- {
- if(LSAPI_NET_GET_GprsNetIf() == FALSE)
- {
- MSG_INFO(1,"sock netif failed\n");
- LSAPI_NET_NetIf_Create();
- }
- else
- {
- MSG_INFO(1,"sock success\n");
- }
-
- //MSG_INFO(1,"LS GprsActState has been ACTIVED");
- }
-
- if(tmepAtt_state!=1){
- //if(LastAtt_state!=tmepAtt_state)MSG_WARN(1,"REG off");
- if(regcnt==60/SHOUHU_CNT){
- MSG_WARN(1,"!!!!CFUN=0");
- msgAtSend("AT+CFUN=0\r\n");
- backLightReset();
- sutPocStatus.firstLogin=0;
- }else if(regcnt>=65/SHOUHU_CNT){
- MSG_WARN(1,"!!!!CFUN=1");
- msgAtSend("AT+CFUN=1\r\n");
- regcnt=0;
- }
- ++regcnt;
- sutApp.RegNetOK=0;
- }else {
- regcnt=0;
- sutApp.RegNetOK=1;
- }
- }
- void HeartTickSend(int interva)
- {
- static int cnt=0;
- //unsigned int HertTime=0;
- const char PwrList[3]={25,45,5};
- if(++cnt<(PwrList[newPara.pwrMode]*1000/interva)) return;
- cnt=0;
- broad_send_ping();
- MSG_INFO(1,"BND HeartTick");
- }
- //30秒 无人呼叫自动退出单呼
- void BNDAutoExitDanhu(int interva)
- {
- static int cnt=0;
- if(sutPocStatus.danHuStatus==0)return;
- if(sutPocStatus.mic||sutPocStatus.spk){
- cnt=0;
- return;
- }
- if(++cnt<(30*1000/interva)) return;
- cnt=0;
- broad_leavegroup();
- }
- //开机配置设定好的模块音频参数文件
- #define READ_PER_SIZE 400 //每次从Bin文件读取最多400字节来发送,AT时长度翻倍
- static void configureVoiceParam(void){
- //const char *confiFile="ZT-MINI101HGS.bin";
- //const char *confiFile="ZT-MINI201-202HGS-20210703.bin";
- const char *confiFile="Q-800KTV.bin";
- unsigned char sendbuf[40+2*400];//AT+CAIET=0,0,9600,400,""
- unsigned char *dataPtr=sendbuf+sizeof(sendbuf)-READ_PER_SIZE;
- char buf[3];
- char status=0;
- int fd,offset,readsize,i;
- LSAPI_FS_Stat_info_t pBuf;
- MSG_INFO(1, "config audio file'%s'",confiFile);
- fd=LSAPI_FS_Open(confiFile, LSAPI_FS_O_RDONLY,0x0);
- if(fd>0){
- memset(&pBuf,0,sizeof(pBuf));
- LSAPI_FS_Fstat(fd,&pBuf);
- offset=0;
- LSAPI_FS_Seek(fd, offset, LSAPI_FS_SEEK_SET);
- while(offset<pBuf.st_size){
- readsize=pBuf.st_size-offset;
- if(readsize>400) readsize=400;
- readsize=LSAPI_FS_Read(fd, dataPtr, readsize);
- if(readsize==0) break;
- else if(readsize<0){
- status=1;
- break;
- }
- sprintf(sendbuf, "AT+CAIET=0,0,%d,%d,\"", offset, readsize);
- for(i=0;i<readsize;i++){
- sprintf(buf, "%02x", dataPtr[i]);
- strcat(sendbuf, buf);
- }
- strcat(sendbuf,"\"\r\n");
- msgAtSend(sendbuf);
- offset += readsize;
- LSAPI_OSI_ThreadSleep(10);
- }
- LSAPI_FS_Close(fd);
- if(status==0) MSG_INFO(1, "config audio file succ:%d",offset);
- else MSG_ERR(1, "config audio failed %d",status);
- }else MSG_ERR(1, "'%s' open failed",confiFile);
- }
- static void paProCtl(void);
- static void subTimerCtl(unsigned char sleep_or_not);
- LSAPI_CellLocation_t nCellInfo[max_neighbor_cellbun];
- void LbsTask(void* param){
- while(1){
- LSAPI_OSI_ThreadSleep(5000);//1000
- if(sutApp.RegNetOK==0||getAppObjStatus(ASLEEP_LCD)==0)continue;//
- //先获取主小区信息
- memset(nCellInfo,0x00,sizeof(nCellInfo));
- LSAPI_NET_CellInfo(nCellInfo,LSAPI_pCurrCellInfo,0);
- }
- }
- int lib_oem_device_bts(int* mcc,int* mnc,int* lac, int* cid){
- int tmp_mcc = 0;
- int tmp_mnc = 0;
- int tmp_lac = 0;
- int tmp_cid = 0;
- char buf[10]={0};
- /*
- tmp_mcc |= (nCellInfo[0].sMcc[0] & 0xff) <<8;
- tmp_mcc |= (nCellInfo[0].sMcc[1] & 0xff) <<4;
- tmp_mcc |= (nCellInfo[0].sMcc[2]& 0xff);
- */
- snprintf(buf, sizeof(buf),"%d%d%d",nCellInfo[0].sMcc[0],nCellInfo[0].sMcc[1],nCellInfo[0].sMcc[2]);
- tmp_mcc=htoi(buf);
- if(tmp_mcc==0)return -1;
- MSG_INFO(1,"tmp_mcc==%x",tmp_mcc);
-
- tmp_mnc |= (nCellInfo[0].sMnc[0] & 0xff) <<4;
- tmp_mnc |= (nCellInfo[0].sMnc[1] & 0xff) ;
- // tmp_mnc |= (nCellInfo[0].sMnc[2]& 0xff);
-
- /*
- if(nCellInfo[0].sMnc[2] != 0x0F){
- snprintf(buf, sizeof(buf),"%d%d%d",nCellInfo[0].sMnc[0],nCellInfo[0].sMnc[1],nCellInfo[0].sMnc[2]);
- tmp_mnc=htoi(buf);
- MSG_INFO(1,"tmp_mnc==%x",tmp_mnc);
- }else{
- snprintf(buf, sizeof(buf),"%d%d",nCellInfo[0].sMnc[0],nCellInfo[0].sMnc[1]);
- tmp_mnc=htoi(buf);
- MSG_INFO(1,"tmp_mnc==%x",tmp_mnc);
-
- }
- // if(tmp_mnc==0)return -1;
- */
- tmp_lac=nCellInfo[0].sLac;
- MSG_INFO(1,"tmp_lac==%d",tmp_lac);
- tmp_cid=nCellInfo[0].sCellID;
- MSG_INFO(1,"tmp_cid==%d",tmp_cid);
-
- *mcc=tmp_mcc;
- *mnc=tmp_mnc;
- *lac= tmp_lac;
- *cid=tmp_cid;
- return 0;
- }
- void LBS_Pth()
- {
- if(NULL==LSAPI_OSI_ThreadCreate("LBS_Pth", LbsTask, NULL, LSAPI_OSI_PRIORITY_NORMAL, LBS_TASK_THREAD_STACK, 10)){
- MSG_INFO(1,"LBS_Pth task failed");
- }
-
- }
- void Lbs_Sendto_bnd(){
-
- if(sutApp.RegNetOK==0){
- //lbs vail
- return;
- }
- broad_request_lbs_info(GLCD_WIDTH,GLCD_HEIGHT-UI_CONTENT_SHOW_Y+8,0,0);//多下载8为了裁剪上方标签
- MSG_INFO(1,"get lbs_info");
- }
- /****************************复制通道0的参数到通道1中***********************/
- void apnCopyHandle(int dly){
- static unsigned short cnt=0xfff;
- if(sutApp.apnCopyDone!=0) return;
- if(++cnt<(1000/dly)) return;
- cnt=0;
- msgAtSend("AT+CGDCONT?\r\n");
- }
- #define APP_NEED_SLEEP OSI_MAKE_TAG('S', 'E', 'L', 'P')
- void ls_suspend(void *ctx, osiSuspendMode_t mode)
- {
- MSG_INFO(1,"\n\r ls_suspend mode:%d\n",mode);
- }
- void ls_resume(void *ctx, osiSuspendMode_t mode, uint32_t source)
- {
- MSG_INFO(1,"\n\r ls_resume mode:%d,source:%d\n",mode,source);
- }
- osiPmSourceOps_t sleep_ops =
- {
- ls_suspend,
- ls_resume,
- NULL,
- NULL
- };
- void appRun(void){
-
- char cnt=0;
- LSAPI_OSI_Event_t event={0};
- 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";
- osiPmSource_t*App_osiPmSource_t=NULL;
- App_osiPmSource_t=osiPmSourceCreate(APP_NEED_SLEEP, &sleep_ops, NULL);
- osiPmWakeLock(App_osiPmSource_t); //拿住资源不让系统休眠
- //等待lcd初始化完
- MSG_INFO(1, "wait lcd init");
- while(sutApp.guiStatus==0){LSAPI_OSI_ThreadSleep(50);}//是否检测超时?
- AntModeRun();
- localAuthNow();
- open_bnd_app();
- msgAtSend("AT+SIMCROSS?\r\n");
- Ear_Judge();
- backLightReset();
- //LSAPI_TTS_Play
- msgAtSend("ATI\r\n");
- configureVoiceParam();
- broad_play_tts(huanying,true);//播报欢迎使用
- while(sutApp.cardStatus==0){
- msgAtSend("AT+CCID\r\n");
- LSAPI_OSI_ThreadSleep(1000);
- if(++cnt>=5){
- MSG_INFO(1, "Check card timeout");
- break;
- }
- }
- msgAtSend("ATE0\r\n");
- LBS_Pth();
- //newPara.lcdParaDefaultIndex=4
- for(;;){
- volUpdateNeed();
- ledsProCtl();
- adcRead(APP_SUB_DIV_TIME);
- uiProcess(APP_SUB_DIV_TIME);
- //gpsProCtl(APP_SUB_DIV_TIME);
- pocProCtl(APP_SUB_DIV_TIME);
- NoteCheck(APP_SUB_DIV_TIME);
- uiTimeOutToStandby(0, APP_SUB_DIV_TIME);
- ShouHuProcess(APP_SUB_DIV_TIME);
- apnCopyHandle(APP_SUB_DIV_TIME);
- //BNDAutoExitDanhu(APP_SUB_DIV_TIME);
- HookGroupUserInfo();
- HookVolToutCheck();
- //IncomingSMS();
- if(isSleepReady()==0) LSAPI_OSI_ThreadSleep(APP_TASK_SLEEP_TIME);
- else if(sutApp.gtMode==0){//正常模式下可以休眿
- MSG_WARN(1, "APP SLEEP");
- osiPmWakeUnlock(App_osiPmSource_t); //释放资源
- uiTimeOutToStandby(1, APP_SUB_DIV_TIME);
- stopKeyTimer();
- subTimerCtl(1);//切换为休眠状态定时器
- sutApp.appStatus=1;
- redLedCtl(false);//休眠后保证灯没亮,否则有可能灯亮10ms,按理10ms后灯能灭,然后10ms时休眠了,应用就短时间内不会灭灯
- greenLedCtl(false);//休眠后保证灯没亮
- LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);
- osiPmWakeLock(App_osiPmSource_t);
- LSAPI_OSI_ThreadSleep(150);//添加这个后,休眠时按键或被呼叫或本机呼叫,tone音能是完整的
- lcdDrv_Init(1);//深度休眠唤醒后重新初始化SPI-LCD
- if(sutApp.lcdDlyLightUp){
- sutApp.lcdDlyLightUp=0;
- CTL_LCD_BL(1);
- }
- sutApp.forceUiFlash=1;
- sutApp.appStatus=0;
- subTimerCtl(0);//切换为唤醒状态定时器
- MSG_WARN(1, "APP WAKEUP");
- }
- //检测是否关机,这里要放在唤醒后操作
- pwrShutPro();
- }
- broad_free();
- }
- unsigned int subTimerInterval=100;//定时器定时的时间
- LSAPI_OSI_Timer_t *pSubtimer_t = NULL;
- /*
- 为了做低功耗,此定时器在休眠时,设置为长时间定旿
- 非休眠时,设置为短时间定旿
- sleep_or_not:0 未休眠, else 休眠
- */
- static void subTimerCtl(unsigned char sleep_or_not){
- if(NULL==pSubtimer_t){
- MSG_WARN(1, "subTimer null");
- return;
- }
- LSAPI_OSI_TimerStop(pSubtimer_t);
- //打开定时噿
- if(sleep_or_not==0) subTimerInterval=100;//未休眠时_00ms
- else subTimerInterval=5000;//休眠旿5000ms
- LSAPI_OSI_TimerStart(pSubtimer_t,subTimerInterval);
- }
- static void subTimeroutcallback(void *param){
- unsigned int *dlyTime=(unsigned int *)param;
- //处理灯的显示
- uioProctl(*dlyTime);
- //控制功放的关闿
- paProCtl();
- if(sutApp.bndPocDone==1){
- HeartTickSend(subTimerInterval);
- BNDAutoExitDanhu(subTimerInterval);
- }
- if(NULL!=pSubtimer_t) LSAPI_OSI_TimerStart(pSubtimer_t,subTimerInterval);
- }
- void subTask(void *param){
- LSAPI_OSI_Event_t event={0};
- if(NULL==pSubtimer_t) pSubtimer_t = LSAPI_OSI_TimerCreate(LSAPI_OSI_ThreadCurrent(), subTimeroutcallback, (void *)&subTimerInterval);
- if(NULL==pSubtimer_t) MSG_WARN(1,"sub timer init failed");
- else LSAPI_OSI_TimerStart(pSubtimer_t,subTimerInterval);
- for(;;){LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);}
-
- }
- static void paProCtl(void){
- //会被定时调用
- if(sutPocStatus.TTS!=0) return;
- if(sutPocStatus.spk!=0) return;
- if(sutPocStatus.TONE!=0) return;
- if(sutPocStatus.beep!=0) return;
- if(sutApp.gtMode!=0) return;
- paControl(false);
- //MSG_INFO(1,"spk off");
- }
- void tryWakeupApp(void){
- if(sutApp.appStatus!=0){
- if(mainThreadPtr!=NULL){
- threadSendEvent(mainThreadPtr,OHPOC_EVENT_MAIN,NULL,NULL,NULL);
- }
- }
- }
- void ttsPlay(ENCODE_USER_ENUM type, char *tts){
- int len,i;
- char ttsMessage[20*4];
- char Playbuf[40]={0};
- unsigned char codeType=ENCODE_USER_GBK;
- if(newPara.ttsMessage[0]==0) return;
- len=strlen(newPara.ttsMessage);
- len = len+(8-len%8);//
- MSG_INFO(1,"tts->");
- if(type==ENCODE_USER_UNICODE_BE)
- {
- codeType=LSAPI_TTS_UNICODE_BIG;
- for(i=0;i<len;i+=4){
- /*
- ttsMessage[i]=newPara.ttsMessage[i+2];
- ttsMessage[i+1]=newPara.ttsMessage[i+3];
- ttsMessage[i+2]=newPara.ttsMessage[i];
- ttsMessage[i+3]=newPara.ttsMessage[i+1];
- */
- ttsMessage[i]=newPara.ttsMessage[i];
- ttsMessage[i+1]=newPara.ttsMessage[i+1];
- ttsMessage[i+2]=newPara.ttsMessage[i+2];
- ttsMessage[i+3]=newPara.ttsMessage[i+3];
- MSG_INFO(0,"%c",ttsMessage[i]);
- MSG_INFO(0,"%c",ttsMessage[i+1]);
- MSG_INFO(0,"%c",ttsMessage[i+2]);
- MSG_INFO(0,"%c",ttsMessage[i+3]);
-
- }
- ttsMessage[len-1]=0;
- StrAsciiToHex(ttsMessage,Playbuf);
- //MSG_INFO(1,"");
- }else if(type==ENCODE_USER_GBK) {
- codeType=LSAPI_TTS_GBK;
- StrAsciiToHex(newPara.ttsMessage,Playbuf);
- MSG_INFO(1, "tts Play:%d,%s",codeType,tts);
- }else if(type==ENCODE_USER_ASCII){
- codeType=LSAPI_TTS_GBK;
- strncpy(Playbuf, tts, strlen(tts));
- }
- paControl(true);
- sutPocStatus.TTS=1;
- LSAPI_TTS_Play(Playbuf,strlen(Playbuf),codeType);
- }
- /*背光时间到,熄灭*/
- void backLightCb(void *param){
- if(sutPocStatus.firstLogin==0) return;//未登录过,不灭屏
- if(newPara.lcdParaList[newPara.lcdParaDefaultIndex]==0) return;//常亮
- CTL_LCD_BL(0);
- lcdBackLightApi(0);
- appSleepCtl(ASLEEP_LCD, 0);//可以休眠
- }
- /*点亮背光*/
- void backLightReset(void){
- unsigned short tmp;
- appSleepCtl(ASLEEP_LCD, 1);//不让休眠
- tmp=newPara.lcdParaList[newPara.lcdParaDefaultIndex];
- if(sutApp.appStatus==0) {
- lcdBackLightApi(1);
- CTL_LCD_BL(1);//未休眠时,直接点亮
- }else sutApp.lcdDlyLightUp=1;//休眠时不马上亮亮,会在LCD初始化完后点亮
-
- startBackLightTimer(tmp*1000);
- }
- void sysPwrLock(void){
- sutApp.pwrLock=1;
- }
- void sysPwrRlease(void){
- sutApp.pwrLock=0;
- }
- //"3132" --> 0x31,0x32
- void StrAsciiToHex(char *src, unsigned char *des){
- unsigned char temp[2],i;
- if(strlen(src)%2) return;
- while(0!=*src)
- {
- for(i=0;i<2;i++)
- {
- temp[i] = *src++;
- if(temp[i] >= '0' && temp[i] <= '9') temp[i] -= 0x30;
- else if(temp[i] >= 'A' && temp[i] <= 'F') temp[i] -= 0x37;
- else temp[i] -= 0x57;
- }
- temp[0] <<= 4;
- temp[0] &= 0xf0;
- *des++=temp[0]|temp[1];
- }
- *des=0;
- }
- #if(USE_PA==NEW_PA)
- const unsigned char spkVolTable[MAX_SPK_VOL+1]={0,20,30,40,50,60,70,80,90};//不接耳机时喇叭音
- #else
- const unsigned char spkVolTable[MAX_SPK_VOL+1]={0,10,20,30,40,50,60,70,80};//不接耳机时喇叭音
- #endif
- void spkVolumeSet(unsigned char level){
- char info[30];
- snprintf(info, sizeof(info), "AT+CLVL=%d\r\n", level);
- msgAtSend(info);
- #if(USE_PA==NEW_PA)
- broad_set_vol(BND_TTS, level/15);
- broad_set_vol(BND_TONE, level/15);
- #else
- broad_set_vol(BND_TTS, level/25);
- broad_set_vol(BND_TONE, level/25);
- #endif
-
- }
- /*调节音量,刷新音量进度条*/
- void volAdjAction(char direction,unsigned char UIStatus){
- int vol;
- if(direction==0){
- if(newPara.spkVol<MAX_SPK_VOL) newPara.spkVol++;
- else goto FLASH;
- }else if(direction==1){
- if(newPara.spkVol>0) newPara.spkVol--;
- else goto FLASH;
- }
- /*
- spkVolumeSet(newPara.spkVol*10);
- MSG_INFO(1,"SPK_VOL:%d",newPara.spkVol*10);
- */
- spkVolumeSet(spkVolTable[newPara.spkVol]);
- MSG_INFO(1,"SPK_VOL:%d",spkVolTable[newPara.spkVol]);
- vol=broad_get_vol(BND_VOICE);
- MSG_INFO(1,"voice_VO1L:%d",vol);
- vol=broad_get_vol(BND_TTS);
- MSG_INFO(1,"tts_VOL2:%d",vol);
- vol=broad_get_vol(BND_TONE);
- MSG_INFO(1,"tone_VOL3:%d",vol);
- sysIniSave();
- //刷新进度条
- FLASH:
- if(UIS_STANDBY==UIStatus)volUiFlash(newPara.spkVol);
- }
- void volUpdateNeed(void){
- if(sutApp.voluemUpdate==0) return;
- if(sutApp.voluemUpdate==1) volAdjAction(0, sutUIstatus.Status);
- else if(sutApp.voluemUpdate==2) volAdjAction(1, sutUIstatus.Status);
- sutApp.voluemUpdate=0;
- }
- static void KeyToneDly()
- {
- static unsigned char Cnt=0;
- if(sutPocStatus.beep){
- if(++Cnt>1){
- Cnt=0;
- sutPocStatus.beep=0;
- }
- }else Cnt=0;
- }
|