Hello together,
I am currently getting into Kaitai to implement a parser for our PEGASUS satellite in SatNOGS. I am failing on implementing some user defined decoding methods. PEGASUS e.g. uses the Q-format to pack its data. Additional information can be found in the Ham Operator Manual page 7.
E.g. the following HEX-number is stored in UFix 3.5 and shall be decoded as followed:
0x7F
→ 0b01111111
→ 0*(2^2) + 1*(2^1) + 1*(2^0) + 1*(2^-1) + 1*(2^-2) + 1*(2^-3) + 1*(2^-4) + 1*(2^-5) = 3.96875 (readable telemtry data for V_PV1)
Any ideas on how to implement this into Kaitai? I have two ideas:
- Extract a raw-frame in
seq
, e.g.:
- id: v_pv1_raw
type: u1
and then perform the decoding in an instance using value:
, e.g.:
instances:
v_pv1:
value: *Ufix3.5 decoding method*
- Use an external code to perform the decoding, e.g. for decoding 1 byte in HEX-format, I have a MWE for a Python-function, which uses a string with the binary data as input:
def Ufix35(Bits='00000000'):
s = int(Bits[0])*(2**2) + int(Bits[1])*(2**1) + int(Bits[2])*(2**0) + int(Bits[3])*(2**-1) + int(Bits[4])*(2**-2) + int(Bits[5])*(2**-3) + int(Bits[6])*(2**-4) + int(Bits[7])*(2**-5)
return s
data = '01111111' # 0x7f
x = Ufix35(data)
print(x)
Nevertheless, I am failing on implementing on both ideas. For idea one, I do not know how to get from 0x7F
to 0b01111111
in Kaitai, in order to implement the decoding routine using value:
. Idea two is titled with “advanced” within the Kaitai user guide. Moreover, there exist several ways to implement it.
I would appreciate any help for implementing this decoding routine, since I am very unexperienced within this field.
For testing I am using data from a SatNOGS observation, which includes a 64 byte O1-Beacon (OBC data) of PEGASUS. Byte 0 is a HEX number and stores the PID (beacon identifier), Byte 1-6 is the CALLSIGN and Byte 7 stores the value for V_PV1 in Ufix3.5 format. For testing the data as well as my Kaitai-file can be downloaded here:
pegasus.zip (444 Bytes).
If needed, detailed information for decoding can be found in the Ham Operator Manual mentioned above.
Many thanks for any help!
Alex