📄 adgsm.pas
字号:
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;
//FirstOctet
FTempWriteMess := FTempWriteMess + '11';
// Lets the phone set the message reference number itself
FTempWriteMess := FTempWriteMess + '00';
TheLength := Length(FSMSAddress);
S := Format ('%02.2x', [TheLength]);
FTempWriteMess := FTempWriteMess + S;
// 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';
// Optional validity period.
FTempWriteMess := FTempWriteMess + 'AA'; //"AA" means 4 days.
// 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;
PDULength := Length(FTempWriteMess) DIV 2 - 1;
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
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;
end;
// Change message to string form
TheMessage := PDUToString(T);
if MessageLength = Length(TheMessage) then
// Store message
TempSMSMessage.FMessage := TheMessage;
end; // else our PDU should handle longer messages
if TempSMSMessage.FMessageIndex = FNeedNewMessage then
// if new message notify wanted, then assign it
FRecNewMess := TempSMSMessage.Message;
MessageStore.AddObject(TempSMSMessage.TimeStampStr, TempSMSMessage);
Result := Pos('+CMGL:', S) > 0;
end;
{ Parse a message }
function ParseAMessage : Boolean;
begin
if Pos (#13#10, S) = 1 then
GetNextField (#13#10);
if Pos('+CMGL:', S) = 1 then begin
// first line of the message
// format is +CMGL: Index, status, address, address name, timestamp
TempSMSMessage := TApdSMSMessage.Create;
S := Copy(S, Pos(':', S) + 1, Length(S));
// extract the index number
TempSMSMessage.FMessageIndex := GSMStrToInt(GetNextField(','));
// extract the status
STemp := GetNextField( ',' );
if STemp = 'STO UNSENT' then TempSMSMessage.FStatus := ssUnsent
else if STemp = 'STO SENT' then TempSMSMessage.FStatus := ssSent
else if STemp = 'ALL' then TempSMSMessage.FStatus := ssAll
else if STemp = 'REC UNREAD' then TempSMSMessage.FStatus := srUnread
else if STemp = 'REC READ' then TempSMSMessage.FStatus := srRead
else TempSMSMessage.FStatus := ssUnknown; {!!.01}
// Read the address field with quotes (if any)
TempSMSMessage.FAddress := GetNextField( ',' );
// Name (??) field followed by ,
TempSMSMessage.FName := GetNextField( ',' );
// DateTime Field followed by ,
TempSMSMessage.FTimeStampStr := GetNextField( ',' );
if TempSMSMessage.FTimeStampStr = '' then
TempSMSMessage.FTimeStampStr := '<no timestamp>';
// Message Type followed by ,
STemp := GetNextField( ',' );
// Message Length followed by #13#10
STemp := GetNextField( #13#10 );
// Message followed by #13#10
TempSMSMessage.Message := GetNextField( #13#10 );
end else begin
// Message more than 1 line???
TempSMSMessage.Message := TempSMSMessage.Message + #13#10 +
GetNextField( #13#10 );
end;
if TempSMSMessage.FMessageIndex = FNeedNewMessage then {!!.06}
FRecNewMess := TempSMSMessage.Message; {!!.06}
MessageStore.AddObject(TempSMSMessage.TimeStampStr, TempSMSMessage);
Result := Pos('+CMGL:', S) > 0; {!!.04}
end;
begin
//State machine response handle
case FGSMState of
gsConfig: begin
S := ResponseStr; {!!.PDU}
inc(CmdIndex);
STemp := ''; {!!.PDU}
if CmdIndex > High(GSMConfigAvail) then begin
// generate the OnComplete event, we're done configuring
ResponseStr := ''; {!!.02}
if not FQuickConnect then begin {!!.02}
// State set to gsNone in PostMessage below
//FGSMState := gsNone; {!!.02}{!!.06}
// PostMessage calls ListAllMessages
PostMessage(FHandle, ApdGSMResponse, 1,0); {!!.06}
//ListAllMessages; {!!.02}{!!.06}
end; {!!.02}
FGSMState := gsConfig; {!!.02}
if Assigned(FOnGSMComplete) then {!!.02}
FOnGSMComplete(Self, FGSMState, FErrorCode); {!!.02}
FGSMState := gsNone;
FConfigList := False; {!!.02}
ResponseStr := '';
end else begin
// send the next command
ResponsePacket.StartString := GSMConfigResponse[CmdIndex];
ResponsePacket.EndString := #13;
ResponsePacket.Enabled := True;
//DelayTicks(4, True); {!!.04}
STemp := GSMConfigAvail[CmdIndex]; {!!.06}
// Detect, PDU, or Text
if STemp = '+CMGF=' then begin {!!.PDU}
STemp := Copy(S, Pos('(',S)+1, Length(S)); {!!.PDU}
if Length(STemp) < 3 then begin {!!.PDU}
if (FGSMMode = gmPDU) and (STemp[1] = '0') then {!!.PDU}
SetPDUMode(True) {!!.PDU}
else {!!.PDU}
if (STemp[1] = '1') then {!!.PDU}
SetPDUMode(False); {!!.PDU}
end else begin {!!.PDU}
if (FGSMMode = gmPDU) and (STemp[3] = '1') then {!!.PDU}
SetPDUMode(True) {!!.PDU}
else {!!.PDU}
SetPDUMode(False); {!!.PDU}
end; {!!.PDU}
STemp := GSMConfigAvail[CmdIndex]; {!!.PDU}
end; {!!.PDU}
if STemp = '+CMGF=' then begin {!!.PDU}
if FPDUMode then {!!.PDU}
STemp := STemp + '0' {!!.PDU}
else {!!.PDU}
STemp := STemp + '1'; {!!.PDU}
if QuickConnect then {!!.PDU}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -