📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Connect, CommConnect, GSM, StdCtrls, LogTerm, Terminal, XSMS, Wap;
type
TForm1 = class(TForm)
GSM1: TGSM;
Comm1: TComm;
Button1: TButton;
Terminal1: TTerminal;
FileTermLogger1: TFileTermLogger;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
procedure GSM1BeforeOpen(DataSet: TConnection);
procedure Comm1BeforeOpen(DataSet: TConnection);
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure GSM1UnsolicitedSMS(Sender: TObject; Idx: Integer;
aSMS: TSMS);
procedure Terminal1KeyPress(Sender: TObject; var Key: Char);
procedure GSM1AfterOpen(DataSet: TConnection);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
fReference: Integer;
fSMSProtocol: TSMSProtocolStack;
procedure ProcessSMS(aSMS: TSMS);
procedure SendSmartMessage(SM: TSmartMessage; aDestAddress: Word);
procedure SendEMS(EMSObj: TEMSObject; aText: string);
procedure SendSEO(aFileName: string);
procedure SendWapPush(aWapPushObj: TWapService; aType: Byte);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
const
DestAddress = '+420604690589';
procedure TForm1.FormCreate(Sender: TObject);
begin
FSMSProtocol:= TSMSProtocolStack.Create; // for delivered message concatenation
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FSMSProtocol.Free;
end;
procedure TForm1.GSM1BeforeOpen(DataSet: TConnection);
begin
with DataSet as TGSM do
begin
Equipment:= eqM35;
PIN:= '1234'; // or empty string if PIN is not required
// phone number of operator service center
SCA:= '+420602909909'; // Eurotel Czech,
// SCA:= '+420603052000'; // T-Mobile Czech
SMSFormat:= smsfPDU; // or smsfText according GSM module
UnsolicitedIndication:= [uindSMSDeliver, uindSMSStatusReport, uindOnlyIndication{some mobiles (Siemens S55) do not send unsolicited message - but indication works}];
end;
end;
procedure TForm1.Comm1BeforeOpen(DataSet: TConnection);
begin
with DataSet as TComm do
begin
DeviceName:= 'Com1';
BaudRate:= br19200;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
GSM1.Open;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
SMS: TSMSSubmit;
begin
SMS:= TSMSSubmit.Create;
try
SMS.GSM:= GSM1;
SMS.DA:= DestAddress; // destination address
// SMS.SRR:= True; // status report request
// SMS.DCS:= $14; // binary 8-bit message
SMS.UD:= 'My first SMS send using Boomerang library'; // text of message
// SMS.DCS:= $18; // UNICODE message
// SMS.WideUD:= 'My first Unicode message';
GSM1.SendSMS(SMS);
finally
SMS.Free; // destroy object instance
end;
end;
procedure TForm1.GSM1UnsolicitedSMS(Sender: TObject; Idx: Integer;
aSMS: TSMS);
var
Stat: Integer;
begin
if aSMS = nil then
begin
try
aSMS:= GSM1.ReadSMS(Idx, Stat);
if Stat in [0{unread}] then
ProcessSMS(aSMS); // process only unreaded messages
finally
GSM1.DeleteSMS(Idx); // delete message from module memory
end;
end
else
begin
ProcessSMS(aSMS);
if Idx <> -1 then
GSM1.DeleteSMS(Idx);
end;
end;
procedure TForm1.ProcessSMS(aSMS: TSMS);
var
S, S2: string;
I: Integer;
NBS: TSMSProtocol;
Addr: Word;
SM: TSmartMessage;
EMS: TEMS;
begin
if aSMS is TSMSDeliver then
begin
with aSMS as TSMSDeliver do
S:= Format('>%s, OA: %s, UD: %s',
[DateTimeToStr(SCTS), OA, UD]);
// do advanced processing
fSMSProtocol.CleanSMSProtocols(5{min}/60/24, False); // remove expired messages
if fSMSProtocol.ProcessSMS(aSMS, NBS) then // check concatanation status of delivered message
begin // message is concatanable
Addr:= 0;
if NBS is TSMSProtocol2 then
Addr:= TSMSProtocol2(NBS).DestinationAddress;
S2:= Format('*ref:%.2x, #%d/%d/%d, , addr:%.4x', [NBS.Reference, NBS.LastInserted, NBS.InsertedCount, NBS.FragmentCount, Addr]);
if NBS.Status = smspsOK then
begin // message is last part
S2:= S2+' complete';
// here is possible process received data, show bitmap, play melody, save it to file etc.
if NBS is TSMSProtocol2 then
begin
// first check if message is Smart Message
SM:= TSmartMessage.CreateSM(NBS.Data, TSMSProtocol2(NBS).DestinationAddress);
if SM <> nil then
try
S2:= S2 + ' SmartMessage:'+SM.ClassName;
{if SM is TSMMultipartMessage then
S2:= S2+'Multipart message'
else if SM is TSMRingingTine then
S2:= S2+'Ringing tone' classname inheritsfrom }
finally
SM.Free;
end
else if NBS is TUDHProtocol then
begin
// if it's not Smart Message it's EMS
EMS:= TEMS.Create;
try
try
EMS.ReadFrom(TUDHProtocol(NBS));
S2:= S2+ ' EMS';
for I:= 0 to EMS.Objects.Count-1 do
begin
if I > 0 then
S2:= S2+',';
S2:= S2+EMS.Objects[I].ClassName;
end;
except
end;
finally
EMS.Free;
end;
end;
end
else if NBS is TSiemensOTA then
begin
S2:= S2 + Format(' SEO: %s, Name: "%s"', [string(TSiemensOTA(NBS).ObjectType), string(TSiemensOTA(NBS).ObjectName)]);
end;
fSMSProtocol.RemoveSMSProtocol(NBS); // remove message from stack
NBS.Free;
end;
S:= S+#13#10+S2;
end;
end
else if aSMS is TSMSStatusReport then
begin
with aSMS as TSMSStatusReport do
S:= Format('!%s, OA: %s, Status: %d, DT: %s', [DateTimeToStr(Now), OA, Status, DateTimeToStr(DT)]);
end
else
Exit;
MessageDlg(S, mtInformation, [mbOk], 0);
end;
procedure TForm1.Terminal1KeyPress(Sender: TObject; var Key: Char);
begin
if not GSM1.Active then
GSM1.COMDevice.Close; // reopen to take effect potential new Comm1 parameters
GSM1.COMDevice.Open;
GSM1.COMDevice.Send(Key); // send key to GSM module
Key:= #0;
end;
procedure TForm1.GSM1AfterOpen(DataSet: TConnection);
var
Sg: TStrings;
I, J: Integer;
begin
// retrieve messages from module memory
if (DataSet as TGSM).Equipment in [eqM20, eqNokia9110, eqWavecom, eqFasttrack] then
Sg:= GSM1.GetSMSList(4{all})
else
Sg:= GSM1.GetSMSList(-1);
try
for I:= 0 to Sg.Count-1 do // process all retrieved messages
begin
J:= StrToInt(Sg.Names[I]);
if StrToInt(Sg.Values[Sg.Names[I]]) in [0{unreaed}] then
begin
if Sg.Objects[I] <> nil then
ProcessSMS(Sg.Objects[I] as TSMS);
end;
GSM1.DeleteSMS(J);
end;
finally
Sg.Free;
end;
end;
procedure TForm1.SendSmartMessage(SM: TSmartMessage; aDestAddress: Word);
var
I: Integer;
NBS: TSMSProtocol2;
SMS: TSMSSubmit;
begin
SMS:= TSMSSubmit.Create;
try
SMS.GSM:= GSM1;
SMS.DA:= DestAddress; // destination address
if SM.InheritsFrom(TSMMIMEDirectory) then
begin
SMS.DCS:= 0; // default message class
NBS:= TNBS.Create // vCard and vCalendar
end
else
begin
SMS.DCS:= $F5; // binary message, class 1, ME
SMS.UDHI:= True; // user data header indicator
NBS:= TUDHProtocol.Create;
end;
try
NBS.Options:= [smspoAddressing, smspoReference];
NBS.DestinationAddress:= aDestAddress; // set port address
NBS.SourceAddress:= NBS.DestinationAddress;
NBS.Data:= SM.Data; // feed binary data
NBS.Reference:= fReference mod 256; // unique identifier
Inc(fReference); // every message has unique identifier
for I:= 1 to NBS.FragmentCount do // send particular messages
begin
SMS.UD:= NBS.Fragments[I];
GSM1.SendSMS(SMS); // send message
end;
finally
NBS.Free;
end;
finally
SMS.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
SM: TSMvCard;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -