layout

package
v0.0.0-...-1daccfa Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SunSpec = 0x53756e53 // "SunS" - marker bytes used to confirm that a region of Modbus address space is laid out according to SunSpec standards
)

Variables

View Source
var (
	ErrNotSunspecDevice = errors.New("not a SunSpec device") // if the Modbus address space doesn't contain the expected marker bytes
	ErrShortRead        = errors.New("short read")           // if an attempt to read from the Modbus addess space returns fewer bytes than expected
	ErrTimeout          = errors.New("timeout")              // if a timeout occurred
)
View Source
var ErrAbsoluteAddress = errors.New("The absolute address for block cannot be calculated from the layout.")

Functions

This section is empty.

Types

type AddressSpaceDriver

type AddressSpaceDriver interface {
	spi.Driver
	BaseOffsets() []uint16
	ReadWords(address uint16, length uint16) ([]byte, error)
}

AddressSpaceDriver abstracts the behaviour of drivers that are mapped onto a linear address space, so that the same AddressSpaceLayout implementation can be used across different linear address space implementations (e.g. memory & Modbus)

type AddressSpaceLayout

type AddressSpaceLayout interface {
	Open(a AddressSpaceDriver) (spi.ArraySPI, error)
}

AddressSpaceLayout encapsulates an algorithm for scanning an address space for devices. There are two implementations - layout.SunSpecLayout and layout.RawLayout.

type RawDeviceLayout

type RawDeviceLayout struct {
	XMLName xml.Name         `xml:"device"`
	Models  []RawModelLayout `xml:"model"`
}

RawDeviceLayout is a slice of RawModelLayouts

type RawLayout

type RawLayout struct {
	XMLName xml.Name          `xml:"layout"`
	Name    string            `xml:"name,attr,omitempty"`
	Devices []RawDeviceLayout `xml:"device"`
}

RawLayout is the type of layout used for non-SunSpec address spaces. This means arbitrary Modbus address spaces where blocks are located at arbitrary addresses in an address space and neither the model ID nor the block length are encoded in the address space itself.

The intent of RawLayout is to allow the sunspec API to be used effectively with non-SunSpec address spaces, assuming the work has been done to markup the address space with SMDX models and an XML document that maps addresses to model ids.

func FromLayoutXML

func FromLayoutXML(reader io.Reader) (*RawLayout, error)

FromLayoutXML reads a layout description from an XML stream.

func (*RawLayout) Open

func (s *RawLayout) Open(driver AddressSpaceDriver) (spi.ArraySPI, error)

Opens an address space with a raw layout.

type RawModelLayout

type RawModelLayout struct {
	XMLName xml.Name        `xml:"model"`
	ModelId sunspec.ModelId `xml:"id,attr"`
	Address *uint16         `xml:"addr,attr,omitempty"`
	Repeats *uint16         `xml:"repeats,attr,omitempty"`
}

RawModel layout specifies the model ID used to describe a block of memory at an Address

type SunSpecLayout

type SunSpecLayout struct {
}

SunspecLayout is the type of layout that understands the SunSpec layout conventions.

func (*SunSpecLayout) Open

Open scans the supplied address space and returns an array of the devices found.

Jump to

Keyboard shortcuts

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