AT命令用法

/*
* Caution: here we execute UART command to retrieve the barcode number from modem. And notice that we rely on the fact that there are double quotations(i.e.") in
* the bar-code returned by UART command.
* If the format of the bar-code number changes, the following code will probably NOT do what it is supposed to do:(
*/
int getBarcode(int fd,char *result)
{
const int BUF_SIZE = 128;
char buf[BUF_SIZE];
const int HALT_TIME = 100 * 1000;

strcpy(buf, "AT+EGMR=0,5\r\n");
send_at(fd, buf);
memset(buf,'\0',BUF_SIZE);
read_ack(fd,buf,BUF_SIZE);
LOGD("buf %s",buf);
char *p = NULL;
//const char *tok = "+EGMR: ";
//p = strstr(buf, tok);
p = strchr(buf, '\"'); // find the first double quotation mark.
if(p) {
strcpy(result, ++p);
} else {
strcpy(result, "unknow\n");
}
LOGE("getBarcode result = %s\n", result);
return 0;
}




    reslt = getBarcode(fd,barcode);
    ptr = strchr(barcode, '\"');
    if (ptr != NULL) {
        *ptr = 0;
    }


fd= openDevice();
if(-1 == fd) {
  LOGD(TAG "Fail to open CCCI interface\n");
return 0;
    }
for (i = 0; i<30; i++) usleep(50000); //sleep 1s wait for modem bootup
send_at (fd, "AT\r\n");
wait4_ack (fd, NULL, 3000);


int openDevice(void)
{
    int fd;
  
    fd = open("/dev/ttyC0", O_RDWR | O_NONBLOCK);
    if(fd < 0) {
        LOGD(TAG "Fail to open ttyC0: %s\n", strerror(errno));
        return -1;
    }
    // +EIND will always feedback +EIND when open device,
    // so move this to openDevice.
    // +EIND
    //wait4_ack (fd, "+EIND", 3000);
    return fd;
}

你可能感兴趣的:(AT命令用法)