char * Gobi_FwVersion(char *line, int size) { const char *atCmd = "I"; const char *tmpFile = "/tmp/ati"; char *p = NULL; if (Gobi_AtCommand(atCmd, tmpFile) >= 0 && (p = get_line_by_str(line, size, tmpFile, "WWLC")) != NULL) { skip_space(p); cut_space(p); } return p; }
char * Gobi_BandChannel(char *line, int size) { const char *atCmd = "$CRFI"; const char *tmpFile = "/tmp/at_crfi"; char *p = NULL; if (Gobi_AtCommand(atCmd, tmpFile) >= 0 && (p = get_line_by_str(line, size, tmpFile, "$CRFI:")) != NULL) { skip_space(p); cut_space(p); } return p; }
char * Gobi_QcnVersion(char *line, int size) { const char *atCmd = "$QCNVER"; const char *tmpFile = "/tmp/at_qcnver"; char *p = NULL; if (Gobi_AtCommand(atCmd, tmpFile) >= 0 && (p = get_line_by_num(line, size, tmpFile, 3)) != NULL) { skip_space(p); cut_space(p); } return p; }
// system("chat -t 1 -e '' 'AT$CBEARER' OK >> /dev/ttyACM0 < /dev/ttyACM0 2>/tmp/at_cbearer; st=`grep '$CBEARER:' /tmp/at_cbearer | awk -F: '{print $2}'` ; echo $st | grep '0x0[1-9A-D]' -q && v=$st || v=FAIL; echo $v"); int Gobi_ConnectStatus_Int(void) { const char *atCmd = "$CBEARER"; const char *tmpFile = "/tmp/at_cbearer"; char line[128]; char *p; int value = 0; if (Gobi_AtCommand(atCmd, tmpFile) >= 0 && (p = get_line_by_str(line, sizeof(line), tmpFile, "$CBEARER:")) != NULL) { skip_space(p); cut_space(p); value = strtoul(p, NULL, 0); } return value; }
// system("chat -t 1 -e '' 'AT+CGSN' OK >> /dev/ttyACM0 < /dev/ttyACM0 2>/tmp/at_cgsn; [ `sed -n 4p /tmp/at_cgsn | wc -m ` = 16 ] && v=`sed -n 4p /tmp/at_cgsn` || v=FAIL; echo $v"); char *Gobi_IMEI(char *line, int size) { const char *atCmd = "+CGSN"; const char *tmpFile = "/tmp/at_cgsn"; char *p; if (Gobi_AtCommand(atCmd, tmpFile) >= 0 && (p = get_line_by_num(line, size, tmpFile, 3)) != NULL) { int cnt; skip_space(p); cut_space(p); for(cnt = 0; cnt <= 15 && isdigit(p[cnt]); cnt++) ; if (cnt == 15 && !isdigit(p[cnt])) return p; } return NULL; }
int Gobi_SignalLevel_Int(void) { const char *atCmd = "$CSIGNAL"; const char *tmpFile = "/tmp/at_csignal"; char line[128]; char *p; int value = 0; if (Gobi_AtCommand(atCmd, tmpFile) >= 0 && (p = get_line_by_str(line, sizeof(line), tmpFile, "$CSIGNAL:")) != NULL) { skip_space(p); cut_space(p); if (*p == '-') { p++; value = - strtoul(p, NULL, 0); } } return value; }
// system("chat -t 1 -e '' 'AT+CSQ' OK >> /dev/ttyACM0 < /dev/ttyACM0 2>/tmp/at_csq; sg=`grep +CSQ: /tmp/at_csq | awk -F: '{print $2}'` ; echo $sg | grep ,99 -q && v=`echo $sg | awk -F, '{print $1}'` || v=FAIL; echo $v"); int Gobi_SignalQuality_Int(void) { const char *atCmd = "+CSQ"; const char *tmpFile = "/tmp/at_csq"; char line[128]; char *p; int value = -1; if (Gobi_AtCommand(atCmd, tmpFile) >= 0 && (p = get_line_by_str(line, sizeof(line), tmpFile, "+CSQ:")) != NULL) { char *p2; skip_space(p); cut_space(p); if ((p2 = strstr(p, ",99")) != NULL) { *p2 = '\0'; value = strtoul(p, NULL, 0); } } return value; }
// system("chat -t 1 -e '' 'AT+CGNWS' OK >> /dev/ttyACM0 < /dev/ttyACM0 2>/tmp/at_cgnws; grep +CGNWS: /tmp/at_cgnws | awk -F, '{print $4}' | grep 0x01 -q && v=`grep +CGNWS: /tmp/at_cgnws | awk -F, '{print $7}'` || v=FAIL; echo $v"); char *Gobi_ConnectISP(char *line, int size) { const char *atCmd = "+CGNWS"; const char *tmpFile = "/tmp/at_cgnws"; char str[64]; char *p; if (Gobi_AtCommand(atCmd, tmpFile) >= 0 && (p = get_line_by_str(line, size, tmpFile, "+CGNWS:")) != NULL) { char *f; skip_space(p); cut_space(p); if ((f = find_field(p, ',', 3, str)) != NULL) { if (strcmp(str, "0x01") == 0) { if((f = find_field(p, ',', 6, str)) != NULL && strcmp(str, "NULL")) // SPN { strcpy(line,str); return line; } else if((f = find_field(p, ',', 7, str)) != NULL) // long name { strcpy(line,str); return line; } else if((f = find_field(p, ',', 8, str)) != NULL) // short name { strcpy(line,str); return line; } } } } return NULL; }
/* * * fetch the first part of a variable * fp = stream * section_name = section_name * if NULL sections are ignored * var_name = variable name * mode = 0 -> normal mode * 1 -> global mode * returns char * item * NULL = error * */ char * real_get_config_item(FILE *fp,char *section_name,char *var_name,int mode) { char *c; c=real_get_config(fp,section_name,var_name,mode); if(c!=NULL) { if (c[0]=='\"') { rmpos(c,0); cut_after_quote(c); } else { cut_space(c); } if(strlen(c)==0) { xfree(c); c=NULL; } else { xrealloc(c,strlen(c)+1); } } return(c); }
char * Gobi_SelectBand(const char *band, char *line, int size) { const char *atCmd1; const char *atCmd2 = "+CSETPREFNET=11"; const char *atCmd3 = "+CFUN=1,1"; const char *tmpFile1 = "/tmp/at_nv65633"; const char *tmpFile2 = "/tmp/at_csetprefnet"; const char *tmpFile3 = "/tmp/at_cfun"; char *p = NULL; if (band == NULL) { atCmd1 = "$NV65633=0000002000080044"; atCmd2 = "+CSETPREFNET=10"; } else if (strcmp(band, "B3") == 0) atCmd1 = "$NV65633=0000000000000004"; else if (strcmp(band, "B7") == 0) atCmd1 = "$NV65633=0000000000000040"; else if (strcmp(band, "B20") == 0) atCmd1 = "$NV65633=0000000000080000"; else if (strcmp(band, "B38") == 0) atCmd1 = "$NV65633=0000002000000000"; else return NULL; if (Gobi_AtCommand(atCmd1, tmpFile1) >= 0 && Gobi_AtCommand(atCmd2, tmpFile2) >= 0 && Gobi_AtCommand(atCmd3, tmpFile3) >= 0 && (p = get_line_by_num(line, size, tmpFile2, 1)) != NULL) { skip_space(p); cut_space(p); } return p; }
int checkline_inf(char *str) { char **tmp; char *line; tmp = NULL; if (str[0] == START_OBJ || str[0] == COMMENT) return (0); tmp = ft_strsplit(str, BREAK); line = tmp[0]; tmp[0] = ft_strsub(tmp[0], cut_space(tmp[0]), ft_strlen(tmp[0])); free(line); if (!ft_strcmp(tmp[0], "numbers of light")) return (free_ret(1, tmp)); if (!ft_strcmp(tmp[0], "numbers of object")) return (free_ret(2, tmp)); if (!ft_strcmp(tmp[0], "point of view")) return (free_ret(3, tmp)); if (!ft_strcmp(tmp[0], "look at")) return (free_ret(4, tmp)); if (!ft_strcmp(tmp[0], "color ambient")) return (free_ret(5, tmp)); return (free_ret(-1, tmp)); }