tsl

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: MIT Imports: 8 Imported by: 0

README

go-tsl-v5

TSL V5 module for Go

Implements the TSL V5 protocol as documented here https://tslproducts.com/media/1959/tsl-umd-protocol.pdf

Examples can be found in the example folder.

Primary use will be from the Marshal and Unmarshal functions, which provided a similar usage to the standard library json package.

TODO

  • Better examples (include TCP)
  • Tests

Documentation

Index

Constants

View Source
const (
	// MaximumPacketSize is the largest a TSL message can be when sent over UDP
	MaximumPacketSize int = 2048
	// BroadcastIndex is the broadcast index, sent to all displays
	BroadcastIndex uint16 = 0xFFFF
)

Variables

View Source
var (
	// ErrInvalidSize is when the provided byte slice does not contain enough control bits
	ErrInvalidSize = errors.New("invalid size")

	// ErrExceededMaximumPacket is returned when the resultant byte slice is too long for a UDP packet.
	ErrExceededMaximumPacket = errors.New("tally has exceeded maximum UDP packet size")
)

Functions

func Marshal added in v0.1.0

func Marshal(tally *Tally) ([]byte, error)

Marshal converts a Message struct into a TSL v5-compliant byte slice. The resulting byte slice can be sent over TCP, serial, or UDP. Returns an error if the message is invalid or cannot be encoded. If the size exceeds the maximum UDP packet size, it will return an ExceededMaximumPacket error with the byte array

func Unmarshal added in v0.1.0

func Unmarshal(buffer []byte, tally *Tally) error

Unmarshal parses a byte slice containing a TSL v5 frame into a Message struct. It expects the slice to contain exactly one complete frame. Returns an error if the frame is malformed, has a bad checksum, or is incomplete.

func WriteMessage added in v0.1.0

func WriteMessage(w io.Writer, tally *Tally) error

WriteMessage encodes a Tally struct into a TSL v5 frame and writes it to an io.Writer. This is intended for stream-oriented transports like TCP or serial. It handles DLE byte-stuffing in the payload and writes DLE STX + length + payload.

Types

type Flags added in v0.1.0

type Flags struct {
	UnicodeStrings bool
	ControlData    bool
}

Flags is the representation of the control flags in a tally message

type Tally added in v0.1.0

type Tally struct {
	Version         byte
	Flags           Flags
	Screen          uint16
	DisplayMessages []tally.Message
	// contains filtered or unexported fields
}

Tally is the representation of a TSL tally

func ReadMessage added in v0.1.0

func ReadMessage(r *bufio.Reader) (tally *Tally, err error)

ReadMessage reads the next complete TSL v5 message from an io.Reader stream. This is intended for stream-oriented transports like TCP or serial. It synchronizes on the start-of-frame byte and reads the full message. Returns the Message and any error encountered during reading or unmarshaling.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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