Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit GrandstreamAPI;
- interface
- uses
- Windows, Classes, SysUtils, Vcl.Graphics,
- IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
- IdAllAuthentications;
- type
- TGrandstreamAPI = class;
- TGsParams = class;
- TGsRequestChannel = class;
- TGsRequestChannelBase = class;
- TGsRequestBase = class;
- //(1) Audio/VIdeo
- TGsAudioVideoChannel = class;
- TGsAudioVideo = class;
- //(2) OSD
- TGsOSDChannel = class;
- TGsOSD = class;
- //(3) Network
- TGsNetwork = class;
- //(4) DDNS
- TGsDynamicDNS = class;
- //(5) SIP
- TGsSIP = class;
- //(6) Date/Time
- TGsDateTime = class;
- //(7) Status
- TGsStatus = class;
- //(8) Accounts
- TGsAccounts = class;
- //(9) SMTP
- TGsSMTP = class;
- //(10) FTP
- TGsFTP = class;
- //(11) PTZ
- TGsPTZ = class;
- //(12) Alarm Events
- TGsAlarmEvent = class;
- //(13) Motion Detection
- TGsMotion = class;
- //(14) System Log
- TGsSyslog = class;
- //(15) Storage
- TGsStorage = class;
- //(16) Maintenance
- TGsMaintenance = class;
- //(17) Video Controls
- TGsVideoControl = class;
- //(18) WiFi
- TGsWiFi = class;
- //(19) Device Settings
- TGsDeviceChannel = class;
- TGsDevice = class;
- //(20) PPPoE
- TGsPPPoE = class;
- //(21) Snapshot
- TGsSnapshot = class;
- //(22) Language
- TGsLanguage = class;
- //(23) Decode
- TGsDecoding = class;
- //(24) Stream
- TGsStreaming = class;
- //(25) CMOS
- TGsCMOS = class;
- //(26) 4*D1 (Fourdone)
- TGsFourdone = class;
- //(27) Alarm Servers
- TGsAlarmServer = class;
- //(28) Recording
- TGsRecording = class;
- { Global }
- TGsRequestResult = (grOkay,grBadRequest,grUnauthorized,grNotFound,
- grServiceUnavailable);
- TGrandstreamAPI = class(TComponent)
- private
- FStream: TStringStream;
- FAddress: String;
- FPort: Integer;
- FPass: String;
- FUser: String;
- FWeb: TIdHTTP;
- FAudioVideo: TGsAudioVideo;
- FOSD: TGsOSD;
- FNetwork: TGsNetwork;
- FDynamicDNS: TGsDynamicDNS;
- FSIP: TGsSIP;
- FDateTime: TGsDateTime;
- FStatus: TGsStatus;
- FAccounts: TGsAccounts;
- FSMTP: TGsSMTP;
- FFTP: TGsFTP;
- FPTZ: TGsPTZ;
- FAlarmEvent: TGsAlarmEvent;
- FMotion: TGsMotion;
- FSyslog: TGsSyslog;
- FStorage: TGsStorage;
- FMaintenance: TGsMaintenance;
- FVideoControl: TGsVideoControl;
- FWiFi: TGsWiFi;
- FDevice: TGsDevice;
- FPPPoE: TGsPPPoE;
- FSnapshot: TGsSnapshot;
- FLanguage: TGsLanguage;
- FDecoding: TGsDecoding;
- FStreaming: TGsStreaming;
- FCMOS: TGsCMOS;
- FFourdone: TGsFourdone;
- FAlarmServer: TGsAlarmServer;
- FRecording: TGsRecording;
- function GetURL: String;
- procedure SetAddress(const Value: String);
- procedure SetPort(const Value: Integer);
- procedure SetPass(const Value: String);
- procedure SetUser(const Value: String);
- function Get(const Module: String): TGsRequestResult;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- property URL: String read GetURL;
- property AudioVideo: TGsAudioVideo read FAudioVideo;
- property OSD: TGsOSD read FOSD;
- property Network: TGsNetwork read FNetwork;
- property DynamicDNS: TGsDynamicDNS read FDynamicDNS;
- property SIP: TGsSIP read FSIP;
- property DateTime: TGsDateTime read FDateTime;
- property Status: TGsStatus read FStatus;
- property Accounts: TGsAccounts read FAccounts;
- property SMTP: TGsSMTP read FSMTP;
- property FTP: TGsFTP read FFTP;
- property PTZ: TGsPTZ read FPTZ;
- property AlarmEvent: TGsAlarmEvent read FAlarmEvent;
- property Motion: TGsMotion read FMotion;
- property Syslog: TGsSyslog read FSyslog;
- property Storage: TGsStorage read FStorage;
- property Maintenance: TGsMaintenance read FMaintenance;
- property VideoControl: TGsVideoControl read FVideoControl;
- property WiFi: TGsWiFi read FWiFi;
- property Device: TGsDevice read FDevice;
- property PPPoE: TGsPPPoE read FPPPoE;
- property Snapshot: TGsSnapshot read FSnapshot;
- property Language: TGsLanguage read FLanguage;
- property Decoding: TGsDecoding read FDecoding;
- property Streaming: TGsStreaming read FStreaming;
- property CMOS: TGsCMOS read FCMOS;
- property Fourdone: TGsFourdone read FFourdone;
- property AlarmServer: TGsAlarmServer read FAlarmServer;
- property Recording: TGsRecording read FRecording;
- published
- property Address: String read FAddress write SetAddress;
- property Port: Integer read FPort write SetPort;
- property User: String read FUser write SetUser;
- property Pass: String read FPass write SetPass;
- end;
- { Request Base Structures }
- TGsParams = class(TObject)
- private
- FItems: TStringList;
- function GetItem(const Name: String): String;
- procedure SetItem(const Name, Value: String);
- function GetName(const Index: Integer): String;
- public
- constructor Create;
- destructor Destroy; override;
- function Count: Integer;
- procedure Clear;
- property Items[const Name: String]: String read GetItem write SetItem; default;
- property Names[const Index: Integer]: String read GetName;
- end;
- TGsRequestBase = class(TObject)
- private
- FOwner: TGrandstreamAPI;
- FList: TStringList;
- FData: String;
- procedure Next;
- function Check(const V: String): Boolean;
- function ValInt: Integer;
- function ValStr: String;
- function ValBol: Boolean;
- public
- constructor Create(AOwner: TGrandstreamAPI); virtual;
- destructor Destroy; override;
- function Owner: TGrandstreamAPI;
- function Get(const Cmd: String): TGsRequestResult;
- function Items: TStringList;
- end;
- TGsRequestChannelClass = class of TGsRequestChannel;
- TGsRequestChannel = class(TObject)
- private
- FChannel: Integer;
- FOwner: TGsRequestChannelBase;
- public
- constructor Create(AOwner: TGsRequestChannelBase); virtual;
- destructor Destroy; override;
- property Owner: TGsRequestChannelBase read FOwner;
- property Channel: Integer read FChannel;
- end;
- TGsRequestChannelBase = class(TGsRequestBase)
- private
- FChannels: TList;
- FItemClass: TGsRequestChannelClass;
- function New: TGsRequestChannel;
- function GetChannel(Index: Integer): TGsRequestChannel;
- public
- constructor Create(AOwner: TGrandstreamAPI; const ItemClass: TGsRequestChannelClass); virtual;
- destructor Destroy; override;
- function Get(const Cmd: String): TGsRequestResult;
- function Count: Integer;
- procedure ClearChannels;
- property Channels[Index: Integer]: TGsRequestChannel read GetChannel; default;
- end;
- { ------------------------ BEGIN MODULE DEFINITIONS ------------------------ }
- { Audio/Video (1) }
- TGsVideoCodec = (gvcH264,gvcMJPEG);
- TGsBrType = (gvbVBR,gvbCBR);
- TGsAudioCodec = (gacPCMU,gacPCMA,gacG726,gacDisabled,gacAAC);
- TGsAudioChipType = (gctAIC33,gctAIC3104,gctNone);
- TGsNtscPalType = (gptPAL,gtpNTSC);
- TGsPowerFreq = (gpfIndoor50,gpfIndoor60,gpfOutdoor);
- TGsVideoResolution = class(TObject)
- private
- FLength: Integer;
- FWidth: Integer;
- procedure SetLength(const Value: Integer);
- procedure SetWidth(const Value: Integer);
- public
- property Width: Integer read FWidth write SetWidth;
- property Length: Integer read FLength write SetLength;
- end;
- TGsAudioVideoStream = class(TObject)
- private
- FVideoEncoder: TGsVideoCodec;
- FResolution: TGsVideoResolution;
- FVideoBitrate: Integer;
- FBrType: TGsBrType;
- FFramerate: Integer;
- FIFrame: Integer;
- FImageQuality: Integer;
- FAudioEncoder: TGsAudioCodec;
- FAudioBitrate: Integer;
- procedure SetAudioBitrate(const Value: Integer);
- procedure SetAudioEncoder(const Value: TGsAudioCodec);
- procedure SetBitrate(const Value: Integer);
- procedure SetBrType(const Value: TGsBrType);
- procedure SetFramerate(const Value: Integer);
- procedure SetIFrame(const Value: Integer);
- procedure SetImageQuality(const Value: Integer);
- procedure SetVideoEncoder(const Value: TGsVideoCodec);
- public
- constructor Create;
- destructor Destroy; override;
- property VideoEncoder: TGsVideoCodec read FVideoEncoder write SetVideoEncoder;
- property Resolution: TGsVideoResolution read FResolution;
- property VideoBitrate: Integer read FVideoBitrate write SetBitrate;
- property BrType: TGsBrType read FBrType write SetBrType;
- property Framerate: Integer read FFramerate write SetFramerate;
- property IFrame: Integer read FIFrame write SetIFrame;
- property ImageQuality: Integer read FImageQuality write SetImageQuality;
- property AudioEncoder: TGsAudioCodec read FAudioEncoder write SetAudioEncoder;
- property AudioBitrate: Integer read FAudioBitrate write SetAudioBitrate;
- end;
- TGsAudioVideoChannel = class(TGsRequestChannel)
- private
- FHasSecondary: Boolean;
- FPrimary: TGsAudioVideoStream;
- FSecondary: TGsAudioVideoStream;
- FMicrophoneVolume: Integer;
- FSpeakerVolume: Integer;
- FAudioLineIn: Boolean;
- FAudioLineOut: Boolean;
- FAudioChipType: TGsAudioChipType;
- FNtscPalType: TGsNtscPalType;
- FPowerFreq: TGsPowerFreq;
- procedure SetAudioChipType(const Value: TGsAudioChipType);
- procedure SetAudioLineIn(const Value: Boolean);
- procedure SetAudioLineOut(const Value: Boolean);
- procedure SetMicrophoneVolume(const Value: Integer);
- procedure SetNtscPalType(const Value: TGsNtscPalType);
- procedure SetPowerFreq(const Value: TGsPowerFreq);
- procedure SetSpeakerVolume(const Value: Integer);
- public
- constructor Create(AOwner: TGsRequestChannelBase); override;
- destructor Destroy; override;
- property HasSecondaryStream: Boolean read FHasSecondary;
- property Primary: TGsAudioVideoStream read FPrimary;
- property Secondary: TGsAudioVideoStream read FSecondary;
- property MicrophoneVolume: Integer read FMicrophoneVolume write SetMicrophoneVolume;
- property SpeakerVolume: Integer read FSpeakerVolume write SetSpeakerVolume;
- property AudioLineIn: Boolean read FAudioLineIn write SetAudioLineIn;
- property AudioLineOut: Boolean read FAudioLineOut write SetAudioLineOut;
- property AudioChipType: TGsAudioChipType read FAudioChipType write SetAudioChipType;
- property NtscPalType: TGsNtscPalType read FNtscPalType write SetNtscPalType;
- property PowerFreq: TGsPowerFreq read FPowerFreq write SetPowerFreq;
- end;
- TGsAudioVideo = class(TGsRequestChannelBase)
- private
- function GetChannel(Index: Integer): TGsAudioVideoChannel;
- function New: TGsAudioVideoChannel;
- public
- constructor Create(AOwner: TGrandstreamAPI);
- destructor Destroy; override;
- function Get: TGsRequestResult;
- property Channels[Index: Integer]: TGsAudioVideoChannel read GetChannel; default;
- end;
- { OSD (2) }
- TGsOSDPosition = (gopTop,gopBottom);
- TGsOSDOpacity = (goo0,goo10,goo20,goo30,goo40,goo50,goo60,goo70,goo80,goo90,goo100);
- TGsOSDColor = (gocAuto,gocWhite,gocRed,gocPurple,gocOrange,gocBlue,gocYellow,
- gocGreen,gocCyan,gocBlack);
- TGsOSDChannel = class(TGsRequestChannel)
- private
- FOSDPosition: TGsOSDPosition;
- FOSDText: String;
- FOSDOpacity: TGsOSDOpacity;
- FOSDTextIndex: Integer;
- FOSDColor: TGsOSDColor;
- FOSDTimeShow: Boolean;
- FOSDTextShow: Boolean;
- procedure SetOSDColor(const Value: TGsOSDColor);
- procedure SetOSDOpacity(const Value: TGsOSDOpacity);
- procedure SetOSDPosition(const Value: TGsOSDPosition);
- procedure SetOSDText(const Value: String);
- procedure SetOSDTextIndex(const Value: Integer);
- procedure SetOSDTextShow(const Value: Boolean);
- procedure SetOSDTimeShow(const Value: Boolean);
- function GetOSDColorStr: String;
- function GetOSDColorVal: TColor;
- function GetOSDOpacityStr: String;
- function GetOSDPositionStr: String;
- public
- constructor Create(AOwner: TGsRequestChannelBase); override;
- destructor Destroy; override;
- property OSDPosition: TGsOSDPosition read FOSDPosition write SetOSDPosition;
- property OSDTimeShow: Boolean read FOSDTimeShow write SetOSDTimeShow;
- property OSDTextShow: Boolean read FOSDTextShow write SetOSDTextShow;
- property OSDOpacity: TGsOSDOpacity read FOSDOpacity write SetOSDOpacity;
- property OSDColor: TGsOSDColor read FOSDColor write SetOSDColor;
- property OSDText: String read FOSDText write SetOSDText;
- property OSDTextIndex: Integer read FOSDTextIndex write SetOSDTextIndex;
- property OSDPositionStr: String read GetOSDPositionStr;
- property OSDOpacityStr: String read GetOSDOpacityStr;
- property OSDColorStr: String read GetOSDColorStr;
- property OSDColorVal: TColor read GetOSDColorVal;
- end;
- TGsOSD = class(TGsRequestChannelBase)
- private
- function GetChannel(Index: Integer): TGsOSDChannel;
- function New: TGsOSDChannel;
- public
- constructor Create(AOwner: TGrandstreamAPI);
- destructor Destroy; override;
- function Get: TGsRequestResult;
- property Channels[Index: Integer]: TGsOSDChannel read GetChannel; default;
- end;
- { Network (3) }
- TGsNetwork = class(TGsRequestBase)
- end;
- { Dynamic DNS (4) }
- TGsDynamicDNS = class(TGsRequestBase)
- end;
- { SIP (5) }
- TGsSIP = class(TGsRequestBase)
- end;
- { Date/Time (6) }
- TGsDateTime = class(TGsRequestBase)
- end;
- { System Info / Status (7) }
- TGsDDNSState = (gdsDisable,gdsProcessing,gdsSuccess,gdsAcctPassErr,
- gdsServerBlocking,gdsStunServerErr,gdsDBFailed);
- TGsWiFiState = (gwsDisconnected,gwsConnected);
- TGsLedStatus = (glsUnsupported,glsOn,glsOff);
- TGsPPPoEStatus = (gpsDisconnected,gpsConnected);
- TGsStatus = class(TGsRequestBase)
- private
- FProductMode: String;
- FDDNSState: TGsDDNSState;
- FPartNumber: String;
- FCoreVersion: String;
- FBootLoaderVersion: String;
- FFirmwareVersion: String;
- FBaseVersion: String;
- FHardwareVersion: String;
- FCameraType: String;
- FSystemRun: String;
- FPPPoEStatus: TGsPPPoEStatus;
- FLedStatus: TGsLedStatus;
- FWiFiState: TGsWiFiState;
- FPPPoEIP: String;
- FMac: String;
- FDefaultGateway: String;
- FSubnetMask: String;
- FIPAddress: String;
- public
- constructor Create(AOwner: TGrandstreamAPI); override;
- destructor Destroy; override;
- function Get: TGsRequestResult;
- function DDNSStateStr: String;
- function WiFiStateStr: String;
- function LedStatusStr: String;
- function PPPoEStatusStr: String;
- property ProductMode: String read FProductMode;
- property HardwareVersion: String read FHardwareVersion;
- property PartNumber: String read FPartNumber;
- property BootLoaderVersion: String read FBootLoaderVersion;
- property CoreVersion: String read FCoreVersion;
- property BaseVersion: String read FBaseVersion;
- property FirmwareVersion: String read FFirmwareVersion;
- property CameraType: String read FCameraType;
- property DDNSState: TGsDDNSState read FDDNSState;
- property WiFiState: TGsWiFiState read FWiFiState;
- property SystemRun: String read FSystemRun;
- property Mac: String read FMac;
- property LedStatus: TGsLedStatus read FLedStatus;
- property PPPoEIP: String read FPPPoEIP;
- property PPPoEStatus: TGsPPPoEStatus read FPPPoEStatus;
- property IPAddress: String read FIPAddress;
- property SubnetMask: String read FSubnetMask;
- property DefaultGateway: String read FDefaultGateway;
- end;
- { Account Management (8) }
- TGsAccounts = class(TGsRequestBase)
- end;
- { SMTP Email (9) }
- TGsSMTP = class(TGsRequestBase)
- end;
- { FTP (10) }
- TGsFTP = class(TGsRequestBase)
- end;
- { PTZ (11) }
- TGsPTZ = class(TGsRequestBase)
- end;
- { Alarm Event (12) }
- TGsAlarmEvent = class(TGsRequestBase)
- end;
- { Motion Detection (13) }
- TGsMotion = class(TGsRequestBase)
- end;
- { System Log (14) }
- TGsSyslog = class(TGsRequestBase)
- end;
- { Storage (15) }
- TGsStorage = class(TGsRequestBase)
- end;
- { Maintenance (16) }
- TGsUpdateVia = (guvTFTP,guvHTTP,guvHTTPS);
- TGsMaintenance = class(TGsRequestBase)
- private
- FUpdateVia: TGsUpdateVia;
- FUpgradeConfigServerPath: String;
- FUpgradeInterval: Integer;
- FUpgradeConfigXmlPassword: String;
- FUpgradeServerPath: String;
- FUpgradeAutomatic: Boolean;
- procedure SetUpdateVia(const Value: TGsUpdateVia);
- procedure SetUpgradeAutomatic(const Value: Boolean);
- procedure SetUpgradeConfigServerPath(const Value: String);
- procedure SetUpgradeConfigXmlPassword(const Value: String);
- procedure SetUpgradeInterval(const Value: Integer);
- procedure SetUpgradeServerPath(const Value: String);
- function GetUpdateViaStr: String;
- public
- constructor Create(AOwner: TGrandstreamAPI); override;
- destructor Destroy; override;
- function Get: TGsRequestResult;
- procedure Restart;
- procedure Restore;
- property UpdateVia: TGsUpdateVia read FUpdateVia write SetUpdateVia;
- property UpgradeServerPath: String read FUpgradeServerPath write SetUpgradeServerPath;
- property UpgradeConfigServerPath: String read FUpgradeConfigServerPath write SetUpgradeConfigServerPath;
- property UpgradeConfigXmlPassword: String read FUpgradeConfigXmlPassword write SetUpgradeConfigXmlPassword;
- property UpgradeAutomatic: Boolean read FUpgradeAutomatic write SetUpgradeAutomatic;
- property UpgradeInterval: Integer read FUpgradeInterval write SetUpgradeInterval;
- property UpdateViaStr: String read GetUpdateViaStr;
- end;
- { Video Control (17) }
- TGsVideoControl = class(TGsRequestBase)
- end;
- { WiFi (18) }
- TGsWiFi = class(TGsRequestBase)
- end;
- { System Settings / Device (19) }
- TGsAlarmType = (gatNormalOpen,gatNormalClose);
- TGsAlarmStatus = (gasOpen,gasClose);
- TGsAlarmOutputTime = (gao0,gao5,gao15,gao30,gao60,gao180,gao300,gao600,gao900,gao1800);
- TGsGpioPinMultiplex = (gpmNone,gpmControl,gpmAlarmIO);
- TGsDeviceChannel = class(TGsRequestChannel)
- private
- FChannel: Integer;
- FAlarmInType: TGsAlarmType;
- FAlarmOutType: TGsAlarmType;
- FAlarmInStatus: TGsAlarmStatus;
- FAlarmOutStatus: TGsAlarmStatus;
- FAlarmOutputTime: TGsAlarmOutputTime;
- FGpioPinMultiplex: TGsGpioPinMultiplex;
- procedure SetAlarmInType(const Value: TGsAlarmType);
- procedure SetAlarmOutputTime(const Value: TGsAlarmOutputTime);
- procedure SetAlarmOutType(const Value: TGsAlarmType);
- procedure SetGpioPinMultiplex(const Value: TGsGpioPinMultiplex);
- public
- constructor Create(AOwner: TGsRequestChannelBase); override;
- destructor Destroy; override;
- property Channel: Integer read FChannel;
- property AlarmInType: TGsAlarmType read FAlarmInType write SetAlarmInType;
- property AlarmOutType: TGsAlarmType read FAlarmOutType write SetAlarmOutType;
- property AlarmInStatus: TGsAlarmStatus read FAlarmInStatus;
- property AlarmOutStatus: TGsAlarmStatus read FAlarmOutStatus;
- property AlarmOutputTime: TGsAlarmOutputTime read FAlarmOutputTime write SetAlarmOutputTime;
- property GpioPinMultiplex: TGsGpioPinMultiplex read FGpioPinMultiplex write SetGpioPinMultiplex;
- end;
- TGsDevice = class(TGsRequestChannelBase)
- private
- FDeviceName: String;
- function New: TGsDeviceChannel;
- function GetChannel(Index: Integer): TGsDeviceChannel;
- procedure SetDeviceName(const Value: String);
- public
- constructor Create(AOwner: TGrandstreamAPI);
- destructor Destroy; override;
- function Get: TGsRequestResult;
- property Channels[Index: Integer]: TGsDeviceChannel read GetChannel; default;
- property DeviceName: String read FDeviceName write SetDeviceName;
- end;
- { PPPoE (20) }
- TGsPPPoE = class(TGsRequestBase)
- end;
- { Snapshot (21) }
- TGsSnapshot = class(TGsRequestBase)
- end;
- { Language (22) }
- TGsLanguage = class(TGsRequestBase)
- end;
- { Decoding (23) }
- TGsDecoding = class(TGsRequestBase)
- end;
- { Streaming (24) }
- TGsStreaming = class(TGsRequestBase)
- end;
- { CMOS (25) }
- TGsCMOS = class(TGsRequestBase)
- end;
- { 4*D1 (Fourdone) (26) }
- TGsFourdone = class(TGsRequestBase)
- end;
- { Alarm Server (27) }
- TGsAlarmServer = class(TGsRequestBase)
- end;
- { Recording (28) }
- TGsRecording = class(TGsRequestBase)
- end;
- implementation
- const
- CAMERA_URL = 'http://%s:%d/';
- // http://user:pass@address:port/
- function EncodeUrl(source: string): string;
- var i:integer;
- begin
- result := '';
- for i := 1 to length(source) do
- if not (source[i] in ['A'..'Z','a'..'z','0','1'..'9','-','_','~','.']) then result := result + '%'+inttohex(ord(source[i]),2) else result := result + source[i];
- end;
- function IntToResult(const R: Integer): TGsRequestResult;
- begin
- case R of
- 200: Result:= grOkay;
- 400: Result:= grBadRequest;
- 401: Result:= grUnauthorized;
- 404: Result:= grNotFound;
- 503: Result:= grServiceUnavailable;
- end;
- end;
- function ResultToInt(const R: TGsRequestResult): Integer;
- begin
- case R of
- grOkay: Result:= 200;
- grBadRequest: Result:= 400;
- grUnauthorized: Result:= 401;
- grNotFound: Result:= 404;
- grServiceUnavailable: Result:= 503;
- end;
- end;
- { TGrandstreamAPI }
- constructor TGrandstreamAPI.Create(AOwner: TComponent);
- begin
- inherited;
- FStream:= TStringStream.Create;
- FWeb:= TIdHTTP.Create(nil);
- FWeb.ProtocolVersion:= pv1_0;
- FWeb.Request.Username:= FUser;
- FWeb.Request.Password:= FPass;
- FWeb.HTTPOptions:= FWeb.HTTPOptions + [hoInProcessAuth];
- FAudioVideo:= TGsAudioVideo.Create(Self);
- FOSD:= TGsOSD.Create(Self);
- FNetwork:= TGsNetwork.Create(Self);
- FDynamicDNS:= TGsDynamicDNS.Create(Self);
- FSIP:= TGsSIP.Create(Self);
- FDateTime:= TGsDateTime.Create(Self);
- FStatus:= TGsStatus.Create(Self);
- FAccounts:= TGsAccounts.Create(Self);
- FSMTP:= TGsSMTP.Create(Self);
- FFTP:= TGsFTP.Create(Self);
- FPTZ:= TGsPTZ.Create(Self);
- FAlarmEvent:= TGsAlarmEvent.Create(Self);
- FMotion:= TGsMotion.Create(Self);
- FSyslog:= TGsSyslog.Create(Self);
- FStorage:= TGsStorage.Create(Self);
- FMaintenance:= TGsMaintenance.Create(Self);
- FVideoControl:= TGsVideoControl.Create(Self);
- FWiFi:= TGsWiFi.Create(Self);
- FDevice:= TGsDevice.Create(Self);
- FPPPoE:= TGsPPPoE.Create(Self);
- FSnapshot:= TGsSnapshot.Create(Self);
- FLanguage:= TGsLanguage.Create(Self);
- FDecoding:= TGsDecoding.Create(Self);
- FStreaming:= TGsStreaming.Create(Self);
- FCMOS:= TGsCMOS.Create(Self);
- FFourdone:= TGsFourdone.Create(Self);
- FRecording:= TGsRecording.Create(Self);
- end;
- destructor TGrandstreamAPI.Destroy;
- begin
- FRecording.Free;
- FFourdone.Free;
- FCMOS.Free;
- FStreaming.Free;
- FDecoding.Free;
- FLanguage.Free;
- FSnapshot.Free;
- FPPPoE.Free;
- FDevice.Free;
- FWiFi.Free;
- FVideoControl.Free;
- FMaintenance.Free;
- FStorage.Free;
- FSyslog.Free;
- FMotion.Free;
- FalarmEvent.Free;
- FPTZ.Free;
- FFTP.Free;
- FSMTP.Free;
- FAccounts.Free;
- FStatus.Free;
- FDateTime.Free;
- FSIP.Free;
- FDynamicDNS.Free;
- FNetwork.Free;
- FOSD.Free;
- FAudioVideo.Free;
- FWeb.Free;
- FStream.Free;
- inherited;
- end;
- function TGrandstreamAPI.GetURL: String;
- begin
- Result:= Format(CAMERA_URL, [FAddress,FPort]);
- end;
- procedure TGrandstreamAPI.SetAddress(const Value: String);
- begin
- FAddress := Value;
- end;
- procedure TGrandstreamAPI.SetPass(const Value: String);
- begin
- FPass := Value;
- end;
- procedure TGrandstreamAPI.SetPort(const Value: Integer);
- begin
- FPort := Value;
- end;
- procedure TGrandstreamAPI.SetUser(const Value: String);
- begin
- FUser := Value;
- end;
- function TGrandstreamAPI.Get(const Module: String): TGsRequestResult;
- var
- U: String;
- begin
- U:= URL+'/goform/'+Module+'?cmd=get';
- FWeb.Request.UserAgent:= 'JD Grandstream API';
- FWeb.Request.Username:= FUser;
- FWeb.Request.Password:= FPass;
- FWeb.Get(U, FStream);
- Result:= grOkay;
- FStream.Position:= 0;
- end;
- { TGsParams }
- constructor TGsParams.Create;
- begin
- FItems:= TStringList.Create;
- end;
- destructor TGsParams.Destroy;
- begin
- FItems.Free;
- inherited;
- end;
- procedure TGsParams.Clear;
- begin
- FItems.Clear;
- end;
- function TGsParams.Count: Integer;
- begin
- Result:= FItems.Count;
- end;
- function TGsParams.GetItem(const Name: String): String;
- begin
- Result:= FItems.Values[Name];
- end;
- function TGsParams.GetName(const Index: Integer): String;
- begin
- Result:= FItems.Names[Index];
- end;
- procedure TGsParams.SetItem(const Name, Value: String);
- begin
- FItems.Values[Name]:= Value;
- end;
- { TGsRequestBase }
- constructor TGsRequestBase.Create(AOwner: TGrandstreamAPI);
- begin
- FOwner:= AOwner;
- FList:= TStringList.Create;
- end;
- destructor TGsRequestBase.Destroy;
- begin
- FList.Free;
- inherited;
- end;
- function TGsRequestBase.Get(const Cmd: String): TGsRequestResult;
- begin
- FOwner.Get(Cmd);
- FList.Text:= Fowner.FStream.DataString;
- end;
- function TGsRequestBase.Items: TStringList;
- begin
- Result:= FList;
- end;
- function TGsRequestBase.Owner: TGrandstreamAPI;
- begin
- Result:= FOwner;
- end;
- procedure TGsRequestBase.Next;
- begin
- FData:= Items[0];
- Items.Delete(0);
- end;
- function TGsRequestBase.Check(const V: String): Boolean;
- begin
- Result:= Pos(V+'=', FData) = 1;
- end;
- function TGsRequestBase.ValStr: String;
- var
- P: Integer;
- begin
- P:= Pos('=', FData);
- Result:= Copy(FData, P+1, Length(FData));
- end;
- function TGsRequestBase.ValInt: Integer;
- begin
- Result:= StrToIntDef(ValStr, 0);
- end;
- function TGsRequestBase.ValBol: Boolean;
- begin
- Result:= ValInt = 1;
- end;
- { TGsRequestChannelBase }
- constructor TGsRequestChannelBase.Create(AOwner: TGrandstreamAPI; const ItemClass: TGsRequestChannelClass);
- begin
- inherited Create(AOwner);
- FChannels:= TList.Create;
- FItemClass:= ItemClass;
- end;
- destructor TGsRequestChannelBase.Destroy;
- begin
- ClearChannels;
- FChannels.Free;
- inherited;
- end;
- procedure TGsRequestChannelBase.ClearChannels;
- begin
- while FChannels.Count > 0 do begin
- TGsRequestChannel(FChannels[0]).Free;
- FChannels.Delete(0);
- end;
- end;
- function TGsRequestChannelBase.Count: Integer;
- begin
- Result:= FChannels.Count;
- end;
- function TGsRequestChannelBase.Get(const Cmd: String): TGsRequestResult;
- begin
- Result:= inherited Get(Cmd);
- end;
- function TGsRequestChannelBase.GetChannel(Index: Integer): TGsRequestChannel;
- begin
- Result:= TGsRequestChannel(FChannels[Index]);
- end;
- function TGsRequestChannelBase.New: TGsRequestChannel;
- begin
- Result:= FItemClass.Create(Self);
- FChannels.Add(Result);
- end;
- { TGsRequestChannel }
- constructor TGsRequestChannel.Create(AOwner: TGsRequestChannelBase);
- begin
- FOwner:= AOwner;
- end;
- destructor TGsRequestChannel.Destroy;
- begin
- inherited;
- end;
- { TGsVideoResolution }
- procedure TGsVideoResolution.SetLength(const Value: Integer);
- begin
- FLength := Value;
- end;
- procedure TGsVideoResolution.SetWidth(const Value: Integer);
- begin
- FWidth := Value;
- end;
- { TGsAudioVideoStream }
- constructor TGsAudioVideoStream.Create;
- begin
- FResolution:= TGsVideoResolution.Create;
- end;
- destructor TGsAudioVideoStream.Destroy;
- begin
- FResolution.Free;
- inherited;
- end;
- procedure TGsAudioVideoStream.SetAudioBitrate(const Value: Integer);
- begin
- FAudioBitrate := Value;
- end;
- procedure TGsAudioVideoStream.SetAudioEncoder(const Value: TGsAudioCodec);
- begin
- FAudioEncoder := Value;
- end;
- procedure TGsAudioVideoStream.SetBitrate(const Value: Integer);
- begin
- FVideoBitrate := Value;
- end;
- procedure TGsAudioVideoStream.SetBrType(const Value: TGsBrType);
- begin
- FBrType := Value;
- end;
- procedure TGsAudioVideoStream.SetFramerate(const Value: Integer);
- begin
- FFramerate := Value;
- end;
- procedure TGsAudioVideoStream.SetIFrame(const Value: Integer);
- begin
- FIFrame := Value;
- end;
- procedure TGsAudioVideoStream.SetImageQuality(const Value: Integer);
- begin
- FImageQuality := Value;
- end;
- procedure TGsAudioVideoStream.SetVideoEncoder(const Value: TGsVideoCodec);
- begin
- FVideoEncoder := Value;
- end;
- { TGsAudioVideoChannel }
- constructor TGsAudioVideoChannel.Create(AOwner: TGsRequestChannelBase);
- begin
- inherited Create(AOwner);
- FPrimary:= TGsAudioVideoStream.Create;
- FSecondary:= TGsAudioVideoStream.Create;
- end;
- destructor TGsAudioVideoChannel.Destroy;
- begin
- FSecondary.Free;
- FPrimary.Free;
- inherited;
- end;
- procedure TGsAudioVideoChannel.SetAudioChipType(const Value: TGsAudioChipType);
- begin
- FAudioChipType := Value;
- end;
- procedure TGsAudioVideoChannel.SetAudioLineIn(const Value: Boolean);
- begin
- FAudioLineIn := Value;
- end;
- procedure TGsAudioVideoChannel.SetAudioLineOut(const Value: Boolean);
- begin
- FAudioLineOut := Value;
- end;
- procedure TGsAudioVideoChannel.SetMicrophoneVolume(const Value: Integer);
- begin
- FMicrophoneVolume := Value;
- end;
- procedure TGsAudioVideoChannel.SetNtscPalType(const Value: TGsNtscPalType);
- begin
- FNtscPalType := Value;
- end;
- procedure TGsAudioVideoChannel.SetPowerFreq(const Value: TGsPowerFreq);
- begin
- FPowerFreq := Value;
- end;
- procedure TGsAudioVideoChannel.SetSpeakerVolume(const Value: Integer);
- begin
- FSpeakerVolume := Value;
- end;
- { TGsAudioVideo }
- constructor TGsAudioVideo.Create(AOwner: TGrandstreamAPI);
- begin
- inherited Create(AOwner, TGsAudioVideoChannel);
- end;
- destructor TGsAudioVideo.Destroy;
- begin
- inherited;
- end;
- function TGsAudioVideo.GetChannel(Index: Integer): TGsAudioVideoChannel;
- begin
- Result:= TGsAudioVideoChannel(inherited Channels[Index]);
- end;
- function TGsAudioVideo.New: TGsAudioVideoChannel;
- begin
- Result:= TGsAudioVideoChannel(inherited New);
- end;
- function TGsAudioVideo.Get: TGsRequestResult;
- var
- I: TGsAudioVideoChannel;
- X: Integer;
- begin
- ClearChannels;
- try
- Result:= inherited Get('audio_video');;
- X:= -1;
- while Items.Count > 0 do begin
- Next;
- if Check('channel') then begin
- Inc(X);
- I:= New;
- I.FChannel:= X;
- I.FHasSecondary:= False;
- end else
- if Check('video.primary.encoder') then begin
- case ValInt of
- 96: I.Primary.FVideoEncoder:= gvcH264;
- 26: I.Primary.FVideoEncoder:= gvcMJPEG;
- end;
- end else
- if Check('video.primary.resolution') then begin
- //I.Primary.Resolution:= StrToRes(ValStr);
- //REDO
- end else
- if Check('video.primary.bitrate') then begin
- I.Primary.FVideoBitrate:= ValInt;
- end else
- if Check('video.primary.brtype') then begin
- case ValInt of
- 0: I.Primary.FBrType:= gvbVBR;
- 1: I.Primary.FBrType:= gvbCBR;
- end;
- end else
- if Check('video.primary.framerate') then begin
- I.Primary.FFramerate:= ValInt;
- end else
- if Check('video.primary.iframe') then begin
- I.Primary.FIFrame:= ValInt;
- end else
- if Check('video.primary.imagequality') then begin
- I.Primary.FImageQuality:= ValInt;
- end else
- if Check('audio.primary.encoder') then begin
- case ValInt of
- 0: I.Primary.FAudioEncoder:= gacPCMU;
- 1: I.Primary.FAudioEncoder:= gacPCMA;
- 2: I.Primary.FAudioEncoder:= gacG726;
- 3: I.Primary.FAudioEncoder:= gacDisabled;
- 4: I.Primary.FAudioEncoder:= gacAAC;
- end;
- end else
- if Check('audio.primary.bitrate') then begin
- I.Primary.FAudioBitrate:= ValInt;
- end else
- if Check('video.secondary.encoder') then begin
- I.FHasSecondary:= True;
- case ValInt of
- 96: I.Secondary.FVideoEncoder:= gvcH264;
- 26: I.Secondary.FVideoEncoder:= gvcMJPEG;
- end;
- end else
- if Check('video.secondary.resolution') then begin
- //I.Secondary.Resolution:= StrToRes(ValStr);
- //REDO
- end else
- if Check('video.secondary.bitrate') then begin
- I.Secondary.FVideoBitrate:= ValInt;
- end else
- if Check('video.secondary.brtype') then begin
- case ValInt of
- 0: I.Secondary.FBrType:= gvbVBR;
- 1: I.Secondary.FBrType:= gvbCBR;
- end;
- end else
- if Check('video.secondary.framerate') then begin
- I.Secondary.FFramerate:= ValInt;
- end else
- if Check('video.secondary.iframe') then begin
- I.Secondary.FIFrame:= ValInt;
- end else
- if Check('video.secondary.imagequality') then begin
- I.Secondary.FImageQuality:= ValInt;
- end else
- if Check('audio.secondary.encoder') then begin
- case ValInt of
- 0: I.Secondary.FAudioEncoder:= gacPCMU;
- 1: I.Secondary.FAudioEncoder:= gacPCMA;
- 2: I.Secondary.FAudioEncoder:= gacG726;
- 3: I.Secondary.FAudioEncoder:= gacDisabled;
- 4: I.Secondary.FAudioEncoder:= gacAAC;
- end;
- end else
- if Check('audio.secondary.bitrate') then begin
- I.Secondary.FAudioBitrate:= ValInt;
- end else
- if Check('audio.microphone.volume') then begin
- I.FMicrophoneVolume:= ValInt;
- end else
- if Check('audio.speaker.volume') then begin
- I.FSpeakerVolume:= ValInt;
- end else
- if Check('audio.linein') then begin
- case ValInt of
- 0: I.FAudioLineIn:= False;
- 1: I.FAudioLineIn:= True;
- end;
- end else
- if Check('audio.lineout') then begin
- case ValInt of
- 0: I.FAudioLineOut:= False;
- 1: I.FAudioLineOut:= True;
- end;
- end else
- if Check('audio.chip.type') then begin
- case ValInt of
- 0: I.FAudioChipType:= gctAIC33;
- 1: I.FAudioChipType:= gctAIC3104;
- $FF: I.FAudioChipType:= gctNone;
- end;
- end else
- if Check('ntscpal.type') then begin
- case ValInt of
- 50: I.FPowerFreq:= gpfIndoor50;
- 60: I.FPowerFreq:= gpfIndoor60;
- 61: I.FPowerFreq:= gpfOutdoor;
- end;
- end else begin
- //Unrecognized property
- end;
- end;
- except
- on e: exception do begin
- end;
- end;
- end;
- { TGsOSDChannel }
- constructor TGsOSDChannel.Create(AOwner: TGsRequestChannelBase);
- begin
- inherited;
- end;
- destructor TGsOSDChannel.Destroy;
- begin
- inherited;
- end;
- function TGsOSDChannel.GetOSDColorStr: String;
- begin
- case FOSDColor of
- gocAuto: Result:= 'Auto';
- gocWhite: Result:= 'White';
- gocRed: Result:= 'Red';
- gocPurple: Result:= 'Purple';
- gocOrange: Result:= 'Orange';
- gocBlue: Result:= 'Blue';
- gocYellow: Result:= 'Yellow';
- gocGreen: Result:= 'Green';
- gocCyan: Result:= 'Cyan';
- gocBlack: Result:= 'Black';
- end;
- end;
- function TGsOSDChannel.GetOSDColorVal: TColor;
- begin
- case FOSDColor of
- gocAuto: Result:= clNone;
- gocWhite: Result:= clWhite;
- gocRed: Result:= clRed;
- gocPurple: Result:= clPurple;
- gocOrange: Result:= $00FF6100;
- gocBlue: Result:= clBlue;
- gocYellow: Result:= clYellow;
- gocGreen: Result:= clGreen;
- gocCyan: Result:= $0000FFFF;
- gocBlack: Result:= clBlack;
- end;
- end;
- function TGsOSDChannel.GetOSDOpacityStr: String;
- begin
- case FOSDOpacity of
- goo0: ;
- goo10: ;
- goo20: ;
- goo30: ;
- goo40: ;
- goo50: ;
- goo60: ;
- goo70: ;
- goo80: ;
- goo90: ;
- goo100: ;
- end;
- end;
- function TGsOSDChannel.GetOSDPositionStr: String;
- begin
- case FOSDPosition of
- gopTop: Result:= 'Top';
- gopBottom: Result:= 'Bottom';
- end;
- end;
- procedure TGsOSDChannel.SetOSDColor(const Value: TGsOSDColor);
- begin
- FOSDColor := Value;
- end;
- procedure TGsOSDChannel.SetOSDOpacity(const Value: TGsOSDOpacity);
- begin
- FOSDOpacity := Value;
- end;
- procedure TGsOSDChannel.SetOSDPosition(const Value: TGsOSDPosition);
- begin
- FOSDPosition := Value;
- end;
- procedure TGsOSDChannel.SetOSDText(const Value: String);
- begin
- FOSDText := Value;
- end;
- procedure TGsOSDChannel.SetOSDTextIndex(const Value: Integer);
- begin
- FOSDTextIndex := Value;
- end;
- procedure TGsOSDChannel.SetOSDTextShow(const Value: Boolean);
- begin
- FOSDTextShow := Value;
- end;
- procedure TGsOSDChannel.SetOSDTimeShow(const Value: Boolean);
- begin
- FOSDTimeShow := Value;
- end;
- { TGsOSD }
- constructor TGsOSD.Create(AOwner: TGrandstreamAPI);
- begin
- inherited Create(AOwner, TGsOSDChannel);
- end;
- destructor TGsOSD.Destroy;
- begin
- inherited;
- end;
- function TGsOSD.GetChannel(Index: Integer): TGsOSDChannel;
- begin
- Result:= TGsOSDChannel(inherited Channels[Index]);
- end;
- function TGsOSD.New: TGsOSDChannel;
- begin
- Result:= TGsOSDChannel(inherited New);
- end;
- function TGsOSD.Get: TGsRequestResult;
- var
- I: TGsOSDChannel;
- X: Integer;
- T: String;
- begin
- ClearChannels;
- try
- Result:= inherited Get('osd');;
- X:= -1;
- while Items.Count > 0 do begin
- Next;
- if Check('channel') then begin
- Inc(X);
- I:= New;
- I.FChannel:= X;
- end else
- if Check('osdposition') then begin
- case ValInt of
- 0: I.FOSDPosition:= gopTop;
- 1: I.FOSDPosition:= gopBottom;
- end;
- end else
- if Check('osdtimeshow') then begin
- I.FOSDTimeShow:= ValInt = 1;
- end else
- if Check('osdtextshow') then begin
- I.FOSDTextShow:= ValInt = 1;
- end else
- if Check('osdopacity') then begin
- case ValInt of
- 0: I.FOSDOpacity:= goo0;
- 10: I.FOSDOpacity:= goo10;
- 20: I.FOSDOpacity:= goo20;
- 30: I.FOSDOpacity:= goo30;
- 40: I.FOSDOpacity:= goo40;
- 50: I.FOSDOpacity:= goo50;
- 60: I.FOSDOpacity:= goo60;
- 70: I.FOSDOpacity:= goo70;
- 80: I.FOSDOpacity:= goo80;
- 90: I.FOSDOpacity:= goo90;
- 100: I.FOSDOpacity:= goo100;
- end;
- end else
- if Check('osdcolor') then begin
- T:= UpperCase(ValStr);
- if T = '0XFFFFFE' then I.FOSDColor:= gocAuto
- else if T = '0XFFFFFF' then I.FOSDColor:= gocWhite
- else if T = '0XFF0000' then I.FOSDColor:= gocRed
- else if T = '0X800080' then I.FOSDColor:= gocPurple
- else if T = '0XFF6100' then I.FOSDColor:= gocOrange
- else if T = '0X0000FF' then I.FOSDColor:= gocBlue
- else if T = '0XFFFF00' then I.FOSDColor:= gocYellow
- else if T = '0X008000' then I.FOSDColor:= gocGreen
- else if T = '0X00FFFF' then I.FOSDColor:= gocCyan
- else if T = '0X000000' then I.FOSDColor:= gocBlack
- else I.FOSDColor:= gocAuto;
- end else
- if Check('osdtext') then begin
- I.FOSDText:= ValStr;
- end else
- if Check('osdtextindex') then begin
- I.FOSDTextIndex:= ValInt;
- end else begin
- end;
- end;
- except
- on e: exception do begin
- end;
- end;
- end;
- { TGsStatus }
- constructor TGsStatus.Create(AOwner: TGrandstreamAPI);
- begin
- inherited;
- end;
- destructor TGsStatus.Destroy;
- begin
- inherited;
- end;
- function TGsStatus.DDNSStateStr: String;
- begin
- case FDDNSState of
- gdsDisable: Result:= 'Disabled';
- gdsProcessing: Result:= 'Processing';
- gdsSuccess: Result:= 'Success';
- gdsAcctPassErr: Result:= 'Account Password Error';
- gdsServerBlocking: Result:= 'Server Blocking';
- gdsStunServerErr: Result:= 'Stun Server Error';
- gdsDBFailed: Result:= 'Database Failed';
- end;
- end;
- function TGsStatus.LedStatusStr: String;
- begin
- case FLedStatus of
- glsUnsupported: Result:= 'Unsupported';
- glsOn: Result:= 'LED On';
- glsOff: Result:= 'LED Off';
- end;
- end;
- function TGsStatus.PPPoEStatusStr: String;
- begin
- case FPPPoEStatus of
- gpsDisconnected: Result:= 'Disconnected';
- gpsConnected: Result:= 'Connected';
- end;
- end;
- function TGsStatus.WiFiStateStr: String;
- begin
- case FWiFiState of
- gwsDisconnected: Result:= 'Disconnected';
- gwsConnected: Result:= 'Connected';
- end;
- end;
- function TGsStatus.Get: TGsRequestResult;
- var
- T: String;
- begin
- try
- FLedStatus:= glsUnsupported;
- Result:= inherited Get('systeminfo');
- while Items.Count > 0 do begin
- Next;
- if Check('productmode') then begin
- FProductMode:= ValStr;
- end else
- if Check('hardwareversion') then begin
- FHardwareVersion:= ValStr;
- end else
- if Check('partnumber') then begin
- FPartNumber:= ValStr;
- end else
- if Check('bootloaderversion') then begin
- FBootloaderVersion:= ValStr;
- end else
- if Check('coreversion') then begin
- FCoreVersion:= ValStr;
- end else
- if Check('baseversion') then begin
- FBaseVersion:= ValStr;
- end else
- if Check('firmwareversion') then begin
- FFirmwareVersion:= ValStr;
- end else
- if Check('cameratype') then begin
- T:= Trim(Items[0]);
- Items.Delete(0);
- T:= T + ' ' + Trim(Items[0]);
- Items.Delete(0);
- FCameraType:= T;
- end else
- if Check('ddnsstate') then begin
- case ValInt of
- 0: FDDNSState:= gdsDisable;
- 1: FDDNSState:= gdsProcessing;
- 2: FDDNSState:= gdsSuccess;
- 3: FDDNSState:= gdsAcctPassErr;
- 4: FDDNSState:= gdsServerBlocking;
- 5: FDDNSState:= gdsStunServerErr;
- 6: FDDNSState:= gdsDBFailed;
- end;
- end else
- if Check('wifistate') then begin
- case ValInt of
- 0: FWiFiState:= gwsDisconnected;
- 1: FWiFiState:= gwsConnected;
- end;
- end else
- if Check('systemrun') then begin
- FSystemRun:= ValStr;
- end else
- if Check('mac') then begin
- FMac:= ValStr;
- end else
- if Check('ledstatus') then begin
- case ValInt of
- 0: FLedStatus:= glsOn;
- 1: FLedStatus:= glsOff;
- end;
- end else
- if Check('pppoe.ip') then begin
- FPPPoEIP:= ValStr;
- end else
- if Check('pppoe.status') then begin
- case ValInt of
- 0: ;
- 1: ;
- end;
- end else
- if Check('ipaddress') then begin
- FIPAddress:= ValStr;
- end else
- if Check('subnetmask') then begin
- FSubnetMask:= ValStr;
- end else
- if Check('defaultgateway') then begin
- FDefaultGateway:= ValStr;
- end else begin
- end;
- end;
- except
- on e: exception do begin
- end;
- end;
- end;
- { TGsMaintenance }
- constructor TGsMaintenance.Create(AOwner: TGrandstreamAPI);
- begin
- inherited;
- end;
- destructor TGsMaintenance.Destroy;
- begin
- inherited;
- end;
- procedure TGsMaintenance.SetUpdateVia(const Value: TGsUpdateVia);
- begin
- FUpdateVia := Value;
- end;
- procedure TGsMaintenance.SetUpgradeAutomatic(const Value: Boolean);
- begin
- FUpgradeAutomatic := Value;
- end;
- procedure TGsMaintenance.SetUpgradeConfigServerPath(const Value: String);
- begin
- FUpgradeConfigServerPath := Value;
- end;
- procedure TGsMaintenance.SetUpgradeConfigXmlPassword(const Value: String);
- begin
- FUpgradeConfigXmlPassword := Value;
- end;
- procedure TGsMaintenance.SetUpgradeInterval(const Value: Integer);
- begin
- FUpgradeInterval := Value;
- end;
- procedure TGsMaintenance.SetUpgradeServerPath(const Value: String);
- begin
- FUpgradeServerPath := Value;
- end;
- procedure TGsMaintenance.Restart;
- begin
- //SENSITIVE - MUST PROTECT
- end;
- procedure TGsMaintenance.Restore;
- begin
- //SENSITIVE - MUST PROTECT
- end;
- function TGsMaintenance.Get: TGsRequestResult;
- var
- T: String;
- begin
- try
- Result:= inherited Get('maintenance');
- while Items.Count > 0 do begin
- Next;
- if Check('restart') then begin
- end else
- if Check('restore') then begin
- end else
- if Check('update.viatype') then begin
- case ValInt of
- 1: FUpdateVia:= guvTFTP;
- 2: FUpdateVia:= guvHTTP;
- 3: FUpdateVia:= guvHTTPS;
- end;
- end else
- if Check('upgrade.serverpath') then begin
- FUpgradeServerPath:= ValStr;
- end else
- if Check('upgrade.cfgserverpath') then begin
- FUpgradeConfigServerPath:= ValStr;
- end else
- if Check('upgrade_cfg_xml_pwd') then begin
- FUpgradeConfigXmlPassword:= ValStr;
- end else
- if Check('upgrade.automatic') then begin
- FUpgradeAutomatic:= ValBol;
- end else
- if Check('upgrade.interval') then begin
- FUpgradeInterval:= ValInt;
- end else begin
- end;
- end;
- except
- on e: exception do begin
- end;
- end;
- end;
- function TGsMaintenance.GetUpdateViaStr: String;
- begin
- case FUpdateVia of
- guvTFTP: Result:= 'TFTP';
- guvHTTP: Result:= 'HTTP';
- guvHTTPS: Result:= 'HTTPS';
- end;
- end;
- { TGsDeviceChannel }
- constructor TGsDeviceChannel.Create(AOwner: TGsRequestChannelBase);
- begin
- inherited Create(AOwner);
- end;
- destructor TGsDeviceChannel.Destroy;
- begin
- inherited;
- end;
- procedure TGsDeviceChannel.SetAlarmInType(const Value: TGsAlarmType);
- begin
- FAlarmInType := Value;
- end;
- procedure TGsDeviceChannel.SetAlarmOutputTime(const Value: TGsAlarmOutputTime);
- begin
- FAlarmOutputTime := Value;
- end;
- procedure TGsDeviceChannel.SetAlarmOutType(const Value: TGsAlarmType);
- begin
- FAlarmOutType := Value;
- end;
- procedure TGsDeviceChannel.SetGpioPinMultiplex(
- const Value: TGsGpioPinMultiplex);
- begin
- FGpioPinMultiplex := Value;
- end;
- { TGsDevice }
- constructor TGsDevice.Create(AOwner: TGrandstreamAPI);
- begin
- inherited Create(AOwner, TGsDeviceChannel);
- end;
- destructor TGsDevice.Destroy;
- begin
- ClearChannels;
- inherited;
- end;
- function TGsDevice.GetChannel(Index: Integer): TGsDeviceChannel;
- begin
- Result:= FChannels[Index];
- end;
- function TGsDevice.New: TGsDeviceChannel;
- begin
- Result:= TGsDeviceChannel(inherited New);
- end;
- procedure TGsDevice.SetDeviceName(const Value: String);
- begin
- FDeviceName := Value;
- end;
- function TGsDevice.Get: TGsRequestResult;
- var
- I: TGsDeviceChannel;
- X: Integer;
- begin
- ClearChannels;
- try
- Result:= inherited Get('device');
- X:= -1;
- while Items.Count > 0 do begin
- Next;
- if Check('devicename') then begin
- FDeviceName:= ValStr;
- end else
- if Check('channel') then begin
- Inc(X);
- I:= New;
- I.FChannel:= X;
- I.FGpioPinMultiplex:= gpmNone;
- end else
- if Check('alarmin.type') then begin
- case ValInt of
- 0: I.FAlarmInType:= gatNormalOpen;
- 1: I.FAlarmInType:= gatNormalClose;
- end;
- end else
- if Check('alarmout.type') then begin
- case ValInt of
- 0: I.FAlarmOutType:= gatNormalOpen;
- 1: I.FAlarmOutType:= gatNormalClose;
- end;
- end else
- if Check('alarmin.status') then begin
- case ValInt of
- 0: I.FAlarmInStatus:= gasOpen;
- 1: I.FAlarmInStatus:= gasClose;
- end;
- end else
- if Check('alarmout.status') then begin
- case ValInt of
- 0: I.FAlarmOutStatus:= gasOpen;
- 1: I.FAlarmOutStatus:= gasClose;
- end;
- end else
- if Check('alarm_output_time') then begin
- case ValInt of
- 0: I.FAlarmOutputTime:= gao0;
- 5: I.FAlarmOutputTime:= gao5;
- 15: I.FAlarmOutputTime:= gao15;
- 30: I.FAlarmOutputTime:= gao30;
- 60: I.FAlarmOutputTime:= gao60;
- 180: I.FAlarmOutputTime:= gao180;
- 300: I.FAlarmOutputTime:= gao300;
- 600: I.FAlarmOutputTime:= gao600;
- 900: I.FAlarmOutputTime:= gao900;
- 1800: I.FAlarmOutputTime:= gao1800;
- end;
- end else
- if Check('gpio_pin_multiplex') then begin
- case ValInt of
- 0: I.FGpioPinMultiplex:= gpmControl;
- 1: I.FGpioPinMultiplex:= gpmAlarmIO;
- end;
- end else begin
- end;
- end;
- except
- on e: exception do begin
- end;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment