Documentation
¶
Index ¶
Constants ¶
const (
SunSpec = 0x53756e53 // "SunS" - marker bytes used to confirm that a region of Modbus address space is laid out according to SunSpec standards
)
Variables ¶
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 )
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 ¶
FromLayoutXML reads a layout description from an XML stream.
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 ¶
func (s *SunSpecLayout) Open(a AddressSpaceDriver) (spi.ArraySPI, error)
Open scans the supplied address space and returns an array of the devices found.