A minimal satnogs-decoders example
This example should eventually move to the wiki (but I didn’t figure out how to use formatted code listings in the wiki yet.
The protocol
source: Cubesat Space Protocol - Wikipedia
An example frame
0x00 0xAB 0x92 0x48
source: data_592806_2019-04-14T09-50-54 from observation 592806 (only the first four bytes)
A Python implementation of the parser
import struct
# Read the frame as binary file
with open("contrib/aausat4_20190414_095054_raw", 'rb') as f:
frame = f.read()
# Unpack the header and parse the fields using bit-shifts & -masks
header=struct.unpack("<I", frame[0:4])[0]
src = ((header >> 25) & 0x1f)
dest = ((header >> 20) & 0x1f)
dest_port = ((header >> 14) & 0x3f)
src_port = ((header >> 8) & 0x3f)
print(src, dest, dest_port, src_port)
# Output: 4, 9, 10, 43
source: aausat4_beacon_parser/parser.py at master · aausat/aausat4_beacon_parser · GitHub
The Kaitai struct implementation
meta:
id: aausat4
file-extension: aausat4
endian: le
seq:
- id: aausat4_frame_raw
type: aausat4_frame_raw
doc-ref: 'https://github.com/aausat/aausat4_beacon_parser/blob/master/parser.py'
types:
aausat4_frame_raw:
seq:
- id: csp_header
type: csp_header
- id: data
type: data
csp_header:
seq:
- id: header
type: u4
instances:
src:
value: ((header >> 25) & 0x1f)
dest:
value: ((header >> 20) & 0x1f)
dest_port:
value: ((header >> 14) & 0x3f)
src_port:
value: ((header >> 8) & 0x3f)
data:
seq:
- id: data_raw
size-eos: true
Example WebIDE output
edit:
- 2019-04-24: Fixed broken hyperlink to the example frame.