中文短消息的编码格式,实现GSM模块中文短消息的传送

hoosainyor 2003-02-13 04:04:31
我遇到了有关传送中文短消息的问题。因此想知道中文短消息的编码格式,怎么实现用AT指令使GSM模块传送中文短消息?
...全文
162 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hacking 2003-05-14
  • 打赏
  • 举报
回复
mark
hoosainyor 2003-03-23
  • 打赏
  • 举报
回复
小弟谢谢了!
czfjf3 2003-02-22
  • 打赏
  • 举报
回复
真的是好牛
man8888 2003-02-14
  • 打赏
  • 举报
回复
这个东东怎么用啊?能不能详细说明一下?
phalcon 2003-02-14
  • 打赏
  • 举报
回复
牛人啊 COPY之
ly_liuyang 2003-02-13
  • 打赏
  • 举报
回复
这东西难找呵呵,Mark下了
Billy_Chen28 2003-02-13
  • 打赏
  • 举报
回复
用GSM模块发中文短讯,必须以PDU包的形式发送。我将它写成了Dll,直接调用SMSEncode函数即可得到追后的编码。现将原码公开:
unit EnCodeCompnent;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

function SMSEncode(s:WideString;Result_Code:pchar):Bool;Stdcall;export;
function SMSDecode(Input_Code:pchar;Result_Str:pchar):Bool;Stdcall;export;
function MakePDU(DestNumber:pchar;Content:pchar;Result_String:pchar):Bool;stdcall;export;
function ConvertPhoneNum(strNum:string):string;
function Transposition(instr:pchar;Result_str:pchar):Bool;stdcall;export;//将一个字符串两两交换位置
{ Public declarations }

implementation


function SMSEncode(s:WideString;Result_Code:pchar):Bool;
var
i,len:Integer;
cur:Integer;
t,temp:String;
begin
if length(s)>0 then
begin
len:=Length(s);
i:=1;
while i<=len do
begin
cur:=ord(s[i]);
//BCD convert
FmtStr(t,'%4.4X',[cur]);
temp:=temp+t;
inc(i);
end;
StrCopy(Result_Code,pchar(temp));
Result:=true;
end
else
Result:=false;
end;

function SMSDecode(Input_Code:pchar;Result_Str:pchar):Bool;
var
str:string;
i:integer;
temp:string;
A_PWideChar:array[0..300] of widechar;
R_String:string;
A_integer:integer;
begin
str:=string(Input_Code);
R_String:='';
if length(str)<=0 then
begin
Result:=false;
exit;
end;
i:=0;
while i<length(str) do
begin
temp:=copy(str,i+1,4);
A_integer:=strtoint('$'+temp);
move(A_integer,A_PWideChar[i div 4],sizeof(A_PWideChar[i div 4]));
inc(i,4);
end;
A_PWideChar[length(str) div 4]:=#0;
R_String:=WideCharToString(@A_PWideChar);
StrCopy(Result_Str,pchar(R_String));
Result:=true;
end;


function MakePDU(DestNumber:pchar;Content:pchar;Result_String:pchar):Bool;
const
lenSmsInfo='00';
firstOctet='11';
TPMessageReference='00';
TypeOfAddress='91';
TpId='00';
TpDcs='08';//"00" is 7 bit encode "08" is 8 bit encode;
TPValidityPeriod='AA';//aa is 4 day
var
DestPhoneNum:string;
AddressLength:string;
TpUserData:string;
TPUserDataLength:string;
temp:WideString;
Tmp_Pchar:pchar;
Rlt_str:string;
begin
if (DestNumber='') or (Content='') then
begin
Result:=false;
exit;
end
else
begin
DestPhoneNum:=ConvertPhoneNum(DestNumber);
AddressLength:=format('%2.2X',[length(DestNumber)]);
temp:=Content;
Tmp_Pchar:=StrAlloc(1000);
if SMSEncode(temp,Tmp_Pchar) then
TpUserData:=string(Tmp_Pchar);
if TpDcs='08' then
TPUserDataLength:=format('%2.2X',[length(TpUserData) div 2])
else
TPUserDataLength:=format('%2.2X',[((length(TpUserData) div 2)*8) div 7]);
Rlt_str:=lenSmsInfo
+firstOctet
+TPMessageReference
+AddressLength
+TypeOfAddress
+DestPhoneNum
+TpId
+TpDcs
+TPValidityPeriod
+TPUserDataLength
+TpUserData;//TpUserData have to Encoded;
StrCopy(Result_String,pchar(Rlt_str));
Result:=true;
end;
end;

function ConvertPhoneNum(strNum:string):string;
var
i:integer;
str:string;
A_Pchar:pchar;
begin
str:=strNum;
i:=length(str);
if odd(i) then
begin
str:=str+'F';
A_Pchar:=StrAlloc(40);
if Transposition(pchar(str),A_pchar) then
result:=string(A_Pchar)
else
result:='Null';
end
else
begin
A_Pchar:=StrAlloc(40);
if Transposition(pchar(str),A_pchar) then
result:=string(A_Pchar)
else
result:='Null';
end;
end;

function Transposition(instr:pchar;Result_str:pchar):Bool;
var
i:integer;
temp:string;
destStr:string;
In_String:string;
begin
if length(instr)>0 then
begin
destStr:='';
In_String:=string(instr);
setlength(In_String,length(In_String));
i:=1;
while i<length(In_String) do
begin
temp:=In_String[i+1]+In_String[i];
destStr:=destStr+temp;
inc(i,2);
end;
StrCopy(Result_Str,pchar(destStr));
result:=true;
end
else
begin
result:=false;
end;
end;


end.
蝈蝈太阳 2003-02-13
  • 打赏
  • 举报
回复
UP

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧