Skip to content

Commit

Permalink
Modify Validate case to use helper fcns with added operation arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Jbsco committed Aug 6, 2024
1 parent ad27156 commit 34720ce
Showing 1 changed file with 8 additions and 44 deletions.
52 changes: 8 additions & 44 deletions src/components/parameters/component-parameters-implementation.adb
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,12 @@ package body Component.Parameters.Implementation is
end Stage_Parameter;

-- 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
function Update_Parameters (Self : in out Instance; Component_Id : in Connector_Types.Connector_Index_Type; Operation : in Parameter_Operation_Type.E := Update) 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_Update : Parameter_Update.T := (
Operation => Update,
Operation => Operation,
Status => Success,
Param => (Header => (Id => 0, Buffer_Length => 0), Buffer => [others => 0]
));
Expand All @@ -319,7 +319,7 @@ package body Component.Parameters.Implementation is
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
function Update_Parameter_Table (Self : in out Instance; Region : in Memory_Region.T; Operation : in Parameter_Operation_Type.E := Parameter_Operation_Type.Update) 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;
Expand Down Expand Up @@ -368,7 +368,7 @@ package body Component.Parameters.Implementation is
-- OK, now we need to update 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.Update_Parameters (Component_Id => Idx));
Set_Status (Self.Update_Parameters (Component_Id => Idx), (Operation => Operation));
end if;
end loop;

Expand Down Expand Up @@ -446,7 +446,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 +462,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)));
-- Return immediately with the memory pointer and 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.Update_Parameter_Table (Arg.Region, Validate);
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 Expand Up @@ -567,7 +531,7 @@ package body Component.Parameters.Implementation is
return Failure;
end if;

-- Now let's update the parameter.
-- Now let's update the parameter.>
if Self.Update_Parameters (Component_Id => Param_Entry.Component_Id) /= Success then
-- No need to throw an event, because an event is thrown in the function above
-- if something doesn't go well.
Expand Down

0 comments on commit 34720ce

Please sign in to comment.