12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037 |
- #include "includes.h"
- #include "lsapi_tts.h"
- #include "osi_api.h"
- #define APP_IDLE_TIME 3 //如果POC已休眿APP没有操作一定秒数后休眠
- int keyNum=0;
- APP_DEF sutApp;
- static void appDataInit(void){
- memset((unsigned char *)&sutApp, 0, sizeof(APP_DEF));
- sutApp.updateStatusBar=1;
- sutApp.g_iBAT=-1;
- sutApp.copstype=-1;
- 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{
- MSG_WARN(1, "USB Buf Over");
- len=0;
- buf[len++]=ch;
- }
- if(lach=='\r' && ch=='\n'){
- buf[len-2]=0; //GWSD 新指令去掉回车换行
- cmdSetting(buf);
- len=0;
- }
- lach=ch;
- }
- }
- static void pttHandler(char type, char ctl){
- #if 1//主PTT, 耳机PTT以及组合PTT都可以触发,即矩阵驱动时,任何一个按下如果没发请麦,则发请麦,只要有一个放开,则直接发放麦指令。因为组合按放后,放开,只有一个放开键值出来
- static char micPttPressed=0;
- static char pttPressed=0;
- static char maxPressed=0;
- if(type==0){//ptt
- if(ctl==0){//free
- pttPressed=0;
- }else{//press
- pttPressed=1;
- }
- }else if(type==1){//mic ptt
- if(ctl==0){//free
- micPttPressed=0;
- }else{//press
- micPttPressed=1;
- }
- }else if(type==2){//mic ptt
- if(ctl==0){//free
- maxPressed=0;
- }else{//press
- maxPressed=1;
- }
- }else return;
-
- if(ctl==0){//free
- if(pttPressed==0 || micPttPressed==0 || maxPressed==0){
- sutApp.pttReq=0;
- pttPressed=0;micPttPressed=0;maxPressed=0;
- msgAtSend("AT+POC=relspk00");
- }
- }else{//press
- if(pttPressed || micPttPressed || maxPressed){
- if(sutApp.pttReq==0){
- sutApp.pttReq=1;
- msgAtSend("AT+POC=reqspk00");
- }
- }
- }
-
- #else
- static char micPttPressed=0;
- static char pttPressed=0;
- 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 if(type==1){//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) msgAtSend("AT+POC=0C0000\r\n");
- else msgAtSend("AT+POC=0B0000\r\n");
- }
- #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_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;
- case MKEY_VALUE_CB_PTT: strcat(buf, "MAX_PTT]");break;
- default: return;
- }
- if(status==0) strcat(buf, freeSeg);
- else strcat(buf, pressSeg);
- MSG_INFO(1,buf);
- }
- /*
- 龙尚矩阵驱动有一个问题:先按A不放,检测到A按下,再按B不放,检测到B按下,同时放开,概率只检测到B放开,A没检测到
- 规避方式:键值发生变化时,如果上次的键值大于等于2,直接清掉键值。
- */
- void assistantCheck(unsigned short key){
- unsigned int i,j,w;
- static unsigned short lkey=0;
- if(lkey==key) return;
-
- j=0;
- for(i=0;i<16;i++){//上次键值置位的个数
- if(lkey & (1<<i)) j++;
- }
- w=0;
- for(i=0;i<16;i++){//本次键值置位的个数
- if(key & (1<<i)) w++;
- }
-
- if(j>=2 && j>w){//上一次至少两个键按下,现在发生变化,至少一个键放开了,全键清除
- lkey=0;
- clearKeyValue();
- }
- lkey=key;
- }
- 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;
- assistantCheck(keyStatus);
- 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){
- sutApp.waitEscReleased=1;
- uISetNextStatus(UIS_MENU_SHUT_PWR);
- }
- }else{
- sutApp.waitEscReleased=0;
- cnt=0;
- }
- #if 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);
- #endif
- }
- 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;
- }
- }
- //key:1 跳过
- void keyToneStart(char type){
- if(newPara.KeySound==0&&type==0) return;
- if(sutPocStatus.TTS)return;
- if(type==2)sutPocStatus.beep=2;
- else sutPocStatus.beep=1;
- paControl(true);
- MSG_INFO(1, "Ptt:%d\r\n",sutPocStatus.PttFail);
- if(ToneThreadPtr!=NULL)threadSendEvent(ToneThreadPtr,OHPOC_EVENT_MAIN,NULL,NULL,NULL);//0702Send("AT+TONE\r\n");
- }
- void quickUiSwitch(int uistatus){
- if(true==isUiSwitchReady()) return;
- 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);
- }
- void keyHandler(unsigned short key,unsigned char status){//普通按键值处琿
- static unsigned char gtModeCnt=0;
- static unsigned char lockCnt=0;
- if(newPara.lockType!=0){
- if(sutApp.keyLock!=0 && MKEY_VALUE_MENU!=key){
- sutApp.lockShow=1;
- return;
- }
- }else{
- if(sutApp.keyLock!=0 && (MKEY_VALUE_DOWN==key || MKEY_VALUE_ESC==key)){
- sutApp.lockShow=1;
- return;
- }
- }
- MSG_INFO(1, "KEY:%d,%d", key,status);
-
- showKeyMessage(key,status);
- if(status==0){//key free
- switch(key){
- case MKEY_VALUE_MIC_PTT:
- pttHandler(0,0);
- break;
- case MKEY_VALUE_PTT:
- pttHandler(1,0);
- break;
- case MKEY_VALUE_CB_PTT:
- pttHandler(2,0);
- break;
- case MKEY_VALUE_ESC:
- pwrDetRead(1);
- break;
- case MKEY_VALUE_F1:
- if(sutApp.key_f1_cnt==1 && sutUIstatus.Status!=UIS_MENU_SYS_SERVERPASS) sutApp.voluemUpdate=1;
- sutApp.key_f1_cnt=0;
- break;
- case MKEY_VALUE_F2:
- if(sutApp.key_f2_cnt==1 && sutUIstatus.Status!=UIS_MENU_SYS_SERVERPASS) sutApp.voluemUpdate=2;
- sutApp.key_f2_cnt=0;
- break;
- case MKEY_VALUE_CB_GT:
- gtModeCnt=0;
- break;
- case MKEY_VALUE_MENU:
- if(sutApp.keyLock != 0 && lockCnt==1)//实际无法实现锁短按一下,因为按下去键值就被使用了,不过锁键盘后,都是在待机界面,不影响
- sutApp.lockShow=1;
- lockCnt=0;
- break;
- default:
- break;
- }
- sutApp.timeOutCnt=0;
- keyInArow=0;
- appSleepCtl(ASLEEP_MKEY, 0);
- }else{//key press
- if(key!=MKEY_VALUE_PTT && key!=MKEY_VALUE_CB_GT&&key!=MKEY_VALUE_MIC_PTT) keyToneStart(0);
- backLightReset();//其它所有键都点亮(接口里面有调阻止休眠接口)
- appSleepCtl(ASLEEP_MKEY, 1);
- keyNum++;
- switch(key){
- case MKEY_VALUE_MIC_PTT:
- pttHandler(0,1);
- break;
- case MKEY_VALUE_PTT:
- pttHandler(1,1);
- break;
- case MKEY_VALUE_CB_PTT:
- pttHandler(2,1);
- break;
- case MKEY_VALUE_ESC:
- keyInArow=1;
- pwrDetRead(0);
- break;
- case MKEY_VALUE_F1:
- keyInArow=1;
- sutApp.key_f1_cnt++;
- if(sutApp.keyLock==0){
- if(sutApp.key_f1_cnt==3) quickUiSwitch(UIS_MENU_GROUP_SEL);
- }else if(sutApp.key_f1_cnt!=1) sutApp.lockShow=1;
- break;
- case MKEY_VALUE_F2:
- keyInArow=1;
- sutApp.key_f2_cnt++;
- if(sutApp.keyLock==0){
- if(sutApp.key_f2_cnt==3) quickUiSwitch(UIS_MENU_USER_SEL);
- }else if(sutApp.key_f2_cnt!=1) sutApp.lockShow=1;
- break;
- case MKEY_VALUE_CB_GT:
- keyInArow=1;
- gtModeCnt++;
- if(sutApp.keyLock==0){
- if(gtModeCnt==3){
- if(sutApp.gtMode==0){
- enterGTMode();
- }
- }
- }else sutApp.lockShow=1;
- break;
- case MKEY_VALUE_CB_IP:
- keyInArow=1;
- break;
- case MKEY_VALUE_MENU:
- keyInArow=1;
- if(++lockCnt==3) lockProcess();
- 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){
- #if 1
- static unsigned char earStatus=0xff;
- unsigned char tmpEar;
- int32_t chargeVol;
- static unsigned short cnt=0,lcnt=0;
- static unsigned int laSiVbat;
- unsigned int adcValueTmp;
- if(++cnt<(1000/interval)) return;//1秒读一次ADC即可
- cnt=0;
- LSAPI_SYS_BattGetVol(&adcValueTmp);
- sutApp.g_iBAT=adcValueTmp/10;
- if(sutApp.g_iBAT == laSiVbat){
- laSiVbat=sutApp.g_iBAT;
- 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;
- }
- //读取充电/耳机接入状态 //不知道为啥是LSAPI_Device_ADC_CHANNEL_3,而不是LSAPI_Device_ADC_CHANNEL_1
- chargeVol=LSAPI_Device_AdcGetChannelVolt(LSAPI_Device_ADC_CHANNEL_3, LSAPI_Device_ADC_SCALE_3V233);
- if(chargeVol<=800){//耳机插入,没在充电
- tmpEar=0;
- sutApp.chargeStatus=0;
- }else if(chargeVol<=1000){//耳机插入,正在充电
- tmpEar=0;
- sutApp.chargeStatus=1;
- }else if(chargeVol<=1400){//耳机拔出,没在充电
- tmpEar=1;
- sutApp.chargeStatus=0;
- }else{//耳机拔出,正在充电
- tmpEar=1;
- sutApp.chargeStatus=1;
- }
- if(tmpEar != earStatus){//耳机状态发生变化
- earStatus=tmpEar;
- tmpEar += 0x30;
- proHeadSet(&tmpEar);
- }
- #else//这里ADC太频繁调用ADC接口,有概率会影响poc播放tone音效果
- #define VBAT_READ_TIME 20
- unsigned int adcValueTmp;
- static unsigned int siVbat=0,laSiVbat;
- static unsigned char index=0;
-
- LSAPI_SYS_BattGetVol(&adcValueTmp);
- siVbat += adcValueTmp;
- if(++index>=VBAT_READ_TIME){
- sutApp.g_iBAT=siVbat / VBAT_READ_TIME / 10;
- if(laSiVbat!=sutApp.g_iBAT){
- //MSG_INFO(1, "bat:%d", sutApp.g_iBAT);
- laSiVbat=sutApp.g_iBAT;
- if(sutApp.g_iBAT<=MIN_PWR_LEVEL){
- MSG_INFO(1, "Low power ,shut");
- sutApp.lowPwrMsg=1;
- appSleepCtl(ASLEEP_PWR, 1);
- }
- }
- siVbat=0;
- index=0;
- }
- #endif
- }
- /*处理UI操作*/
- static void uiProcess(unsigned int exeInterval){
- static int cnt=0;
- if(getAppObjStatus(ASLEEP_PWR) != 0) return;//关机后,不切换菜单,只显示关机
- //uiLoop(exeInterval);
- uiResponse(exeInterval);
- }
- /*触发关机操作*/
- static void pwrShutPro(void){
- static char shutFlag=0;
-
- if(getAppObjStatus(ASLEEP_PWR) == 0) return;
- 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);
- guiShowBmp(0,0,"BYEBYE.bmp");
- LSAPI_OSI_ThreadSleep(1000);
- }
- MSG_INFO(1, "Normal PwrOff");
- //msgAtSend("AT+TRB=1\r\n");//normal power off 当前固件先不发模块关机指令,否则断电再上电有可能是起不来皿
- //LSAPI_OSI_ThreadSleep(1000);//一秒后释放电源锿防止软关机不成功
- lcdBackLightApi(0);
- MSG_INFO(1, "Release pwr");
- guiFillRect(0,0,GLCD_WIDTH-1,GLCD_HEIGHT-1,guiGetBackColor());//防止下次开机能看到残留
- msgAtSend("AT+CPOF\r\n");//软件关机模块
- LSAPI_OSI_ThreadSleep(100);
- CTL_POWER_HOLD(false);
- }
- static void NoteCheck(int interval){
- int dlyMs;
- if(sutApp.lowPwrWarn!=0){
- sutApp.lowPwrCnt += interval;
- if(sutPocStatus.spk==0 && sutPocStatus.mic==0){//对计状态下不播放请充电
- if(sutApp.lowPwrCnt>=WARN_TTS_INTERVAL){
- sutApp.lowPwrCnt=0;
- ttsPlay(ENCODE_USER_GBK, "C7EBB3E4B5E7");
- }
- }
- }
- }
- void AntModeRun(void){
- #ifdef ENABLE_ANT_MODE
- guiShowMessageBox("调天线模式");
- for(;;){
- LSAPI_OSI_ThreadSleep(2000);
- }
- #endif
- }
- static void paProCtl(void);
- static void subTimerCtl(unsigned char sleep_or_not);
- static void configureVoiceParam(void);
- static void startPocLogin(void){
- //if(sutApp.startPoc==0) return;
- MSG_INFO(1, "Start poc");
- sutApp.startPoc=0;
- msgAtSend("AT+POC=startup011");//打开对讲,关闭POC播放TTS //msgAtSend("AT+POC=0000000101\r\n");
- }
- void pocSetDomain(void){//设置域名前缀
- const char platform[]="platform2";
- const char pFormatMark[]="chn-gwsd-";
-
- char info[100]={0};
- char tbuf[50];
- char len =0;
-
- // char* platform=0;
- // char* pFormatMark=0;
-
- // platform=sutApp.UserInfo.platform;
- // pFormatMark=sutApp.UserInfo.pFormatMark;
- snprintf(tbuf, sizeof(tbuf), "%s&%s", platform,pFormatMark);
- len =strlen(tbuf);
-
- snprintf(info, sizeof(info), "AT+POC=setdns%02x%s",len ,tbuf);
- msgAtSend(info);
- MSG_INFO(0, "%s",info);
- }
- void appRun(void){
-
- char cnt=0;
- LSAPI_OSI_Event_t event={0};
- //等待lcd初始化完房
- MSG_INFO(1, "wait lcd init");
- while(sutApp.guiStatus==0){LSAPI_OSI_ThreadSleep(50);}//是否检测超时?
-
- // AntModeRun();
- // localAuthNow();
- sutApp.authReady=1;
- newPara.lcdParaDefaultIndex=4;
-
- //等待poc启动完成
- MSG_INFO(1, "lcd init done, wait poc start");
- // while(sutApp.pocInitStatus==0){
- // msgAtSend("ATE0\r\n");
- // LSAPI_OSI_ThreadSleep(1000);
- // }//是否检测超时?
- MSG_INFO(1, "app loop start");
-
- msgToModem("AT+AUDCH=0,0\r\n");//此机型只使用主通道
- //设置一下TTS语音速度
- msgToModem("AT+LSHTTSPARAM=3000,106,100\r\n");//设置TTS参数
- //查询一下POC版本叿
- msgToModem("AT+SIMCROSS?\r\n");
- msgAtSend("AT+POC=version\r\n");//发指令后等待POC启动
-
- // configureVoiceParam();
- // adcRead(APP_SUB_DIV_TIME);//在开机播放前设置下SPK
- // splVolumeSet(newPara.spkVol*10);//更新音量
- backLightReset();
- newGuiNoteBoot(1);
-
- // //检测卡是否存在
- // while(sutApp.cardStatus==0){
- // msgAtSend("AT+CCID\r\n");
- // LSAPI_OSI_ThreadSleep(500);
- // if(++cnt>=10){
- // MSG_INFO(1, "Check card timeout");
- // break;
- // }
- // }
- sutApp.cardStatus=1;
- LSAPI_OSI_ThreadSleep(3000);
- msgAtSend("AT+POC=poccmd1");
- LSAPI_OSI_ThreadSleep(3000);
-
- pocSetDomain();
- setPocPara();
- LSAPI_OSI_ThreadSleep(1000);
- startPocLogin();
- msgToModem("AT+CLVL=100\r\n");
-
- for(;;){
- ledsProCtl();
- adcRead(APP_SUB_DIV_TIME);
- uiProcess(APP_SUB_DIV_TIME);
- pocProCtl(APP_SUB_DIV_TIME);
- NoteCheck(APP_SUB_DIV_TIME);
- uiTimeOutToStandby(0, APP_SUB_DIV_TIME);
- HookGroupUserInfo();
- LogoutOutTimeCheck(APP_SUB_DIV_TIME);
- if(isSleepReady()==0) LSAPI_OSI_ThreadSleep(APP_TASK_SLEEP_TIME);
- else if(sutApp.gtMode==0){//正常模式下可以休眿
- MSG_WARN(1, "APP SLEEP");
- uiTimeOutToStandby(1, APP_SUB_DIV_TIME);
- stopKeyTimer();
- subTimerCtl(1);//切换为休眠状态定时器
- sutApp.appStatus=1;
- redLedCtl(false);//休眠后保证灯没亮,否则有可能灯亮10ms,按理10ms后灯能灭,然后10ms时休眠了,应用就短时间内不会灭灯
- greenLedCtl(false);//休眠后保证灯没亮
- sutApp.updateStatusBar=1;
- LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);
- LSAPI_OSI_ThreadSleep(150);//添加这个后,休眠时按键或被呼叫或本机呼叫,tone音能是完整的
- lcdDrv_Init(1);//深度休眠唤醒后重新初始化SPI-LCD
- if(sutApp.lcdDlyLightUp){
- sutApp.lcdDlyLightUp=0;
- lcdBackLightApi(1);
- }
- sutApp.forceUiFlash=1;
- sutApp.appStatus=0;
- subTimerCtl(0);//切换为唤醒状态定时器
- MSG_WARN(1, "APP WAKEUP");
- }
- //检测是否关机,这里要放在唤醒后操作
- pwrShutPro();
- }
- }
- 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(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[100]={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];
- 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);
- StrAsciiToHex(tts,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;
- // OEM_TTS_Spk(int type, char * atxt);
- LSAPI_TTS_Play(Playbuf,strlen(Playbuf),codeType);
- }
- /*背光时间到,熄灭*/
- void backLightCb(void *param){
- if(sutPocStatus.firstLogin==0) return;//未登录过,不灭屏
- if(newPara.lcdParaList[newPara.lcdParaDefaultIndex]==0) return;//常亮
- 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);//未休眠时,直接点亮
- 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;
- }
- void splVolumeSet(unsigned char level){
- char info[30];
-
- snprintf(info, sizeof(info), "AT+CLVL=%d\r\nAT+CRSL=%d\r\n", level,level);
- msgAtSend(info);
- MSG_INFO(1,"SPK_VOL:%d",level);
- }
- const unsigned char spkGainTable[SPK_GAIN_NUM];
- /*调节音量,刷新音量进度条*/
- void volAdjAction(char direction,unsigned char UIStatus){
- unsigned char vol;
- if(sutApp.earLev==0){//不接耳机
- if(direction==0){
- if(newPara.spkVol<MAX_SPK_VOL) newPara.spkVol++;
- else goto FLASH;
- }else{
- if(newPara.spkVol>0) newPara.spkVol--;
- else goto FLASH;
- }
- vol=newPara.spkVol*10;
- splVolumeSet(vol);
- }else{//接了耳机
- if(direction==0){
- if(newPara.spkGain<SPK_GAIN_NUM) newPara.spkGain++;
- else goto FLASH;
- }else{
- if(newPara.spkGain>0) newPara.spkGain--;
- else goto FLASH;
- }
- if(newPara.spkGain==0) vol=0;
- else vol=spkGainTable[newPara.spkGain-1];
- splVolumeSet(vol);
- vol=newPara.spkGain;
- }
- sysIniSave();
- //刷新进度条
- FLASH:
- if(sutApp.earLev==0) vol=newPara.spkVol;
- else vol=newPara.spkGain;
- //if(UIS_STANDBY==UIStatus) volUiFlash(vol);
- }
- 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;
- }
- const unsigned char spkGainTable[SPK_GAIN_NUM]={
- 24,32,40,48,56,64,72,80
- };
- void VolSpkUpdate(void){
- char cmd[30];
- unsigned char volLev;
- if(sutApp.earLev==0){//耳机拔掉后,恢复正常的SPK增益
- volLev=newPara.spkVol*10;
- }else{//耳机接入,应用特定值
- if(newPara.spkGain>=SPK_GAIN_NUM) volLev=SPK_GAIN_DEFAULT;
- else volLev=newPara.spkGain;
- if(volLev>0) volLev=spkGainTable[newPara.spkGain-1];
- }
- splVolumeSet(volLev);
- }
- //对都使用主音频通道设计来说,耳机模式时,需要按比例降低输入输出增益
- const unsigned short micGainTable[MIC_GAIN_NUM][2]={
- {2,6},{2,10},{3,10},{4,10},{5,10},{6,10},{6,13}
- };
- void VolMicUpdate(void){
- #if 1
- char cmd[50];
- unsigned char hana,lana,hadc,ladc;
- if(sutApp.earLev==0){//耳机拔掉,恢复正常MIC增益
- hana=sutApp.mic_ana>>8;
- lana=sutApp.mic_ana;
- hadc=sutApp.mic_adc>>8;
- ladc=sutApp.mic_adc;
- }else{//耳机接入
- hana=micGainTable[newPara.micGain][0]>>8;
- lana=micGainTable[newPara.micGain][0];
- hadc=micGainTable[newPara.micGain][1]>>8;
- ladc=micGainTable[newPara.micGain][1];
- }
- snprintf(cmd, sizeof(cmd), "AT+CACCP=0,0,0,\"%02x%02x%02x%02x\"\r\n",lana,hana,ladc,hadc);
- msgAtSend(cmd);
- #else
- unsigned char tableIndex;
- char cmd[50];
- int vol=newPara.spkVol*10;
- splVolumeSet(vol);
- if(sutApp.earLev==0){//耳机拔掉,恢复正常MIC增益
- tableIndex=newPara.micGain_onspk;
- //msgAtSend("AT+CACCP=0,0,0,\"04000a00\"\r\n");
- }else{//耳机接入
- tableIndex=newPara.micGain_onear;
- //msgAtSend("AT+CACCP=0,0,0,\"02000f00\"\r\n");
- }
- if(tableIndex>=MIC_GAIN_NUM){
- MSG_WARN(1, "Index invalid:%d", tableIndex);
- return;
- }
- snprintf(cmd, sizeof(cmd), "AT+CACCP=0,0,0,\"%02x00%02x00\"\r\n", micGainTable[tableIndex][0],micGainTable[tableIndex][1]);
- msgAtSend(cmd);
- #endif
- }
- //开机配置设定好的模块音频参数文件
- #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";
- 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);
-
- if(status==0){//配置成功后,回读一下默认的Mic,这个值在不接耳机时是固定值
- LSAPI_OSI_ThreadSleep(50);
- msgAtSend("AT+CACCP=0,0,1,\"\"\r\n");
- LSAPI_OSI_ThreadSleep(50);
- }else{
- //如果配置失败了,直接使用默认值
- sutApp.mic_ana=4;
- sutApp.mic_adc=4;//12;
- }
- VolMicUpdate();
- }
- //+CACCP:
- //+CACCP: "04000C00" ana=0x0004 adc=0x000c
- void proCaccpMsg(char *msg){
- char tmp[10],*pName;
- char i=0,j=0;
- if(msg[0]=='"'){
- memcpy(tmp+j, msg+7,2);j += 2;
- memcpy(tmp+j, msg+5,2);j += 2;
- memcpy(tmp+j, msg+3,2);j += 2;
- memcpy(tmp+j, msg+1,2);j += 2;
- tmp[j]=0;//000C0004
- sutApp.mic_ana=strtol(tmp+4, &pName,16);
- tmp[4]=0;
- sutApp.mic_adc=strtol(tmp, &pName,16);
- }
- }
|