123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- /********************************************************************************
- * 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;
- YUNYINGSHANG_DEF thisYunYingShang=CHINA_NONE;
- void WarnTTSReport(void);
- /*******************************************************************
- *ModemUartTask
- ********************************************************************/
- __task void ModemUartTask(void)
- {
- os_sem_init (&ModemUartSem, 0);
- while(1)
- {
- os_sem_wait (&ModemUartSem, 0xffff);
- Uart2RecvProcess();
- }
- }
- /*******************************************************************
- *ModemTask
- ********************************************************************/
- __task void ModemTask(void)
- {
- unsigned char i;
- unsigned short susCt=0;
- static unsigned int Second2Cnt=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;
- snprintf(buf, sizeof(buf), "[01]hardID:%s", sutNewSegmentPara.HARDID);
- SlwTrace(INF, buf,1);
-
- SlwTrace(INF,"Modem Task start!",1);
- SlwTrace(INF,"ModemInit...",1);
- MODEM_RESTART:
- modemInitReady=0;
- PWR_EN_HIGH;
- SetLedIndicator(IndNoNet);
- memset((unsigned char *)&sutPocStatus,0,sizeof(SUT_POC_STATUS));
- //1、模块初始化:通过能否检测到MEID
- if(ModemInit())
- {//成功
- //sprintf(buf, "[01]IMEI:%s", sutProductPara.IMEI);
- SlwTrace(INF, buf,1);
- }else
- {//模块初始化失败,进入GT模式,为了升级模块
- PWR_EN_LOW;
- SlwTrace(INF,"[01]Failed\r\nEnter GT Mode!",1);
- // SlwTrace(INF,"GT+TM:OK",1);//进入GT+TM
- // ComSelect(COM_SEL_MODEM); //
- EnterGTMode();
- while(1)
- {
- sutPocStatus.ModemInactiveCt=0;
- os_dly_wait(100);
- }
- }
- if(GPIO_ReadInputDataBit(ONOFF_CK_PORT,ONOFF_CK_PIN)==1)
- modemPwrOffNow=1;
- else PWR_EN_LOW;
- modemInitReady=1;
-
- //2、关闭回显示
- ModemSendAT("ATE0\r\n");
- SlwTrace(INF, "[02]ATE0 OK",1);
- //3、获取模块版本
- ModemInfo();
- //4、POC version check
- ModemPocVersionCheck();
- //5、查询IMEI
- // if(ModemGetIMEI())
- // {
- // sprintf(buf, "[05]IMEI:%s", sutProductPara.IMEI);
- // SlwTrace(INF, buf,1);
- // }else SlwTrace(INF, "[05]IMEI:Failed",1);
- //6、配置TTS语音速度
- ModemSetSpeed();
- //7、配置音量
- VolumeSet();
- //8、检测卡是否存在
- if(0==ModemCheckUIM())
- {//卡不在位,循环播报请插卡
- susCt=3500;
- GPSRestart();
- while(1)
- {
-
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- continue;
- }
- else os_dly_wait(1);
- if(g_usRx3Len>0)
- {
- process_nema((char *)RxBuffer3);
- g_usRx3Len=0;
- }
- sutPocStatus.ModemInactiveCt=0;
- if(0==g_ucModemTaskEn)continue;
- if(++susCt>=1000)susCt=0;
- else continue;
- MeSpeak(ENCODE_UNICODE,"F78BD2636153",0);
- //os_dly_wait(200);
- SpeakerDisable();
- SlwTrace(INF,"[08]No UIM Card!",1);
- }
- }else SlwTrace(INF, "[08]Card ready",1);
- //9、查询CCID
- ModemGetCCID();
- //10、检查并重新设置POC参数
- if(ModemCheckPocParam()) SlwTrace(INF,"[10]Rst_POCPara",1);
- else SlwTrace(INF, "[10]POC still",1);
- //11、设置APN
- ModemApnConfig();
- //12、集群功能初始化数据
- SlwTrace(INF, "[12]HigosSerInit",1);
- HigosInit();
- //12、GPS配置
- GPSRestart();
- sutPocStatus.ModemPowerOn=1;
- SlwTrace(INF, "ModemLoopStart",1);
- while(1)
- {
- if(0==g_ucModemTaskEn)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- SlwTrace(INF,(char *)pMsg->MsgData,0);
- if(0==ModemStrCmp(pMsg->MsgData,"^MSG:Quit")){
- SetLedIndicator(IndReboot);//红灯闪表示升级完成(无论成功与否),用户需要重启设备
- }
- #if(USE_CONFIG_FUN==1)
- SlwTrace(INF,(char *)pMsg->MsgData,0);
- AtHandle(pMsg->MsgData);
- continue;
- #endif
- }else os_dly_wait(1);
- #if(USE_CONFIG_FUN==1)
- ConfigCtrHandle();
- #endif
- continue;
- }
-
- //Modem Uart消息处理,等待1个系统tick, 大约等待10ms
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- if(pMsg->MsgData[0]=='+' || pMsg->MsgData[0] == '$')
- {
- sutPocStatus.ModemInactiveCt=0;
- SlwTrace(INF,(char *)pMsg->MsgData,0);
- }else{
- continue;
- }
- if(1 == PocHandle((char *)pMsg->MsgData)) continue;
- AtHandle((char *)pMsg->MsgData);
- 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);
- if(sutGpsStatus.PPPStatus==OPEN)
- HigosTick();
- SMSHandle();
- WarnTTSReport();
- if(sutPocStatus.modemRstFlag !=0) goto MODEM_RESTART;
-
- if(os_time_get() < Second2Cnt) continue;
- Second2Cnt = os_time_get() + 300;
- ModemSendAT("AT+MODODREX?\r\n");
- os_dly_wait(1);
- ModemSendAT("AT+LCTMOBAPREF?\r\n");
- }
- }
- void WarnTTSReport(void)
- {
- static unsigned int cnt=0;
- if(sutPocStatus.FirstLogined==0) return;
- if(sutPocStatus.Logined==1)
- {
- sutPocStatus.reportTimeCnt1=0;
- sutPocStatus.reportTimeCnt2=0;
- return;
- }
- if(os_time_get() < cnt) return;
- cnt=os_time_get()+100;
-
- 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);
- }
- }
- /*******************************************************************************/
|