tmsc

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package tmsc implements the TM Synchronization and Channel Coding sublayer per CCSDS 131.0-B-5 (TM Synchronization and Channel Coding).

This sublayer sits between the TM Data Link Protocol (CCSDS 132.0-B-3) and the physical layer, providing:

  • Attached Sync Marker (ASM) for frame synchronization
  • CCSDS pseudo-randomization for bit transition density assurance
  • Channel Access Data Unit (CADU) wrapping and unwrapping

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDataTooShort indicates the provided CADU is too short to contain the ASM.
	ErrDataTooShort = errors.New("provided data is too short to unwrap")

	// ErrSyncMarkerMismatch indicates the CADU does not start with the expected ASM.
	ErrSyncMarkerMismatch = errors.New("attached sync marker mismatch")

	// ErrInvalidDataLength indicates the data length does not match the RS code parameters.
	ErrInvalidDataLength = errors.New("data length does not match RS code parameters")

	// ErrInvalidInterleaveDepth indicates an unsupported interleaving depth.
	ErrInvalidInterleaveDepth = errors.New("unsupported interleaving depth: must be 1, 2, 3, 4, 5, or 8")

	// ErrUncorrectable indicates the codeword has more errors than the code can correct.
	ErrUncorrectable = errors.New("uncorrectable errors: exceeds RS correction capability")

	// ErrInvalidVirtualFill indicates a virtual fill length that is negative,
	// not a multiple of the interleaving depth, or not smaller than the data
	// capacity of the codeblock (CCSDS 131.0-B-5 4.3.7.3, 4.3.8.2).
	ErrInvalidVirtualFill = errors.New("virtual fill must be a non-negative multiple of the interleaving depth and smaller than depth x DataLen()")
)

Functions

func DefaultASM

func DefaultASM() []byte

DefaultASM returns the standard CCSDS Attached Sync Marker (0x1ACFFC1D) used to identify the start of each Transfer Frame in the bitstream. A fresh copy is returned each call to prevent accidental mutation.

func GeneratePNSequence

func GeneratePNSequence(length int) []byte

GeneratePNSequence produces the CCSDS 255-bit pseudo-random sequence using an 8-bit LFSR with polynomial h(x) = x^8 + x^7 + x^5 + x^3 + 1, initialized to all 1s. This is the legacy-compatible sequence of CCSDS 131.0-B-5 10.4.2; the 131071-bit sequence of 10.4.1 is not implemented.

The generator lives in internal/pn next to the TC one. The two are different sequences from different polynomials (CCSDS 231.0-B-4 clause 6.2 for TC), so the internal names are qualified by standard and this package uses only the TM pair.

func Randomize

func Randomize(data []byte) []byte

Randomize applies CCSDS pseudo-randomization by XOR-ing data with the standard PN (pseudo-noise) sequence. The same operation is used for both randomization and de-randomization since XOR is self-inverse. Returns a new slice; the input is not modified.

func UnwrapCADU

func UnwrapCADU(cadu, asm []byte, randomize bool) ([]byte, error)

UnwrapCADU extracts encoded frame data from a Channel Access Data Unit. It validates and strips the ASM, and optionally de-randomizes the data. If asm is nil, DefaultASM is used.

func WrapCADU

func WrapCADU(frameData, asm []byte, randomize bool) []byte

WrapCADU produces a Channel Access Data Unit from encoded frame data. It optionally applies CCSDS pseudo-randomization and prepends the Attached Sync Marker per CCSDS 131.0-B-5 section 9. If asm is nil, DefaultASM is used.

Types

type RSCodec

type RSCodec struct {
	// contains filtered or unexported fields
}

RSCodec holds precomputed state for a CCSDS Reed-Solomon code.

func NewRS255_223

func NewRS255_223() *RSCodec

NewRS255_223 returns an RSCodec for CCSDS (255,223) with 32 parity symbols. This code can correct up to 16 symbol errors per codeword.

func NewRS255_239

func NewRS255_239() *RSCodec

NewRS255_239 returns an RSCodec for CCSDS (255,239) with 16 parity symbols. This code can correct up to 8 symbol errors per codeword.

func (*RSCodec) DataLen

func (rs *RSCodec) DataLen() int

DataLen returns the data length per codeword (255 - nroots).

func (*RSCodec) Decode

func (rs *RSCodec) Decode(codeword []byte) ([]byte, int, error)

Decode corrects errors in a 255-byte codeword and returns the corrected data (first DataLen() bytes), the number of corrected symbol errors, and any error. Returns ErrUncorrectable if errors exceed correction capability. The input slice is not modified.

func (*RSCodec) DecodeInterleaved

func (rs *RSCodec) DecodeInterleaved(data []byte, depth int) ([]byte, int, error)

DecodeInterleaved decodes interleaved data, correcting errors. Input length must be exactly depth * 255 bytes. Returns corrected data of length depth * DataLen(), total corrections, and error.

func (*RSCodec) DecodeShortened added in v0.3.0

func (rs *RSCodec) DecodeShortened(data []byte, depth, virtualFill int) ([]byte, int, error)

DecodeShortened decodes a shortened codeblock encoded with virtualFill symbols of virtual fill, correcting errors. It logically restores the leading zero symbols before decoding and strips them again afterwards. The input must be exactly depth*255 - virtualFill bytes; the result is the corrected data of depth*DataLen() - virtualFill bytes, with the total number of corrected symbol errors. Both ends must agree on virtualFill: the fill is not transmitted, so its length is a managed parameter (CCSDS 131.0-B-5 4.3.7.2 note 2).

func (*RSCodec) Encode

func (rs *RSCodec) Encode(data []byte) ([]byte, error)

Encode appends nroots parity symbols to data and returns a 255-byte codeword. The input must be exactly DataLen() bytes. The input slice is not modified.

func (*RSCodec) EncodeInterleaved

func (rs *RSCodec) EncodeInterleaved(data []byte, depth int) ([]byte, error)

EncodeInterleaved encodes data using symbol interleaving at the given depth. Input length must be exactly depth * DataLen() bytes. Returns a slice of length depth * 255.

func (*RSCodec) EncodeShortened added in v0.3.0

func (rs *RSCodec) EncodeShortened(data []byte, depth, virtualFill int) ([]byte, error)

EncodeShortened encodes a shortened codeblock using virtual fill per CCSDS 131.0-B-5 4.3.7 and 4.3.8. The codeblock is logically completed by virtualFill zero symbols that precede the data; they are neither passed in nor transmitted, only fed to the encoder. A zero byte is zero in both the dual and the conventional basis, so the fill needs no basis transform.

virtualFill must be a non-negative multiple of depth and smaller than depth * DataLen() (4.3.7.3, 4.3.8.2 e)). The input must be exactly depth*DataLen() - virtualFill bytes; the result is the transmitted codeblock of depth*255 - virtualFill bytes. With virtualFill = 0 this is EncodeInterleaved; a single shortened codeword is depth = 1.

func (*RSCodec) NRoots

func (rs *RSCodec) NRoots() int

NRoots returns the number of parity symbols.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL