CCSDS 124.0-B-1 C 1.0.0
CCSDS 124.0-B-1 Lossless Compression
Loading...
Searching...
No Matches
encode.c File Reference

CCSDS 124.0-B-1 encoding functions (COUNT, RLE, BE). More...

#include "ccsds124.h"

Go to the source code of this file.

Functions

Counter Encoding (COUNT)

Implements CCSDS 124.0-B-1 Section 5.2 encoding schemes:

  • Counter Encoding (COUNT) - Section 5.2.2, Table 5-1, Equation 9
  • Run-Length Encoding (RLE) - Section 5.2.3, Equation 10
  • Bit Extraction (BE) - Section 5.2.4, Equation 11
Authors
Georges Labrèche georg.nosp@m.es@t.nosp@m.anagr.nosp@m.aspa.nosp@m.ce.co.nosp@m.mhttps://georges.fyi
Claude Code (Anthropic) norep.nosp@m.ly@a.nosp@m.nthro.nosp@m.pic..nosp@m.com
See also
https://ccsds.org/Pubs/124x0b1.pdf CCSDS 124.0-B-1 Standard

CCSDS Section 5.2.2, Table 5-1, Equation 9. Encodes positive integers 1 ≤ A ≤ 2^16 - 1:

  • A = 1 → '0'
  • 2 ≤ A ≤ 33 → '110' ∥ BIT₅(A-2)
  • A ≥ 34 → '111' ∥ BIT_E(A-2) where E = 2⌊log₂(A-2)+1⌋ - 6
int ccsds124_count_encode (bitbuffer_t *output, uint32_t A)
 Counter encoding (CCSDS Section 5.2.2, Equation 9).
 
Run-Length Encoding (RLE)

CCSDS Section 5.2.3, Equation 10. RLE(a) = COUNT(C₀) ∥ COUNT(C₁) ∥ ... ∥ COUNT(C_{H(a)-1}) ∥ '10'

where Cᵢ = 1 + (count of consecutive '0' bits before i-th '1' bit) and H(a) = Hamming weight (number of '1' bits in a)

Note
Trailing zeros are not encoded (deducible from vector length)
int ccsds124_rle_encode (bitbuffer_t *output, const bitvector_t *input)
 Run-length encoding (CCSDS Section 5.2.3, Equation 10).
 
Bit Extraction (BE)

CCSDS Section 5.2.4, Equation 11. BE(a, b) = a_{g_{H(b)-1}} ∥ ... ∥ a_{g₁} ∥ a_{g₀}

where gᵢ is the position of the i-th '1' bit in b (MSB to LSB order)

Extracts bits from 'a' at positions where 'b' has '1' bits. Output order: MSB to LSB (reverse order of finding '1' bits)

Example
BE('10110011', '01001010') = '001'
Positions with '1' in mask: 1, 3, 6
Extract from data: bit[1]=1, bit[3]=0, bit[6]=0
Output (MSB→LSB): 0, 0, 1
int ccsds124_bit_extract (bitbuffer_t *output, const bitvector_t *data, const bitvector_t *mask)
 Bit extraction (CCSDS Section 5.2.4, Equation 11).
 
int ccsds124_bit_extract_forward (bitbuffer_t *output, const bitvector_t *data, const bitvector_t *mask)
 Bit extraction in forward order (LSB to MSB).
 

Detailed Description

CCSDS 124.0-B-1 encoding functions (COUNT, RLE, BE).

Definition in file encode.c.