unit GSM;


{ Listing generated by Opus Documentor 1.2.1.1147 on 6.3.2004 }
{ Parts omitted from listing: private, undocumented }


{==============================================================================}
interface
uses
  Classes, Windows, Messages, Connect, CommConnect, SyncObjs;

type 

  TSMS = class
  protected
    function Get2Bits( 
        aVar: Byte; 
        Index: Integer ): Byte;
    procedure Set2Bits( 
        var aVar: Byte; 
        Index: Integer; 
        Value: Byte );
    function EncodePDU{}: TString; virtual; abstract;
    procedure DecodePDU( const Value: TString ); virtual; abstract;
  end {TSMS};

  TSMS2 = class( TSMS )
  public
    class function CreateSMS( 
        aOwner: TGSM; 
        const aPDU: TString; 
        aMTDir: Boolean ): TSMS2;
  end {TSMS2};

  TSMSDeliver = class( TSMS2 )
  end {TSMSDeliver};

  TSMSSubmit = class( TSMS2 )
  end {TSMSSubmit};

  TSMSStatusReport = class( TSMS2 )
  end {TSMSStatusReport};

  TSMSCommand = class( TSMS2 )
  end {TSMSCommand};

  TSMSDeliverReport = class( TSMS2 )
  end {TSMSDeliverReport};

  TSMSSubmitReport = class( TSMSDeliverReport )
  end {TSMSSubmitReport};

  TCellBroadcast = class( TSMS )
  end {TCellBroadcast};

  TGSMAsyncThread = class( TThread )
  end {TGSMAsyncThread};

  TGSM = class( TConnection )
  protected
    procedure OpenComDevice;
    procedure CloseComDevice( aRestore: Boolean );
    procedure ProcessRxLine( const aLine: TString ); virtual;
    function GetCMGLength( aSMS: TSMS2 ): Integer; virtual;
    function SCAinPDU{}: Boolean;
  public
    procedure SetDefaults;
    procedure Busy;
    procedure Unbusy;
    function SendATCommand( 
        const aCmd: TString; 
        aWaitFor: Byte; 
        aResultS: TStrings; 
        RepCount: Integer = 0 ): Integer;
    function CheckAT( aRes: Integer ): Integer;
    procedure SendSMS( aSMS: TSMS2 );
    function ReadSMS( 
        aIndex: Integer; 
        var Stat: Integer ): TSMS;
    procedure DeleteSMS( aIndex: Integer );
    function GetSMSList( aStat: Integer ): TStrings;
    procedure SwitchOff;
    function GetSupportedSMSFormats{}: TByteSet;
  public
    property IsBusy: Boolean read;
    property LastError: Integer read write;
    property LastErrorMsg: TString read write;
    property ErrorCodes: TStrings read write;
    property NetworkRegistration: Integer read;
    property mem1: TString read write;
    property ManufacturerId: TString read GetMEId;
    property ModelId: TString read GetMEId;
    property RevisionId: TString read GetMEId;
    property SerialNumberId: TString read GetMEId;
  published
    property Equipment: TGSMEquipment read write;
    property SMSFormat: Byte read write;
    property UnsolicitedIndication: TGSMUnsolicitedIndicationSet read write;
    property PIN: TString read write;
    property SCA: TString read write;
    property COMDevice: TComm read write;
    property CommandEcho: Boolean read write
        default True;
    property ExtendedErrorMsg: Boolean read write
        default False;
    property RepeatCount: Integer read write
        default 5;
    property RecTimeout: LongInt read write
        default 6000;
    property RepeatTimeout: LongInt read write
        default 500;
    property OnRxChar: TRxCharEvent read write;
    property OnUnsolicitedLine: TUnsolicitedLineEvent read write;
    property OnUnsolicitedSMS: TUnsolicitedSMSEvent read write;
    property OnNetworkRegistration: TNetworkRegistrationEvent read write;
    property OnBusyChanged: TBusyChanged read write;
  end {TGSM};

  EGSMError = class( EComError )
  end {EGSMError};

function DTToValPer( DT: TDateTime ): Byte;

function ValPerToDT( VP: Byte ): TDateTime;

function StripATResponse( const S: TString ): TString;

function IsATResponse( const S: TString ): Boolean;

function ExtractParam( 
    const S: TString; 
    var Pos: Integer ): TString;

function ExtractParamSet( 
    const S: TString; 
    var Pos: Integer ): TByteSet;

function TrimQuotes( const S: TString ): TString;

procedure GSMError( const Msg: string );

function ISOtoSMS( ISOstring: TString ): TString;

function SMStoISO( SMSstring: TString ): TString;

const 
  StatS: array[ 0 .. 4 ] of TString= 
    ( 'REC UNREAD'
    , 'REC READ'
    , 'STO UNSENT'
    , 'STO SENT'
    , 'ALL'
    );
  GSMEquipmentShortName: array[ TGSMEquipment ] of string= 
    ( 'A1'
    , 'M1'
    , 'M20'
    , 'GM12'
    , 'Nokia6210'
    , 'Nokia6650'
    , 'Nokia9110'
    , 'M35'
    , 'S25'
    , 'T260'
    , 'WaveCom'
    , 'TC35'
    , 'Fasttrack'
    );
  GSMEquipmentLongName: array[ TGSMEquipment ] of string= 
    ( 'Siemens A1'
    , 'Siemens M1'
    , 'Siemens M20'
    , 'Ericsson GM12'
    , 'Nokia 6210'
    , 'Nokia 6650'
    , 'Nokia 9110'
    , 'Siemens M35'
    , 'Siemens S25'
    , 'Motorola T260'
    , 'WaveCom'
    , 'Siemens TC35'
    , 'Wavecom Fasttrack'
    );

function Str2GMSEquipment( const S: TString ): TGSMEquipment;


{==============================================================================}
implementation
