Skip to content

Commit

Permalink
Add helper functions for Validation case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jbsco committed Aug 6, 2024
1 parent 65c2708 commit 08f052b
Showing 1 changed file with 84 additions and 44 deletions.
128 changes: 84 additions & 44 deletions src/components/parameters/component-parameters-implementation.adb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,25 @@ package body Component.Parameters.Implementation is
return Param_Update.Status;
end Stage_Parameter;

-- Helper function to send a validation for a single components parameters:
function Validate_Parameters (Self : in out Instance; Component_Id : in Connector_Types.Connector_Index_Type) return Parameter_Enums.Parameter_Update_Status.E is
use Parameter_Enums.Parameter_Update_Status;
use Parameter_Enums.Parameter_Operation_Type;
-- Create a parameter update record:
Param_Validate : Parameter_Update.T := (
Operation => Validate,
Status => Success,
Param => (Header => (Id => 0, Buffer_Length => 0), Buffer => [others => 0]
));
-- Component index:
Idx : constant Parameter_Update_T_Provide_Index := Parameter_Update_T_Provide_Index (Component_Id);
begin
-- Send the parameter fetch request to the appropriate component:
Self.Parameter_Update_T_Provide (Idx, Param_Validate);

return Param_Validate.Status;
end Validate_Parameters;

-- Helper function to send an update for a single components parameters:
function Update_Parameters (Self : in out Instance; Component_Id : in Connector_Types.Connector_Index_Type) return Parameter_Enums.Parameter_Update_Status.E is
use Parameter_Enums.Parameter_Update_Status;
Expand Down Expand Up @@ -318,8 +337,8 @@ package body Component.Parameters.Implementation is
return Param_Update.Status;
end Update_Parameters;

-- Helper function to update all connected component's parameter tables from data within a provided memory region.
function Update_Parameter_Table (Self : in out Instance; Region : in Memory_Region.T) return Parameters_Memory_Region_Release.T is
-- Helper function to stage all connected component's parameter tables from data within a provided memory region.
function Stage_Parameter_Table (Self : in out Instance; Region : in Memory_Region.T) return Parameter_Enums.Parameter_Table_Update_Status.E is
use Parameter_Enums.Parameter_Update_Status;
use Parameter_Enums.Parameter_Table_Update_Status;
Status_To_Return : Parameter_Enums.Parameter_Table_Update_Status.E := Success;
Expand All @@ -337,9 +356,6 @@ package body Component.Parameters.Implementation is
end if;
end Set_Status;
begin
-- Send info event:
Self.Event_T_Send_If_Connected (Self.Events.Starting_Parameter_Table_Update (Self.Sys_Time_T_Get, Region));

-- Go through all our entries linearly, extracting data from the incoming memory region, and
-- using the values stored there as values to stage our parameters.
for Param_Entry of Self.Entries.all loop
Expand All @@ -364,6 +380,66 @@ package body Component.Parameters.Implementation is
Set_Status (Self.Stage_Parameter (Param_Entry => Param_Entry, Value => Value));
end;
end loop;
return Status_To_Return;
end Stage_Parameter_Table;

-- Helper function to update all connected component's parameter tables from data within a provided memory region.
function Validate_Parameter_Table (Self : in out Instance; Region : in Memory_Region.T) return Parameters_Memory_Region_Release.T is
use Parameter_Enums.Parameter_Update_Status;
use Parameter_Enums.Parameter_Table_Update_Status;
Status_To_Return : Parameter_Enums.Parameter_Table_Update_Status.E := Success;

-- If the status returned is not success then set our status to return to a parameter error.
procedure Set_Status (Stat : in Parameter_Enums.Parameter_Update_Status.E) is
begin
-- Check the return status. Even if it is bad, we still continue to try to stage
-- the rest of the parameters.
if Stat /= Success then
Status_To_Return := Parameter_Error;
end if;
end Set_Status;
begin
-- Stage all of the parameters:
Status_To_Return := Self.Stage_Parameter_Table (Region);

-- OK, now we need to validate all the parameters.
for Idx in Self.Connector_Parameter_Update_T_Provide'Range loop
if Self.Is_Parameter_Update_T_Provide_Connected (Idx) then
Set_Status (Self.Validate_Parameters (Component_Id => Idx));
end if;
end loop;

-- Send out a new parameter's packet if configured to do so:
if Self.Dump_Parameters_On_Change then
-- Send the packet:
Set_Status (Self.Send_Parameters_Packet);
end if;

-- Return the memory pointer with the status for deallocation.
return (Region => Region, Status => Status_To_Return);
end Validate_Parameter_Table;

-- Helper function to update all connected component's parameter tables from data within a provided memory region.
function Update_Parameter_Table (Self : in out Instance; Region : in Memory_Region.T) return Parameters_Memory_Region_Release.T is
use Parameter_Enums.Parameter_Update_Status;
use Parameter_Enums.Parameter_Table_Update_Status;
Status_To_Return : Parameter_Enums.Parameter_Table_Update_Status.E := Success;

-- If the status returned is not success then set our status to return to a parameter error.
procedure Set_Status (Stat : in Parameter_Enums.Parameter_Update_Status.E) is
begin
-- Check the return status. Even if it is bad, we still continue to try to stage
-- the rest of the parameters.
if Stat /= Success then
Status_To_Return := Parameter_Error;
end if;
end Set_Status;
begin
-- Send info event:
Self.Event_T_Send_If_Connected (Self.Events.Starting_Parameter_Table_Update (Self.Sys_Time_T_Get, Region));

-- Stage all of the parameters:
Status_To_Return := Self.Stage_Parameter_Table (Region);

-- OK, now we need to update all the parameters.
for Idx in Self.Connector_Parameter_Update_T_Provide'Range loop
Expand Down Expand Up @@ -446,7 +522,6 @@ package body Component.Parameters.Implementation is
when Get =>
To_Return := Self.Copy_Parameter_Table_To_Region (Arg.Region);
when Validate =>
-- Validate the parameter table.
-- Length is checked at the beginning of this procedure.
-- Check the CRC:
declare
Expand All @@ -463,48 +538,13 @@ package body Component.Parameters.Implementation is
-- If the CRCs do not match then throw an event and set return to CRC error:
if Table_Header.Crc_Table /= Computed_Crc then
Self.Event_T_Send_If_Connected (Self.Events.Memory_Region_Crc_Invalid (Self.Sys_Time_T_Get, (Parameters_Region => Arg, Header => Table_Header, Computed_Crc => Computed_Crc)));
-- Set status:
To_Return := (Region => Arg.Region, Status => Crc_Error);
else
To_Return := (Region => Arg.Region, Status => Success);
-- CRC is okay, continue with validating the parameter table:
To_Return := Self.Validate_Parameter_Table (Arg.Region);
end if;
end;
-- Check the individual component parameter validation status:
declare
use Parameter_Enums.Parameter_Update_Status;
use Parameter_Enums.Parameter_Operation_Type;
begin
-- Go through all entries linearly to validate parameters.
for Param_Entry of Self.Entries.all loop
declare
-- Calculate the parameters length:
Param_Length : constant Parameter_Types.Parameter_Buffer_Length_Type := Param_Entry.End_Index - Param_Entry.Start_Index + 1;
-- Create a parameter validate record:
Param_Validate : Parameter_Update.T := (
Operation => Validate,
Status => Success,
Param => (Header => (Id => Param_Entry.Id, Buffer_Length => Param_Length), Buffer => [others => 0]
));
-- Create a temporary buffer to hold the parameter value:
Value : constant Parameter_Types.Parameter_Buffer_Type := [others => 0];
-- Component index:
Idx : constant Parameter_Update_T_Provide_Index := Parameter_Update_T_Provide_Index (Param_Entry.Component_Id);
begin
-- Validate the parameter:
-- Copy over value into record:
Param_Validate.Param.Buffer (Param_Validate.Param.Buffer'First .. Param_Validate.Param.Buffer'First + Param_Length - 1)
:= Value (Param_Validate.Param.Buffer'First .. Param_Validate.Param.Buffer'First + Param_Length - 1);

-- Send the parameter fetch request to the appropriate component:
Self.Parameter_Update_T_Provide (Idx, Param_Validate);

-- Make sure the status is successful. If it is not, then produce an event.
if Param_Validate.Status /= Success then
To_Return := (Region => Arg.Region, Status => Parameter_Error);
end if;
end;
end loop;
-- If this point was reached without changing To_Return, then it should still be Success
end;
end case;
end if;

Expand Down

0 comments on commit 08f052b

Please sign in to comment.