node

package
v0.0.0-...-94bc3c9 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package node contains functionality to manage different types of nodes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager is responsible for maintaining node state, running rules, etc

func NewManger

func NewManger(nc *nats.Conn, appVersion, osVersionField string) *Manager

NewManger creates a new Manager

func (*Manager) Start

func (m *Manager) Start() error

Start manager

func (*Manager) Stop

func (m *Manager) Stop(_ error)

Stop manager

type Modbus

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

Modbus describes a modbus bus

func NewModbus

func NewModbus(nc *nats.Conn, node data.NodeEdge) (*Modbus, error)

NewModbus creates a new bus from a node

func (*Modbus) CheckIOs

func (b *Modbus) CheckIOs() error

CheckIOs goes through ios on the bus and handles any config changes

func (*Modbus) ClientIO

func (b *Modbus) ClientIO(io *ModbusIO) error

ClientIO processes an IO on a client bus

func (*Modbus) ClosePort

func (b *Modbus) ClosePort()

ClosePort closes both the server and client ports

func (*Modbus) InitRegs

func (b *Modbus) InitRegs(io *ModbusIONode)

InitRegs is used in server mode to initilize the internal modbus regs when a IO changes

func (*Modbus) LogError

func (b *Modbus) LogError(io *ModbusIONode, err error) error

LogError ...

func (*Modbus) ReadBusBit

func (b *Modbus) ReadBusBit(io *ModbusIO) error

ReadBusBit is used to read coil of discrete input values from bus this function modifies io.value. This should only be called from client.

func (*Modbus) ReadBusReg

func (b *Modbus) ReadBusReg(io *ModbusIO) error

ReadBusReg reads an io value from a reg from bus this function modifies io.value

func (*Modbus) ReadReg

func (b *Modbus) ReadReg(io *ModbusIONode) (float64, error)

ReadReg reads an value from a reg (internal, not bus) This should only be used on server

func (*Modbus) Run

func (b *Modbus) Run()

Run is routine that runs the logic for a bus. Intended to be run as a goroutine It assumes an initial dataset is obtained from the database and all updates come from NATs this routine may need to run fast scan times, so it should be doing slow things like reading the database.

func (*Modbus) SendPoint

func (b *Modbus) SendPoint(nodeID, pointType string, value float64) error

SendPoint sends a point over nats

func (*Modbus) ServerIO

func (b *Modbus) ServerIO(io *ModbusIONode) error

ServerIO processes an IO on a server bus

func (*Modbus) SetupPort

func (b *Modbus) SetupPort() error

SetupPort sets up io for the bus

func (*Modbus) Stop

func (b *Modbus) Stop()

Stop stops the bus and resets various fields

func (*Modbus) WriteBusHoldingReg

func (b *Modbus) WriteBusHoldingReg(io *ModbusIONode) error

WriteBusHoldingReg used to write register values to bus should only be used by client

func (*Modbus) WriteReg

func (b *Modbus) WriteReg(io *ModbusIONode) error

WriteReg writes an io value to a reg This should only be used on server

type ModbusIO

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

ModbusIO represents the state of a managed modbus io

func NewModbusIO

func NewModbusIO(nc *nats.Conn, node *ModbusIONode, chPoint chan<- pointWID) (*ModbusIO, error)

NewModbusIO creates a new modbus IO

func (*ModbusIO) Stop

func (io *ModbusIO) Stop()

Stop io

type ModbusIONode

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

ModbusIONode describes a modbus IO db node

func NewModbusIONode

func NewModbusIONode(busType string, node *data.NodeEdge) (*ModbusIONode, error)

NewModbusIONode Convert node to modbus IO node

func (*ModbusIONode) Changed

func (io *ModbusIONode) Changed(newIO *ModbusIONode) bool

Changed returns true if the config of the IO has changed FIXME, we should not need this once we get NATS wired

type ModbusManager

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

ModbusManager manages state of modbus

func NewModbusManager

func NewModbusManager(nc *nats.Conn, rootNodeID string) *ModbusManager

NewModbusManager creates a new modbus manager

func (*ModbusManager) Update

func (mm *ModbusManager) Update() error

Update queries DB for modbus nodes and synchronizes with internal structures and updates data

type ModbusNode

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

ModbusNode is the node data from the database

func NewModbusNode

func NewModbusNode(node data.NodeEdge) (*ModbusNode, error)

NewModbusNode converts a node to ModbusNode data structure

Jump to

Keyboard shortcuts

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