123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- #include "includes.h"
- #include "lsapi_sock.h"
- #include "lsapi_http.h"
- #include "lsapi_fota.h"
- #include "lsapi_os.h"
- NET_DEF netWork;
- DOMAIN_INFO_DEF domainInfo;
- char targetVersion[10]={0};
- char wgetPath[64];
- short serverAck=0;
- LSAPI_OSI_Thread_t *lteThread=NULL;
- HttpInfoSet httpinfo;
- TUPSEND_DEF tupsendPara;
- typedef enum{
- TUP_STATUS_TRUE,
- TUP_STATUS_FALSE,
- TUP_STATUS_WAIT,
- TUP_STATUS_ONLINE
- }TUP_CONNECT_ENUM;
- FOTA_INFO AppFotaInfo;
- typedef enum{
- LTE_UPDATE_BUSY,
- LTE_UPDATE_FAILED,
- LTE_UPDATE_DONE
- }LTE_UPDATE_ENUM;
- LTE_UPDATE_ENUM lteResult;
- LTE_UPDATE_ENUM getLteUpdateStatus(void){return lteResult;}
- void MS5700_Networking(unsigned int interval){
- unsigned char info[23];
- uint32_t nRet,id;
- static bool getIccidFlag=FALSE;
-
- static int nAttstate,nActstate;
- static int LastnAttstate=0,LastnActstate=0;
- bool netIf;
- static bool lastNetIf=FALSE;
- static unsigned short cnt=0;
- static unsigned short regCnt=0;
- static unsigned short tickcnt=0;
- if(++tickcnt<(1000/interval)) return;//1秒读一次ADC即可
- tickcnt=0;
-
- nRet = LSAPI_NET_GetGprsAttState(&nAttstate);
- if(nRet!=0){
- MSG_WARN(1,"Get REG status failed");
- return;
- }
- if(nAttstate!=1){
- if(LastnAttstate!=nAttstate){ MSG_WARN(1,"reg off");}
- netWork.reg=0;
- netWork.pdp=0;
- netWork.netReady=0;
- MSG_INFO(1,"wait reg");
- if(regCnt==60){
- MSG_WARN(1,"!!!CFUN=0");
- LSAPI_NET_CFUN(0);
- }else if(regCnt>=61) {
- regCnt=0;
- MSG_WARN(1,"!!!CFUN=1");
- LSAPI_NET_CFUN(1);
- }
- ++regCnt;
- }else{
- regCnt=0;
- if(LastnAttstate!=nAttstate){ MSG_WARN(1,"reg on");}
- netWork.reg=1;
- nRet = LSAPI_NET_GetGprsActState(&nActstate);
- if(nRet!=0){
- MSG_WARN(1,"LSAPI_NET_GetGprsActState get failed:%d",nRet);
- }else{
- if(nActstate!=1){
- if(LastnActstate != nActstate){ MSG_WARN(1,"pdp off");}
- netWork.pdp=0;
- netWork.netReady=0;
- // ls_PdpActive(); HYL
-
- }else{
- if(LastnActstate != nActstate){ MSG_WARN(1,"pdp on");}
- netWork.pdp=1;
- netIf=LSAPI_NET_GET_GprsNetIf();
- if(false==netIf){
- if(lastNetIf!=netIf){ MSG_WARN(1,"netif off");}
- netWork.netReady=0;
- MSG_INFO(1,"netif start create");
- LSAPI_NET_NetIf_Create();
- MSG_INFO(1,"netif create done");
- }else{
- if(lastNetIf!=netIf){ MSG_WARN(1,"netif on");}
- netWork.netReady=1;
- }
- lastNetIf=netIf;
- }
- LastnActstate=nActstate;
- }
- }
- LastnAttstate=nAttstate;
- }
- void userExitThread(const char *name){
- MSG_INFO("[DieThread:%x]%s", LSAPI_OSI_ThreadCurrent(),name);
- LSAPI_OSI_ThreadExit();
- }
- void threadPostEvent(LSAPI_OSI_Thread_t *threadId, unsigned int id){
- LSAPI_OSI_Event_t pEventSend;
- pEventSend.id=id;
- osiEventTrySend(threadId,&pEventSend,0);
- }
- void domainCallBack(void *param){
- LSAPI_OSI_Event_t *ev = (LSAPI_OSI_Event_t *)param;
- bool needtobeclose=FALSE;
- if (ev->id== LSAPI_SOCK_DNS_RESOLV_SUC_IND) {
- LSAPI_SOCK_IP_ADDR_t* nIpAddr = (LSAPI_SOCK_IP_ADDR_t *)ev->param1;
- snprintf(domainInfo.address, sizeof(domainInfo.address),"%s",LSAPI_SOCK_IPAddr_ntoa(nIpAddr));
- MSG_INFO(1,"LSAPI_SOCK_Gethostbyname callback: %s",domainInfo.address);
- domainInfo.status=2;
- needtobeclose=TRUE;
-
- }else if (ev->id== LSAPI_SOCK_RESOLV_ERR_IND) {
- MSG_WARN(1,"LSAPI_SOCK_Gethostbyname EV_CFW_DNS_RESOLV_ERR_IND FAIL");
- domainInfo.status=0;
- needtobeclose=TRUE;
- }
- LSAPI_OSI_Free(ev);
- if(TRUE==needtobeclose) threadPostEvent(LSAPI_OSI_ThreadCurrent(),USER_EVENT_EXIT);
- }
- void dnsEntry(void *param){
-
- LSAPI_DNS_RESULT_t dnsRet;
- LSAPI_SOCK_IP_ADDR_t pAddr;
- LSAPI_OSI_Event_t event = {};
-
- MSG_INFO(1,"[NewThread:dnsEntry]%x:%s",LSAPI_OSI_ThreadCurrent(),domainInfo.address);
- dnsRet=LSAPI_SOCK_Gethostbyname(FOTADOMAIN_ADDR, &pAddr, 1,0,domainCallBack,(void *)param);
-
- if(dnsRet==LSAPI_RESOLV_COMPLETE) {
- MSG_INFO(1,"domain LSAPI_RESOLV_COMPLETE");
- snprintf(domainInfo.address, sizeof(domainInfo.address),"%s",LSAPI_SOCK_IPAddr_ntoa(&pAddr));
- domainInfo.status=2;
- userExitThread("dnsEntry");
- }else if(dnsRet==LSAPI_RESOLV_QUERY_INVALID){
- MSG_WARN(1,"domain LSAPI_RESOLV_QUERY_INVALID");
- domainInfo.status=0;
- userExitThread("dnsEntry");
- }else if(dnsRet==LSAPI_RESOLV_QUERY_QUEUED){
- MSG_INFO(1,"domain LSAPI_RESOLV_QUERY_QUEUED");
- //domainInfo.status=0;
- }
- for(;;){
- LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);
- if(USER_EVENT_EXIT==event.id){
- userExitThread("dnsEntry");
- }
- }
- }
- void dns_Thread(void)
- {
- domainInfo.status=1; //进行中
- if(0==LSAPI_OSI_ThreadCreate("dns", dnsEntry,NULL,LSAPI_OSI_PRIORITY_NORMAL,1024,4))MSG_INFO(1,"creat dnsEntry error");
-
- }
- void Domain_Process(unsigned int interval)
- {
- static unsigned short cnt=0;
- if(++cnt<(1000/interval)) return;//1秒读一次ADC即可
- cnt=0;
- if(domainInfo.status!=0)return;
- if(netWork.netReady==0)return;
- dns_Thread();
- }
- static unsigned short translateAfterRecv(unsigned char *src, unsigned char *in_src,unsigned short length){
- unsigned short i,retlen=0;
- unsigned char lastByte=0xff;
- unsigned char *savePtr=src;
-
- for(i=1;i<length-2;i++){
- if(lastByte==0x7D){
- if(in_src[i]==0x01){
- *savePtr++=0x7D;
- retlen++;
- }else if(in_src[i]==0x02){
- *savePtr++=0x7E;
- retlen++;
- }else{
- *savePtr++=in_src[i];
- retlen++;
- }
- }else{
- *savePtr++=in_src[i];
- retlen++;
- }
- lastByte=in_src[i];
- }
- return retlen;
- }
- void fillTargetVersion(char *filePath){
- //120.77.66.129/higos/fotaFiles/M5700_POC_ZT_2006.pack
- //-->120.77.66.129/higos/fotaFiles/M5700_POC_ZT_20052006.pack
- int i,len;
- char findDot=0;
- char info[30];
- len=strlen(filePath)-1;
- for(i=len;i>=0;i--){
- if(findDot==0){
- if(filePath[i]=='.'){
- filePath[i]=0;
- findDot=1;
- }
- }else if(filePath[i]=='_'){
- snprintf(targetVersion,sizeof(targetVersion),"%s",&filePath[i+1]);
- strcpy(filePath+i+1,OHPOC_VERSION);
- strcat(filePath, targetVersion);
- strcat(filePath, ".pack");
- return;
- }
- }
- }
- #define BUF_SIZE 150
- static signed char RecvDataHandle(unsigned char *src, unsigned short length){
- unsigned short i,j;
- unsigned int k;
- unsigned char num_7E=0,sum=0,reallen;
- unsigned short takenotelen=0,temp;
- unsigned char temBuf[BUF_SIZE*2];
- unsigned char *realPtr;
- unsigned char filePath[80];
- unsigned char gpsTime;
- static bool handleDataOk=FALSE;
- for(i=0;i<length;i++){
- takenotelen++;
- if(src[i]==0x7E){
- if(++num_7E>=2){
- break;
- }
- }
- }
- memcpy(temBuf, src,takenotelen);
- if(num_7E != 2 || takenotelen<=2) return 1;
- j=translateAfterRecv(temBuf,src,takenotelen);
- if(j<12) return 2;//header len err
- temp = temBuf[2];temp <<= 8;temp &= 0xFF00;
- temp |= temBuf[3];
- if(((temp >> 10)&0xF) != 0) return 4;//no support sub packet or encrypt
- temp &= 0x3FF;//sms length
- if((12+temp) != j) return 5;//packet length err
- for(i=0;i<j-0;i++) sum ^= temBuf[i];
- if(sum != temBuf[j+1]) return 6;//sum err
- realPtr = temBuf + 12;
- if(temBuf[0] == 0x89 && temBuf[1] == 0x29){
- if(handleDataOk==TRUE) return 8;
- realPtr += 6;
-
- //handle ack info
- /* 超时响应
- if(realPtr[0]==1){
- rightFlag=1;//have right
- updateLocalTime(realPtr-6);
- }
- else rightFlag=0;//no right
- tudptime2_3=realPtr[1];
- tudptime4=realPtr[2];
- */
- gpsTime=realPtr[3];
- realPtr += 4;//point to extend info
- temp -= 9;//extend info length
- k=temp;
-
- while(k>0){
- if(realPtr[0]==1){
- //take type 1 info, for poc update
- i=realPtr[1];//take length
- //decrypt
- realPtr += 2;
- for(j=0;j<i;j++){
- if(j % 2 !=0) filePath[j]=realPtr[j] ^ 0xB8;
- else filePath[j]=realPtr[j] ^ 0x56;
- }
- filePath[j]=0;
- MSG_INFO(1,"Get file path:%s",filePath);
- //backup file path
- strcpy(wgetPath,filePath);
- fillTargetVersion(wgetPath);
- MSG_INFO(1,"target:%s,file:%s",targetVersion,wgetPath);
- serverAck=1;
- handleDataOk=TRUE;
- return 0;
- }else k -= (1+1+realPtr[1]);
- }
- serverAck=2;
- return 7;
- }
- else return 3;//ID not fit
- }
- void tupParaSet(TUPSEND_DEF *para, unsigned short port, LSAPI_SOCK_Callback *callback,unsigned short stacksize){
- para->port=port;
- para->tupRecvCallBack=callback;
- para->stacksize=stacksize;
-
- }
- void authFotaRecv_cb(void *param){
- int len_ret;
- unsigned char buffer[BUF_SIZE];
- LSAPI_OSI_Event_t *pEvent = (LSAPI_OSI_Event_t *)param;
- TUPSEND_DEF *para=(TUPSEND_DEF *)pEvent->param3;
- bool needExitThread=FALSE;
-
- // showTupEventInfo("authFota",pEvent->id,para,0);
-
- switch(pEvent->id){
- case LSAPI_SOCK_TCPIP_SOCKET_CONNECT_RSP:
- // if(AF_TCP_WAIT==fotaStatus) fotaStatus=AF_SEND_WAIT_ACK;
- break;
- case LSAPI_SOCK_TCPIP_SOCKET_SEND_RSP:break;
- case LSAPI_SOCK_TCPIP_SOCKET_CLOSE_RSP:
- MSG_WARN(1,"authfota client close");
- serverAck=-1;
- needExitThread=TRUE;
- break;
- case LSAPI_SOCK_TCPIP_REV_DATA_IND:
- while(1){
- len_ret=LSAPI_SOCK_Recvfrom(para->fd, buffer, sizeof(buffer),0, ¶->sockAddr);
- if(len_ret>=0){
- if(len_ret==0) break;
- len_ret=RecvDataHandle(buffer, len_ret);
- MSG_INFO(1,"RecvDataHandle return %d", len_ret);
- }else{
- MSG_WARN(1,"authFotaRecv_cb recv failed");
- break;
- }
- }
- break;
- case LSAPI_SOCK_TCPIP_CLOSE_IND:break;
- default: break;
- }
- LSAPI_OSI_Free(pEvent);
- if(TRUE==needExitThread) threadPostEvent(LSAPI_OSI_ThreadCurrent(),USER_EVENT_EXIT);
- }
- void userCloseSocket(int *fd){
- if(*fd<=0) return;
- MSG_INFO(1,"SockClose:%d",*fd);
- LSAPI_SOCK_Close(*fd);
- *fd=0;
- }
- void sockEntry(void *param){
-
- TUPSEND_DEF *para=(TUPSEND_DEF *)param;
- unsigned int sockfd;
- unsigned char type;
- int g_keepalive = 0;
- MSG_INFO(1,"[NewThread:sockEntry]%x",LSAPI_OSI_ThreadCurrent());
- if(TUP_TCP==para->tupType) type=LSAPI_SOCK_TCPIP_SOCK_STREAM;
- else type=LSAPI_SOCK_TCPIP_SOCK_DGRAM;
- sockfd = LSAPI_SOCK_Create(LSAPI_SOCK_TCPIP_AF_INET, type, 0, para->tupRecvCallBack,(uint32_t)para);
- if(sockfd<0){
- MSG_INFO(1,"sockfd create err=%d",LSAPI_SOCK_Error());
- para->errno=1;
- LSAPI_OSI_ThreadExit();
- }
- para->fd=sockfd;
-
- MSG_INFO(1,"tup info:%d,%s:%d", sockfd,para->saddr, para->port);
-
- LSAPI_SOCK_TcpipSocketAddr_t *serveraddr=¶->sockAddr;
-
- serveraddr->sin_family = LSAPI_SOCK_TCPIP_AF_INET;
- serveraddr->sin_port = LSAPI_SOCK_htons(para->port);
- serveraddr->sin_addr.s_addr = LSAPI_SOCK_inet_addr(para->saddr);
- LSAPI_SOCK_SetSockOpt(sockfd, LSAPI_SOCK_SOL_SOCKET, LSPAI_SOCK_KEEPALIVE, (void *)&g_keepalive, sizeof(g_keepalive));
- if(LSAPI_RET_OK != LSAPI_SOCK_Connect(sockfd, serveraddr)){
- MSG_ERR(1,"sockfd connect err");
- userCloseSocket(&sockfd);
- para->fd=0;
- para->errno=2;
- userExitThread("sockEntry");
- return;
- }
- /*
- para->ptimer_t=LSAPI_OSI_TimerCreate(LSAPI_OSI_ThreadCurrent(), sockTimerOutCallback, param);
- if(NULL != para->ptimer_t) LSAPI_OSI_TimerStart(para->ptimer_t, 10000);
- MSG_INFO(1,"open fd:%d",sockfd);
- */
-
- LSAPI_OSI_Event_t event={};
- for(;;){
- LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);
- if(USER_EVENT_EXIT==event.id){
- userCloseSocket(¶->fd);
- userExitThread("sockEntry");
- }
- }
- }
- LSAPI_OSI_Thread_t *TcpConnectthreadid = NULL;
- TUP_CONNECT_ENUM tryConnectTup(char *seraddr, TUP_ENUM tup,TUPSEND_DEF *para){
-
- para->saddr=seraddr;
- para->tupType=tup;
- para->errno=0;
- para->fd=0;
-
- if(NULL==LSAPI_OSI_ThreadCreate("sockCreate", sockEntry,(void *)para,LSAPI_OSI_PRIORITY_NORMAL,para->stacksize,4)){
- MSG_ERR(1,"tryConnectTup thread create error for %s",seraddr);
- return TUP_STATUS_FALSE;
- }
- return TUP_STATUS_WAIT;
-
- }
- void FOTA_Process(unsigned char interval)
- {
- unsigned char ret;
- static unsigned short tickcnt=0;
- if(++tickcnt<(1000/interval)) return;//1秒读一次ADC即可
- tickcnt=0;
- if(AppFotaInfo.fota_statue==ENABLE){
- //try to update poc
- tryUpdateLte(wgetPath);
- /*
- do{
- ret=getLteUpdateStatus();
- PTTimerStart(ptPool, &ptTimer,10);//should be fast
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }while(LTE_UPDATE_BUSY==ret);
- */
- ret=getLteUpdateStatus();
- if(LTE_UPDATE_BUSY==ret){
- AppFotaInfo.fota_statue=DISENABLE;
- goto PTHREAD_END;;
- }
-
- }
-
- if(1==serverAck){
- MSG_INFO(1,"get server ack");
- if(0==strcmp(OHPOC_VERSION,targetVersion)){
- if(fotaStep==0){
- fotaStep=6;
- MSG_INFO(1,"无可更新版本");
- }
- } else {
- if(fotaStep==0){
- fotaStep=9;
- }
- }
- }else if(2==serverAck){
- MSG_INFO(1,"no extend info, exit");//扩展
- goto PTHREAD_END;
- }else{
- // MSG_INFO(1,"ack data not fit, exit");
- goto PTHREAD_END;
- }
- PTHREAD_END:
- serverAck=-1;
- return;
-
- }
- static void lteEntry(void *param){
-
- MSG_INFO(1,"lteEntry:url=%s",httpinfo.url);
- if(LSAPI_HTTP_GET(&httpinfo)){
- MSG_WARN(1,"httpget err");
- goto FOTA_FAILED;
- }
- if(httpinfo.recvlen==0){
- MSG_WARN(1,"pack file len err");
- goto FOTA_FAILED;
- }
- MSG_WARN(1,"pack file len:%d",httpinfo.recvlen);
- showLoading();
- if(false==LSAPI_FOTA_UpdataSetReady(httpinfo.RecvData,httpinfo.recvlen)){
- MSG_WARN(1,"fota file update err");
- if(fotaStep!=4&&fotaStep!=5)fotaStep=7;
- goto FOTA_FAILED;
- }
-
- lteResult=LTE_UPDATE_DONE;
- fotaStep=8;
- LSAPI_HTTP_ParaClear(&httpinfo);
- MSG_WARN(1,"fota file done,and reboot");
- lteThread=NULL;
-
- MSG_INFO(1,"lteEntry End");
- LSAPI_OSI_ThreadExit();
-
- return;
- FOTA_FAILED:
- LSAPI_HTTP_ParaClear(&httpinfo);
- lteThread=NULL;
- lteResult=LTE_UPDATE_FAILED;
- MSG_INFO(1,"lteEntry End");
- LSAPI_OSI_ThreadExit();
- }
- void tryUpdateLte(char *httpfilePath){
- if(NULL != lteThread){
- MSG_WARN(1,"lte proc is busy");
- return;
- }
- lteResult=LTE_UPDATE_BUSY;
- memset(&httpinfo, 0, sizeof(HttpInfoSet));
- snprintf(httpinfo.url, sizeof(httpinfo.url), "http://%s",httpfilePath);
- httpinfo.cid=1;
- lteThread=LSAPI_OSI_ThreadCreate("lteEntry", lteEntry,NULL,LSAPI_OSI_PRIORITY_NORMAL,HTTP_THREAD_STACK,4);
- if(NULL==lteThread){
- MSG_ERR(1,"lteEntry thread error");
- lteResult=LTE_UPDATE_FAILED;
- }
- }
- static unsigned short translateBeforeSend(unsigned char *src, unsigned short length){
- //0x7E-->0X7D,0X02
- //0X7D-->0X7D,0X01
- unsigned char temp[BUF_SIZE*2];
- unsigned short i,retlen;
- retlen=0;
- for(i=0;i<length;i++){
- if(src[i]==0x7E){
- temp[retlen++]=0x7D;
- temp[retlen++]=0x02;
- }else if(src[i]==0x7D){
- temp[retlen++]=0x7D;
- temp[retlen++]=0x01;
- }else{
- temp[retlen++]=src[i];
- }
- }
- memcpy(src, temp, retlen);
- return retlen;
- }
- void trySendTup(unsigned char *data, unsigned short len, TUP_ENUM tup, TUPSEND_DEF *para){
- int ret;
- if(para->fd<=0) return;
- if(TUP_TCP==para->tupType) ret=LSAPI_SOCK_Send(para->fd,data,len,0);
- else ret=LSAPI_SOCK_Sendto(para->fd,data,len,0, ¶->sockAddr, sizeof(LSAPI_SOCK_TcpipSocketAddr_t));
- if(ret<0) MSG_INFO(1,"tup[%d]:%d send failed", para->fd,len);
- else MSG_INFO(1,"tup[%d]:%d send ok",para->fd,len);
- }
- void infoPacketAndSend(
- unsigned int psn,
- char *imei,
- char *version,
- char *modemType,
- unsigned char udpvalue2_3,
- unsigned char udpvalue4){
- unsigned char sendbuf[BUF_SIZE];
- unsigned char *ptr=sendbuf;
- unsigned char sum=0,th,tl;
- unsigned short i,len;
- char temp[20];
- unsigned int ret;
- unsigned int tver=atoi(version);
- static short liushui=0;//hyl
- len=0;
- //make login info
- //start indicator
- ptr[len++]=0x7E;
- //header
- //sms type 2bytes
- ptr[len++]=0x09;
- ptr[len++]=0x29;
- //sms property 2bytes
- i=59;//only low 10bits are define as sms length
- ptr[len++]=i>>8;//no sub packets,no encrypt
- ptr[len++]=i;//sms length
- //device SN 6bytes
- snprintf(temp, sizeof(temp),"%012d",psn);
- for(i=0;i<6;i++){
- th=temp[2*i];
- tl=temp[2*i+1];
- th <<= 4;th &= 0xF0;
- tl &= 0x0F;
- ptr[len++]=th | tl;
- }
- //serial nuber 2bytes
- ptr[len++]=(liushui>>8)&0xFF;
- ptr[len++]=liushui&0xFF;
- liushui++;
- //sms info
- //poc modle:EC20TGA_POC 16bytes
- memset(&ptr[len], 0, 16);
- // snprintf(temp, sizeof(temp), "%s_%s",fotaGetModle(),fotaGetCt());
- /*
- #define OHPOC_MODLE "M5700" //浣滀负OPEN鏃讹紝姝ゅ€肩敤浜嶧OTA鍗囩骇鏍囪瘑浣跨敤
- #define OHPOC_CUST OHPOC_APP_NAME //浣滀负OPEN鏃讹紝姝ゅ€肩敤浜嶧OTA鍗囩骇鏍囪瘑浣跨敤
- */
- snprintf(temp, sizeof(temp), "%s_%s",OHPOC_MODLE,OHPOC_CUST);
- memcpy(&ptr[len],temp,16);
- len += 16;
- //poc tver 4bytes
- ptr[len++]=tver>>24;
- ptr[len++]=tver>>16;
- ptr[len++]=tver>>8;
- ptr[len++]=tver;
- //mcu modle 16bytes
- memset(&ptr[len], 0, 16);
- len += 16;
- //mcu version 4bytes
- memset(&ptr[len], 0, 4);
- len += 4;
- //NET CODE:IMEI 16:fill 15bytes
- memset(&ptr[len], 0, 16);
- memcpy(&ptr[len], imei, 15);
- len += 16;
- //current udp2_3 heart time 1byte
- ptr[len++]=udpvalue2_3;
- //current udp4 heart time 1byte
- ptr[len++]=udpvalue4;
- //current gps upload time 1byte
- ptr[len++]=0;
- //verify code
- for(i=1;i<len;i++) sum ^= sendbuf[i];
- ptr[len++]=sum;
- //translate
- len=translateBeforeSend(sendbuf+1,len-1)+1;
- sendbuf[len++]=0x7E;
- //printf("Len:%d\r\n",len);
- //for(i=0;i<len;i++) printf("%02x",sendbuf[i]);
- //printf("\r\n");
- //send now
- //wlog_info("udp send data len %d\n", len)
- trySendTup(sendbuf,len,TUP_UDP,&tupsendPara);
- }
|