求指导,CDMA PDU发送短信出错
打印信息:
[98, send_at_cmd] send: AT
[151, send_at_cmd] recv:
AT
OK
[98, send_at_cmd] send: ATE0
[151, send_at_cmd] recv:
ATE0
OK
[98, send_at_cmd] send: AT+CMGF=0
[151, send_at_cmd] recv:
OK
[98, send_at_cmd] send: AT+CPMS="SM","SM","SM"
[151, send_at_cmd] recv:
+CPMS:2,40,2,40,2,40
OK
[98, send_at_cmd] send: AT+CNMI=1,1,0,1,0
[151, send_at_cmd] recv:
OK
[98, send_at_cmd] send: AT^HSMSSS=0,0,1,0
[151, send_at_cmd] recv:
OK
[98, send_at_cmd] send: AT^HCMGS=19
[151, send_at_cmd] recv:
>
[98, send_at_cmd] send: 0011000D91688123310268f0000801044F60597D001A
[151, send_at_cmd] recv:(这里recv返回值为0)
代码实现部分:
if (0 != send_at_cmd(fd, (char*)"AT^HCMGS=19\r", (char *) ">", NULL)) {
debug(_dbg_err_, "send_at_command\n");
goto EXIT;
}
if (0 != send_at_cmd(fd, (char *)"0011000D91688123310268f0000801044F60597D001A", "OK", NULL)) {
debug(_dbg_err_, "send_at_command\n");
goto EXIT;
}
send_at_cmd()函数如下:
int send_at_cmd(int fd, char *cmd, char* expect, char* actual)
{
int n = 0;
int ret = 0;
char *send_buf = NULL;
char *recv_buf = NULL;
char *tmp = NULL;
int byte_recevied = 0;
char get_message[AT_RECV_BUFFER_SIZE] = {0};
char *str = NULL;
int flag = 1;
send_buf = (char *)malloc(strlen(cmd) + 2);
memset(send_buf, 0, strlen(cmd));
sprintf(send_buf, "%s", cmd);
recv_buf = (char *)malloc(AT_RECV_BUFFER_SIZE);
memset(recv_buf, 0, AT_RECV_BUFFER_SIZE);
n = write(fd, send_buf, strlen(send_buf));
debug(_dbg_always_, "send: %s\n", cmd);
if (n != (int) strlen(send_buf)) {
debug(_dbg_err_, "send len:%d\n", n);
perror("send");
goto EXIT;
}
usleep(50000);
n = read(fd, recv_buf, AT_RECV_BUFFER_SIZE);
if (n < 0) {
debug(_dbg_err_, "read recv_buf\n");
perror("read");
goto EXIT;
}
printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!n=%d\n\n",n);
fflush(stdout);
debug(_dbg_always_, "recv:\n %s\n", recv_buf);
fflush(stdout);
ret = check_exit_code(recv_buf);
if (0 != ret) {
debug(_dbg_err_, "error\n");
goto EXIT;
}
if (NULL != expect) {
tmp = strstr(recv_buf, expect);
if (NULL == tmp) {
debug(_dbg_err_, "error\n");
goto EXIT;
}
if ( NULL != actual) {
memcpy(actual, tmp, strlen(tmp));
}
} else {
if ( NULL != actual) {
memcpy(actual, recv_buf, strlen(recv_buf));
}
}
free(send_buf);
free(recv_buf);
return 0;
EXIT:
free(send_buf);
free(recv_buf);
return -1;
}
PDU编码部分001100 0D 91 688123310268f0 000801044F60597D 001A这里用字符串格式,ctrl+Z发送001A