📄 adgsm.pas
字号:
if Messages[I].MessageIndex = PhoneIndex then
Break;
if I < Count then
begin
if Objects[I] <> nil then
begin
TApdSMSMessage(Objects[I]).Free;
Objects[I] := nil;
end;
inherited Delete(I);
end;
end;
end;
{ Return the phone's message store capacity }
function TApdMessageStore.GetCapacity: Integer;
begin
result := FCapacity;
end;
{ Get message number of Index }
function TApdMessageStore.GetMessage(Index: Integer): TApdSMSMessage;
begin
Result := TApdSMSMessage(Objects[Index]);
end;
{ issues + to send all messages with a Status of ssUnsent }
procedure TApdCustomGSMPhone.SendAllMessages;
var
Res : Integer;
HighIndex: Integer;
I: Integer;
begin
if FGSMState > gsNone then
begin
DoFail(secSMSBusy,-8100);
Exit;
end;
if not FConnected then begin
{ Do connection/configuration stuff }
FQuickConnect := False;
Connect;
repeat
Sleep(SLEEPTIME);
Res := SafeYield;
until (FGSMState = gsNone) or (Res = wm_Quit);
end;
CmdIndex := 0;
{ tell the GSMPhone to send all messages in it's store }
HighIndex := FMessageStore.GetCapacity;
for I := 0 to HighIndex do
begin
SendFromMemory(I);
end;
end;
procedure TApdCustomGSMPhone.ProcessResponse;
{ Convert String to Integer }
function GSMStrToInt(Str : string) : Integer;
begin
while Pos(' ', Str) > 0 do
Str[Pos(' ', Str)] := '0';
Result := StrToInt(Str);
end;
var
S : string;
STemp : string;
MsgRdy : Boolean;
PDULength : Integer; {!!.PDU}
{ Get next field in message }
function GetNextField( aDelimiter: String ): String;
var
aDelimiterPosition: Integer;
begin
{To retrieve the text from position 1 until the occurance of aDelimiter
while advancing the pointer in S so that we can just call this function
again and again. }
if S[1] = '"' then
begin
aDelimiter := '"' + aDelimiter;
end;
aDelimiterPosition := Pos( aDelimiter, S );
Result := Copy( S, 1, aDelimiterPosition - 1 );
if ( Result <> '' ) and ( Result[ 1 ] = '"' ) then
Result := Copy( Result, 2, Length( Result ) );
if ( Result <> '' ) and ( Result[ Length( Result ) ] = '"' )then
Result := Copy( Result, 1, Length( Result ) - 1 );
S := Copy( S, aDelimiterPosition + Length( aDelimiter ), Length( S ));
// s := copy(S, pos(s,'+CMGL:'),length(S));
end;
{ Build a PDU message !!.PDU}
function BuildPDUMessage : string;
var
TheLength, I: Integer;
TheNextOctet, S: string;
T: ShortString;
TheHeadWidth: Integer;
begin
TheLength := Length(FSMSCenter);
if Odd(TheLength) then
TheLength := TheLength + 1;
if FSMSCenter = '' then
// No SMSCenter needed
FTempWriteMess := '00'
else
begin
// Add the length of SMSCenter in octets
FTempWriteMess := '0' + IntToStr((TheLength Div 2) + 1);
if Length(FSMSCenter) > 10 then
begin
FTempWriteMess := FTempWriteMess + '91'; // International format
end else
begin
FTempWriteMess := FTempWriteMess + '81'; // Let phone handle format
end;
I := 1;
// Add SMSCenter to PDU message
while I < Length(FSMSCenter) do
begin
TheNextOctet := FSMSCenter[I+1] + FSMSCenter[I];
FTempWriteMess := FTempWriteMess + TheNextOctet;
I := I + 2;
end;
if Odd(Length(FSMSCenter)) then
FTempWriteMess := FTempWriteMess + 'F' + FSMSCenter[Length(FSMSCenter)];
end;
TheHeadWidth := length(FTempWriteMess);
//FirstOctet
FTempWriteMess := FTempWriteMess + '11';
// Lets the phone set the message reference number itself
FTempWriteMess := FTempWriteMess + '00';
TheLength := Length(FSMSAddress);
S := Format ('%02.2x', [TheLength]);
//Modify By AHA
FTempWriteMess := FTempWriteMess + S;
// FTempWriteMess := FTempWriteMess + '0D';
// Add SMSAddress to PDU message
if Length(FSMSAddress) > 10 then
FTempWriteMess := FTempWriteMess + '91' // International format
else
FTempWriteMess := FTempWriteMess + '81'; // Let phone handle format
I := 1;
while I < Length(FSMSAddress) do begin
TheNextOctet := FSMSAddress[I+1] + FSMSAddress[I];
FTempWriteMess := FTempWriteMess + TheNextOctet;
I := I + 2;
end;
if Odd(Length(FSMSAddress)) then
FTempWriteMess := FTempWriteMess + 'F' + FSMSAddress[I];
// Protocol identifier
FTempWriteMess := FTempWriteMess + '00';
// Datacoding scheme
// FTempWriteMess := FTempWriteMess + '00';
FTempWriteMess := FTempWriteMess + '08';
// Optional validity period.
// FTempWriteMess := FTempWriteMess + 'AA'; //"AA" means 4 days.
// FTempWriteMess := FTempWriteMess + '10'; //"AA" means 4 days.
FTempWriteMess := FTempWriteMess + '00'; //"AA" means 4 days.
/////////////////////////////////////////////////////
//modify by aha to Change the CHina Language setting
/////////////////////////////////////////////////////
// Length of SMS message converted to HEX
// TheLength := Length(FMessage);
// S := Format ('%02.2x', [TheLength]);
// FTempWriteMess := FTempWriteMess + S;
// T := '';
// Add SMSMessage after transformation to PDU string
// S := StringToPDU(FMessage);
// for I := 1 to Length(S) do begin
// T := T + IntToHex(Byte(S[I]), 2);
// end;
// FTempWriteMess := FTempWriteMess + T;
////////////////////////////////////////////////////
////////////////////////////////////////////////////
s:= StringToPDUCN(FMessage);
TheLength := length(s);
TheLength := TheLength div 2;
FTempWriteMess := FTempWriteMess + Format ('%02.2x', [TheLength]);
FTempWriteMess := FTempWriteMess + s;
// PDULength := Length(FTempWriteMess) DIV 2 - 1;
PDULength := (Length(FTempWriteMess)-TheHeadWidth) DIV 2;
end;
{ Parse PDU message } {!!.PDU}
function ParseAPDUMessage : Boolean;
var
St, TempS, TempStaID, U: String;
T, TheMessage: ShortString;
NumLength, I, TempI, MessageLength : Integer;
begin
// Make sure we are not at the end of the last message
if Pos (#13#10, S) = 1 then
GetNextField (#13#10);
// Make sure we are at the beginning of a message
{ TODO : Modified by AHA }
// if Pos('+CMGL:', S) = 1 then
if Pos('+CMGL:', S) <>-1 then
begin
// Build the SMS message while reading
TempSMSMessage := TApdSMSMessage.Create;
// format is +CMGL: Index, status, address, address name, timestamp
S := Copy(S, Pos(':', S) + 1, Length(S));
// extract the index number
TempSMSMessage.FMessageIndex := GSMStrToInt(GetNextField(','));
//Let the phone handle the status
//TempSMSMessage.FStatus := GSMStrToInt(GetNextField(','));
GetNextField(#13#10);
// Assign PDU stuff to TempS
TempS := GetNextField(#13#10);
NumLength := StrToInt(Copy(TempS, 0, 2));
I := 0;
//NumLength is length of center number, in octets
if NumLength > 0 then begin
// Next two digits is Type-of-Address octet
I := StrToInt(Copy(TempS, 3, 2));
// I is the Type-of-Address octet
case I of
91 : begin
end;
81 : begin
end;
end; // End Case
// NumLength = length of center phone number
TempStaID := '';
I := 5;
while I < (NumLength*2 + 3) do begin
if TempS[I] = 'F' then
TempStaID := TempStaID + TempS[I+1]
else
TempStaID := TempStaID + TempS[I+1] + TempS[I];
I := I + 2;
end;
// TempStaID is the Center Address at this point
end else begin
STemp := Copy(STemp, 3, Length(STemp));
end;
// TempI = octet is First Octet of SMS-Deliver PDU
TempI := StrToInt(Copy(TempS, I, 2));
// Get next octet
TempS := Copy(TempS, I+2, Length(TempS));
St := Copy(TempS, 0, 2);
case TempI of
4 : begin // This PDU is a SMS delivery
end;
11: begin // Message ready to send
if St = '00' then begin
// The "00" lets the phone set the message reference number.
TempS := Copy(TempS, 3, Length(TempS));
St := Copy(TempS, 0, 2);
end;
end;
24: begin // Status report indication returned
end;
end; // End Case
//Address-Length. Length of the sender number (0B hex = 11 dec)
NumLength := (StrToInt('$' + St));
// Next two digits is Type-of-Address octet
I := StrToInt('$' + Copy(TempS, 3, 2));
case I of
133 : begin
// 85 in Hex = Voice mail ?
end;
145 : begin
// 91 in Hex
end;
129 : begin
// 81 in Hex
end;
200 : begin
// C8 in Hex
end;
end; // End Case
// NumLength = Length of phone number
TempStaID := '';
if Odd(NumLength) then
NumLength := NumLength + 1;
// Change NumLength to Octets
NumLength := NumLength Div 2;
I := 5;
while I < (NumLength*2 + 5) do begin
if TempS[I] = 'F' then
TempStaID := TempStaID + TempS[I+1]
else
TempStaID := TempStaID + TempS[I+1] + TempS[I];
I := I + 2;
end;
// TempStaID is the StationID at this point
TempSMSMessage.FAddress := TempStaID;
// Protocol identifier of "00" and Data coding scheme of "00"
// are the 2 octets or the 4 added to I, below
I := I + 4; // start of time stamp
St := '';
if TempS[I] = 'A' then
begin
// No time stamp - not sent yet
TempI := I + 2;
end else
begin
St := TempS[I+1] + TempS[I] + '/' + // Year
TempS[I+3] + TempS[I+2] + '/' + // Month
TempS[I+5] + TempS[I+4] + ',' + // Day
TempS[I+7] + TempS[I+6] + ':' + // Hours
TempS[I+9] + TempS[I+8] + ':' + // Minutes
TempS[I+11] + TempS[I+10] + '+' + // Seconds
TempS[I+13] + TempS[I+12]; // Time Zone
// 14 is length of time stamp - Keeping track where we are in TempS
TempI := I + 14;
TempSMSMessage.FTimeStampStr := St;
end;
// Get next octet
St := TempS[TempI] + TempS[TempI + 1];
// MessageLength
MessageLength := StrToInt('$' + St);
// U is the message
U := Copy(TempS,TempI+2,Length(TempS));
// NumLength is the length of the message
{ NumLength := Length(U);
// Set pointer to start of message
I := 1;
T := '';
while I < NumLength do
begin
St := '$' + U[I] + U[I+1];
TempI := StrToInt(St);
T := T + char(TempI);
I := I + 2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -