This might be a nobrainer but as a novice i can not get my head around it.
I have a function returning a fixed size array. I am trying to convert this array into a record of the same size
The function signature is like this:
type Control is new UInt8_Array (1 .. 2);
function readControl (Command : Control) return Control;
I am trying to get the two bytes (UInt8) into the record Contro_Status_Bytes with the following definition:
type Control_Status_MSB is
record
RES_UP : Boolean;
QMAX_UP : Boolean;
BCA : Boolean;
CCA : Boolean;
CALMODE : Boolean;
SS : Boolean;
WDRESET : Boolean;
SHUTDOWNEN : Boolean;
end record;
for Control_Status_MSB use
record
RES_UP at 0 range 0 .. 0;
QMAX_UP at 0 range 1 .. 1;
BCA at 0 range 2 .. 2;
CCA at 0 range 3 .. 3;
CALMODE at 0 range 4 .. 4;
SS at 0 range 5 .. 5;
WDRESET at 0 range 6 .. 6;
SHUTDOWNEN at 0 range 7 .. 7;
end record;
type Control_Status_LSB is
record
VOK : Boolean;
RUP_DIS : Boolean;
LDMD : Boolean;
SLEEP : Boolean;
HIBERNATE : Boolean;
INITCOMP : Boolean;
end record;
for Control_Status_LSB use
record
VOK at 0 range 1 .. 1;
end record;
type Control_Status_Bytes is
record
HighByte : Control_Status_MSB;
LowByte : Control_Status_LSB;
end record;
I think it must be possible to convert the array to the record and vice versa without an unchecked conversion. But currently i am missing something.
Update: This might be an valid answer/way to do that i came up after reading @Simons answer.
function readControl (Command : Control) return Control_Status_Bytes is
CSB : Control_Status_Bytes;
begin
-- do stuff return UInt8_Array of size 2 as response
CSB.HighByte := response'First;
CSB.LowByte := response'Last;
return CSB;
end readControl;