Spacecraft Command and Data Handling (space-systems/subsystems/command-data-handling)
Use when the task is spacecraft command and data handling: validating
telecommands, packetizing telemetry into CCSDS-style frames, sizing
onboard storage from collected data volume, budgeting the downlink
against a contact window, or checking C&DH redundancy.
Units convention (stated once): data volume in bits (downlink
functions) or bytes (onboard storage), rates in bits per second, time
in seconds, frames are whole units. Margin fractions are dimensionless
(e.g. 0.1 = 10%).
Domain quick reference
- C&DH is the subsystem that collects payload and housekeeping
telemetry, formats it into packets, stores it onboard, and relays
it to the ground; it also receives, validates, and distributes
uplinked telecommands to the other subsystems.
- Telemetry packetization: a CCSDS-style space packet carries a 6-byte
primary header (version, packet type, APID, sequence flags, sequence
count, packet data length) plus data and a CRC-16 trailer. The
length field stores len(data) - 1, so a 2-byte payload reads 1.
- Error detection: CRC-16-CCITT (poly 0x1021, init 0xFFFF) over
header + data detects any single-bit corruption and most burst
errors; a corrupted packet must be dropped or retransmitted, never
executed.
- Command validation: each telecommand is checked for structural
length, CRC-16 integrity, expected opcode, and addressed APID before
execution; a rejected command is discarded and logged.
- Onboard storage sizing: storage = per-orbit data volume x orbits,
plus a margin (typically 10-30%) for retransmissions, housekeeping
growth, and file-system overhead; round up to whole bytes.
- Downlink budgeting: downlink time = data volume (bits) / link rate
(bps); the stored volume must clear inside the contact window, or
the required rate is volume / window. Storage growth over N orbits
must fit the mass memory until the next downlink opportunity.
- Redundancy: dual-string C&DH keeps the function available while at
least one string is healthy; string loss degrades margin, not
availability, until the second string fails.
Workflow
- Validate the incoming telecommand: check structure and length
field with validate_command_packet, then the CRC-16, then the
expected opcode and APID; execute only on (True, "ok").
- Packetize telemetry with telemetry_packet: choose the APID per
source, increment the 14-bit sequence count per packet (wrap at
16383), and append the CRC-16 trailer.
- Parse and verify on the ground side with parse_telemetry_packet;
a CRC mismatch means the packet is corrupted and must be dropped.
- Size onboard storage with storage_size_bytes from the per-orbit
data volume, the number of orbits between downlinks, and the
sizing margin.
- Budget the downlink: downlink_time_s or data_rate_for_window
against the contact window; close with downlink_fits_window.
- Size the link framing with frame_count and confirm the redundancy
arrangement with redundancy_ok.
Pitfalls
- Executing a command on CRC failure: the checksum is the last line
of defense; a corrupted command must never reach the subsystem.
- Storing len(data) instead of len(data) - 1 in the packet length
field, or parsing it off by one; the CCSDS field is payload minus
one, and the two-byte field is big endian.
- Sizing storage without a margin: retransmissions and file-system
overhead turn a "full" memory into an overwritten one.
- Budgeting the downlink with bytes instead of bits, or mixing
megabits with megabytes.
- Using float ceil on margin arithmetic (3000 x 1.1 can round up to
3301); use integer basis-point math as storage_size_bytes does.
- Forgetting the sequence count is 14 bits: it wraps at 16383, not
- Treating a single healthy string as full redundancy: dual-string
means two independent strings, not one with spares.
Behavior contract (gate 3)
The CRC, packetization, command validation, storage sizing, downlink
budget, framing, and redundancy logic is exercised by the gate 3
contract test: scripts/test_command_data_handling.py against
scripts/command_data_handling_logic.py (stdlib unittest, offline).
Run from the repo root:
python3 skills/space-systems/subsystems/command-data-handling/scripts/test_command_data_handling.py
Compliance
- ECSS standards (E-ST-50 series for space data links and
communication) are freely downloadable from https://ecss.nl/standards/
and copyright ESA; cite the source and paraphrase, per
standards-map.yaml and brief 06. This leaf cites ECSS as reference
only; the logic here is generic C&DH arithmetic (CRC, packet layout,
data rates), not ECSS text.
- compliance: STANDARDS-REF, gated: false.
1---2name: command-data-handling3description: Use when the task is command validation, telemetry packetization, CCSDS framing, onboard data storage sizing, downlink budgeting, spacecraft data bus selection, or C&DH redundancy. Design and check spacecraft command and data handling (C&DH): validate telecommands against opcode, length, and CRC-16 checksum; packetize telemetry into CCSDS-style frames with sequence counts and error detection; size onboard storage from per-orbit data volume; and budget downlink time and rate from stored data volume and link capacity. Computes CRC-16 checksums, byte-exact CCSDS packets, storage sizes, and downlink verdicts with deterministic functions. Trigger: command data handling, telemetry, telecommand, CCSDS, packetization, downlink, CRC-16, onboard storage, data bus, SpaceWire, MIL-STD-1553.4license: Apache-2.05---67# Spacecraft Command and Data Handling (space-systems/subsystems/command-data-handling)89Use when the task is spacecraft command and data handling: validating10telecommands, packetizing telemetry into CCSDS-style frames, sizing11onboard storage from collected data volume, budgeting the downlink12against a contact window, or checking C&DH redundancy.1314Units convention (stated once): data volume in bits (downlink15functions) or bytes (onboard storage), rates in bits per second, time16in seconds, frames are whole units. Margin fractions are dimensionless17(e.g. 0.1 = 10%).1819## Domain quick reference2021- C&DH is the subsystem that collects payload and housekeeping22 telemetry, formats it into packets, stores it onboard, and relays23 it to the ground; it also receives, validates, and distributes24 uplinked telecommands to the other subsystems.25- Telemetry packetization: a CCSDS-style space packet carries a 6-byte26 primary header (version, packet type, APID, sequence flags, sequence27 count, packet data length) plus data and a CRC-16 trailer. The28 length field stores len(data) - 1, so a 2-byte payload reads 1.29- Error detection: CRC-16-CCITT (poly 0x1021, init 0xFFFF) over30 header + data detects any single-bit corruption and most burst31 errors; a corrupted packet must be dropped or retransmitted, never32 executed.33- Command validation: each telecommand is checked for structural34 length, CRC-16 integrity, expected opcode, and addressed APID before35 execution; a rejected command is discarded and logged.36- Onboard storage sizing: storage = per-orbit data volume x orbits,37 plus a margin (typically 10-30%) for retransmissions, housekeeping38 growth, and file-system overhead; round up to whole bytes.39- Downlink budgeting: downlink time = data volume (bits) / link rate40 (bps); the stored volume must clear inside the contact window, or41 the required rate is volume / window. Storage growth over N orbits42 must fit the mass memory until the next downlink opportunity.43- Redundancy: dual-string C&DH keeps the function available while at44 least one string is healthy; string loss degrades margin, not45 availability, until the second string fails.4647## Workflow48491. Validate the incoming telecommand: check structure and length50 field with validate_command_packet, then the CRC-16, then the51 expected opcode and APID; execute only on (True, "ok").522. Packetize telemetry with telemetry_packet: choose the APID per53 source, increment the 14-bit sequence count per packet (wrap at54 16383), and append the CRC-16 trailer.553. Parse and verify on the ground side with parse_telemetry_packet;56 a CRC mismatch means the packet is corrupted and must be dropped.574. Size onboard storage with storage_size_bytes from the per-orbit58 data volume, the number of orbits between downlinks, and the59 sizing margin.605. Budget the downlink: downlink_time_s or data_rate_for_window61 against the contact window; close with downlink_fits_window.626. Size the link framing with frame_count and confirm the redundancy63 arrangement with redundancy_ok.6465## Pitfalls6667- Executing a command on CRC failure: the checksum is the last line68 of defense; a corrupted command must never reach the subsystem.69- Storing len(data) instead of len(data) - 1 in the packet length70 field, or parsing it off by one; the CCSDS field is payload minus71 one, and the two-byte field is big endian.72- Sizing storage without a margin: retransmissions and file-system73 overhead turn a "full" memory into an overwritten one.74- Budgeting the downlink with bytes instead of bits, or mixing75 megabits with megabytes.76- Using float ceil on margin arithmetic (3000 x 1.1 can round up to77 3301); use integer basis-point math as storage_size_bytes does.78- Forgetting the sequence count is 14 bits: it wraps at 16383, not79 65535.80- Treating a single healthy string as full redundancy: dual-string81 means two independent strings, not one with spares.8283## Behavior contract (gate 3)8485The CRC, packetization, command validation, storage sizing, downlink86budget, framing, and redundancy logic is exercised by the gate 387contract test: scripts/test_command_data_handling.py against88scripts/command_data_handling_logic.py (stdlib unittest, offline).89Run from the repo root:90python3 skills/space-systems/subsystems/command-data-handling/scripts/test_command_data_handling.py9192## Compliance9394- ECSS standards (E-ST-50 series for space data links and95 communication) are freely downloadable from https://ecss.nl/standards/96 and copyright ESA; cite the source and paraphrase, per97 standards-map.yaml and brief 06. This leaf cites ECSS as reference98 only; the logic here is generic C&DH arithmetic (CRC, packet layout,99 data rates), not ECSS text.100- compliance: STANDARDS-REF, gated: false.