Imported gammu 0.90.7
[gammu.git] / win32 / delphi7.gui / gammu.pas
blobcf525d36f06fc936883df83c8409c8ea44ed7362
1 unit Gammu;
3 interface
5 uses Classes,Forms,SysUtils;
7 const GSM_MAX_SMSC_NAME_LENGTH = 30;
8 GSM_MAX_SMS_NAME_LENGTH = 40;
9 GSM_MAX_NUMBER_LENGTH = 50;
11 GSM_MAX_UDH_LENGTH = 140;
12 GSM_MAX_SMS_LENGTH = 160;
13 GSM_MAX_8BIT_SMS_LENGTH = 140;
15 MAX_MULTI_SMS = 10;
17 {$MINENUMSIZE 4}
19 type GSM_NetworkInfo_State = (
20 GSM_HomeNetwork = 1, //phone logged into home network
21 GSM_RoamingNetwork, //phone logged into other than home network
22 GSM_RequestingNetwork, //phone tries to log into network
23 GSM_NoNetwork); //no network found
25 GSM_NetworkInfo = record
26 NetworkName : array[1..30] of char; // network name showed in some phones on display
27 State : GSM_NetworkInfo_State; // network state
28 NetworkCode : array[1..10] of char; // GSM network code
29 CellID : array[1..10] of char; // CellID
30 LAC : array[1..10] of char; // LAC
31 end;
32 PGSM_NetworkInfo = ^GSM_NetworkInfo;
34 type GSM_Error = (
35 GE_NONE = 1,
36 GE_DEVICEOPENERROR, // Error during opening device
37 GE_DEVICELOCKED,
38 GE_DEVICENOTEXIST,
39 GE_DEVICEBUSY,
40 GE_DEVICENOPERMISSION,
41 GE_DEVICENODRIVER,
42 GE_DEVICENOTWORK,
43 GE_DEVICEDTRRTSERROR, // Error during setting DTR/RTS in device
44 GE_DEVICECHANGESPEEDERROR, // Error during changing speed in device
45 GE_DEVICEWRITEERROR, // Error during writing device
46 GE_DEVICEREADERROR, // Error during reading device
47 GE_DEVICEPARITYERROR, // Can't set parity on device
48 GE_TIMEOUT, // Command timed out
49 GE_FRAMENOTREQUESTED, // Frame handled, but not requested in this moment //10
50 GE_UNKNOWNRESPONSE, // Response not handled by gammu
51 GE_UNKNOWNFRAME, // Frame not handled by gammu
52 GE_UNKNOWNCONNECTIONTYPESTRING, // Unknown connection type given by user
53 GE_UNKNOWNMODELSTRING, // Unknown model given by user
54 GE_SOURCENOTAVAILABLE, // Some functions not compiled in your OS
55 GE_NOTSUPPORTED, // Not supported by phone
56 GE_EMPTY, // Empty phonebook entry, ...
57 GE_SECURITYERROR, // Not allowed
58 GE_INVALIDLOCATION, // Too high or too low location...
59 GE_NOTIMPLEMENTED, // Function not implemented //20
60 GE_FULL, // Memory is full
61 GE_UNKNOWN,
62 GE_CANTOPENFILE, // Error during opening file
63 GE_MOREMEMORY, // More memory required
64 GE_PERMISSION, // No permission
65 GE_EMPTYSMSC, // SMSC number is empty
66 GE_INSIDEPHONEMENU, // Inside phone menu - can't make something
67 GE_NOTCONNECTED, // Phone NOT connected - can't make something
68 GE_WORKINPROGRESS, // Work in progress
69 GE_PHONEOFF, // Phone is disabled and connected to charger //30
70 GE_FILENOTSUPPORTED, // File format not supported by Gammu
71 GE_BUG, // Found bug in implementation or phone //32
72 GE_CANCELED,
73 GE_NEEDANOTHERANSWER,
74 GE_OTHERCONNECTIONREQUIRED,
75 GE_WRONGCRC);
77 GSM_DateTime = record
78 Year : integer; //full year (for example,2002)
79 Month : integer;
80 Day : integer;
81 Hour : integer;
82 Minute : integer;
83 Second : integer;
84 Timezone : integer;
85 end;
86 PGSM_DateTime = ^GSM_DateTime;
88 GSM_ValidityPeriodFormat = (
89 GSM_NoValidityPeriod = 1, //sms doesn't have validity info
90 GSM_RelativeFormat); //sms has relative validity (starting from the sending moment). Example, one day, one week, 1 hour
92 // Validity of SMS Messages.
93 GSM_ValidityPeriod = (
94 GSMV_1_Hour = 11,
95 GSMV_6_Hours = 71,
96 GSMV_24_Hours = 167,
97 GSMV_72_Hours = 169,
98 GSMV_1_Week = 173,
99 GSMV_Max_Time = 255);
101 GSM_SMSValidity = record
102 VPF : GSM_ValidityPeriodFormat; //type of sms validity
103 Relative : GSM_ValidityPeriod; //how long is validity. example: 1 week or 3 days
104 end;
106 // SMS Messages sent as...
107 GSM_SMSFormat = (
108 GSMF_Pager = 1,
109 GSMF_Fax,
110 GSMF_Email,
111 GSMF_Text); //sms sent as normal text
113 // Define datatype for SMS Message Center
114 GSM_SMSC = record
115 Location : integer; // Number of the SMSC in the phone memory.
116 Name : array[1..(GSM_MAX_SMSC_NAME_LENGTH+1)*2] of char; // Name of the SMSC.
117 Format : GSM_SMSFormat; // SMS is sent as text/fax/paging/email.
118 Validity : GSM_SMSValidity; // Validity of SMS Message.
119 Number : array[1..(GSM_MAX_NUMBER_LENGTH+1)*2] of char; // Number of the SMSC.
120 DefaultNumber : array[1..(GSM_MAX_NUMBER_LENGTH+1)*2] of char; // Number of default recipient
121 end;
123 // types of UDH (User Data Header)
124 GSM_UDH = (
125 UDH_NoUDH = 1, //no user header. SMS has only "normal" text
126 UDH_ConcatenatedMessages,
127 UDH_ConcatenatedMessages16Bit,
128 UDH_DisableVoice,
129 UDH_DisableFax,
130 UDH_DisableEmail,
131 UDH_EnableVoice,
132 UDH_EnableFax,
133 UDH_EnableEmail,
134 UDH_VoidSMS,
135 UDH_NokiaRingtone,
136 UDH_NokiaRingtoneLong,
137 UDH_NokiaOperatorLogo,
138 UDH_NokiaOperatorLogoLong,
139 UDH_NokiaCallerLogo,
140 UDH_NokiaWAP,
141 UDH_NokiaWAPLong,
142 UDH_NokiaCalendarLong,
143 UDH_NokiaProfileLong,
144 UDH_NokiaPhonebookLong,
145 UDH_UserUDH, // Other user UDH
146 UDH_MMSIndicatorLong);
148 // Structure to hold UDH Header
149 GSM_UDHHeader = record
150 UDHType : GSM_UDH; //Type
151 Length : integer; //Length
152 Text : array[1..GSM_MAX_UDH_LENGTH] of char; // Text
153 ID8Bit : integer;
154 ID16Bit : integer;
155 PartNumber : integer;
156 AllParts : integer;
157 end;
159 GSM_SMS_State = (
160 GSM_Sent = 1, //for outbox sms - sent
161 GSM_UnSent, //for outbox sms - unsent
162 GSM_Read, //for inbox sms - read
163 GSM_UnRead); //for inbox sms - unread
165 GSM_Coding_Type = (
166 GSM_Coding_Unicode = 1, // 70 Unicode chars
167 GSM_Coding_Default, // 160 chars from Default GSM alphabet
168 GSM_Coding_8bit); // 140 8 bit chars
170 GSM_SMSMessageType = (
171 SMS_Deliver = 1, // when we save SMS in Inbox
172 SMS_Status_Report, // Delivery Report received by phone
173 SMS_Submit); // when we send SMS or save it in Outbox
175 GSM_SMSMessage = record
176 SMSC : GSM_SMSC; // Message center
177 UDH : GSM_UDHHeader; // User Data Header
178 Folder : integer; // Inbox or Outbox message
179 InboxFolder : LongBool; // true, when sms is from inbox
180 Memory : integer;
181 Location : integer; // location of sms in sim memory (for example)
182 Length : integer; // Length of the SMS message.
183 // for 8 bit sms number of 8 bit chars
184 Name : array[1..(GSM_MAX_SMS_NAME_LENGTH+1)*2] of char; // Name in Nokia 6210/7110, etc. Ignored in other
185 Number : array[1..(GSM_MAX_NUMBER_LENGTH+1)*2] of char; // Sender or recipient number
186 Text : array[1..(GSM_MAX_SMS_LENGTH+1)*2] of char; // Text for SMS
187 PDU : GSM_SMSMessageType; // Type of message
188 Coding : GSM_Coding_Type; // Type of coding
189 DateTime : GSM_DateTime; // Date of reception/response of messages.
190 SMSCTime : GSM_DateTime; // Date of SMSC response if DeliveryReport messages.
191 DeliveryStatus : char; // In delivery reports: status
192 ReplyViaSameSMSC : LongBool; // Indicates whether "Reply via same center" is set
193 State : GSM_SMS_State; // Read, UnRead, etc.
194 SMSClass : shortint; // SMS class. Normally -1.
195 MessageReference : char; // SMS Reference Number in SMS_Submit. 0, when don't used
196 ReplaceMessage : char; // 0, when don't use this feature. 1 - 7 set SMS ID
197 RejectDuplicates : LongBool; // true, if set this flag. Normally false
198 end;
199 PGSM_SMSMessage = ^GSM_SMSMessage;
201 GSM_MultiSMSMessage = record
202 Number : char; //how many sms we have in collection now
203 SMS : array[1..MAX_MULTI_SMS] of GSM_SMSMessage;
204 end;
205 PGSM_MultiSMSMessage = ^GSM_MultiSMSMessage;
207 GSM_SMSMemoryStatus = record
208 SIMUnRead : integer; //unread sms on sim
209 SIMUsed : integer; //all used (including unread) locations on sim
210 SIMSize : integer; //size of sim memory
211 PhoneUnRead : integer;
212 PhoneUsed : integer;
213 PhoneSize : integer;
214 TemplatesUsed : integer;
215 end;
216 PGSM_SMSMemoryStatus = ^GSM_SMSMemoryStatus;
218 GSM_SecurityCodeType = (
219 GSCT_UNKNOWN,
220 GSCT_SecurityCode, // Security code.
221 GSCT_Pin, // PIN.
222 GSCT_Pin2, // PIN 2.
223 GSCT_Puk, // PUK.
224 GSCT_Puk2, // PUK 2.
225 GSCT_None); // Code not needed.
227 GSM_SecurityCode = record
228 CodeType : GSM_SecurityCodeType; //type of code
229 Code : array[1..10] of char; //code (without unicode !)
230 end;
231 PGSM_SecurityCode = ^GSM_SecurityCode;
233 type
234 //callback, which is called, when phone is connected or disconnected
235 PhoneCallBackProc = procedure(x:integer;ID:integer;connected:LongBool);stdcall;
236 PPhoneCallBackProc = ^PhoneCallBackProc;
237 //this definition is used, when call back is defined under Class
238 PhoneCallBackProcClass = procedure(ID:integer;connected:LongBool);stdcall;
239 PPhoneCallBackProcClass = ^PhoneCallBackProcClass;
241 //called, when phone needs PIN, PUK, etc.
242 SecurityCallBackProc = procedure(x:integer;ID:integer;SecurityState:GSM_SecurityCodeType);stdcall;
243 PSecurityCallBackProc = ^SecurityCallBackProc;
244 //this definition is used, when call back is defined under Class
245 SecurityCallBackProcClass = procedure(ID:integer;SecurityState:GSM_SecurityCodeType);stdcall;
246 PSecurityCallBackProcClass = ^SecurityCallBackProcClass;
248 //called, when there are ANY SMS on sim
249 SMSCallBackProc = procedure(x:integer;ID:integer);stdcall;
250 PSMSCallBackProc = ^SMSCallBackProc;
251 //this definition is used, when call back is defined under Class
252 SMSCallBackProcClass = procedure(ID:integer);stdcall;
253 PSMSCallBackProcClass = ^SMSCallBackProcClass;
255 function GSM_StartConnection (Phone : Pinteger; Device: PChar;Connection: PChar; Model : PChar; LogFile: PChar; LogFileType: PChar; CallBack1 : PPhoneCallBackProc; CallBack2: PSecurityCallBackProc; CallBack3: PSMSCallBackProc): GSM_Error; stdcall; external 'gammu.dll' name 'mystartconnection';
256 function GSM_StartConnectionClass (Phone : Pinteger; Device: PChar;Connection: PChar; Model : PChar; LogFile: PChar; LogFileType: PChar; CallBack1 : PPhoneCallBackProcClass; CallBack2: PSecurityCallBackProcClass; CallBack3: PSMSCallBackProcClass): GSM_Error; stdcall; external 'gammu.dll' name 'mystartconnection';
257 function GSM_EndConnection (Phone : integer): GSM_Error; stdcall; external 'gammu.dll' name 'myendconnection';
258 function GSM_GetNetworkInfo (Phone : integer; NetworkInfo : PGSM_NetworkInfo): GSM_Error; stdcall; external 'gammu.dll' name 'mygetnetworkinfo';
259 function GSM_GetSMSStatus (Phone : integer; status : PGSM_SMSMemoryStatus): GSM_Error; stdcall; external 'gammu.dll' name 'mygetsmsstatus';
260 function GSM_GetNextSMSMessage (Phone : integer; SMS : PGSM_MultiSMSMessage;start : LongBool): GSM_Error; stdcall; external 'gammu.dll' name 'mygetnextsmsmessage';
261 function GSM_DeleteSMSMessage (Phone : integer; SMS : PGSM_SMSMessage): GSM_Error; stdcall; external 'gammu.dll' name 'mydeletesmsmessage';
262 function GSM_SendSMSMessage (Phone : integer; SMS : PGSM_SMSMessage;timeout:integer): GSM_Error; stdcall; external 'gammu.dll' name 'mysendsmsmessage';
263 function GSM_AddSMSMessage (Phone : integer; SMS : PGSM_SMSMessage): GSM_Error; stdcall; external 'gammu.dll' name 'myaddsmsmessage';
264 function GSM_EnterSecurityCode (Phone : integer; Code : PGSM_SecurityCode): GSM_Error; stdcall ; external 'gammu.dll' name 'myentersecuritycode';
265 function GSM_GetIMEI (Phone : integer; IMEI:PAnsiString): GSM_Error; stdcall; external 'gammu.dll' name 'mygetimei';
266 function GSM_GetDCT4SimlockNetwork (Phone : integer; Info:PAnsiString): GSM_Error; stdcall; external 'gammu.dll' name 'mygetdct4simlocknetwork';
267 function GSM_GetDCT4SecurityCode (Phone : integer; Code:PAnsiString): GSM_Error; stdcall; external 'gammu.dll' name 'mygetdct4securitycode';
268 function GSM_GetManufacturer (Phone : integer; IMEI:PAnsiString): GSM_Error; stdcall; external 'gammu.dll' name 'mygetmanufacturer';
269 function GSM_GetModel (Phone : integer; Model:PAnsiString): GSM_Error; stdcall; external 'gammu.dll' name 'mygetmodel';
270 function GSM_GetModelName (Phone : integer; Model:PAnsiString): GSM_Error; stdcall; external 'gammu.dll' name 'mygetmodelname';
271 function GSM_GetFirmwareVersion (Phone : integer; Version: PDouble): GSM_Error; stdcall; external 'gammu.dll' name 'mygetfirmwareversion';
272 function GSM_Reset (Phone : integer; Hard: LongBool): GSM_Error; stdcall; external 'gammu.dll' name 'myreset';
273 function GSM_SMSCounter (MessageLength:Integer;MessageBuffer:PAnsiString;UDH:GSM_UDH;Coding:GSM_Coding_Type;SMSNum:PInteger;CharsLeft:PInteger): GSM_Error; stdcall; external 'gammu.dll' name 'mysmscounter';
274 function GSM_MakeMultiPartSMS (MessageBuffer:PAnsiString;MessageLength:Integer;UDHType:GSM_UDH;Coding:GSM_Coding_Type;MyClass:Integer;ReplaceMessage:ShortInt;SMS:PGSM_MultiSMSMessage): GSM_Error; stdcall; external 'gammu.dll' name 'mymakemultipartsms';
275 function GSM_GetStructureSize (i: integer): integer; stdcall; external 'gammu.dll' name 'mygetstructuresize';
276 procedure GSM_GetNetworkName (NetworkCode: PAnsiString; NetworkName: PAnsiString); stdcall; external 'gammu.dll' name 'mygetnetworkname';
277 procedure GSM_GetGammuVersion (Version: PAnsiString); stdcall; external 'gammu.dll' name 'mygetgammuversion';
279 function GetGammuUnicodeString (Source : AnsiString):string;
281 type
282 TGammuGSMDevice = class(TObject)
283 private
284 fDeviceID : integer;
285 fDevice : PChar;
286 fConnection : PChar;
287 fUsed : Boolean;
288 fConnected : Boolean;
289 fPhoneCallBackPointer : PPhoneCallBackProcClass;
290 fSecurityCallBackPointer : PSecurityCallBackProcClass;
291 fSMSCallBackPointer : PSMSCallBackProcClass;
292 public
293 function StartConnection(DeviceString:String;ConnectionString:String;PhoneCallBack:PPhoneCallBackProcClass;SecurityCallBack:PSecurityCallBackProcClass;SMSCallBack:PSMSCallBackProcClass;LogFile:String;LogFormat:String):GSM_Error;
294 function EndConnection:GSM_Error;
295 constructor Create;
297 property Device : PChar read fDevice;
298 property DeviceID : integer read fDeviceID;
299 property Connection : PChar read fConnection;
300 property Used : Boolean read fUsed write fUsed;
301 property Connected : Boolean read fConnected write fConnected;
302 end;
304 implementation //here all private variables, stuff, etc.
306 constructor TGammuGSMDevice.Create;
307 begin
308 Connected := False;
309 Used := False;
310 inherited;
311 end;
313 function TGammuGSMDevice.EndConnection():GSM_Error;
314 begin
315 EndConnection:=GSM_EndConnection(fDeviceID);
316 end;
318 function TGammuGSMDevice.StartConnection(DeviceString:String;ConnectionString:String;PhoneCallBack:PPhoneCallBackProcClass;SecurityCallBack:PSecurityCallBackProcClass;SMSCallBack:PSMSCallBackProcClass;LogFile:String;LogFormat:String):GSM_Error;
319 begin
320 GetMem(fDevice,Length(DeviceString) + 1);
321 StrCopy(fDevice,PChar(DeviceString));
322 GetMem(fConnection,50);
323 StrCopy(fConnection,PChar(ConnectionString));
325 fPhoneCallBackPointer := PhoneCallBack;
326 fSecurityCallBackPointer := SecurityCallBack;
327 fSMSCallBackPointer := SMSCallback;
329 StartConnection:=GSM_StartConnection(@fDeviceID,fDevice,fConnection,'',PChar(LogFile),PChar(LogFormat),@fPhoneCallBackPointer,@fSecurityCallBackPointer,@fSMSCallBackPointer);
330 end;
332 function GetGammuUnicodeString(Source:AnsiString):string;
334 i : integer;
335 Dest : array[1..255] of Word;
336 begin
337 i := 1;
338 while ((Source[i*2-1]<>chr(0)) or (Source[i*2]<>chr(0))) do
339 begin
340 Dest[i] := ord(Source[i*2])*256+ord(Source[i*2-1]);
341 i := i + 1;
342 end;
343 Dest[i] := 0;
344 GetGammuUnicodeString := WideCharLenToString(@Dest,i-1);
345 end;
347 begin
348 if (GSM_GetStructureSize(0) <> sizeof(gsm_smsmessage)) then application.MessageBox('gsm_smsmessage','',0);
349 if (GSM_GetStructureSize(1) <> sizeof(gsm_smsc)) then application.MessageBox('gsm_smsc','',0);
350 if (GSM_GetStructureSize(2) <> sizeof(gsm_sms_state)) then application.MessageBox('gsm_sms_state','',0);
351 if (GSM_GetStructureSize(3) <> sizeof(gsm_UDHHeader)) then application.MessageBox('gsm_udhheader','',0);
352 if (GSM_GetStructureSize(4) <> sizeof(LongBool)) then application.MessageBox('bool','',0);
353 if (GSM_GetStructureSize(5) <> sizeof(gsm_datetime)) then application.MessageBox('gsm_datetime','',0);
354 if (GSM_GetStructureSize(6) <> sizeof(integer)) then application.MessageBox('int','',0);
355 if (GSM_GetStructureSize(7) <> sizeof(gsm_networkinfo)) then application.MessageBox('gsm_networinfo','',0);
356 if (GSM_GetStructureSize(8) <> sizeof(gsm_UDH)) then application.MessageBox('gsm_udhtype','',0);
357 end.