123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809 |
- #include "includes.h"
- #include "socket.h"
- int g_iCSQ=-1;
- signed char Chargeing;
- YUNYINGSHANG_DEF thisYunYingShang=CHINA_NONE;
- unsigned char g_ucModemTaskEn=0;
- unsigned char modemInitStatus=0;
- unsigned char g_ucCardStatus=0;
- unsigned char modemInitReady=0;//0模块没开始初始化 1模块初始化成功 2模块初始化失败
- static char ChekCardCnt=0;
- char CardStatue=0x11;
- unsigned char SIMSelect;
- unsigned int TTSPlayTick=0;
- char SendAT[50];
- char WaitAT1[30];
- char WaitAT2[30];
- typedef enum{
- MINI_WAT_START,
- MINI_GET_MODULE,
- MINI_GET_POC_VER,
- MINI_GET_POC_CODE,
- MINI_GET_CARD,
- MINI_GET_IMEI,
- MINI_PLY_ICCID,
- MINI_POC_PARA,
- MINI_SET_TONES,
- MINI_READ_SPKLV,
- MINI_GET_SIMSELECT,
- MINI_SET_MICLV,
- MINI_SET_TTSPARM,
- MINI_SET_GPSPARM,
- MINI_CHEAK_HEADSET,
- MINI_POC_AUTHSET,
- }M_INIT_STATUS;
- static unsigned char initStatus;
- static unsigned short timeOut;
- static unsigned char PocGetTypeCnt=0;
- char *FirmSperkr="AT+CAIET=0,0,9600,400,\"8080808002003400d3ff000002003400d6ff0000020\
- 03400d9ff000002003400dcff000002003400dfff000002003400e2ff000002003400e5ff000002003400e8ff000002003400ebff000002003400eeff000002003400f1ff000002003400f4ff000002003400f7ff000002003400faff000002003400fdff0000020034000000000002003400d3ff000002003400d6ff000002003400d9ff000002003400dcff000002003400dfff000002003400e2ff000002003400e5ff000002003400e8ff000002003400ebff000002003400eeff000002003400f1ff000002003400f4ff000002003400f7ff000002003400faff000002003400fdff0000020034000000000004003400d3ff000004003400d6ff000004003400d9ff000004003400dcff000004003400dfff000004003400e2ff000004003400e5ff000004003400e8ff000004003400ebff000004003400eeff000004003400f1ff000004003400f4ff000004003400f7ff000004003400faff000004003400fdff0000040034000000000004003400d3ff000004003400\"\r\n";
- char *FirmSperkr2="AT+CAIET=0,0,10000,372,\"d6ff000004003400d9ff000004003400dcff000004\
- 003400dfff000004003400e2ff000004003400e5ff000004003400e8ff000004003400ebff000004003400eeff000004003400f1ff000004003400f4ff000004003400f7ff000004003400faff000004003400fdff0000040034000000000004003400d3ff000004003400d6ff000004003400d9ff000004003400dcff000004003400dfff000004003400e2ff000004003400e5ff000004003400e8ff000004003400ebff000004003400eeff000004003400f1ff000004003400f4ff000004003400f7ff000004003400faff000004003400fdff0000040034000000000004003400d3ff000004003400d6ff000004003400d9ff000004003400dcff000004003400dfff000004003400e2ff000004003400e5ff000004003400e8ff000004003400ebff000004003400eeff000004003400f1ff000004003400f4ff000004003400f7ff000004003400faff000004003400fdff00000400340000000000\"\r\n";
- void SpeakTTSVoice(void)
- {
- int len,timeout,i;
- char ttsMessage[20*4];
- //SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- unsigned char codeType=ENCODE_UNICODE;
- if(newPara.ttsMessage[0]==0) return;
- len=strlen(newPara.ttsMessage);
- len = len+(8-len%8);//8倍数
- if(newPara.ttsCodeType==TTS_UNICODE)
- {
- codeType=ENCODE_UNICODEBigend;
- 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];
- printf("%c",ttsMessage[i]);
- printf("%c",ttsMessage[i+1]);
- printf("%c",ttsMessage[i+2]);
- printf("%c",ttsMessage[i+3]);
- }
- ttsMessage[len-1]=0;
- printf("\r\n");
- }else if(newPara.ttsCodeType==TTS_GBK) codeType=ENCODE_ASCII;
- MeSpeak(codeType,ttsMessage);
- }
- void mInitSwitchStatus(unsigned char status){
- timeOut=10;//5秒
- initStatus=status;
- snprintf(WaitAT2, sizeof(WaitAT2), "@#@");
-
- switch(initStatus){
- case MINI_WAT_START:
- timeOut=60;//只有模块启动时时间才要长些这里设置为30秒//60
- SlwTrace(INF, "WaitModemRun..",1);
- snprintf(SendAT, sizeof(SendAT), "ATE0\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "OK");
- snprintf(WaitAT2, sizeof(WaitAT2), "+POC:START");
- break;
- case MINI_POC_AUTHSET:
- timeOut=6;
- //timeOut=10;//只有模块启动时时间才要长些这里设置为30秒//60
- SlwTrace(INF, "PocAuth",1);
- snprintf(SendAT, sizeof(SendAT), "AT+GAUTH\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+GAUTH:");
- snprintf(WaitAT2, sizeof(WaitAT2), "+GAUTH:");
- break;
- case MINI_GET_MODULE:
- SlwTrace(INF, "GetModemModule..",1);
- snprintf(SendAT, sizeof(SendAT), "ATI\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "SV");
- break;
-
- case MINI_GET_POC_VER:
- timeOut=12;
- SlwTrace(INF, "GetPocVersion..",1);
- if(PocGetTypeCnt==0){
- snprintf(SendAT, sizeof(SendAT), "AT+POC_VER?\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+POC_VER:");
- }
- else {
- snprintf(SendAT, sizeof(SendAT), "AT+POC=version\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+POC:BROAD");
- }
-
- break;
- case MINI_GET_POC_CODE:
- SlwTrace(INF, "GetPocCode..",1);
- snprintf(SendAT, sizeof(SendAT), "AT+POC=40000000\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+POC:400000000");
- break;
-
- case MINI_GET_CARD:
- SlwTrace(INF, "GetCardStatus..",1);
- snprintf(SendAT, sizeof(SendAT), "AT+CPIN?\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+CPIN: READY");
- break;
-
- case MINI_GET_IMEI:
- SlwTrace(INF, "GetIMEI..",1);
- snprintf(SendAT, sizeof(SendAT), "AT+LSHIMEI\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+LSHIMEI:");
- break;
-
- case MINI_PLY_ICCID:
- SlwTrace(INF, "GetICCID..",1);
- snprintf(SendAT, sizeof(SendAT), "AT+CCID\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+CCID:");
- break;
-
- case MINI_POC_PARA:
- SlwTrace(INF, "GetPOCPara..",1);
- snprintf(SendAT, sizeof(SendAT), "AT+POC=020000\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+POC:02");
- break;
-
- case MINI_SET_TONES:
- SlwTrace(INF, "SetTones..",1);
- if(newPara.KeySound!=0){
- snprintf(SendAT, sizeof(SendAT), "AT+TONES=1\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+TONES:1");
- }else {
- snprintf(SendAT, sizeof(SendAT), "AT+TONES=0\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+TONES:0");
- }
- break;
- case MINI_READ_SPKLV:
- SlwTrace(INF, "SetCLVL..",1);
- snprintf(SendAT, sizeof(SendAT), "AT+CLVL?\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+CLVL:");
- break;
-
- //MINI_GET_SIMSELECT
- case MINI_GET_SIMSELECT:
- SlwTrace(INF, "GetSIMSelect..",1);
- snprintf(SendAT, sizeof(SendAT), "AT+SIMCROSS?\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+SIMCROSS:");
- break;
-
- //newPara.Miclv
- case MINI_SET_MICLV:
- SlwTrace(INF, "SetMIClv..",1);
- //+CACCP: "07000b00" newPara.Miclv
- snprintf(SendAT, sizeof(SendAT), "AT+CACCP=2,1,6,\"%02x00%02x00\"\r\n",newPara.Miclv/16,newPara.Miclv%16);
- snprintf(WaitAT1, sizeof(WaitAT1), "+CACCP:");
- break;
-
- //AT+LSHTTSPARAM=3000,106,100 设置TTS 音量 语调 语速
- // +LSHTTSPARAM:3000,106,100
-
- case MINI_SET_TTSPARM:
- SlwTrace(INF, "SetTTSPARAM..",1);
- snprintf(SendAT, sizeof(SendAT), "AT+LSHTTSPARAM=3000,106,100\r\n");//32768
- snprintf(WaitAT1, sizeof(WaitAT1), "OK");
- break;
-
- //MINI_SET_GPSPARM
- case MINI_SET_GPSPARM:
- SlwTrace(INF, "Set_SET_GPSPARM..",1);
- snprintf(SendAT, sizeof(SendAT), "AT+GPS?\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+GPS:O");//+GPS:ON +GPS:OFF
- break;
-
- case MINI_CHEAK_HEADSET:
- SlwTrace(INF, "CHEAK_HEADSET..",1);
- snprintf(SendAT, sizeof(SendAT), "AT+HEADSET?\r\n");
- snprintf(WaitAT1, sizeof(WaitAT1), "+HEADSET:");//+GPS:ON
- break;
- }
- }
- short ModemInitAckHandler(unsigned char result){
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- char buf[20];
- char *msg=(char *)pMsg->MsgData;
- short ret=0;
- static char FirstInitTTS=0;
-
- switch(initStatus){
- case MINI_WAT_START:
- if(result==1){
- SlwTrace(INF, "ModemStart...",1);
- ModemSendAt("ATE0\r\n");
- mInitSwitchStatus(MINI_POC_AUTHSET);
- }else ret=-1;
- break;
-
- case MINI_POC_AUTHSET:
- if(result==1){
- SlwTrace(INF, "POC-AuthOk--",1);
- PocAuthProcess(&msg[7]);
-
- }
- mInitSwitchStatus(MINI_GET_POC_VER);
- break;
-
- case MINI_GET_POC_VER:
- if(result!=1) {
- PocGetTypeCnt++;
- if(PocGetTypeCnt==1){
- mInitSwitchStatus(MINI_GET_POC_VER);//
- break;
- }
- else if(PocGetTypeCnt==2){
- hgs_poc_type=POC_NULL;
- SlwTrace(INF, "GetPocVer fail",1);
- }
- }
- else{
- if(PocGetTypeCnt==0){
- hgs_poc_type=POC_OWN;
- ModemSendAt("AT+POC=050000\r\n");
- }
- else if(PocGetTypeCnt==1){
- hgs_poc_type=POC_BND;
- ModemSendAt("AT+LSPA=1\r\n");
- }
- getPocVersion(msg,hgs_poc_type);
- }
- PocGetTypeCnt=0;
- mInitSwitchStatus(MINI_SET_TTSPARM);
- break;
-
- case MINI_SET_TTSPARM:
- if(result != 1) SlwTrace(INF, "SetTTSPARAM fail",1);
- else SlwTrace(INF, "SetTTSPARAM OK",1);
- // if(hgs_poc_type==POC_OWN)mInitSwitchStatus(MINI_CHEAK_HEADSET);//
- // else {
- // mInitSwitchStatus(MINI_GET_MODULE);
- // }
- mInitSwitchStatus(MINI_GET_MODULE);
-
- break;
-
- case MINI_SET_MICLV://目前未使用
- if(result != 1) SlwTrace(INF, "SET_MICLV fail",1);
- else SlwTrace(INF, "SET_MICLV OK",1);
- mInitSwitchStatus(MINI_CHEAK_HEADSET);
- break;
-
- case MINI_CHEAK_HEADSET:
- if(result != 1) SlwTrace(INF, "CHEAK_HEADSET fail",1);
- else{
- SlwTrace(INF, "CHEAK_HEADSET OK",1);
- if(msg[9]=='0'){
- sutPocStatus.HeadSetPtt=1;
- // ModemSendAt("AT+AUDCH=1,3\r\n");
- printf("耳机接入-----\r\n");
- }
- else if(msg[9]=='1'){
-
- ModemSendAt("AT+AUDCH=0,0\r\n");
- printf("耳机未接入----\r\n");
- }
- }
- mInitSwitchStatus(MINI_GET_MODULE);
- break;
-
- case MINI_GET_MODULE:
- if(result != 1) SlwTrace(INF, "GetModemModule fail",1);
- else getModemModule(msg);
- uTimerHardDly(100);
- HeadsetProcess(1);
- /***********************************/
- uTimerHardDly(50);
- ModemSendAt(FirmSperkr);
- uTimerHardDly(50);
- ModemSendAt(FirmSperkr2);
- mInitSwitchStatus(MINI_PLY_ICCID);
- break;
-
-
- case MINI_PLY_ICCID:
- if(result != 1) SlwTrace(INF, "GetICCID fail",1);
- else ModemGetICCID(msg);
- mInitSwitchStatus(MINI_GET_SIMSELECT);
- break;
-
- case MINI_GET_SIMSELECT:
- if(result != 1) SlwTrace(INF, "GetSIMSelect fail",1);
- else SIMSelect=atoi(&msg[10]);
-
- if(hgs_poc_type==POC_OWN)mInitSwitchStatus(MINI_SET_TONES);
- else mInitSwitchStatus(MINI_READ_SPKLV);
- break;
-
- case MINI_SET_TONES:
- if(result != 1) SlwTrace(INF, "SetTones fail",1);
- else SlwTrace(INF, "SetTones_Ok",1);
- mInitSwitchStatus(MINI_READ_SPKLV);
- break;
-
- case MINI_READ_SPKLV:
- //+CLVL:60
- if(result!=1) SlwTrace(INF, "ReadSpkLv fail",1);
- else{
- SetSpkLvProcess(2);
- if(newPara.VolumLv!=atoi(&msg[6])/10){
- snprintf(buf,sizeof(buf),"AT+CLVL=%d\r\n",newPara.VolumLv*10);//num
- printf("VolumLv=%d\r\n",newPara.VolumLv);
- ModemSendAt(buf);
- }
-
- SlwTrace(INF, "SetSPKlv OK",1);
- }
-
- TTSPlayTick=uSysTickGet()+500;//5S后 才播报TONE音
- if(hgs_poc_type==POC_BND){
- g_uiGpsStat=0;
- newPara.gpsTimeIndex=0;
- snprintf(buf,sizeof(buf),"AT+POC=ttsvol=%d\r\n",newPara.VolumLv);
- ModemSendAt(buf);
- SpeakerCtrl(1);
- if(newPara.KeySound==0)ModemSendAt("AT+POC=tonevol=0\r\n");
- else {
- //ModemSendAt("AT+POC=tonevol=%d\r\n",newPara.VolumLv);
- snprintf(buf,sizeof(buf),"AT+POC=tonevol=%d\r\n",newPara.VolumLv);
- ModemSendAt(buf);
- }
- mInitSwitchStatus(MINI_GET_CARD);
- }else {
- mInitSwitchStatus(MINI_SET_GPSPARM);
- }
- if(FirstInitTTS==0){
- SpeakTTSVoice();
- FirstInitTTS=1;
- }
-
- break;
- case MINI_SET_GPSPARM:
- if(result!=1) SlwTrace(INF, "GetGPSstatue fail",1);
- else {
- if(msg[6]=='N'){
- if(!g_uiGpsStat){
- ModemSendAt("AT+GPS=\"OFF\"\r\n");
- //AT+VIBCTRL
- ModemSendAt("AT+VIBCTRL=\"POWER\",\"OFF\"\r\n");
- printf("close GPS--%d\r\n",g_uiGpsStat);
- }
- }else{
- if(g_uiGpsStat){
- ModemSendAt("AT+GPS=\"ON\"\r\n");
- ModemSendAt("AT+VIBCTRL=\"POWER\",\"ON\"\r\n");
- printf("open GPS--%d\r\n",g_uiGpsStat);
- }
- }
- SlwTrace(INF, "Seting GPS",1);
- }
- if(g_uiGpsStat)ModemSendAt("AT+GPSANT=1\r\n");
- if(hgs_poc_type==POC_OWN)mInitSwitchStatus(MINI_GET_POC_CODE);
- else mInitSwitchStatus(MINI_GET_CARD);
- CardStatue=0x11;
- break;
-
- case MINI_GET_POC_CODE:
- if(result!=1) SlwTrace(INF, "GetPocCode fail",1);
- else getPocCode(msg);
- mInitSwitchStatus(MINI_GET_CARD);
- break;
-
- case MINI_GET_CARD:
- switch(ChekCardCnt){
- case 0:
- if(result != 1)CardStatue&=0x10;
- else {
- goto CARDREDY;
- }
- SIMSelect=!SIMSelect;
- snprintf(buf,sizeof(buf),"AT+SIMCROSS=%d\r\n",SIMSelect);
- ModemSendAt(buf);
- uTimerHardDly(100);
- ret=-3;
- ChekCardCnt=1;
- sutPocStatus.modemRstFlag=1;
- break;
-
- case 1:
- ChekCardCnt=0;
- if(result != 1){
- CardStatue&=0x01;
- ret=-2;
- break;
- }
-
- CARDREDY:
- SlwTrace(INF, "Card Ready",1);
- sutPocStatus.CardStatus=1;//卡准备好
- if(hgs_poc_type==POC_OWN){
- ModemSendAt("AT+POC=10000020\r\n");
- mInitSwitchStatus(MINI_POC_PARA);
- }
- else {
- ModemSendAt("AT+POC=open,1,1\r\n");
- ret=1;
- }
- break;
- }
- break;
-
- case MINI_POC_PARA:
-
- if(result != 1) SlwTrace(INF, "GetPocPara fail",1);
- else ModemSetPocPara(msg,pMsg->MsgLen);
- ModemApnConfig();
- //ModemSendAt("AT+ROUTE=0,1\r\n");//打开POClog
- ModemSendAt("AT+POC=030000\r\n");
- ret=1;
- break;
- }
- return ret;
- }
- PT_THREAD (ptModemInitTask(struct pt *pt))
- {
- static timer_t ptTimer;
- static unsigned char intCmd;
- static unsigned char status;
- static short i,t;
- short ret;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- PT_BEGIN(pt);
- while(1){
- M_RESTART:
- SlwTrace(INF,"ModemInit...",1);
- memset((unsigned char *)&sutPocStatus, 0, sizeof(SUT_POC_STATUS));
- SetLedIndicator(IndNoNet);
- sutPocStatus.modemRstFlag=0;
- modemInitReady=0;
- modemInitStatus=0;
- MsgQueueSet();
-
- MODEM_PWREN_HIGH;
- PTTimerStart(&pt_timerPool, &ptTimer, 200);
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- MODEM_PWREN_LOW;
- PTTimerStart(&pt_timerPool, &ptTimer, 200);
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- mInitSwitchStatus(MINI_WAT_START);
- modemInitReady=1;
- sutPocStatus.ModemPowerOn=1;
- SEND_WAIT_PRO:
- status=0;
- for(i=0;i<timeOut;i++){//共等60*500=30000ms
- ModemSendAt(SendAT);
- t=25;//以下等20*25=500ms
- while(t--){
- if(g_ucEnterGTNow!=0||USBSeletCt>1) goto INIT_DONE;//使得GT可以直接跳出初始化过程 //或者升级模块模式直接跳转
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData)))){
- //printf("Ack:%s",pMsg->MsgData);调试
- if(0==ModemStrCmp((char *)pMsg->MsgData,"+POC:8B0002")) SpeakerEnable();//wjl
- else if(0==ModemStrCmp((char *)pMsg->MsgData,"+POC:8B0000")) SpeakerDisable();//wjl
- if(0==ModemStrCmp((char *)pMsg->MsgData,WaitAT1) ||
- 0==ModemStrCmp((char *)pMsg->MsgData,WaitAT2)){
- status=1;
- goto SEND_GET_RET;
- }
- }else{
- PTTimerStart(&pt_timerPool, &ptTimer, 2);
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }
- }
- }
- SEND_GET_RET:
- ret=ModemInitAckHandler(status);
- //ret=-1;
- if(ret ==0) goto SEND_WAIT_PRO;
- else if(ret<0){//模块启动失败/卡不在
- if(ret==-1){
- SlwTrace(INF, "ModemInitTimeout GT Mode",1);
- EnterGTMode();
- }else if(ret==-2){
- SlwTrace(INF, "insert card error----",1);
- sutPocStatus.loginResult=4;
- }
- }
- INIT_DONE:
- //初始化完成
- modemInitStatus=1;//可以消耗模块消息队列了
- g_ucModemTaskEn=1;
-
- while(1){
- if(sutPocStatus.modemRstFlag!=0){
- printf("reset modem----\r\n");
- MODEM_RESET_HIGH;
- PTTimerStart(&pt_timerPool, &ptTimer, 300);
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- MODEM_RESET_LOW;
- goto M_RESTART;
- }
- //sutPocStatus.ModemInactiveCt=0; /****************V113守护进程BUG********/
- PTTimerStart(&pt_timerPool, &ptTimer, 100);//100
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }
- }
- PT_END(pt);
- }
- void InfoTick(void){
- static unsigned int tick;
- if(g_ucEnterGTNow) return;
- if(uTimerExpired(&tick)){
- uTimerStart(&tick, 500);
- printf("Info:Auth[%d],GT[%d],MI[%d],UI[%d] \r\n",sutGpsInfo.isGpsAuthOk,g_ucEnterGTNow,modemInitStatus,sutUIstatus.Status);
- }
- }
- static void AtHandle(char *msg);
- void ModemATProcess(void){
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- if(modemInitStatus==0) return;
- while(1){
- pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData));
- if(pMsg->MsgLen>0){
- if(g_ucEnterGTNow!=0||USBSeletCt>1) continue;//如果进入GT模式,不需要处理模块消息了
- SlwTrace(INF, (char *)pMsg->MsgData,0);
- sutPocStatus.ModemInactiveCt=0;
- if(pMsg->MsgData[0]=='+' || pMsg->MsgData[0] == '^'){
- if(1 == PocHandle((char *)pMsg->MsgData)) continue;
- AtHandle((char *)pMsg->MsgData);
- }else if(pMsg->MsgData[0]=='$'&&pMsg->MsgData[3]=='R'&&pMsg->MsgData[5]=='C'){
- process_gps_data((char*)&pMsg->MsgData[7],pMsg->MsgLen);
- sutGpsInfo.isGpsWork=1;
- }
- continue;
- }else if(pMsg->MsgLen<0){
- SlwTrace(INF, "QueueF1",1);
- continue;
- }
- break;
- }
- }
- void ModemLedCtl(void){
-
- if(g_ucModemTaskEn==0||g_ucEnterGTNow!=0) return;
- if(0==sutPocStatus.Logined)SetLedIndicator(IndNoNet);
- else if(sutPocStatus.Speaker>0)SetLedIndicator(IndRX);
- else if(sutPocStatus.Mic>0 )SetLedIndicator(IndTX);
- else SetLedIndicator(IndStandby);
- }
- static void AtHandle(char *pMsg)
- {
- int csq;
- short targetIndex;
- unsigned char tempSocket,i,temp;
- unsigned short tempLen;
- char buf[80]="\r\n";
- char bufTemp[3];
- char buf3[40];
- static char Timerequest=0;
- STATUE ipStatus;
- if(0==ModemStrCmp(pMsg,"^SYSINFO:")){
- if(pMsg[15]!=','){
- netshowvalue=atoi(&pMsg[15]);
- }else{
- netshowvalue=atoi(&pMsg[16]);
- }
- }else if(0==ModemStrCmp(pMsg,"+CSQ:"))
- {
- g_iCSQ=atoi(&pMsg[6]);
-
-
- }else if(0==ModemStrCmp(pMsg,"+POC_PPP:")){
- if(pMsg[9]=='1') netPPP=OPEN;
- else netPPP=CLOSE;
- if(0==Timerequest&&netPPP==OPEN){
- Timerequest=1;
- ModemSendAt("AT+CCLK?\r\n");
- }
- }else if(0==ModemStrCmp(pMsg,"+POC:npong,"))
- {
-
- if(pMsg[11]=='1'){
- netPPP=OPEN;
- }
- else netPPP=CLOSE;
-
- if(0==Timerequest&&netPPP==OPEN){
- Timerequest=1;
- ModemSendAt("AT+CCLK?\r\n");
- }
- }
- else if(0==ModemStrCmp(pMsg,"+TCPSTATUS:")){
- tcpSocketStatusUpdate(pMsg[11],pMsg[13],0);
- }else if(0==ModemStrCmp(pMsg,"+TCPRECV:")){//+TCPRECV:0,2,31
- if(-1 != (targetIndex=FindTargetIndex(pMsg, '\r', ":", 1,1))){
- tempSocket = atoi(&pMsg[targetIndex]);//找到socket
- if(-1 != (targetIndex=FindTargetIndex(pMsg, '\r', ",",1,1))){
- tempLen = atoi(&pMsg[targetIndex]);
- if(-1 != (targetIndex=FindTargetIndex(pMsg, '\r', ",",1,2))){
- tcpSocketRecv(tempSocket, &pMsg[targetIndex], tempLen);
- }
- }
- }
- }else if(0==ModemStrCmp(pMsg,"+TCPOPEN:")){
- tcpSocketStatusUpdate(pMsg[9],pMsg[11],0);
- }else if(0==ModemStrCmp(pMsg, "+TCPCLOSE:")){//主动关掉或者服务器关掉都是这样
- tcpSocketStatusUpdate(pMsg[10],NULL,1);
- }else if(0==ModemStrCmp(pMsg, "+CCLK:"))
- {
- ModemGetTime(pMsg);
- }else if(0==ModemStrCmp(pMsg, "^MODE:"))
- {//^MODE: 9 与下面位置不一,模块问题
- //^MODE:2 与上面位置不一,模块问题
- if(pMsg[6] == ' ') bufTemp[0]=pMsg[7];
- else bufTemp[0]=pMsg[6];
- snprintf(buf, sizeof(buf), "[Mode %c]", bufTemp[0]);
- switch(bufTemp[0])
- {
- case 0x30:strcat(buf, "No server");break;
- case 0x32:strcat(buf, "CDMA Mode");break;
- case 0x33:strcat(buf, "GSM");break;
- case 0x34:strcat(buf, "TD-SCDMA/EVDO");break;
- case 0x35:strcat(buf, "WCDMA");break;
- case 0x39:strcat(buf, "LTE");break;
- default:strcat(buf, "Unknow");break;
- }
- SlwTrace(INF, buf, 1);
- }else if(0==ModemStrCmp(pMsg, "+POC:START"))
- {
- sutPocStatus.modemRstFlag=1;
- sutPocStatus.ModemInactiveCt=0;//当模块重启后重新计数串口通讯异常计数器
- }
- else if(0==ModemStrCmp(pMsg, "+GGIP:"))
- { //GSPIP返回
- //+GPIP:183.131.13.10
- if(newPara.serList.defaultuse==SER_JIQUN||newPara.serList.defaultuse==SER_IP)chekPipGip(pMsg,1);
- //strcpy(gSocket.socketList[0].Ip,showGIP);//
- }else if(0==ModemStrCmp(pMsg, "+GPIP:"))
- {
- if(newPara.serList.defaultuse==SER_JIQUN||newPara.serList.defaultuse==SER_IP)chekPipGip(pMsg,0);
- }else if(0==ModemStrCmp(pMsg, "+FOTA:")){
- FotaStatusProcess(pMsg+6);
- uTimerStart(&fotaTick,10);
- }else if(0==ModemStrCmp(pMsg, "+POC:WAKEUP")){
- enableDataSend();
- }else if(0==ModemStrCmp(pMsg, "+UDP:")){
- GetPwrMode(pMsg+5);
- }else if(0==ModemStrCmp(pMsg, "+AUDCH"))//
- {
-
- }else if(0==ModemStrCmp(pMsg,"+CTEC:"))
- {
- tempnetshowvalue=atoi(&pMsg[7]);
- if(newPara.netMode!=tempnetshowvalue){
- snprintf(buf,sizeof(buf),"AT+CTEC=%d,%d\r\n",tempnetshowvalue,newPara.netMode);
- ModemSendAt(buf);
- }
- }else if(0==ModemStrCmp(pMsg,"+COPS")){
- //netshowvalue=atoi(&pMsg[FindContentByChar( pMsg,',',3)]);
- netshowvalue=atoi(FindContentByChar(pMsg,',',3,buf));
-
- }else if(0==ModemStrCmp(pMsg,"+HEADSET:"))
- {
-
- //InternalHeadSet(atoi(&pMsg[9]));
-
- }
- }
- void InternalHeadSet(char type)
- {
- switch(type)
- {
- case 0:
- sutPocStatus.HeadSetPtt=1;
- //ModemSendAt("AT+AUDCH=1,3\r\n");
- break;
- case 1:
- sutPocStatus.HeadSetPtt=0;
- ModemSendAt("AT+AUDCH=0,0\r\n");
- break;
-
- case 2:
- ModemSendAt("AT+POC=0B0000\r\n");
- break;
-
- case 3:
- ModemSendAt("AT+POC=0C0000\r\n");
- break;
- }
- }
- char *FindContentByChar( char *src,char c, char index,char *dest)
- {
- char i;
- char j=0;
- char *p=dest;
- for(i=0;i<strlen(src);i++)
- {
- if(src[i]==c)j++;
- if(j==index){
- p=&src[i+1];
- return p;
- }
- }
- }
- void chekPipGip(char *src,char type)
- {
- char buf[40];
- char *p;
- p=src+6;
- if(!type)snprintf(buf,sizeof(buf),"+GPIP:%s\r\n",showPIP);
- else snprintf(buf,sizeof(buf),"+GGIP:%s\r\n",showGIP);
- if(strlen(src)<9||(0==ModemStrCmp(src, "+GGIP:0.0.0.0"))||(0==strcmp(src,buf))||(0==ModemStrCmp(src, "+GPIP:0.0.0.0")))return ;
- if(!type){
- memcpy(showPIP,p,strlen(p)-2);
- showPIP[strlen(p)-2]=0;
- printf("get new PIP====%s\r\n",showPIP);
- }else{
- memcpy(showGIP,p,strlen(p)-2);
- showGIP[strlen(p)-2]=0;
- printf("get new GIP====%s\r\n",showGIP);
- strcpy(gSocket.socketList[0].Ip,showGIP);
- }
- }
- int CodecFileInit(void)
- {
- int len;
- char tempData[400];
- char CodecFileIndex=0;
- int tempLen,i;
- char *p=NULL;
- char tempbuf[40];
- unsigned short PreRead;
- int StartAddr=0;
-
-
- CodecFileIndex=GetFileIndex("Audio.ini");
-
- if(CodecFileIndex == -1)
- {
- printf("No Audio.ini file\r\n");
- return -1;
- }
-
- len=GetFileLen(CodecFileIndex);
- printf("Audio.ini len===%d\r\n",len);
-
- if(len==0)
- {
- printf("Audio.ini empty\r\n");
- return-2;
- }
-
- while(len==0){
-
- if(len>400)PreRead=400;
- else PreRead=len;
-
- tempLen=ReadFileData(CodecFileIndex,StartAddr,PreRead,(u8*)tempData);
- len-=PreRead;
- StartAddr+=PreRead;
- snprintf(tempbuf,sizeof(tempbuf),"AT+CAIET=0,0,%d,%d,\"",StartAddr,PreRead);
- ModemSendAt(tempbuf);
- ModemSendData(tempData,PreRead);
- ModemSendAt("\"\r\n");
- }
-
- return 0;
- }
|