#include "http.h" #include "log.h" #include "main.h" #include "lsapi_http.h" #include "lsapi_fota.h" #include "lsapi_os.h" #include "app.h" #include "domain.h" ///////////////////////////////////////FOTA LTE//////////////////////////////////////////// #define FOTA_SERVER_ADDR "fota.rtuol.com" #define FOTA_FILE_FOLDER "RTL" HttpInfoSet fotaHttpInfo; LSAPI_OSI_Thread_t *fotaLteThread=NULL; LTE_UPDATE_ENUM fotaLteResult; char newVersion[30]; LTE_UPDATE_ENUM getLteUpdateStatus(void){return fotaLteResult;} static void lteEntry(void *param); /* FOTA升级LTE接口API,实现从http服务器获取差分包 如果获取成功且差分包正确,则自动重启并完成LTE升级 如果失败则返回,不影响正常业务 */ void fotaLetPre(char *NewVer){ int i; char ch; for(i=0;i%s", FOTA_SERVER_ADDR,ipAddr); break; }else{//wait result LSAPI_OSI_ThreadSleep(20); } } } memset(&fotaHttpInfo, 0, sizeof(HttpInfoSet)); snprintf(fotaHttpInfo.url, sizeof(fotaHttpInfo.url), "http://%s/%s/%s/%s_V%s%s.pack", ipAddr, FOTA_FILE_FOLDER, APP_NAME, APP_NAME, APP_VERSION,newVersion);//http://120.77.66.129/RTL/RTL271_V20022003.pack fotaHttpInfo.cid=1; wlog_info("lteEntry url:%s",fotaHttpInfo.url); if(LSAPI_HTTP_GET(&fotaHttpInfo)){//尝试获取差分包 wlog_warn("httpget err"); goto FOTA_FAILED; } if(fotaHttpInfo.recvlen==0){//差分包获取成功,但数据长度为0,FOTA失败 wlog_warn("pack file len err"); goto FOTA_FAILED; } wlog_warn("pack file len:%d",fotaHttpInfo.recvlen); LSAPI_OSI_ThreadSleep(1000);//为了让业务中的反馈包能发给服务器。 if(false==LSAPI_FOTA_UpdataSetReady(fotaHttpInfo.RecvData,fotaHttpInfo.recvlen)){//差分包有数据,检测是否可以升级 wlog_warn("LSAPI_FOTA_UpdataSetReady:FALSE"); goto FOTA_FAILED; } fotaLteResult=LTE_UPDATE_DONE; //差分包正确且可以升级,清除缓存并执行重启,系统会自动完成LTE升级 LSAPI_HTTP_ParaClear(&fotaHttpInfo); wlog_warn("fota file done,and reboot"); #ifdef TAKE_NOTE_FOR_REBOOT saveRebootReason("fota done\r\n"); #endif LSAPI_OSI_ThreadSleep(1000); msgToInner("AT+LSHTTS=0\r\n");//即将升级 msgToInner("AT+LSHTTS=2,\"53735C0691CD542F\"\r\n");//即将重启 LSAPI_OSI_ThreadSleep(1000);//仅为能看日志而加,去掉可能看不到日志 LSAPI_SYS_reboot(); return; FOTA_FAILED: LSAPI_OSI_ThreadSleep(1000); msgToInner("AT+LSHTTS=0\r\n");//即将升级 msgToInner("AT+LSHTTS=2,\"900051FA53477EA7\"\r\n");//退出升级 LSAPI_HTTP_ParaClear(&fotaHttpInfo); fotaLteThread=NULL; fotaLteResult=LTE_UPDATE_FAILED; wlog_info("lteEntry End"); LSAPI_OSI_ThreadExit(); } //////////////////////////////////////POST VOICE////////////////////////////////////////// #ifdef ENABLE_HTTP_POST HttpInfoSet postHttpInfo; LSAPI_OSI_Thread_t *postVoiceThread=NULL; POST_VOICE_ENUM postVoiceResult; unsigned char *postData=NULL; unsigned int postLen=0; T_BOOL postTimeFlag=FALSE; POST_VOICE_ENUM getLtePostStatus(void){return postVoiceResult;} static void postEntry(void *param); void tryPostVoiceData(unsigned char *pcm, unsigned int len, char *httpfilePath){ if(NULL != postVoiceThread){ wlog_warn("lte proc is busy"); return; } if(len==0) return; postVoiceResult=POST_BUSY; memset(&postHttpInfo, 0, sizeof(HttpInfoSet)); snprintf(postHttpInfo.url, sizeof(postHttpInfo.url), "http://%s",httpfilePath); postHttpInfo.cid=1; postData=pcm; postLen=len; postVoiceThread=LSAPI_OSI_ThreadCreate("postEntry", postEntry,NULL,LSAPI_OSI_PRIORITY_NORMAL,POST_THREAD_STACK,4); if(NULL==postVoiceThread){ wlog_error("postEntry thread error");//因为是阻塞的,故需要开线程,且栈要比较大 postVoiceResult=POST_FAILED; } } /*外部检测超时未成功时调用此API取消POST*/ void postTimeOut(void){ if(postVoiceResult!=POST_BUSY) return; postTimeFlag=TRUE; } static void postEntry(void *param){ int i,index=0,sendlen; wlog_info("postEntry:url=%s,datalen=%d",postHttpInfo.url,postLen); i=postLen; do{ if(i>sizeof(postHttpInfo.SendData)) sendlen=sizeof(postHttpInfo.SendData); else sendlen=i; memcpy(postHttpInfo.SendData, postData+index,sendlen); if(LSAPI_HTTP_POST(&postHttpInfo)) wlog_warn("post failed, retry"); else{ i -= sendlen; index += sendlen; } LSAPI_OSI_ThreadSleep(10); if(postTimeFlag==TRUE){ postTimeFlag=FALSE; wlog_info("post timeout cancle"); break; } }while(i>0); if(i==0) wlog_info("post ok"); LSAPI_HTTP_ParaClear(&postHttpInfo); postVoiceThread=NULL; postVoiceResult=POST_DONE; wlog_info("postEntry End"); LSAPI_OSI_ThreadExit(); } #endif