Documentation
¶
Index ¶
- Constants
- func CRC16(data []byte) uint16
- func CRC16Recursive(byteVal byte, remainder uint16) uint16
- type Frame
- type FramingState
- type TMMsg
- type TMTransport
- type TMType
- type Telemetry
- func (t *Telemetry) Attach(topic string, variable interface{})
- func (t *Telemetry) GetAvailableTopics() []string
- func (t *Telemetry) GetValue(topic string) interface{}
- func (t *Telemetry) PrintHashTable()
- func (t *Telemetry) Publish(topic string, msgType TMType, payload []byte) error
- func (t *Telemetry) Subscribe(topic string, callback func(TMMsg))
- func (t *Telemetry) TryUpdateHashTable(msg TMMsg)
- func (t *Telemetry) UpdateTelemetry(stopChan chan struct{})
Constants ¶
const ( SOF = 0xF7 EOF = 0x7F ESC = 0x7D )
Frame handling
const ( IncomingBufferSize = 128 OutgoingBufferSize = 128 TopicBufferSize = 64 MaxRetries = 1000 RetryDelay = 10 * time.Second )
Telemetry Core
const ( VendorID = "0403" // Default vendor for FTDI devices ProductID = "6015" // Default product for FTDI devices )
Variables ¶
This section is empty.
Functions ¶
func CRC16Recursive ¶
CRC16Recursive performs the CRC-CCITT (0x1021) computation for a single byte.
Types ¶
type Frame ¶
type Frame struct {
// IncomingBuffer stores the bytes of the incoming frame.
IncomingBuffer []byte
// OutgoingBuffer stores the bytes of the outgoing frame.
OutgoingBuffer []byte
// IncomingState represents the current state of the frame parsing.
IncomingState FramingState
// OnFrame is called when a complete frame is received.
OnFrame func(data []byte)
// OnError is called when an error occurs during frame parsing.
OnError func(err error)
}
Frame represents the framing protocol for handling incoming and outgoing data.
func (*Frame) AppendByte ¶
AppendByte appends a byte to the outgoing buffer, escaping it if necessary.
func (*Frame) AppendUint16 ¶
AppendUint16 appends a 16-bit unsigned integer to the outgoing buffer, escaping it if necessary.
func (*Frame) BeginFrame ¶
func (f *Frame) BeginFrame()
BeginFrame initializes the outgoing buffer with the Start of Frame (SOF) byte.
type TMTransport ¶
type TMTransport struct {
Read func([]byte) (int, error)
Write func([]byte) (int, error)
ProductID string
VendorID string
PortName string
}
func GetTransport ¶
func GetTransport(vendorId string, productId string) (*TMTransport, error)
GetTransport scans for available USB ports and returns the first one that matches the specified VendorID and ProductID.
type Telemetry ¶
type Telemetry struct {
// Frame handles the framing protocol for incoming and outgoing messages.
Frame *Frame
// HashTable stores the values of attached variables by topic.
HashTable map[string]interface{}
// TopicCallbacks stores the callbacks for specific topics.
TopicCallbacks map[string]func(TMMsg)
// GeneralCallback is called for any received message if no specific topic callback is registered.
GeneralCallback func(TMMsg)
// Transport handles the read and write operations for the telemetry system.
Transport *TMTransport
// Mutex ensures thread-safe access to the telemetry system's data structures.
Mutex sync.Mutex
// ReceivedTopics keeps track of all received topics.
ReceivedTopics map[string]bool
}
Telemetry represents the core telemetry system, handling frame parsing, topic-based messaging, and CRC validation.
func NewTelemetry ¶
func NewTelemetry(transport *TMTransport) *Telemetry
NewTelemetry creates a new telemetry instance with the provided transport.
func (*Telemetry) GetAvailableTopics ¶
GetAvailableTopics returns a list of all received topics.
func (*Telemetry) PrintHashTable ¶
func (t *Telemetry) PrintHashTable()
PrintHashTable prints the current values stored in the telemetry's hash table.
func (*Telemetry) Subscribe ¶
Subscribe registers a callback for a specific topic. If the topic is an empty string, the callback is called for any received message.
func (*Telemetry) TryUpdateHashTable ¶
TryUpdateHashTable updates the hash table with the received message and calls the appropriate callbacks.
func (*Telemetry) UpdateTelemetry ¶
func (t *Telemetry) UpdateTelemetry(stopChan chan struct{})
UpdateTelemetry starts listening for incoming messages and processes them.