Module 07 · Lesson 2
CCSDS Space Packets and Data Handling
Most missions wrap telemetry and commands in the CCSDS Space Packet. This lesson decodes its six-byte header and shows how packets ride in transfer frames and how sequence counts reveal lost data.
Learning objectives
After this lesson you will be able to:
- Explain why space agencies and suppliers share data format standards
- Decode the seven fields of the CCSDS Space Packet primary header from six bytes
- Describe how packets are carried in transfer frames and how sequence counts are used to detect gaps
Why shared standards matter
The previous lesson treated a packet as a container with an identifier. In principle every mission could invent its own container. In practice almost none do, for three reasons.
- Ground stations are shared. A common frame format lets one antenna serve many missions without knowing what is inside the frames.
- Agencies support each other. One agency's station may track another agency's spacecraft during a launch or an emergency. That only works if both speak the same protocols.
- Hardware and software are reused. Radios, on-board computers, test equipment and ground systems are built once against the standard and used on many missions.
The standards come from the Consultative Committee for Space Data Systems (CCSDS), a forum formed by space agencies in 1982. Its normative standards are published as Blue Books and are free to download. The parallel with the Internet protocol suite is fair: layered, public and independently implemented. The difference is the link underneath, which is intermittent and slow.
The Space Packet
The Space Packet is the CCSDS unit of application data. It is used in both directions, for telemetry and for commands. It has a six-byte primary header followed by a packet data field of 1 to 65,536 bytes.
| Field | Bits | Meaning |
|---|---|---|
| Packet version number | 3 | 000 for the Space Packet |
| Packet type | 1 | 0 for telemetry, 1 for telecommand |
| Secondary header flag | 1 | 1 if the data field begins with a secondary header |
| Application process identifier | 11 | Which stream the packet belongs to |
| Sequence flags | 2 | 11 for a complete, unsegmented unit of data |
| Packet sequence count | 14 | A counter kept for each identifier |
| Packet data length | 16 | Number of bytes in the data field, minus one |
The fields total 48 bits. Bits are numbered from the most significant bit of the first byte, as described in the previous lesson.
Three fields need comment.
The application process identifier, or APID, is the packet's address. The mission assigns its values, typically one for each kind of packet from each on-board source, and records them in the telemetry and command database. The value with all eleven bits set, 2047, is reserved for idle packets that carry no data.
The sequence flags allow a large unit of data to be split across several packets. 01 marks the first segment, 00 a continuation, 10 the last, and 11 an unsegmented unit.
The packet data length is the number of bytes after the primary header, minus one. A value of 0 therefore means one byte of data, and an empty packet cannot be expressed. The total packet size is the field value plus seven.
Parsing the primary header
The header is three 16-bit words, most significant byte first. Shifts and masks are enough.
interface PrimaryHeader {
version: number;
type: "telemetry" | "telecommand";
hasSecondaryHeader: boolean;
apid: number;
sequenceFlags: number;
sequenceCount: number;
dataFieldBytes: number;
}
function parsePrimaryHeader(b: Uint8Array): PrimaryHeader {
if (b.length < 6) throw new RangeError("a primary header is 6 bytes");
const word0 = (b[0] << 8) | b[1]; // version, type, flag, APID
const word1 = (b[2] << 8) | b[3]; // sequence flags and count
const lengthField = (b[4] << 8) | b[5];
return {
version: word0 >> 13,
type: (word0 >> 12) & 0x1 ? "telecommand" : "telemetry",
hasSecondaryHeader: ((word0 >> 11) & 0x1) === 1,
apid: word0 & 0x7ff,
sequenceFlags: word1 >> 14,
sequenceCount: word1 & 0x3fff,
dataFieldBytes: lengthField + 1, // the field holds the byte count minus one
};
}
// Hand-built: version 0, telemetry, secondary header present, APID 0x123,
// flags 0b11 (unsegmented), count 1234, 16 bytes of data (length field 15).
// 000 0 1 00100100011 -> 0x09 0x23; 11 00010011010010 -> 0xC4 0xD2; 15 -> 0x00 0x0F
const header = new Uint8Array([0x09, 0x23, 0xc4, 0xd2, 0x00, 0x0f]);
console.log(parsePrimaryHeader(header));
Running it prints the expected values. APID 0x123 is 291 in decimal.
{
version: 0,
type: 'telemetry',
hasSecondaryHeader: true,
apid: 291,
sequenceFlags: 3,
sequenceCount: 1234,
dataFieldBytes: 16
}
The secondary header
The primary header says nothing about when the packet was made. That information normally lives in the secondary header, an optional structure at the start of the data field whose presence is signaled by the flag bit.
Its format is mission-defined. Most missions put a timestamp there, usually a count of seconds and fractions of a second from an agreed epoch. CCSDS publishes time code formats that many missions adopt, but the packet standard does not impose one. European missions that follow the ECSS Packet Utilization Standard add service type and subtype fields. A parser must therefore take the secondary header layout from the mission's database, never from an assumption carried over from the last project.
Packets in transfer frames
Packets are not transmitted on their own. On the downlink they are placed into transfer frames. A telemetry transfer frame has a fixed length for a given link, a header that identifies the spacecraft, and a virtual channel identifier that lets several streams share one physical link. A common arrangement puts live housekeeping on one virtual channel and recorded playback on another.
Because frames are fixed in length and packets are not, packets are poured into frames as a continuous stream. A packet can start in one frame and finish in the next. Each frame header carries a pointer to the first packet header that begins inside it. A receiver that has lost a frame uses that pointer to find a packet boundary again. Frames also carry their own counters, so the ground can tell that a frame was lost.
Below the frame, the link adds a synchronization marker and error-correcting codes. Command frames on the uplink are shorter and variable in length.
Sequence counts and gap detection
Each APID has its own 14-bit sequence count, which increases by one for each packet and wraps from 16,383 to 0. The ground checks continuity for each APID separately:
step = (current - previous + 16384) mod 16384
A step of 1 is normal. A larger step means step - 1 packets were lost. A step of 0 suggests a duplicate, which is common when recorded data is replayed. Because the counter wraps, long outages are detected from timestamps instead.
This resembles offsets in a message log, with a much smaller number space. The count detects a gap. Recovering the data needs a separate action, such as commanding a replay from on-board storage.
Try it: decode a header
The decoder below shows the six bytes of a primary header bit by bit. Start with Housekeeping telemetry, then select single bits and watch the fields change. Work through the challenges under the model.
Decode a space packet
Interactive model
Two hexadecimal digits make a byte. The first six bytes are the header and the rest is the data field. Edit the digits here, or select a bit below to flip it.
Six bytes of header, then 6 bytes of data. That matches the length in the header.
The 48 bits of the header in the order they are sent, grouped by field: version 000, always 000; type 0, telemetry; secondary header 1, follows; application process identifier 00000100001, 33; sequence flags 11, stands alone; sequence count 00010011010010, 1,234; data length 0000000000000101, 5 + 1 = 6 bytes of data.
Bytes 1 and 2: 08 21
Version
Always 000
Type
Telemetry
Secondary header
Follows
Application process identifier
33
Bytes 3 and 4: C4 D2
Sequence flags
Stands alone
Sequence count
1,234
Bytes 5 and 6: 00 05
Data length
5 + 1 = 6 bytes of data
- Packet type
- Telemetry
- Application process identifier
- 33
- Position in a series
- Stands alone
- Sequence count
- 1,234
- Data field length
- 6 bytes
- Total packet length
- 12 bytes
In words. A telemetry packet from application process 33. A secondary header follows this one. It stands alone, and its sequence count is 1,234. The header says the data field is 6 bytes long, so the whole packet is 12 bytes.
Challenges
0 of 3 done
To do: Start from the Housekeeping telemetry example and turn it into a command by flipping one bit.
Hint
The type is a single bit: 0 for telemetry, 1 for a command.
To do: Set the application process identifier to 100.
Hint
100 is 64 + 32 + 4. Written in eleven bits, that is 00001100100.
To do: Make the header claim a data field of 256 bytes.
Hint
The length field holds one less than the number of bytes in the data field.
A practical example: an off-by-one in the length field
An instrument team delivers its first packets for integration testing. Each has a 16-byte data field. The ground system's packet extractor walks the byte stream: read six bytes, compute the packet size from the length field, skip that far, and read the next header.
The first instrument packet decodes correctly. The next header is nonsense, with a version number of 1 and an APID nobody assigned.
The instrument software wrote 16 into the length field instead of 15. The extractor therefore treated the packet as 23 bytes when it was 22, and consumed the first byte of the following header. That header began 0x09 0x23, like the one parsed above. Starting one byte late, the extractor read 0x23 as the first header byte. The top three bits of 0x23 are 001, which gives version 1.
Two design points follow. First, the extractor should validate what it reads: the version must be zero, the APID must be one the database knows, and the length must be plausible for that APID. On failure it should discard data up to the next frame's first-header pointer and resynchronize, reporting what it dropped. Second, the fix belongs in the instrument software, not in a ground workaround, because every other consumer of the packets would have to copy the workaround.
From format to control
Packets and frames move data reliably in both directions. The next lesson follows a command along that path and looks at how each stage is verified and how hazardous commands are kept from being sent by accident.
Key takeaways
- The Space Packet primary header is six bytes - version, type, secondary header flag, application process identifier, sequence flags, sequence count and data length.
- The data length field holds the number of bytes in the packet data field minus one. Forgetting the minus one misaligns every packet that follows.
- Sequence counts are kept per application process identifier and wrap at 16,384. A step other than one means lost, repeated or reordered packets.
- The secondary header usually carries a timestamp, but its format is defined by the mission, not by the packet standard.
Knowledge check
Check your understanding. These questions are not graded and you can retry as often as you like.
0 of 3 questions answered.
Glossary
CCSDS
The Consultative Committee for Space Data Systems, a forum of space agencies that publishes data and communication standards used across the industry.
Space Packet
A variable-length CCSDS data unit made of a six-byte primary header and a packet data field, used for both telemetry and commands.
Application process identifier
An 11-bit field in the Space Packet header, usually shortened to APID, that identifies the stream a packet belongs to. Its values are assigned by the mission.
Sequence count
A 14-bit counter in the Space Packet header that increases by one for each packet of a given APID and wraps from 16,383 to 0.
Transfer frame
The data unit sent over the radio link. Telemetry frames have a fixed length for a given link and carry packets, which may span frame boundaries.
Secondary header
An optional, mission-defined header at the start of the packet data field, most often used for a timestamp.
References and further reading
- Blue Books - Recommended Standards, including the Space Packet Protocol (CCSDS 133.0-B) (opens in a new tab)Consultative Committee for Space Data Systems
- Consultative Committee for Space Data Systems (opens in a new tab)CCSDS
- ECSS-E-ST-70-41C - Telemetry and telecommand packet utilization (opens in a new tab)European Cooperation for Space Standardization
Finished this lesson?
Loading your progress…
Lesson version 1.0.0.