Documentation ¶
Index ¶
- Variables
- type ConnectionHandlerFunc
- type DefaultProtocol
- func (p *DefaultProtocol) Close() error
- func (p *DefaultProtocol) PublishMessage(topic string, payload []byte) error
- func (p *DefaultProtocol) ReceiveMessage() (*Message, error)
- func (p *DefaultProtocol) SendMessage(msg *Message) error
- func (p *DefaultProtocol) StartReceiving(parentCtx context.Context)
- func (p *DefaultProtocol) Subscribe(topic string, handler IMessageRxHandler)
- func (p *DefaultProtocol) Unsubscribe(topic string, handler IMessageRxHandler)
- type DefaultSubscriptionManager
- type FTDIConfig
- type FTDITransport
- type IConnectionHandler
- type IMessageHandler
- type IMessageRxHandler
- type IMessageTxHandler
- type IProtocol
- type ISubscriptionManager
- type ITransport
- type Message
- type MessageHandlerFunc
- type MessageReader
- type MessageRxHandlerFunc
- type MessageTxHandlerFunc
- type TCPClientTransport
- type TCPServerTransport
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidMessage = errors.New("invalid message format") ErrCRCMismatch = errors.New("CRC checksum mismatch") )
Common errors
var DefaultFTDIConfig = FTDIConfig{
VID: 0x0403,
PID: 0x6001,
Interface: 0,
ReadEP: 0x81,
WriteEP: 0x01,
BaudRate: 115200,
DataBits: 8,
StopBits: 1,
Parity: 0,
FlowControl: 0,
}
DefaultFTDIConfig provides default configuration for common FTDI devices
Functions ¶
This section is empty.
Types ¶
type ConnectionHandlerFunc ¶
type ConnectionHandlerFunc struct { OnConnectFunc func(transport ITransport) OnDisconnectFunc func(transport ITransport, err error) }
ConnectionHandlerFunc is a function type that implements IConnectionHandler
func (ConnectionHandlerFunc) OnConnect ¶
func (h ConnectionHandlerFunc) OnConnect(transport ITransport)
func (ConnectionHandlerFunc) OnDisconnect ¶
func (h ConnectionHandlerFunc) OnDisconnect(transport ITransport, err error)
type DefaultProtocol ¶
type DefaultProtocol struct {
// contains filtered or unexported fields
}
DefaultProtocol handles reading and writing messages over a transport
func (*DefaultProtocol) Close ¶
func (p *DefaultProtocol) Close() error
Close cancels the context and closes the transport
func (*DefaultProtocol) PublishMessage ¶
func (p *DefaultProtocol) PublishMessage(topic string, payload []byte) error
PublishMessage publishes a message to a topic
func (*DefaultProtocol) ReceiveMessage ¶
func (p *DefaultProtocol) ReceiveMessage() (*Message, error)
ReceiveMessage reads a message from the transport
func (*DefaultProtocol) SendMessage ¶
func (p *DefaultProtocol) SendMessage(msg *Message) error
SendMessage sends a message over the transport
func (*DefaultProtocol) StartReceiving ¶
func (p *DefaultProtocol) StartReceiving(parentCtx context.Context)
StartReceiving starts message processing loop
func (*DefaultProtocol) Subscribe ¶
func (p *DefaultProtocol) Subscribe(topic string, handler IMessageRxHandler)
Subscribe adds a message handler for a topic pattern
func (*DefaultProtocol) Unsubscribe ¶
func (p *DefaultProtocol) Unsubscribe(topic string, handler IMessageRxHandler)
Unsubscribe removes a message handler for a topic pattern
type DefaultSubscriptionManager ¶
type DefaultSubscriptionManager struct {
// contains filtered or unexported fields
}
DefaultSubscriptionManager implements ISubscriptionManager
func (*DefaultSubscriptionManager) OnMessageRx ¶
func (sm *DefaultSubscriptionManager) OnMessageRx(msg *Message)
func (*DefaultSubscriptionManager) Subscribe ¶
func (sm *DefaultSubscriptionManager) Subscribe(topic string, handler IMessageRxHandler)
func (*DefaultSubscriptionManager) Unsubscribe ¶
func (sm *DefaultSubscriptionManager) Unsubscribe(topic string, handler IMessageRxHandler)
type FTDIConfig ¶
type FTDIConfig struct { VID uint16 // Vendor ID PID uint16 // Product ID Interface int // Interface number ReadEP int // Read endpoint number WriteEP int // Write endpoint number BaudRate int // Baud rate for UART DataBits int // Data bits (5, 6, 7, 8) StopBits int // Stop bits (1, 2) Parity int // Parity (0=none, 1=odd, 2=even) FlowControl int // Flow control (0=none, 1=hardware) }
FTDIConfig holds configuration for FTDI transport
type FTDITransport ¶
type FTDITransport struct {
// contains filtered or unexported fields
}
FTDITransport implements ITransport for FTDI USB devices
func NewFTDITransport ¶
func NewFTDITransport(config FTDIConfig, connectionHandler IConnectionHandler) (*FTDITransport, error)
func (*FTDITransport) Close ¶
func (t *FTDITransport) Close() error
func (*FTDITransport) ReadMessage ¶
func (t *FTDITransport) ReadMessage() (*Message, error)
func (*FTDITransport) WriteMessage ¶
func (t *FTDITransport) WriteMessage(msg *Message) error
type IConnectionHandler ¶
type IConnectionHandler interface { OnConnect(transport ITransport) OnDisconnect(transport ITransport, err error) }
IConnectionHandler defines callbacks for transport connection status
type IMessageHandler ¶
type IMessageHandler interface { IMessageRxHandler IMessageTxHandler }
IMessageHandler defines the interface for message handlers
type IMessageRxHandler ¶
type IMessageRxHandler interface {
OnMessageRx(msg *Message)
}
IMessageRxHandler defines callback interface for message handlers
type IMessageTxHandler ¶
type IMessageTxHandler interface {
OnMessageTx(msg *Message)
}
IMessageTxHandler defines callback interface for message handlers
type IProtocol ¶
type IProtocol interface { SendMessage(msg *Message) error ReceiveMessage() (*Message, error) Subscribe(topic string, handler IMessageRxHandler) Unsubscribe(topic string, handler IMessageRxHandler) PublishMessage(topic string, payload []byte) error StartReceiving(ctx context.Context) Close() error }
IProtocol defines the interface for the QDP protocol implementation
func NewProtocol ¶
func NewProtocol(transport ITransport, subscribers ISubscriptionManager, msgHandler IMessageHandler) IProtocol
type ISubscriptionManager ¶
type ISubscriptionManager interface { Subscribe(topic string, handler IMessageRxHandler) Unsubscribe(topic string, handler IMessageRxHandler) OnMessageRx(msg *Message) }
ISubscriptionManager defines the interface for managing subscriptions
func NewSubscriptionManager ¶
func NewSubscriptionManager() ISubscriptionManager
type ITransport ¶
type ITransport interface { ReadMessage() (*Message, error) WriteMessage(*Message) error Close() error }
ITransport defines the interface for different transport mechanisms
type Message ¶
Message represents a QDP protocol message
type MessageHandlerFunc ¶
type MessageHandlerFunc struct { OnMessageRxFunc func(msg *Message) OnMessageTxFunc func(msg *Message) }
func (MessageHandlerFunc) OnMessageRx ¶
func (f MessageHandlerFunc) OnMessageRx(msg *Message)
func (MessageHandlerFunc) OnMessageTx ¶
func (f MessageHandlerFunc) OnMessageTx(msg *Message)
type MessageReader ¶ added in v0.0.8
type MessageReader struct {
// contains filtered or unexported fields
}
MessageReader handles buffered reading of QDP messages
func NewMessageReader ¶ added in v0.0.8
func NewMessageReader(reader io.Reader) *MessageReader
NewMessageReader creates a new buffered message reader
func (*MessageReader) ReadMessage ¶ added in v0.0.8
func (r *MessageReader) ReadMessage() (*Message, error)
ReadMessage handles buffered reading of messages
type MessageRxHandlerFunc ¶
type MessageRxHandlerFunc func(msg *Message)
MessageRxHandlerFunc is a function type that implements IMessageRxHandler
func (MessageRxHandlerFunc) OnMessageRx ¶
func (f MessageRxHandlerFunc) OnMessageRx(msg *Message)
type MessageTxHandlerFunc ¶
type MessageTxHandlerFunc func(msg *Message)
MessageTxHandlerFunc is a function type that implements IMessageTxHandler
func (MessageTxHandlerFunc) OnMessageTx ¶
func (f MessageTxHandlerFunc) OnMessageTx(msg *Message)
type TCPClientTransport ¶
type TCPClientTransport struct {
// contains filtered or unexported fields
}
TCPClientTransport implements ITransport for TCP client connections
func NewTCPClientTransport ¶
func NewTCPClientTransport(address string, connectionHandler IConnectionHandler) (*TCPClientTransport, error)
NewTCPClientTransport creates a new TCP client transport by dialing a server
func NewTCPClientTransportFromConn ¶
func NewTCPClientTransportFromConn(conn net.Conn, connectionHandler IConnectionHandler) *TCPClientTransport
NewTCPClientTransportFromConn creates a new TCP client transport from existing connection
func (*TCPClientTransport) Close ¶
func (t *TCPClientTransport) Close() error
func (*TCPClientTransport) ReadMessage ¶
func (t *TCPClientTransport) ReadMessage() (*Message, error)
func (*TCPClientTransport) WriteMessage ¶
func (t *TCPClientTransport) WriteMessage(msg *Message) error
type TCPServerTransport ¶
type TCPServerTransport struct {
// contains filtered or unexported fields
}
TCPServerTransport implements both a TCP server and ITransport
func NewTCPServerTransport ¶
func NewTCPServerTransport(address string, connectionHandler IConnectionHandler) (*TCPServerTransport, error)
NewTCPServerTransport creates a new TCP server transport
func (*TCPServerTransport) Close ¶
func (t *TCPServerTransport) Close() error
Close implements ITransport
func (*TCPServerTransport) ReadMessage ¶
func (t *TCPServerTransport) ReadMessage() (*Message, error)
func (*TCPServerTransport) WriteMessage ¶
func (t *TCPServerTransport) WriteMessage(msg *Message) error