📄 adgsm.pas
字号:
MessageIndex := StrToInt(NotifyStr); {!!.02}
//if Assigned(FOnNewMessage) then begin {!!.02}
{ if OnNewMessage event then PostMessage to Synchronize/ListAllMessages }
FNeedNewMessage := MessageIndex; {!!.04}
PostMessage(FHandle, ApdGSMResponse, 1,0); {!!.04}
// FOnNewMessage(Self, MessageIndex, TheMessage); {!!.02} {!!.04}
//end; {!!.04} {!!.06}
end; {!!.02}
end; {!!.02}
end; {!!.02}
{ issues +CMGL to list all messages with a Status of ssUnsend}
procedure TApdCustomGSMPhone.ListAllMessages;
var
Res : Integer;
ET : EventTimer;
begin
if FQuickConnect then {!!.06}
exit; {!!.06}
if FGSMState > gsNone then begin
DoFail(secSMSBusy,-8100);
Exit;
end;
if not FConnected then begin
{ Do connection/configuration stuff }
DoFail(secBadOperation,-8302);
Exit;
end;
CmdIndex := 0;
SetState(gsListAll);
FMessageStore.ClearStore;
FComPort.FlushInBuffer;
ResponsePacket.StartCond := scAnyData; {!!.02}
//ResponsePacket.StartString := #13#10; {!!.02}
//ResponsePacket.StartString := '+CMGL: '; {!!.02}
ResponsePacket.EndString := #13#10'OK'#13#10; {!!.02}
ResponsePacket.IncludeStrings := True; {!!.04}
ResponsePacket.Enabled := True;
//DelayTicks(4, True); {!!.04}
FComPort.Output := 'AT' + GSMListAllMessagesCommands[CmdIndex] + #13;
NewTimer(ET, 1080); // 60 second timer
DelayTicks(1, True); {!!.06}
repeat
Res := SafeYield;
until (FGSMState = gsNone) or (Res = wm_Quit) or TimerExpired(ET);
if TimerExpired(ET) then begin
DoFail(secSMSTimedOut,-8101);
Exit;
end;
end;
{ issues +CMSS to send message from storage indexed by Index }
procedure TApdCustomGSMPhone.SendFromMemory(TheIndex: Integer);
var
Res : Integer;
ET : EventTimer;
begin
if FGSMState > gsNone then begin
DoFail(secSMSBusy,-8100);
Exit;
end;
if not FConnected then begin
{ Do connection/configuration stuff }
FQuickConnect := False;
Connect;
end;
CmdIndex := 0;
SetState(gsSendFStore);
ResponsePacket.StartString := '+CMSS: ';
ResponsePacket.EndString := #13#10'OK';
ResponsePacket.ComPort := FComPort;
ResponsePacket.Enabled := True;
//DelayTicks(4, True); {!!.04}
FComPort.Output := 'AT' + GSMSendMessFromStorage[CmdIndex] +
IntToStr(TheIndex) + #13;
NewTimer(ET, 1080); // 60 second timer
repeat
Res := SafeYield;
until (FGSMState = gsNone) or (Res = wm_Quit) or TimerExpired(ET);
if TimerExpired(ET) then begin
DoFail(secSMSTimedOut,-8101);
Exit;
end;
end;
{ issues +CMGS to send message without placing the message in memory }
{$IFDEF AproBCB}
procedure TApdCustomGSMPhone.SendSMSMessage;
{$ELSE}
procedure TApdCustomGSMPhone.SendMessage;
{$ENDIF}
var
Res : Integer;
ET : EventTimer;
begin
if FGSMState > gsNone then begin
DoFail(secSMSBusy,-8100);
Exit;
end;
if not FConnected then begin
{ Do connection/configuration stuff }
Connect;
end;
//if FNotifyOnNewMessage then {!!.01}{!!.06}
// CmdIndex := 0 {!!.01}{!!.06}
//else {!!.01}{!!.06}
//CmdIndex := 1; // Handled in the gsConfig {!!.06}
CmdIndex := 0; {!!.06}
ResponsePacket.EndString := #13; {!!.01}
ResponsePacket.StartString := GSMSendMessageResponse[CmdIndex];
ResponsePacket.Enabled := True;
//DelayTicks(4, True); {!!.04}
SetState(gsSend);
FComPort.Output := 'AT' + GSMSendMessageCommands[CmdIndex] + #13;
NewTimer(ET, 1080); // 60 second timer
repeat
Res := SafeYield;
until (FGSMState = gsNone) or (Res = wm_Quit) or TimerExpired(ET);
if TimerExpired(ET) then begin
DoFail(secSMSTimedOut,-8101);
Exit;
end;
end;
procedure TApdCustomGSMPhone.SetMessage(const Value: string);
begin
if Length(Value) > 160 then begin
DoFail(secSMSTooLong,-8102);
Exit;
end;
FMessage := Value;
end;
{ enables/disables new message notification (+CNMI), new messages provided
through OnNewMessage event }
procedure TApdCustomGSMPhone.SetNotifyOnNewMessage(const Value: Boolean);
begin
FNotifyOnNewMessage := Value;
// Return True for then +CMTI for New Message Indications to TE
end;
{ TApdMessageStore }
function TApdMessageStore.AddMessage(const Dest, Msg: string): Integer;
var
SMS : TApdSMSMessage;
begin
SMS := nil;
try
SMS := TApdSMSMessage.Create;
SMS.Message := Msg;
SMS.Address := Dest;
SMS.TimeStampStr := FormatDateTime('yy/mm/dd/hh:mm:ss', Now);
SMS.Status := ssUnsent;
Result := AddObject(SMS.TimeStampStr, SMS);
finally
SMS.Free;
end;
end;
{ Clear all Messages }
procedure TApdMessageStore.Clear;
begin
inherited;exit;
// Clear All messages
while Count > 0 do begin
if Objects[Count - 1] <> nil then begin
TApdSMSMessage(Objects[Count - 1]).Free;
Objects[Count - 1] := nil;
end;
Delete(Count - 1);
end;
end;
{ Just clears our message store - not the phone }
procedure TApdMessageStore.ClearStore;
begin
JustClearStore := True;
Clear;
JustClearStore := False;
end;
{ Create Message Store }
constructor TApdMessageStore.Create(GSMPhone : TApdCustomGSMPhone);
begin
FGSMPhone := GSMPhone;
JustClearStore := False;
end;
{ issues +CMGD to Delete Message at Index }
procedure TApdMessageStore.Delete(PhoneIndex: Integer);
var
I : Integer;
begin
if (FGSMPhone.FConnected) and not(JustClearStore) then
FGSMPhone.DeleteFromMemoryIndex(PhoneIndex)
else begin
for I := 0 to pred(Count) do
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 }
{$IFDEF AproBCB}
function TApdMessageStore.GetSMSMessage(Index: Integer): TApdSMSMessage;
{$ELSE}
function TApdMessageStore.GetMessage(Index: Integer): TApdSMSMessage;
{$ENDIF}
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
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 ));
end;
{ Build a PDU message !!.PDU}
function BuildPDUMessage : string;
var
TheLength, I: Integer;
TheNextOctet, S: string;
T: ShortString;
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -