core

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionManager

type ConnectionManager struct {
	Config   *config.ConnectionConfig
	Devices  map[uint8]*Device // SlaveID -> Device
	Listener net.Listener
	// contains filtered or unexported fields
}

ConnectionManager manages a Modbus connection (Server or Client-Dialer).

func NewConnectionManager

func NewConnectionManager(cfg *config.ConnectionConfig, devices []*Device) *ConnectionManager

NewConnectionManager creates a new manager.

func (*ConnectionManager) GetDevice

func (cm *ConnectionManager) GetDevice(unitID uint8) (*Device, bool)

Error types for internal use if needed, or just use modbus package constants

func (*ConnectionManager) HandleReadCoils

func (cm *ConnectionManager) HandleReadCoils(unitID uint8, addr uint16, quantity uint16) ([]bool, error)

func (*ConnectionManager) HandleReadDiscreteInputs

func (cm *ConnectionManager) HandleReadDiscreteInputs(unitID uint8, addr uint16, quantity uint16) ([]bool, error)

func (*ConnectionManager) HandleReadHoldingRegisters

func (cm *ConnectionManager) HandleReadHoldingRegisters(unitID uint8, addr uint16, quantity uint16) ([]uint16, error)

func (*ConnectionManager) HandleReadInputRegisters

func (cm *ConnectionManager) HandleReadInputRegisters(unitID uint8, addr uint16, quantity uint16) ([]uint16, error)

func (*ConnectionManager) HandleWriteCoils

func (cm *ConnectionManager) HandleWriteCoils(unitID uint8, addr uint16, values []bool) error

func (*ConnectionManager) HandleWriteRegisters

func (cm *ConnectionManager) HandleWriteRegisters(unitID uint8, addr uint16, values []uint16) error

func (*ConnectionManager) Start

func (cm *ConnectionManager) Start() error

Start starts the connection (Listen or Dial).

func (*ConnectionManager) Stop

func (cm *ConnectionManager) Stop() error

Stop stops the connection.

type Device

type Device struct {
	Config *config.DeviceConfig
	Type   *config.DeviceType
	// contains filtered or unexported fields
}

Device represents a simulated Modbus device.

func NewDevice

func NewDevice(cfg *config.DeviceConfig, devType *config.DeviceType) *Device

NewDevice creates a new Device instance.

func (*Device) AddEventListener

func (d *Device) AddEventListener(cb EventCallback)

AddEventListener adds a callback for device events.

func (*Device) GetParameterValue

func (d *Device) GetParameterValue(paramName string) (interface{}, error)

GetParameterValue reads and parses the current value of a parameter

func (*Device) ReadCoil

func (d *Device) ReadCoil(addr uint16) (bool, error)

HandleCoil handles coil read/write.

func (*Device) ReadDiscreteInput

func (d *Device) ReadDiscreteInput(addr uint16) (bool, error)

func (*Device) ReadRegister

func (d *Device) ReadRegister(fc int, addr uint16) (uint16, error)

ReadRegister handles external read requests.

func (*Device) UpdateLoop

func (d *Device) UpdateLoop(stopChan <-chan struct{})

UpdateLoop runs the script generation loop.

func (*Device) WriteCoil

func (d *Device) WriteCoil(addr uint16, val bool) error

func (*Device) WriteRegister

func (d *Device) WriteRegister(fc int, addr uint16, val uint16) error

WriteRegister handles external write requests.

type EventCallback

type EventCallback func(eventType EventType, paramName string, details string)

EventCallback is a function called when an event occurs.

type EventType

type EventType string

EventType defines the type of event.

const (
	EventRead  EventType = "READ"
	EventWrite EventType = "WRITE"
	EventError EventType = "ERROR"
)

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator handles dynamic value generation.

func NewGenerator

func NewGenerator() *Generator

NewGenerator creates a new Generator.

func (*Generator) Evaluate

func (g *Generator) Evaluate(script string) (interface{}, error)

Evaluate evaluates a script.

type LogLevel

type LogLevel int

LogLevel defines the severity of the log.

const (
	LogLevelInfo LogLevel = iota
	LogLevelError
	LogLevelDebug
)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger handles application logging.

func GetLogger

func GetLogger() *Logger

GetLogger returns the singleton logger instance.

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...interface{})

Debug logs a debug message.

func (*Logger) Error

func (l *Logger) Error(format string, args ...interface{})

Error logs an error message.

func (*Logger) Info

func (l *Logger) Info(format string, args ...interface{})

Info logs an info message.

func (*Logger) Log

func (l *Logger) Log(level LogLevel, format string, args ...interface{})

Log logs a message.

func (*Logger) Subscribe

func (l *Logger) Subscribe(handler func(level LogLevel, msg string))

Subscribe adds a handler to receive log messages.

Jump to

Keyboard shortcuts

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