djjd47130

Grandstream IP Camera API [in progress] [Better]

Dec 20th, 2013
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 47.88 KB | None | 0 0
  1. unit GrandstreamAPI;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Classes, SysUtils, Vcl.Graphics,
  7.   IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
  8.   IdAllAuthentications;
  9.  
  10. type
  11.   TGrandstreamAPI = class;
  12.  
  13.   TGsParams = class;
  14.   TGsRequestChannel = class;
  15.   TGsRequestChannelBase = class;
  16.   TGsRequestBase = class;
  17.  
  18.  
  19.   //(1) Audio/VIdeo
  20.   TGsAudioVideoChannel = class;
  21.   TGsAudioVideo = class;
  22.   //(2) OSD
  23.   TGsOSDChannel = class;
  24.   TGsOSD = class;
  25.   //(3) Network
  26.   TGsNetwork = class;
  27.   //(4) DDNS
  28.   TGsDynamicDNS = class;
  29.   //(5) SIP
  30.   TGsSIP = class;
  31.   //(6) Date/Time
  32.   TGsDateTime = class;
  33.   //(7) Status
  34.   TGsStatus = class;
  35.   //(8) Accounts
  36.   TGsAccounts = class;
  37.   //(9) SMTP
  38.   TGsSMTP = class;
  39.   //(10) FTP
  40.   TGsFTP = class;
  41.   //(11) PTZ
  42.   TGsPTZ = class;
  43.   //(12) Alarm Events
  44.   TGsAlarmEvent = class;
  45.   //(13) Motion Detection
  46.   TGsMotion = class;
  47.   //(14) System Log
  48.   TGsSyslog = class;
  49.   //(15) Storage
  50.   TGsStorage = class;
  51.   //(16) Maintenance
  52.   TGsMaintenance = class;
  53.   //(17) Video Controls
  54.   TGsVideoControl = class;
  55.   //(18) WiFi
  56.   TGsWiFi = class;
  57.   //(19) Device Settings
  58.   TGsDeviceChannel = class;
  59.   TGsDevice = class;
  60.   //(20) PPPoE
  61.   TGsPPPoE = class;
  62.   //(21) Snapshot
  63.   TGsSnapshot = class;
  64.   //(22) Language
  65.   TGsLanguage = class;
  66.   //(23) Decode
  67.   TGsDecoding = class;
  68.   //(24) Stream
  69.   TGsStreaming = class;
  70.   //(25) CMOS
  71.   TGsCMOS = class;
  72.   //(26) 4*D1 (Fourdone)
  73.   TGsFourdone = class;
  74.   //(27) Alarm Servers
  75.   TGsAlarmServer = class;
  76.   //(28) Recording
  77.   TGsRecording = class;
  78.  
  79.   { Global }
  80.  
  81.   TGsRequestResult = (grOkay,grBadRequest,grUnauthorized,grNotFound,
  82.     grServiceUnavailable);
  83.  
  84.   TGrandstreamAPI = class(TComponent)
  85.   private
  86.     FStream: TStringStream;
  87.     FAddress: String;
  88.     FPort: Integer;
  89.     FPass: String;
  90.     FUser: String;
  91.     FWeb: TIdHTTP;
  92.  
  93.     FAudioVideo: TGsAudioVideo;
  94.     FOSD: TGsOSD;
  95.     FNetwork: TGsNetwork;
  96.     FDynamicDNS: TGsDynamicDNS;
  97.     FSIP: TGsSIP;
  98.     FDateTime: TGsDateTime;
  99.     FStatus: TGsStatus;
  100.     FAccounts: TGsAccounts;
  101.     FSMTP: TGsSMTP;
  102.     FFTP: TGsFTP;
  103.     FPTZ: TGsPTZ;
  104.     FAlarmEvent: TGsAlarmEvent;
  105.     FMotion: TGsMotion;
  106.     FSyslog: TGsSyslog;
  107.     FStorage: TGsStorage;
  108.     FMaintenance: TGsMaintenance;
  109.     FVideoControl: TGsVideoControl;
  110.     FWiFi: TGsWiFi;
  111.     FDevice: TGsDevice;
  112.     FPPPoE: TGsPPPoE;
  113.     FSnapshot: TGsSnapshot;
  114.     FLanguage: TGsLanguage;
  115.     FDecoding: TGsDecoding;
  116.     FStreaming: TGsStreaming;
  117.     FCMOS: TGsCMOS;
  118.     FFourdone: TGsFourdone;
  119.     FAlarmServer: TGsAlarmServer;
  120.     FRecording: TGsRecording;
  121.  
  122.     function GetURL: String;
  123.     procedure SetAddress(const Value: String);
  124.     procedure SetPort(const Value: Integer);
  125.     procedure SetPass(const Value: String);
  126.     procedure SetUser(const Value: String);
  127.     function Get(const Module: String): TGsRequestResult;
  128.   public
  129.     constructor Create(AOwner: TComponent); override;
  130.     destructor Destroy; override;
  131.     property URL: String read GetURL;
  132.  
  133.     property AudioVideo: TGsAudioVideo read FAudioVideo;
  134.     property OSD: TGsOSD read FOSD;
  135.     property Network: TGsNetwork read FNetwork;
  136.     property DynamicDNS: TGsDynamicDNS read FDynamicDNS;
  137.     property SIP: TGsSIP read FSIP;
  138.     property DateTime: TGsDateTime read FDateTime;
  139.     property Status: TGsStatus read FStatus;
  140.     property Accounts: TGsAccounts read FAccounts;
  141.     property SMTP: TGsSMTP read FSMTP;
  142.     property FTP: TGsFTP read FFTP;
  143.     property PTZ: TGsPTZ read FPTZ;
  144.     property AlarmEvent: TGsAlarmEvent read FAlarmEvent;
  145.     property Motion: TGsMotion read FMotion;
  146.     property Syslog: TGsSyslog read FSyslog;
  147.     property Storage: TGsStorage read FStorage;
  148.     property Maintenance: TGsMaintenance read FMaintenance;
  149.     property VideoControl: TGsVideoControl read FVideoControl;
  150.     property WiFi: TGsWiFi read FWiFi;
  151.     property Device: TGsDevice read FDevice;
  152.     property PPPoE: TGsPPPoE read FPPPoE;
  153.     property Snapshot: TGsSnapshot read FSnapshot;
  154.     property Language: TGsLanguage read FLanguage;
  155.     property Decoding: TGsDecoding read FDecoding;
  156.     property Streaming: TGsStreaming read FStreaming;
  157.     property CMOS: TGsCMOS read FCMOS;
  158.     property Fourdone: TGsFourdone read FFourdone;
  159.     property AlarmServer: TGsAlarmServer read FAlarmServer;
  160.     property Recording: TGsRecording read FRecording;
  161.  
  162.   published
  163.     property Address: String read FAddress write SetAddress;
  164.     property Port: Integer read FPort write SetPort;
  165.     property User: String read FUser write SetUser;
  166.     property Pass: String read FPass write SetPass;
  167.   end;
  168.  
  169.   { Request Base Structures }
  170.  
  171.   TGsParams = class(TObject)
  172.   private
  173.     FItems: TStringList;
  174.     function GetItem(const Name: String): String;
  175.     procedure SetItem(const Name, Value: String);
  176.     function GetName(const Index: Integer): String;
  177.   public
  178.     constructor Create;
  179.     destructor Destroy; override;
  180.     function Count: Integer;
  181.     procedure Clear;
  182.     property Items[const Name: String]: String read GetItem write SetItem; default;
  183.     property Names[const Index: Integer]: String read GetName;
  184.   end;
  185.  
  186.   TGsRequestBase = class(TObject)
  187.   private
  188.     FOwner: TGrandstreamAPI;
  189.     FList: TStringList;
  190.     FData: String;
  191.     procedure Next;
  192.     function Check(const V: String): Boolean;
  193.     function ValInt: Integer;
  194.     function ValStr: String;
  195.     function ValBol: Boolean;
  196.   public
  197.     constructor Create(AOwner: TGrandstreamAPI); virtual;
  198.     destructor Destroy; override;
  199.     function Owner: TGrandstreamAPI;
  200.     function Get(const Cmd: String): TGsRequestResult;
  201.     function Items: TStringList;
  202.   end;
  203.  
  204.   TGsRequestChannelClass = class of TGsRequestChannel;
  205.  
  206.   TGsRequestChannel = class(TObject)
  207.   private
  208.     FChannel: Integer;
  209.     FOwner: TGsRequestChannelBase;
  210.   public
  211.     constructor Create(AOwner: TGsRequestChannelBase); virtual;
  212.     destructor Destroy; override;
  213.     property Owner: TGsRequestChannelBase read FOwner;
  214.     property Channel: Integer read FChannel;
  215.   end;
  216.  
  217.   TGsRequestChannelBase = class(TGsRequestBase)
  218.   private
  219.     FChannels: TList;
  220.     FItemClass: TGsRequestChannelClass;
  221.     function New: TGsRequestChannel;
  222.     function GetChannel(Index: Integer): TGsRequestChannel;
  223.   public
  224.     constructor Create(AOwner: TGrandstreamAPI; const ItemClass: TGsRequestChannelClass); virtual;
  225.     destructor Destroy; override;
  226.     function Get(const Cmd: String): TGsRequestResult;
  227.     function Count: Integer;
  228.     procedure ClearChannels;
  229.     property Channels[Index: Integer]: TGsRequestChannel read GetChannel; default;
  230.   end;
  231.  
  232.   { ------------------------ BEGIN MODULE DEFINITIONS ------------------------ }
  233.  
  234.   { Audio/Video (1) }
  235.  
  236.   TGsVideoCodec = (gvcH264,gvcMJPEG);
  237.  
  238.   TGsBrType = (gvbVBR,gvbCBR);
  239.  
  240.   TGsAudioCodec = (gacPCMU,gacPCMA,gacG726,gacDisabled,gacAAC);
  241.  
  242.   TGsAudioChipType = (gctAIC33,gctAIC3104,gctNone);
  243.  
  244.   TGsNtscPalType = (gptPAL,gtpNTSC);
  245.  
  246.   TGsPowerFreq = (gpfIndoor50,gpfIndoor60,gpfOutdoor);
  247.  
  248.   TGsVideoResolution = class(TObject)
  249.   private
  250.     FLength: Integer;
  251.     FWidth: Integer;
  252.     procedure SetLength(const Value: Integer);
  253.     procedure SetWidth(const Value: Integer);
  254.   public
  255.     property Width: Integer read FWidth write SetWidth;
  256.     property Length: Integer read FLength write SetLength;
  257.   end;
  258.  
  259.   TGsAudioVideoStream = class(TObject)
  260.   private
  261.     FVideoEncoder: TGsVideoCodec;
  262.     FResolution: TGsVideoResolution;
  263.     FVideoBitrate: Integer;
  264.     FBrType: TGsBrType;
  265.     FFramerate: Integer;
  266.     FIFrame: Integer;
  267.     FImageQuality: Integer;
  268.     FAudioEncoder: TGsAudioCodec;
  269.     FAudioBitrate: Integer;
  270.     procedure SetAudioBitrate(const Value: Integer);
  271.     procedure SetAudioEncoder(const Value: TGsAudioCodec);
  272.     procedure SetBitrate(const Value: Integer);
  273.     procedure SetBrType(const Value: TGsBrType);
  274.     procedure SetFramerate(const Value: Integer);
  275.     procedure SetIFrame(const Value: Integer);
  276.     procedure SetImageQuality(const Value: Integer);
  277.     procedure SetVideoEncoder(const Value: TGsVideoCodec);
  278.   public
  279.     constructor Create;
  280.     destructor Destroy; override;
  281.     property VideoEncoder: TGsVideoCodec read FVideoEncoder write SetVideoEncoder;
  282.     property Resolution: TGsVideoResolution read FResolution;
  283.     property VideoBitrate: Integer read FVideoBitrate write SetBitrate;
  284.     property BrType: TGsBrType read FBrType write SetBrType;
  285.     property Framerate: Integer read FFramerate write SetFramerate;
  286.     property IFrame: Integer read FIFrame write SetIFrame;
  287.     property ImageQuality: Integer read FImageQuality write SetImageQuality;
  288.     property AudioEncoder: TGsAudioCodec read FAudioEncoder write SetAudioEncoder;
  289.     property AudioBitrate: Integer read FAudioBitrate write SetAudioBitrate;
  290.   end;
  291.  
  292.   TGsAudioVideoChannel = class(TGsRequestChannel)
  293.   private
  294.     FHasSecondary: Boolean;
  295.     FPrimary: TGsAudioVideoStream;
  296.     FSecondary: TGsAudioVideoStream;
  297.     FMicrophoneVolume: Integer;
  298.     FSpeakerVolume: Integer;
  299.     FAudioLineIn: Boolean;
  300.     FAudioLineOut: Boolean;
  301.     FAudioChipType: TGsAudioChipType;
  302.     FNtscPalType: TGsNtscPalType;
  303.     FPowerFreq: TGsPowerFreq;
  304.     procedure SetAudioChipType(const Value: TGsAudioChipType);
  305.     procedure SetAudioLineIn(const Value: Boolean);
  306.     procedure SetAudioLineOut(const Value: Boolean);
  307.     procedure SetMicrophoneVolume(const Value: Integer);
  308.     procedure SetNtscPalType(const Value: TGsNtscPalType);
  309.     procedure SetPowerFreq(const Value: TGsPowerFreq);
  310.     procedure SetSpeakerVolume(const Value: Integer);
  311.   public
  312.     constructor Create(AOwner: TGsRequestChannelBase); override;
  313.     destructor Destroy; override;
  314.     property HasSecondaryStream: Boolean read FHasSecondary;
  315.     property Primary: TGsAudioVideoStream read FPrimary;
  316.     property Secondary: TGsAudioVideoStream read FSecondary;
  317.     property MicrophoneVolume: Integer read FMicrophoneVolume write SetMicrophoneVolume;
  318.     property SpeakerVolume: Integer read FSpeakerVolume write SetSpeakerVolume;
  319.     property AudioLineIn: Boolean read FAudioLineIn write SetAudioLineIn;
  320.     property AudioLineOut: Boolean read FAudioLineOut write SetAudioLineOut;
  321.     property AudioChipType: TGsAudioChipType read FAudioChipType write SetAudioChipType;
  322.     property NtscPalType: TGsNtscPalType read FNtscPalType write SetNtscPalType;
  323.     property PowerFreq: TGsPowerFreq read FPowerFreq write SetPowerFreq;
  324.   end;
  325.  
  326.   TGsAudioVideo = class(TGsRequestChannelBase)
  327.   private
  328.     function GetChannel(Index: Integer): TGsAudioVideoChannel;
  329.     function New: TGsAudioVideoChannel;
  330.   public
  331.     constructor Create(AOwner: TGrandstreamAPI);
  332.     destructor Destroy; override;
  333.     function Get: TGsRequestResult;
  334.     property Channels[Index: Integer]: TGsAudioVideoChannel read GetChannel; default;
  335.   end;
  336.  
  337.  
  338.   { OSD (2) }
  339.  
  340.   TGsOSDPosition = (gopTop,gopBottom);
  341.  
  342.   TGsOSDOpacity = (goo0,goo10,goo20,goo30,goo40,goo50,goo60,goo70,goo80,goo90,goo100);
  343.  
  344.   TGsOSDColor = (gocAuto,gocWhite,gocRed,gocPurple,gocOrange,gocBlue,gocYellow,
  345.     gocGreen,gocCyan,gocBlack);
  346.  
  347.   TGsOSDChannel = class(TGsRequestChannel)
  348.   private
  349.     FOSDPosition: TGsOSDPosition;
  350.     FOSDText: String;
  351.     FOSDOpacity: TGsOSDOpacity;
  352.     FOSDTextIndex: Integer;
  353.     FOSDColor: TGsOSDColor;
  354.     FOSDTimeShow: Boolean;
  355.     FOSDTextShow: Boolean;
  356.     procedure SetOSDColor(const Value: TGsOSDColor);
  357.     procedure SetOSDOpacity(const Value: TGsOSDOpacity);
  358.     procedure SetOSDPosition(const Value: TGsOSDPosition);
  359.     procedure SetOSDText(const Value: String);
  360.     procedure SetOSDTextIndex(const Value: Integer);
  361.     procedure SetOSDTextShow(const Value: Boolean);
  362.     procedure SetOSDTimeShow(const Value: Boolean);
  363.     function GetOSDColorStr: String;
  364.     function GetOSDColorVal: TColor;
  365.     function GetOSDOpacityStr: String;
  366.     function GetOSDPositionStr: String;
  367.   public
  368.     constructor Create(AOwner: TGsRequestChannelBase); override;
  369.     destructor Destroy; override;
  370.     property OSDPosition: TGsOSDPosition read FOSDPosition write SetOSDPosition;
  371.     property OSDTimeShow: Boolean read FOSDTimeShow write SetOSDTimeShow;
  372.     property OSDTextShow: Boolean read FOSDTextShow write SetOSDTextShow;
  373.     property OSDOpacity: TGsOSDOpacity read FOSDOpacity write SetOSDOpacity;
  374.     property OSDColor: TGsOSDColor read FOSDColor write SetOSDColor;
  375.     property OSDText: String read FOSDText write SetOSDText;
  376.     property OSDTextIndex: Integer read FOSDTextIndex write SetOSDTextIndex;
  377.     property OSDPositionStr: String read GetOSDPositionStr;
  378.     property OSDOpacityStr: String read GetOSDOpacityStr;
  379.     property OSDColorStr: String read GetOSDColorStr;
  380.     property OSDColorVal: TColor read GetOSDColorVal;
  381.   end;
  382.  
  383.   TGsOSD = class(TGsRequestChannelBase)
  384.   private
  385.     function GetChannel(Index: Integer): TGsOSDChannel;
  386.     function New: TGsOSDChannel;
  387.   public
  388.     constructor Create(AOwner: TGrandstreamAPI);
  389.     destructor Destroy; override;
  390.     function Get: TGsRequestResult;
  391.     property Channels[Index: Integer]: TGsOSDChannel read GetChannel; default;
  392.   end;
  393.  
  394.  
  395.   { Network (3) }
  396.  
  397.   TGsNetwork = class(TGsRequestBase)
  398.  
  399.   end;
  400.  
  401.   { Dynamic DNS (4) }
  402.  
  403.   TGsDynamicDNS = class(TGsRequestBase)
  404.  
  405.   end;
  406.  
  407.   { SIP (5) }
  408.  
  409.   TGsSIP = class(TGsRequestBase)
  410.  
  411.   end;
  412.  
  413.   { Date/Time (6) }
  414.  
  415.   TGsDateTime = class(TGsRequestBase)
  416.  
  417.   end;
  418.  
  419.   { System Info / Status (7) }
  420.  
  421.   TGsDDNSState = (gdsDisable,gdsProcessing,gdsSuccess,gdsAcctPassErr,
  422.     gdsServerBlocking,gdsStunServerErr,gdsDBFailed);
  423.  
  424.   TGsWiFiState = (gwsDisconnected,gwsConnected);
  425.  
  426.   TGsLedStatus = (glsUnsupported,glsOn,glsOff);
  427.  
  428.   TGsPPPoEStatus = (gpsDisconnected,gpsConnected);
  429.  
  430.   TGsStatus = class(TGsRequestBase)
  431.   private
  432.     FProductMode: String;
  433.     FDDNSState: TGsDDNSState;
  434.     FPartNumber: String;
  435.     FCoreVersion: String;
  436.     FBootLoaderVersion: String;
  437.     FFirmwareVersion: String;
  438.     FBaseVersion: String;
  439.     FHardwareVersion: String;
  440.     FCameraType: String;
  441.     FSystemRun: String;
  442.     FPPPoEStatus: TGsPPPoEStatus;
  443.     FLedStatus: TGsLedStatus;
  444.     FWiFiState: TGsWiFiState;
  445.     FPPPoEIP: String;
  446.     FMac: String;
  447.     FDefaultGateway: String;
  448.     FSubnetMask: String;
  449.     FIPAddress: String;
  450.   public
  451.     constructor Create(AOwner: TGrandstreamAPI); override;
  452.     destructor Destroy; override;
  453.     function Get: TGsRequestResult;
  454.     function DDNSStateStr: String;
  455.     function WiFiStateStr: String;
  456.     function LedStatusStr: String;
  457.     function PPPoEStatusStr: String;
  458.     property ProductMode: String read FProductMode;
  459.     property HardwareVersion: String read FHardwareVersion;
  460.     property PartNumber: String read FPartNumber;
  461.     property BootLoaderVersion: String read FBootLoaderVersion;
  462.     property CoreVersion: String read FCoreVersion;
  463.     property BaseVersion: String read FBaseVersion;
  464.     property FirmwareVersion: String read FFirmwareVersion;
  465.     property CameraType: String read FCameraType;
  466.     property DDNSState: TGsDDNSState read FDDNSState;
  467.     property WiFiState: TGsWiFiState read FWiFiState;
  468.     property SystemRun: String read FSystemRun;
  469.     property Mac: String read FMac;
  470.     property LedStatus: TGsLedStatus read FLedStatus;
  471.     property PPPoEIP: String read FPPPoEIP;
  472.     property PPPoEStatus: TGsPPPoEStatus read FPPPoEStatus;
  473.     property IPAddress: String read FIPAddress;
  474.     property SubnetMask: String read FSubnetMask;
  475.     property DefaultGateway: String read FDefaultGateway;
  476.   end;
  477.  
  478.   { Account Management (8) }
  479.  
  480.   TGsAccounts = class(TGsRequestBase)
  481.  
  482.   end;
  483.  
  484.   { SMTP Email (9) }
  485.  
  486.   TGsSMTP = class(TGsRequestBase)
  487.  
  488.   end;
  489.  
  490.   { FTP (10) }
  491.  
  492.   TGsFTP = class(TGsRequestBase)
  493.  
  494.   end;
  495.  
  496.   { PTZ (11) }
  497.  
  498.   TGsPTZ = class(TGsRequestBase)
  499.  
  500.   end;
  501.  
  502.   { Alarm Event (12) }
  503.  
  504.   TGsAlarmEvent = class(TGsRequestBase)
  505.  
  506.   end;
  507.  
  508.   { Motion Detection (13) }
  509.  
  510.   TGsMotion = class(TGsRequestBase)
  511.  
  512.   end;
  513.  
  514.   { System Log (14) }
  515.  
  516.   TGsSyslog = class(TGsRequestBase)
  517.  
  518.   end;
  519.  
  520.   { Storage (15) }
  521.  
  522.   TGsStorage = class(TGsRequestBase)
  523.  
  524.   end;
  525.  
  526.   { Maintenance (16) }
  527.  
  528.   TGsUpdateVia = (guvTFTP,guvHTTP,guvHTTPS);
  529.  
  530.   TGsMaintenance = class(TGsRequestBase)
  531.   private
  532.     FUpdateVia: TGsUpdateVia;
  533.     FUpgradeConfigServerPath: String;
  534.     FUpgradeInterval: Integer;
  535.     FUpgradeConfigXmlPassword: String;
  536.     FUpgradeServerPath: String;
  537.     FUpgradeAutomatic: Boolean;
  538.     procedure SetUpdateVia(const Value: TGsUpdateVia);
  539.     procedure SetUpgradeAutomatic(const Value: Boolean);
  540.     procedure SetUpgradeConfigServerPath(const Value: String);
  541.     procedure SetUpgradeConfigXmlPassword(const Value: String);
  542.     procedure SetUpgradeInterval(const Value: Integer);
  543.     procedure SetUpgradeServerPath(const Value: String);
  544.     function GetUpdateViaStr: String;
  545.   public
  546.     constructor Create(AOwner: TGrandstreamAPI); override;
  547.     destructor Destroy; override;
  548.     function Get: TGsRequestResult;
  549.     procedure Restart;
  550.     procedure Restore;
  551.     property UpdateVia: TGsUpdateVia read FUpdateVia write SetUpdateVia;
  552.     property UpgradeServerPath: String read FUpgradeServerPath write SetUpgradeServerPath;
  553.     property UpgradeConfigServerPath: String read FUpgradeConfigServerPath write SetUpgradeConfigServerPath;
  554.     property UpgradeConfigXmlPassword: String read FUpgradeConfigXmlPassword write SetUpgradeConfigXmlPassword;
  555.     property UpgradeAutomatic: Boolean read FUpgradeAutomatic write SetUpgradeAutomatic;
  556.     property UpgradeInterval: Integer read FUpgradeInterval write SetUpgradeInterval;
  557.     property UpdateViaStr: String read GetUpdateViaStr;
  558.   end;
  559.  
  560.   { Video Control (17) }
  561.  
  562.   TGsVideoControl = class(TGsRequestBase)
  563.  
  564.   end;
  565.  
  566.   { WiFi (18) }
  567.  
  568.   TGsWiFi = class(TGsRequestBase)
  569.  
  570.   end;
  571.  
  572.   { System Settings / Device (19) }
  573.  
  574.   TGsAlarmType = (gatNormalOpen,gatNormalClose);
  575.  
  576.   TGsAlarmStatus = (gasOpen,gasClose);
  577.  
  578.   TGsAlarmOutputTime = (gao0,gao5,gao15,gao30,gao60,gao180,gao300,gao600,gao900,gao1800);
  579.  
  580.   TGsGpioPinMultiplex = (gpmNone,gpmControl,gpmAlarmIO);
  581.  
  582.   TGsDeviceChannel = class(TGsRequestChannel)
  583.   private
  584.     FChannel: Integer;
  585.     FAlarmInType: TGsAlarmType;
  586.     FAlarmOutType: TGsAlarmType;
  587.     FAlarmInStatus: TGsAlarmStatus;
  588.     FAlarmOutStatus: TGsAlarmStatus;
  589.     FAlarmOutputTime: TGsAlarmOutputTime;
  590.     FGpioPinMultiplex: TGsGpioPinMultiplex;
  591.     procedure SetAlarmInType(const Value: TGsAlarmType);
  592.     procedure SetAlarmOutputTime(const Value: TGsAlarmOutputTime);
  593.     procedure SetAlarmOutType(const Value: TGsAlarmType);
  594.     procedure SetGpioPinMultiplex(const Value: TGsGpioPinMultiplex);
  595.   public
  596.     constructor Create(AOwner: TGsRequestChannelBase); override;
  597.     destructor Destroy; override;
  598.     property Channel: Integer read FChannel;
  599.     property AlarmInType: TGsAlarmType read FAlarmInType write SetAlarmInType;
  600.     property AlarmOutType: TGsAlarmType read FAlarmOutType write SetAlarmOutType;
  601.     property AlarmInStatus: TGsAlarmStatus read FAlarmInStatus;
  602.     property AlarmOutStatus: TGsAlarmStatus read FAlarmOutStatus;
  603.     property AlarmOutputTime: TGsAlarmOutputTime read FAlarmOutputTime write SetAlarmOutputTime;
  604.     property GpioPinMultiplex: TGsGpioPinMultiplex read FGpioPinMultiplex write SetGpioPinMultiplex;
  605.   end;
  606.  
  607.   TGsDevice = class(TGsRequestChannelBase)
  608.   private
  609.     FDeviceName: String;
  610.     function New: TGsDeviceChannel;
  611.     function GetChannel(Index: Integer): TGsDeviceChannel;
  612.     procedure SetDeviceName(const Value: String);
  613.   public
  614.     constructor Create(AOwner: TGrandstreamAPI);
  615.     destructor Destroy; override;
  616.     function Get: TGsRequestResult;
  617.     property Channels[Index: Integer]: TGsDeviceChannel read GetChannel; default;
  618.     property DeviceName: String read FDeviceName write SetDeviceName;
  619.   end;
  620.  
  621.   { PPPoE (20) }
  622.  
  623.   TGsPPPoE = class(TGsRequestBase)
  624.  
  625.   end;
  626.  
  627.   { Snapshot (21) }
  628.  
  629.   TGsSnapshot = class(TGsRequestBase)
  630.  
  631.   end;
  632.  
  633.   { Language (22) }
  634.  
  635.   TGsLanguage = class(TGsRequestBase)
  636.  
  637.   end;
  638.  
  639.   { Decoding (23) }
  640.  
  641.   TGsDecoding = class(TGsRequestBase)
  642.  
  643.   end;
  644.  
  645.   { Streaming (24) }
  646.  
  647.   TGsStreaming = class(TGsRequestBase)
  648.  
  649.   end;
  650.  
  651.   { CMOS (25) }
  652.  
  653.   TGsCMOS = class(TGsRequestBase)
  654.  
  655.   end;
  656.  
  657.   { 4*D1 (Fourdone) (26) }
  658.  
  659.   TGsFourdone = class(TGsRequestBase)
  660.  
  661.   end;
  662.  
  663.   { Alarm Server (27) }
  664.  
  665.   TGsAlarmServer = class(TGsRequestBase)
  666.  
  667.   end;
  668.  
  669.   { Recording (28) }
  670.  
  671.   TGsRecording = class(TGsRequestBase)
  672.  
  673.   end;
  674.  
  675.  
  676.  
  677. implementation
  678.  
  679. const
  680.   CAMERA_URL = 'http://%s:%d/';
  681.   // http://user:pass@address:port/
  682.  
  683. function EncodeUrl(source: string): string;
  684.  var i:integer;
  685. begin
  686.    result := '';
  687.    for i := 1 to length(source) do
  688.        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];
  689. end;
  690.  
  691. function IntToResult(const R: Integer): TGsRequestResult;
  692. begin
  693.   case R of
  694.     200: Result:= grOkay;
  695.     400: Result:= grBadRequest;
  696.     401: Result:= grUnauthorized;
  697.     404: Result:= grNotFound;
  698.     503: Result:= grServiceUnavailable;
  699.   end;
  700. end;
  701.  
  702. function ResultToInt(const R: TGsRequestResult): Integer;
  703. begin
  704.   case R of
  705.     grOkay:                 Result:= 200;
  706.     grBadRequest:           Result:= 400;
  707.     grUnauthorized:         Result:= 401;
  708.     grNotFound:             Result:= 404;
  709.     grServiceUnavailable:   Result:= 503;
  710.   end;
  711. end;
  712.  
  713. { TGrandstreamAPI }
  714.  
  715. constructor TGrandstreamAPI.Create(AOwner: TComponent);
  716. begin
  717.   inherited;
  718.   FStream:= TStringStream.Create;
  719.   FWeb:= TIdHTTP.Create(nil);
  720.   FWeb.ProtocolVersion:= pv1_0;
  721.   FWeb.Request.Username:= FUser;
  722.   FWeb.Request.Password:= FPass;
  723.   FWeb.HTTPOptions:= FWeb.HTTPOptions + [hoInProcessAuth];
  724.  
  725.   FAudioVideo:= TGsAudioVideo.Create(Self);
  726.   FOSD:= TGsOSD.Create(Self);
  727.   FNetwork:= TGsNetwork.Create(Self);
  728.   FDynamicDNS:= TGsDynamicDNS.Create(Self);
  729.   FSIP:= TGsSIP.Create(Self);
  730.   FDateTime:= TGsDateTime.Create(Self);
  731.   FStatus:= TGsStatus.Create(Self);
  732.   FAccounts:= TGsAccounts.Create(Self);
  733.   FSMTP:= TGsSMTP.Create(Self);
  734.   FFTP:= TGsFTP.Create(Self);
  735.   FPTZ:= TGsPTZ.Create(Self);
  736.   FAlarmEvent:= TGsAlarmEvent.Create(Self);
  737.   FMotion:= TGsMotion.Create(Self);
  738.   FSyslog:= TGsSyslog.Create(Self);
  739.   FStorage:= TGsStorage.Create(Self);
  740.   FMaintenance:= TGsMaintenance.Create(Self);
  741.   FVideoControl:= TGsVideoControl.Create(Self);
  742.   FWiFi:= TGsWiFi.Create(Self);
  743.   FDevice:= TGsDevice.Create(Self);
  744.   FPPPoE:= TGsPPPoE.Create(Self);
  745.   FSnapshot:= TGsSnapshot.Create(Self);
  746.   FLanguage:= TGsLanguage.Create(Self);
  747.   FDecoding:= TGsDecoding.Create(Self);
  748.   FStreaming:= TGsStreaming.Create(Self);
  749.   FCMOS:= TGsCMOS.Create(Self);
  750.   FFourdone:= TGsFourdone.Create(Self);
  751.   FRecording:= TGsRecording.Create(Self);
  752.  
  753. end;
  754.  
  755. destructor TGrandstreamAPI.Destroy;
  756. begin
  757.  
  758.   FRecording.Free;
  759.   FFourdone.Free;
  760.   FCMOS.Free;
  761.   FStreaming.Free;
  762.   FDecoding.Free;
  763.   FLanguage.Free;
  764.   FSnapshot.Free;
  765.   FPPPoE.Free;
  766.   FDevice.Free;
  767.   FWiFi.Free;
  768.   FVideoControl.Free;
  769.   FMaintenance.Free;
  770.   FStorage.Free;
  771.   FSyslog.Free;
  772.   FMotion.Free;
  773.   FalarmEvent.Free;
  774.   FPTZ.Free;
  775.   FFTP.Free;
  776.   FSMTP.Free;
  777.   FAccounts.Free;
  778.   FStatus.Free;
  779.   FDateTime.Free;
  780.   FSIP.Free;
  781.   FDynamicDNS.Free;
  782.   FNetwork.Free;
  783.   FOSD.Free;
  784.   FAudioVideo.Free;
  785.  
  786.   FWeb.Free;
  787.   FStream.Free;
  788.   inherited;
  789. end;
  790.  
  791. function TGrandstreamAPI.GetURL: String;
  792. begin
  793.   Result:= Format(CAMERA_URL, [FAddress,FPort]);
  794. end;
  795.  
  796. procedure TGrandstreamAPI.SetAddress(const Value: String);
  797. begin
  798.   FAddress := Value;
  799. end;
  800.  
  801. procedure TGrandstreamAPI.SetPass(const Value: String);
  802. begin
  803.   FPass := Value;
  804. end;
  805.  
  806. procedure TGrandstreamAPI.SetPort(const Value: Integer);
  807. begin
  808.   FPort := Value;
  809. end;
  810.  
  811. procedure TGrandstreamAPI.SetUser(const Value: String);
  812. begin
  813.   FUser := Value;
  814. end;
  815.  
  816. function TGrandstreamAPI.Get(const Module: String): TGsRequestResult;
  817. var
  818.   U: String;
  819. begin
  820.  
  821.   U:= URL+'/goform/'+Module+'?cmd=get';
  822.  
  823.   FWeb.Request.UserAgent:= 'JD Grandstream API';
  824.   FWeb.Request.Username:= FUser;
  825.   FWeb.Request.Password:= FPass;
  826.  
  827.   FWeb.Get(U, FStream);
  828.  
  829.   Result:= grOkay;
  830.  
  831.   FStream.Position:= 0;
  832.  
  833. end;
  834.  
  835. { TGsParams }
  836.  
  837. constructor TGsParams.Create;
  838. begin
  839.   FItems:= TStringList.Create;
  840. end;
  841.  
  842. destructor TGsParams.Destroy;
  843. begin
  844.   FItems.Free;
  845.   inherited;
  846. end;
  847.  
  848. procedure TGsParams.Clear;
  849. begin
  850.   FItems.Clear;
  851. end;
  852.  
  853. function TGsParams.Count: Integer;
  854. begin
  855.   Result:= FItems.Count;
  856. end;
  857.  
  858. function TGsParams.GetItem(const Name: String): String;
  859. begin
  860.   Result:= FItems.Values[Name];
  861. end;
  862.  
  863. function TGsParams.GetName(const Index: Integer): String;
  864. begin
  865.   Result:= FItems.Names[Index];
  866. end;
  867.  
  868. procedure TGsParams.SetItem(const Name, Value: String);
  869. begin
  870.   FItems.Values[Name]:= Value;
  871. end;
  872.  
  873. { TGsRequestBase }
  874.  
  875. constructor TGsRequestBase.Create(AOwner: TGrandstreamAPI);
  876. begin
  877.   FOwner:= AOwner;
  878.   FList:= TStringList.Create;
  879. end;
  880.  
  881. destructor TGsRequestBase.Destroy;
  882. begin
  883.   FList.Free;
  884.   inherited;
  885. end;
  886.  
  887. function TGsRequestBase.Get(const Cmd: String): TGsRequestResult;
  888. begin
  889.   FOwner.Get(Cmd);
  890.   FList.Text:= Fowner.FStream.DataString;
  891. end;
  892.  
  893. function TGsRequestBase.Items: TStringList;
  894. begin
  895.   Result:= FList;
  896. end;
  897.  
  898. function TGsRequestBase.Owner: TGrandstreamAPI;
  899. begin
  900.   Result:= FOwner;
  901. end;
  902.  
  903. procedure TGsRequestBase.Next;
  904. begin
  905.   FData:= Items[0];
  906.   Items.Delete(0);
  907. end;
  908.  
  909. function TGsRequestBase.Check(const V: String): Boolean;
  910. begin
  911.   Result:= Pos(V+'=', FData) = 1;
  912. end;
  913.  
  914. function TGsRequestBase.ValStr: String;
  915. var
  916.   P: Integer;
  917. begin
  918.   P:= Pos('=', FData);
  919.   Result:= Copy(FData, P+1, Length(FData));
  920. end;
  921.  
  922. function TGsRequestBase.ValInt: Integer;
  923. begin
  924.   Result:= StrToIntDef(ValStr, 0);
  925. end;
  926.  
  927. function TGsRequestBase.ValBol: Boolean;
  928. begin
  929.   Result:= ValInt = 1;
  930. end;
  931.  
  932. { TGsRequestChannelBase }
  933.  
  934. constructor TGsRequestChannelBase.Create(AOwner: TGrandstreamAPI; const ItemClass: TGsRequestChannelClass);
  935. begin
  936.   inherited Create(AOwner);
  937.   FChannels:= TList.Create;
  938.   FItemClass:= ItemClass;
  939. end;
  940.  
  941. destructor TGsRequestChannelBase.Destroy;
  942. begin
  943.   ClearChannels;
  944.   FChannels.Free;
  945.   inherited;
  946. end;
  947.  
  948. procedure TGsRequestChannelBase.ClearChannels;
  949. begin
  950.   while FChannels.Count > 0 do begin
  951.     TGsRequestChannel(FChannels[0]).Free;
  952.     FChannels.Delete(0);
  953.   end;
  954. end;
  955.  
  956. function TGsRequestChannelBase.Count: Integer;
  957. begin
  958.   Result:= FChannels.Count;
  959. end;
  960.  
  961. function TGsRequestChannelBase.Get(const Cmd: String): TGsRequestResult;
  962. begin
  963.   Result:= inherited Get(Cmd);
  964. end;
  965.  
  966. function TGsRequestChannelBase.GetChannel(Index: Integer): TGsRequestChannel;
  967. begin
  968.   Result:= TGsRequestChannel(FChannels[Index]);
  969. end;
  970.  
  971. function TGsRequestChannelBase.New: TGsRequestChannel;
  972. begin
  973.   Result:= FItemClass.Create(Self);
  974.   FChannels.Add(Result);
  975. end;
  976.  
  977. { TGsRequestChannel }
  978.  
  979. constructor TGsRequestChannel.Create(AOwner: TGsRequestChannelBase);
  980. begin
  981.   FOwner:= AOwner;
  982. end;
  983.  
  984. destructor TGsRequestChannel.Destroy;
  985. begin
  986.  
  987.   inherited;
  988. end;
  989.  
  990. { TGsVideoResolution }
  991.  
  992. procedure TGsVideoResolution.SetLength(const Value: Integer);
  993. begin
  994.   FLength := Value;
  995. end;
  996.  
  997. procedure TGsVideoResolution.SetWidth(const Value: Integer);
  998. begin
  999.   FWidth := Value;
  1000. end;
  1001.  
  1002. { TGsAudioVideoStream }
  1003.  
  1004. constructor TGsAudioVideoStream.Create;
  1005. begin
  1006.   FResolution:= TGsVideoResolution.Create;
  1007. end;
  1008.  
  1009. destructor TGsAudioVideoStream.Destroy;
  1010. begin
  1011.   FResolution.Free;
  1012.   inherited;
  1013. end;
  1014.  
  1015. procedure TGsAudioVideoStream.SetAudioBitrate(const Value: Integer);
  1016. begin
  1017.   FAudioBitrate := Value;
  1018. end;
  1019.  
  1020. procedure TGsAudioVideoStream.SetAudioEncoder(const Value: TGsAudioCodec);
  1021. begin
  1022.   FAudioEncoder := Value;
  1023. end;
  1024.  
  1025. procedure TGsAudioVideoStream.SetBitrate(const Value: Integer);
  1026. begin
  1027.   FVideoBitrate := Value;
  1028. end;
  1029.  
  1030. procedure TGsAudioVideoStream.SetBrType(const Value: TGsBrType);
  1031. begin
  1032.   FBrType := Value;
  1033. end;
  1034.  
  1035. procedure TGsAudioVideoStream.SetFramerate(const Value: Integer);
  1036. begin
  1037.   FFramerate := Value;
  1038. end;
  1039.  
  1040. procedure TGsAudioVideoStream.SetIFrame(const Value: Integer);
  1041. begin
  1042.   FIFrame := Value;
  1043. end;
  1044.  
  1045. procedure TGsAudioVideoStream.SetImageQuality(const Value: Integer);
  1046. begin
  1047.   FImageQuality := Value;
  1048. end;
  1049.  
  1050. procedure TGsAudioVideoStream.SetVideoEncoder(const Value: TGsVideoCodec);
  1051. begin
  1052.   FVideoEncoder := Value;
  1053. end;
  1054.  
  1055. { TGsAudioVideoChannel }
  1056.  
  1057. constructor TGsAudioVideoChannel.Create(AOwner: TGsRequestChannelBase);
  1058. begin
  1059.   inherited Create(AOwner);
  1060.   FPrimary:= TGsAudioVideoStream.Create;
  1061.   FSecondary:= TGsAudioVideoStream.Create;
  1062. end;
  1063.  
  1064. destructor TGsAudioVideoChannel.Destroy;
  1065. begin
  1066.   FSecondary.Free;
  1067.   FPrimary.Free;
  1068.   inherited;
  1069. end;
  1070.  
  1071. procedure TGsAudioVideoChannel.SetAudioChipType(const Value: TGsAudioChipType);
  1072. begin
  1073.   FAudioChipType := Value;
  1074. end;
  1075.  
  1076. procedure TGsAudioVideoChannel.SetAudioLineIn(const Value: Boolean);
  1077. begin
  1078.   FAudioLineIn := Value;
  1079. end;
  1080.  
  1081. procedure TGsAudioVideoChannel.SetAudioLineOut(const Value: Boolean);
  1082. begin
  1083.   FAudioLineOut := Value;
  1084. end;
  1085.  
  1086. procedure TGsAudioVideoChannel.SetMicrophoneVolume(const Value: Integer);
  1087. begin
  1088.   FMicrophoneVolume := Value;
  1089. end;
  1090.  
  1091. procedure TGsAudioVideoChannel.SetNtscPalType(const Value: TGsNtscPalType);
  1092. begin
  1093.   FNtscPalType := Value;
  1094. end;
  1095.  
  1096. procedure TGsAudioVideoChannel.SetPowerFreq(const Value: TGsPowerFreq);
  1097. begin
  1098.   FPowerFreq := Value;
  1099. end;
  1100.  
  1101. procedure TGsAudioVideoChannel.SetSpeakerVolume(const Value: Integer);
  1102. begin
  1103.   FSpeakerVolume := Value;
  1104. end;
  1105.  
  1106. { TGsAudioVideo }
  1107.  
  1108. constructor TGsAudioVideo.Create(AOwner: TGrandstreamAPI);
  1109. begin
  1110.   inherited Create(AOwner, TGsAudioVideoChannel);
  1111.  
  1112. end;
  1113.  
  1114. destructor TGsAudioVideo.Destroy;
  1115. begin
  1116.  
  1117.   inherited;
  1118. end;
  1119.  
  1120. function TGsAudioVideo.GetChannel(Index: Integer): TGsAudioVideoChannel;
  1121. begin
  1122.   Result:= TGsAudioVideoChannel(inherited Channels[Index]);
  1123. end;
  1124.  
  1125. function TGsAudioVideo.New: TGsAudioVideoChannel;
  1126. begin
  1127.   Result:= TGsAudioVideoChannel(inherited New);
  1128. end;
  1129.  
  1130. function TGsAudioVideo.Get: TGsRequestResult;
  1131. var
  1132.   I: TGsAudioVideoChannel;
  1133.   X: Integer;
  1134. begin
  1135.   ClearChannels;
  1136.   try
  1137.     Result:= inherited Get('audio_video');;
  1138.     X:= -1;
  1139.     while Items.Count > 0 do begin
  1140.       Next;
  1141.       if Check('channel') then begin
  1142.         Inc(X);
  1143.         I:= New;
  1144.         I.FChannel:= X;
  1145.         I.FHasSecondary:= False;
  1146.       end else
  1147.       if Check('video.primary.encoder') then begin
  1148.         case ValInt of
  1149.           96: I.Primary.FVideoEncoder:= gvcH264;
  1150.           26: I.Primary.FVideoEncoder:= gvcMJPEG;
  1151.         end;
  1152.       end else
  1153.       if Check('video.primary.resolution') then begin
  1154.         //I.Primary.Resolution:= StrToRes(ValStr);
  1155.         //REDO
  1156.       end else
  1157.       if Check('video.primary.bitrate') then begin
  1158.         I.Primary.FVideoBitrate:= ValInt;
  1159.       end else
  1160.       if Check('video.primary.brtype') then begin
  1161.         case ValInt of
  1162.           0: I.Primary.FBrType:= gvbVBR;
  1163.           1: I.Primary.FBrType:= gvbCBR;
  1164.         end;
  1165.       end else
  1166.       if Check('video.primary.framerate') then begin
  1167.         I.Primary.FFramerate:= ValInt;
  1168.       end else
  1169.       if Check('video.primary.iframe') then begin
  1170.         I.Primary.FIFrame:= ValInt;
  1171.       end else
  1172.       if Check('video.primary.imagequality') then begin
  1173.         I.Primary.FImageQuality:= ValInt;
  1174.       end else
  1175.       if Check('audio.primary.encoder') then begin
  1176.         case ValInt of
  1177.           0: I.Primary.FAudioEncoder:= gacPCMU;
  1178.           1: I.Primary.FAudioEncoder:= gacPCMA;
  1179.           2: I.Primary.FAudioEncoder:= gacG726;
  1180.           3: I.Primary.FAudioEncoder:= gacDisabled;
  1181.           4: I.Primary.FAudioEncoder:= gacAAC;
  1182.         end;
  1183.       end else
  1184.       if Check('audio.primary.bitrate') then begin
  1185.         I.Primary.FAudioBitrate:= ValInt;
  1186.       end else
  1187.       if Check('video.secondary.encoder') then begin
  1188.         I.FHasSecondary:= True;
  1189.         case ValInt of
  1190.           96: I.Secondary.FVideoEncoder:= gvcH264;
  1191.           26: I.Secondary.FVideoEncoder:= gvcMJPEG;
  1192.         end;
  1193.       end else
  1194.       if Check('video.secondary.resolution') then begin
  1195.         //I.Secondary.Resolution:= StrToRes(ValStr);
  1196.         //REDO
  1197.       end else
  1198.       if Check('video.secondary.bitrate') then begin
  1199.         I.Secondary.FVideoBitrate:= ValInt;
  1200.       end else
  1201.       if Check('video.secondary.brtype') then begin
  1202.         case ValInt of
  1203.           0: I.Secondary.FBrType:= gvbVBR;
  1204.           1: I.Secondary.FBrType:= gvbCBR;
  1205.         end;
  1206.       end else
  1207.       if Check('video.secondary.framerate') then begin
  1208.         I.Secondary.FFramerate:= ValInt;
  1209.       end else
  1210.       if Check('video.secondary.iframe') then begin
  1211.         I.Secondary.FIFrame:= ValInt;
  1212.       end else
  1213.       if Check('video.secondary.imagequality') then begin
  1214.         I.Secondary.FImageQuality:= ValInt;
  1215.       end else
  1216.       if Check('audio.secondary.encoder') then begin
  1217.         case ValInt of
  1218.           0: I.Secondary.FAudioEncoder:= gacPCMU;
  1219.           1: I.Secondary.FAudioEncoder:= gacPCMA;
  1220.           2: I.Secondary.FAudioEncoder:= gacG726;
  1221.           3: I.Secondary.FAudioEncoder:= gacDisabled;
  1222.           4: I.Secondary.FAudioEncoder:= gacAAC;
  1223.         end;
  1224.       end else
  1225.       if Check('audio.secondary.bitrate') then begin
  1226.         I.Secondary.FAudioBitrate:= ValInt;
  1227.       end else
  1228.       if Check('audio.microphone.volume') then begin
  1229.         I.FMicrophoneVolume:= ValInt;
  1230.       end else
  1231.       if Check('audio.speaker.volume') then begin
  1232.         I.FSpeakerVolume:= ValInt;
  1233.       end else
  1234.       if Check('audio.linein') then begin
  1235.         case ValInt of
  1236.           0: I.FAudioLineIn:= False;
  1237.           1: I.FAudioLineIn:= True;
  1238.         end;
  1239.       end else
  1240.       if Check('audio.lineout') then begin
  1241.         case ValInt of
  1242.           0: I.FAudioLineOut:= False;
  1243.           1: I.FAudioLineOut:= True;
  1244.         end;
  1245.       end else
  1246.       if Check('audio.chip.type') then begin
  1247.         case ValInt of
  1248.           0: I.FAudioChipType:= gctAIC33;
  1249.           1: I.FAudioChipType:= gctAIC3104;
  1250.           $FF: I.FAudioChipType:= gctNone;
  1251.         end;
  1252.       end else
  1253.       if Check('ntscpal.type') then begin
  1254.         case ValInt of
  1255.           50: I.FPowerFreq:= gpfIndoor50;
  1256.           60: I.FPowerFreq:= gpfIndoor60;
  1257.           61: I.FPowerFreq:= gpfOutdoor;
  1258.         end;
  1259.       end else begin
  1260.         //Unrecognized property
  1261.       end;
  1262.     end;
  1263.  
  1264.   except
  1265.     on e: exception do begin
  1266.  
  1267.     end;
  1268.   end;
  1269. end;
  1270.  
  1271. { TGsOSDChannel }
  1272.  
  1273. constructor TGsOSDChannel.Create(AOwner: TGsRequestChannelBase);
  1274. begin
  1275.   inherited;
  1276.  
  1277. end;
  1278.  
  1279. destructor TGsOSDChannel.Destroy;
  1280. begin
  1281.  
  1282.   inherited;
  1283. end;
  1284.  
  1285. function TGsOSDChannel.GetOSDColorStr: String;
  1286. begin
  1287.   case FOSDColor of
  1288.     gocAuto:    Result:= 'Auto';
  1289.     gocWhite:   Result:= 'White';
  1290.     gocRed:     Result:= 'Red';
  1291.     gocPurple:  Result:= 'Purple';
  1292.     gocOrange:  Result:= 'Orange';
  1293.     gocBlue:    Result:= 'Blue';
  1294.     gocYellow:  Result:= 'Yellow';
  1295.     gocGreen:   Result:= 'Green';
  1296.     gocCyan:    Result:= 'Cyan';
  1297.     gocBlack:   Result:= 'Black';
  1298.   end;
  1299. end;
  1300.  
  1301. function TGsOSDChannel.GetOSDColorVal: TColor;
  1302. begin
  1303.   case FOSDColor of
  1304.     gocAuto:    Result:= clNone;
  1305.     gocWhite:   Result:= clWhite;
  1306.     gocRed:     Result:= clRed;
  1307.     gocPurple:  Result:= clPurple;
  1308.     gocOrange:  Result:= $00FF6100;
  1309.     gocBlue:    Result:= clBlue;
  1310.     gocYellow:  Result:= clYellow;
  1311.     gocGreen:   Result:= clGreen;
  1312.     gocCyan:    Result:= $0000FFFF;
  1313.     gocBlack:   Result:= clBlack;
  1314.   end;
  1315. end;
  1316.  
  1317. function TGsOSDChannel.GetOSDOpacityStr: String;
  1318. begin
  1319.   case FOSDOpacity of
  1320.     goo0: ;
  1321.     goo10: ;
  1322.     goo20: ;
  1323.     goo30: ;
  1324.     goo40: ;
  1325.     goo50: ;
  1326.     goo60: ;
  1327.     goo70: ;
  1328.     goo80: ;
  1329.     goo90: ;
  1330.     goo100: ;
  1331.   end;
  1332. end;
  1333.  
  1334. function TGsOSDChannel.GetOSDPositionStr: String;
  1335. begin
  1336.   case FOSDPosition of
  1337.     gopTop:     Result:= 'Top';
  1338.     gopBottom:  Result:= 'Bottom';
  1339.   end;
  1340. end;
  1341.  
  1342. procedure TGsOSDChannel.SetOSDColor(const Value: TGsOSDColor);
  1343. begin
  1344.   FOSDColor := Value;
  1345. end;
  1346.  
  1347. procedure TGsOSDChannel.SetOSDOpacity(const Value: TGsOSDOpacity);
  1348. begin
  1349.   FOSDOpacity := Value;
  1350. end;
  1351.  
  1352. procedure TGsOSDChannel.SetOSDPosition(const Value: TGsOSDPosition);
  1353. begin
  1354.   FOSDPosition := Value;
  1355. end;
  1356.  
  1357. procedure TGsOSDChannel.SetOSDText(const Value: String);
  1358. begin
  1359.   FOSDText := Value;
  1360. end;
  1361.  
  1362. procedure TGsOSDChannel.SetOSDTextIndex(const Value: Integer);
  1363. begin
  1364.   FOSDTextIndex := Value;
  1365. end;
  1366.  
  1367. procedure TGsOSDChannel.SetOSDTextShow(const Value: Boolean);
  1368. begin
  1369.   FOSDTextShow := Value;
  1370. end;
  1371.  
  1372. procedure TGsOSDChannel.SetOSDTimeShow(const Value: Boolean);
  1373. begin
  1374.   FOSDTimeShow := Value;
  1375. end;
  1376.  
  1377. { TGsOSD }
  1378.  
  1379. constructor TGsOSD.Create(AOwner: TGrandstreamAPI);
  1380. begin
  1381.   inherited Create(AOwner, TGsOSDChannel);
  1382. end;
  1383.  
  1384. destructor TGsOSD.Destroy;
  1385. begin
  1386.  
  1387.   inherited;
  1388. end;
  1389.  
  1390. function TGsOSD.GetChannel(Index: Integer): TGsOSDChannel;
  1391. begin
  1392.   Result:= TGsOSDChannel(inherited Channels[Index]);
  1393. end;
  1394.  
  1395. function TGsOSD.New: TGsOSDChannel;
  1396. begin
  1397.   Result:= TGsOSDChannel(inherited New);
  1398. end;
  1399.  
  1400. function TGsOSD.Get: TGsRequestResult;
  1401. var
  1402.   I: TGsOSDChannel;
  1403.   X: Integer;
  1404.   T: String;
  1405. begin
  1406.   ClearChannels;
  1407.   try
  1408.     Result:= inherited Get('osd');;
  1409.     X:= -1;
  1410.     while Items.Count > 0 do begin
  1411.       Next;
  1412.       if Check('channel') then begin
  1413.         Inc(X);
  1414.         I:= New;
  1415.         I.FChannel:= X;
  1416.       end else
  1417.       if Check('osdposition') then begin
  1418.         case ValInt of
  1419.           0: I.FOSDPosition:= gopTop;
  1420.           1: I.FOSDPosition:= gopBottom;
  1421.         end;
  1422.       end else
  1423.       if Check('osdtimeshow') then begin
  1424.         I.FOSDTimeShow:= ValInt = 1;
  1425.       end else
  1426.       if Check('osdtextshow') then begin
  1427.         I.FOSDTextShow:= ValInt = 1;
  1428.       end else
  1429.       if Check('osdopacity') then begin
  1430.         case ValInt of
  1431.           0:    I.FOSDOpacity:= goo0;
  1432.           10:   I.FOSDOpacity:= goo10;
  1433.           20:   I.FOSDOpacity:= goo20;
  1434.           30:   I.FOSDOpacity:= goo30;
  1435.           40:   I.FOSDOpacity:= goo40;
  1436.           50:   I.FOSDOpacity:= goo50;
  1437.           60:   I.FOSDOpacity:= goo60;
  1438.           70:   I.FOSDOpacity:= goo70;
  1439.           80:   I.FOSDOpacity:= goo80;
  1440.           90:   I.FOSDOpacity:= goo90;
  1441.           100:  I.FOSDOpacity:= goo100;
  1442.         end;
  1443.       end else
  1444.       if Check('osdcolor') then begin
  1445.         T:= UpperCase(ValStr);
  1446.         if T = '0XFFFFFE' then      I.FOSDColor:= gocAuto
  1447.         else if T = '0XFFFFFF' then I.FOSDColor:= gocWhite
  1448.         else if T = '0XFF0000' then I.FOSDColor:= gocRed
  1449.         else if T = '0X800080' then I.FOSDColor:= gocPurple
  1450.         else if T = '0XFF6100' then I.FOSDColor:= gocOrange
  1451.         else if T = '0X0000FF' then I.FOSDColor:= gocBlue
  1452.         else if T = '0XFFFF00' then I.FOSDColor:= gocYellow
  1453.         else if T = '0X008000' then I.FOSDColor:= gocGreen
  1454.         else if T = '0X00FFFF' then I.FOSDColor:= gocCyan
  1455.         else if T = '0X000000' then I.FOSDColor:= gocBlack
  1456.         else I.FOSDColor:= gocAuto;
  1457.       end else
  1458.       if Check('osdtext') then begin
  1459.         I.FOSDText:= ValStr;
  1460.       end else
  1461.       if Check('osdtextindex') then begin
  1462.         I.FOSDTextIndex:= ValInt;
  1463.       end else begin
  1464.  
  1465.       end;
  1466.     end;
  1467.   except
  1468.     on e: exception do begin
  1469.  
  1470.     end;
  1471.   end;
  1472. end;
  1473.  
  1474. { TGsStatus }
  1475.  
  1476. constructor TGsStatus.Create(AOwner: TGrandstreamAPI);
  1477. begin
  1478.   inherited;
  1479.  
  1480. end;
  1481.  
  1482. destructor TGsStatus.Destroy;
  1483. begin
  1484.  
  1485.   inherited;
  1486. end;
  1487.  
  1488. function TGsStatus.DDNSStateStr: String;
  1489. begin
  1490.   case FDDNSState of
  1491.     gdsDisable:         Result:= 'Disabled';
  1492.     gdsProcessing:      Result:= 'Processing';
  1493.     gdsSuccess:         Result:= 'Success';
  1494.     gdsAcctPassErr:     Result:= 'Account Password Error';
  1495.     gdsServerBlocking:  Result:= 'Server Blocking';
  1496.     gdsStunServerErr:   Result:= 'Stun Server Error';
  1497.     gdsDBFailed:        Result:= 'Database Failed';
  1498.   end;
  1499. end;
  1500.  
  1501. function TGsStatus.LedStatusStr: String;
  1502. begin
  1503.   case FLedStatus of
  1504.     glsUnsupported: Result:= 'Unsupported';
  1505.     glsOn:          Result:= 'LED On';
  1506.     glsOff:         Result:= 'LED Off';
  1507.   end;
  1508. end;
  1509.  
  1510. function TGsStatus.PPPoEStatusStr: String;
  1511. begin
  1512.   case FPPPoEStatus of
  1513.     gpsDisconnected:  Result:= 'Disconnected';
  1514.     gpsConnected:     Result:= 'Connected';
  1515.   end;
  1516. end;
  1517.  
  1518. function TGsStatus.WiFiStateStr: String;
  1519. begin
  1520.   case FWiFiState of
  1521.     gwsDisconnected:  Result:= 'Disconnected';
  1522.     gwsConnected:     Result:= 'Connected';
  1523.   end;
  1524. end;
  1525.  
  1526. function TGsStatus.Get: TGsRequestResult;
  1527. var
  1528.   T: String;
  1529. begin
  1530.   try
  1531.     FLedStatus:= glsUnsupported;
  1532.     Result:= inherited Get('systeminfo');
  1533.     while Items.Count > 0 do begin
  1534.       Next;
  1535.       if Check('productmode') then begin
  1536.         FProductMode:= ValStr;
  1537.       end else
  1538.       if Check('hardwareversion') then begin
  1539.         FHardwareVersion:= ValStr;
  1540.       end else
  1541.       if Check('partnumber') then begin
  1542.         FPartNumber:= ValStr;
  1543.       end else
  1544.       if Check('bootloaderversion') then begin
  1545.         FBootloaderVersion:= ValStr;
  1546.       end else
  1547.       if Check('coreversion') then begin
  1548.         FCoreVersion:= ValStr;
  1549.       end else
  1550.       if Check('baseversion') then begin
  1551.         FBaseVersion:= ValStr;
  1552.       end else
  1553.       if Check('firmwareversion') then begin
  1554.         FFirmwareVersion:= ValStr;
  1555.       end else
  1556.       if Check('cameratype') then begin
  1557.         T:= Trim(Items[0]);
  1558.         Items.Delete(0);
  1559.         T:= T + ' ' + Trim(Items[0]);
  1560.         Items.Delete(0);
  1561.         FCameraType:= T;
  1562.       end else
  1563.       if Check('ddnsstate') then begin
  1564.         case ValInt of
  1565.           0: FDDNSState:= gdsDisable;
  1566.           1: FDDNSState:= gdsProcessing;
  1567.           2: FDDNSState:= gdsSuccess;
  1568.           3: FDDNSState:= gdsAcctPassErr;
  1569.           4: FDDNSState:= gdsServerBlocking;
  1570.           5: FDDNSState:= gdsStunServerErr;
  1571.           6: FDDNSState:= gdsDBFailed;
  1572.         end;
  1573.       end else
  1574.       if Check('wifistate') then begin
  1575.         case ValInt of
  1576.           0: FWiFiState:= gwsDisconnected;
  1577.           1: FWiFiState:= gwsConnected;
  1578.         end;
  1579.       end else
  1580.       if Check('systemrun') then begin
  1581.         FSystemRun:= ValStr;
  1582.       end else
  1583.       if Check('mac') then begin
  1584.         FMac:= ValStr;
  1585.       end else
  1586.       if Check('ledstatus') then begin
  1587.         case ValInt of
  1588.           0: FLedStatus:= glsOn;
  1589.           1: FLedStatus:= glsOff;
  1590.         end;
  1591.       end else
  1592.       if Check('pppoe.ip') then begin
  1593.         FPPPoEIP:= ValStr;
  1594.       end else
  1595.       if Check('pppoe.status') then begin
  1596.         case ValInt of
  1597.           0: ;
  1598.           1: ;
  1599.         end;
  1600.       end else
  1601.       if Check('ipaddress') then begin
  1602.         FIPAddress:= ValStr;
  1603.       end else
  1604.       if Check('subnetmask') then begin
  1605.         FSubnetMask:= ValStr;
  1606.       end else
  1607.       if Check('defaultgateway') then begin
  1608.         FDefaultGateway:= ValStr;
  1609.       end else begin
  1610.  
  1611.       end;
  1612.     end;
  1613.   except
  1614.     on e: exception do begin
  1615.  
  1616.     end;
  1617.   end;
  1618. end;
  1619.  
  1620. { TGsMaintenance }
  1621.  
  1622. constructor TGsMaintenance.Create(AOwner: TGrandstreamAPI);
  1623. begin
  1624.   inherited;
  1625.  
  1626. end;
  1627.  
  1628. destructor TGsMaintenance.Destroy;
  1629. begin
  1630.  
  1631.   inherited;
  1632. end;
  1633.  
  1634. procedure TGsMaintenance.SetUpdateVia(const Value: TGsUpdateVia);
  1635. begin
  1636.   FUpdateVia := Value;
  1637. end;
  1638.  
  1639. procedure TGsMaintenance.SetUpgradeAutomatic(const Value: Boolean);
  1640. begin
  1641.   FUpgradeAutomatic := Value;
  1642. end;
  1643.  
  1644. procedure TGsMaintenance.SetUpgradeConfigServerPath(const Value: String);
  1645. begin
  1646.   FUpgradeConfigServerPath := Value;
  1647. end;
  1648.  
  1649. procedure TGsMaintenance.SetUpgradeConfigXmlPassword(const Value: String);
  1650. begin
  1651.   FUpgradeConfigXmlPassword := Value;
  1652. end;
  1653.  
  1654. procedure TGsMaintenance.SetUpgradeInterval(const Value: Integer);
  1655. begin
  1656.   FUpgradeInterval := Value;
  1657. end;
  1658.  
  1659. procedure TGsMaintenance.SetUpgradeServerPath(const Value: String);
  1660. begin
  1661.   FUpgradeServerPath := Value;
  1662. end;
  1663.  
  1664. procedure TGsMaintenance.Restart;
  1665. begin
  1666.   //SENSITIVE - MUST PROTECT
  1667.  
  1668. end;
  1669.  
  1670. procedure TGsMaintenance.Restore;
  1671. begin
  1672.   //SENSITIVE - MUST PROTECT
  1673.  
  1674. end;
  1675.  
  1676. function TGsMaintenance.Get: TGsRequestResult;
  1677. var
  1678.   T: String;
  1679. begin
  1680.   try
  1681.     Result:= inherited Get('maintenance');
  1682.     while Items.Count > 0 do begin
  1683.       Next;
  1684.       if Check('restart') then begin
  1685.  
  1686.       end else
  1687.       if Check('restore') then begin
  1688.  
  1689.       end else
  1690.       if Check('update.viatype') then begin
  1691.         case ValInt of
  1692.           1: FUpdateVia:= guvTFTP;
  1693.           2: FUpdateVia:= guvHTTP;
  1694.           3: FUpdateVia:= guvHTTPS;
  1695.         end;
  1696.       end else
  1697.       if Check('upgrade.serverpath') then begin
  1698.         FUpgradeServerPath:= ValStr;
  1699.       end else
  1700.       if Check('upgrade.cfgserverpath') then begin
  1701.         FUpgradeConfigServerPath:= ValStr;
  1702.       end else
  1703.       if Check('upgrade_cfg_xml_pwd') then begin
  1704.         FUpgradeConfigXmlPassword:= ValStr;
  1705.       end else
  1706.       if Check('upgrade.automatic') then begin
  1707.         FUpgradeAutomatic:= ValBol;
  1708.       end else
  1709.       if Check('upgrade.interval') then begin
  1710.         FUpgradeInterval:= ValInt;
  1711.       end else begin
  1712.  
  1713.       end;
  1714.     end;
  1715.   except
  1716.     on e: exception do begin
  1717.  
  1718.     end;
  1719.   end;
  1720. end;
  1721.  
  1722. function TGsMaintenance.GetUpdateViaStr: String;
  1723. begin
  1724.   case FUpdateVia of
  1725.     guvTFTP:  Result:= 'TFTP';
  1726.     guvHTTP:  Result:= 'HTTP';
  1727.     guvHTTPS: Result:= 'HTTPS';
  1728.   end;
  1729. end;
  1730.  
  1731. { TGsDeviceChannel }
  1732.  
  1733. constructor TGsDeviceChannel.Create(AOwner: TGsRequestChannelBase);
  1734. begin
  1735.   inherited Create(AOwner);
  1736.  
  1737. end;
  1738.  
  1739. destructor TGsDeviceChannel.Destroy;
  1740. begin
  1741.  
  1742.   inherited;
  1743. end;
  1744.  
  1745. procedure TGsDeviceChannel.SetAlarmInType(const Value: TGsAlarmType);
  1746. begin
  1747.   FAlarmInType := Value;
  1748. end;
  1749.  
  1750. procedure TGsDeviceChannel.SetAlarmOutputTime(const Value: TGsAlarmOutputTime);
  1751. begin
  1752.   FAlarmOutputTime := Value;
  1753. end;
  1754.  
  1755. procedure TGsDeviceChannel.SetAlarmOutType(const Value: TGsAlarmType);
  1756. begin
  1757.   FAlarmOutType := Value;
  1758. end;
  1759.  
  1760. procedure TGsDeviceChannel.SetGpioPinMultiplex(
  1761.   const Value: TGsGpioPinMultiplex);
  1762. begin
  1763.   FGpioPinMultiplex := Value;
  1764. end;
  1765.  
  1766. { TGsDevice }
  1767.  
  1768. constructor TGsDevice.Create(AOwner: TGrandstreamAPI);
  1769. begin
  1770.   inherited Create(AOwner, TGsDeviceChannel);
  1771. end;
  1772.  
  1773. destructor TGsDevice.Destroy;
  1774. begin
  1775.   ClearChannels;
  1776.   inherited;
  1777. end;
  1778.  
  1779. function TGsDevice.GetChannel(Index: Integer): TGsDeviceChannel;
  1780. begin
  1781.   Result:= FChannels[Index];
  1782. end;
  1783.  
  1784. function TGsDevice.New: TGsDeviceChannel;
  1785. begin
  1786.   Result:= TGsDeviceChannel(inherited New);
  1787. end;
  1788.  
  1789. procedure TGsDevice.SetDeviceName(const Value: String);
  1790. begin
  1791.   FDeviceName := Value;
  1792. end;
  1793.  
  1794. function TGsDevice.Get: TGsRequestResult;
  1795. var
  1796.   I: TGsDeviceChannel;
  1797.   X: Integer;
  1798. begin
  1799.   ClearChannels;
  1800.   try
  1801.     Result:= inherited Get('device');
  1802.     X:= -1;
  1803.     while Items.Count > 0 do begin
  1804.       Next;
  1805.       if Check('devicename') then begin
  1806.         FDeviceName:= ValStr;
  1807.       end else
  1808.       if Check('channel') then begin
  1809.         Inc(X);
  1810.         I:= New;
  1811.         I.FChannel:= X;
  1812.         I.FGpioPinMultiplex:= gpmNone;
  1813.       end else
  1814.       if Check('alarmin.type') then begin
  1815.         case ValInt of
  1816.           0: I.FAlarmInType:= gatNormalOpen;
  1817.           1: I.FAlarmInType:= gatNormalClose;
  1818.         end;
  1819.       end else
  1820.       if Check('alarmout.type') then begin
  1821.         case ValInt of
  1822.           0: I.FAlarmOutType:= gatNormalOpen;
  1823.           1: I.FAlarmOutType:= gatNormalClose;
  1824.         end;
  1825.       end else
  1826.       if Check('alarmin.status') then begin
  1827.         case ValInt of
  1828.           0: I.FAlarmInStatus:= gasOpen;
  1829.           1: I.FAlarmInStatus:= gasClose;
  1830.         end;
  1831.       end else
  1832.       if Check('alarmout.status') then begin
  1833.         case ValInt of
  1834.           0: I.FAlarmOutStatus:= gasOpen;
  1835.           1: I.FAlarmOutStatus:= gasClose;
  1836.         end;
  1837.       end else
  1838.       if Check('alarm_output_time') then begin
  1839.         case ValInt of
  1840.           0: I.FAlarmOutputTime:= gao0;
  1841.           5: I.FAlarmOutputTime:= gao5;
  1842.           15: I.FAlarmOutputTime:= gao15;
  1843.           30: I.FAlarmOutputTime:= gao30;
  1844.           60: I.FAlarmOutputTime:= gao60;
  1845.           180: I.FAlarmOutputTime:= gao180;
  1846.           300: I.FAlarmOutputTime:= gao300;
  1847.           600: I.FAlarmOutputTime:= gao600;
  1848.           900: I.FAlarmOutputTime:= gao900;
  1849.           1800: I.FAlarmOutputTime:= gao1800;
  1850.         end;
  1851.       end else
  1852.       if Check('gpio_pin_multiplex') then begin
  1853.         case ValInt of
  1854.           0: I.FGpioPinMultiplex:= gpmControl;
  1855.           1: I.FGpioPinMultiplex:= gpmAlarmIO;
  1856.         end;
  1857.       end else begin
  1858.  
  1859.       end;
  1860.     end;
  1861.   except
  1862.     on e: exception do begin
  1863.  
  1864.     end;
  1865.   end;
  1866. end;
  1867.  
  1868. end.
Advertisement
Add Comment
Please, Sign In to add comment