源码如下,是不是要把完整的数据包m_strAPacket的类型转换成Widechar就可以了?
我发送和接受的全部是16进制的asc码形式啊!请高手赐教!!!
procedure TNoramlCommGSM.AnalyseCMGRPacket;
var
strData,str,strContent : string;
str1,str2,str3,str4,strDateTime:string;
i,nCount,nComma,nPos0A,nPosComma2,nStat,nLen,nTimeLen:integer;
nPosComma: array[1..7] of integer;
nPosDoub:array[1..6] of integer;
nCommaCount,nDoubCount: integer;//逗号和双引号的个数
dt:TDateTime;
ContentArray : TMsgBArray;
aCommandRecord :TCommandRecord;//向协议解析单元传送的报文记录
begin
strData := m_strAPacket;//m_strAPacket完整的数据包 string类型
ShowCommStr('Recv: ' + m_strAPacket);
nCount := Length(strData);
if nCount<50 then
begin
PubToolsUnit.DebugInfo('短信长度错误!',clRed);
exit;
end;
//逗号和双引号的总数
nCommaCount := 0;
nDoubCount := 0;
//记录逗号和双引号的位置
for i:= 1 to nCount do
begin
if strData=',' then
begin
Inc(nCommaCount);
nPosComma[nCommaCount] := i; //逗号位置
end
else if strData='"' then
begin
Inc(nDoubCount);
nPosDoub[nDoubCount] := i; //双引号位置
end;
end;
if nCommaCount<>7 then
begin
PubToolsUnit.DebugInfo('逗号总数出错!',clRed);
exit;
end;
if nDoubCount<>6 then
begin
end;
//短信读取状态
try
str1 := copy(strData,nPosDoub[1],nPosDoub[2]-nPosDoub[1]+1);//读取状态
if str1<>'"REC UNREAD"' then
begin
PubToolsUnit.DebugInfo('短信已经读取!',clRed);
exit;
end;
except
end;
//读取CDMA-ID号码
try
str2 := copy(strData,nPosDoub[3],nPosDoub[4]-nPosDoub[3]+1); //"13912345678"
str2 := copy(str2, 2, Length(str2)-2); //把前后的双引号去掉
except
end;
//读取日期和时间
try
str3 := copy(strData,nPosDoub[5],nPosDoub[6]-nPosDoub[5]+1);//"05-06-28,10 :48 :40"
// nTimeLen := Length(str3);
strDateTime := '20'+copy(str3,2,2)+'-';
strDateTime := strDateTime + copy(str3,5,2)+'-';
strDateTime := strDateTime + copy(str3,8,2)+' ';
strDateTime := strDateTime + copy(str3,11,2);
strDateTime := strDateTime + copy(str3,14,3);
strDateTime := strDateTime + copy(str3,18,3);
dt := StrToDatetime(strDateTime);
except
PubToolsUnit.DebugInfo('短信日期转换出错!',clRed);
exit;
end;
//复制短信息内容
try
//str4 := copy(strData,nPosDoub[6]+13,nCount-nPosDoub[6]-13-1);
i := pos(#$A, strData);
str4 := copy(strData, i+1, nCount - i - 2); //把尾巴上的0d0a去掉
except
PubToolsUnit.DebugInfo('短信内容复制出错!',clRed);
exit;
end;
SetLength( ContentArray, 1 );
if (Length(str4) mod 2) <> 0 then
str4 := StringReplace(str4, ':' , '3A', [rfReplaceAll]);
ContentArray := HexTxtToBArray(str4);
aCommandRecord.PacketHeader.GSM_ID := str2;
aCommandRecord.PacketHeader.RecTime := now;
aCommandRecord.CmdTime := dt; //cdma模块接收短信息的时间
aCommandRecord.cmdLength := Length(ContentArray);
aCommandRecord.CmdContent := ContentArray;
AnalyseRecvPacket(aCommandRecord);
end;