Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
--------------------------------------------------------------------------------
-- Sunline_Srukf Component Implementation Body
--------------------------------------------------------------------------------

with Nav_Att.C;
with Sunline_Srukf_Input.C;
with Sunline_Srukf_Output.C;
with Sunline_Srukf_Algorithm_C; use Sunline_Srukf_Algorithm_C;
with Algorithm_Wrapper_Util;

package body Component.Sunline_Srukf.Implementation is

--------------------------------------------------
-- Subprogram for implementation init method:
--------------------------------------------------
-- Initializes the sunline SRuKF algorithm.
overriding procedure Init (Self : in out Instance) is
pragma Unreferenced (Self);
begin
-- Stateless algorithm, nothing to initialize.
null;
end Init;

---------------------------------------
-- Invokee connector primitives:
---------------------------------------
-- Run the algorithm up to the current time.
overriding procedure Tick_T_Recv_Sync (Self : in out Instance; Arg : in Tick.T) is
use Data_Product_Enums;
use Data_Product_Enums.Data_Dependency_Status;
use Algorithm_Wrapper_Util;

-- Grab data dependencies:
Sc_Att : Nav_Att.T;
Sc_Att_Status : constant Data_Dependency_Status.E :=
Self.Get_Spacecraft_Attitude (Value => Sc_Att, Stale_Reference => Arg.Time);
begin
if Is_Dep_Status_Success (Sc_Att_Status) then
-- Call algorithm:
declare
Sc_Att_C : constant Nav_Att.C.U_C := Nav_Att.C.To_C (Nav_Att.Unpack (Sc_Att));

-- Build algorithm input from nav att data:
Input_C : aliased Sunline_Srukf_Input.C.U_C := (
Time_Tag => Sc_Att_C.Time_Tag,
Sigma_Bn => Sc_Att_C.Sigma_Bn,
Omega_Bn_B => Sc_Att_C.Omega_Bn_B,
Veh_Sun_Pnt_Bdy => Sc_Att_C.Veh_Sun_Pnt_Bdy,
N_Css => 0,
Cos_Values => [others => 0.0]
);

-- Call the C algorithm:
Output_C : constant Sunline_Srukf_Output.C.U_C := Update_State (
Input => Input_C'Unchecked_Access
);
begin
-- Send out data product:
Self.Data_Product_T_Send (Self.Data_Products.Sunline_Srukf_State (
Arg.Time,
Sunline_Srukf_Output.Pack (Sunline_Srukf_Output.C.To_Ada (Output_C))
));
end;
end if;
end Tick_T_Recv_Sync;

-----------------------------------------------
-- Data dependency handlers:
-----------------------------------------------
-- Description:
-- Data dependencies for the Sunline SRuKF component.
-- Invalid data dependency handler. This procedure is called when a data dependency's id or length are found to be invalid:
overriding procedure Invalid_Data_Dependency (Self : in out Instance; Id : in Data_Product_Types.Data_Product_Id; Ret : in Data_Product_Return.T) is
pragma Annotate (GNATSAS, Intentional, "subp always fails", "intentional assertion");
begin
-- None of the data dependencies should be invalid in this case.
pragma Assert (False);
end Invalid_Data_Dependency;

end Component.Sunline_Srukf.Implementation;
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
--------------------------------------------------------------------------------
-- Sunline_Srukf Component Implementation Spec
--------------------------------------------------------------------------------

-- Includes:
with Tick;

-- Sunline SRuKF pass-through algorithm wrapping the C++ SunlineSRuKFAlgorithm.
package Component.Sunline_Srukf.Implementation is

-- The component class instance record:
type Instance is new Sunline_Srukf.Base_Instance with private;

--------------------------------------------------
-- Subprogram for implementation init method:
--------------------------------------------------
-- Initializes the sunline SRuKF algorithm.
overriding procedure Init (Self : in out Instance);

private

-- The component class instance record:
type Instance is new Sunline_Srukf.Base_Instance with record
null;
end record;

---------------------------------------
-- Set Up Procedure
---------------------------------------
-- Null method which can be implemented to provide some component
-- set up code. This method is generally called by the assembly
-- main.adb after all component initialization and tasks have been started.
-- Some activities need to only be run once at startup, but cannot be run
-- safely until everything is up and running, ie. command registration, initial
-- data product updates. This procedure should be implemented to do these things
-- if necessary.
overriding procedure Set_Up (Self : in out Instance) is null;

---------------------------------------
-- Invokee connector primitives:
---------------------------------------
-- Run the algorithm up to the current time.
overriding procedure Tick_T_Recv_Sync (Self : in out Instance; Arg : in Tick.T);

---------------------------------------
-- Invoker connector primitives:
---------------------------------------
-- This procedure is called when a Data_Product_T_Send message is dropped due to a full queue.
overriding procedure Data_Product_T_Send_Dropped (Self : in out Instance; Arg : in Data_Product.T) is null;

-----------------------------------------------
-- Data dependency primitives:
-----------------------------------------------
-- Description:
-- Data dependencies for the Sunline SRuKF component.
-- Function which retrieves a data dependency.
-- The default implementation is to simply call the Data_Product_Fetch_T_Request connector. Change the implementation if this component
-- needs to do something different.
overriding function Get_Data_Dependency (Self : in out Instance; Id : in Data_Product_Types.Data_Product_Id) return Data_Product_Return.T is (Self.Data_Product_Fetch_T_Request ((Id => Id)));

-- Invalid data dependency handler. This procedure is called when a data dependency's id or length are found to be invalid:
overriding procedure Invalid_Data_Dependency (Self : in out Instance; Id : in Data_Product_Types.Data_Product_Id; Ret : in Data_Product_Return.T);

end Component.Sunline_Srukf.Implementation;
16 changes: 16 additions & 0 deletions src/components/sunline_srukf/sunline_srukf.component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
description: Sunline SRuKF pass-through algorithm wrapping the C++ SunlineSRuKFAlgorithm.
execution: passive
init:
description: Initializes the sunline SRuKF algorithm.
connectors:
- description: Run the algorithm up to the current time.
type: Tick.T
kind: recv_sync
- description: Fetch a data product item from the database.
type: Data_Product_Fetch.T
return_type: Data_Product_Return.T
kind: request
- description: The data product invoker connector
type: Data_Product.T
kind: send
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
description: Data dependencies for the Sunline SRuKF component.
data_dependencies:
- name: Spacecraft_Attitude
type: Nav_Att.T
description: Spacecraft attitude navigation state (sigma_BN, omega_BN_B, vehSunPntBdy, timeTag)
6 changes: 6 additions & 0 deletions src/components/sunline_srukf/sunline_srukf.data_products.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
description: Data products for the Sunline SRuKF component.
data_products:
- name: Sunline_Srukf_State
type: Sunline_Srukf_Output.T
description: Output state from the sunline SRuKF algorithm (timeTag, sigma_BN, omega_BN_B, vehSunPntBdy).
40 changes: 40 additions & 0 deletions src/components/sunline_srukf/sunline_srukf_algorithm_c.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
pragma Ada_2012;

pragma Style_Checks (Off);
pragma Warnings (Off, "-gnatwu");

with Interfaces.C; use Interfaces; use Interfaces.C;
with Sunline_Srukf_Input.C;
with Sunline_Srukf_Output.C;

package Sunline_Srukf_Algorithm_C is

-- MAX_NUM_CSS must match the #define in sunlineSRuKFAlgorithm_c.h:12
-- Re-run h2ads if the C header changes to regenerate this binding
MAX_NUM_CSS : constant := 32;

--* @brief Get the maximum number of CSS sensors.
--* @return The maximum CSS count (SUNLINE_SRUKF_MAX_NUM_CSS).
function Get_Max_Num_Css
return Unsigned_32
with Import => True,
Convention => C,
External_Name => "SunlineSRuKFAlgorithm_getMaxNumCss";

-- Runtime validation: ensure Ada constant matches C definition
pragma Assert (Unsigned_32 (MAX_NUM_CSS) = Get_Max_Num_Css);

--* @brief Run the sunline SRuKF update step (stateless).
--* @param Input Pointer to the input structure (read-only).
--* @return The computed output.
function Update_State
(Input : Sunline_Srukf_Input.C.U_C_Access)
return Sunline_Srukf_Output.C.U_C
with Import => True,
Convention => C,
External_Name => "SunlineSRuKFAlgorithm_updateState";

end Sunline_Srukf_Algorithm_C;

pragma Style_Checks (On);
pragma Warnings (On, "-gnatwu");
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
--------------------------------------------------------------------------------
-- Sunline_Srukf Component Tester Body
--------------------------------------------------------------------------------

package body Component.Sunline_Srukf.Implementation.Tester is

---------------------------------------
-- Initialize heap variables:
---------------------------------------
procedure Init_Base (Self : in out Instance) is
begin
-- Initialize tester heap:
-- Connector histories:
Self.Data_Product_Fetch_T_Service_History.Init (Depth => 100);
Self.Data_Product_T_Recv_Sync_History.Init (Depth => 100);
-- Data product histories:
Self.Sunline_Srukf_State_History.Init (Depth => 100);
end Init_Base;

procedure Final_Base (Self : in out Instance) is
begin
-- Destroy tester heap:
-- Connector histories:
Self.Data_Product_Fetch_T_Service_History.Destroy;
Self.Data_Product_T_Recv_Sync_History.Destroy;
-- Data product histories:
Self.Sunline_Srukf_State_History.Destroy;
end Final_Base;

---------------------------------------
-- Test initialization functions:
---------------------------------------
procedure Connect (Self : in out Instance) is
begin
Self.Component_Instance.Attach_Data_Product_Fetch_T_Request (To_Component => Self'Unchecked_Access, Hook => Self.Data_Product_Fetch_T_Service_Access);
Self.Component_Instance.Attach_Data_Product_T_Send (To_Component => Self'Unchecked_Access, Hook => Self.Data_Product_T_Recv_Sync_Access);
Self.Attach_Tick_T_Send (To_Component => Self.Component_Instance'Unchecked_Access, Hook => Self.Component_Instance.Tick_T_Recv_Sync_Access);
end Connect;

-- Helper function for returning data dependencies:
function Return_Data_Dependency (Self : in out Instance; Arg : in Data_Product_Fetch.T) return Data_Product_Return.T is
use Data_Product_Types;
use Data_Product_Enums.Fetch_Status;
use Sys_Time;
-- Set default return values. These will be overridden below based on test configuration and
-- the ID requested.
Id_To_Return : Data_Product_Types.Data_Product_Id := Self.Data_Dependency_Return_Id_Override;
Length_To_Return : Data_Product_Types.Data_Product_Buffer_Length_Type := Self.Data_Dependency_Return_Length_Override;
Return_Status : Data_Product_Enums.Fetch_Status.E := Self.Data_Dependency_Return_Status_Override;
Buffer_To_Return : Data_Product_Types.Data_Product_Buffer_Type;
Time_To_Return : Sys_Time.T := Self.Data_Dependency_Timestamp_Override;
begin
-- Determine return data product ID:
if Id_To_Return = 0 then
case Arg.Id is
-- ID for Spacecraft_Attitude:
when 0 => Id_To_Return := 0;
-- If ID can not be found, then return ID out of range error.
when others =>
if Return_Status = Data_Product_Enums.Fetch_Status.Success then
Return_Status := Data_Product_Enums.Fetch_Status.Id_Out_Of_Range;
end if;
end case;
end if;

-- Determine return data product length:
if Length_To_Return = 0 then
case Arg.Id is
-- Length for Spacecraft_Attitude:
when 0 => Length_To_Return := Nav_Att.Size_In_Bytes;
-- If ID can not be found, then return ID out of range error.
when others =>
if Return_Status = Data_Product_Enums.Fetch_Status.Success then
Return_Status := Data_Product_Enums.Fetch_Status.Id_Out_Of_Range;
end if;
end case;
end if;

-- Determine return timestamp:
if Time_To_Return = (0, 0) then
Time_To_Return := Self.System_Time;
end if;

-- Fill the data product buffer:
if Return_Status = Data_Product_Enums.Fetch_Status.Success then
case Arg.Id is
-- Length for Spacecraft_Attitude:
when 0 =>
Buffer_To_Return (Buffer_To_Return'First .. Buffer_To_Return'First + Nav_Att.Size_In_Bytes - 1) :=
Nav_Att.Serialization.To_Byte_Array (Self.Spacecraft_Attitude);
-- Do not fill. The ID is not recognized.
when others =>
Return_Status := Data_Product_Enums.Fetch_Status.Id_Out_Of_Range;
end case;
end if;

-- Return the data product with the status:
return (
The_Status => Return_Status,
The_Data_Product => (
Header => (
Time => Time_To_Return,
Id => Id_To_Return,
Buffer_Length => Length_To_Return
),
Buffer => Buffer_To_Return
)
);
end Return_Data_Dependency;

---------------------------------------
-- Invokee connector primitives:
---------------------------------------
-- Fetch a data product item from the database.
overriding function Data_Product_Fetch_T_Service (Self : in out Instance; Arg : in Data_Product_Fetch.T) return Data_Product_Return.T is
To_Return : constant Data_Product_Return.T := Self.Return_Data_Dependency (Arg);
begin
-- Push the argument onto the test history for looking at later:
Self.Data_Product_Fetch_T_Service_History.Push (Arg);
return To_Return;
end Data_Product_Fetch_T_Service;

-- The data product invoker connector
overriding procedure Data_Product_T_Recv_Sync (Self : in out Instance; Arg : in Data_Product.T) is
begin
-- Push the argument onto the test history for looking at later:
Self.Data_Product_T_Recv_Sync_History.Push (Arg);
-- Dispatch the data product to the correct handler:
Self.Dispatch_Data_Product (Arg);
end Data_Product_T_Recv_Sync;

-----------------------------------------------
-- Data product handler primitive:
-----------------------------------------------
-- Description:
-- Data products for the Sunline SRuKF component.
-- Output state from the sunline SRuKF algorithm (timeTag, sigma_BN, omega_BN_B,
-- vehSunPntBdy).
overriding procedure Sunline_Srukf_State (Self : in out Instance; Arg : in Sunline_Srukf_Output.T) is
begin
-- Push the argument onto the test history for looking at later:
Self.Sunline_Srukf_State_History.Push (Arg);
end Sunline_Srukf_State;

end Component.Sunline_Srukf.Implementation.Tester;
Loading
Loading