|
楼主
根据gsm0705规范,发送短信息的命令是AT+CMGS=<length><CR>pdu<CTRL-Z>;
用c实现如下:
.
.
.
char at_command_d[128];
char pdu_buff[1024];
memset(pdu_buff,0,sizeof(pdu_buff));
memset(at_command_d,o,sizeof(at_command_d));
create_smssubmit_pdu(pdu_buff);
at_command(at_command_d,"+CMGS");
add_at_command(at_command_d,"=%d\13",(strlen(pdu_buff)/2-1));
write_mytty(at_command_d);/*向终端写入命令 AT+CMGS=<Length><CR> (CR的IRA为13)*/
printf("waiting for data request.\n");
read_mytty(at_command_d,ack_buff);
if(!strncmp(ack_buff,">",1)){
printf("sending the pdu data...\n");
if(write(mytty,pdu_buff,strlen(pdu_buff))!=strlen(pdu_buff)||write(mytty,"\26",1)!=1){
printf("error on sending data.\n");
exit(1);
}/*向终端写入pdu<ctrl+z> (ctrl+z 的IRA 为26)*/
read_mytty(at_command_d,ack_buff);
printf("the respone is :%s\n",ack_buff);
}
.
.
.
void create_smssubmit_pdu(char *pdu)
{
char number[]="683175428705F3";
char buff[]="E8329BFD4697D9EC37";/*hellohello 的gsm编码*/
memset(pdu,0,sizeof(pdu));
sprintf(&pdu[strlen(pdu)],"%02X",0);
sprintf(&pdu[strlen(pdu)],"%02X",17);
sprintf(&pdu[strlen(pdu)],"%02X",0);
sprintf(&pdu[strlen(pdu)],"%02X",13);
sprintf(&pdu[strlen(pdu)],"%02X",145);
sprintf(&pdu[strlen(pdu)],"%s",number);
sprintf(&pdu[strlen(pdu)],"%02X",0);
sprintf(&pdu[strlen(pdu)],"%02X",0);
sprintf(&pdu[strlen(pdu)],"%02X",167);
sprintf(&pdu[strlen(pdu)],"%02X",10);
sprintf(&pdu[strlen(pdu)],"%s",buff);
}
creat_smssubmit_pdu产生的pdu如下:
00 11 00 0D 91 683175428705F3 00 00 A7 0A E8329BFD4697D9EC37 (其中的空格仅仅为了方便查看,实际是没有的)
同样我也用11位电话号码来组织(省去前面的86),如下:
00 11 00 0B 91 3175428705F3 00 00 A7 0A E8329BFD4697D9EC37
但是当我发送完命令AT+CMGS=<length><CR>后,要等至少十秒才会出现simens 6618给出的回应">",此时发送pdu,结果不论我怎么组织pdu中各个分组6618总是给出"ERROR",而且没有给出错误号.
知道为什么吗? |
|