From: steele@telerobotics.jpl.nasa.gov (Rob Steele)
Newsgroups: comp.os.vxworks
Subject: Ada bindings for StethoScope
Date: Tue, 18 Aug 92 09:41:42 PDT
Organization: Lawrence Berkeley Laboratory, Berkeley CA
NNTP-Posting-Host: 128.3.112.16
Originator: daemon@vxw.ee.lbl.gov

 
-- What follows are Ada bindings for StethoScope. Per the header, these
-- are largely untested, but could be a nice place to start from. Some
-- sample code showing how we used these bindings is listed at the end.

				Rob Steele
				email: steele@telerobotics.jpl.nasa.gov

  -- Package:  Scope
  -- File Name:  Scope_Bindings.a
  -- Purpose:  Allows interfacing between ADA code and Stethescope software
  --           such that Stethescope commands can be called from ADA.
  -- Author:  Rob Steele, Kevin Wedeward
  -- Creation Data:  Created July 27, 1992
  -- Information:  The basic commands have been used and tested, but for the
  --               most part the package is untested.  A procedure and function
  --               to convert ADA strings to C strings are included in this
  --               package.
  --          
  --               If there are any questions, Rob Steele can be called at
  --               (818) 354-5837 or sent email at
  --               steele@telerobotics.jpl.nasa.gov and Kevin Wedeward can
  --               be sent email at kwedewar@nmsu.edu.
  -- Warranty:  Absolutely no warranty exists for this binding.
  -- Jet Propulsion Laboratory
  -- Supervisory Telerobotics Laboratory
  -- Copywrite C 1992, California Institute of Technology.
  -- U.S. Government Sponsorship under NASA Contract NAS7-918 is acknowledged.

with system;
with vxTypes;		use vxTypes;
with vxWorks;		use vxWorks;
with language;		use language;
with unsigned_types;	use unsigned_types;

package Scope is

function A_to_C (Item : in String) return String;
procedure A_to_C (Item : in String; Result : out String);

INT_CONSTANT    : constant String (1..4) := "int"    & ASCII.NUL;
FLOAT_CONSTANT  : constant String (1..6) := "float"  & ASCII.NUL;
DOUBLE_CONSTANT : constant String (1..7) := "double" & ASCII.NUL;

OK : Boolean;

type size_t is new UNSIGNED_INTEGER;

function MaxSamples return INTEGER;

procedure SendScript(script_address : SYSTEM.ADDRESS);

procedure ClearScript;

procedure SendAnnotation(coordX : FLOAT; coordY : FLOAT;
                         text_address : SYSTEM.ADDRESS);

procedure ClearAnnotation;

function RemoveSignal(name_address : SYSTEM.ADDRESS)
                      return BOOLEAN;

function RemoveMultipleSignals(namestart_address : SYSTEM.ADDRESS)
                               return INTEGER;

function InstallSignal(name_address : SYSTEM.ADDRESS;
                       units_address : SYSTEM.ADDRESS;
                       ptrToStaticVar_address : SYSTEM.ADDRESS;
                       type_address : SYSTEM.ADDRESS)
                       return BOOLEAN;

procedure SignalsShow;

function ArmTrigger return BOOLEAN;

procedure ImmediateTrigger;

procedure DisableTrigger;

procedure CollectSignals;

procedure ChangeSampleRate(newSampleRate : FLOAT);

function SetTrigger(source_address : SYSTEM.ADDRESS;
                    level : FLOAT;
                    slope : INTEGER;
                    probedelay : INTEGER)
                    return BOOLEAN;

function GetTrigger(source_address : SYSTEM.ADDRESS;
                    level_address : SYSTEM.ADDRESS;
                    slope_address : SYSTEM.ADDRESS;
                    delay_address : SYSTEM.ADDRESS;
                    armed_address : SYSTEM.ADDRESS)
                    return BOOLEAN;

function RequestSamplingParameters(sampleDivisor_address : SYSTEM.ADDRESS;
                                   numberOfSamples_address : SYSTEM.ADDRESS)
                                   return BOOLEAN;

function CollectMeasurements return INTEGER;

procedure AbortMeasurements;

function GetMeasurement(signalName_address : SYSTEM.ADDRESS;
                        number : INTEGER)
                        return FLOAT;

function GetAverageMeasurement(signalName_address : SYSTEM.ADDRESS;
                               avgvalue_address : SYSTEM.ADDRESS)
                               return INTEGER;

function GetIntegralMeasurement(gateName_address : SYSTEM.ADDRESS;
                                gateStart_address : SYSTEM.ADDRESS;
                                gateEnd_address : SYSTEM.ADDRESS;
                                signalName_address : SYSTEM.ADDRESS;
                                integratedSignalValue_address : SYSTEM.ADDRESS)
                                return FLOAT;

function sis(name_address : SYSTEM.ADDRESS;
             units_address : SYSTEM.ADDRESS;
             ptrToStaticVar_address : SYSTEM.ADDRESS;
             type_address : SYSTEM.ADDRESS)
             return INTEGER;

function LinkStart(bufSize : size_t;
                   debuglevel : INTEGER;
                   probeHost_address : SYSTEM.ADDRESS)
                   return INTEGER;

function ProbeStart(bufSize : size_t;
                    debuglevel : INTEGER)
                    return INTEGER;

function InitServer(bufSize : size_t;
                    debuglevel : INTEGER)
                    return INTEGER;

private
  pragma interface(C, MaxSamples);
  pragma interface_name(MaxSamples, c_prefix & "ScopeMaxSamples");

  pragma interface(C, SendScript);
  pragma interface_name(SendScript, c_prefix & "ScopeSendScript");

  pragma interface(C, ClearScript);
  pragma interface_name(ClearScript, c_prefix & "ScopeClearScript");

  pragma interface(C, SendAnnotation);
  pragma interface_name(SendAnnotation, c_prefix & "ScopeSendAnnotation");

  pragma interface(C, ClearAnnotation);
  pragma interface_name(ClearAnnotation, c_prefix & "ScopeClearAnnotation");

  pragma interface(C, RemoveSignal);
  pragma interface_name(RemoveSignal, c_prefix & "ScopeRemoveSignal");

  pragma interface(C, RemoveMultipleSignals);
  pragma interface_name(RemoveMultipleSignals,
                        c_prefix & "ScopeRemoveMultipleSignals");

  pragma interface(C, InstallSignal);
  pragma interface_name(InstallSignal, c_prefix & "ScopeInstallSignal");

  pragma interface(C, SignalsShow);
  pragma interface_name(SignalsShow, c_prefix & "ScopeSignalsShow");

  pragma interface(C, ArmTrigger);
  pragma interface_name(ArmTrigger, c_prefix & "ScopeArmTrigger");

  pragma interface(C, ImmediateTrigger);
  pragma interface_name(ImmediateTrigger, c_prefix & "ScopeImmediateTrigger");

  pragma interface(C, DisableTrigger);
  pragma interface_name(DisableTrigger, c_prefix & "ScopeDisableTrigger");

  pragma interface(C, CollectSignals);
  pragma interface_name(CollectSignals, c_prefix & "ScopeCollectSignals");

  pragma interface(C, ChangeSampleRate);
  pragma interface_name(ChangeSampleRate, c_prefix & "ScopeChangeSampleRate");

  pragma interface(C, SetTrigger);
  pragma interface_name(SetTrigger, c_prefix & "ScopeSetTrigger");

  pragma interface(C, GetTrigger);
  pragma interface_name(GetTrigger, c_prefix & "ScopeGetTrigger");

  pragma interface(C, RequestSamplingParameters);
  pragma interface_name(RequestSamplingParameters,
                          c_prefix & "ScopeRequestSamplingParameters");

  pragma interface(C, CollectMeasurements);
  pragma interface_name(CollectMeasurements,
                        c_prefix & "ScopeCollectMeasurements");

  pragma interface(C, AbortMeasurements);
  pragma interface_name(AbortMeasurements,
                        c_prefix & "ScopeAbortMeasurements");

  pragma interface(C, GetMeasurement);
  pragma interface_name(GetMeasurement, c_prefix & "ScopeGetMeasurement");

  pragma interface(C, GetAverageMeasurement);
  pragma interface_name(GetAverageMeasurement,
                        c_prefix & "ScopeGetAverageMeasurement");

  pragma interface(C, GetIntegralMeasurement);
  pragma interface_name(GetIntegralMeasurement,
                        c_prefix & "ScopeGetIntegralMeasurement");

  pragma interface(C, sis);
  pragma interface_name(sis, c_prefix & "sis");

  pragma interface(C, LinkStart);
  pragma interface_name(LinkStart, c_prefix & "ScopeLinkStart");

  pragma interface(C, ProbeStart);
  pragma interface_name(ProbeStart, c_prefix & "ScopeProbeStart");

  pragma interface(C, InitServer);
  pragma interface_name(InitServer, c_prefix & "ScopeInitServer");

end Scope;

package body Scope is

  function A_to_C (Item : in String) return String is
    Result : String (1..Item'Last+1);
  begin
    Result(1..Item'Last) := Item;
    Result(Item'Last+1) := ASCII.NUL;
    return Result;
  end A_to_C;

  procedure A_to_C (Item : in String; Result : out String) is
  begin
    Result(1..Item'Last) := Item;
    for i in Item'Last+1 .. Result'Last-1 loop
      Result(i) := ' ';
    end loop;
    Result(Result'Last) := ASCII.NUL;
  end A_to_C;

 end Scope;
 
  -- Package:  Profile
  -- File Name:  Profile_Bindings.a
  -- Purpose:  Allows interfacing between ADA code and Stethescope Profile
  --           software such that Stethescope Profile commands can be
  --           called from ADA.
  -- Author:  Rob Steele, Kevin Wedeward
  -- Creation Data:  Created July 27, 1992
  -- Information:  This package has not been tested.
  --
  --               If there are any questions, Rob Steele can be called at
  --               (818) 354-5837 or sent email at
  --               steele@telerobotics.jpl.nasa.gov and Kevin Wedeward can
  --               be sent email at kwedewar@nmsu.edu.
  --              
  -- Warranty:  Absolutely no warranty exists for this binding.
  -- Jet Propulsion Laboratory
  -- Supervisory Telerobotics Laboratory
  -- Copywrite C 1992, California Institute of Technology.
  -- U.S. Government Sponsorship under NASA Contract NAS7-918 is acknowledged.

with system;
with vxTypes;		use vxTypes;
with vxWorks;		use vxWorks;
with language;		use language;
with unsigned_types;	use unsigned_types;

package Profile is

procedure Sample(pi_address : SYSTEM.ADDRESS);

procedure ConnectClk(useSysClk : BOOLEAN;
                     pi_address : SYSTEM.ADDRESS);

function Init(clock : INTEGER;
              tid : INTEGER;
              granularity : INTEGER;
              scopeDisable : BOOLEAN;
              maxSamples : INTEGER;
              maxStack : INTEGER)
              return SYSTEM.ADDRESS;

procedure Sort(sortKey : INTEGER;
               waitUntilDone : BOOLEAN;
               pi_address : SYSTEM.ADDRESS);

procedure SortTree(sortKey : INTEGER;
                   waitUntilDone : BOOLEAN;
                   pi_address : SYSTEM.ADDRESS);

procedure ShowStatus(pi_address : SYSTEM.ADDRESS);

procedure Show(maxcount : INTEGER;
               verbosity : INTEGER;
               pi_address : SYSTEM.ADDRESS);

procedure ShowTop(maxCount : INTEGER;
                  sortKey : INTEGER;
                  verbosity : INTEGER;
                  pi_address : SYSTEM.ADDRESS);

procedure ShowTasks(pi_address : SYSTEM.ADDRESS);

procedure ShowAll(sortKey : INTEGER;
                  verbosity : INTEGER;
                  pi_address : SYSTEM.ADDRESS);

procedure ShowTree(nameStart_address : SYSTEM.ADDRESS;
                   verbosity : INTEGER;
                   minPercentage : FLOAT;
                   pi_address : SYSTEM.ADDRESS);

procedure InstallTop(count : INTEGER;
                     sortKey : INTEGER;
                     pi_address : SYSTEM.ADDRESS);

procedure InstallByName(nameStart_address : SYSTEM.ADDRESS;
                        limit : INTEGER;
                        pi_address : SYSTEM.ADDRESS);

procedure RemoveByName(nameStart_address : SYSTEM.ADDRESS;
                       pi_address : SYSTEM.ADDRESS);

procedure InstallTasks(pi_address : SYSTEM.ADDRESS);

procedure InstallAllTasks(disableInstallTasks : BOOLEAN;
                          pi_address : SYSTEM.ADDRESS);

procedure RemoveTasks(pi_address : SYSTEM.ADDRESS);

procedure SetAnalysisRate(requestedSR : FLOAT;
                          pi_address : SYSTEM.ADDRESS);

procedure SetSampleRate(requestedSR : FLOAT;
                        pi_address : SYSTEM.ADDRESS);

procedure SetRates(sampleRate : FLOAT;
                   analysisRate : FLOAT;
                   pi_address : SYSTEM.ADDRESS);

procedure SetFilter(pole : FLOAT;
                    pi_address : SYSTEM.ADDRESS);

procedure SetTaskFilter(pole : FLOAT;
                        pi_address : SYSTEM.ADDRESS);

procedure Clear(killEntries : BOOLEAN;
                dontWaitForBufferClear : BOOLEAN;
                pi_address : SYSTEM.ADDRESS);

function SetMode(tid : INTEGER;
                 granularity : INTEGER;
                 processSampling : BOOLEAN;
                 dontClear : BOOLEAN;
                 pi_address : SYSTEM.ADDRESS)
                 return BOOLEAN;

procedure SetOptions(traceOS : BOOLEAN;
                     showNotReady : BOOLEAN;
                     localOSSymbols : BOOLEAN;
                     traceInterrupts : BOOLEAN;
                     dontClear : BOOLEAN;
                     pi_address : SYSTEM.ADDRESS);

procedure SetTaskIgnore(tid : INTEGER;
                        ignore : BOOLEAN;
                        pi_address : SYSTEM.ADDRESS);

procedure Freeze(freeze : BOOLEAN;
                 pi_address : SYSTEM.ADDRESS);

procedure Kill(pi_address : SYSTEM.ADDRESS);

procedure SetMemoryLimits(memoryBottom : UNSIGNED_INTEGER;
                          memoryTop : UNSIGNED_INTEGER);

private
  pragma interface(C, Sample);
  pragma interface_name(Sample, c_prefix & "ProfileSample");

  pragma interface(C, ConnectClk);
  pragma interface_name(ConnectClk, c_prefix & "ProfileConnectClk");

  pragma interface(C, Init);
  pragma interface_name(Init, c_prefix & "ProfileInit");

  pragma interface(C, Sort);
  pragma interface_name(Sort, c_prefix & "ProfileSort");

  pragma interface(C, SortTree);
  pragma interface_name(SortTree, c_prefix & "ProfileSortTree");

  pragma interface(C, ShowStatus);
  pragma interface_name(ShowStatus, c_prefix & "ProfileShowStatus");

  pragma interface(C, Show);
  pragma interface_name(Show, c_prefix & "ProfileShow");

  pragma interface(C, ShowTop);
  pragma interface_name(ShowTop, c_prefix & "ProfileShowTop");

  pragma interface(C, ShowTasks);
  pragma interface_name(ShowTasks, c_prefix & "ProfileShowTasks");

  pragma interface(C, ShowAll);
  pragma interface_name(ShowAll, c_prefix & "ProfileShowAll");

  pragma interface(C, ShowTree);
  pragma interface_name(ShowTree, c_prefix & "ProfileShowTree");

  pragma interface(C, InstallTop);
  pragma interface_name(InstallTop, c_prefix & "ProfileInstalltop");

  pragma interface(C, InstallByName);
  pragma interface_name(InstallByName, c_prefix & "ProfileInstallByName");

  pragma interface(C, RemoveByName);
  pragma interface_name(RemoveByName, c_prefix & "ProfileRemoveByName");

  pragma interface(C, InstallTasks);
  pragma interface_name(InstallTasks, c_prefix & "ProfileInstallTasks");

  pragma interface(C, InstallAllTasks);
  pragma interface_name(InstallAllTasks, c_prefix & "ProfileInstallAllTasks");

  pragma interface(C, RemoveTasks);
  pragma interface_name(RemoveTasks, c_prefix & "ProfileRemoveTasks");

  pragma interface(C, SetAnalysisRate);
  pragma interface_name(SetAnalysisRate, c_prefix & "ProfileSetAnalysisRate");

  pragma interface(C, SetSampleRate);
  pragma interface_name(SetSampleRate, c_prefix & "ProfileSetSampleRate");

  pragma interface(C, SetRates);
  pragma interface_name(SetRates, c_prefix & "ProfileSetRates");

  pragma interface(C, SetFilter);
  pragma interface_name(SetFilter, c_prefix & "ProfileSetFilter");

  pragma interface(C, SetTaskFilter);
  pragma interface_name(SetTaskFilter, c_prefix & "ProfileSetTaskFilter");

  pragma interface(C, Clear);
  pragma interface_name(Clear, c_prefix & "ProfileClear");

  pragma interface(C, SetMode);
  pragma interface_name(SetMode, c_prefix & "ProfileSetMode");

  pragma interface(C, SetOptions);
  pragma interface_name(SetOptions, c_prefix & "ProfileSetOptions");

  pragma interface(C, SetTaskIgnore);
  pragma interface_name(SetTaskIgnore, c_prefix & "ProfileSetTaskIgnore");

  pragma interface(C, Freeze);
  pragma interface_name(Freeze, c_prefix & "ProfileFreeze");

  pragma interface(C, Kill);
  pragma interface_name(Kill, c_prefix & "ProfileKill");

  pragma interface(C, SetMemoryLimits);
  pragma interface_name(SetMemoryLimits, c_prefix & "ProfileSetMemoryLimits");

end Profile;


-- Sample code:
...
    Name : String (1..31);
    Units : String (1..11);
    Scope_Int : constant String := Scope.INT_CONSTANT;
    Scope_Double : constant String := Scope.DOUBLE_CONSTANT;
    Scope_Float : constant String := Scope.FLOAT_CONSTANT;
...

    for i in JOINT_SPACE_RANGE loop
      if i = 1 then
        Scope.A_to_C ("Radians", Units);
        Scope.A_to_C("Modeled Info (CP), J" & JOINT_SPACE_RANGE'Image(i), Name);
        Scope.OK := Scope.InstallSignal
                      (Name'Address,
                       Units'Address,
                       RR_Modeled_Info.Current_Position(i)'Address,
                       Scope_Double'Address);
        if not Scope.OK then
          Put_Line ("error installing signal " & Name);
        end if;
      end if;
    end loop;
...
    -- Inside of a periodic section of code
...
       Scope.CollectSignals;
...