Guest User

Grandstream IP Camera API

a guest
Dec 16th, 2013
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 20.80 KB | None | 0 0
  1. unit GrandstreamAPI;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Classes, SysUtils,
  7.   IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
  8.   IdAllAuthentications ;
  9.  
  10. type
  11.   TGrandstreamAPI = class;
  12.   TGsRequestBase = class;
  13.   TGsAudioVideo = class;
  14.   TGsDevice = class;
  15.   TGsStatus = class;
  16.  
  17.   TGrandstreamAPI = class(TComponent)
  18.   private
  19.     FAddress: String;
  20.     FPort: Integer;
  21.     FPass: String;
  22.     FUser: String;
  23.     FWeb: TIdHTTP;
  24.     FAudioVideo: TGsAudioVideo;
  25.     FDevice: TGsDevice;
  26.     FStatus: TGsStatus;
  27.     function GetURL: String;
  28.     procedure SetAddress(const Value: String);
  29.     procedure SetPort(const Value: Integer);
  30.     procedure SetPass(const Value: String);
  31.     procedure SetUser(const Value: String);
  32.   public
  33.     constructor Create(AOwner: TComponent); override;
  34.     destructor Destroy; override;
  35.     property URL: String read GetURL;
  36.     property AudioVideo: TGsAudioVideo read FAudioVideo;
  37.     property Device: TGsDevice read FDevice;
  38.     property Status: TGsStatus read FStatus;
  39.   published
  40.     property Address: String read FAddress write SetAddress;
  41.     property Port: Integer read FPort write SetPort;
  42.     property User: String read FUser write SetUser;
  43.     property Pass: String read FPass write SetPass;
  44.   end;
  45.  
  46.   TGsRequestResult = (grOkay,grBadRequest,grUnauthorized,grNotFound,
  47.     grServiceUnavailable);
  48.  
  49.   TGsRequestBase = class(TObject)
  50.   private
  51.     FOwner: TGrandstreamAPI;
  52.     FStream: TStringStream;
  53.     FList: TStringList;
  54.   public
  55.     constructor Create(AOwner: TGrandstreamAPI); virtual;
  56.     destructor Destroy; override;
  57.     function Owner: TGrandstreamAPI;
  58.     function Get(const Cmd: String): TGsRequestResult;
  59.     function Stream: TStringStream;
  60.     function Items: TStringList;
  61.   end;
  62.  
  63.   { Audio/Video }
  64.  
  65.   TGsChannel = (gcPrimary,gcSecondary);
  66.  
  67.   TGsVideoCodec = (gvcH264,gvcMJPEG);
  68.  
  69.   TGsResolution = record
  70.     Width: Integer;
  71.     Height: Integer;
  72.   end;
  73.  
  74.   TGsBrType = (gvbVBR,gvbCBR);
  75.  
  76.   TGsAudioCodec = (gacPCMU,gacPCMA,gacG726,gacDisabled,gacAAC);
  77.  
  78.   TGsAudioChipType = (gctAIC33,gctAIC3104,gctNone);
  79.  
  80.   TGsNtscPalType = (gptPAL,gtpNTSC);
  81.  
  82.   TGsPowerFreq = (gpfIndoor50,gpfIndoor60,gpfOutdoor);
  83.  
  84.   TGsChannelInfo = record
  85.     Encoder: TGsVideoCodec;
  86.     Resolution: TGsResolution;
  87.     Bitrate: Integer;
  88.     BrType: TGsBrType;
  89.     Framerate: Integer;
  90.     IFrame: Integer;
  91.     ImageQuality: Integer;
  92.     AudioEncoder: TGsAudioCodec;
  93.     AudioBitrate: Integer;
  94.   end;
  95.  
  96.   PGsStreamInfo = ^TGsStreamInfo;
  97.   TGsStreamInfo = record
  98.     HasSecondary: Boolean;
  99.     Channel: Integer;
  100.     Primary: TGsChannelInfo;
  101.     Secondary: TGsChannelInfo;
  102.     MicrophoneVolume: Integer;
  103.     SpeakerVolume: Integer;
  104.     AudioLineIn: Boolean;
  105.     AudioLineOut: Boolean;
  106.     AudioChipType: TGsAudioChipType;
  107.     NtscPalType: TGsNtscPalType;
  108.     PowerFreq: TGsPowerFreq
  109.   end;
  110.  
  111.   TGsAudioVideo = class(TGsRequestBase)
  112.   private
  113.     FChannels: Array of PGsStreamInfo;
  114.     function GetChannel(Index: Integer): PGsStreamInfo;
  115.     procedure ClearChannels;
  116.   public
  117.     constructor Create(AOwner: TGrandstreamAPI); override;
  118.     destructor Destroy; override;
  119.     function Get: TGsRequestResult;
  120.     function Count: Integer;
  121.     property Channels[Index: Integer]: PGsStreamInfo read GetChannel; default;
  122.   end;
  123.  
  124.   { System Settings }
  125.  
  126.   TGsAlarmType = (gatNormalOpen,gatNormalClose);
  127.  
  128.   TGsAlarmStatus = (gasOpen,gasClose);
  129.  
  130.   TGsAlarmOutputTime = (gao0,gao5,gao15,gao30,gao60,gao180,gao300,gao600,gao900,gao1800);
  131.  
  132.   TGsGpioPinMultiplex = (gpmNone,gpmControl,gpmAlarmIO);
  133.  
  134.   PGsDeviceInfo = ^TGsDeviceInfo;
  135.   TGsDeviceInfo = record
  136.     Channel: Integer;
  137.     AlarmInType: TGsAlarmType;
  138.     AlarmOutType: TGsAlarmType;
  139.     AlarmInStatus: TGsAlarmStatus;
  140.     AlarmOutStatus: TGsAlarmStatus;
  141.     AlarmOutputTime: TGsAlarmOutputTime;
  142.     GpioPinMultiplex: TGsGpioPinMultiplex;
  143.   end;
  144.  
  145.   TGsDevice = class(TGsRequestBase)
  146.   private
  147.     FChannels: Array of PGsDeviceInfo;
  148.     FDeviceName: String;
  149.     function GetChannel(Index: Integer): PGsDeviceInfo;
  150.     procedure ClearChannels;
  151.     procedure SetDeviceName(const Value: String);
  152.   public
  153.     constructor Create(AOwner: TGrandstreamAPI); override;
  154.     destructor Destroy; override;
  155.     function Get: TGsRequestResult;
  156.     function Count: Integer;
  157.     property Channels[Index: Integer]: PGsDeviceInfo read GetChannel; default;
  158.     property DeviceName: String read FDeviceName write SetDeviceName;
  159.   end;
  160.  
  161.   { System Info }
  162.  
  163.   TGsDDNSState = (gdsDisable,gdsProcessing,gdsSuccess,gdsAcctPassErr,
  164.     gdsServerBlocking,gdsStunServerErr,gdsDBFailed);
  165.  
  166.   TGsWiFiState = (gwsDisconnected,gwsConnected);
  167.  
  168.   TGsLedStatus = (glsUnsupported,glsOn,glsOff);
  169.  
  170.   TGsPPPoEStatus = (gpsDisconnected,gpsConnected);
  171.  
  172.   TGsStatus = class(TGsRequestBase)
  173.   private
  174.     FProductMode: String;
  175.     FDDNSState: TGsDDNSState;
  176.     FPartNumber: String;
  177.     FCoreVersion: String;
  178.     FBootLoaderVersion: String;
  179.     FFirmwareVersion: String;
  180.     FBaseVersion: String;
  181.     FHardwareVersion: String;
  182.     FCameraType: String;
  183.     FSystemRun: String;
  184.     FPPPoEStatus: TGsPPPoEStatus;
  185.     FLedStatus: TGsLedStatus;
  186.     FWiFiState: TGsWiFiState;
  187.     FPPPoEIP: String;
  188.     FMac: String;
  189.     FDefaultGateway: String;
  190.     FSubnetMask: String;
  191.     FIPAddress: String;
  192.   public
  193.     constructor Create(AOwner: TGrandstreamAPI); override;
  194.     destructor Destroy; override;
  195.     function Get: TGsRequestResult;
  196.     function DDNSStateStr: String;
  197.     function WiFiStateStr: String;
  198.     function LedStatusStr: String;
  199.     function PPPoEStatusStr: String;
  200.     property ProductMode: String read FProductMode;
  201.     property HardwareVersion: String read FHardwareVersion;
  202.     property PartNumber: String read FPartNumber;
  203.     property BootLoaderVersion: String read FBootLoaderVersion;
  204.     property CoreVersion: String read FCoreVersion;
  205.     property BaseVersion: String read FBaseVersion;
  206.     property FirmwareVersion: String read FFirmwareVersion;
  207.     property CameraType: String read FCameraType;
  208.     property DDNSState: TGsDDNSState read FDDNSState;
  209.     property WiFiState: TGsWiFiState read FWiFiState;
  210.     property SystemRun: String read FSystemRun;
  211.     property Mac: String read FMac;
  212.     property LedStatus: TGsLedStatus read FLedStatus;
  213.     property PPPoEIP: String read FPPPoEIP;
  214.     property PPPoEStatus: TGsPPPoEStatus read FPPPoEStatus;
  215.     property IPAddress: String read FIPAddress;
  216.     property SubnetMask: String read FSubnetMask;
  217.     property DefaultGateway: String read FDefaultGateway;
  218.   end;
  219.  
  220. implementation
  221.  
  222. const
  223.   CAMERA_URL = 'http://%s:%s@%s:%d/';
  224.   // http://user:pass@address:port/
  225.  
  226. function EncodeUrl(source: string): string;
  227.  var i:integer;
  228. begin
  229.    result := '';
  230.    for i := 1 to length(source) do
  231.        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];
  232. end;
  233.  
  234. function IntToResult(const R: Integer): TGsRequestResult;
  235. begin
  236.   case R of
  237.     200: Result:= grOkay;
  238.     400: Result:= grBadRequest;
  239.     401: Result:= grUnauthorized;
  240.     404: Result:= grNotFound;
  241.     503: Result:= grServiceUnavailable;
  242.   end;
  243. end;
  244.  
  245. function ResultToInt(const R: TGsRequestResult): Integer;
  246. begin
  247.   case R of
  248.     grOkay:                 Result:= 200;
  249.     grBadRequest:           Result:= 400;
  250.     grUnauthorized:         Result:= 401;
  251.     grNotFound:             Result:= 404;
  252.     grServiceUnavailable:   Result:= 503;
  253.   end;
  254. end;
  255.  
  256. function StrToRes(const R: String): TGsResolution;
  257. begin
  258.  
  259. end;
  260.  
  261. function ResToStr(const R: TGsResolution): String;
  262. begin
  263.  
  264. end;
  265.  
  266. { TGrandstreamAPI }
  267.  
  268. constructor TGrandstreamAPI.Create(AOwner: TComponent);
  269. begin
  270.   inherited;
  271.   FWeb:= TIdHTTP.Create(nil);
  272.   FWeb.ProtocolVersion:= pv1_0;
  273.   FWeb.Request.Username:= FUser;
  274.   FWeb.Request.Password:= FPass;
  275.   FAudioVideo:= TGsAudioVideo.Create(Self);
  276.   FDevice:= TGsDevice.Create(Self);
  277.   FStatus:= TGsStatus.Create(Self);
  278.  
  279. end;
  280.  
  281. destructor TGrandstreamAPI.Destroy;
  282. begin
  283.  
  284.   FStatus.Free;
  285.   FDevice.Free;
  286.   FAudioVideo.Free;
  287.   FWeb.Free;
  288.   inherited;
  289. end;
  290.  
  291. function TGrandstreamAPI.GetURL: String;
  292. begin
  293.   Result:= Format(CAMERA_URL,
  294.     [EncodeUrl(FUser),EncodeUrl(FPass),FAddress,FPort]);
  295. end;
  296.  
  297. procedure TGrandstreamAPI.SetAddress(const Value: String);
  298. begin
  299.   FAddress := Value;
  300. end;
  301.  
  302. procedure TGrandstreamAPI.SetPass(const Value: String);
  303. begin
  304.   FPass := Value;
  305. end;
  306.  
  307. procedure TGrandstreamAPI.SetPort(const Value: Integer);
  308. begin
  309.   FPort := Value;
  310. end;
  311.  
  312. procedure TGrandstreamAPI.SetUser(const Value: String);
  313. begin
  314.   FUser := Value;
  315. end;
  316.  
  317. { TGsRequestBase }
  318.  
  319. constructor TGsRequestBase.Create(AOwner: TGrandstreamAPI);
  320. begin
  321.   FOwner:= AOwner;
  322.   FStream:= TStringStream.Create;
  323.   FList:= TStringList.Create;
  324. end;
  325.  
  326. destructor TGsRequestBase.Destroy;
  327. begin
  328.   FList.Free;
  329.   FStream.Free;
  330.   inherited;
  331. end;
  332.  
  333. function TGsRequestBase.Get(const Cmd: String): TGsRequestResult;
  334. var
  335.   U: String;
  336. begin
  337.  
  338.   U:= FOwner.URL+'/goform/'+Cmd+'?cmd=get';
  339.  
  340.   FOwner.FWeb.Request.UserAgent:= 'JD Grandstream API';
  341.   FOwner.FWeb.Request.Username:= FOwner.FUser;
  342.   FOwner.FWeb.Request.Password:= FOwner.FPass;
  343.  
  344.   FOwner.FWeb.Get(U);
  345.   FOwner.FWeb.Get(U, FStream);
  346.  
  347.   Result:= grOkay;
  348.  
  349.   FStream.Position:= 0;
  350.   FList.Text:= FStream.DataString;
  351.  
  352. end;
  353.  
  354. function TGsRequestBase.Items: TStringList;
  355. begin
  356.   Result:= FList;
  357. end;
  358.  
  359. function TGsRequestBase.Owner: TGrandstreamAPI;
  360. begin
  361.   Result:= FOwner;
  362. end;
  363.  
  364. function TGsRequestBase.Stream: TStringStream;
  365. begin
  366.   Result:= FStream;
  367. end;
  368.  
  369. { TGsAudioVideo }
  370.  
  371. constructor TGsAudioVideo.Create(AOwner: TGrandstreamAPI);
  372. begin
  373.   inherited;
  374.   SetLength(FChannels, 0);
  375. end;
  376.  
  377. destructor TGsAudioVideo.Destroy;
  378. begin
  379.   ClearChannels;
  380.   inherited;
  381. end;
  382.  
  383. function TGsAudioVideo.Count: Integer;
  384. begin
  385.   Result:= Length(FChannels);
  386. end;
  387.  
  388. procedure TGsAudioVideo.ClearChannels;
  389. var
  390.   X: Integer;
  391. begin
  392.   for X := 0 to Length(FChannels) - 1 do
  393.     Dispose(PGsStreamInfo(FChannels[X]));
  394.   SetLength(FChannels, 0);
  395. end;
  396.  
  397. function TGsAudioVideo.GetChannel(Index: Integer): PGsStreamInfo;
  398. begin
  399.   Result:= FChannels[Index];
  400. end;
  401.  
  402. function TGsAudioVideo.Get: TGsRequestResult;
  403. var
  404.   I: PGsStreamInfo;
  405.   N: String;
  406.   X: Integer;
  407.   function Chk(const V: String): Boolean;
  408.   begin
  409.     Result:= Pos(V+'=', N) = 1;
  410.   end;
  411.   function VStr: String;
  412.   var
  413.     P: Integer;
  414.   begin
  415.     P:= Pos('=', N);
  416.     Result:= Copy(N, P+1, Length(N));
  417.   end;
  418.   function VInt: Integer;
  419.   begin
  420.     Result:= StrToIntDef(VStr, 0);
  421.   end;
  422. begin
  423.   ClearChannels;
  424.   try
  425.     Result:= inherited Get('audio_video');;
  426.     X:= -1;
  427.     while Items.Count > 0 do begin
  428.       N:= Items[0];
  429.       Items.Delete(0);
  430.  
  431.       if Chk('channel') then begin
  432.         Inc(X);
  433.         SetLength(FChannels, Length(FChannels)+1);
  434.         I:= New(PGsStreamInfo);
  435.         FChannels[X]:= I;
  436.         I.Channel:= X;
  437.         I.HasSecondary:= False;
  438.       end else
  439.       if Chk('video.primary.encoder') then begin
  440.         case VInt of
  441.           96: I.Primary.Encoder:= gvcH264;
  442.           26: I.Primary.Encoder:= gvcMJPEG;
  443.         end;
  444.       end else
  445.       if Chk('video.primary.resolution') then begin
  446.         I.Primary.Resolution:= StrToRes(VStr);
  447.       end else
  448.       if Chk('video.primary.bitrate') then begin
  449.         I.Primary.Bitrate:= VInt;
  450.       end else
  451.       if Chk('video.primary.brtype') then begin
  452.         case VInt of
  453.           0: I.Primary.BrType:= gvbVBR;
  454.           1: I.Primary.BrType:= gvbCBR;
  455.         end;
  456.       end else
  457.       if Chk('video.primary.framerate') then begin
  458.         I.Primary.Framerate:= VInt;
  459.       end else
  460.       if Chk('video.primary.iframe') then begin
  461.         I.Primary.IFrame:= VInt;
  462.       end else
  463.       if Chk('video.primary.imagequality') then begin
  464.         I.Primary.ImageQuality:= VInt;
  465.       end else
  466.       if Chk('audio.primary.encoder') then begin
  467.         case VInt of
  468.           0: I.Primary.AudioEncoder:= gacPCMU;
  469.           1: I.Primary.AudioEncoder:= gacPCMA;
  470.           2: I.Primary.AudioEncoder:= gacG726;
  471.           3: I.Primary.AudioEncoder:= gacDisabled;
  472.           4: I.Primary.AudioEncoder:= gacAAC;
  473.         end;
  474.       end else
  475.       if Chk('audio.primary.bitrate') then begin
  476.         I.Primary.AudioBitrate:= VInt;
  477.       end else
  478.       if Chk('video.secondary.encoder') then begin
  479.         I.HasSecondary:= True;
  480.         case VInt of
  481.           96: I.Secondary.Encoder:= gvcH264;
  482.           26: I.Secondary.Encoder:= gvcMJPEG;
  483.         end;
  484.       end else
  485.       if Chk('video.secondary.resolution') then begin
  486.         I.Secondary.Resolution:= StrToRes(VStr);
  487.       end else
  488.       if Chk('video.secondary.bitrate') then begin
  489.         I.Secondary.Bitrate:= VInt;
  490.       end else
  491.       if Chk('video.secondary.brtype') then begin
  492.         case VInt of
  493.           0: I.Secondary.BrType:= gvbVBR;
  494.           1: I.Secondary.BrType:= gvbCBR;
  495.         end;
  496.       end else
  497.       if Chk('video.secondary.framerate') then begin
  498.         I.Secondary.Framerate:= VInt;
  499.       end else
  500.       if Chk('video.secondary.iframe') then begin
  501.         I.Secondary.IFrame:= VInt;
  502.       end else
  503.       if Chk('video.secondary.imagequality') then begin
  504.         I.Secondary.ImageQuality:= VInt;
  505.       end else
  506.       if Chk('audio.secondary.encoder') then begin
  507.         case VInt of
  508.           0: I.Secondary.AudioEncoder:= gacPCMU;
  509.           1: I.Secondary.AudioEncoder:= gacPCMA;
  510.           2: I.Secondary.AudioEncoder:= gacG726;
  511.           3: I.Secondary.AudioEncoder:= gacDisabled;
  512.           4: I.Secondary.AudioEncoder:= gacAAC;
  513.         end;
  514.       end else
  515.       if Chk('audio.secondary.bitrate') then begin
  516.         I.Secondary.AudioBitrate:= VInt;
  517.       end else
  518.       if Chk('audio.microphone.volume') then begin
  519.         I.MicrophoneVolume:= VInt;
  520.       end else
  521.       if Chk('audio.speaker.volume') then begin
  522.         I.SpeakerVolume:= VInt;
  523.       end else
  524.       if Chk('audio.linein') then begin
  525.         case VInt of
  526.           0: I.AudioLineIn:= False;
  527.           1: I.AudioLineIn:= True;
  528.         end;
  529.       end else
  530.       if Chk('audio.lineout') then begin
  531.         case VInt of
  532.           0: I.AudioLineOut:= False;
  533.           1: I.AudioLineOut:= True;
  534.         end;
  535.       end else
  536.       if Chk('audio.chip.type') then begin
  537.         case VInt of
  538.           0: I.AudioChipType:= gctAIC33;
  539.           1: I.AudioChipType:= gctAIC3104;
  540.           $FF: I.AudioChipType:= gctNone;
  541.         end;
  542.       end else
  543.       if Chk('ntscpal.type') then begin
  544.         case VInt of
  545.           50: I.PowerFreq:= gpfIndoor50;
  546.           60: I.PowerFreq:= gpfIndoor60;
  547.           61: I.PowerFreq:= gpfOutdoor;
  548.         end;
  549.       end else begin
  550.         //Unrecognized property
  551.       end;
  552.     end;
  553.  
  554.   except
  555.     on e: exception do begin
  556.  
  557.     end;
  558.   end;
  559. end;
  560.  
  561. { TGsDevice }
  562.  
  563. constructor TGsDevice.Create(AOwner: TGrandstreamAPI);
  564. begin
  565.   inherited;
  566.   SetLength(FChannels, 0);
  567. end;
  568.  
  569. destructor TGsDevice.Destroy;
  570. begin
  571.   ClearChannels;
  572.   inherited;
  573. end;
  574.  
  575. procedure TGsDevice.ClearChannels;
  576. var
  577.   X: Integer;
  578. begin
  579.   for X := 0 to Length(FChannels) - 1 do
  580.     Dispose(PGsStreamInfo(FChannels[X]));
  581.   SetLength(FChannels, 0);
  582. end;
  583.  
  584. function TGsDevice.Count: Integer;
  585. begin
  586.   Result:= Length(FChannels);
  587. end;
  588.  
  589. function TGsDevice.GetChannel(Index: Integer): PGsDeviceInfo;
  590. begin
  591.   Result:= FChannels[Index];
  592. end;
  593.  
  594. procedure TGsDevice.SetDeviceName(const Value: String);
  595. begin
  596.   FDeviceName := Value;
  597. end;
  598.  
  599. function TGsDevice.Get: TGsRequestResult;
  600. var
  601.   I: PGsDeviceInfo;
  602.   N: String;
  603.   X: Integer;
  604.   function Chk(const V: String): Boolean;
  605.   begin
  606.     Result:= Pos(V+'=', N) = 1;
  607.   end;
  608.   function VStr: String;
  609.   var
  610.     P: Integer;
  611.   begin
  612.     P:= Pos('=', N);
  613.     Result:= Copy(N, P+1, Length(N));
  614.   end;
  615.   function VInt: Integer;
  616.   begin
  617.     Result:= StrToIntDef(VStr, 0);
  618.   end;
  619. begin
  620.   ClearChannels;
  621.   try
  622.     Result:= inherited Get('device');
  623.     X:= -1;
  624.     while Items.Count > 0 do begin
  625.       N:= Items[0];
  626.       Items.Delete(0);
  627.       if Chk('devicename') then begin
  628.         FDeviceName:= VStr;
  629.       end else
  630.       if Chk('channel') then begin
  631.         Inc(X);
  632.         SetLength(FChannels, Length(FChannels)+1);
  633.         I:= New(PGsDeviceInfo);
  634.         FChannels[X]:= I;
  635.         I.Channel:= X;
  636.         I.GpioPinMultiplex:= gpmNone;
  637.       end else
  638.       if Chk('alarmin.type') then begin
  639.         case VInt of
  640.           0: I.AlarmInType:= gatNormalOpen;
  641.           1: I.AlarmInType:= gatNormalClose;
  642.         end;
  643.       end else
  644.       if Chk('alarmout.type') then begin
  645.         case VInt of
  646.           0: I.AlarmOutType:= gatNormalOpen;
  647.           1: I.AlarmOutType:= gatNormalClose;
  648.         end;
  649.       end else
  650.       if Chk('alarmin.status') then begin
  651.         case VInt of
  652.           0: I.AlarmInStatus:= gasOpen;
  653.           1: I.AlarmInStatus:= gasClose;
  654.         end;
  655.       end else
  656.       if Chk('alarmout.status') then begin
  657.         case VInt of
  658.           0: I.AlarmOutStatus:= gasOpen;
  659.           1: I.AlarmOutStatus:= gasClose;
  660.         end;
  661.       end else
  662.       if Chk('alarm_output_time') then begin
  663.         case VInt of
  664.           0: I.AlarmOutputTime:= gao0;
  665.           5: I.AlarmOutputTime:= gao5;
  666.           15: I.AlarmOutputTime:= gao15;
  667.           30: I.AlarmOutputTime:= gao30;
  668.           60: I.AlarmOutputTime:= gao60;
  669.           180: I.AlarmOutputTime:= gao180;
  670.           300: I.AlarmOutputTime:= gao300;
  671.           600: I.AlarmOutputTime:= gao600;
  672.           900: I.AlarmOutputTime:= gao900;
  673.           1800: I.AlarmOutputTime:= gao1800;
  674.         end;
  675.       end else
  676.       if Chk('gpio_pin_multiplex') then begin
  677.         case VInt of
  678.           0: I.GpioPinMultiplex:= gpmControl;
  679.           1: I.GpioPinMultiplex:= gpmAlarmIO;
  680.         end;
  681.       end else begin
  682.  
  683.       end;
  684.     end;
  685.   except
  686.     on e: exception do begin
  687.  
  688.     end;
  689.   end;
  690. end;
  691.  
  692. { TGsStatus }
  693.  
  694. constructor TGsStatus.Create(AOwner: TGrandstreamAPI);
  695. begin
  696.   inherited;
  697.  
  698. end;
  699.  
  700. function TGsStatus.DDNSStateStr: String;
  701. begin
  702.  
  703. end;
  704.  
  705. destructor TGsStatus.Destroy;
  706. begin
  707.  
  708.   inherited;
  709. end;
  710.  
  711. function TGsStatus.Get: TGsRequestResult;
  712. var
  713.   N: String;
  714.   T: String;
  715.   function Chk(const V: String): Boolean;
  716.   begin
  717.     Result:= Pos(V+'=', N) = 1;
  718.   end;
  719.   function VStr: String;
  720.   var
  721.     P: Integer;
  722.   begin
  723.     P:= Pos('=', N);
  724.     Result:= Copy(N, P+1, Length(N));
  725.   end;
  726.   function VInt: Integer;
  727.   begin
  728.     Result:= StrToIntDef(VStr, 0);
  729.   end;
  730. begin
  731.   try
  732.     Result:= inherited Get('systeminfo');
  733.     while Items.Count > 0 do begin
  734.       N:= Items[0];
  735.       Items.Delete(0);
  736.       if Chk('productmode') then begin
  737.         FProductMode:= VStr;
  738.       end else
  739.       if Chk('hardwareversion') then begin
  740.         FHardwareVersion:= VStr;
  741.       end else
  742.       if Chk('partnumber') then begin
  743.         FPartNumber:= VStr;
  744.       end else
  745.       if Chk('bootloaderversion') then begin
  746.         FBootloaderVersion:= VStr;
  747.       end else
  748.       if Chk('coreversion') then begin
  749.         FCoreVersion:= VStr;
  750.       end else
  751.       if Chk('baseversion') then begin
  752.         FBaseVersion:= VStr;
  753.       end else
  754.       if Chk('firmwareversion') then begin
  755.         FFirmwareVersion:= VStr;
  756.       end else
  757.       if Chk('cameratype') then begin
  758.         T:= Trim(Items[0]);
  759.         Items.Delete(0);
  760.         T:= T + ' ' + Trim(Items[0]);
  761.         Items.Delete(0);
  762.         FCameraType:= T;
  763.       end else
  764.       if Chk('ddnsstate') then begin
  765.         case VInt of
  766.           0: FDDNSState:= gdsDisable;
  767.           1: FDDNSState:= gdsProcessing;
  768.           2: FDDNSState:= gdsSuccess;
  769.           3: FDDNSState:= gdsAcctPassErr;
  770.           4: FDDNSState:= gdsServerBlocking;
  771.           5: FDDNSState:= gdsStunServerErr;
  772.           6: FDDNSState:= gdsDBFailed;
  773.         end;
  774.       end else
  775.       if Chk('wifistate') then begin
  776.         case VInt of
  777.           0: ;
  778.           1: ;
  779.         end;
  780.       end else
  781.       if Chk('systemrun') then begin
  782.         FSystemRun:= VStr;
  783.       end else
  784.       if Chk('mac') then begin
  785.         FMac:= VStr;
  786.       end else
  787.       if Chk('ledstatus') then begin
  788.         case VInt of
  789.           0: ;
  790.           1: ;
  791.         end;
  792.       end else
  793.       if Chk('pppoe.ip') then begin
  794.         FPPPoEIP:= VStr;
  795.       end else
  796.       if Chk('pppoe.status') then begin
  797.         case VInt of
  798.           0: ;
  799.           1: ;
  800.         end;
  801.       end else
  802.       if Chk('ipaddress') then begin
  803.         FIPAddress:= VStr;
  804.       end else
  805.       if Chk('subnetmask') then begin
  806.         FSubnetMask:= VStr;
  807.       end else
  808.       if Chk('defaultgateway') then begin
  809.         FDefaultGateway:= VStr;
  810.       end else begin
  811.  
  812.       end;
  813.     end;
  814.   except
  815.     on e: exception do begin
  816.  
  817.     end;
  818.   end;
  819. end;
  820.  
  821. function TGsStatus.LedStatusStr: String;
  822. begin
  823.  
  824. end;
  825.  
  826. function TGsStatus.PPPoEStatusStr: String;
  827. begin
  828.  
  829. end;
  830.  
  831. function TGsStatus.WiFiStateStr: String;
  832. begin
  833.  
  834. end;
  835.  
  836. end.
Advertisement
Add Comment
Please, Sign In to add comment