?? gsmctrfr.pas
字號:
unit GSMCtrFr;
interface
uses
{$IFDEF LINUX}Qt, {$ENDIF}SysUtils, Connect, CommConnect, QControls, QExtCtrls, QComCtrls, QForms,
QStdCtrls, Terminal, Classes, {$IFDEF LINUX} Libc, Types, GSM, XSMS, Wap, QDialogs,
QImgList, QButtons, AuxGSM, dm_GSM, QGrids, QGraphics{$ELSE}Windows, Messages{$ENDIF};
const
glRed = 1;
glGreen = 3;
glYellow = 5;
glNone = 0;
type
TGSMCentralForm = class(TForm)
ImageList: TImageList;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
Panel2: TPanel;
GroupBox2: TGroupBox;
IndNetRegStatus: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
Panel1: TPanel;
Panel6: TPanel;
StatusBar: TStatusBar;
Semafor: TSpeedButton;
SpeedButton1: TSpeedButton;
TabSheet5: TTabSheet;
Panel7: TPanel;
TabSheet6: TTabSheet;
TabSheet7: TTabSheet;
Panel8: TPanel;
Panel9: TPanel;
ModemLog: TTerminal;
SMSLog: TTerminal;
Label1: TLabel;
DA: TEdit;
Label2: TLabel;
Message: TEdit;
BitBtn1: TBitBtn;
AutoShowModemLog: TCheckBox;
ConfigureGroupbox: TGroupBox;
SCAEdit: TEdit;
PinEdit: TEdit;
PINLabel: TLabel;
SCALabel: TLabel;
ModemComboBox: TComboBox;
ModemLabel: TLabel;
SMSLOGCheckBox: TCheckBox;
GSMLOGCheckBox: TCheckBox;
SMSLogButton: TButton;
GSMLogButton: TButton;
SMSLogSaveDialog: TSaveDialog;
GSMLogSaveDialog: TSaveDialog;
Label3: TLabel;
SMSFormat: TComboBox;
GroupBox1: TGroupBox;
CatchSMSMT: TCheckBox;
CatchSMSCB: TCheckBox;
CatchSMSDS: TCheckBox;
OnlyIndication: TCheckBox;
ManufacturerId: TMemo;
DeviceNameEdit: TEdit;
DeliveryNotification: TCheckBox;
DCS: TComboBox;
SMSKind: TComboBox;
Label4: TLabel;
Label5: TLabel;
SMSKind2: TComboBox;
PictureGB: TGroupBox;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
PictureWidth: TEdit;
PictureHeight: TEdit;
PictureNumAnimations: TEdit;
ScrollBox1: TScrollBox;
Picture: TPaintBox;
Label9: TLabel;
PictureOperator: TComboBox;
vCardGB: TGroupBox;
Label10: TLabel;
Label11: TLabel;
vCardName: TEdit;
vCardPhone: TEdit;
Blink: TButton;
Button2: TButton;
Button3: TButton;
SavePictureDialog: TSaveDialog;
OpenPictureDialog: TOpenDialog;
MelodyGB: TGroupBox;
Label12: TLabel;
MelodyName: TEdit;
MelodyKeyboard: TPaintBox;
Button1: TButton;
Button4: TButton;
MelodyGrid: TStringGrid;
MelodyNote: TComboBox;
MelodyDuration: TComboBox;
MelodyDuration2: TComboBox;
MelodyScale: TComboBox;
MelodyStyle: TComboBox;
MelodyTempo: TComboBox;
MelodyVolume: TComboBox;
MelodyInsert: TCheckBox;
Button5: TButton;
Button6: TButton;
SaveMelodyDialog: TSaveDialog;
OpenMelodyDialog: TOpenDialog;
procedure FormCreate(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure IndNetRegStatusClick(Sender: TObject);
procedure StatusBarClick(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ModemLogKeyPress(Sender: TObject; var Key: Char);
procedure BitBtn1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure SMSLOGCheckBoxClick(Sender: TObject);
procedure SMSLogButtonClick(Sender: TObject);
procedure GSMLogButtonClick(Sender: TObject);
procedure GSMLOGCheckBoxClick(Sender: TObject);
procedure SMSKindChange(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PicturePaint(Sender: TObject);
procedure PictureWidthExit(Sender: TObject);
procedure PictureWidthKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure PictureMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure BlinkClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure MelodyKeyboardPaint(Sender: TObject);
procedure MelodyKeyboardMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure MelodyKeyboardMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure MelodyGridDblClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
FSaveActivePage: TTabSheet;
FLastSMSKind, FLastSMSKind2: Integer;
FSMSKindLock: Byte;
FSmartMessage: TSmartMessageClass;
FEMS: TEMSObjectClass;
fPictureBitmap: TBitmap;
fReference: Integer;
fMelodyKeyPressTick: Longint;
fMelodyKeyPressed: Integer;
fMelodyArray: array[0..6] of TComboBox;
procedure CheckGSMActive;
procedure cmNetRegistrationChanged(var Msg: TCMNotifyMessage); message cm_NetRegistrationChanged;
procedure cmModemStatusChanged(var Msg: TCMNotifyMessage); message cm_ModemStatusChanged;
procedure SendSMSPhn(aDA, S: string; aDeliveryNotification: Boolean; aDCS: Byte; aUDH, aNoConv, aUnicode: Boolean);
function GetGlyphNum(aGlyph: Byte; aOnOff: Boolean): Integer;
procedure StatusLineOnHint(Sender: TObject);
procedure ShowModemLog;
procedure HideModemLog;
procedure GetConfiguration;
procedure SetConfiguration;
procedure AdjustSMSKind;
procedure AdjustPicture;
procedure GetKeyRect(aScale: Byte; aNote: Byte; var R: TRect; var Keyis: Boolean);
procedure MelodySetFromGrid;
procedure SMRingingToneFromGrid(SM: TSMRingingTone);
public
{ Public declarations }
end;
var
GSMCentralForm: TGSMCentralForm;
implementation
uses
AuxStr, IniFiles, CmdLine, Math;
resourcestring
sModemNotActive = 'Device is not active';
{$R *.dfm}
const
SendPrefix = '+:';
MaxSMSLength = 160;
CaptionStr = 'GSM Central [%s]';
procedure TGSMCentralForm.FormCreate(Sender: TObject);
var
i: TGSMEquipment;
J: Integer;
S: string;
resourcestring
sMelodyTitles = 'Scale;Note;Dur;Dur2;Tempo;Style;Vol.;';
const
MelodyDef: array[0..6] of Integer = (smrtiScaleDefault, 0, 0, 0, smrtiTempoDefault, smrtiStyleDefault, smrtiVolumeDefault);
begin
GSMDataModule.ModemLog:= ModemLog;
GSMDataModule.SMSLog:= SMSLog;
PageControl1.ActivePage:= TabSheet1;
Semafor.Align:= alClient;
Caption:= Format(CaptionStr, [GSMEquipmentLongName[GSMDataModule.GSM.Equipment]]);
ImageList.GetBitmap(GetGlyphNum(glNone, False), IndNetRegStatus.Glyph);
ImageList.GetBitmap(GetGlyphNum(glNone, False), Semafor.Glyph);
for i:=Low(TGSMEquipment) to High(TGSMEquipment) do
ModemComboBox.Items.Add(GSMEquipmentLongName[i]);
// GSMDataModule.Comm1.Open;
Application.OnHint:= StatusLineOnHint;
DCS.ItemIndex:= 2;
fPictureBitmap:= TBitmap.Create;
{$IFNDEF LINUX} // some problem when setting Pixels[x,y]
fPictureBitmap.Monochrome:= True;
{$ENDIF}
MelodyGrid.ColCount:= High(fMelodyArray)-Low(fMelodyArray)+1;
fMelodyArray[0]:= MelodyScale;
fMelodyArray[1]:= MelodyNote;
fMelodyArray[2]:= MelodyDuration;
fMelodyArray[3]:= MelodyDuration2;
fMelodyArray[4]:= MelodyTempo;
fMelodyArray[5]:= MelodyStyle;
fMelodyArray[6]:= MelodyVolume;
S:= sMelodyTitles;
for J:= Low(fMelodyArray) to High(fMelodyArray) do
begin
MelodyGrid.ColWidths[J]:= fMelodyArray[J].Width;
MelodyGrid.Cells[J, 0]:= Copy(S, 1, Pos(';', S)-1);
Delete(S, 1, Pos(';', S));
MelodyGrid.Objects[J, 0]:= Pointer(MelodyDef[J]);
end;
MelodySetFromGrid;
end;
function TGSMCentralForm.GetGlyphNum;
begin
Result:= aGlyph;
Inc(Result, Byte((aGlyph > 0) and aOnOff));
end;
procedure TGSMCentralForm.CheckGSMActive;
begin
if not GSMDataModule.Active then
GSMError(sModemNotActive);
end;
procedure TGSMCentralForm.SendSMSPhn;
var
aSMS: TSMSSubmit;
resourcestring
sDeviceNotActive = 'Device not active. Connect?';
begin
if not GSMDataModule.Active then
begin
if MessageDlg(sDeviceNotActive, mtConfirmation, [mbYes, mbNo], 0) <> mrYes then
Abort;
SetConfiguration;
GSMDataModule.GSM.Open;
end;
CheckGSMActive;
aSMS:= TSMSSubmit.Create;
try
aSMS.GSM:= GSMDataModule.GSM;
aSMS.DA:= aDA;
if not aNoConv then
S:= ISOtoSMS(S);
if aUnicode then
aSMS.WideUD:= Copy(S,1,70)
else
aSMS.UD:= Copy(S,1,MaxSMSLength);
aSMS.DCS:= aDCS;
aSMS.SRR:= aDeliveryNotification;
aSMS.UDHI:= aUDH;
GSMDataModule.SendSMS(aSMS);
GSMDataModule.LogSMS(aSMS);
finally
aSMS.Free;
end;
end;
procedure TGSMCentralForm.cmNetRegistrationChanged;
var
Col: Byte;
begin
case Msg.wParam of
1: Col:= glGreen;
2: Col:= glYellow;
else
Col:= glRed;
end;
IndNetRegStatus.Glyph:= nil;
ImageList.GetBitmap(GetGlyphNum(Col, True), IndNetRegStatus.Glyph);
end;
procedure TGSMCentralForm.cmModemStatusChanged;
var
Col: Byte;
i: Integer;
begin
for i:=0 to ConfigureGroupBox.ControlCount-1 do
ConfigureGroupBox.Controls[i].Enabled := not GSMDataModule.GSM.Active;
with SMSLogCheckBox do
SMSLogButton.Enabled := Enabled and Checked;
with GSMLogCheckBox do
GSMLogButton.Enabled := Enabled and Checked;
case Msg.wParam and $7F of
0: Col:= glRed;
1:
begin
Col:= glGreen;
with GSMDataModule do
if (Msg.wParam and $80 <> 0) and GSM.Active then
begin
ManufacturerId.Lines.Text:= Format('%s/%s'#13#10'%s'#13#10'S/N: %s', [GSM.ManufacturerId, GSM.ModelId, GSM.RevisionId, GSM.SerialNumberId]);
end;
end;
else
Col:= glNone;
end;
Semafor.Glyph:= nil;
ImageList.GetBitmap(GetGlyphNum(Col, True), Semafor.Glyph);
Application.ProcessMessages;
end;
procedure TGSMCentralForm.SpeedButton3Click(Sender: TObject);
var MakeActive: Boolean;
begin
ShowModemLog;
try
MakeActive:=Boolean((Sender as TControl).Tag);
if MakeActive then
begin
GSMDataModule.GSM.ComDevice.Close;
SetConfiguration;
end;
GSMDataModule.Active:=MakeActive;
finally
HideModemLog;
end;
end;
procedure TGSMCentralForm.IndNetRegStatusClick(Sender: TObject);
var
Sg: TStrings;
I: Integer;
begin
CheckGSMActive;
with GSMDataModule do
begin
Sg:= TStringList.Create;
try
if GSM.SendATCommand('AT+CSQ', atrCode+atrParams+atrATResponse, Sg) = 0 then
begin
I:= 1;
I:= StrToNum(ExtractParam(Sg[0], I));
if I = 99 then begin
IndNetRegStatus.Caption:= '?';
I:= 0;
end
else IndNetRegStatus.Caption:= Format('%d dBm', [2*I + (-113)]);
end;
finally
Sg.Free;
end;
end;
end;
procedure TGSMCentralForm.StatusLineOnHint;
begin
StatusBar.SimpleText:= GetLongHint(Application.Hint);
end;
procedure TGSMCentralForm.StatusBarClick(Sender: TObject);
begin
with StatusBar do
SimpleText:= GetShortHint(Hint);
end;
procedure TGSMCentralForm.SpeedButton1Click(Sender: TObject);
begin
ShowModemLog;
try
GSMDataModule.GSM.SwitchOff;
finally
HideModemLog;
end;
end;
procedure TGSMCentralForm.FormShow(Sender: TObject);
begin
GetConfiguration;
fLastSMSKind:= -MaxInt;
SMSKind.ItemIndex:= 0;
AdjustSMSKind;
if IsThereCmd('START', clUpcase) then
SpeedButton3Click(SpeedButton3);
StatusBarClick(nil);
end;
procedure TGSMCentralForm.ModemLogKeyPress(Sender: TObject; var Key: Char);
begin
if not GSMDataModule.GSM.Active then
GSMDataModule.GSM.COMDevice.Close;
GSMDataModule.GSM.COMDevice.Open;
GSMDataModule.GSM.COMDevice.Send(Key);
Key:= #0;
end;
procedure TGSMCentralForm.ShowModemLog;
begin
if AutoShowModemLog.Checked then
begin
FSaveActivePage:= PageControl1.ActivePage;
PageControl1.ActivePage:= TabSheet7;
Application.ProcessMessages;
end;
end;
procedure TGSMCentralForm.HideModemLog;
begin
if AutoShowModemLog.Checked then
begin
PageControl1.ActivePage:= FSaveActivePage;
end;
end;
procedure TGSMCentralForm.GetConfiguration;
begin
with GSMDataModule,GSM do
begin
ModemComboBox.ItemIndex := Ord(Equipment);
SCAEdit.Text := SCA;
PINEdit.Text := PIN;
Self.SMSFormat.ItemIndex := SMSFormat;
CatchSMSMT.Checked := uindSMSDeliver in UnsolicitedIndication;
CatchSMSCB.Checked := uindCellBroadcast in UnsolicitedIndication;
CatchSMSDS.Checked := uindSMSStatusReport in UnsolicitedIndication;
OnlyIndication.Checked := uindOnlyIndication in UnsolicitedIndication;
DeviceNameEdit.Text:= ComDevice.DeviceName;
SMSLogCheckBox.Checked := SMSLogFile <> NO_LOG_FILE;
GSMLogCheckBox.Checked := GSMLogFile <> NO_LOG_FILE;
SMSLogSaveDialog.FileName := SMSLogFile;
GSMLogSaveDialog.FileName := GSMLogFile;
end;
end;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -