Documentation
¶
Overview ¶
Package sdl provides shared data link primitives used by both TM (tmdl) and TC (tcdl) Space Data Link Protocol implementations.
It contains generic channel buffers, multiplexers, service interfaces, and manager types that are parameterized by frame type, avoiding code duplication between the TM downlink and TC uplink packages.
Index ¶
- Variables
- type Channel
- type Counter
- type GapCounter
- type MCMultiplexer
- type MCSource
- type MasterChanneler
- type Multiplexer
- type PacketSizer
- type Service
- type ServiceManager
- func (m *ServiceManager[S, F]) AddFrameToMasterChannel(scid uint16, frame F) error
- func (m *ServiceManager[S, F]) FlushService(vcid uint8, serviceType S) error
- func (m *ServiceManager[S, F]) GetNextFrameFromMasterChannel(scid uint16) (F, error)
- func (m *ServiceManager[S, F]) HasPendingFramesInMasterChannel(scid uint16) bool
- func (m *ServiceManager[S, F]) ReceiveData(vcid uint8, serviceType S) ([]byte, error)
- func (m *ServiceManager[S, F]) RegisterMasterChannel(scid uint16, mc MasterChanneler[F])
- func (m *ServiceManager[S, F]) RegisterVirtualService(vcid uint8, serviceType S, service Service)
- func (m *ServiceManager[S, F]) SendData(vcid uint8, serviceType S, data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoFramesAvailable indicates there are no frames to retrieve. ErrNoFramesAvailable = errors.New("no frames available") // ErrBufferFull indicates the channel buffer is full. ErrBufferFull = errors.New("channel buffer full") // ErrNoChannels indicates no channels are registered on the multiplexer. ErrNoChannels = errors.New("no channels registered") // ErrServiceNotFound indicates the requested service was not found. ErrServiceNotFound = errors.New("service not found for specified key") // ErrMasterChannelNotFound indicates the requested master channel was not found. ErrMasterChannelNotFound = errors.New("master channel not found for specified SCID") // ErrNoMasterChannels indicates no master channels are registered. ErrNoMasterChannels = errors.New("no master channels registered") )
Functions ¶
This section is empty.
Types ¶
type Channel ¶
Channel is a generic thread-safe FIFO frame buffer. F is the frame type (e.g., *TMTransferFrame or *TCTransferFrame).
func NewChannel ¶
NewChannel creates a new channel with the given ID and buffer capacity.
type Counter ¶ added in v0.3.0
Counter is a frame count field. The protocols use widths from eight bits (TM, TC) through twenty-four (AOS) up to USLP's managed maximum of fifty-six, carried in whichever unsigned type holds them.
type GapCounter ¶ added in v0.3.0
type GapCounter[C Counter] struct { // contains filtered or unexported fields }
GapCounter tracks one wrapping frame count and reports how many frames went missing between one it saw and the next. It is safe for concurrent use.
The zero value is not usable; construct with NewGapCounter, which needs the mask.
func NewGapCounter ¶ added in v0.3.0
func NewGapCounter[C Counter](mask C) *GapCounter[C]
NewGapCounter returns a counter for a field of the given mask, which must be all ones up to the field width, 0xFF for eight bits, 0xFFFFFF for twenty-four, up to 0xFFFFFFFFFFFFFF for USLP's 56-bit maximum.
func (*GapCounter[C]) LastGap ¶ added in v0.3.0
func (g *GapCounter[C]) LastGap() int
LastGap returns the gap reported by the most recent Track, across all channels.
func (*GapCounter[C]) Reset ¶ added in v0.3.0
func (g *GapCounter[C]) Reset()
Reset forgets every channel, so the next frame on each is treated as a first frame again.
func (*GapCounter[C]) Track ¶ added in v0.3.0
func (g *GapCounter[C]) Track(channel uint8, count C) int
Track records a frame count seen on a channel and returns the gap before it: how many frames are missing between the last one tracked on that channel and this one.
The first frame on a channel reports a gap of zero. There is nothing to compare it against, and reporting the distance from an assumed zero would invent a loss that did not happen. A receiver joining a pass in progress would report a gap of however far the counter had already run.
func (*GapCounter[C]) TrackWithCycle ¶ added in v0.3.0
func (g *GapCounter[C]) TrackWithCycle(channel uint8, count C, cycle uint8, cycleMask uint8) int
TrackWithCycle records a frame count together with the cycle counter some protocols pair it with, and returns the gap before it. AOS is the one that needs this: when the VC frame count usage flag is set, the signaling field carries a four-bit VC frame count cycle that increments each time the 24-bit count wraps (CCSDS 732.0-B-4 4.1.2.5.5.3), and the pair behaves as one 28-bit count. cycleMask is the cycle field's width in the same all-ones form as the count mask: 0xF for AOS's four bits.
The combined count (cycle bits above the count bits) must fit in C. Do not mix Track and TrackWithCycle on the same channel: the two disagree about the modulus, so a gap computed across the switch would be wrong.
type MCMultiplexer ¶
type MCMultiplexer[F any] struct { // contains filtered or unexported fields }
MCMultiplexer handles weighted round-robin scheduling across master channels, keyed by Spacecraft ID (uint16). A MCMultiplexer is safe for concurrent use.
func NewMCMultiplexer ¶
func NewMCMultiplexer[F any]() *MCMultiplexer[F]
NewMCMultiplexer creates a new master channel multiplexer.
func (*MCMultiplexer[F]) Add ¶
func (m *MCMultiplexer[F]) Add(mc MCSource[F], priority int)
Add registers a master channel with a priority weight. Priority must be at least 1; values below 1 are clamped to 1.
func (*MCMultiplexer[F]) HasPending ¶
func (m *MCMultiplexer[F]) HasPending() bool
HasPending checks if any master channel has pending frames.
func (*MCMultiplexer[F]) Len ¶
func (m *MCMultiplexer[F]) Len() int
Len returns the number of registered master channels.
func (*MCMultiplexer[F]) Next ¶
func (m *MCMultiplexer[F]) Next() (F, error)
Next selects the next frame for transmission using weighted round-robin.
type MCSource ¶
MCSource is the interface that master channels must implement to participate in physical-channel multiplexing.
type MasterChanneler ¶
type MasterChanneler[F any] interface { AddFrame(frame F) error GetNextFrame() (F, error) HasPendingFrames() bool }
MasterChanneler is the interface that master channels must implement to be used with ServiceManager. F is the frame type.
type Multiplexer ¶
type Multiplexer[F any] struct { // contains filtered or unexported fields }
Multiplexer handles frame scheduling from multiple channels using weighted round-robin. F is the frame type.
A Multiplexer is safe for concurrent use. Its own scheduling state (the cursor and the remaining weight) is guarded here; the channels it draws from carry their own locks.
func NewMultiplexer ¶
func NewMultiplexer[F any]() *Multiplexer[F]
NewMultiplexer initializes a new multiplexer.
func (*Multiplexer[F]) AddChannel ¶
func (mux *Multiplexer[F]) AddChannel(ch *Channel[F], priority int)
AddChannel registers a channel with a priority weight. Priority must be at least 1; values below 1 are clamped to 1.
func (*Multiplexer[F]) HasPending ¶
func (mux *Multiplexer[F]) HasPending() bool
HasPending checks if any channel has pending frames.
func (*Multiplexer[F]) Len ¶
func (mux *Multiplexer[F]) Len() int
Len returns the number of registered channels.
func (*Multiplexer[F]) Next ¶
func (mux *Multiplexer[F]) Next() (F, error)
Next selects the next frame for transmission based on weighted round-robin.
type PacketSizer ¶
PacketSizer returns the total length in bytes of the packet starting at data[0], or -1 if the data is too short to determine length. Used by packet services to find packet boundaries within frame data.
type ServiceManager ¶
type ServiceManager[S comparable, F any] struct { // contains filtered or unexported fields }
ServiceManager manages services and master channels generically. S is the service type key, F is the frame type. A ServiceManager is safe for concurrent use.
func NewServiceManager ¶
func NewServiceManager[S comparable, F any]() *ServiceManager[S, F]
NewServiceManager creates a new ServiceManager.
func (*ServiceManager[S, F]) AddFrameToMasterChannel ¶
func (m *ServiceManager[S, F]) AddFrameToMasterChannel(scid uint16, frame F) error
AddFrameToMasterChannel routes a frame to the specified Master Channel.
func (*ServiceManager[S, F]) FlushService ¶
func (m *ServiceManager[S, F]) FlushService(vcid uint8, serviceType S) error
FlushService flushes the specified service.
func (*ServiceManager[S, F]) GetNextFrameFromMasterChannel ¶
func (m *ServiceManager[S, F]) GetNextFrameFromMasterChannel(scid uint16) (F, error)
GetNextFrameFromMasterChannel retrieves the next frame from the Master Channel's multiplexer.
func (*ServiceManager[S, F]) HasPendingFramesInMasterChannel ¶
func (m *ServiceManager[S, F]) HasPendingFramesInMasterChannel(scid uint16) bool
HasPendingFramesInMasterChannel checks if a Master Channel has pending frames.
func (*ServiceManager[S, F]) ReceiveData ¶
func (m *ServiceManager[S, F]) ReceiveData(vcid uint8, serviceType S) ([]byte, error)
ReceiveData receives data from the specified service type for a given VCID.
func (*ServiceManager[S, F]) RegisterMasterChannel ¶
func (m *ServiceManager[S, F]) RegisterMasterChannel(scid uint16, mc MasterChanneler[F])
RegisterMasterChannel registers a Master Channel.
func (*ServiceManager[S, F]) RegisterVirtualService ¶
func (m *ServiceManager[S, F]) RegisterVirtualService(vcid uint8, serviceType S, service Service)
RegisterVirtualService registers a service for a specific VCID and service type.