void setCommand(char* command){ char* cmd = NULL; char idx=0; char* pch=NULL; cmd = Ql_strstr(command, "DEBUG="); if (cmd){ cmd += 6; if (Ql_strstr(cmd, "TRUE")){ __debug=TRUE; } else{ __debug=FALSE; } Ql_strcpy(&__settings.Debug[0],cmd); } cmd = Ql_strstr(command, "LOG="); if (cmd){ cmd += 4; if (Ql_strstr(cmd, "TRUE")){ __log=TRUE; } else{ __log=FALSE; } Ql_strcpy(&__settings.Log[0],cmd); } cmd = Ql_strstr(command, "TCP="); if (cmd){ cmd += 4; __settings.TCP=Ql_atoi(cmd); } cmd = Ql_strstr(command, "IP="); if (cmd){ cmd += 3; pch = strtok(cmd, "."); while (pch != NULL) { __settings.IP[idx] = Ql_atoi(pch); pch = strtok(NULL, "."); idx++; } //OUTD("Set IP:%d.%d.%d.%d\r\n",__settings.IP[0],__settings.IP[1],__settings.IP[2],__settings.IP[3]); } cmd = Ql_strstr(command, "APN="); if (cmd){ cmd += 4; Ql_strcpy(&__settings.APN[0],cmd); } cmd = Ql_strstr(command, "PASS="******"NUM="); if (cmd){ cmd += 4; __settings.Num=Ql_atoi(cmd); } /*cmd = Ql_strstr(command, "PWD="); if (cmd){ cmd += 4; Ql_strcpy(&__settings.Pwd[0],cmd); }*/ cmd = Ql_strstr(command, "USER="******"TIME="); if (cmd){ char* last; QlSysTimer tm; Ql_GetLocalTime(&tm); cmd+=5; if (Ql_strlen(cmd)==8) { tm.hour = Ql_atoi(strtok_r(cmd, ":",&last)); tm.minute = Ql_atoi(strtok_r(last, ":",&last)); tm.second = Ql_atoi(strtok_r(last, ":",&last)); Ql_SetLocalTime(&tm); } } cmd = Ql_strstr(command, "DATE="); if (cmd){ char* last; QlSysTimer tm; Ql_GetLocalTime(&tm); cmd+=5; if (Ql_strlen(cmd)==8) { tm.day = Ql_atoi(strtok_r(cmd, ".",&last)); tm.month = Ql_atoi(strtok_r(last, ".",&last)); tm.year = Ql_atoi(strtok_r(last, ".",&last)); Ql_SetLocalTime(&tm); } } cmd = Ql_strstr(command, "REBOOT"); if (cmd){ OUTD("!-----Get command to reboot..-----",NULL); Ql_Sleep(100); Ql_Reset(0); } cmd = Ql_strstr(command, "TSEND="); if (cmd){ s32 tsend; cmd+=6; tsend=Ql_atoi(cmd); if (tsend>10 && tsend<60) { __settings.TSend = tsend; } } cmd = Ql_strstr(command, "DEBOUNCE="); if (cmd){ s32 deboung; cmd+=9; deboung=Ql_atoi(cmd); //OUTD("set debounce ok:%d",deboung); if (deboung>=100 && deboung<=1000) { //OUTD("set debounce ok:%d",deboung); __settings.Deboung = deboung; } } cmd = Ql_strstr(command, "WUser="******"WPass="******"?"); if (cmd){ PrintSettings(); } }
static void proc_handle(char *pData,s32 len) { char *p = NULL; char parambuf[100]; //command: Reset=<type> p = Ql_strstr(pData,"Reset="); if (p) { Ql_memset(parambuf, 0, 100); if (Analyse_Command(pData, 1, '>', parambuf)) { APP_DEBUG("<--Parameter Error.-->\r\n"); return; } if (Ql_atoi(parambuf) != 0)//must be 0 { APP_DEBUG("<--Parameter Error.-->\r\n"); return; } APP_DEBUG("<--Set Reset Parameter Successfully<%d>.-->\r\n",Ql_atoi(parambuf)); Ql_Sleep(100); Ql_Reset(Ql_atoi(parambuf)); return; } //command: Sleep=<msec> p = Ql_strstr(pData,"Sleep="); if (p) { s32 ret; ST_Time time,*tm; Ql_memset(parambuf, 0, 100); if (Analyse_Command(pData, 1, '>', parambuf)) { APP_DEBUG("<--Parameter Error.-->\r\n"); return; } APP_DEBUG("<--Set Sleep Parameter Successfully<%d>.-->\r\n",Ql_atoi(parambuf)); APP_DEBUG("<--Start sleeping-->\r\n"); Ql_Sleep(Ql_atoi(parambuf)); APP_DEBUG("<--sleeping over-->\r\n"); return; } //command: Read Module UID p = Ql_strstr(pData,"Read Module UID"); if (p) { s32 i, uidLen; u8 moduleUID[100]; u8 tmpbuf[100]; Ql_memset(moduleUID, 0, sizeof(moduleUID)); Ql_memset(tmpbuf, 0, sizeof(tmpbuf)); uidLen = Ql_GetUID(moduleUID, sizeof(moduleUID)); for (i = 0; i < uidLen; i++) { Ql_sprintf(tmpbuf + i*2, "%02X", moduleUID[i]); } APP_DEBUG("<--Module UID=0x%s,len=%d-->\r\n", tmpbuf, uidLen); return; } //command: Get Core Version p = Ql_strstr(pData,"Get Core Version"); if (p) { s32 ret; u8 tmpbuf[100]; Ql_memset(tmpbuf, 0, sizeof(tmpbuf)); ret = Ql_GetCoreVer((u8*)tmpbuf, sizeof(tmpbuf)); if(ret > 0) { APP_DEBUG("<--Core Version:%s-->\r\n", tmpbuf); } else { APP_DEBUG("<--Get Core Version Failure.-->\r\n"); } return; } //command: Get SDK Version p = Ql_strstr(pData,"Get SDK Version"); if (p) { s32 ret; u8 tmpbuf[100]; Ql_memset(tmpbuf, 0, sizeof(tmpbuf)); ret = Ql_GetSDKVer((u8*)tmpbuf, sizeof(tmpbuf)); if(ret > 0) { APP_DEBUG("<--SDK Version:%s.-->\r\n", tmpbuf); } else { APP_DEBUG("<--Get SDK Version Failure.-->\r\n"); } return; } //command: Get Ms Since PwrOn p = Ql_strstr(pData,"Get Ms Since PwrOn"); if (p) { u64 totalMS; totalMS = Ql_GetMsSincePwrOn(); APP_DEBUG("<--Get Ms Since PwrOn:=%lld.-->\r\n", totalMS); return; } //command: Ql_SleepEnable set the module into sleep mod p= Ql_strstr(pData,"Ql_SleepEnable"); if(p) { s32 ret; APP_DEBUG("<-- Ql_SleepEnable=%d -->\r\n", ret); ret = Ql_SleepEnable(); return; } // p= Ql_strstr(pData,"Ql_SleepDisable"); if(p) { s32 ret; APP_DEBUG("<-- Ql_SleepDisable=%d -->\r\n", ret); ret = Ql_SleepDisable(); return; } //command:Ql_SecureData_Store=<n> , n=1~13. p= Ql_strstr(pData,"Ql_SecureData_Store="); if(p) { s32 ret; u8 index; Ql_memset(parambuf, 0, 100); if (Analyse_Command(pData, 1, '>', parambuf)) { APP_DEBUG("<--Parameter Error.-->\r\n"); return; } index = Ql_atoi(parambuf); if(index <1 || index >13) { APP_DEBUG("<--Parameter n Error.-->\r\n"); return; } ret = Ql_SecureData_Store(index, (u8*)&test,sizeof(test)); APP_DEBUG("<-- Ql_SecureData_Store(index=%d, value=%d, data size=%d)=%d -->\r\n", index,test.reset.Period,sizeof(Global_SYS_Cfg),ret); return; } //command:Ql_SecureData_Read=<n> , n=1~13. p= Ql_strstr(pData,"Ql_SecureData_Read="); if(p) { s32 ret; u8 index; Ql_memset(parambuf, 0, 100); if (Analyse_Command(pData, 1, '>', parambuf)) { APP_DEBUG("<--Parameter Error.-->\r\n"); return; } index = Ql_atoi(parambuf); if(index <1 || index >13) { APP_DEBUG("<--Parameter n Error.-->\r\n"); return; } ret = Ql_SecureData_Read(index, (u8*)&tempTest,sizeof(Global_SYS_Cfg)); APP_DEBUG("<-- Ql_SecureData_Read =%d \r\n test.version:%s test.data=%s test.reset.timeDelay =%d-->\r\n",ret, tempTest.version,tempTest.data,tempTest.reset.timeDelay); return; } return; }
static void CallBack_UART_Hdlr(Enum_SerialPort port, Enum_UARTEventType msg, bool level, void* customizedPara) { s32 ret; APP_DEBUG("CallBack_UART_Hdlr: port=%d, event=%d, level=%d, p=%x\r\n", port, msg, level, customizedPara); switch (msg) { case EVENT_UART_READY_TO_READ: { if (m_myUartPort == port) { // Write the data from UART port to virtual serial port s32 totalBytes = ReadSerialPort(port, m_RxBuf_UartPort, sizeof(m_RxBuf_UartPort)); APP_DEBUG("m_RxBuf_UartPort:%s\r\n",m_RxBuf_UartPort ); if (totalBytes > 0) { if (m_bCsdConnected && Ql_StrPrefixMatch(m_RxBuf_UartPort, "+++")) { // -------- Disconnect CSD ------- CSD_Disconnect(); m_bCsdConnected = FALSE; }else{ // No CSD connection, then transparently transmit the data from UART port to virtual serial port // And make sure all data is sent out s32 realSentByte = 0; do { ret = Ql_UART_Write(m_myVirtualPort, m_RxBuf_UartPort + realSentByte, totalBytes - realSentByte); if (ret > 0 && ret < (totalBytes - realSentByte)) { Ql_Sleep(100); } realSentByte += ret; APP_DEBUG("CallBack_UART_Hdlr ret:%d realSentByte:%d \r\n",ret,realSentByte ); } while (realSentByte != totalBytes); } } } else if (m_myVirtualPort == port) { // Write the data from virtual serial port to UART port s32 totalBytes = ReadSerialPort(port, m_RxBuf_VirtualPort, sizeof(m_RxBuf_VirtualPort)); APP_DEBUG(" m_RxBuf_VirtualPort:%s\r\n",m_RxBuf_VirtualPort ); if (totalBytes > 0) { if (Ql_strstr(m_RxBuf_VirtualPort, "\r\nRING\r\n")) { // -------- Received RING, answer CSD call ------- CSD_Answer(); } else if (Ql_strstr(m_RxBuf_VirtualPort, "CONNECT")) { // -------- Received CONNECT 9600, CSD connected ------- m_bCsdConnected = TRUE; } Ql_UART_Write(m_myUartPort, m_RxBuf_VirtualPort, totalBytes); } } break; } default: break; } }
void page_response(HttpHeader *header){ bool reset=FALSE; bool prepare=TRUE; char* action=header->action; OUTD("action=%s",action); Ql_memset(__data_buf,0,4096); Ql_memset(__s_buf,0,10240); if (Ql_strstr(header->action, "/")) { get_main_page( __est_connection ? "System state is start":"System state stop"); OUTD("main page",NULL); } else if (Ql_strstr(action,"reboot")) { get_rebot_page(); reset=TRUE; } else if (Ql_strstr(action,"settings?")) { char* pch=NULL; char* last=NULL; //OUTD("parse setting action:%s",pch); pch=strtok_r(action+9,"&",&last); //OUTD("parse command:%s",pch); while (pch!=NULL) { setCommand(pch); pch=strtok_r(NULL,"&",&last); //OUTD("parse command:%s",pch); } WriteSettings(); ReadSettings(); get_main_page("Save settings controller is OK"); } else if (Ql_strstr(action,"date?")) { bool sdt=SetLocDate(action+5); get_main_page(sdt ? "Set date and time is OK":"Error set date and time"); } else if (Ql_strstr(action,"stop")) { StopEstConnection(); get_main_page("Recive command Stop"); } else if (Ql_strstr(action,"run")) { nSTATE=STATE_EST_SOCKET_CREATE; get_main_page("Recive command Start"); } else if (Ql_strstr(action,"log")) { u16 size=0; ReadLogFile(&size); Ql_sprintf(__s_buf,__download_page,size); //Ql_strcpy(&__s_buf[Ql_strlen(__s_buf)],__buf_log); Ql_memcpy(&__s_buf[Ql_strlen(__s_buf)],__buf_log,size); OUTD("__download_page:%d file size:%d buffer-len:%d",Ql_strlen(__download_page),size,Ql_strlen(__s_buf)); prepare=FALSE; } else if (Ql_strstr(action, "autorize")) { Ql_sprintf(__s_buf,__autorize,0); prepare=FALSE; OUTD("set autorize",NULL); } else { get_error_page(); Ql_sprintf(__s_buf,__error_page,0); prepare=FALSE; } if (prepare) { //if (header->set_cookie) { // Ql_sprintf(__s_buf, __ok_page, Ql_strlen(__data_buf),"\r\nSet-Cookie: __ztp=987654321\r\n"); //} Ql_sprintf(__s_buf, __ok_page, Ql_strlen(__data_buf)); Ql_strcpy(&__s_buf[Ql_strlen(__s_buf)],__data_buf); OUTD("sbuf:%d dbuf:%d",Ql_strlen(__s_buf),Ql_strlen(__data_buf)); } if (reset) { Ql_Sleep(10000); Ql_Reset(0); } }