123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- /********************************************************************************
- * File Name: ModemTask.c
- * Function Describe: 完成串口与Modem的通讯
- * Explain:
- * Writer: ShiLiangWen
- * Date: 2015-8-2
- *******************************************************************************/
- #define THIS_FILE_ID 17
- /*******************************************************************************/
- #include "includes.h"
- OS_TID idModemTask=0;
- U64 stkModemTask[MODEM_TASK_STK_SIZE];
- OS_TID idModemUartTask=0;
- U64 stkModemUartTask[MODEM_UART_TASK_STK_SIZE];
- OS_SEM ModemUartSem;
- unsigned char g_ucModemTaskEn=0;
- unsigned char g_ucQuitModemInitNow=0;//此值设置时,无论公网处于何种操作,马上退出,主要针对ModemTask进入WHILE前的判断
- unsigned short g_usModemProtectEn=0;
- FEEDBACK_DEF sutFeed;
- SUPPORT_TYPE support_type=Un_Known;
- YUNYINGSHANG_DEF thisYunYingShang=CHINA_NONE;
- int WaitModemReady(void);
- void WarnTTSReport(void);
- /*******************************************************************
- *ModemUartTask
- ********************************************************************/
- __task void ModemUartTask(void)
- {
- os_sem_init (&ModemUartSem, 0);
- while(1){
- os_sem_wait (&ModemUartSem, 0xffff);
- Uart2RecvProcess();
- }
- }
- void SoSDetected(void)
- {
- static char tCnt=0;
- static unsigned int TickCnt=0;
- if(sutPocStatus.SOS_Flag==1)
- {
- if(os_time_get() < TickCnt) return;
- TickCnt=os_time_get()+15;
- if(++tCnt <=2)
- {
- SpeakerEnable();
- SetBeep(500,10);
- }
- else {
- sutPocStatus.SOS_Flag=0;
- tCnt=0;
- TickCnt=0;
- }
- }
- }
- //测试定位时间
- unsigned int locationTime=0;
- unsigned char locationflag=0;
- /*******************************************************************
- *ModemTask
- ********************************************************************/
- __task void ModemTask(void)
- {
- #ifdef SLW_DEBUG
- unsigned short MsgBoxCheck;
- unsigned short MinMsgBoxCheck=20;
- #endif
- static unsigned int sucCt=0;
-
- unsigned char i;
- unsigned short susCt=0;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- char buf[40];
- g_ucModemTaskEn=1;
- SlwTrace(INF,"Poc Task start!",1);
-
- //GPS相关初始化
- GpsTaskTick(1);
- g_ucModemSentTcpCt=0;
- //TSGpsDataInit();
- sutGpsStatus.PPPStatus=INVALID;
- sutGpsStatus.IPStatus=INVALID;
- sutGpsStatus.CheckCnt=0;
- SlwTrace(INF,"Modem Task start!",1);
- MODEM_RESTART:
- SlwTrace(INF,"ModemInit...",1);
- SetLedIndicator(IndNoNet);
- PWR_EN_HIGH;
- sutPocStatus.modemRstFlag=0;
- sutPocStatus.loginResult=0;
- sutPocStatus.Logined=0;
- modemInitReady=0;
- g_iPocVer=0;
-
- sutGpsInfo.locationTime=os_time_get();//
-
- //soc ID替代IMEI
- if(GetUniStringByID(DEV_HARDID)==1){
- snprintf(buf, sizeof(buf), "[01]hardID:%s", DEV_HARDID);
- SlwTrace(INF, buf,1);
- }
-
- //1、模块初始化
- if(ModemInit())
- {//成功
-
- }else
- {//模块初始化失败,进入GT模式,为了升级模块
- bootFlag=1;
- PWR_EN_LOW;
- SlwTrace(INF,"[01]Failed\r\nEnter GT Mode!",1);
- EnterGTMode();
- while(1)
- {
- sutPocStatus.ModemInactiveCt=0;
- os_dly_wait(100);
- }
- }
-
- if(0!=ModemLCCCheck()){
- goto MODEM_RESTART;
- }
- if(GPIO_ReadInputDataBit(ONOFF_CK_PORT,ONOFF_CK_PIN)==1)
- modemPwrOffNow=1;
- else PWR_EN_LOW;
- modemInitReady=1;
-
- //暂停POC
- ModemSendAT("AT+POC=050000\r\n");
- //2??????
- ModemSendAT("ATE0\r\n");
- SlwTrace(INF, "[02]ATE0 OK",1);
-
- os_dly_wait(250);
- //3、获取模块版本
- ModemInfo();
- //4、POC version check
- ModemPocVersionCheck();CheckPocType();ModemOwnPocSet();
- //5、查询IMEI
- ModemGetPocCodeType();
- //6、配置TTS语音速度
- ModemSetSpeed();os_dly_wait(50);
- //7、配置音量
- VolumeSet();
- /*****************************/
- VolumeSetSpk();
- VolumeSetMIC();
- CodecFileInit();
- SpeakTTSVoice();//定制化开机播报语
-
- //8、检测卡是否存在
- if(0==ModemCheckUIM())
- {//卡不在位,循环播报请插卡
- sutPocStatus.loginResult=4;
- susCt=3500;
- //SetPowerEn(0);
- GPSInit();
- while(1)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- continue;
- }
- else os_dly_wait(1);
- sutPocStatus.ModemInactiveCt=0;
- if(0==g_ucModemTaskEn)continue;
- //GPS Uart消息处理
- if(g_usUart3RecvLen){
- process_nema((char *)RxBuffer3);
- g_usUart3RecvLen=0;
- }
- }
- }else SlwTrace(INF, "[08]Card ready",1);
-
-
- //9、查询CCID
- ModemGetCCID();ResetNetConfi();
- //10、检查并重新设置POC参数
- if(ModemCheckPocParam()) SlwTrace(INF,"[10]Rst_POCPara",1);
- else SlwTrace(INF, "[10]POC still",1);
- sutPocStatus.ModemPowerOn=1;
- //SetPowerEn(0);
- //11、设置APN
- ModemApnConfig();
- //12、集群功能初始化数据
- SlwTrace(INF, "[12]HigosSerInit",1);
- //HigosInit();
- //ConolyInit();
-
-
- //13、GPS配置
- GPSInit();
- GpsTimeUpdate();
-
- //14、设置成员获取简单模式
- SetModemPocSimpleMode();
-
- SlwTrace(INF, "ModemLoopStart",1);
-
- //15、检查并设置POCFOTA域名
- if(ModemCheckFotaDomain()) SlwTrace(INF,"[15]Rst_FotaDomain",1);
- else SlwTrace(INF, "[15]FotaDomain still",1);
- //启动POC
- ModemSendAT("AT+POC=030000\r\n");
-
- while(1)
- {
- if(0==g_ucModemTaskEn)
- {
- pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData));
- if(pMsg->MsgLen > 0)
- {
- SlwTrace(INF,(char *)pMsg->MsgData,0);
- AtHandle(pMsg->MsgData);
- continue;
- }else if(pMsg->MsgLen < 0)
- {
- SlwTrace(INF, "QueueF1",1);
- continue;
- }
- else os_dly_wait(1);
- #if(USE_CONFIG_FUN==1)
- ConfigCtrHandle();
- #endif
- continue;
- }
-
- pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData));
- if(pMsg->MsgLen > 0)
- {
- if(pMsg->MsgData[0] == '\r' && pMsg->MsgData[1] == '\n') continue;
- #if ENABL_FOGA_BACK_DATA_PRINT
- if(Fota_Rcv_Pri_Flag)
- #endif
- SlwTrace(INF,(char *)pMsg->MsgData,0);
- FotaIap_Handle((char *)pMsg->MsgData);
- sutPocStatus.ModemInactiveCt=0;
-
- if(pMsg->MsgData[0]=='+' || pMsg->MsgData[0] == '^')
- {
- if(1 == PocHandle((char *)pMsg->MsgData)) continue;
- AtHandle((char *)pMsg->MsgData);
- }
- continue;
- }else if(pMsg->MsgLen < 0)
- {
- SlwTrace(INF, "QueueF1",1);
- continue;
- }
- else os_dly_wait(1);
-
- //---指示灯设置---
- if(0==sutPocStatus.Logined)SetLedIndicator(IndNoNet);
- else if(sutPocStatus.Speaker>0)SetLedIndicator(IndRX);
- else if(sutPocStatus.Mic>0 && sutPocStatus.PPTpress>0)SetLedIndicator(IndTX);
- else SetLedIndicator(IndStandby);
-
- //以下控制GPS上传
- GpsTaskTick(0);//GPS功能打开。
- if(sutGpsStatus.PPPStatus==OPEN)
- SMSHandle();
- SoSDetected();
- WarnTTSReport();
- if(sutPocStatus.modemRstFlag !=0) goto MODEM_RESTART;
- if(os_time_get() < sucCt) continue;
- sucCt = os_time_get()+100;//
- AtQuery();
- }
- }
- void WarnTTSReport(void)
- {
- static unsigned char cnt=0;
- if(sutPocStatus.FirstLogined==0) return;
- if(sutPocStatus.Logined==1)
- {
- sutPocStatus.reportTimeCnt1=0;
- sutPocStatus.reportTimeCnt2=0;
- return;
- }
- if(++cnt< 99) return;
- cnt=0;
- if(sutPocStatus.reportTimeCnt1 < 250) sutPocStatus.reportTimeCnt1++;
- if(sutPocStatus.reportTimeCnt2 < 250) sutPocStatus.reportTimeCnt2++;
- }
- void Modem_Stopinit()
- {
- PWR_EN_LOW;
- SlwTrace(INF, "go GT_Mode\r\n",1);
- EnterGTMode();
-
- while(1)
- {
- sutPocStatus.ModemInactiveCt = 0;
- os_dly_wait(100);
- }
- }
- /*******************************************************************************/
|