123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- /********************************************************************************
- * 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_uGtTaskEn=0; //进入写号模式
- unsigned char g_uGtFactory=0;
- unsigned char g_ucQuitModemInitNow=0;//此值设置时,无论公网处于何种操作,马上退出,主要针对ModemTask进入WHILE前的判断
- FEEDBACK_DEF sutFeed;
- SUPPORT_TYPE support_type=Un_Known;
- Modem_TYPE Modem_type=Un_KnownModem;
- YUNYINGSHANG_DEF thisYunYingShang=CHINA_NONE;
- int WaitModemReady(void);
- /*******************************************************************
- *ModemUartTask
- ********************************************************************/
- __task void ModemUartTask(void)
- {
- os_sem_init (&ModemUartSem, 0);
- while(1){
- os_sem_wait (&ModemUartSem, 0xffff);
- Uart2RecvProcess();
- }
- }
- /*******************************************************************
- *ModemTask
- ********************************************************************/
- __task void ModemTask(void)
- {
-
- static unsigned char sucPocLostTimeoutCount=0;//
- static unsigned char sucModemInactiveCount=0;
- RCC_ClocksTypeDef User_Rcc_Clock;
-
- #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 PrintfBuf[20];
- 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);
-
- EnterGTProcess();/*************M20检测写号*********************/
- GtFactory_XIEHAO(0); //写号死等
- MODEM_RESTART:
- SlwTrace(INF,"ModemInit...",1);
- sutPocStatus.modemRstFlag=0;
- sutPocStatus.ModemInactiveCt=0;//
- sutPocStatus.loginResult=0;
- modemInitReady=0;
- PWR_EN_HIGH;
-
- USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //这个中断开过早,系统会崩
- printf("\r\n%s_V%d.%d Start...\r\n",sutProductPara.ProductName,sutProductPara.ProductVersion,INTER_VER);
- os_dly_wait(100);//gps会受到模块刚开机的干扰,而定位变差
- sutPocStatus.Prepare=1;
- //
- //1、模块初始
- if(ModemInit())
- {//成功
- SlwTrace(INF,"[01] Modem Init OK",1);
- }else
- {
-
- //模块初始化失败,进入GT模式,为了升级模块
- bootFlag=1;
- PWR_EN_HIGH;
- SlwTrace(INF,"[01]Failed\r\nEnter GT Mode!",1);
- EnterGTMode();
- IWDG_ReloadCounter();
- while(1)
- {
- sutPocStatus.ModemInactiveCt=0;
- os_dly_wait(100);
- }
- }
-
- SetLedIndicator(IndNoNet);
- GtFactory_XIEHAO(1);
- RCC_GetClocksFreq(&User_Rcc_Clock);
- snprintf(PrintfBuf,sizeof(PrintfBuf),"Clock===%d\r\n",User_Rcc_Clock.SYSCLK_Frequency);
- SlwTrace(INF,PrintfBuf,1);
- modemInitReady=1;
- if(WaitPocInit())goto MODEM_RESTART;
- SpeakerEnable();
-
- GetPocVer();
- GetModemVer();
- VolumeSet();
- modemInitReady=2;
- Ear_check(1);
- // //apn接入点设置
- // APNSet();
- // ModemGetCCID();
- // //判断国内还是国外
- // GetCountry();
- // //开机设置网络模式
- // ModemNetSet();
- // //检测卡是否存在
- if(0==ModemCheckUIM())
- {//卡不在位,循环播报请插卡
- sutPocStatus.loginResult=4;
- susCt=3500;
- //SetPowerEn(0);
- if(sutGpsInfo.Updata==1){
- GPSInit();
- }
- sutPocStatus.Modeminited=1;
- 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, "[2]Card ready",1);
- //开机发送二次
- LoginPocInfo();
- sutPocStatus.Modeminited=1;
-
- while(1)
- {
- GOWHILE:
- if(0==g_ucModemTaskEn)
- {
- sutPocStatus.ModemInactiveCt=0;
-
- pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData));
- if(pMsg->MsgLen > 0)
- {
- sutPocStatus.ModemInactiveCt=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);
- continue;
- }
-
- pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData));
- if(pMsg->MsgLen > 0)
- {
- sutPocStatus.ModemInactiveCt=0;
- if(pMsg->MsgData[0]=='+' || pMsg->MsgData[0] == '^')
- {
- AtHandle((char *)pMsg->MsgData);
- continue;
- }
- ZXPocHandle((char *)pMsg->MsgData,pMsg->MsgLen);
- 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.PPTpress>0)SetLedIndicator(IndTX);
- else if(((Vbat-340)*100/(430-340))<15)SetLedIndicator(InVbatLow);
- else SetLedIndicator(IndStandby);
- //以下控制GPS上传
- //GpsTaskTick(0);//GPS功能打开。
- if(sutPocStatus.modemRstFlag !=0) goto MODEM_RESTART;
- if(os_time_get() < sucCt) continue;
- sucCt = os_time_get()+100;//
- AtQuery();
- }
- }
- void Vbatsend()
- {
- static unsigned char VbatSendct=0;// 定时发送
- char PrintfBuf[20];
- if(sutPocStatus.Modeminited==0)return;
- if(g_ucModemTaskEn==0)return;
- if(BOOTDebug==1)return;
-
- if(VbatSendct<250) {
- VbatSendct++;
- if(VbatSendct%30==0){
- //SEND Vbat
- if(Vbat>330&&ChangeIng!=1){
- if(Vbat>435)snprintf(PrintfBuf,sizeof(PrintfBuf),"AT+POC=522&%d&%d\r\n",100,g_iCSQ);
- else snprintf(PrintfBuf,sizeof(PrintfBuf),"AT+POC=522&%d&%d\r\n",(Vbat-340)*100/(430-340),g_iCSQ);//435
- ModemSendAT(PrintfBuf);
- SlwTrace(INF,PrintfBuf,1);
- VbatSendct=0;
- }
- // os_dly_wait(10);
- // ModemSendAT("AT+POC=606\r\n");//心跳
- }
-
- }else VbatSendct=0;
- }
- void Modem_Stopinit()
- {
- //PWR_EN_LOW;
- SlwTrace(INF, "go GT_Mode\r\n",1);
- EnterGTMode();
- while(1)
- {
- sutPocStatus.ModemInactiveCt = 0;
- os_dly_wait(100);
- }
- }
- void GtFactory_XIEHAO(char type)
- {
- char flag=0;
- if(!type){
- if(g_uGtTaskEn==1) flag=1;
- }else{
- if(g_uGtFactory==1){
- flag=1;
- ModemSendAT(RF_TEST);
- SlwTrace(INF,RF_TEST,1);
- }
- }
- if(flag){
- while(1)
- {
- sutPocStatus.ModemInactiveCt=0;
- os_dly_wait(100);
- }
- }
- }
- /*******************************************************************************/
|