-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathat_rsp_qlinkdatanode.c
1096 lines (929 loc) · 26.6 KB
/
at_rsp_qlinkdatanode.c
1
#include <string.h>#include <stdlib.h>#include "at_rsp_qlinkdatanode.h"#include "common_qlinkdatanode.h"#include "feature_macro_qlinkdatanode.h"#include "at_qlinkdatanode.h"#ifndef FEATURE_ENABLE_AT_RSP_qlinkdatanode_C_LOG #define LOG print_to_null#endif/******************************External Functions*******************************/extern int one_digit_hex_to_dec(const char digit); #ifdef FEATURE_ENABLE_CPOL_CONFIG extern unsigned long Ascii_To_int(char * pbuf, char datalen); #endif/******************************External Variables*******************************/extern At_Config at_config;extern Dev_Info sim5360_dev_info;extern rsmp_transmit_buffer_s_type g_rsmp_transmit_buffer[THD_IDX_MAX+1];extern bool isLogDumped;extern bool g_isEmodemcipopen_vaid;extern char LAST_Imodem_CELLID[4]; extern unsigned int MdmEmodemCountryType; extern unsigned int MdmEmodemMCCMNC;#ifdef FEATURE_ENABLE_3GONLY extern bool isneedtoset3Gonly;#endif#ifdef FEATURE_ENABLE_4G3GAUTO_FOR_US extern bool isneedtoset4G3Gauto;#endif/******************************Global Variables*******************************///Description:// If executing "AT+CIPSEND=0,X" returns "+CIPSEND: 0,X,0", app will execute "AT+CIPSEND=0,X" again right away.// And "+CIPERROR: 4" will be reported but following rsp "ERROR" is missed! This var is to avoid this condition where app// waits for missing rsp "ERROR".bool isCipsendFailedV01 = false;//Return Value:// The pointer which is pointed to the first valid char right after the prefix string (or ':').// For example, the URC report is "+NETCLOSE: 0", then the return pointer is pointed to// '0'.static char *skip_prefix(char *str){ int count; int eol_count; int len = strlen(str); char *p =NULL; if(str[0] != '+'){ LOG("ERROR: Wrong param input. No + found.\n"); return NULL; } for(count=1; (count<len)&&(str[count]!=':'); count++); //not include '\0' //len-1: last position if(count>=len-1 || count==1){ LOG("ERROR: ':' is at wrong position.\n"); return NULL; } if(str[count+1] == ' ') p = str+count+2; else if(str[count+1] == ' ' && str[count+2] == ' ') p = str+count+3; else p = str+count+1; for(eol_count=0; p[eol_count]!='\r' && p[eol_count]!='\n' && p[eol_count]!='\0'; eol_count++); p[eol_count] = '\0'; return p;}//return value// >=0: rssi// -1: Unexpected error// -2: Unexpected message found.int process_CSQ(Dev_Info *di, char *str){ char *p; unsigned int rssi = 0; int count = 0; if(str == NULL || di == NULL){ LOG("ERROR: Wrong param input.\n"); return -1; } if(strncmp(str, "+CSQ: ", 6) != 0){ LOG("ERROR: Unexpected message found. Message=%s.\n", str); return -2; } p = skip_prefix(str); for(; p[count]!=','; count++){ rssi *= 10; rssi += p[count]-'0'; } if(rssi == 99){ //di->sig_strength = rssi; }else if(rssi == 0){ //di->sig_strength = rssi; }#ifdef FEATURE_DISABLE_REDUNDANT_QRY_CMD_LOG if(isLogDumped){ //isLogDumped will be reset later in r_acqDataHdlr(). LOG("rssi = %d.\n", rssi); }#else di->sig_strength = rssi; LOG("rssi = %d.\n", rssi);#endif return rssi;}//Return Values:// >=0: Stat.// -1: Unexpected error.// -2: Unexpected msg found.int process_CGREG(char *str){ char *p_comma = NULL, *cur = NULL; int stat = 0; if(str == NULL){ LOG("ERROR: Wrong param input. str=null.\n"); return -1; } if(NULL == strstr(str, "+CGREG:")){ LOG("ERROR: Correct rsp prefix not found. str: %s.\n", str); return -2; } p_comma = strchr(skip_prefix(str), ','); if(p_comma == NULL){ LOG("ERROR: Wrong rsp format found. Comma not found! str: %s.\n", str); return -2; } for( cur=p_comma+1; *cur!='\r'&&*cur!='\n'&&*cur!='\0'&&*cur!=','; cur++){ stat *= 10; stat += *cur-'0'; } return stat;}int process_CGSN(char *str){ char *cur = str; int ret = 0; char count= 0; for(; *cur=='\r'||*cur=='\n'; cur++); strncpy(sim5360_dev_info.IMEI, cur, 15); for(count = 0;count < 15;count++) { if( (sim5360_dev_info.IMEI[count] >= 0x30 ) && (sim5360_dev_info.IMEI[count] <= 0x39 )) { ret = 1; } else { ret = -1; memset(sim5360_dev_info.IMEI, 0, 15); break; } } LOG("IMEI=%s.\n", sim5360_dev_info.IMEI); return ret;}/*void process_CPSI(char *str){ char *cur; char comma_cnt = 0; short mcc = 0; char mnc = 0; char lac[2] = {0,0}; cur = skip_prefix(str); for(; comma_cnt<2; cur++) if(*cur == ',') comma_cnt++; mcc = 100*(cur[0]-'0') + 10*(cur[1]-'0') + cur[2]-'0'; mnc = 10*(cur[4]-'0') + cur[5]-'0'; strncpy(dev_info.PLMN, (char *)(&mcc), 2); strncpy(dev_info.PLMN+2, &mnc, 1); lac[0] = 16*one_digit_hex_to_dec(cur[9])+one_digit_hex_to_dec(cur[10]); lac[1] = 16*one_digit_hex_to_dec(cur[11])+one_digit_hex_to_dec(cur[12]); strncpy(dev_info.LAC, lac, 2); LOG("PLMN=%s, LAC=%s.\n", dev_info.PLMN, dev_info.LAC);}*/int process_COPS(Dev_Info *di, char *str){ char *cur, *last_char; //Last char of MNC #ifdef FEATURE_ENABLE_CPOL_CONFIG_DEBUG char ptemp[6];#endif if(str == NULL || di == NULL){ LOG("ERROR: Wrong parameter input.\n"); return -1; } LOG("process_COPS =%s.\n", str); cur = strchr(str, '"'); // Find the first "(double quotation mark) if(cur == NULL) { if(strstr(str, "ERROR") != NULL){ LOG("NOTICE: Rsp \"ERROR\" found. USIM card may have been set unavailable.\n"); di->PLMN[0] = 0xff; di->PLMN[1] = 0xff; di->PLMN[2] = 0xff; return -1; } LOG("ERROR: Wrong response format. \" (double quotation mark) not found. Rsp: \"%s\".\n", str); di->PLMN[0] = 0xff; di->PLMN[1] = 0xff; di->PLMN[2] = 0xff; return -1; } cur++; last_char = strchr(cur, '"'); di->PLMN[0] = (cur[0]-'0')+16*(cur[1]-'0'); if(last_char - cur == 5){ di->PLMN[1] = cur[2]-'0'; di->PLMN[2] = (cur[3]-'0')+16*(cur[4]-'0'); MdmEmodemMCCMNC = Ascii_To_int(cur,5); LOG("MdmEmodemMCCMNC =%d.\n", MdmEmodemMCCMNC); }else{ // if(last_char - cur == 6) di->PLMN[1] = (cur[2]-'0')+16*(cur[3]-'0'); di->PLMN[2] = (cur[4]-'0')+16*(cur[5]-'0'); MdmEmodemMCCMNC = Ascii_To_int(cur,6); LOG("MdmEmodemMCCMNC =%d.\n", MdmEmodemMCCMNC); } //MdmEmodemMCCMNC = 25001; //ptemp[0] = 0x32; //ptemp[1] = 0x35; //ptemp[2] = 0x30; //MdmEmodemCountryType = Ascii_To_int(ptemp,3); MdmEmodemCountryType = Ascii_To_int(cur,3); LOG("MdmEmodemCountryType =%d.\n", MdmEmodemCountryType); #ifdef FEATURE_ENABLE_3GONLY /*if( (MdmEmodemCountryType == 510) ) // the function has been cancel { isneedtoset3Gonly = true; }*/ LOG("isneedtoset3Gonly =%d.\n", isneedtoset3Gonly);#endif#ifdef FEATURE_ENABLE_4G3GAUTO_FOR_US if(MdmEmodemCountryType == 310 ) //if( (MdmEmodemCountryType == 310) || (MdmEmodemCountryType == 460) ) { isneedtoset4G3Gauto = true; } LOG("isneedtoset4G3Gauto =%d.\n", isneedtoset4G3Gauto);#endif /*ptemp[0] = 0x32; ptemp[1] = 0x30; ptemp[2] = 0x34; ptemp[3] = 0x30; ptemp[4] = 0x34; /*ptemp[0] = 0x33; ptemp[1] = 0x31; ptemp[2] = 0x30; ptemp[3] = 0x34; ptemp[4] = 0x31; ptemp[5] = 0x30;*/ //MdmEmodemMCCMNC = Ascii_To_int(ptemp,3); // LOG("MdmEmodemMCCMNC =%d.\n", MdmEmodemMCCMNC); LOG("PLMN[0]=%d, PLMN[1]=%d, PLMN[2]=%d.\n", di->PLMN[0], di->PLMN[1], di->PLMN[2]); LOG("cur[0]=0x%02x, cur[1]=0x%02x, cur[2]=0x%02x, cur[3]=0x%02x,cur[4]=0x%02x.\n", cur[0], cur[1], cur[2],cur[3], cur[4]); return 0;}//Return Values:// 1 : Success// 0 : Not reg yet.//-1 : Wrong param input.//Modification Record://2015-8-17 : Add return value.int process_CGREG_lac_and_cellid(Dev_Info *di, char *str){ char *cur = NULL;char *pre = NULL; char *post=NULL;char *ptemp=NULL; char lac[2] = {0, 0}; char cellid[4] = {0,0,0,0}; int ret = -99; if(str == NULL || di == NULL){ LOG("ERROR: Wrong parameter input.\n"); return -1; } //add by jack 20160427 start ptemp = strchr(str, ','); if (NULL == ptemp) { LOG("ERROR: NULL == ptemp.\n"); return -1; } else { cur = strchr(ptemp+1, ','); } //add by jack 20160427 end if(NULL != cur) { pre = strchr(cur, '"'); //add by jack 20160427 start if (NULL == pre ) { LOG("ERROR: NULL == pre.\n"); return -1; } post = strchr(pre+1, '"'); if (NULL == post ) { LOG("ERROR: NULL == post.\n"); return -1; } //add by jack 20160427 end if(NULL!= pre && NULL != post) { if( (post-pre) == 5) { LOG("get Emodem LAC case 5\n");//"A835" cur = pre + 1; lac[1] = 16*one_digit_hex_to_dec(cur[2])+one_digit_hex_to_dec(cur[3]); lac[0] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((post-pre) == 4) { LOG("get LAC case 4\n");//"835" cur = pre + 1; lac[1] = 16*one_digit_hex_to_dec(cur[1])+one_digit_hex_to_dec(cur[2]); lac[0] = one_digit_hex_to_dec(cur[0]); }else if((post-pre) == 3) { LOG("get LAC case 3\n");//"35" cur = pre + 1; lac[1] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((post-pre) == 2) { LOG("get LAC case 2\n");//"5" cur = pre + 1; lac[1] = one_digit_hex_to_dec(cur[0]); }else { LOG("get LAC case 1 err fatal\n");//"" } } memcpy(di->LAC, lac, 2); cur = strchr(cur, ','); if (NULL == cur) { LOG("ERROR: NULL == cur.\n"); return -1; } if(NULL != cur) { LOG("get Emodem cell id... \n"); pre = strchr(cur, '"'); if (NULL == pre) { LOG("ERROR: NULL == pre.\n"); return -1; } post = strrchr(cur, '"'); if(NULL!= pre && NULL != post) { if( (post-pre) == 9) { LOG("get cellid case 9\n"); //"C8B6B8A7" cur = pre + 1; cellid[3] = 16*one_digit_hex_to_dec(cur[6])+one_digit_hex_to_dec(cur[7]); cellid[2] = 16*one_digit_hex_to_dec(cur[4])+one_digit_hex_to_dec(cur[5]); cellid[1] = 16*one_digit_hex_to_dec(cur[2])+one_digit_hex_to_dec(cur[3]); cellid[0] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if( (post-pre) == 8) { LOG("get cellid case 8\n"); //"8B6B8A7" cur = pre + 1; cellid[3] = 16*one_digit_hex_to_dec(cur[5])+one_digit_hex_to_dec(cur[6]); cellid[2] = 16*one_digit_hex_to_dec(cur[3])+one_digit_hex_to_dec(cur[4]); cellid[1] = 16*one_digit_hex_to_dec(cur[1])+one_digit_hex_to_dec(cur[2]); cellid[0] = one_digit_hex_to_dec(cur[0]); }else if((post-pre) == 7) { LOG("get cellid case 7\n"); //"B6B8A7" cur = pre + 1; cellid[3] = 16*one_digit_hex_to_dec(cur[4])+one_digit_hex_to_dec(cur[5]); cellid[2] = 16*one_digit_hex_to_dec(cur[2])+one_digit_hex_to_dec(cur[3]); cellid[1] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((post-pre) == 6) { LOG("get cellid case 6\n");//"6B8A7" cur = pre + 1; cellid[3] = 16*one_digit_hex_to_dec(cur[3])+one_digit_hex_to_dec(cur[4]); cellid[2] = 16*one_digit_hex_to_dec(cur[1])+one_digit_hex_to_dec(cur[2]); cellid[1] = one_digit_hex_to_dec(cur[0]); }else if((post-pre) == 5) { LOG("get cellid case 5\n"); //"B8A7" cur = pre + 1; cellid[3] = 16*one_digit_hex_to_dec(cur[2])+one_digit_hex_to_dec(cur[3]); cellid[2] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((post-pre) == 4) { LOG("get cellid case 4\n"); //"8A7" cur = pre + 1; cellid[3] = 16*one_digit_hex_to_dec(cur[1])+one_digit_hex_to_dec(cur[2]); cellid[2] = one_digit_hex_to_dec(cur[0]); }else if((post-pre) == 3) { LOG("get cellid case 3\n");//"A7" cur = pre + 1; cellid[3] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((post-pre) == 2) { LOG("get cellid case 2\n");//"7" cur = pre + 1; cellid[3] = one_digit_hex_to_dec(cur[0]); }else { LOG("get cellid case 1 err fatal\n");//"" } } memcpy(di->CELLID, cellid, 4); ret = 1; } //xiaobin add 20150215 }else{ (di->LAC)[0] = 0xff; (di->LAC)[1] = 0xff; ret = -2; } return ret;}// 1,A835,B66A3D,7int process_Imodem_CEREG_lac_and_cellid(Dev_Info *di, char *str){ char *cur = NULL;char *start = NULL; char *end=NULL; char lac[2] = {0, 0}; char cellid[4] = {0,0,0,0}; int ret = -99; LOG(" str <-- \"%s\" \n", str); if(str == NULL || di == NULL){ LOG("ERROR: Wrong parameter input.\n"); return -1; } // [1,A835,B6B8A7,7] // add by jack li 20160427 start start = strchr(str, ','); if (NULL == start) { LOG("ERROR: NULL == start.\n"); return -1; } else { start += 1; } end = strchr(start, ','); if (NULL == end) { LOG("ERROR: NULL == end.\n"); return -1; } else { end -= 1; } // add by jack li 20160427 end if(NULL!= start && NULL != end) { if( (end-start) == 3) { //LOG("get Imodem LAC case 3\n");//A835 cur = start; lac[1] = 16*one_digit_hex_to_dec(cur[2])+one_digit_hex_to_dec(cur[3]); lac[0] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((end-start) ==2) { // LOG("get LAC case 2\n");//835 cur = start; lac[1] = 16*one_digit_hex_to_dec(cur[1])+one_digit_hex_to_dec(cur[2]); lac[0] = one_digit_hex_to_dec(cur[0]); }else if((end-start) == 1) { // LOG("get LAC case 1\n");//35 cur = start; lac[1] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((end-start) == 0) { // LOG("get LAC case 0\n");//5 cur = start; lac[1] = one_digit_hex_to_dec(cur[0]); }else { LOG("get LAC case 1 err fatal\n");// } } memcpy(di->LAC, lac, 2); // if(NULL != end) { //LOG("get Imodem cell id... \n"); // add by jack li 20160427 start start = strchr(end, ','); if (NULL == start) { LOG("ERROR: NULL == start.\n"); return -1; } else { start += 1; } end = strchr(start, ','); if (NULL == end) { LOG("ERROR: NULL == end.\n"); return -1; } else { end -= 1; } // add by jack li 20160427 end if(NULL!= start && NULL != end ) { if( (end-start) == 7) { // LOG("get cellid case 7\n"); //C8B6B8A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[6])+one_digit_hex_to_dec(cur[7]); cellid[2] = 16*one_digit_hex_to_dec(cur[4])+one_digit_hex_to_dec(cur[5]); cellid[1] = 16*one_digit_hex_to_dec(cur[2])+one_digit_hex_to_dec(cur[3]); cellid[0] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if( (end-start) == 6) { // LOG("get cellid case 6\n"); //8B6B8A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[5])+one_digit_hex_to_dec(cur[6]); cellid[2] = 16*one_digit_hex_to_dec(cur[3])+one_digit_hex_to_dec(cur[4]); cellid[1] = 16*one_digit_hex_to_dec(cur[1])+one_digit_hex_to_dec(cur[2]); cellid[0] = one_digit_hex_to_dec(cur[0]); }else if((end-start) == 5) { // LOG("get cellid case 5\n");//B6B8A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[4])+one_digit_hex_to_dec(cur[5]); cellid[2] = 16*one_digit_hex_to_dec(cur[2])+one_digit_hex_to_dec(cur[3]); cellid[1] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((end-start) == 4) { // LOG("get cellid case 4\n"); //6B8A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[3])+one_digit_hex_to_dec(cur[4]); cellid[2] = 16*one_digit_hex_to_dec(cur[1])+one_digit_hex_to_dec(cur[2]); cellid[1] = one_digit_hex_to_dec(cur[0]); }else if((end-start) == 3) { // LOG("get cellid case 3\n");//B8A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[2])+one_digit_hex_to_dec(cur[3]); cellid[2] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((end-start) == 2) { // LOG("get cellid case 2\n");//5A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[1])+one_digit_hex_to_dec(cur[2]); cellid[2] = one_digit_hex_to_dec(cur[0]); }else if((end-start) == 1) { // LOG("get cellid case 1\n");//A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((end-start) == 0) { // LOG("get cellid case 0\n");//7 cur = start; cellid[3] = one_digit_hex_to_dec(cur[0]); }else { LOG("get cellid case 1 err fatal\n");// } } memcpy(di->CELLID, cellid, 4); memcpy(LAST_Imodem_CELLID, cellid, 4); ret = 1; } return ret;}// 1,A835,B66A3Dint process_Imodem_CGREG_lac_and_cellid(Dev_Info *di, char *str){ char *cur = NULL;char *start = NULL; char *end=NULL; char lac[2] = {0, 0}; char cellid[4] = {0,0,0,0}; int ret = -99; int urc_len = 0; if(str == NULL || di == NULL){ LOG("ERROR: Wrong parameter input.\n"); return -1; } LOG(" str <-- \"%s\" \n", str); // [1,A835,B6B8A7] start = strchr(str, ','); if(NULL == start) // add by jack li 20160427 start { LOG("ERROR: NULL == start.\n"); return -1; } else { start += 1; } end = strchr(start, ','); if(NULL == end) { LOG("ERROR: NULL == end.\n"); return -1; } else { end -= 1; } // add by jack li 20160427 end if(NULL!= start && NULL != end) { if( (end-start) == 3) { //LOG("get Imodem LAC case 3\n");//A835 cur = start; lac[1] = 16*one_digit_hex_to_dec(cur[2])+one_digit_hex_to_dec(cur[3]); lac[0] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((end-start) == 2) { //LOG("get LAC case 2\n");//835 cur = start; lac[1] = 16*one_digit_hex_to_dec(cur[1])+one_digit_hex_to_dec(cur[2]); lac[0] = one_digit_hex_to_dec(cur[0]); }else if((end-start) == 1) { // LOG("get LAC case 1\n");//35 cur = start; lac[1] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((end-start) == 0) { // LOG("get LAC case 0\n");//5 cur = start; lac[1] = one_digit_hex_to_dec(cur[0]); }else { LOG("get LAC case 1 err fatal\n");// } } memcpy(di->LAC, lac, 2); // [1,A835,B6B8A7] if(NULL != end) { //LOG("get Imodem cell id... \n"); // add by jack li 20160427 start start = strchr(end, ','); if (NULL == start) { LOG("ERROR: NULL == start.\n"); return -1; } else { start += 1; } // add by jack li 20160427 end end = str + (strlen(str) - 1); if(NULL!= start && NULL != end ) { if( (end-start) == 7) { // LOG("get cellid case 7\n"); //C8B6B8A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[6])+one_digit_hex_to_dec(cur[7]); cellid[2] = 16*one_digit_hex_to_dec(cur[4])+one_digit_hex_to_dec(cur[5]); cellid[1] = 16*one_digit_hex_to_dec(cur[2])+one_digit_hex_to_dec(cur[3]); cellid[0] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if( (end-start) == 6) { // LOG("get cellid case 6\n"); //8B6B8A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[5])+one_digit_hex_to_dec(cur[6]); cellid[2] = 16*one_digit_hex_to_dec(cur[3])+one_digit_hex_to_dec(cur[4]); cellid[1] = 16*one_digit_hex_to_dec(cur[1])+one_digit_hex_to_dec(cur[2]); cellid[0] = one_digit_hex_to_dec(cur[0]); }else if((end-start) == 5) { // LOG("get cellid case 5\n");//B6B8A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[4])+one_digit_hex_to_dec(cur[5]); cellid[2] = 16*one_digit_hex_to_dec(cur[2])+one_digit_hex_to_dec(cur[3]); cellid[1] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((end-start) == 4) { // LOG("get cellid case 4\n"); //6B8A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[3])+one_digit_hex_to_dec(cur[4]); cellid[2] = 16*one_digit_hex_to_dec(cur[1])+one_digit_hex_to_dec(cur[2]); cellid[1] = one_digit_hex_to_dec(cur[0]); }else if((end-start) == 3) { // LOG("get cellid case 3\n");//B8A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[2])+one_digit_hex_to_dec(cur[3]); cellid[2] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((end-start) == 2) { // LOG("get cellid case 2\n");//5A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[1])+one_digit_hex_to_dec(cur[2]); cellid[2] = one_digit_hex_to_dec(cur[0]); }else if((end-start) == 1) { // LOG("get cellid case 1\n");//A7 cur = start; cellid[3] = 16*one_digit_hex_to_dec(cur[0])+one_digit_hex_to_dec(cur[1]); }else if((end-start) == 0) { LOG("get cellid case 0\n");//7 cur = start; cellid[3] = one_digit_hex_to_dec(cur[0]); }else { LOG("get cellid case 1 err fatal\n");// } } memcpy(di->CELLID, cellid, 4); memcpy(LAST_Imodem_CELLID, cellid, 4); ret = 1; } return ret;}//Return Values:// >=0 : The AT cmd result val.// -1 : Wrong param input.// -2 : Unexpected msg found.int process_NETOPEN(char *str){ char *p =NULL; int i = 0, val = 0; if(str == NULL){ LOG("ERROR: Wrong parameter input. str=null.\n"); return -1; } if(NULL == strstr(str, "+NETOPEN:")){ LOG("ERROR: Correct rsp prefix not found. str: %s.\n", str); return -2; } for(p = skip_prefix(str); p[i]!='\r'&&p[i]!='\n'&&p[i]!='\0'; i++){ val *= 10; val += p[i]-'0'; }// LOG("\"AT+NETOPEN\" succeed.\n"); return val;}//Return Values:// >=0 : The 2nd param of rsp.// -1 : Wrong param input.// -2 : Unexpected msg found.int process_CIPOPEN(char *str){ char *p_comma = NULL, *cur = NULL; int val = 0, ret = -99; int v_linknum = 0; int v_error = 0;// LOG6("~~~~ process_CIPOPEN ~~~~\n"); if(str == NULL){ LOG("ERROR: Wrong param input. str=null.\n"); return -1; } if(NULL == strstr(str, "+CIPOPEN:")){ LOG("ERROR: Correct rsp prefix not found. str: %s.\n", str); return -2; } p_comma = strchr(skip_prefix(str), ','); if(NULL == p_comma){ LOG("ERROR: Wrong rsp format found. Comma not found! str: %s.\n", str); return -2; } for( cur=p_comma+1; *cur!='\r'&&*cur!='\n'&&*cur!='\0'; cur++){ val *= 10; val += *cur-'0'; } // LOG("\"+CIPOPEN: X,%d\" \n", val); cur=p_comma-1; v_linknum *= 10; v_linknum += *cur-'0'; LOG("Debug: v_linknum ====== %d\" \n", v_linknum); LOG("Debug: val ====== %d\" \n", val); if ((v_linknum == 0) && (val == 0)){ g_isEmodemcipopen_vaid = 1; } else if ((v_linknum == 1) && (val == 0)){ g_isEmodemcipopen_vaid = 2; } else{ g_isEmodemcipopen_vaid = 0; } // g_isEmodemcipopen_vaid = val; LOG("Debug: g_isEmodemcipopen_vaid ====== %d\" \n", g_isEmodemcipopen_vaid); switch(val){ case 0:{ print_cur_gm_time(" Server Connected "); break; } default: break; } ret = val; return ret;}//Return Values:// 3: Unexpected msg found.// 2: AT+CIPSEND fail// 1: Success// 0: Errorint process_CIPSEND(char *str){ char *p = NULL; int req = 0; int cnf = 0; int count = 0; int len = strlen(str); //index of first char of <reqSendLength> int i_req = 0; //index of first char of <cnfSendLength> int i_cnf = 0; //index of '\0' int i_end = 0; rsmp_transmit_buffer_s_type *p_req_cfg = &g_rsmp_transmit_buffer[THD_IDX_EVTLOOP]; if(str == NULL){ LOG("ERROR: Wrong param input. str=null.\n"); return 0; } if(NULL == strstr(str, "+CIPSEND:")){ LOG("ERROR: Wrong rsp prefix found. Rsp: \"%s\".\n", str); return 3; } p = skip_prefix(str); if(at_config.net_config.link_num != p[count]-'0'){ LOG("ERROR: Wrong link index found! Expected index: %d, actual index: %d.\n", at_config.net_config.link_num, p[count]-'0'); return 0; } for(; count<len&&p[count]!=','; count++); if(count == len){ LOG("ERROR: Wrong response format found. Not find 1st ','.\n"); return 3; } count++; i_req = count; for(; count<len&&p[count]!=','; count++); if(count == len){ LOG("ERROR: Wrong response format found. Not find 2nd ','.\n"); return 3; } count++; i_cnf = count; for(; count<len&&p[count]!='\0'; count++); if(count == len){ LOG("ERROR: Unexpected error happened. Not find '\\0'.\n"); //No '\0' found in the end of "<link_num>,<reqSendLength>,<cnfSendLength>" return 0; } i_end = count; for( count=i_req; count<i_cnf-1; count++){ req*=10; req+=p[count]-'0'; } for( count=i_cnf; count<i_end; count++){ cnf*=10; cnf+=p[count]-'0'; } if(req != cnf){ LOG("ERROR: AT cmd failed. req=%d. cnf=%d.\n", req, cnf); isCipsendFailedV01 = true; //Add by rjf at 20151016 return 2; }else if(p_req_cfg->size != req){ LOG("ERROR: Unexpected error! req=%d, p_req_cfg->size=%d.\n", req, p_req_cfg->size); return 2; } print_cur_gm_time(" App->server ");// LOG("\"AT+CIPSEND\" succeed.\n"); return 1;}//Return Value:// >=0: Result.// -1: Wrong param input.// -2: skip_prefix() error.// -3: Unexpected msg recved. No comma found.int process_CIPCLOSE(char *rsp){ char *p = NULL, *p_comma = NULL; int result = 0; LOG6("~~~~ process_CIPCLOSE ~~~~\n"); if(rsp == NULL){ LOG("ERROR: Wrong param input. rsp=NULL.\n"); return -1; } p = skip_prefix(rsp); if(p == NULL){ LOG("ERROR: skip_prefix() error.\n"); return -2; } p_comma = strchr(p, ','); if(p_comma == NULL){ LOG("ERROR: No comma mark found!\n"); return -3; } p = p_comma+1; for(; *p!='\0'&&*p!='\r'&&*p!='\n'; p++){ result *= 10; result += *p-'0'; } return result;}//Return Value:// >=0: The val of "X" in "+NETCLOSE: X".// -1: Wrong param input.// -2: skip_prefix() error.// -3: Unexpected URC report found.int process_NETCLOSE(char *rsp){ char *p = NULL; int result = 0; LOG6("~~~~ process_NETCLOSE ~~~~\n"); if(rsp == NULL){ LOG("ERROR: Wrong param input. rsp=NULL.\n"); return -1; } if(strstr(rsp, "+NETCLOSE:") == NULL){ LOG("NOTICE: Wrong URC report found. Msg: %s.\n", rsp); return -3; } p = skip_prefix(rsp); if(p == NULL){ LOG("ERROR: skip_prefix() error.\n"); return -2; } for(; *p!='\0'&&*p!='\r'&&*p!='\n'; p++){ result *= 10; result += *p-'0'; } return result;}