bool SendMtkBinCmd(u8 *strCmd) { int len = 0,ret = 0; unsigned char outBuffer[256]; // At initial, the protocol setting of the communication UART is supposed to be PMTK protocol. // Since EPO data are transferred using MTK Binary Packet, you have to change the protocol setting to MTK Binary Protocol // before starting EPO Transfer Protocol. You can use PMTK command 253 to change the UART protocol setting. // Please refer to 7.1 for the details of PMTK command 253. Ql_memset(outBuffer,0,sizeof(outBuffer)); Ql_memcpy((void *)outBuffer, strCmd, Ql_strlen(strCmd)); len = Ql_strlen(outBuffer); outBuffer[len++] = 0x0D; outBuffer[len++] = 0x0A; outBuffer[len] = '\0'; /*send the data of outBuffer to the GPS module example L70 ect. */ ret = Ql_UART_Write(m_gnssUartPort,outBuffer,len); if (ret < len) { APP_DEBUG("SendMtkBinCmd Only part of bytes are written, %d/%d \r\n", ret, len); return FALSE; } return TRUE; }
void ql_entry() { bool keepGoing = TRUE; QlEventBuffer flSignalBuffer; s32 period = 10; char buffer[100]; char *pData, *p; Ql_SetDebugMode(BASIC_MODE); Ql_DebugTrace("keyboard: ql_entry\r\n"); Ql_OpenModemPort(ql_md_port1); queryPinStatus(); while(keepGoing) { Ql_GetEvent(&flSignalBuffer); switch(flSignalBuffer.eventType) { case EVENT_KEY: { Key_Event* pKeyEvt = &flSignalBuffer.eventData.key_evt; Ql_sprintf(buffer, "\r\nEVENT_KEY: key_val(%x), isPressed=%d\r\n", pKeyEvt->key_val, pKeyEvt->isPressed); Ql_SendToUart(ql_uart_port1, (u8*)buffer, Ql_strlen(buffer)); break; } case EVENT_POWERKEY: { Powerkey_Event* pPwrkeyEvt = &flSignalBuffer.eventData.powerkey_evt; char* pwrKeyOn = "POWERKEY_ON"; char* pwrKeyOff = "POWERKEY_OFF"; if (POWERKEY_ON == pPwrkeyEvt->powerkey) { Ql_sprintf(buffer, "\r\nEVENT_KEY: POWERKEY_ON"); } else { Ql_sprintf(buffer, "\r\nEVENT_KEY: POWERKEY_OFF"); } if (pPwrkeyEvt->isPressed) { Ql_sprintf(buffer + Ql_strlen(buffer), ", Press Key Down\r\n"); } else { Ql_sprintf(buffer + Ql_strlen(buffer), ", Release Key\r\n"); } Ql_SendToUart(ql_uart_port1, (u8*)buffer, Ql_strlen(buffer)); break; } default: break; } } }
static void InitializeSerialPort(void) { s32 ret; // Register & open UART port // UART port ret = Ql_UART_Register(m_myUartPort, CallBack_UART_Hdlr, NULL); if (ret < QL_RET_OK) { Ql_Debug_Trace("Fail to register serial port[%d], ret=%d\r\n", m_myUartPort, ret); } ret = Ql_UART_Open(m_myUartPort, 115200, FC_NONE); if (ret < QL_RET_OK) { Ql_Debug_Trace("Fail to open serial port[%d], ret=%d\r\n", m_myUartPort, ret); } Ql_UART_Write(m_myUartPort, "\r\nRDY\r\n", Ql_strlen("\r\nRDY\r\n")); // Register & open virtual serial port ret = Ql_UART_Register(m_myVirtualPort, CallBack_UART_Hdlr, NULL); if (ret < QL_RET_OK) { APP_DEBUG("Fail to register serial port[%d], ret=%d\r\n", m_myVirtualPort, ret); } ret = Ql_UART_Open(m_myVirtualPort, 115200, FC_NONE); if (ret < QL_RET_OK) { APP_DEBUG("Fail to open serial port[%d], ret=%d\r\n", m_myVirtualPort, ret); } }
void custom_at_handler(void) { char *p=NULL; AT_Response response = INVAT; u8 off; if (!pData) return; p = pData; response = parse_at_response(&off); p+=off; switch(response) { case CPIN: { if (Ql_strncmp(p," READY",6)==0) { Ql_sprintf((char *)buffer,"\r\nCPIN is ready\r\n"); Ql_SendToUart(ql_uart_port1, (u8*)buffer,Ql_strlen(buffer)); Ql_sprintf((char *)buffer,"\r\nSet timer for 5 second\r\n"); Ql_SendToUart(ql_uart_port1, (u8*)buffer,Ql_strlen(buffer)); timer.timeoutPeriod = Ql_SecondToTicks(5); Ql_StartTimer(&timer); }else if (Ql_strncmp(p," SIM PIN",8)==0) { Ql_sprintf((char *)buffer,"\r\nSIM PIN is needed\r\n"); Ql_SendToUart(ql_uart_port1, (u8*)buffer,Ql_strlen(buffer)); Ql_memset(atbuffer,0,100); Ql_sprintf((char *)atbuffer,"AT+CPIN=1234\n"); Ql_SendToModem(ql_md_port1,atbuffer,Ql_strlen((char *)atbuffer)); } break; } default: break; } }
bool createDirRecursively(char *dirName) { OUT_DEBUG_2("createDirRecursively(\"%s\")\r\n", dirName); if (!Ql_strlen(dirName)) { OUT_DEBUG_1("Directory name is empty\r\n"); return FALSE; } // -- create dirs hierarchy char parted_dir_name[255] = {0}; Ql_strcpy(parted_dir_name, dirName); s16 nPathParts = 0; char *temp_str = parted_dir_name; const char path_separator = '\\'; do { temp_str = Ql_strchr(temp_str, path_separator); if (temp_str) *temp_str++ = 0; ++nPathParts; } while (temp_str); while (nPathParts) { if (nPathParts-- > 1) { // if not last iteration s32 ret = Ql_FS_CheckDir(parted_dir_name); if (ret < QL_RET_OK && QL_RET_ERR_FILENOTFOUND != ret) // if an error occured { OUT_DEBUG_1("Error %d occured while checking directory \"%s\".\r\n", ret, parted_dir_name); return FALSE; } else if (QL_RET_OK == ret) // if the dir was found { OUT_DEBUG_3("Directory \"%s\" already exists. Creation skipped\r\n", parted_dir_name); char *end = Ql_strchr(parted_dir_name, 0); // find the end of the dir name's part *end = path_separator; continue; } } // -- create dest dir if (!createDir(parted_dir_name)) return FALSE; char *end = Ql_strchr(parted_dir_name, 0); // find the end of the dir name's part *end = path_separator; } return TRUE; }
bool get_http_data(QlClient *client,HttpHeader *header) { char* fota = Ql_strstr((char*)client->recvBuffer, "QUECTEL_FOTA_UPGRADE"); if (fota) { unsigned char* end = &client->recvBuffer[client->pRecvCurrentPos - (Ql_strlen(header->boundary) + 8)]; if (Ql_strstr((char*)end, header->boundary)) { int lens = (char*)end - fota; Ql_memcpy(header->data, fota, lens); } return TRUE; } else return FALSE; }
void queryPinStatus() { QlPinSubscribe subscribe; QlPinMode wrkMode; QlPinParameter pinParam; ST_Pin pins[10]; char notes[100]; int i; // Fill in pins Ql_sprintf(pins[0].pinName, "QL_PINNAME_KBR0"); pins[0].pinNo= QL_PINNAME_KBR0; Ql_sprintf(pins[1].pinName, "QL_PINNAME_KBR1"); pins[1].pinNo= QL_PINNAME_KBR1; Ql_sprintf(pins[2].pinName, "QL_PINNAME_KBR2"); pins[2].pinNo= QL_PINNAME_KBR2; Ql_sprintf(pins[3].pinName, "QL_PINNAME_KBR3"); pins[3].pinNo= QL_PINNAME_KBR3; Ql_sprintf(pins[4].pinName, "QL_PINNAME_KBR4"); pins[4].pinNo= QL_PINNAME_KBR4; Ql_sprintf(pins[5].pinName, "QL_PINNAME_KBC0"); pins[5].pinNo= QL_PINNAME_KBC0; Ql_sprintf(pins[6].pinName, "QL_PINNAME_KBC1"); pins[6].pinNo= QL_PINNAME_KBC1; Ql_sprintf(pins[7].pinName, "QL_PINNAME_KBC2"); pins[7].pinNo= QL_PINNAME_KBC2; Ql_sprintf(pins[8].pinName, "QL_PINNAME_KBC3"); pins[8].pinNo= QL_PINNAME_KBC3; Ql_sprintf(pins[9].pinName, "QL_PINNAME_KBC4"); pins[9].pinNo= QL_PINNAME_KBC4; // Query the status of all multifunction pins for (i = 0; i < (sizeof(pins) / sizeof(pins[0])); i++) { Ql_pinQueryMode(pins[i].pinNo, &subscribe, &wrkMode, &pinParam); Ql_sprintf(notes, "%s: subscribe:%d, pinMode:%d\r\n", pins[i].pinName, subscribe, wrkMode); Ql_SendToUart(ql_uart_port1, (u8*)notes, Ql_strlen(notes)); } }
bool createDir(char *dirName) { OUT_DEBUG_2("createDir(\"%s\")\r\n", dirName); if (!Ql_strlen(dirName)) { OUT_DEBUG_1("Directory name is empty\r\n"); return FALSE; } s32 ret = Ql_FS_CheckDir(dirName); if (QL_RET_ERR_FILENOTFOUND == ret) { ret = Ql_FS_CreateDir(dirName); if (ret < QL_RET_OK) { OUT_DEBUG_1("Error %d occured while creating directory \"%s\".\r\n", ret, dirName); return FALSE; } } else if (ret < QL_RET_OK) { OUT_DEBUG_1("Error %d occured while checking directory \"%s\".\r\n", ret, dirName); return FALSE; } else if (QL_RET_OK == ret) { OUT_DEBUG_3("Directory \"%s\" already exists thereby its content will be re-writed.\r\n", dirName); ret = Ql_FS_XDelete(dirName, QL_FS_FILE_TYPE|QL_FS_DIR_TYPE|QL_FS_RECURSIVE_TYPE); if (ret < QL_RET_OK) { OUT_DEBUG_1("Error %d occured while deleting directory \"%s\".\r\n", ret, dirName); return FALSE; } ret = Ql_FS_CreateDir(dirName); if (ret < QL_RET_OK) { OUT_DEBUG_1("Error %d occured while creating directory \"%s\".\r\n", ret, dirName); return FALSE; } } return TRUE; }
void ql_entry(void) { s32 ret; bool keepGoing = TRUE; bool isContinued = FALSE; u32 cnt = 0; Ql_DebugTrace("OpenCPU: Hello TTS !\r\n\r\n"); /* Print out messages through DEBUG port */ Ql_SetDebugMode(BASIC_MODE); /* Only after the device reboots, * the set debug-mode takes effect. */ // Initialize TTS, and register callback function Ql_TTS_Initialize(&Callback_TTS_Play); while(keepGoing) { Ql_GetEvent(&g_event); switch(g_event.eventType) { case EVENT_UARTDATA: { // TODO: receive and handle data from UART ascii* pChar; s16 strLen; PortData_Event* pDataEvt = (PortData_Event*)&g_event.eventData.uartdata_evt; /* Change audio path (Command: audio path=0/1/2) * 0 = the main audio path * 1 = earphone audio path * 2 = loudspeaker audio path */ Ql_memset(g_buffer, 0x0, sizeof(g_buffer)); strLen = Ql_sprintf(g_buffer, "audio path="); pChar = Ql_strstr((char*)pDataEvt->data, g_buffer); if (pChar) { u8 audPath; char* p1; char* p2; Ql_DebugTrace((char*)pDataEvt->data); p1 = Ql_strstr((char*)pDataEvt->data, "="); p2 = Ql_strstr((char*)pDataEvt->data, "\r\n"); Ql_memset(g_buffer, 0x0, sizeof(g_buffer)); memcpy(g_buffer, p1 + 1, p2 - p1 -1); if (Ql_strcmp(g_buffer, "1") == 0) { audPath = QL_AUDIO_PATH_HEADSET; } else if (Ql_strcmp(g_buffer, "2") == 0) { audPath = QL_AUDIO_PATH_LOUDSPEAKER; } else { audPath = QL_AUDIO_PATH_NORMAL; } if (!Ql_VoiceCallChangePath(audPath)) { Ql_DebugTrace("Fail to change audio path.\r\n"); } else { Ql_DebugTrace("Change audio path to %d.\r\n", audPath); } break; } // Start tts speech (Command: start tts=...) strLen = Ql_sprintf(g_buffer, "start tts="); ret = Ql_strncmp((char*)pDataEvt->data, g_buffer, strLen); if (0 == ret) { char* pCh = NULL; pCh = Ql_strstr((char*)pDataEvt->data, "="); if (pCh != NULL) { Ql_memset(g_buffer, 0x0, sizeof(g_buffer)); Ql_strncpy(g_buffer, pCh + 1, pDataEvt->len - (pCh - (char*)pDataEvt->data + 1) - 2); Ql_DebugTrace("Ql_TTS_Play(), len=%d\r\n", Ql_strlen(g_buffer)); ret = Ql_TTS_Play((u8*)g_buffer, sizeof(g_buffer)); if (ret < 0) { Ql_DebugTrace("Fail to play TTS.\r\n"); break; } else { Ql_DebugTrace("Playing finished.\r\n"); } } break; } // Stop TTS (Command: stop tts) Ql_memset(g_buffer, 0x0, Ql_strlen(g_buffer)); strLen = Ql_sprintf(g_buffer, "stop tts\r\n"); ret = Ql_strncmp((char*)pDataEvt->data, g_buffer, strLen); if (0 == ret) { Ql_DebugTrace(g_buffer); Ql_TTS_Stop(); break; } // Query TTS' status (Command: tts?) Ql_memset(g_buffer, 0x0, Ql_strlen(g_buffer)); strLen = Ql_sprintf(g_buffer, "tts?\r\n"); ret = Ql_strncmp((char*)pDataEvt->data, g_buffer, strLen); if (0 == ret) { Ql_DebugTrace(g_buffer); ret = Ql_TTS_Query(); switch (ret) { case TTS_STATUS_IDLE: Ql_DebugTrace("TTS: idle\r\n"); break; case TTS_STATUS_PLAYING: Ql_DebugTrace("TTS: playing\r\n"); break; default: Ql_DebugTrace("Fail to query TTS' status. Error code: %d\r\n", ret); break; } break; } // Set volume (Command: tts vol=0..100) Ql_memset(g_buffer, 0x0, sizeof(g_buffer)); strLen = Ql_sprintf(g_buffer, "tts vol="); pChar = Ql_strstr((char*)pDataEvt->data, g_buffer); if (pChar) { u8 ttsVol; char* p1; char* p2; Ql_DebugTrace((char*)pDataEvt->data); p1 = Ql_strstr((char*)pDataEvt->data, "="); p2 = Ql_strstr((char*)pDataEvt->data, "\r\n"); Ql_memset(g_buffer, 0x0, sizeof(g_buffer)); memcpy(g_buffer, p1 + 1, p2 - p1 -1); ttsVol = Ql_atoi(g_buffer); ttsVol = (ttsVol > 100) ? 100 : ttsVol; Ql_SetVolume_Ex(VOL_TYPE_MEDIA, QL_AUDIO_PATH_HEADSET, ttsVol); break; } // Set TTS Style // Set TTS fastest voice speed Ql_memset(g_buffer, 0x0, sizeof(g_buffer)); strLen = Ql_sprintf(g_buffer, "tts Style1="); pChar = Ql_strstr((char*)pDataEvt->data, g_buffer); if (pChar) { u32 ret; ret = Ql_TTS_SetStyle(TTS_PARAM_VOICE_SPEED,TTS_SPEED_MAX); Ql_DebugTrace("Set TTS fastest voice speed.\r\n"); break; } // Set TTS minimized volume. Ql_memset(g_buffer, 0x0, sizeof(g_buffer)); strLen = Ql_sprintf(g_buffer, "tts Style2="); pChar = Ql_strstr((char*)pDataEvt->data, g_buffer); if (pChar) { u32 ret; ret = Ql_TTS_SetStyle(TTS_PARAM_VOLUME,TTS_VOLUME_MIN); Ql_DebugTrace("Set TTS minimized volume.\r\n"); break; } // Set TTS voice effect --eccentric Ql_memset(g_buffer, 0x0, sizeof(g_buffer)); strLen = Ql_sprintf(g_buffer, "tts Style3="); pChar = Ql_strstr((char*)pDataEvt->data, g_buffer); if (pChar) { u32 ret; ret = Ql_TTS_SetStyle(TTS_PARAM_VEMODE,TTS_VEMODE_ECCENTRIC); Ql_DebugTrace("Set TTS voice effect --eccentric.\r\n"); break; } } /************************************* * 'Case' another EVENT if needed. * **************************************/ default: break; } } }
bool VerifyFileAndSendFirstEpoPacket(u8 *strFilePath) { int ret = 0,filesize = 0; int sendLen = 0; if((strFilePath == NULL) || (Ql_strlen(strFilePath) == 0)) { APP_DEBUG("VerifyFileAndSendFirstEpoPacket, strFilePath %s \r\n", strFilePath); return FALSE; } ret = Ql_FS_Check((char*)strFilePath); if(ret != QL_RET_OK) { APP_DEBUG("Ql_FS_Check, strFilePath %s error \r\n", strFilePath); return FALSE; } filesize = Ql_FS_GetSize((char*)strFilePath); if(filesize < 0) { APP_DEBUG("Ql_FS_GetSize, filesize %d error \r\n ", filesize); return FALSE; } if (Ql_strncmp((char*)strFilePath,"RAM:", 4)) { g_pEpoFile = Ql_FS_Open((char*)strFilePath, QL_FS_READ_ONLY); } else { g_pEpoFile = Ql_FS_OpenRAMFile((char*)strFilePath, QL_FS_READ_ONLY, filesize); } // Read in the EPO file, and then verify the validity of EPO data. If the input EPO file is not in valid MTK EPO format, the // programmer shall terminate the process. if(g_pEpoFile < 0) { Ql_FS_Close(g_pEpoFile); APP_DEBUG("Ql_FS_OpenRAMFile, g_pEpoFile %d error \r\n ", g_pEpoFile); return FALSE; } else { if (!fgEPO_Verify_File(g_pEpoFile)) { Ql_FS_Close(g_pEpoFile); APP_DEBUG("fgEPO_Verify_File, g_pEpoFile %d error \r\n", g_pEpoFile); return FALSE; } } // Get total number of MTK_BIN_EPO packets that will be sent. g_i4NumSvEpoPkt = i2EPO_Get_Num_Pkt(g_pEpoFile); // Start EPO Data Transfer Protocol to send EPO data // fgEPO_Get_One_Pkt takes out three SAT data from the EPO file and encapsulated them in a MTK_BIN_EPO packet // with appropriate EPO SEQ number. // In order to save the total transferring time, we suggest to generate current EPO packet first, and then wait for // MTK_BIN_ACK_EPO acknowledge of the previous MTK_BIN_EPO packet from the GPS receiver. // The function fgEPO_Get_One_Pkt must be implemented by the programmer. g_u2LastEpoSeq = 0; g_u2EpoSeq = 0; Ql_memset(g_szPktData,0,sizeof(g_szPktData)); if (fgEPO_Get_One_Pkt(g_u2EpoSeq, g_pEpoFile, g_szPktData)) { sendLen = MTKBIN_3EPO_PKT_LNG; ret = Ql_UART_Write(m_gnssUartPort,g_szPktData,sendLen); if (ret < sendLen) { APP_DEBUG("VerifyFileAndSendFirstEpoPacket Only part of bytes are written, %d/%d \r\n", ret, sendLen); return FALSE; } // Update sequence number g_u2LastEpoSeq = g_u2EpoSeq; g_u2EpoSeq++; return TRUE; } else { APP_DEBUG("VerifyFileAndSendFirstEpoPacket fgEPO_Get_One_Pkt error \r\n"); return FALSE; } }
void ql_entry() { bool keepGoing = TRUE; QlEventBuffer flSignalBuffer; s32 period = 10; char buffer[100]; char *pData, *p; Ql_SetDebugMode(BASIC_MODE); Ql_DebugTrace("pwm: ql_entry\r\n"); Ql_OpenModemPort(ql_md_port1); while(keepGoing) { Ql_GetEvent(&flSignalBuffer); switch(flSignalBuffer.eventType) { case EVENT_UARTDATA: { if (flSignalBuffer.eventData.uartdata_evt.len>0) { s32 pin; s32 mod = 0; s32 pinpullenable = 0; s32 pindirection = 0; s32 pinlevel = 0; s32 iret; pData = (char*)flSignalBuffer.eventData.uartdata_evt.data; //command-->select QL_PINNAME_BUZZER pin function to mode1, it is Net light function p = Ql_strstr(pData,"1"); if (p) { iret = Ql_pinSubscribe(QL_PINNAME_BUZZER, QL_PINMODE_1, NULL); Ql_sprintf(buffer, "\r\nSubscribe(%d),pin=%d,mod=%d\r\n",iret,QL_PINNAME_BUZZER,QL_PINMODE_1); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); break; } //command-->select QL_PINNAME_BUZZER pin function to mode3, it is pwm function p = Ql_strstr(pData,"3"); if (p) { QlPinParameter pinparameter; pinparameter.pinconfigversion = QL_PIN_VERSION; pinparameter.pinparameterunion.pwmparameter.pwmsource = QL_PWMSOURCE_32K; pinparameter.pinparameterunion.pwmparameter.pwmclkdiv = QL_PWMSOURCE_DIV8; pinparameter.pinparameterunion.pwmparameter.lowpulesnumber = 4000; pinparameter.pinparameterunion.pwmparameter.highpulesnumber = 8000; iret = Ql_pinSubscribe(QL_PINNAME_BUZZER, QL_PINMODE_3, &pinparameter); Ql_sprintf(buffer, "\r\nSubscribe(%d),pin=%d,mod=%d\r\n",iret,QL_PINNAME_BUZZER,QL_PINMODE_3); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); break; } //command-->unsubscribe p = Ql_strstr(pData,"u"); if (p) { iret = Ql_pinUnSubscribe(QL_PINNAME_BUZZER); Ql_sprintf(buffer, "\r\nUnSubscribe(%d),pin=%d\r\n",iret,QL_PINNAME_BUZZER); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); break; } //command-->control start pwm p = Ql_strstr(pData,"s"); if (p) { iret = Ql_pinControl(QL_PINNAME_BUZZER, QL_PINCONTROL_START); Ql_sprintf(buffer, "\r\nStart(%d),pin=%d\r\n",iret,QL_PINNAME_BUZZER); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); break; } //command-->control stop pwm p = Ql_strstr(pData,"t"); if (p) { iret = Ql_pinControl(QL_PINNAME_BUZZER, QL_PINCONTROL_STOP); Ql_sprintf(buffer, "\r\nStop(%d),pin=%d\r\n",iret,QL_PINNAME_BUZZER); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); break; } } break; } default: break; } } }
void fillBuffer(char* ctxt){ if ((__buf_command_pos+Ql_strlen(ctxt))>BUFFER_COMMAND_LEN) __buf_command_pos=0; Ql_sprintf(&__buf_command[__buf_command_pos], "%s", ctxt); __buf_command_pos+=Ql_strlen(ctxt); }
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 Callback_Timer(u32 timerId, void* param) { if (TIMEOUT_90S_TIMER_ID == timerId) { APP_DEBUG("<--90s time out!!!-->\r\n"); APP_DEBUG("<-- Close socket.-->\r\n"); Ql_SOC_Close(m_socketid); m_socketid = -1; m_tcp_state = STATE_GPRS_DEACTIVATE; timeout_90S_monitor = FALSE; } else if (TCP_TIMER_ID == timerId) { //APP_DEBUG("<--...........m_tcp_state=%d..................-->\r\n",m_tcp_state); switch (m_tcp_state) { case STATE_NW_GET_SIMSTATE: { s32 simStat = 0; //if (Ql_NW_GetSIMCardState()== Ql_SIM_NORMAL) RIL_NW_GetSIMCardState(&simStat); if (simStat == SIM_STAT_READY) { m_tcp_state = STATE_NW_QUERY_STATE; APP_DEBUG("<--SIM card status is normal!-->\r\n"); }else { // Ql_Timer_Stop(TCP_TIMER_ID); APP_DEBUG("<--SIM card status is unnormal!-->\r\n"); } break; } case STATE_NW_QUERY_STATE: { s32 creg = 0; s32 cgreg = 0; //Ql_NW_GetNetworkState(&creg, &cgreg); ret = RIL_NW_GetGSMState(&creg); ret = RIL_NW_GetGPRSState(&cgreg); APP_DEBUG("<--Network State:creg=%d,cgreg=%d-->\r\n",creg,cgreg); if((cgreg == NW_STAT_REGISTERED)||(cgreg == NW_STAT_REGISTERED_ROAMING)) { m_tcp_state = STATE_GPRS_REGISTER; } break; } case STATE_GPRS_REGISTER: { ret = Ql_GPRS_Register(0, &callback_gprs_func, NULL); if (GPRS_PDP_SUCCESS == ret) { APP_DEBUG("<--Register GPRS callback function successfully.-->\r\n"); m_tcp_state = STATE_GPRS_CONFIG; }else if (GPRS_PDP_ALREADY == ret) { APP_DEBUG("<--GPRS callback function has already been registered,ret=%d.-->\r\n",ret); m_tcp_state = STATE_GPRS_CONFIG; }else { APP_DEBUG("<--Register GPRS callback function failure,ret=%d.-->\r\n",ret); } break; } case STATE_GPRS_CONFIG: { Ql_strcpy(m_gprsCfg.apnName, m_apn); Ql_strcpy(m_gprsCfg.apnUserId, m_userid); Ql_strcpy(m_gprsCfg.apnPasswd, m_passwd); m_gprsCfg.authtype = 0; ret = Ql_GPRS_Config(0, &m_gprsCfg); if (GPRS_PDP_SUCCESS == ret) { APP_DEBUG("<--configure GPRS param successfully.-->\r\n"); }else { APP_DEBUG("<--configure GPRS param failure,ret=%d.-->\r\n",ret); } m_tcp_state = STATE_GPRS_ACTIVATE; break; } case STATE_GPRS_ACTIVATE: { m_tcp_state = STATE_GPRS_ACTIVATING; ret = Ql_GPRS_Activate(0); if (ret == GPRS_PDP_SUCCESS) { APP_DEBUG("<--Activate GPRS successfully.-->\r\n"); m_tcp_state = STATE_GPRS_GET_DNSADDRESS; }else if (ret == GPRS_PDP_WOULDBLOCK) { APP_DEBUG("<--Waiting for the result of GPRS activated.,ret=%d.-->\r\n",ret); //waiting Callback_GPRS_Actived }else if (ret == GPRS_PDP_ALREADY) { APP_DEBUG("<--GPRS has already been activated,ret=%d.-->\r\n",ret); m_tcp_state = STATE_GPRS_GET_DNSADDRESS; }else//error { APP_DEBUG("<--Activate GPRS failure,ret=%d.-->\r\n",ret); m_tcp_state = STATE_GPRS_ACTIVATE; } break; } case STATE_GPRS_GET_DNSADDRESS: { u8 primaryAddr[16] = {0}; u8 bkAddr[16] = {0}; ret =Ql_GPRS_GetDNSAddress(0, (u32*)primaryAddr, (u32*)bkAddr); if (ret == GPRS_PDP_SUCCESS) { APP_DEBUG("<--Get DNS address successfully,primaryAddr=%d.%d.%d.%d,bkAddr=%d.%d.%d.%d-->\r\n",primaryAddr[0],primaryAddr[1],primaryAddr[2],primaryAddr[3],bkAddr[0],bkAddr[1],bkAddr[2],bkAddr[3]); m_tcp_state = STATE_GPRS_GET_LOCALIP; }else { APP_DEBUG("<--Get DNS address failure,ret=%d.-->\r\n",ret); m_tcp_state = STATE_GPRS_DEACTIVATE; } break; } case STATE_GPRS_GET_LOCALIP: { u8 ip_addr[5]; Ql_memset(ip_addr, 0, 5); ret = Ql_GPRS_GetLocalIPAddress(0, (u32 *)ip_addr); if (ret == GPRS_PDP_SUCCESS) { APP_DEBUG("<--Get Local Ip successfully,Local Ip=%d.%d.%d.%d-->\r\n",ip_addr[0],ip_addr[1],ip_addr[2],ip_addr[3]); m_tcp_state = STATE_CHACK_SRVADDR; }else { APP_DEBUG("<--Get Local Ip failure,ret=%d.-->\r\n",ret); } break; } case STATE_CHACK_SRVADDR: { Ql_memset(m_ipaddress,0,5); ret = Ql_IpHelper_ConvertIpAddr(m_SrvADDR, (u32 *)m_ipaddress); if(ret == SOC_SUCCESS) // ip address, xxx.xxx.xxx.xxx { APP_DEBUG("<--Convert Ip Address successfully,m_ipaddress=%d,%d,%d,%d-->\r\n",m_ipaddress[0],m_ipaddress[1],m_ipaddress[2],m_ipaddress[3]); m_tcp_state = STATE_SOC_REGISTER; }else //domain name { ret = Ql_IpHelper_GetIPByHostName(0, 0, m_SrvADDR, Callback_GetIpByName); if(ret == SOC_SUCCESS) { APP_DEBUG("<--Get ip by hostname successfully.-->\r\n"); } else if(ret == SOC_WOULDBLOCK) { APP_DEBUG("<--Waiting for the result of Getting ip by hostname,ret=%d.-->\r\n",ret); //waiting CallBack_getipbyname } else { APP_DEBUG("<--Get ip by hostname failure:ret=%d-->\r\n",ret); if(ret == SOC_BEARER_FAIL) { m_tcp_state = STATE_GPRS_DEACTIVATE; } else { m_tcp_state = STATE_GPRS_GET_DNSADDRESS; } } } break; } case STATE_SOC_REGISTER: { ret = Ql_SOC_Register(callback_soc_func, NULL); if (SOC_SUCCESS == ret) { APP_DEBUG("<--Register socket callback function successfully.-->\r\n"); m_tcp_state = STATE_SOC_CREATE; }else if (SOC_ALREADY == ret) { APP_DEBUG("<--Socket callback function has already been registered,ret=%d.-->\r\n",ret); m_tcp_state = STATE_SOC_CREATE; }else { APP_DEBUG("<--Register Socket callback function failure,ret=%d.-->\r\n",ret); } break; } case STATE_SOC_CREATE: { m_socketid = Ql_SOC_Create(0, SOC_TYPE_TCP); if (m_socketid >= 0) { APP_DEBUG("<--Create socket id successfully,socketid=%d.-->\r\n",m_socketid); m_tcp_state = STATE_SOC_CONNECT; }else { APP_DEBUG("<--Create socket id failure,error=%d.-->\r\n",m_socketid); } break; } case STATE_SOC_CONNECT: { m_tcp_state = STATE_SOC_CONNECTING; ret = Ql_SOC_Connect(m_socketid,(u32) m_ipaddress, m_SrvPort); if(ret == SOC_SUCCESS) { APP_DEBUG("<--The socket is already connected.-->\r\n"); m_tcp_state = STATE_SOC_SEND; }else if(ret == SOC_WOULDBLOCK) { if (!timeout_90S_monitor)//start timeout monitor { Ql_Timer_Start(TIMEOUT_90S_TIMER_ID, TIMEOUT_90S_PERIOD, FALSE); timeout_90S_monitor = TRUE; } APP_DEBUG("<--Waiting for the result of socket connection,ret=%d.-->\r\n",ret); //waiting CallBack_getipbyname }else //error { APP_DEBUG("<--Socket Connect failure,ret=%d.-->\r\n",ret); APP_DEBUG("<-- Close socket.-->\r\n"); Ql_SOC_Close(m_socketid); m_socketid = -1; if(ret == SOC_BEARER_FAIL) { m_tcp_state = STATE_GPRS_DEACTIVATE; } else { m_tcp_state = STATE_GPRS_GET_DNSADDRESS; } } break; } case STATE_SOC_SEND: { if (!Ql_strlen(m_send_buf))//no data need to send break; m_tcp_state = STATE_SOC_SENDING; do { ret = Ql_SOC_Send(m_socketid, m_pCurrentPos, m_remain_len); APP_DEBUG("<--Send data,socketid=%d,number of bytes sent=%d-->\r\n",m_socketid,ret); if(ret == m_remain_len)//send compelete { m_remain_len = 0; m_pCurrentPos = NULL; m_nSentLen += ret; m_tcp_state = STATE_SOC_ACK; break; } else if((ret <= 0) && (ret == SOC_WOULDBLOCK)) { //waiting CallBack_socket_write, then send data; break; } else if(ret <= 0) { APP_DEBUG("<--Send data failure,ret=%d.-->\r\n",ret); APP_DEBUG("<-- Close socket.-->\r\n"); Ql_SOC_Close(m_socketid);//error , Ql_SOC_Close m_socketid = -1; m_remain_len = 0; m_pCurrentPos = NULL; if(ret == SOC_BEARER_FAIL) { m_tcp_state = STATE_GPRS_DEACTIVATE; } else { m_tcp_state = STATE_GPRS_GET_DNSADDRESS; } break; } else if(ret < m_remain_len)//continue send, do not send all data { m_remain_len -= ret; m_pCurrentPos += ret; m_nSentLen += ret; } }while(1); break; } case STATE_SOC_ACK: { u64 ackedNumCurr; ret = Ql_SOC_GetAckNumber(m_socketid, &ackedNumCurr); if (ret < 0) { checkErr_AckNumber(ret); } if (m_nSentLen == ackedNumCurr) { if (timeout_90S_monitor) //stop timeout monitor { Ql_Timer_Stop(TIMEOUT_90S_TIMER_ID); timeout_90S_monitor = FALSE; } APP_DEBUG("<-- ACK Number:%llu/%llu. Server has received all data. -->\r\n\r\n", m_nSentLen, ackedNumCurr); Ql_memset(m_send_buf,0,SEND_BUFFER_LEN); m_tcp_state = STATE_SOC_SEND; } else { if (!timeout_90S_monitor)//start timeout monitor { Ql_Timer_Start(TIMEOUT_90S_TIMER_ID, TIMEOUT_90S_PERIOD, FALSE); timeout_90S_monitor = TRUE; } APP_DEBUG("<-- ACK Number:%llu/%llu from socket[%d] -->\r\n", ackedNumCurr, m_nSentLen, m_socketid); } break; } case STATE_GPRS_DEACTIVATE: { APP_DEBUG("<--Deactivate GPRS.-->\r\n"); Ql_GPRS_Deactivate(0); break; } default: break; } } }
static void proc_handle(char *pData,s32 len) { char *p = NULL; s32 iret; u8 srvport[10]; //command: Set_APN_Param=<APN>,<username>,<password> p = Ql_strstr(pData,"Set_APN_Param="); if (p) { Ql_memset(m_apn, 0, 10); if (Analyse_Command(pData, 1, '>', m_apn)) { APP_DEBUG("<--APN Parameter Error.-->\r\n"); return; } Ql_memset(m_userid, 0, 10); if (Analyse_Command(pData, 2, '>', m_userid)) { APP_DEBUG("<--APN Username Parameter Error.-->\r\n"); return; } Ql_memset(m_passwd, 0, 10); if (Analyse_Command(pData, 3, '>', m_passwd)) { APP_DEBUG("<--APN Password Parameter Error.-->\r\n"); return; } APP_DEBUG("<--Set APN Parameter Successfully<%s>,<%s>,<%s>.-->\r\n",m_apn,m_userid,m_passwd); return; } //command: Set_Srv_Param=<srv ip>,<srv port> p = Ql_strstr(pData,"Set_Srv_Param="); if (p) { Ql_memset(m_SrvADDR, 0, SRVADDR_BUFFER_LEN); if (Analyse_Command(pData, 1, '>', m_SrvADDR)) { APP_DEBUG("<--Server Address Parameter Error.-->\r\n"); return; } Ql_memset(srvport, 0, 10); if (Analyse_Command(pData, 2, '>', srvport)) { APP_DEBUG("<--Server Port Parameter Error.-->\r\n"); return; } m_SrvPort = Ql_atoi(srvport); APP_DEBUG("<--Set TCP Server Parameter Successfully<%s>,<%d>.-->\r\n",m_SrvADDR,m_SrvPort); m_tcp_state = STATE_NW_GET_SIMSTATE; APP_DEBUG("<--Restart the TCP connection process.-->\r\n"); return; } //if not command,send it to server m_pCurrentPos = m_send_buf; Ql_strcpy(m_pCurrentPos + m_remain_len, pData); m_remain_len = Ql_strlen(m_pCurrentPos); }
bool parse_header(void *clients,HttpHeader *http_header){ char *param; char *value; char *last; char *ph; char* bon_val = NULL; char header[1024 * 2]; char*lens=NULL; QlClient *client=(QlClient*)clients; char* head = Ql_strstr((char*)client->recvBuffer, "\r\n\r\n"); if (head) { http_header->set_cookie=FALSE; http_header->authorization=FALSE; Ql_memset(http_header->action,0,100); Ql_memset(http_header->boundary,0,200); Ql_memset(http_header->cookie,0,200); Ql_memset(http_header->data,0,10 * 1024); http_header->length=0; Ql_strcpy(http_header->cookie, "NONE"); int head_len = (char*)head - ((char*)client->recvBuffer); int body_len = (int)(client->pRecvCurrentPos) - head_len - 4; Ql_memcpy(header, client->recvBuffer, head_len); ph = strtok_r(header, "\r\n", &last); char* lst; if (Ql_strstr(ph, "GET")!=NULL) { char* act = strtok_r(ph+4, " ", &lst); if (Ql_strlen(act)>1) Ql_strcpy(http_header->action, act+1); else Ql_strcpy(http_header->action, act); http_header->method = GET; OUTD("action:%s",http_header->action); } if (Ql_strstr(ph, "POST")!=NULL) { http_header->method = POST; char* act = strtok_r(ph+5, " ", &lst); if (Ql_strlen(act)>1) Ql_strcpy(http_header->action, act+1); else Ql_strcpy(http_header->action, act); } while (1) { ph = strtok_r(NULL, "\r", &last); if (ph == NULL) { return TRUE; } param = strtok_r(ph + 1, ":", &value); if (Ql_strstr(param, "Content-Type")) { char* bon = Ql_strstr(value, "boundary"); bon_val = bon + 9; Ql_strcpy(http_header->boundary, bon_val); } else if ((lens = Ql_strstr(param, "Cookie"))!=NULL) { char* cookie; if ((cookie=Ql_strstr(value,"__ztp"))!=NULL) { Ql_strcpy(http_header->cookie, cookie+6); http_header->authorization=TRUE; http_header->set_cookie=FALSE; } } else if ((lens = Ql_strstr(param, "Content-Length"))!=NULL) { char* slen = lens + 16; int len_head = Ql_atoi(slen); http_header->length = len_head; if (len_head == body_len){ OUTD("data full",NULL); } else { OUTD("not full data.wait:%d have:%d", len_head, body_len); return FALSE; } } else if ((lens = Ql_strstr(param, "Authorization"))!=NULL) { /*char* slen = lens + 21; unsigned char dbuf[50]; Ql_memset(dbuf,0,50); decode_b64((unsigned char*)slen,dbuf); OUTD("decode buf:%s",dbuf); param = strtok_r((char*)dbuf, ":", &value); if (Ql_strstr(param,"admin") && Ql_strstr(value,"admin")) { OUTD("Autorization user:%s pswd:%s",param,value); http_header->authorization=TRUE; http_header->set_cookie=TRUE; }*/ } } } else { return FALSE; } }
void ql_entry() { bool keepGoing = TRUE; QlEventBuffer flSignalBuffer; s32 period = 10; Ql_DebugTrace("at: ql_entry\r\n"); Ql_SetDebugMode(BASIC_MODE); Ql_OpenModemPort(ql_md_port1); Ql_memset(atbuffer,0,100); //Ql_sprintf((char *)atbuffer,"AT+QLOCPU=0\n"); Ql_sprintf((char *)atbuffer,"AT+CPIN?\n"); Ql_SendToModem(ql_md_port1,atbuffer,Ql_strlen((char*)atbuffer)); while(keepGoing) { Ql_GetEvent(&flSignalBuffer); switch(flSignalBuffer.eventType) { case EVENT_TIMER: { Ql_sprintf((char *)buffer,"\r\nTimer expired\r\n"); Ql_SendToUart(ql_uart_port1, (u8*)buffer,Ql_strlen(buffer)); Ql_memset(atbuffer,0,100); Ql_sprintf((char *)atbuffer,"AT+QAUDCH=1\n"); Ql_SendToModem(ql_md_port1,atbuffer,Ql_strlen((char *)atbuffer)); //Ql_PlayAudio(QL_AUDIO_EMS_TADA,0); break; } case EVENT_MODEMDATA: { Ql_DebugTrace("\r\nEVENT_MODEMDATA type=%d \r\n",flSignalBuffer.eventData.modemdata_evt.type); if (flSignalBuffer.eventData.modemdata_evt.type==DATA_AT) { pData = (char*)flSignalBuffer.eventData.modemdata_evt.data; custom_at_handler(); } break; } case EVENT_UARTDATA: { Ql_DebugTrace("\r\nEVENT_UARTDATA PORT=%d\r\n",flSignalBuffer.eventData.uartdata_evt.port); Ql_DebugTrace("\r\nuart data =%s\r\n",flSignalBuffer.eventData.uartdata_evt.data); break; } case EVENT_SERIALSTATUS: { bool val = flSignalBuffer.eventData.portstatus_evt.val; u8 port = flSignalBuffer.eventData.portstatus_evt.port; u8 type = flSignalBuffer.eventData.portstatus_evt.type; Ql_DebugTrace("EVENT_SERIALSTATUS port=%d type=%d val=%d\r\n",port,type,val); break; } default: break; } } }
void ql_entry(void) { bool keepGoing = TRUE; s32 ret; s32 i; char notes[50]; OUT_DEBUG(debug_buffer,"sms: ql_entry\r\n"); Ql_SetDebugMode(ADVANCE_MODE); Ql_OpenModemPort(ql_md_port1); Ql_SMS_Callback cb_func={CallBack_NewSMS,CallBack_SendSMS,CallBack_DeleteSMS, //public CallBack_ReadPDUSMS,CallBack_NewFlashPDUSMS,CallBack_PDUStatusReport, //pdu CallBack_ReadTextSMS,CallBack_NewFlashTextSMS,CallBack_TextStatusReport}; //text ret=Ql_SMSInitialize(&cb_func); OUT_DEBUG(debug_buffer,"\r\nQl_SMSInitialize=%d\r\n",ret); //OUT_DEBUG(debug_buffer,"CallBack_ReadPDUSMS=%X\r\n",CallBack_ReadPDUSMS); while(keepGoing) { Ql_GetEvent(&g_event); switch(g_event.eventType) { case EVENT_MODEMDATA: { //TODO: receive and hanle data from CORE through virtual modem port PortData_Event* pPortEvt = (PortData_Event*)&g_event.eventData.modemdata_evt; OUT_DEBUG(debug_buffer,"%s", pPortEvt->data); break; } case EVENT_UARTDATA: { char* pChar=NULL; char* pChar2=NULL; PortData_Event* pDataEvt = (PortData_Event*)&g_event.eventData.uartdata_evt; //Ql_SetSMSStorage=(0-3) Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_SetSMSStorage="); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { u8 storage; pChar+=17; storage=Ql_atoi(pChar); ret=Ql_SetSMSStorage(storage); OUT_DEBUG(debug_buffer,"\r\nQl_SetSMSStorage(storage=%d)=%d\r\n",storage,ret); break; } //Ql_GetSMSStorageInfo Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_GetSMSStorageInfo"); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { u8 current_mem,used,total; ret=Ql_GetSMSStorageInfo(¤t_mem, &used, &total); OUT_DEBUG(debug_buffer,"\r\nQl_GetSMSStorageInfo(current_mem=%d,used=%d,total=%d)=%d\r\n", current_mem,used,total,ret); break; } //Ql_SetInfoCentreNum="<sca number>" eg:Ql_SetInfoCentreNum="+8613800551500" Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_SetInfoCentreNum=\""); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { pChar+=21; pChar2 = Ql_strstr(pChar,"\""); *pChar2=0; ret=Ql_SetInfoCentreNum((u8*)pChar); OUT_DEBUG(debug_buffer,"\r\nQl_SetInfoCentreNum(sca_num=%s)=%d\r\n", pChar,ret); break; } //Ql_GetInfoCentreNum Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_GetInfoCentreNum"); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { u8 sca_number[40]; u8 type; ret=Ql_GetInfoCentreNum(sca_number,&type); OUT_DEBUG(debug_buffer,"\r\nQl_GetInfoCentreNum(sca_number=\"%s\",type=%d)=%d\r\n", sca_number,type,ret); break; } //Ql_SetNewSMSDirectToTE=(0,1) Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_SetNewSMSDirectToTE="); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { u8 op; pChar+=23; op=Ql_atoi(pChar); ret=Ql_SetNewSMSDirectToTE(op); OUT_DEBUG(debug_buffer,"\r\nQl_SetNewSMSDirectToTE(op=%d)=%d\r\n",op,ret); break; } //Ql_SetSMSFormat=(0,1) Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_SetSMSFormat="); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { u8 format; pChar+=16; format=Ql_atoi(pChar); ret=Ql_SetSMSFormat(format); OUT_DEBUG(debug_buffer,"\r\nQl_SetSMSFormat(format=%d)=%d\r\n",format,ret); break; } //Ql_ReadSMS=(1,300),(0,1) Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_ReadSMS="); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { u16 index; u8 mode; pChar+=11; index=Ql_atoi(pChar); pChar=Ql_strstr(pChar, ","); pChar++; mode=Ql_atoi(pChar); ret=Ql_ReadSMS(index,mode); OUT_DEBUG(debug_buffer,"\r\nQl_ReadSMS(index=%d,mode=%d)=%d\r\n",index,mode,ret); break; } //Ql_DeleteSMS=(1,300),(0,4) Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_DeleteSMS="); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { u16 index; u8 flag; pChar+=13; index=Ql_atoi(pChar); pChar=Ql_strstr(pChar, ","); pChar++; flag=Ql_atoi(pChar); ret=Ql_DeleteSMS(index,flag); OUT_DEBUG(debug_buffer,"\r\nQl_DeleteSMS(index=%d,flag=%d)=%d\r\n",index,flag,ret); break; } //Ql_ListSMS=(0,4) Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_ListSMS="); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { u8 by_status; u16 sms_count=0; QlSMSListNode sms_list[MAX_LIST_NODE_COUNT]; //MAX_LIST_NODE_COUNT should be set large enough pChar+=11; by_status=Ql_atoi(pChar); ret=Ql_ListSMS(sms_list, MAX_LIST_NODE_COUNT, by_status, &sms_count); OUT_DEBUG(debug_buffer,"\r\nQl_ListSMS(by_status=%d,node_count=%d,sms_count=%d)=%d\r\n", by_status,MAX_LIST_NODE_COUNT,sms_count,ret); if(0==ret) { for(i=0;i<sms_count;i++) { OUT_DEBUG(debug_buffer,"index=%d,status=%d\r\n",sms_list[i].index,sms_list[i].status); } } break; } //Ql_GetUnReadSMS=(0,1) Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_GetUnReadSMS="); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { u8 mode; pChar+=16; mode=Ql_atoi(pChar); ret=Ql_GetUnReadSMS(mode); OUT_DEBUG(debug_buffer,"\r\nQl_GetUnReadSMS(mode=%d)=%d\r\n",mode,ret); break; } //Ql_SendPDUSMS Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_SendPDUSMS"); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { u8 pdu_len; u8 pdu_string[]={0x00, //Set aside for SCA 0x31, //FO 0xff, //Set aside for MR /* 0x05, //DA Length 0x81, //DA type 0x01, 0x80, 0xf6, //DA:10086 */ 0x0b, //DA Length 0x81, //DA type 0x31, 0x58, 0x15, 0x64, 0x79, 0xf3, //DA:13855146973 0x00, //PID 0x00, //DCS 0x47, //VP 0x07, //UDH 0xd1, 0x7a, 0x79, 0x4c, 0x2f, 0xb3, 0x01 //UD:Quectel, GSM 7-bit coding }; pdu_len=sizeof(pdu_string); ret=Ql_SendPDUSMS(pdu_string,pdu_len); OUT_DEBUG(debug_buffer,"\r\nQl_SendPDUSMS(pdu_len=%d)=%d\r\n",pdu_len,ret); if(0==ret) { for(i=0;i<pdu_len;i++) { OUT_DEBUG(debug_buffer,"%02X",pdu_string[i]); } OUT_DEBUG(debug_buffer,"\r\n"); } break; } //Ql_SetTextSMSPara=(0-2),(0,1),(0,1) Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_SetTextSMSPara="); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { u8 chset,isflashsms,status_report; pChar+=18; chset=Ql_atoi(pChar); pChar=Ql_strstr(pChar, ","); pChar++; isflashsms=Ql_atoi(pChar); pChar=Ql_strstr(pChar, ","); pChar++; status_report=Ql_atoi(pChar); ret=Ql_SetTextSMSPara(chset, isflashsms, status_report); OUT_DEBUG(debug_buffer, "\r\nQl_SetTextSMSPara(chset=%d,isflashsms=%d,status_report=%d)=%d\r\n",chset,isflashsms,status_report,ret); break; } //Ql_SendTextSMS="<phone number>" Ql_memset(notes, 0x0, sizeof(notes)); Ql_sprintf(notes, "Ql_SendTextSMS=\""); pChar = Ql_strstr((char*)pDataEvt->data, notes); if (NULL != pChar) { pChar+=16; pChar2 = Ql_strstr(pChar,"\""); *pChar2=0; ret=Ql_SendTextSMS((u8*)pChar,(u8*)"Welcome to use Quectel module!", Ql_strlen((u8*)"Welcome to use Quectel module!")); OUT_DEBUG(debug_buffer, "\r\nQl_SendTextSMS(phone_num=\"%s\")=%d\r\n",pChar,ret); break; } Ql_SendToModem(ql_md_port1, (u8*)pDataEvt->data, pDataEvt->len); break; } default: break; } } }
static void CallBack_UART_Hdlr(Enum_SerialPort port, Enum_UARTEventType msg, bool level, void* customizedPara) { u32 rdLen=0; s32 ret; char *p=NULL; char *p1=NULL; char *p2=NULL; u8 write_buffer[4]={'a','b','c','D'}; u8 read_buffer[6]={0x00,0x00,0x00,0x00,0x00,0x00}; u8 registerAdrr[2]={0x01,0x45}; switch (msg) { case EVENT_UART_READY_TO_READ: { Ql_memset(m_Read_Buffer, 0x0, sizeof(m_Read_Buffer)); rdLen = Ql_UART_Read(port, m_Read_Buffer, sizeof(m_Read_Buffer)); //command-->Init the IIC , type 0 Лђеп 1. p = Ql_strstr(m_Read_Buffer,"Ql_IIC_Init="); if(p) { char* p1 = NULL; char* p2 = NULL; u8 NumberBuf[10]; s8 IIC_type=0; p1 = Ql_strstr(m_Read_Buffer, "="); p2 = Ql_strstr(m_Read_Buffer, "\r\n"); Ql_memset(NumberBuf, 0x0, sizeof(NumberBuf)); Ql_memcpy(NumberBuf, p1 + 1, p2 - p1 -1); IIC_type = Ql_atoi(NumberBuf); if(0 == IIC_type)// simultion iic test, and we choose PINNAME_GPIO4, PINNAME_GPIO5 for IIC SCL and SDA pins { ret = Ql_IIC_Init(0,PINNAME_CTS,PINNAME_RTS,0); if(ret < 0) { APP_DEBUG("\r\n<--Failed!! Ql_IIC_Init channel 0 fail ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--pins(%d & %d) Ql_IIC_Init channel 0 ret=%d-->\r\n",PINNAME_CTS,PINNAME_RTS,ret); break; } else if(1 == IIC_type)// IIC controller { ret = Ql_IIC_Init(1,PINNAME_RI,PINNAME_DCD,1); if(ret < 0) { APP_DEBUG("\r\n<--Failed!! IIC controller Ql_IIC_Init channel 1 fail ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--pins(SCL=%d,SDA=%d) IIC controller Ql_IIC_Init channel 1 ret=%d-->\r\n",PINNAME_RI,PINNAME_DCD,ret); break; } else { APP_DEBUG("\r\n<--IIC type error!!!!-->\r\n"); break; } } //command-->IIC config, IIC controller interface Ql_memset(m_buffer, 0x0, sizeof(m_buffer)); Ql_sprintf(m_buffer, "Ql_IIC_Config=0\r\n");// simultion IIC (channel 0) ret = Ql_strncmp(m_Read_Buffer, m_buffer, Ql_strlen(m_buffer)); if(0 == ret) { ret = Ql_IIC_Config(0,TRUE, 0x07, 0);// simultion IIC interface ,do not care the IicSpeed. if(ret < 0) { APP_DEBUG("\r\n<--Failed !!Ql_IIC_Config channel 0 fail ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--Ql_IIC_Config channel 0 ret=%d-->\r\n",ret); break; } //command-->IIC config, IIC controller interface Ql_memset(m_buffer, 0x0, sizeof(m_buffer)); Ql_sprintf(m_buffer, "Ql_IIC_Config=1\r\n");// IIC controller (channel 1) ret = Ql_strncmp(m_Read_Buffer, m_buffer, Ql_strlen(m_buffer)); if(0 == ret) { ret = Ql_IIC_Config(1,TRUE, 0x07, 300);// just for the IIC controller if(ret < 0) { APP_DEBUG("\r\n<--Failed !! IIC controller Ql_IIC_Config channel 1 fail ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--IIC controller Ql_IIC_Config channel 1 ret=%d-->\r\n",ret); break; } //command-->IIC write Ql_memset(m_buffer, 0x0, sizeof(m_buffer)); Ql_sprintf(m_buffer, "Ql_IIC_Write=0\r\n");// channel 0 ret = Ql_strncmp(m_Read_Buffer, m_buffer, Ql_strlen(m_buffer)); if(0 == ret) { ret = Ql_IIC_Write(0, 0x07, write_buffer, 4); if(ret < 0) { APP_DEBUG("\r\n<--Failed !! Ql_IIC_Write channel 0 fail ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--channel 0 Ql_IIC_Write ret=%d-->\r\n",ret); break; } Ql_memset(m_buffer, 0x0, sizeof(m_buffer)); Ql_sprintf(m_buffer, "Ql_IIC_Write=1\r\n");// channel 1 ret = Ql_strncmp(m_Read_Buffer, m_buffer, Ql_strlen(m_buffer)); if(0 == ret) { ret = Ql_IIC_Write(1, 0x07, write_buffer,4); if(ret < 0) { APP_DEBUG("\r\n<--Failed !! IIC controller Ql_IIC_Write channel 1 fail ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--IIC controller Ql_IIC_Write ret=%d-->\r\n",ret); break; } //command-->IIC read Ql_memset(m_buffer, 0x0, sizeof(m_buffer)); Ql_sprintf(m_buffer, "Ql_IIC_Read=0\r\n");// channel 0 ret = Ql_strncmp(m_Read_Buffer, m_buffer, Ql_strlen(m_buffer)); if(0 == ret) { ret = Ql_IIC_Read(0, 0x07, read_buffer, 6); if(ret < 0) { APP_DEBUG("\r\n<--Failed !! Ql_IIC_Read channel 0 fail ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--channel 0 Ql_IIC_Read ret=%d-->\r\n",ret); break; } Ql_memset(m_buffer, 0x0, sizeof(m_buffer)); Ql_sprintf(m_buffer, "Ql_IIC_Read=1\r\n");// channel 1 ret = Ql_strncmp(m_Read_Buffer, m_buffer, Ql_strlen(m_buffer)); if(0 == ret) { ret = Ql_IIC_Read(1, 0x07, write_buffer, 6); if(ret < 0) { APP_DEBUG("\r\n<--Failed !! IIC controller Ql_IIC_Read channel 1 fail ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--IIC controller Ql_IIC_Read ret=%d-->\r\n",ret); break; } //command-->IIC write then read Ql_memset(m_buffer, 0x0, sizeof(m_buffer)); Ql_sprintf(m_buffer, "Ql_IIC_Write_Read=0\r\n");// channel 0 ret = Ql_strncmp(m_Read_Buffer, m_buffer, Ql_strlen(m_buffer)); if(0 == ret) { ret = Ql_IIC_Write_Read(0, 0x07, registerAdrr, 2,read_buffer, 6); if(ret < 0) { APP_DEBUG("\r\n<--Failed !! Ql_IIC_Write_Read channel 0 fail ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--channel 0 Ql_IIC_Write_Read ret=%d-->\r\n",ret); break; } Ql_memset(m_buffer, 0x0, sizeof(m_buffer)); Ql_sprintf(m_buffer, "Ql_IIC_Write_Read=1\r\n");// channel 1 ret = Ql_strncmp(m_Read_Buffer, m_buffer, Ql_strlen(m_buffer)); if(0 == ret) { ret = Ql_IIC_Write_Read(1, 0x07, registerAdrr, 2,read_buffer, 6); if(ret < 0) { APP_DEBUG("\r\n<--Failed !! IIC controller Ql_IIC_Write_Read channel 1 fail ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--IIC controller Ql_IIC_Write_Read ret=%d-->\r\n",ret); break; } //command-->IIC write then read Ql_memset(m_buffer, 0x0, sizeof(m_buffer)); Ql_sprintf(m_buffer, "Ql_IIC_Uninit=0\r\n");// channel 0 ret = Ql_strncmp(m_Read_Buffer, m_buffer, Ql_strlen(m_buffer)); if(0 == ret) { ret = Ql_IIC_Uninit(0); if(ret < 0) { APP_DEBUG("\r\n<--Failed !! Ql_IIC_Uninit channel 0 fail ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--channel 0 Ql_IIC_Uninit ret=%d-->\r\n",ret); break; } Ql_memset(m_buffer, 0x0, sizeof(m_buffer)); Ql_sprintf(m_buffer, "Ql_IIC_Uninit=1\r\n");// channel 1 ret = Ql_strncmp(m_Read_Buffer, m_buffer, Ql_strlen(m_buffer)); if(0 == ret) { ret = Ql_IIC_Uninit(1); if(ret < 0) { APP_DEBUG("\r\n<--Failed !! IIC controller Ql_IIC_Uninit channel 1 fail ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--IIC controller (chnnlNo 1) Ql_IIC_Uninit ret=%d-->\r\n",ret); break; } APP_DEBUG("\r\n<--Not found this command, please check you command-->\r\n"); } default: break; } }
/****************************************************************** * Please refer to how to configure the constant * 'Customer_user_qlconfig' in ql_customer_config.c *******************************************************************/ void ql_entry() { bool keepGoing = TRUE; QlEventBuffer flSignalBuffer; s32 period = 10; char buffer[100]; char *pData, *p; QlAudioPlayPath path; Ql_SetDebugMode(BASIC_MODE); Ql_DebugTrace("headset: ql_entry\r\n"); Ql_OpenModemPort(ql_md_port1); while(keepGoing) { Ql_GetEvent(&flSignalBuffer); switch(flSignalBuffer.eventType) { case EVENT_POWERKEY: { if(flSignalBuffer.eventData.powerkey_evt.powerkey == POWERKEY_ON) { Ql_PowerOnAck(); Ql_sprintf(buffer, "\r\nNow, Power on System\r\n"); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); path = Ql_VoiceCallGetCurrentPath(); Ql_sprintf(buffer, "\r\nCurrent Voice call path is %d\r\n",path); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); Ql_VoiceCallChangePath(QL_AUDIO_PATH_LOUDSPEAKER); if(path == QL_AUDIO_PATH_NORMAL) { Ql_sprintf(buffer, "\r\nnow change to QL_AUDIO_PATH_LOUDSPEAKER\r\n"); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); } } else if(flSignalBuffer.eventData.powerkey_evt.powerkey == POWERKEY_OFF) { if( flSignalBuffer.eventData.powerkey_evt.isPressed) { Ql_sprintf(buffer, "\r\nNow, Press PWRKEY\r\n"); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); } else { Ql_sprintf(buffer, "\r\nNow, Release PWRKEY\r\n"); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); } } break; } case EVENT_HEADSET: { switch(flSignalBuffer.eventData.headset_evt.headsettype) { case HEADSET_PLUGOUT: Ql_sprintf(buffer, "\r\nHEADSET_PLUGOUT"); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); path = Ql_VoiceCallGetCurrentPath(); Ql_sprintf(buffer, "\r\nCurrent Voice call path is %d\r\n",path); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); #if 1 if(path != QL_AUDIO_PATH_LOUDSPEAKER) { Ql_sprintf(buffer, "\r\nnow change to QL_AUDIO_PATH_LOUDSPEAKER\r\n"); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); Ql_VoiceCallChangePath(QL_AUDIO_PATH_LOUDSPEAKER); } #endif break; case HEADSET_PLUGIN: Ql_sprintf(buffer, "\r\nHEADSET_PLUGIN"); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); path = Ql_VoiceCallGetCurrentPath(); Ql_sprintf(buffer, "\r\nCurrent Voice call path is %d\r\n",path); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); #if 1 if(path != QL_AUDIO_PATH_HEADSET) { Ql_sprintf(buffer, "\r\nnow change to QL_AUDIO_PATH_HEADSET\r\n"); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); Ql_VoiceCallChangePath(QL_AUDIO_PATH_HEADSET); } #endif break; case HEADSET_KEYPRESS: Ql_sprintf(buffer, "\r\nHEADSET_KEYPRESS"); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); break; case HEADSET_KEYRELEASE: Ql_sprintf(buffer, "\r\nHEADSET_KEYRELEASE"); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); break; case HEADSET_ADC: Ql_sprintf(buffer, "\r\nHEADSET_ADC:%d",flSignalBuffer.eventData.headset_evt.data1); Ql_SendToUart(ql_uart_port1,(u8*)buffer,Ql_strlen(buffer)); break; } break; } case EVENT_MODEMDATA: { //Ql_DebugTrace("\r\nEVENT_MODEMDATA type=%d \r\n",flSignalBuffer.eventData.modemdata_evt.type); //Ql_DebugTrace("\r\nmodemdata =%s\r\n",flSignalBuffer.eventData.uartdata_evt.data); //if (flSignalBuffer.eventData.modemdata_evt.type==DATA_AT) Ql_SendToUart(ql_uart_port1,(u8*)flSignalBuffer.eventData.uartdata_evt.data,flSignalBuffer.eventData.uartdata_evt.len); break; } case EVENT_UARTDATA: { //Ql_DebugTrace("\r\nEVENT_UARTDATA PORT=%d\r\n",flSignalBuffer.eventData.uartdata_evt.port); //Ql_DebugTrace("\r\nuart data =%s\r\n",flSignalBuffer.eventData.uartdata_evt.data); Ql_SendToModem(ql_md_port1,(u8*)flSignalBuffer.eventData.uartdata_evt.data,flSignalBuffer.eventData.uartdata_evt.len); 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); } }