关于手机GSM MODEM的收发短信问题!(50分)

  • 主题发起人 主题发起人 lzplzp001
  • 开始时间 开始时间
L

lzplzp001

Unregistered / Unconfirmed
GUEST, unregistred user!
我用WAVECOM的GSM MODEM做了一个收发短信的程序!但是遇到了两个问题!请高手指点
1、收到到的短信怎么解码,一般的中文的可以解码!但是纯英文的却无法解码(PDU码)!
2、群发短信的时候,设断点测试可以循环群发短信,但是程序直接运行却无法群发!!
我已经设置了SLEEP(4000)了!


 
没有人知道吗?
 
1.纯英文解码(PDU码)
function DecodeE(s: string): string;
function HexCharToInt(HexToken: char): Integer;
begin
{if HexToken>#97 then HexToken:=Chr(Ord(HexToken)-32);
{ use lowercase aswell }

Result := 0;

if (HexToken > #47) and (HexToken < #58) then { chars 0....9 }
Result := Ord(HexToken) - 48
else
if (HexToken > #64) and (HexToken < #71) then { chars A....F }
Result := Ord(HexToken) - 65 + 10;
end;

function HexCharToBin(HexToken: char): string;
var
DivLeft: integer;
begin
DivLeft := HexCharToInt(HexToken); { first HEX->BIN }
Result := '';
{ Use reverse dividing }
repeat { Trick; divide by 2 }
if odd(DivLeft) then { result = odd ? then bit = 1 }
Result := '1' + Result { result = even ? then bit = 0 }
else
Result := '0' + Result;

DivLeft := DivLeft div 2; { keep dividing till 0 left and length = 4 }
until (DivLeft = 0) and (length(Result) = 4); { 1 token = nibble = 4 bits }
end;

function HexToBin(HexNr: string): string;
{ only stringsize is limit of binnr }
var
Counter: integer;
begin
Result := '';

for Counter := 1 to length(HexNr) do
Result := Result + HexCharToBin(HexNr[Counter]);
end;

function pow(base, power: integer): integer;
var
counter: integer;
begin
Result := 1;

for counter := 1 to power do
Result := Result * base;
end;

function BinStrToInt(BinStr: string): integer;
var
counter: integer;
begin
if length(BinStr) > 16 then
raise ERangeError.Create(#13 + BinStr + #13 +
'is not within the valid range of a 16 bit binary.' + #13);

Result := 0;

for counter := 1 to length(BinStr) do
if BinStr[Counter] = '1' then
Result := Result + pow(2, length(BinStr) - counter);
end;

var
OctetStr: string;
OctetBin: string;
Charbin: string;
PrevOctet: string;
Counter: integer;
Counter2: integer;
begin
PrevOctet := '';
Result := '';

for Counter := 1 to length(s) do
begin
if length(PrevOctet) >= 7 then { if 7 Bit overflow on previous }
begin
if BinStrToInt(PrevOctet) <> 0 then
Result := Result + Chr(BinStrToInt(PrevOctet))
else
Result := Result + ' ';

PrevOctet := '';
end;

if Odd(Counter) then { only take two nibbles at a time }
begin
OctetStr := Copy(s, Counter, 2);
OctetBin := HexToBin(OctetStr);

Charbin := '';
for Counter2 := 1 to length(PrevOctet) do
Charbin := Charbin + PrevOctet[Counter2];

for Counter2 := 1 to 7 - length(PrevOctet) do
Charbin := OctetBin[8 - Counter2 + 1] + Charbin;

if BinStrToInt(Charbin) <> 0 then
Result := Result + Chr(BinStrToInt(CharBin))
else
Result := Result + ' ';

PrevOctet := Copy(OctetBin, 1, length(PrevOctet) + 1);
end;
end;
end;

2.在AT+CMGS= ....后Sleep(3000); 然后写入信息发送后,再Sleep(4000)
然后循环
 
感谢你的支持!
第一、用PDU格式(at+cmgf=0)接收短信时无法分辨是否是纯英文,我就算有英文的解码和中文的解码程序!但是也无法确定对方发给我的是何种类的短信!
第二、发送时代码是这样的!代码用的是SPCOMM控件的。单步执行没有问题!但是不设断点运行会出错。
mess:='at+cmgf=0'+#13;
comm1.WriteCommData(pchar(mess),Length(mess));
Sleep(2000);
mess:='at+cmgs='+发送短信长度+#13+短信的PDU编码+#26+#13;
comm1.WriteCommData(pchar(mess),Length(mess));
Sleep(4000);
出错的信息:

at+cmgf=0

OK

at+cmgs=138
0011
> 000B813108729201F20008107C002A4E0A6D77516B767E4F34004A0034003400360035002A4E0A6D77516B767E4F3400500036003900340037002A4E0A6D774E1C65B9004A0035003300320032002A4E0A6D774E1C65B900500033003900350036002A4E0A6D778679686500500033003000340030002A4E0A6D77534E805400500035003300390035

at+cmgs=138
00
ERROR
F033753130
+CMGS: 217
 
试过,第二个问题已经解决!
第一个问题请教有没有什么好方法!!可以加分!!
 
第一个问题也就是如何确定对方发送的是纯英文还是中英混编!!
如果是纯英文,可以用你的解码程序解码,如果不是,则需要用中文解码程序解码!
你做过吗?如何解决的??有代码最好!
 
如:
0891683108301105F0000D91683137882787F2 00 [red]08[/red] 40307241112300 04 4E2D56FD
先判断接收数据的红色部分 :08为中文编码,00为英文编码
 
谢谢!!有效!
 
后退
顶部