unit SpecAnaService_Impl;

{$I RemObjects.inc}

interface

uses
  Windows, Messages, System.SysUtils, System.Classes, System.TypInfo, Dialogs,
  uROXMLIntf, uROClientIntf, uROClasses, uROTypes, uROServer, uROServerIntf, uROSessions,
  uRORemoteDataModule, uRORTTIAttributes, uRORTTIServerSupport, uROArray, JSON,
  uSpectrumAnalyzer, Vcl.WinXCtrls, Vcl.TMSLogging;

{$REGION 'TMS LOGGING Tags'}
//
// Tag   Expected valued
// d     Decimal(integer)
// e     Scientific
// f     Fixed
// g     General
// m     Money
// n     Number (floating)
// p     Pointer
// s     String
// u     Unsigned decimal
// x     Hexadecimal
// The general format of each formatting tagis as follows: {%[Index:][-][Width][.Precision]Tag}
//

{$ENDREGION}
{$REGION 'brief info for CodeFirst Services'}
(*
  some useful attributes:
  [ROSkip] - type with this attribute will be skiped at generating RODL for client-side
  [RORole('allow_role')]  - service&service methods only
  [RORole('!deny_role')]  - service&service methods only
  [ROCustom('myname','myvalue')] - custom attributes
  [RODocumentation('documentation')] - documentation
  [ROObsolete] - add "obsolete" message into documentation
  [ROObsolete('custom message')] - add specified message into documentation
  [ROService('name')] - service identificator
  [ROServiceMethod]   - service method identificator
  [ROEventSink]       - event sink identificator

  examples:
  TMyStruct = class(TROComplexType)
  private
  fA: Integer;
  published
  property A :Integer read fA write fA;
  end;

  TMyStructArray = class(TROArray<TMyStruct>);

  [ROEventSink]
  IMyEvents = interface(IROEventSink)
  ['{75F9A466-518A-4B09-9DC4-9272B1EEFD95}']
  procedure OnMyEvent(const aStr: String);
  end;

  simple usage of event sinks:
  //ev: IROEventWriter<IMyEvents>;
  ..
  ev := EventRepository.GetWriter<IMyEvents>(Session.SessionID);
  ev.Event.OnMyEvent('Message');
*)
// JSON Example of a get.
// function TNewService.getSpecAnaState: String;
// var
// JSONObject: TJSONObject;
// begin
// try
// JSONObject := TJSONObject.Create;
// with JSONObject do
// begin
// AddPair(TJSONPair.Create(TJSONString.Create('BinShift'), TJSONNumber.Create(fSpecAna.FBinShift))); // Number
// AddPair(TJSONPair.Create(TJSONString.Create('HzPerBin'), TJSONNumber.Create(fSpecAna.FHzPerBin))); // Boolean
// AddPair(TJSONPair.Create(TJSONString.Create('InUse'), TJSONBool.Create(FInUse))); // Has been started
//
// end;
// result := JSONObject.ToString;
// finally
// JSONObject.Free;
// end;
// end;

{$ENDREGION}

const
  __ServiceName = 'NewService';

type

  [ROService(__ServiceName)]
  TNewService = class(TRORemoteDataModule)
  private

  public

    [ROServiceMethod]
    function setDelFiles: boolean; // Clear out the EOF WAV and JPG files

    [ROServiceMethod]
    function getRun: boolean;

    [ROServiceMethod]
    procedure setRun(value: boolean); // done

    [ROServiceMethod]
    function getScan: boolean;

    [ROServiceMethod]
    procedure setScan(value: boolean);

    [ROServiceMethod]
    procedure setTerminate(value: boolean);

    [ROServiceMethod]
    function getWaterRun: boolean;

    [ROServiceMethod]
    procedure setWaterRun(value: boolean);

    [ROServiceMethod]
    function getHit: boolean;

    [ROServiceMethod]
    function getBin: integer;

    [ROServiceMethod]
    procedure setReferenceFrequency(value: int64);

    [ROServiceMethod]
    function getFrequencyET: int64;

    [ROServiceMethod]
    function getAudioFreq: integer;

    [ROServiceMethod]
    function getVerticalRange: Double;

    [ROServiceMethod]
    function getAmplitude: Double;

    [ROServiceMethod]
    function getAmbiant: int64;

    [ROServiceMethod]
    function getBinWidth: Double;

    [ROServiceMethod]
    function getThreshold: integer;

    [ROServiceMethod]
    function getIntegeration: integer;

    [ROServiceMethod]
    function getLinesPerFrame: integer;

    [ROServiceMethod]
    function getWAVFileName: String;

    [ROServiceMethod]
    function getJPGFileName: String;

    [ROServiceMethod]
    function getSum(const A: integer; const B: integer): integer;

    [ROServiceMethod]
    function getIntegration: integer;

    [ROServiceMethod]
    function getFFTSize: integer;

    [ROServiceMethod]
    function getSegmentSize: integer;

    [ROServiceMethod]
    function setWavSML(value: String): boolean;

    [ROServiceMethod]
    function getWavSML: String;

    [ROServiceMethod]
    procedure setSnapShot(value: String);

    [ROServiceMethod]
    function getSnapShot: String;

    [ROServiceMethod]
    procedure setReset(value: boolean);

  end;

implementation

{ %CLASSGROUP 'System.Classes.TPersistent' }
{$R *.dfm}

uses uWaterfall;

function TNewService.setDelFiles: boolean; // Clear out the EOF WAV and JPG files
begin
  // result := frmSpecAna.setDelFilesRMT;
  result := frmSpecAna.setDelFiles;
end;

{$REGION ' get/setRun }

function TNewService.getRun: boolean;
begin
  result := frmSpecAna.RunRMT;

end;

procedure TNewService.setRun(value: boolean);
begin

  frmSpecAna.RunRMT := value;
end;
{$ENDREGION}
//
{$REGION ' get/setSCAN }

function TNewService.getScan: boolean;
begin
  result := frmSpecAna.ScanRMT;

end;

procedure TNewService.setScan(value: boolean);
begin

  frmSpecAna.ScanRMT := (value);

end;
{$ENDREGION}
//
{$REGION ' get/setWater }

function TNewService.getWaterRun: boolean;
begin
  result := frmSpecAna.WaterRunRMT;

end;

procedure TNewService.setWaterRun(value: boolean);
begin

  frmSpecAna.WaterRunRMT := value;
end;
//
{$REGION ' setTerminate }

procedure TNewService.setTerminate(value: boolean);
begin

  frmSpecAna.TerminateRMT := (true);
end;

{$ENDREGION}
//
{$REGION ' getSegmentSize }

function TNewService.getSegmentSize: integer;
begin
  result := frmSpecAna.SegmentSizeRMT;

end;

{$ENDREGION}
//
{$REGION ' get/FFTSize }

function TNewService.getFFTSize: integer;
begin
  result := frmSpecAna.FFTSizeRMT;

end;

{$ENDREGION}
//
{$REGION ' getBinWidth }

function TNewService.getBinWidth: Double;

begin
  result := frmSpecAna.BinWidthRMT;

end;

{$ENDREGION}
//
{$REGION ' get/set Threshold ' }

function TNewService.getThreshold: integer;
begin
  result := frmSpecAna.ThresholdRMT;

end;

{$ENDREGION}
//
{$REGION ' getIntegration}

function TNewService.getIntegration: integer;
begin
  result := frmSpecAna.IntegrationRMT;

end;

{$ENDREGION}
//
{$REGION ' get/setSML }

function TNewService.setWavSML(value: String): boolean;
var
  res: boolean;
begin
  res := frmSpecAna.setSML(value);
end;

function TNewService.getWavSML: string;
begin
  result := frmSpecAna.SMLRMT;

end;

{$ENDREGION}
//
{$REGION ' getE.T. }

function TNewService.getWAVFileName: String;
begin
  result := frmSpecAna.ET.WAVFileName;

end;

function TNewService.getJPGFileName: String;
begin
  result := frmSpecAna.ET.JPGFileName;

end;

function TNewService.getAmplitude: Double;
begin

  result := frmSpecAna.ET.Amplitude;

end;

function TNewService.getAmbiant: int64;
begin
  result := frmSpecAna.ET.Ambiant;

end;

function TNewService.getHit: boolean;
begin
  result := frmSpecAna.ET.Hit;

end;

function TNewService.getBin: integer;
begin
  result := frmSpecAna.ET.Bin;

end;

function TNewService.getAudioFreq: integer;
begin
  result := frmSpecAna.ET.AudioFreq;

end;

{$ENDREGION}
//
{$REGION ' get/set Frequencies }

function TNewService.getFrequencyET: int64;
begin
  result := frmSpecAna.FrequencyET;

end;

procedure TNewService.setReferenceFrequency(value: int64);
begin
  frmSpecAna.FrequencyReference := value;

end;

{$ENDREGION}
//
{$REGION ' getVerticalRange }

function TNewService.getVerticalRange: Double;
begin
  result := frmSpecAna.VerticalRangeRMT;

end;

{$ENDREGION}
//
{$REGION ' getIntegration }

function TNewService.getIntegeration: integer;
begin
  result := frmSpecAna.IntegrationRMT;

end;

{$ENDREGION}
//
{$REGION ' getLinesPerFrame }

function TNewService.getLinesPerFrame: integer;
begin
  result := frmSpecAna.LinesPerFrameRMT;

end;

{$ENDREGION}
//
{$REGION ' Collect Snapshot }

function TNewService.getSnapShot: String;

begin
  frmSpecAna.getSnapShotRMT;

end;

procedure TNewService.setSnapShot(value: String);

begin
  frmSpecAna.setSnapshotRMT(value);

end;

{$ENDREGION}
//
{$REGION ' setReset }

procedure TNewService.setReset(value: boolean);
begin

  frmSpecAna.ResetRMT := (value);

end;
{$ENDREGION}
//
{$REGION ' Class Factory }

FUNCTION TNewService.getSum(const A: integer;

  const B: integer): integer;
begin

  result := A + B;
end;

procedure Create_NewService(out anInstance: IUnknown);
begin
  anInstance := TNewService.Create(nil);
end;

var
  fClassFactory: IROClassFactory;

initialization

fClassFactory := TROClassFactory.Create(__ServiceName, Create_NewService, TRORTTIInvoker);

// RegisterForZeroConf(fClassFactory, Format('_%s_rosdk._tcp.',[__ServiceName]));
finalization

UnRegisterClassFactory(fClassFactory);
fClassFactory := nil;
{$ENDREGION}

end.
