lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /***************************************************************/
|
| 2 | //
|
| 3 | //À©Õ¹atÃüÁ¾ß¼¯£¬ÓÃÓÚÉú³ÉºÍ½âÎöÀ©Õ¹atÃüÁî
|
| 4 | //¶¯×÷ÇëÇó£ºat+xx=yy,zz\r\n
|
| 5 | //²éѯÇëÇó: at+xx? \r\n
|
| 6 | //Ö÷¶¯Éϱ¨: \r\n+xx:yy,zz\r\n
|
| 7 | //½á¹ûÂ룺\r\nok:2\r\n
|
| 8 | // \r\nerror:ww\r\n
|
| 9 | //±¸×¢£ºÆäÖУ¬xxΪATÃüÁîÃû£»yyΪ²ÎÊý1µÄÖµ£¬zzΪ²ÎÊý2µÄÖµ£»wwΪ¾ßÌåµÄ´íÎóÂëÖµ£¬Èç¹ûûÓдíÎóÂ룬ĬÈÏΪ0.
|
| 10 | //
|
| 11 | /***************************************************************/
|
| 12 | #include "at_utils.h"
|
| 13 | #include <stdio.h>
|
| 14 | #include <stdlib.h>
|
| 15 | #include <string.h>
|
| 16 | #include "zxic_errno.h"
|
| 17 | #include "at_msg.h"
|
| 18 | #include "softap_log.h"
|
| 19 | #include <ctype.h>
|
| 20 | #include <sys/time.h>
|
| 21 | #include <termios.h>
|
| 22 |
|
| 23 | #define DIFF_VALUE ('a'-'A')
|
| 24 | #define AT_PARAM_MAX_NUM (50)
|
| 25 |
|
| 26 | /***************************************************************/
|
| 27 | //
|
| 28 | //Éú³Éat¶¯×÷ÇëÇóÃüÁî,Ò»°ãÔÚapp_clt_ops_tÖе÷Ó㬸ù¾ÝÏûÏ¢ÄÚÈÝ£¬Éú³É×îÖÕµÄatÇëÇóÃüÁî
|
| 29 | //Éú³ÉatÇëÇóÃüÁîʱ£¬±ØÐëͨ¹ýmallocÉêÇëʹÓõÄÄڴ棬²¢·µ»Ø¸ÃÖ¸Õë¸øÍâ²ãµ÷Óú¯ÊýʹÓã¬
|
| 30 | //×îÖÕÓÉÍâ²ãµ÷Óú¯ÊýÊͷŸÃÄÚ´æ
|
| 31 | //input: cmd "xx"
|
| 32 | // param "yy,zz"
|
| 33 | //output: at+xx=yy,zz\r\n
|
| 34 | /***************************************************************/
|
| 35 |
|
| 36 | char* at_act_build(char* cmd, char* param)
|
| 37 | {
|
| 38 | char * at_str;
|
| 39 | if(param)
|
| 40 | {
|
| 41 | at_str = malloc(32 + strlen(cmd) + strlen(param));
|
| 42 | }
|
| 43 | else
|
| 44 | {
|
| 45 | at_str = malloc(32 + strlen(cmd));
|
| 46 | }
|
| 47 | assert(at_str);
|
| 48 | //if(!at_str)
|
| 49 | //return NULL;
|
| 50 | if(param)
|
| 51 | sprintf(at_str,"at+%s=%s\r\n",cmd,param);
|
| 52 | else
|
| 53 | sprintf(at_str,"at+%s\r\n",cmd);
|
| 54 | return at_str;
|
| 55 |
|
| 56 | }
|
| 57 |
|
| 58 |
|
| 59 | /***************************************************************/
|
| 60 | //Éú³Éat²éѯÇëÇóÃüÁһ°ãÔÚapp_clt_ops_tÖе÷Ó㬸ù¾ÝÏûÏ¢ÄÚÈÝ£¬Éú³É×îÖÕµÄatÇëÇóÃüÁî
|
| 61 | //Éú³Éat²éѯÃüÁîʱ£¬Í¨¹ýmallocÉêÇëʹÓõÄÄڴ棬²¢·µ»Ø¸ÃÖ¸Õë¸øÍâ²ãµ÷Óú¯ÊýʹÓã¬
|
| 62 | //×îÖÕÓÉÍâ²ãµ÷Óú¯ÊýÊͷŸÃÄÚ´æ
|
| 63 | //input: cmd "xx"
|
| 64 | //output: at+xx? \r\n
|
| 65 | /***************************************************************/
|
| 66 | char* at_query_build(char* cmd)
|
| 67 | {
|
| 68 | char * at_str;
|
| 69 |
|
| 70 | at_str = malloc(32 + strlen(cmd)); //ÓÉat_ctl¸ºÔðÊÍ·Å
|
| 71 | assert(at_str);
|
| 72 | //if(!at_str)
|
| 73 | //return NULL;
|
| 74 | sprintf(at_str,"at+%s?\r\n",cmd);
|
| 75 |
|
| 76 | return at_str;
|
| 77 |
|
| 78 | }
|
| 79 |
|
| 80 |
|
| 81 | /***************************************************************/
|
| 82 | //Éú³Éat²éѯÇëÇóÃüÁîµÄÏìÓ¦ÃüÁµ±ÓÐÖмä½á¹ûÉϱ¨Ê±£¬ÔÚser_ops_t2µÄrsp_actµ÷Óã¬
|
| 83 | //¸Ãº¯ÊýÖн«ÖмäÉϱ¨½á¹ûºÍokatÃüÁî×é×°ÔÚÒ»Æð£¬Í¨¹ýmallocÉêÇëʹÓõÄÄڴ棬²¢·µ»Ø
|
| 84 | //¸ÃÖ¸Õë¸øÍâ²ãµ÷Óú¯ÊýʹÓã¬×îÖÕÓÉÍâ²ãµ÷Óú¯ÊýÊͷŸÃÄÚ´æ
|
| 85 | //input: cmd "xx"
|
| 86 | // param "yy,zz"
|
| 87 | //output: \r\n+xx:yy,zz\r\n
|
| 88 | /***************************************************************/
|
| 89 | char* at_query_result_build(char* cmd, char* param)
|
| 90 | {
|
| 91 | char * at_str;
|
| 92 |
|
| 93 | if(param)
|
| 94 | {
|
| 95 | at_str = malloc(32 + strlen(cmd) + strlen(param));
|
| 96 | }
|
| 97 | else
|
| 98 | {
|
| 99 | at_str = malloc(32 + strlen(cmd));
|
| 100 | }
|
| 101 | assert(at_str);
|
| 102 | //if(!at_str)
|
| 103 | //return NULL;
|
| 104 | if(!param)
|
| 105 | sprintf(at_str,"\r\n+%s\r\n\r\nOK\r\n",cmd);
|
| 106 | else
|
| 107 | sprintf(at_str,"\r\n+%s: %s\r\n\r\nOK\r\n",cmd,param);
|
| 108 |
|
| 109 | return at_str;
|
| 110 |
|
| 111 | }
|
| 112 |
|
| 113 | /***************************************************************/
|
| 114 | //Éú³ÉatµÄokÏìÓ¦ÃüÁ¸ù¾Ý²ÎÊýÐÅÏ¢Éú³É²»Í¬µÄokÏìÓ¦ÃüÁî
|
| 115 | //ͨ¹ýmallocÉêÇëʹÓõÄÄڴ棬²¢·µ»Ø¸ÃÖ¸Õë¸øÍâ²ãµ÷Óú¯ÊýʹÓã¬×îÖÕÓÉÍâ²ãµ÷Óú¯ÊýÊͷŸÃÄÚ´æ
|
| 116 | //input: param "xx"
|
| 117 |
|
| 118 | //output: \r\nok:xx
|
| 119 | /***************************************************************/
|
| 120 |
|
| 121 |
|
| 122 | char* at_ok_build()
|
| 123 | {
|
| 124 | char * at_str;
|
| 125 |
|
| 126 | at_str = malloc(32); //ÓÉat_ctl¸ºÔðÊÍ·Å
|
| 127 | assert(at_str);
|
| 128 |
|
| 129 | sprintf(at_str,"\r\nOK\r\n");
|
| 130 |
|
| 131 |
|
| 132 | return at_str;
|
| 133 |
|
| 134 | }
|
| 135 |
|
| 136 | /***************************************************************/
|
| 137 | //Éú³ÉatµÄerrÏìÓ¦ÃüÁ¸ù¾Ý²ÎÊýÐÅÏ¢Éú³É²»Í¬µÄerrÏìÓ¦ÃüÁî
|
| 138 | //ͨ¹ýmallocÉêÇëʹÓõÄÄڴ棬²¢·µ»Ø¸ÃÖ¸Õë¸øÍâ²ãµ÷Óú¯ÊýʹÓã¬×îÖÕÓÉÍâ²ãµ÷Óú¯ÊýÊͷŸÃÄÚ´æ
|
| 139 | //input: param xx
|
| 140 | //output: \r\nerr:xx
|
| 141 | /***************************************************************/
|
| 142 |
|
| 143 |
|
| 144 | char* at_err_build(int param)
|
| 145 | {
|
| 146 | char *at_str = NULL;
|
| 147 |
|
| 148 | at_str = malloc(32);
|
| 149 |
|
| 150 | assert(at_str);
|
| 151 | if(param == 0)
|
| 152 | sprintf(at_str,"\r\nERROR\r\n");
|
| 153 | else
|
| 154 | sprintf(at_str,"\r\n+CME ERROR: %d\r\n",param);
|
| 155 |
|
| 156 | return at_str;
|
| 157 |
|
| 158 | }
|
| 159 |
|
| 160 | static int is_digit_str(const char *str)
|
| 161 | {
|
| 162 | unsigned int digit_len = 0;
|
| 163 | while(*str == ' '){
|
| 164 | str++;
|
| 165 | }
|
| 166 | if(*str == '-' || *str == '+'){
|
| 167 | str++;
|
| 168 | }
|
| 169 | while(isdigit(*str)){
|
| 170 | str++;
|
| 171 | digit_len++;
|
| 172 | }
|
| 173 | while(*str == ' '){
|
| 174 | str++;
|
| 175 | }
|
| 176 | return *str == '\0' && digit_len > 0;
|
| 177 | }
|
| 178 |
|
| 179 |
|
| 180 | /*¸Ãº¯ÊýÓÃÓÚ°´ÕÕ¸ø¶¨µÄ¸ñʽ½âÎö²ÎÊý£¬¸ñʽ½öÖ§³Ö%dºÍ%s,ͬʱ¿ÉÒÔÔÚÿ¸ö¸ñʽǰ¼ÓÉÏÊý×ÖÒÔÖ¸¶¨
|
| 181 | ±äÁ¿¿ÉÒÔ¸³ÖµµÄ¿Õ¼ä´óС£¬µ¥Î»Îª×Ö½Ú£¬ÀýÈç%2d±íʾ½ÓÊÜ´æ´¢¿Õ¼äΪ2×Ö½Ú£»%5s±íʾËãÉÏ'\0'£¬×î¶à¿ÉÒÔ
|
| 182 | ½ÓÊÜ5¸ö×Ö·û¡£µ±%d²»Ö¸¶¨Êý×Öʱ£¬°´ÕÕ4×Ö½Ú½øÐи³Öµ£¬%sÔò°´ÕÕʵ¼Ê½âÎöµÄ×Ö·û´®³¤¶ÈÍêÈ«¸³Öµ£¬ÓпÉÄÜ
|
| 183 | »áÓÐÔ½½ç¡£´ËÍâÓû§Ê¹ÓÃʱ£¬Èô²»ÏëÓɸýӿÚÄÚ²¿½øÐвÎÊýµÄ¸ñʽ»¯½âÎö£¬¿ÉÒÔ½«fmt¸³ÖµÎª"%s"£¬
|
| 184 | pval¸³ÖµÎªchar **p˫ָÕ룬ÕâÑù²ÎÊý½«×÷ΪÕûÌå×Ö·û´®·µ»Ø¸øµ÷ÓÃÕß*/
|
| 185 | int parse_param2(char *fmt, char *buf, void **pval)
|
| 186 | {
|
| 187 | char *p;
|
| 188 | char *sepp;
|
| 189 | char *tmp;
|
| 190 | char sepc;
|
| 191 | char *pstr[AT_PARAM_MAX_NUM] = { 0 };
|
| 192 | int len, flag;
|
| 193 | int n = 0;
|
| 194 | int nparam = 0;
|
| 195 | if (buf == NULL) {
|
| 196 | printf("buf NULL\n");
|
| 197 | return -1;
|
| 198 | }
|
| 199 |
|
| 200 | len = strlen(buf) + 1;
|
| 201 | tmp = p = (char*)malloc(len);
|
| 202 | if (p == NULL) {
|
| 203 | //assert(0);
|
| 204 | printf("fail to malloc\n");
|
| 205 | return -1;
|
| 206 | }
|
| 207 | memset(p, 0, len);
|
| 208 | memcpy(p, buf, strlen(buf));
|
| 209 | /* remove \r or \n at th end */
|
| 210 | for(len--; len > 0; len--){
|
| 211 | if(p[len - 1] == '\r' || p[len - 1] == '\n'){
|
| 212 | p[len - 1] = '\0';
|
| 213 | } else {
|
| 214 | break;
|
| 215 | }
|
| 216 | }
|
| 217 | /* divise the at-string to some string param */
|
| 218 | do {
|
| 219 | flag = 0;
|
| 220 | if (*p == '"') {
|
| 221 | int i, j;
|
| 222 | for (i = j = 0, ++p; p[j] != '\0'; i++, j++) {
|
| 223 | if (p[j] == '"') {
|
| 224 | ++j;
|
| 225 | break;
|
| 226 | }
|
| 227 | }
|
| 228 |
|
| 229 | if (j == 1) flag = 1;
|
| 230 | p[j - 1] = '\0';
|
| 231 | sepp = p + j;
|
| 232 | } else {
|
| 233 | sepp = p + strcspn(p, ",");
|
| 234 | if (p == sepp) flag = 1;
|
| 235 | }
|
| 236 |
|
| 237 | nparam++;
|
| 238 | sepc = sepp[0];
|
| 239 | sepp[0] = '\0';
|
| 240 |
|
| 241 | if (flag == 1)
|
| 242 | pstr[n++] = NULL;
|
| 243 | else
|
| 244 | pstr[n++] = p;
|
| 245 | p = sepp + 1;
|
| 246 | } while ((n < AT_PARAM_MAX_NUM) && (sepc == ','));
|
| 247 |
|
| 248 | /* convert the string params to the types that fmt Appointed */
|
| 249 | int param_count = 0; /* count the param that being get */
|
| 250 | int param_str_index = 0; /* the index of string params */
|
| 251 | int param_val_index = 0; /* the index of param values */
|
| 252 | for (; fmt != NULL && param_str_index < nparam; param_str_index++) {
|
| 253 | char type;
|
| 254 | int size;
|
| 255 | char str_param_size[6] = { 0 };
|
| 256 | int param_size_index = 0;
|
| 257 |
|
| 258 | while(*fmt == ' ') fmt++;
|
| 259 | if(*fmt == ','){
|
| 260 | fmt++;
|
| 261 | continue; /* igmore the param that is without type */
|
| 262 | }
|
| 263 | if(*fmt++ != '%'){
|
| 264 | break;
|
| 265 | }
|
| 266 | for (; param_size_index < sizeof(str_param_size) - 1; fmt++, param_size_index++){
|
| 267 | if(!isdigit(*fmt)){
|
| 268 | break;
|
| 269 | }
|
| 270 | str_param_size[param_size_index] = *fmt;
|
| 271 | }
|
| 272 | type = *(fmt++);
|
| 273 | char *stop;
|
| 274 | errno = 0;
|
| 275 | size = (int)strtol(str_param_size, &stop, 10);
|
| 276 | if (errno == ERANGE)// kw ERRNO.NOT_CHECKED
|
| 277 | {
|
| 278 | printf("strtol errno %d: %s\n", errno, strerror(errno));
|
| 279 | }
|
| 280 | //size = atoi(str_param_size);
|
| 281 | if(size < 0)
|
| 282 | break;
|
| 283 | while(*fmt == ' ') fmt++; /* igmore the blanks */
|
| 284 | fmt = (*fmt == ',' ? fmt + 1 : NULL);
|
| 285 |
|
| 286 | if (type == 'd') {
|
| 287 | if(size == 0 || size == 4) {
|
| 288 | if(pstr[param_str_index] != NULL) {
|
| 289 | if(!is_digit_str(pstr[param_str_index])){
|
| 290 | break;
|
| 291 | }
|
| 292 | *((int *)pval[param_val_index]) = (int)atoi(pstr[param_str_index]);
|
| 293 | param_count++;
|
| 294 | }
|
| 295 | } else if(size == 1) {
|
| 296 | if(pstr[param_str_index] != NULL) {
|
| 297 | if(!is_digit_str(pstr[param_str_index])){
|
| 298 | break;
|
| 299 | }
|
| 300 | *((char *)pval[param_val_index]) = (char)atoi(pstr[param_str_index]);
|
| 301 | param_count++;
|
| 302 | }
|
| 303 | } else if(size == 2) {
|
| 304 | if(pstr[param_str_index] != NULL) {
|
| 305 | if(!is_digit_str(pstr[param_str_index])){
|
| 306 | break;
|
| 307 | }
|
| 308 | *((short *)pval[param_val_index]) = (short)atoi(pstr[param_str_index]);
|
| 309 | param_count++;
|
| 310 | }
|
| 311 | }else {
|
| 312 | break;
|
| 313 | }
|
| 314 | } else if (type == 's') {
|
| 315 | if (size == 0) {
|
| 316 | if(pstr[param_str_index] != NULL) {
|
| 317 | strcpy((char *)pval[param_val_index], pstr[param_str_index]);
|
| 318 | param_count++;
|
| 319 | }
|
| 320 | } else if (size < 0xffff) {//klocwork
|
| 321 | if(pstr[param_str_index] != NULL) {
|
| 322 | //strncpy((char *)pval[param_val_index], pstr[param_str_index], size - 1);
|
| 323 | snprintf((char *)pval[param_val_index],size,"%s",pstr[param_str_index]);
|
| 324 | param_count++;
|
| 325 | }
|
| 326 | } else {
|
| 327 | break;
|
| 328 | }
|
| 329 | } else {
|
| 330 | break;
|
| 331 | }
|
| 332 | param_val_index++;
|
| 333 | }
|
| 334 | free(tmp);
|
| 335 |
|
| 336 | return param_count;
|
| 337 | }
|
| 338 |
|
| 339 |
|
| 340 | static int is_print_str(const char *str){
|
| 341 | while(isprint(*str)){
|
| 342 | str++;
|
| 343 | }
|
| 344 | return *str == '\0';
|
| 345 | }
|
| 346 |
|
| 347 | static int get_fmt_param_count(const char *str){
|
| 348 | int fmt_param_count = 0;
|
| 349 |
|
| 350 | for(; *str != '\0'; str++){
|
| 351 | if(*str == ','){
|
| 352 | fmt_param_count++;
|
| 353 | }
|
| 354 | }
|
| 355 | return fmt_param_count + 1;
|
| 356 | }
|
| 357 |
|
| 358 | /*return 0±íʾ½âÎö²ÎÊýÕý³££¬ÄÚ²¿½øÐÐÑϸñµÄ²ÎÊý¼ì²é£¬°üÀ¨²ÎÊý¸öÊýÒ»ÖÂÐÔ¼ì²é£¬¶ÔÓÚ¿ÉÑ¡²ÎÊý£¬ÐèÒªµ÷ÓÃÕß×ÔÐп¼ÂÇ*/
|
| 359 | int parse_param_safe(char *fmt, char *buf, void **pval)
|
| 360 | {
|
| 361 | char *p;
|
| 362 | char *sepp;
|
| 363 | char *tmp;
|
| 364 | char sepc;
|
| 365 | char *pstr[AT_PARAM_MAX_NUM] = {0};
|
| 366 | int len, flag;
|
| 367 | int n = 0;
|
| 368 | int nparam = 0;//buf×Ö·û´®Êµ¼ÊµÄ²ÎÊý¸öÊý
|
| 369 | int fmt_param_num = 0;//fmt¸ñʽ»¯ÖÐÒªÇóµÄ²ÎÊý×ܸöÊý£¬Óë%¸öÊýÒ»ÖÂ
|
| 370 | int ret = AT_PARSE_OK;
|
| 371 | int mark_flag = 0;//ÓÃÓÚ±êÊ¶ÌØÊâ·ûºÅµÄÅä¶ÔÇé¿ö£¬Ä¿Ç°ÓÃÓÚË«ÒýºÅ
|
| 372 | if (buf == NULL) {
|
| 373 | return ATERR_PROC_FAILED;
|
| 374 | }
|
| 375 | while(*buf == ' ') buf++;
|
| 376 | len = strlen(buf) + 1;
|
| 377 | tmp = p = (char*)malloc(len);
|
| 378 | if (p == NULL) {
|
| 379 | return ATERR_NO_PRINT;
|
| 380 | }
|
| 381 | //fmt_param_num = find_char_num(fmt,"%");
|
| 382 | memset(p, 0, len);
|
| 383 | //ÉêÇëÐÂÄÚ´æ´æ·ÅÈë²ÎµÄATÃüÁÒÔ±ã½øÐÐÕûÐζ¨ÖÆ
|
| 384 | memcpy(p, buf, strlen(buf));
|
| 385 | /*È¥³ýβ²¿µÄ\r\n£¬Ä¿Ç°½öÔÚ7100ÉÏÓдËÎÊÌâ */
|
| 386 | for(len--; len > 0; len--){
|
| 387 | if(p[len - 1] == '\r' || p[len - 1] == '\n'){
|
| 388 | p[len - 1] = '\0';
|
| 389 | } else {
|
| 390 | break;
|
| 391 | }
|
| 392 | }
|
| 393 | if(!is_print_str(p)){/* ÈçATÃüÁîÖаüº¬²»¿É¼û×Ö·ûÖ±½Ó·µ»Ø´íÎó */
|
| 394 | free(tmp);
|
| 395 | return ATERR_NO_PRINT;
|
| 396 | }
|
| 397 | /*°´¶ººÅ½øÐÐÿ¸ö²ÎÊýµÄ·Ö¸îÕûÐÎ,Ë«ÒýºÅÀïµÄ¶ººÅÌø¹ý*/
|
| 398 | do {
|
| 399 | flag = 0;
|
| 400 | mark_flag = 0;
|
| 401 | if (*p == '"') {
|
| 402 | int i, j;
|
| 403 | for (i = j = 0, ++p; p[j] != '\0'; i++, j++) {
|
| 404 | if (p[j] == '"') {
|
| 405 | ++j;
|
| 406 | mark_flag = 1;
|
| 407 | break;
|
| 408 | }
|
| 409 | }
|
| 410 | if(mark_flag == 0){/* δƥÅ䵽˫ÒýºÅÖ±½Ó·µ»Ø´íÎó */
|
| 411 | free(tmp);
|
| 412 | return ATERR_DROP_MARK;
|
| 413 | }
|
| 414 | if (j == 1) flag = 1;
|
| 415 | p[j - 1] = '\0';
|
| 416 | sepp = p + j;
|
| 417 | } else {
|
| 418 | sepp = p + strcspn(p, ",");
|
| 419 | if (p == sepp) flag = 1;
|
| 420 | }
|
| 421 |
|
| 422 | nparam++;
|
| 423 | sepc = sepp[0];
|
| 424 | sepp[0] = '\0';
|
| 425 |
|
| 426 | if (flag == 1)
|
| 427 | pstr[n++] = NULL;
|
| 428 | else
|
| 429 | pstr[n++] = p;
|
| 430 | p = sepp + 1;
|
| 431 | } while ((n < AT_PARAM_MAX_NUM) && (sepc == ','));
|
| 432 |
|
| 433 | if(nparam < get_fmt_param_count(fmt)){
|
| 434 | ret = ATWARN_DROP_RN;
|
| 435 | }else if(nparam > get_fmt_param_count(fmt)){
|
| 436 | ret = ATWARN_LACK_PARAM;
|
| 437 | }
|
| 438 | /* convert the string params to the types that fmt Appointed */
|
| 439 | int param_count = 0; /*ÊäÈëµÄ×Ö·û´®ÖÐÓÐЧ²ÎÊý¸öÊý*/
|
| 440 | int param_str_index = 0; /* the index of string params */
|
| 441 | int param_val_index = 0; /* the index of param values */
|
| 442 | //°´ÕÕÈë²Î¸ñʽ½øÐÐÿ¸ö²ÎÊýÖµµÄ·µ»Ø¸³Öµ
|
| 443 | for (; fmt != NULL && param_str_index < nparam; param_str_index++) {
|
| 444 | char type;
|
| 445 | int size;
|
| 446 | char str_param_size[10] = { 0 };
|
| 447 | int param_size_index = 0;
|
| 448 |
|
| 449 | while(*fmt == ' ') fmt++;
|
| 450 | if(*fmt == ','){
|
| 451 | fmt++;
|
| 452 | continue; /* igmore the param that is without type */
|
| 453 | }
|
| 454 | if(*fmt++ != '%'){
|
| 455 | ret = ATERR_NO_PRINT;
|
| 456 | break;
|
| 457 | }
|
| 458 | for (; param_size_index < sizeof(str_param_size) - 1; fmt++, param_size_index++){
|
| 459 | if(!isdigit(*fmt)){
|
| 460 | break;
|
| 461 | }
|
| 462 | str_param_size[param_size_index] = *fmt;
|
| 463 | }
|
| 464 | type = *(fmt++);
|
| 465 | char *stop;
|
| 466 | errno = 0;
|
| 467 | size = (int)strtol(str_param_size, &stop, 10);
|
| 468 | if (errno == ERANGE)// kw ERRNO.NOT_CHECKED
|
| 469 | {
|
| 470 | printf("strtol errno %d: %s\n", errno, strerror(errno));
|
| 471 | }
|
| 472 | //size = atoi(str_param_size);
|
| 473 | if(size < 0){
|
| 474 | ret = ATERR_STR_TOO_LONG;
|
| 475 | break;
|
| 476 | }
|
| 477 | while(*fmt == ' ') fmt++; /* igmore the blanks */
|
| 478 | fmt = (*fmt == ',' ? fmt + 1 : NULL);
|
| 479 |
|
| 480 | if (type == 'd') {
|
| 481 | if(size == 0 || size == 4) {
|
| 482 | if(pstr[param_str_index] != NULL) {
|
| 483 | *((int *)pval[param_val_index]) = (int)atoi(pstr[param_str_index]);
|
| 484 | param_count++;
|
| 485 | }
|
| 486 | } else if(size == 1) {
|
| 487 | if(pstr[param_str_index] != NULL) {
|
| 488 | *((char *)pval[param_val_index]) = (char)atoi(pstr[param_str_index]);
|
| 489 | param_count++;
|
| 490 | }
|
| 491 | } else if(size == 2) {
|
| 492 | if(pstr[param_str_index] != NULL) {
|
| 493 | *((short *)pval[param_val_index]) = (short)atoi(pstr[param_str_index]);
|
| 494 | param_count++;
|
| 495 | }
|
| 496 | }else {
|
| 497 | assert(0);
|
| 498 | break;
|
| 499 | }
|
| 500 | } else if (type == 's') {
|
| 501 | if (size == 0) {
|
| 502 | if(pstr[param_str_index] != NULL) {
|
| 503 | strcpy((char *)pval[param_val_index], pstr[param_str_index]);
|
| 504 | param_count++;
|
| 505 | }
|
| 506 | } else {
|
| 507 | if(pstr[param_str_index] != NULL && size < strlen(pstr[param_str_index])){
|
| 508 | ret = ATERR_STR_TOO_LONG;
|
| 509 | break;
|
| 510 | }
|
| 511 | if(pstr[param_str_index] != NULL) {
|
| 512 | //strncpy((char *)pval[param_val_index], pstr[param_str_index], size - 1);
|
| 513 | if(size < 0xffff)//klocwork
|
| 514 | snprintf((char *)pval[param_val_index],size,"%s",pstr[param_str_index]);
|
| 515 | param_count++;
|
| 516 | }
|
| 517 | }
|
| 518 | } else {
|
| 519 | assert(0);
|
| 520 | break;
|
| 521 | }
|
| 522 | param_val_index++;
|
| 523 | }
|
| 524 | free(tmp);
|
| 525 | return ret;
|
| 526 | }
|
| 527 | /*return 0±íʾ½âÎö²ÎÊýÕý³££¬²»½øÐвÎÊý¸öÊýµÄÓÐЧÐÔ¼ì²é£¬¾ßÌå·µ»ØÖµ²Î¿´AT_PARSE_OKµÈºêÖµ*/
|
| 528 | int parse_param(char *fmt, char *buf, void **pval)
|
| 529 | {
|
| 530 | int ret = parse_param_safe(fmt,buf,pval);
|
| 531 | if(ret==ATWARN_LACK_PARAM||ret==ATWARN_DROP_RN)
|
| 532 | return AT_PARSE_OK;
|
| 533 | return ret;
|
| 534 | }
|
| 535 | /**
|
| 536 | * @brief ¿É´òÓ¡×Ö·û´®×ª»»Îª×Ö½ÚÊý¾Ý £¬È磺
|
| 537 | "C8329BFD0E01" --> {0xC8, 0x32, 0x9B, 0xFD, 0x0E, 0x01}
|
| 538 | * @param pSrc Ô´×Ö·û´®Ö¸Õë
|
| 539 | * @param pDst Ä¿±êÊý¾ÝÖ¸Õë
|
| 540 | * @param nSrcLength Ô´×Ö·û´®³¤¶È
|
| 541 | * @return Ä¿±êÊý¾Ý³¤¶È
|
| 542 | * @note
|
| 543 | * @warning
|
| 544 | */
|
| 545 | int string2bytes(const char* pSrc, unsigned char* pDst, int nSrcLength)
|
| 546 | {
|
| 547 | int i=0;
|
| 548 |
|
| 549 | //УÑé²ÎÊý
|
| 550 | if(pSrc == NULL || pDst == NULL || nSrcLength < 0)
|
| 551 | {
|
| 552 | return -1;
|
| 553 | }
|
| 554 |
|
| 555 | for(i = 0; i < nSrcLength; i += 2)
|
| 556 | {
|
| 557 | // Êä³ö¸ß4λ
|
| 558 | if(*pSrc >= '0' && *pSrc <= '9')
|
| 559 | {
|
| 560 | *pDst = (*pSrc - '0') << 4;
|
| 561 | }
|
| 562 | else
|
| 563 | {
|
| 564 | *pDst = ((toupper(*pSrc) - 'A') + 10) << 4;
|
| 565 | }
|
| 566 |
|
| 567 | pSrc++;
|
| 568 |
|
| 569 | // Êä³öµÍ4λ
|
| 570 | if(*pSrc >= '0' && *pSrc <= '9')
|
| 571 | {
|
| 572 | *pDst |= *pSrc - '0';
|
| 573 | }
|
| 574 | else
|
| 575 | {
|
| 576 | *pDst |= (toupper(*pSrc) - 'A') + 10;
|
| 577 | }
|
| 578 |
|
| 579 | pSrc++;
|
| 580 | pDst++;
|
| 581 | }
|
| 582 |
|
| 583 | // ·µ»ØÄ¿±êÊý¾Ý³¤¶È
|
| 584 | return nSrcLength / 2;
|
| 585 | }
|
| 586 |
|
| 587 | /**
|
| 588 | * @brief ×Ö½ÚÊý¾Ýת»»Îª¿É´òÓ¡×Ö·û´® £¬È磺
|
| 589 | {0xC8, 0x32, 0x9B, 0xFD, 0x0E, 0x01} --> "C8329BFD0E01"
|
| 590 | * @param pSrc Ô´Êý¾ÝÖ¸Õë
|
| 591 | * @param pDst Ä¿±ê×Ö·û´®Ö¸Õë
|
| 592 | * @param nSrcLength Ô´Êý¾Ý³¤¶È
|
| 593 | * @return Ä¿±êÊý¾Ý³¤¶È£»
|
| 594 | * @note
|
| 595 | * @warning
|
| 596 | */
|
| 597 | int bytes2string(const unsigned char* pSrc, char* pDst, int nSrcLength)
|
| 598 | {
|
| 599 | const char tab[]="0123456789ABCDEF"; // 0x0-0xfµÄ×Ö·û²éÕÒ±í
|
| 600 | int i = 0;
|
| 601 |
|
| 602 | //УÑé²ÎÊý
|
| 603 | if(pSrc == NULL || pDst == NULL || nSrcLength < 0)
|
| 604 | {
|
| 605 | return -1;
|
| 606 | }
|
| 607 |
|
| 608 | for(i=0; i<nSrcLength; i++)
|
| 609 | {
|
| 610 | *pDst++ = tab[*pSrc >> 4]; // Êä³öµÍ4λ
|
| 611 | *pDst++ = tab[*pSrc & 0x0f]; // Êä³ö¸ß4λ
|
| 612 | pSrc++;
|
| 613 | }
|
| 614 |
|
| 615 | // ·µ»ØÄ¿±ê×Ö·û´®³¤¶È
|
| 616 | return nSrcLength * 2;
|
| 617 | }
|
| 618 |
|
| 619 |
|
| 620 | /**************************************************************************
|
| 621 | * º¯ÊýÃû³Æ£º void zxic_err_track(int err)
|
| 622 | * ¹¦ÄÜÃèÊö£º ½«Ó¦ÓôíÎóºÅÌí¼Óµ½nvÖÐ
|
| 623 | * ÊäÈë²ÎÊý£º err: ´íÎóºÅ
|
| 624 | * ·µ »Ø Öµ£ºÄ¿±êÊý¾Ý³¤¶È£»
|
| 625 | **************************************************************************/
|
| 626 | void zxic_err_track(int err)
|
| 627 | {
|
| 628 | ERR_TRACK errTrack = {0};
|
| 629 | char nvErrTrack[2 * sizeof(ERR_TRACK)] = {0};
|
| 630 | char assert_errno[10] = {0};
|
| 631 | int recordLen = 0, curErrno = 0, prenum = 0, i = 0;
|
| 632 | struct timeval curTime = {0};
|
| 633 | unsigned long curErrTime = 0; //ºÁÃë
|
| 634 | int index;
|
| 635 |
|
| 636 | gettimeofday(&curTime, NULL);
|
| 637 | curErrTime = curTime.tv_sec * 1000 + curTime.tv_usec / 1000;
|
| 638 |
|
| 639 | curErrno = err;
|
| 640 | //at_print(AT_DEBUG,"[ERR]curErrno = %d\r\n", curErrno);
|
| 641 |
|
| 642 | //·¢ËÍÐèÒª¶ÏÑÔµÄerrno£¬Ö±½Ó¶ÏÑÔ
|
| 643 | sc_cfg_get("assert_errno", assert_errno, sizeof(assert_errno));
|
| 644 | if (curErrno == atoi(assert_errno)) {
|
| 645 | assert(0);
|
| 646 | }
|
| 647 |
|
| 648 | //´ÓNV¶ÁÈ¡´íÎó¿ìÕÕÐÅÏ¢
|
| 649 | recordLen = 2 * sizeof(ERR_TRACK);
|
| 650 | memset(nvErrTrack, 0x00, recordLen);
|
| 651 | sc_cfg_get("err_track", nvErrTrack, recordLen);
|
| 652 | string2bytes(nvErrTrack, (unsigned char*)&errTrack, strlen(nvErrTrack));
|
| 653 |
|
| 654 |
|
| 655 | //´òÓ¡¿ìÕÕÐÅÏ¢
|
| 656 | #if 0
|
| 657 | at_print(AT_DEBUG, "[ERR]num = %d\r\n", errTrack.num);
|
| 658 | for (i = 0; i < 5; i++) {
|
| 659 | at_print(AT_DEBUG, "[ERR]errTrack.errInfo[%d].errno = %d\r\n", i, errTrack.errInfo[i].err_no);
|
| 660 | at_print(AT_DEBUG, "[ERR]errTrack.errInfo[%d].errtime = %ld\r\n", i, errTrack.errInfo[i].err_time);
|
| 661 | }
|
| 662 | #endif
|
| 663 | index = errTrack.num % ERR_TRACK_MAX_NUM;
|
| 664 | //Ñ»·¼Ç¼´íÎóÐÅÏ¢
|
| 665 | if (index == 0 && errTrack.num != 0)
|
| 666 | prenum = ERR_TRACK_MAX_NUM - 1;
|
| 667 | else if (index == 0)
|
| 668 | prenum = 0;
|
| 669 | else
|
| 670 | prenum = index - 1;
|
| 671 |
|
| 672 | //Á½´ÎerrnoÏàͬ£¬½ö¸üÐÂʱ¼ä
|
| 673 | if (curErrno == errTrack.errInfo[prenum].err_no) {
|
| 674 | errTrack.errInfo[prenum].err_time = curErrTime;
|
| 675 | }
|
| 676 | //Á½´Îerrno²»Ïàͬ£¬¼Ç¼ÏÂеÄerrnoºÍerrtime
|
| 677 | else {
|
| 678 | errTrack.errInfo[index].err_no = curErrno;
|
| 679 | errTrack.errInfo[index].err_time = curErrTime;
|
| 680 | errTrack.num++;
|
| 681 | }
|
| 682 |
|
| 683 | //±£´æ´íÎó¿ìÕÕÐÅÏ¢µ½NV
|
| 684 |
|
| 685 | memset(nvErrTrack, 0x00, recordLen);
|
| 686 | bytes2string((unsigned char*)&errTrack, nvErrTrack, sizeof(ERR_TRACK));
|
| 687 | sc_cfg_set("err_track", nvErrTrack);
|
| 688 |
|
| 689 | }
|
| 690 |
|
| 691 |
|
| 692 | void get_at_req_prefix(char *at_str, char** at_prefix)
|
| 693 | {
|
| 694 | char *prefix = NULL;
|
| 695 | char *pszAtHead = NULL;
|
| 696 | char *ptemstr = NULL;
|
| 697 |
|
| 698 | if((*at_str == 'A'||*at_str == 'a')&&(*(at_str+1) == 'T'||*(at_str+1) == 't'))
|
| 699 | {
|
| 700 | if(isalpha(*(at_str+2)))
|
| 701 | {
|
| 702 | *at_prefix = NULL;
|
| 703 | }
|
| 704 | else
|
| 705 | {
|
| 706 | prefix = (char*)malloc(50);
|
| 707 | if(prefix == NULL) {
|
| 708 | softap_assert("malloc fail!");
|
| 709 | return;
|
| 710 | }
|
| 711 | memset(prefix, 0x00, 50);
|
| 712 |
|
| 713 | pszAtHead = at_str;
|
| 714 | //ÕÒµ½Ê׸ö·Ç×Öĸ»òÕßÊý×ֵIJÎÊý£¬ÀýÈç+
|
| 715 | for(; *at_str != '\0'; at_str++)
|
| 716 | {
|
| 717 | if(!(isalnum(*at_str) || *at_str == '\r' || *at_str == '\n'))
|
| 718 | {
|
| 719 | pszAtHead = at_str;
|
| 720 | pszAtHead++;
|
| 721 | break;
|
| 722 | }
|
| 723 | }
|
| 724 |
|
| 725 | for(ptemstr = pszAtHead; *ptemstr != '\0'; ptemstr++)
|
| 726 | {
|
| 727 | if(*ptemstr == '=' || *ptemstr == '?' || *ptemstr == '\r')
|
| 728 | {
|
| 729 | memcpy(prefix, pszAtHead, ptemstr-pszAtHead);
|
| 730 | *at_prefix = prefix;
|
| 731 | return;
|
| 732 | }
|
| 733 | }
|
| 734 | }
|
| 735 | }
|
| 736 | else
|
| 737 | {
|
| 738 | softap_assert("req_at cmd is invalid!");
|
| 739 | }
|
| 740 | if(prefix)
|
| 741 | free(prefix);
|
| 742 | }
|
| 743 |
|
| 744 |
|
| 745 | //¸øat_client·¢ËÍÇëÇóÏûÏ¢£¬Ð¯´øatÃüÁî×Ö·û´®ºÍ³¬Ê±Ê±³¤
|
| 746 | void send_app_req(int module_id, char *req_at, int len, int timeout,int direct)
|
| 747 | {
|
| 748 | struct app_send_req_at appreq;
|
| 749 |
|
| 750 | memset(&appreq, 0x00, sizeof(struct app_send_req_at));
|
| 751 | memcpy(appreq.atstr, req_at, len);
|
| 752 | appreq.str_len = len;
|
| 753 | appreq.timeout = timeout;
|
| 754 | if(direct == NEAR_PS)
|
| 755 | ipc_send_message(module_id, MODULE_ID_AT_CTL, MSG_CMD_SEND_AT_TO_PS,sizeof(struct app_send_req_at), &appreq, 0);
|
| 756 | else
|
| 757 | ipc_send_message(module_id, MODULE_ID_AT_CTL, MSG_CMD_SEND_REQAT_TO_FARPS,sizeof(struct app_send_req_at), &appreq, 0);
|
| 758 |
|
| 759 | printf("send_app_req\n");
|
| 760 |
|
| 761 | }
|
| 762 |
|
| 763 |
|
| 764 | /**
|
| 765 | * @brief Ó¦Ó÷¢ËͶ¯×÷ÀàATÇëÇ󣬲¢×èÈûµÈ´ý¶¯×÷½á¹û£»×¢Ò⣺¸Ã½Ó¿ÚÖ»ÄÜÓÃÓÚ²éѯºÍÉèÖúÍÖ´ÐÐÇëÇó£¬Í¨¹ýÈë²Î½øÐÐÖмä½á¹ûµÄÄÚ²¿½âÎö´¦Àí£¬²¢ÇÒ
|
| 766 | ÓÐÖмä½á¹ûÉϱ¨Ê±£¬Ö»Ö§³ÖÒ»ÌõÖмä½á¹ûµÄÉϱ¨½âÎö£»
|
| 767 | * @param req_at ÇëÇóATÃüÁî
|
| 768 | * @param info_fmt ATÏìÓ¦µÄ¸ñʽ»¯·½Ê½
|
| 769 | * @param pval ¸ñʽ»¯ºóµÄATÏìÓ¦
|
| 770 | * @param safe_parm_check ָʾÊÇ·ñ¶Ô²ÎÊý¸öÊý½øÐÐÒ»ÖÂÐÔ¼ì²é£¬0±íʾº¬¿ÉÑ¡²ÎÊý£¬²»¶Ô²ÎÊý¸öÊý½øÐмì²é;1±íʾ¶Ô²ÎÊý¸öÊý½øÐÐÑϸñ¼ì²é
|
| 771 | * @return 0±íʾ·µ»Ø³É¹¦£¬ÆäËûÖµ±íʾʧ°Ü´íÎóÂë
|
| 772 | * @note 1. Óû§Ê¹ÓÃʱ£¬Èô²»ÏëÓɸýӿÚÄÚ²¿½øÐвÎÊýµÄ¸ñʽ»¯½âÎö£¬¿ÉÒÔ½«info_fmt¸³ÖµÎª"%s"£¬pval¸³ÖµÎªchar **p˫ָÕ룬ÕâÑù²ÎÊý½«×÷ΪÕûÌå×Ö·û´®·µ»Ø¸øµ÷ÓÃÕß
|
| 773 | 2. ¶ÔÓÚZMGL,CPBR, COPS=?µÈÒ»ÌõÇëÇó»áÓжàÌõÖмä½á¹ûÇé¿ö£¬»¹ÐèʹÓÃregister_inform_func×¢²áÖмä½á¹ûµÄ´¦Àíº¯Êý
|
| 774 | * @warning
|
| 775 | */
|
| 776 | int send_req_and_wait(char *req_at,int len,char *info_fmt,void **pval, int safe_parm_check,int timeout,int direct)
|
| 777 | {
|
| 778 | int my_handle = 0;
|
| 779 | char *prefix = NULL;
|
| 780 | MSG_BUF rsp_msg = {0};
|
| 781 | LONG msgSize = sizeof(MSG_BUF)-sizeof(LONG);
|
| 782 | int iRet = 0;
|
| 783 | int module_id = MODULE_ID_ATDYNAMIC_BASE;//ÄÚ²¿¶¯Ì¬»ñȡԴģ¿éID£¬³õʼֵΪMODULE_ID_ATDYNAMIC_BASE
|
| 784 | int err = 0;
|
| 785 | int at_send_cnt = 0;
|
| 786 |
|
| 787 |
|
| 788 | if(len >= MSG_DATA_MAX_LEN-12)
|
| 789 | softap_assert("send_req_and_wait req at is too long!!!!!");
|
| 790 | assert((info_fmt==NULL&&pval==NULL)||(info_fmt!=NULL&&pval!=NULL));
|
| 791 | //¶¯Ì¬´´½¨ÁÙʱµÄÏûÏ¢¶ÓÁйܵÀ
|
| 792 | //msggetʹÓòÎÊýIPC_CREAT | IPC_EXCL| 0600£¬Åжϵ±Ç°module_idµÄÏûÏ¢¶ÓÁÐÊÇ·ñ
|
| 793 | //´æÔÚ£¬Èç¹û²»´æÔÚ£¬Ö±½Ó´´½¨ÐµÄÏûÏ¢¶ÓÁУ»Èç¹û´æÔÚ£¬·µ»ØÖµÎ´-1£¬È»ºómodule_id
|
| 794 | //Öµ¼Ó1£¬²»¶ÏÑ»·Ö±µ½ÕÒµ½Ã»ÓÐʹÓõÄmodule_idÖµ
|
| 795 | while((my_handle = msgget(module_id,IPC_CREAT | IPC_EXCL| 0600)) == -1)
|
| 796 | {
|
| 797 | module_id++;
|
| 798 | if (module_id > MODULE_ID_ATDYNAMIC_END)
|
| 799 | //µ±module_id´óÓÚMODULE_ID_ATDYNAMIC_ENDֵʱ£¬Ö÷¶¯¶ÏÑÔ
|
| 800 | softap_assert("at dynamic msg pipi not free timely!!!!!!!!!!!");
|
| 801 | }
|
| 802 | //¸ù¾ÝÇëÇóATÃüÁîºÍ²éѯÓï·¨£¬ÕÒµ½¶ÔÓ¦µÄ²éѯǰ׺£¬¶¯Ì¬¸³Öµ¸ø³ö²Î£¬Íⲿ½øÐÐÄÚ´æµÄÊÍ·Å
|
| 803 | get_at_req_prefix(req_at,&prefix);
|
| 804 | RESEND:
|
| 805 | //¸øat_ctl·¢ËÍÏûÏ¢£¬·¢Ë͵ÄÏûÏ¢ÄÚÈÝÊÇatÃüÁî×Ö·û´®
|
| 806 | at_send_cnt++;
|
| 807 | assert(at_send_cnt<=3);
|
| 808 | //ÓÉatctlÖ÷¿ØÄÚ²¿ÉèÖó¬Ê±µÈ´ý£¬ÖØ·¢ºó»áÓÉÖØ¹¹ÖØÉè¸Ã¶¨Ê±Æ÷
|
| 809 | send_app_req(module_id,req_at,len,timeout,direct);
|
| 810 | slog(NET_PRINT, SLOG_ERR, "prefix:%s\n",prefix);
|
| 811 | while(1)
|
| 812 | {
|
| 813 | iRet = 0;
|
| 814 | memset(&rsp_msg, 0x00, sizeof(MSG_BUF));
|
| 815 | iRet = msgrcv(my_handle, &rsp_msg, msgSize, 0, 0);
|
| 816 | if (iRet < 0)
|
| 817 | {
|
| 818 | continue;
|
| 819 | }
|
| 820 | //ËÀµÈÓ¦´ðÏûÏ¢
|
| 821 | if(rsp_msg.usMsgCmd == MSG_CMD_SEND_AT_MSG_RSP)//Æ¥Åäµ½ÊÇMSG_CMD_SEND_AT_MSG_RSPʱ²Å´¦Àí
|
| 822 | {
|
| 823 | char *buf = rsp_msg.aucDataBuf;
|
| 824 | char *at_paras = NULL;
|
| 825 | char *rsp_head = NULL;
|
| 826 | char *rsp_tail = NULL;
|
| 827 | rsp_head = buf;
|
| 828 | slog(NET_PRINT, SLOG_ERR, "recv MSG_CMD_SEND_AT_MSG_RSP, buf:%s\n",buf);
|
| 829 | //¶ÔÓÚ²éѯÇëÇ󣬲¢ÌṩÁ˲ÎÊýÄÚ´æ¿Õ¼ä£¬Ôò½øÐвÎÊýµÄ½âÎö
|
| 830 | if(prefix!=NULL && info_fmt!=NULL && pval!=NULL && ((rsp_head=at_strstr(buf,prefix))!=NULL))
|
| 831 | {
|
| 832 | //Ìø¹ýÖмä½á¹ûµÄÍ·²¿£¬ÕÒµ½²ÎÊýµÄÊ×µØÖ·
|
| 833 | rsp_head = rsp_head+strlen(prefix)+2;
|
| 834 | if((rsp_tail = strstr(rsp_head,"\r\n")) == NULL)//µ±Éϱ¨µÄÖмä½á¹ûÖÐûÓÐ\r\nʱ£¬ËµÃ÷½á¹ûÓÐÎÊÌ⣬ֱ½Ó¶ÏÑÔ
|
| 835 | softap_assert("rsp result is wrong and please contact with yangyun!");
|
| 836 |
|
| 837 | if(strcmp(info_fmt,"%s") == 0)
|
| 838 | //Èç¹û²»ÏëÓÉÄÚ²¿½øÐвÎÊýµÄ¸ñʽ»¯½âÎöʱ£¬Ö±½Ó½«È«²¿²ÎÊýÄÚÈÝÈ¡³öÀ´¸³Öµµ½pval[0]ÖУ¬²»×öÈκνâÎö
|
| 839 | //strncpy((char *)*pval, rsp_head, (int)(rsp_tail-rsp_head));
|
| 840 | //·ÀÖ¹Èë²Î·ÇÈ«0£¬ÔÚĩβ¼Ó×Ö·û´®½áÊø·û
|
| 841 | snprintf((char *)*pval, (rsp_tail-rsp_head)+1, "%s", rsp_head);
|
| 842 | else//ÐèÒª²ÎÊý½âÎöʱ£¬½«Öмä½á¹û´ÓÉϱ¨½á¹ûÖгé³öÀ´£¨Éϱ¨µÄ½á¹ûÖпÉÄÜÓÐOK´æÔÚ£©
|
| 843 | {
|
| 844 | char *at_paras = malloc(strlen(rsp_head)+1);
|
| 845 | if(at_paras == NULL) {
|
| 846 | softap_assert("malloc fail!");
|
| 847 | break;
|
| 848 | }
|
| 849 | memset(at_paras, 0, strlen(rsp_head)+1);
|
| 850 | memcpy(at_paras, rsp_head, (int)(rsp_tail-rsp_head));
|
| 851 |
|
| 852 | if(safe_parm_check)
|
| 853 | err = parse_param_safe(info_fmt, at_paras, pval);//°´ÕÕ¸ñʽ½âÎö²ÎÊý
|
| 854 | else
|
| 855 | err = parse_param(info_fmt, at_paras, pval);//°´ÕÕ¸ñʽ½âÎö²ÎÊý
|
| 856 | slog(NET_PRINT, SLOG_ERR, "rsp parse_param_safe return ERR=%d!!!!!!\n",err);
|
| 857 |
|
| 858 | //if(at_paras != NULL)
|
| 859 | free(at_paras);
|
| 860 | //²ÎÊý²»ºÏ·¨£¬ÇÒÊÇÓëÍⲿMCU½øÐн»»¥Ê±£¬Á¢¼´ÖØÐ·¢ËÍÇëÇó
|
| 861 | if(direct==FAR_PS && err != AT_PARSE_OK)
|
| 862 | goto RESEND;
|
| 863 | //²ÎÊý²»ºÏ·¨£¬ZXICÄÚ²¿½»»¥Ê±£¬Á¢¼´·µ»Ø²ÎÊý´íÎóÂë
|
| 864 | else if(err != AT_PARSE_OK)
|
| 865 | break;
|
| 866 | }
|
| 867 | }
|
| 868 | //¶ÔÓÚ²éѯÀ࣬²»Ó¦¸Ã·µ»Ø´íÎó£¬ÕÒÐÒéÕ»
|
| 869 | if((rsp_head = strstr(buf,"ERROR")) != NULL)
|
| 870 | {
|
| 871 | err = USER_EXTAND_ERR_BASE;
|
| 872 | sscanf(rsp_head+strlen("ERROR")+2, "%d", &err);
|
| 873 | slog(NET_PRINT, SLOG_ERR, "server return ERR=%d, at_send_cnt=%d!!!!!!!\n",err,at_send_cnt);
|
| 874 | //ÎÞÐè³¬Ê±ÖØ·¢»òÕß·µ»ØµÄ´íÎóÂëΪÓû§À©Õ¹´íÎ󣬲»½øÐÐÖØ·¢
|
| 875 | if(direct==FAR_PS&&err<9000)
|
| 876 | goto RESEND;
|
| 877 |
|
| 878 | char needInit[20] = {0};
|
| 879 | //¶ÔÓÚͨ¹ý7100ÉÏÍøÄ£Ê½£¬×öÌØÊâ¶¨ÖÆ£¬»Ø¸´errorºó±ØÐëÖØ´«
|
| 880 | sc_cfg_get("customer_type",needInit,sizeof(needInit));
|
| 881 | if(0 == strcmp(needInit, "7100modem") && err<9000)
|
| 882 | goto RESEND;
|
| 883 |
|
| 884 | break;
|
| 885 | }
|
| 886 | //¶ÔÓÚÉèÖÃÀàÃüÁîºÍһЩִÐÐÀàÃüÁֻÓÐOKÉϱ¨Ã»ÓÐÖмä½á¹ûÉϱ¨
|
| 887 | else if((rsp_head = strstr(buf,"OK")) != NULL)
|
| 888 | {
|
| 889 | break;
|
| 890 | }
|
| 891 | }
|
| 892 | }
|
| 893 | if(prefix!=NULL)
|
| 894 | free(prefix);
|
| 895 | //²éѯÃüÁî½á¹û·µ»Øºó£¬Ïú»Ù֮ǰ´´½¨µÄÏûÏ¢¶ÓÁÐ
|
| 896 | if(msgctl(my_handle,IPC_RMID,0) < 0)
|
| 897 | slog(NET_PRINT, SLOG_ERR, "%d:%s",errno,strerror(errno));
|
| 898 | return err;
|
| 899 | }
|
| 900 | int get_modem_info(char *req_at,char *info_fmt,void **pval)
|
| 901 | {
|
| 902 | return send_req_and_wait(req_at,strlen(req_at),info_fmt,pval,0,0,NEAR_PS);
|
| 903 | }
|
| 904 | int get_modem_info2(char *req_at,char *info_fmt,void **pval, int safe_parm_check, int timeout)
|
| 905 | {
|
| 906 | return send_req_and_wait(req_at,strlen(req_at),info_fmt,pval,safe_parm_check,timeout,NEAR_PS);
|
| 907 | }
|
| 908 | int send_reqat_to_farps(char *req_at,int len,char *info_fmt,void **pval, int safe_parm_check, int timeout)
|
| 909 | {
|
| 910 | return send_req_and_wait(req_at,len,info_fmt,pval,safe_parm_check,timeout,FAR_PS);
|
| 911 | }
|
| 912 |
|
| 913 | /*ÔÚºöÂÔ´óСдµÄǰÌáÏÂ,±È½ÏÁ½×Ö·û´®ÊÇ·ñÍêȫƥÅ䣬Èç¹ûÆ¥Åä·µ»Ø0£¬Èç¹ûµÚÒ»¸öÈë²Î´óÓÚµÚ¶þ¸öÈë²Î£¬
|
| 914 | ·µ»ØÕýÖµ£¬·ñÔò·µ»Ø¸ºÖµ£»
|
| 915 | ¿ÉÓÃÓڱȽÏATÃüÁîǰ׺ÊÇ·ñÆ¥Å䣬ÀýÈçat+cops?ºÍAT+COPS?µÄ±È½Ï*/
|
| 916 | int at_strcmp(const char *dest, const char *source)
|
| 917 | {
|
| 918 | //int DIFF_VALUE = 'a'-'A';
|
| 919 | int ch1 = 0;
|
| 920 | int ch2 = 0;
|
| 921 |
|
| 922 | if(NULL == dest || NULL == source)
|
| 923 | {
|
| 924 | return -1;
|
| 925 | }
|
| 926 |
|
| 927 | //½«Á½×Ö·û´®ÖеĴóС×ÖĸÏÈת»¯³É¶ÔÓ¦µÄСд×Öĸºó±È½Ï
|
| 928 | do
|
| 929 | {
|
| 930 | if((ch1 = *(unsigned char *)dest) >= 'A' && (ch1 <= 'Z'))
|
| 931 | {
|
| 932 | ch1 += DIFF_VALUE;
|
| 933 | }
|
| 934 | if((ch2 = *(unsigned char *)source) >= 'A' && (ch2 <= 'Z'))
|
| 935 | {
|
| 936 | ch2 += DIFF_VALUE;
|
| 937 | }
|
| 938 | dest++;
|
| 939 | source++;
|
| 940 | }while((ch1 == ch2) && ch1 && ch2);
|
| 941 |
|
| 942 | if(ch1 == ch2)
|
| 943 | return 0;
|
| 944 | else
|
| 945 | return *(--dest) - *(--source);
|
| 946 | }
|
| 947 |
|
| 948 | /*ÔÚºöÂÔ´óСдµÄǰÌáÏÂ,±È½ÏÁ½×Ö·û´®Ç°size×Ö·ûÊÇ·ñÆ¥Å䣬Èç¹ûÆ¥Åä·µ»Ø0£¬
|
| 949 | Èç¹ûµÚÒ»¸öÈë²Î´óÓÚµÚ¶þ¸öÈë²Î£¬·µ»ØÕýÖµ£¬·ñÔò·µ»Ø¸ºÖµ£»
|
| 950 | ¿ÉÓÃÓڱȽÏATÃüÁîÇëÇóǰ׺ºÍÆäÖмä½á¹ûµÄǰ׺ÊÇ·ñÆ¥Å䣬ÀýÈçcops?ºÍCOPSÔÚǰ4¸ö×Ö·ûµÄ±È½Ï*/
|
| 951 | int at_strncmp(const char *dest, const char *source, int size)
|
| 952 | {
|
| 953 | //int DIFF_VALUE = 'a'-'A';
|
| 954 | int ch1 = 0;
|
| 955 | int ch2 = 0;
|
| 956 |
|
| 957 | if(NULL == dest || NULL == source || size < 0)
|
| 958 | {
|
| 959 | return -1;
|
| 960 | }
|
| 961 | if(0 == size)
|
| 962 | {
|
| 963 | return 0;
|
| 964 | }
|
| 965 | //½«Á½×Ö·û´®ÖеĴóС×ÖĸÏÈת»¯³É¶ÔÓ¦µÄСд×Öĸºó±È½Ïǰsize×Ö·û
|
| 966 | do
|
| 967 | {
|
| 968 | if((ch1 = *(unsigned char *)dest) >= 'A' && (ch1 <= 'Z'))
|
| 969 | {
|
| 970 | ch1 += DIFF_VALUE;
|
| 971 | }
|
| 972 | if((ch2 = *(unsigned char *)source) >= 'A' && (ch2 <= 'Z'))
|
| 973 | {
|
| 974 | ch2 += DIFF_VALUE;
|
| 975 | }
|
| 976 | dest++;
|
| 977 | source++;
|
| 978 | }while(--size && (ch1 == ch2) && ch1 && ch2);
|
| 979 |
|
| 980 | if(ch1 == ch2)
|
| 981 | return 0;
|
| 982 | else
|
| 983 | return *(--dest) - *(--source);
|
| 984 |
|
| 985 | }
|
| 986 |
|
| 987 | /*ÔÚºöÂÔ´óСдµÄǰÌáÏÂ, ÔÚsourceÖÐѰÕÒsubstr×Ó´®£¬Èç¹ûÕÒµ½£¬Ö±½Ó·µ»ØÔÚsourceÖеÚÒ»´Î³öÏÖµÄλÖã¬
|
| 988 | Èç¹ûûÓÐÕÒµ½£¬·µ»ØNULL*/
|
| 989 | char * at_strstr(const char * source, const char * substr)
|
| 990 | {
|
| 991 | //int DIFF_VALUE = 'a'-'A';
|
| 992 | int ch1 = 0;
|
| 993 | int ch2 = 0;
|
| 994 |
|
| 995 | if(substr == NULL || source == NULL)
|
| 996 | return NULL;
|
| 997 | //½«Á½×Ö·û´®ÖеĴóС×ÖĸÏÈת»¯³É¶ÔÓ¦µÄСд×ÖĸºóÔÙ²éÕÒ
|
| 998 | while(*source != '\0')
|
| 999 | {
|
| 1000 | char *p = (char *)source;
|
| 1001 | char *q = (char *)substr;
|
| 1002 | char *res = NULL;
|
| 1003 |
|
| 1004 | res = p;
|
| 1005 | do
|
| 1006 | {
|
| 1007 | if((ch1 = *(unsigned char *)p) >= 'A' && (ch1 <= 'Z'))
|
| 1008 | {
|
| 1009 | ch1 += DIFF_VALUE;
|
| 1010 | }
|
| 1011 | if((ch2 = *(unsigned char *)q) >= 'A' && (ch2 <= 'Z'))
|
| 1012 | {
|
| 1013 | ch2 += DIFF_VALUE;
|
| 1014 | }
|
| 1015 | p++;
|
| 1016 | q++;
|
| 1017 | }while(ch1 && ch2 && (ch1 == ch2));
|
| 1018 |
|
| 1019 | if(ch2 == '\0')
|
| 1020 | return res;
|
| 1021 | source++;
|
| 1022 | }
|
| 1023 | return NULL;
|
| 1024 | }
|
| 1025 |
|
| 1026 | //·þÎñ¶ËÓ¦ÓóÌÐò£¬·¢ËÍÖмä½á¹ûºÍÏìÓ¦µ½ÍⲿMCU
|
| 1027 | int send_rsp_str_to_farps(int module_id, char *rsp_cmd,int rsp_len)
|
| 1028 | {
|
| 1029 | return ipc_send_message(module_id, MODULE_ID_AT_CTL, MSG_CMD_SEND_RSP_TO_OUTSIDE, rsp_len, rsp_cmd, 0);
|
| 1030 | }
|
| 1031 |
|
| 1032 |
|
| 1033 | unsigned short get_chksum(const unsigned char *ptr, unsigned short len)
|
| 1034 | {
|
| 1035 | unsigned int sum = 0;
|
| 1036 | unsigned int tmp;
|
| 1037 | const unsigned char *end;
|
| 1038 |
|
| 1039 | end = ptr + len - 1;
|
| 1040 |
|
| 1041 | while (ptr < end) {
|
| 1042 | tmp = (ptr[0] << 8) + ptr[1];
|
| 1043 | sum += tmp;
|
| 1044 | if (sum < tmp) {
|
| 1045 | sum++;
|
| 1046 | }
|
| 1047 | ptr += 2;
|
| 1048 | }
|
| 1049 |
|
| 1050 | if (ptr == end) {
|
| 1051 | tmp = ptr[0] << 8;
|
| 1052 | sum += tmp;
|
| 1053 | if (sum < tmp) {
|
| 1054 | sum++;
|
| 1055 | }
|
| 1056 | }
|
| 1057 |
|
| 1058 | return sum;
|
| 1059 | }
|
| 1060 |
|