sources

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sources provides capture.Source implementations for serial ports, TCP connections, and local files.

Index

Constants

This section is empty.

Variables

View Source
var CommonBaudRates = []int{9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600}

CommonBaudRates lists baud rates we routinely offer to users.

View Source
var DataBitsOptions = []int{5, 6, 7, 8}

DataBitsOptions enumerates supported data bit widths.

View Source
var FlowControlOptions = []SerialOption{
	{Code: "none", Label: "None"},
	{Code: "hardware", Label: "Hardware (RTS/CTS)"},
	{Code: "software", Label: "Software (XON/XOFF)"},
}

FlowControlOptions enumerates supported flow control strategies.

View Source
var ParityOptions = []SerialOption{
	{Code: "N", Label: "None"},
	{Code: "O", Label: "Odd"},
	{Code: "E", Label: "Even"},
	{Code: "M", Label: "Mark"},
	{Code: "S", Label: "Space"},
}

ParityOptions enumerates supported parity settings and their display labels.

View Source
var StopBitsOptions = []SerialOption{
	{Code: "1", Label: "1"},
	{Code: "1.5", Label: "1.5"},
	{Code: "2", Label: "2"},
}

StopBitsOptions enumerates supported stop bit configurations.

Functions

This section is empty.

Types

type Config

type Config struct {
	Port        string
	Baud        int
	Parity      string // "N", "O", "E", "M", "S"
	DataBits    int    // 5, 6, 7, 8
	StopBits    string // "1", "1.5", "2"
	FlowControl string // "none", "hardware", "software"
}

Config captures the serial connection parameters that can be shared across UIs and sources.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the standard serial defaults used throughout the application.

type File

type File struct {
	FileConfig
	// contains filtered or unexported fields
}

File represents a file-based data source for ingesting existing data files.

func NewFile

func NewFile(path string) (*File, error)

NewFile creates a file source with just a path (backward compatibility).

func NewFileWithConfig

func NewFileWithConfig(cfg FileConfig) (*File, error)

NewFileWithConfig constructs a File source from an explicit configuration.

func (*File) Close

func (f *File) Close() error

Close closes the file and stops the read loop.

func (*File) Frames

func (f *File) Frames() <-chan []byte

Frames returns the channel for receiving file data.

func (*File) Meta

func (f *File) Meta() core.SourceMeta

Meta returns source metadata for the file.

func (*File) Open

func (f *File) Open(ctx context.Context) error

Open starts reading the file and streaming data through the channel.

type FileConfig

type FileConfig struct {
	Path      string
	ChunkSize int  // bytes per chunk (0 = line-by-line)
	SkipLines int  // skip N header lines
	Follow    bool // tail -f mode (future enhancement)
}

FileConfig captures file ingestion parameters.

func DefaultFileConfig

func DefaultFileConfig() FileConfig

DefaultFileConfig returns standard file ingestion defaults.

type Serial

type Serial struct {
	Config
	// contains filtered or unexported fields
}

Serial is a capture source that reads newline-delimited frames from a hardware serial port. It opens the port in a background goroutine and streams frames over the channel returned by Frames.

func NewSerial

func NewSerial(port string, baud int) *Serial

NewSerial keeps backward compatibility for callers that only supply port and baud.

func NewSerialWithConfig

func NewSerialWithConfig(cfg Config) *Serial

NewSerialWithConfig constructs a Serial source from an explicit configuration.

func (*Serial) Close

func (s *Serial) Close() error

Close cancels the read loop and closes the underlying serial port.

func (*Serial) Frames

func (s *Serial) Frames() <-chan []byte

Frames returns the channel on which raw byte frames are delivered. The channel is closed when the read loop exits.

func (*Serial) Meta

func (s *Serial) Meta() core.SourceMeta

Meta returns the source metadata (kind, port, baud) for this serial source.

func (*Serial) Open

func (s *Serial) Open(ctx context.Context) error

Open configures and opens the serial port, then starts the background read loop. The context controls the lifetime of the read loop; cancelling it stops reading.

type SerialOption

type SerialOption struct {
	Code  string
	Label string
}

SerialOption exposes a code/label pair for presenting serial settings.

type TCP

type TCP struct {
	TCPConfig
	// contains filtered or unexported fields
}

TCP represents a TCP socket data source for ingesting streaming data.

func NewTCP

func NewTCP(host string, port int) (*TCP, error)

NewTCP creates a TCP source with just host and port (backward compatibility).

func NewTCPWithConfig

func NewTCPWithConfig(cfg TCPConfig) (*TCP, error)

NewTCPWithConfig constructs a TCP source from an explicit configuration.

func (*TCP) Address

func (t *TCP) Address() string

Address returns the full TCP address (host:port).

func (*TCP) Close

func (t *TCP) Close() error

Close closes the TCP connection and stops the read loop.

func (*TCP) Frames

func (t *TCP) Frames() <-chan []byte

Frames returns the channel for receiving TCP data.

func (*TCP) Meta

func (t *TCP) Meta() core.SourceMeta

Meta returns source metadata for the TCP connection.

func (*TCP) Open

func (t *TCP) Open(ctx context.Context) error

Open establishes the TCP connection and starts streaming data.

type TCPConfig

type TCPConfig struct {
	Host           string        // hostname or IP address
	Port           int           // TCP port
	ConnectTimeout time.Duration // connection timeout
	ReadTimeout    time.Duration // read timeout (0 = no timeout)
	BufferSize     int           // read buffer size in bytes
}

TCPConfig captures the TCP connection parameters.

func DefaultTCPConfig

func DefaultTCPConfig() TCPConfig

DefaultTCPConfig returns the standard TCP defaults.

Jump to

Keyboard shortcuts

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