/* main.c authod: wjl 应用程序主要使用pt来完成 */ #include "includes.h" //pt任务部分声明 pt_timer_t pt_timerPool; struct pt pt_NetWorkTask; struct pt pt_QueueComReadTask; struct pt pt_QueueRecordReadTask; struct pt pt_DomainTask; struct pt pt_TTSTask; struct pt pt_PlayerTask; struct pt pt_RecorderTask; struct pt pt_AuthLoginTask; struct pt pt_LocationTask; struct pt pt_McuIapTask; struct pt pt_LbsMotionTask; struct pt pt_HookTask; struct pt pt_NearTask; struct pt pt_VoiceUploadTask; struct pt pt_HearTickTask; #ifdef ENABLE_ANT_MODE struct pt pt_McuAckTask; #endif #if defined ENABLE_TICKET struct pt pt_TicketTask; #endif /*读取模块相关信息*/ void modemInfoRead(void){ snprintf(app.opVersion,sizeof(app.opVersion),"%s",LSAPI_SYS_getOPVERSION()); wlog_info("OpVersion:%s",app.opVersion); snprintf(app.fmVersion,sizeof(app.fmVersion),"%s",LSAPI_SYS_getFMVERSION()); wlog_info("FmVersion:%s",app.fmVersion); } /* ptTickRun pt 需要的时间池用于pt任务调试 */ void ptTickRun(void){ PTTimerTick(&pt_timerPool); //pt需要的系统时钟,最好是准确的 } //初始化数据及外设接口 static void InitStart(void){ if(0!=msgQueueSet()){//初始化消息队列 wlog_error("msgQueueSet err"); } app_init();//应用数据测试,需要比para_inits先调用 para_inits();//系统参数测试,需要在app_init后调用 recordsInit();//初始化记录文件区 authLoginInit(); onWorkChecking(TRUE); onWorkTimerInit(); userTimerInit(); bspInit();//外设部分初始化 #ifdef ENABLE_ANT_MODE wlog_info("%s VER:%s MODULE:%s TEST:%d CUST:%d ant mode start...", APP_NAME, APP_VERSION, APP_MODULE_TYPE, APP_TEST, APP_CUSTOMER); #else wlog_info("%s VER:%s MODULE:%s TEST:%d CUST:%d start...", APP_NAME, APP_VERSION, APP_MODULE_TYPE, APP_TEST, APP_CUSTOMER); #endif //先发消息,MCU先把电源锁住 setInitMcu(); //配置收到手机短信主动上报内容 innerInfo("AT+CNMI=0,2,0,0,0\r\n",19); //再振动 vibraNow(); //检测是否有未播放文件 if(TRUE==vFileGetUnplaySet()) vibratWorkNow(TRUE); } #ifdef ENABLE_ANT_MODE PT_THREAD (ptMcuAckTask(pt_timer_t *ptPool, struct pt *pt)){ static pt_timer_t ptTimer; //定时发设置MCU指令给MCU PT_BEGIN(pt); while(1){ setInitMcu(); PTTimerStart(ptPool, &ptTimer,500);//need set to 1 seconds PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer)); } PT_END(pt); } #endif /* taskRun 应用程序主要任务入口 */ static void taskRun(void){ //深度休眠投票:每个PT如果空闲了,则向属于自己的票据投上 //当票箱满员后,当前任务开启一个下次唤醒的定时器,并交出系统资源调度 #ifndef ENABLE_ANT_MODE //天线调试模式 if(app.tgMode==FALSE){ //ptDomainTask-->domain.c 负责域名解析任务,应用将需要解析的要求推入域名列队,域名任务会自动消耗 ptDomainTask(&pt_timerPool, &pt_DomainTask);//has better run first //ptNetWorkTask-->netWork.c 负责网络任务,包括注册,拨号,设备硬件参数等 ptNetWorkTask(&pt_timerPool, &pt_NetWorkTask); //ptQueueRecordReadTask-->plyRec.c 语音消息队列读取任务 ptQueueRecordReadTask(&pt_timerPool, &pt_QueueRecordReadTask); //ptTTSTask-->tts.c TTS播报任务 ptTTSTask(&pt_timerPool, &pt_TTSTask); //ptPlayerTask-->plyRec.c 对讲语音播放逻辑控制任务 ptPlayerTask(&pt_timerPool, &pt_PlayerTask); //ptRecorderTask-->plyRec.c 对讲语音录制逻辑控制任务 ptRecorderTask(&pt_timerPool, &pt_RecorderTask); //ptAuthLoginTask-->authlogin.c 系统开机后登陆IOT服务器 ptAuthLoginTask(&pt_timerPool, &pt_AuthLoginTask); //ptLocationTask-->location.c 负责处理GPS跟LSB业务 ptLocationTask(&pt_timerPool, &pt_LocationTask); //ptMcuIapTask-->mcuIap.c 负责处理更新IAP的业务 ptMcuIapTask(&pt_timerPool, &pt_McuIapTask); //ptLbsMotionTask-->location.c 负责LSB处理业务 ptLbsMotionTask(&pt_timerPool, &pt_LbsMotionTask); //ptHookTask-->hook.c 钩子任务 ptHookTask(&pt_timerPool, &pt_HookTask); //ptNearTask-->location.c 负责附近信息业务的收集 ptNearTask(&pt_timerPool, &pt_NearTask); //ptVoiceUploadTask-->plyRec.c 录制语音上传服务器任务控制 ptVoiceUploadTask(&pt_timerPool, &pt_VoiceUploadTask); //ptHearTickTask-->authlogin.c // ptHearTickTask(&pt_timerPool, &pt_HearTickTask);//请放在ptAuthLoginTask后面调用 #if defined ENABLE_TICKET //ptTickTask-->ticket.c 深度睡眠任务 ptTicketTask(&pt_timerPool, &pt_TicketTask); #endif } #else ptMcuAckTask(&pt_timerPool, &pt_McuAckTask); #endif if(FALSE==app.tmMode) //ptQueueComReadTask-->app.c 通用消息队列读取任务 ptQueueComReadTask(&pt_timerPool, &pt_QueueComReadTask); } T_BOOL appQuit=FALSE; #ifdef USE_DETECTED_THREAD static unsigned int ptTickCnt=0; #endif /*定义一个定时器用于其它作用,比如按键SOS超时,定时器的话,在休眠时也能用*/ LSAPI_OSI_Timer_t *ptimer_user = NULL; unsigned char userTimerFun=0; void userTimerCb(void *param){ switch(userTimerFun){ case 1: app.ksos=1; wlog_info("keyPress Timeout, vibra"); vibraNow(); if(app.onWorkZone==0 && sut_para.sosUpoadEnable_N==0) wlog_warn("un_onworkzone,sos disable, quit upload"); else warnSendNow(WARN_SOS); break; } userTimerFun=0; if(NULL != ptimer_user) LSAPI_OSI_TimerStop(ptimer_user); } static void userTimerEntry(void *param){ ptimer_user = LSAPI_OSI_TimerCreate(LSAPI_OSI_ThreadCurrent(), userTimerCb, NULL); if(NULL==ptimer_user){ wlog_error("ptimer_user timer error !!!!!"); return; } wlog_info("ptimer_user entry start ok"); LSAPI_OSI_Event_t event = {}; for(;;){LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);} LSAPI_OSI_ThreadExit(); } void userTimerInit(void){ if(NULL==LSAPI_OSI_ThreadCreate("userTimerEntry", userTimerEntry, NULL, LSAPI_OSI_PRIORITY_NORMAL, USER_TIMER_THREAD_STACK, 4)){ wlog_error("userTimer Thread create failed!"); } } void userTimerStart(T_UINT32 timeMs,unsigned char fun){ if(NULL==ptimer_user){ wlog_error("ptimer_user null, start failed"); return; } wlog_info("userTimerStart:%d ms",timeMs); userTimerFun=fun; LSAPI_OSI_TimerStart(ptimer_user, timeMs); } void userTimerSTOP(void){ wlog_info("userTimer stop"); if(NULL != ptimer_user) LSAPI_OSI_TimerStop(ptimer_user); } //主线程根据系统时间产生pt心跳,系统可以休眠 static int64_t lasttimems; /*pt心跳*/ void ptTimePro(void){ int i; int64_t timems,j; timems=LSAPI_OSI_UpTime(); j=timems-lasttimems; if(j>=10){ for(i=0;iyear=ltm.tm_year + 1900; myclock->month=ltm.tm_mon+1; myclock->day=ltm.tm_mday; myclock->hour=ltm.tm_hour;//+USER_TIME_ZONE; myclock->min=ltm.tm_min; myclock->sec=ltm.tm_sec; } void setMyClock(MY_CLOCK myclock){ struct tm ltm; memset(<m,0,sizeof(ltm)); ltm.tm_year=myclock.year-1900; ltm.tm_mon=myclock.month-1; ltm.tm_mday=myclock.day; ltm.tm_hour=myclock.hour-USER_TIME_ZONE; ltm.tm_min=myclock.min; ltm.tm_sec=myclock.sec; LSAPI_OSI_SetEpochTime(1000*mktime(<m)); } unsigned char *getBCDDateTime(void){ static unsigned char bcdDate[6]; MY_CLOCK myclock; getMyClock(&myclock); bcdDate[0]=decToBCD(myclock.year-2000); bcdDate[1]=decToBCD(myclock.month); bcdDate[2]=decToBCD(myclock.day); bcdDate[3]=decToBCD(myclock.hour); bcdDate[4]=decToBCD(myclock.min); bcdDate[5]=decToBCD(myclock.sec); return bcdDate; } #ifdef USE_DETECTED_THREAD //用于检测pt滴答是否正常 void detector(void *param){ char info[80]; wlog_info("detector start"); for(;;){ LSAPI_OSI_ThreadSleep(500); snprintf(info, sizeof(info),"ptTickCnt:%d\r\n",ptTickCnt); outterInfo(info, strlen(info)); } } #endif