Documentation
¶
Index ¶
- Constants
- Variables
- func CalculatePacketSize(header []byte) (int, error)
- func ComputeCRC(data []byte) uint16
- func DescribeAPID(apid uint16) string
- func IsIdlePacket(packet *SpacePacket) bool
- func WritePacket(packet *SpacePacket, writer io.Writer) error
- type APIDManager
- type PacketOption
- type PrimaryHeader
- type SecondaryHeader
- type SpacePacket
- func Decode(data []byte) (*SpacePacket, error)
- func NewSpacePacket(apid uint16, packetType uint8, data []byte, options ...PacketOption) (*SpacePacket, error)
- func NewTCPacket(apid uint16, data []byte, options ...PacketOption) (*SpacePacket, error)
- func NewTMPacket(apid uint16, data []byte, options ...PacketOption) (*SpacePacket, error)
- func ReadPacket(reader io.Reader) (*SpacePacket, error)
Constants ¶
const PrimaryHeaderSize = 6 // CCSDS Packet Header is 6 bytes
Variables ¶
var ( // ErrInvalidHeader indicates an invalid primary or secondary header. ErrInvalidHeader = errors.New("invalid header: header does not conform to CCSDS standards") // ErrInvalidAPID indicates that the provided APID is out of range or invalid. ErrInvalidAPID = errors.New("invalid APID: must be in the range 0-2047") // ErrPacketTooLarge indicates that the packet size exceeds the allowable limit. ErrPacketTooLarge = errors.New("packet size exceeds the maximum allowable limit") // ErrDataTooShort indicates that the provided data is too short for decoding. ErrDataTooShort = errors.New("provided data is too short to decode the packet") // ErrSecondaryHeaderMissing indicates that a required secondary header is missing. ErrSecondaryHeaderMissing = errors.New("secondary header flag is set but no secondary header is provided") // ErrCRCValidationFailed indicates that the CRC validation of the packet failed. ErrCRCValidationFailed = errors.New("CRC validation failed: data integrity check failed") )
Functions ¶
func CalculatePacketSize ¶
CalculatePacketSize computes the total size of a space packet from a raw header dump. It uses the packet length field in the primary header to determine the full packet size.
func ComputeCRC ¶
ComputeCRC computes the CRC checksum for the given data.
func DescribeAPID ¶
DescribeAPID provides a description for a given APID.
func IsIdlePacket ¶
func IsIdlePacket(packet *SpacePacket) bool
IsIdlePacket determines if a given Space Packet is an idle packet. For CCSDS Space Packets, idle packets are identified by the APID being 0x7FF (2047 in decimal).
func WritePacket ¶
func WritePacket(packet *SpacePacket, writer io.Writer) error
WritePacket writes a single pre-formatted Space Packet to an io.Writer. This function only writes one packet at a time.
Types ¶
type APIDManager ¶
type APIDManager struct {
// contains filtered or unexported fields
}
APIDManager manages the allocation and validation of APIDs.
func NewAPIDManager ¶
func NewAPIDManager() *APIDManager
NewAPIDManager creates a new APIDManager instance.
func (*APIDManager) IsAPIDReserved ¶
func (m *APIDManager) IsAPIDReserved(apid uint16) bool
IsAPIDReserved checks if an APID is reserved.
func (*APIDManager) ReleaseAPID ¶
func (m *APIDManager) ReleaseAPID(apid uint16)
ReleaseAPID releases a reserved APID.
func (*APIDManager) ReserveAPID ¶
func (m *APIDManager) ReserveAPID(apid uint16) error
ReserveAPID reserves an APID.
type PacketOption ¶
type PacketOption func(*SpacePacket) error
PacketOption defines a function type for configuring SpacePacket options.
func WithErrorControl ¶
func WithErrorControl(crc uint16) PacketOption
WithErrorControl adds an error control field to the SpacePacket.
func WithSecondaryHeader ¶
func WithSecondaryHeader(header SecondaryHeader) PacketOption
WithSecondaryHeader adds a secondary header to the SpacePacket.
type PrimaryHeader ¶
type PrimaryHeader struct {
Version uint8 // Protocol version (3 bits)
Type uint8 // Packet type (1 bit)
SecondaryHeaderFlag uint8 // Indicates if a secondary header is present (1 bit)
APID uint16 // Application Process Identifier (11 bits)
SequenceFlags uint8 // Packet sequence control flags (2 bits)
SequenceCount uint16 // Packet sequence number (14 bits)
PacketLength uint16 // Total packet length minus the primary header (16 bits)
}
PrimaryHeader represents the mandatory header section of a space packet.
func (*PrimaryHeader) Decode ¶
func (ph *PrimaryHeader) Decode(data []byte) error
Decode deserializes a 6-byte array into a PrimaryHeader.
func (*PrimaryHeader) Encode ¶
func (ph *PrimaryHeader) Encode() ([]byte, error)
Encode serializes the PrimaryHeader into a 6-byte array.
func (*PrimaryHeader) Humanize ¶
func (ph *PrimaryHeader) Humanize() string
Humanize generates a human-readable representation of the PrimaryHeader.
func (*PrimaryHeader) Validate ¶
func (ph *PrimaryHeader) Validate() error
Validate method for PrimaryHeader
type SecondaryHeader ¶
type SecondaryHeader struct {
Timestamp uint64 // Optional timestamp for mission-specific data
OtherFields map[string]interface{} // Additional mission-specific fields
}
SecondaryHeader represents the optional customizable secondary header of a space packet.
func (*SecondaryHeader) Decode ¶
func (sh *SecondaryHeader) Decode(data []byte) error
Decode deserializes a byte slice into a SecondaryHeader.
func (*SecondaryHeader) Encode ¶
func (sh *SecondaryHeader) Encode() ([]byte, error)
Encode serializes the SecondaryHeader into a byte slice.
func (*SecondaryHeader) Humanize ¶
func (sh *SecondaryHeader) Humanize() string
Humanize generates a human-readable representation of the SecondaryHeader.
func (*SecondaryHeader) Validate ¶
func (sh *SecondaryHeader) Validate() error
Validate method for SecondaryHeader
type SpacePacket ¶
type SpacePacket struct {
PrimaryHeader PrimaryHeader // The primary header of the space packet
SecondaryHeader *SecondaryHeader // Optional secondary header
UserData []byte // User data contained in the packet
ErrorControl *uint16 // Optional error control field (e.g., CRC)
}
SpacePacket represents a complete space packet as per CCSDS standards.
func Decode ¶
func Decode(data []byte) (*SpacePacket, error)
Decode parses a byte slice into a SpacePacket.
func NewSpacePacket ¶
func NewSpacePacket(apid uint16, packetType uint8, data []byte, options ...PacketOption) (*SpacePacket, error)
NewSpacePacket creates a new SpacePacket instance.
func NewTCPacket ¶
func NewTCPacket(apid uint16, data []byte, options ...PacketOption) (*SpacePacket, error)
func NewTMPacket ¶
func NewTMPacket(apid uint16, data []byte, options ...PacketOption) (*SpacePacket, error)
func ReadPacket ¶
func ReadPacket(reader io.Reader) (*SpacePacket, error)
ReadPacket reads a single Space Packet from an io.Reader. It reads the primary header first to determine the total packet size and then reads the rest of the packet based on that size. This function only reads one packet at a time.
func (*SpacePacket) Encode ¶
func (sp *SpacePacket) Encode() ([]byte, error)
Encode converts the SpacePacket into a byte slice for transmission.
func (*SpacePacket) Humanize ¶
func (sp *SpacePacket) Humanize() string
Humanize generates a human-readable representation of the SpacePacket.
func (*SpacePacket) Validate ¶
func (sp *SpacePacket) Validate() error
Validate checks the integrity and correctness of the SpacePacket.