Skip to content

Commit

Permalink
Implement validation of individual parameters in a table for `Validat…
Browse files Browse the repository at this point in the history
…e` case
  • Loading branch information
Jbsco committed Aug 5, 2024
1 parent 2b9f1eb commit 510a5e4
Showing 1 changed file with 38 additions and 54 deletions.
92 changes: 38 additions & 54 deletions src/components/parameters/component-parameters-implementation.adb
Original file line number Diff line number Diff line change
Expand Up @@ -460,67 +460,51 @@ package body Component.Parameters.Implementation is
-- Compute the CRC over the incoming table:
Computed_Crc : constant Crc_16.Crc_16_Type := Self.Crc_Parameter_Table (To_Byte_Array (Ptr));
begin
-- If the CRCs do not match then throw an event
-- 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)));
To_Return := (Region => Arg.Region, Status => Crc_Error);
else
To_Return := (Region => Arg.Region, Status => Success);
end if;
end;
-- TODO Check the individual component parameter validation status:
-- Search through our entries linearly to see if a parameter with the id is found:
-- for Idx in Self.Entries.all'Range loop
-- declare
-- Param_Entry : Parameters_Component_Types.Parameter_Table_Entry renames Self.Entries.all (Idx);
-- begin
-- -- See if this entry contains the ID we are looking for.
-- if Arg.Header.Id = Param_Entry.Id then
-- declare
-- -- Calculate expected parameter length:
-- Param_Length : constant Parameter_Types.Parameter_Buffer_Length_Type := Param_Entry.End_Index - Param_Entry.Start_Index + 1;
-- begin
-- -- See if the length in the header is what we expect.
-- if Arg.Header.Buffer_Length /= Param_Length then
-- Self.Event_T_Send_If_Connected (Self.Events.Parameter_Update_Length_Mismatch (Self.Sys_Time_T_Get, (
-- Header => Arg.Header,
-- Expected_Length => Param_Length)
-- ));
-- return Failure;
-- else
-- -- OK everything looks good, let's stage the parameter.
-- if Self.Stage_Parameter (Param_Entry => Param_Entry, Value => Arg.Buffer) /= Success then
-- -- No need to throw an event, because an event is thrown in the function above
-- -- if something doesn't go well.
-- return Failure;
-- end if;

-- -- 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.
-- return Failure;
-- end if;

-- -- Send out a new parameter's packet if configured to do so:
-- if Self.Dump_Parameters_On_Change then
-- declare
-- -- Just call the dump parameter's command handler.
-- Stat : constant Command_Execution_Status.E := Self.Dump_Parameters;
-- begin
-- if Stat /= Success then
-- return Stat;
-- end if;
-- end;
-- end if;

-- -- If we got here than everything worked as expected:
-- Self.Event_T_Send_If_Connected (Self.Events.Parameter_Update_Success (Self.Sys_Time_T_Get, (Id => Arg.Header.Id)));
-- return Success;
-- end if;
-- end;
-- 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 510a5e4

Please sign in to comment.