cemi

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cemi provides the functionality to parse and generate KNX CEMI-encoded frames.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pack

func Pack(buffer []byte, message Message)

Pack assembles a CEMI-encoded frame using the given message.

func Size

func Size(message Message) uint

Size returns the size for a CEMI-encoded frame with the given message.

func Unpack

func Unpack(data []byte, message *Message) (n uint, err error)

Unpack a message from a CEMI-encoded frame.

Types

type APCI

type APCI uint8

APCI is the Application-layer Protocol Control Information.

const (
	GroupValueRead         APCI = 0
	GroupValueResponse     APCI = 1
	GroupValueWrite        APCI = 2
	IndividualAddrWrite    APCI = 3
	IndividualAddrRequest  APCI = 4
	IndividualAddrResponse APCI = 5
	AdcRead                APCI = 6
	AdcResponse            APCI = 7
	MemoryRead             APCI = 8
	MemoryResponse         APCI = 9
	MemoryWrite            APCI = 10
	UserMessage            APCI = 11
	MaskVersionRead        APCI = 12
	MaskVersionResponse    APCI = 13
	Restart                APCI = 14
	Escape                 APCI = 15
)

These are usable APCI values.

func (APCI) IsGroupCommand

func (apci APCI) IsGroupCommand() bool

IsGroupCommand determines if the APCI indicates a group command.

type AppData

type AppData struct {
	Numbered  bool
	SeqNumber uint8
	Command   APCI
	Data      []byte
}

An AppData contains application data in a transport unit.

func (*AppData) Pack

func (app *AppData) Pack(buffer []byte)

Pack into a transport data unit including its leading length byte.

func (*AppData) Size

func (app *AppData) Size() uint

Size retrieves the packed size.

type ControlData

type ControlData struct {
	Numbered  bool
	SeqNumber uint8
	Command   uint8
}

A ControlData encodes control information in a transport unit.

func (*ControlData) Pack

func (control *ControlData) Pack(buffer []byte)

Pack into a transport data unit including its leading length byte.

func (ControlData) Size

func (ControlData) Size() uint

Size retrieves the packed size.

type ControlField1

type ControlField1 uint8

ControlField1 contains various control information.

const (
	// Control1StdFrame indicate that the frame is not an extended frame. Extended frames contain
	// application data units greater than 15 bytes.
	Control1StdFrame ControlField1 = 1 << 7

	// Control1NoRepeat causes a repeated frame not to be sent on the medium. If you send two
	// identical frames, than one of them will not be sent on the medium when this flag is present.
	Control1NoRepeat ControlField1 = 1 << 5

	// Control1NoSysBroadcast causes the frame to be transmitted in normal broadcast mode, instead
	// of system broadcast mode.
	Control1NoSysBroadcast ControlField1 = 1 << 4

	// Control1WantAck requests an acknowledgement. Only works for L_Data.req.
	Control1WantAck ControlField1 = 1 << 1

	// Control1HasError indicates an error. Only relevant in L_Data.con.
	Control1HasError ControlField1 = 1
)

func Control1Prio

func Control1Prio(prio Priority) ControlField1

Control1Prio generates the control field 1 flag for the given priority.

type ControlField2

type ControlField2 uint8

ControlField2 contains various control information.

const (
	// Control2GroupAddr determines that the destination address inside the frame is a group address,
	// instead of an individual address.
	Control2GroupAddr ControlField2 = 1 << 7

	// Control2LTEFrame indicates that the frame is a LTE-frame.
	Control2LTEFrame ControlField2 = 1 << 2
)

func Control2Hops

func Control2Hops(hops uint8) ControlField2

Control2Hops generates the control field 2 flag for the given number of hops.

func (ControlField2) Hops

func (ctrl2 ControlField2) Hops() uint8

Hops retrieves the number of hops.

func (ControlField2) IsGroupAddr

func (ctrl2 ControlField2) IsGroupAddr() bool

IsGroupAddr determines if the destination address is a group address.

type GroupAddr

type GroupAddr uint16

GroupAddr is an address for a KNX group object.

func NewGroupAddr2

func NewGroupAddr2(a, b uint8) GroupAddr

NewGroupAddr2 generates a group address with format a/b.

func NewGroupAddr3

func NewGroupAddr3(a, b, c uint8) GroupAddr

NewGroupAddr3 generates a group address with format a/b/c.

func NewGroupAddrString

func NewGroupAddrString(addr string) (GroupAddr, error)

NewGroupAddrString parses the given string as a group address. Supported formats are %d/%d/%d, %d/%d and %d.

func (GroupAddr) String

func (addr GroupAddr) String() string

String generates a string representation.

type IndividualAddr

type IndividualAddr uint16

IndividualAddr is an address for a KNX device.

func NewIndividualAddr2

func NewIndividualAddr2(a, b uint8) IndividualAddr

NewIndividualAddr2 generates a group address with format a/b.

func NewIndividualAddr3

func NewIndividualAddr3(a, b, c uint8) IndividualAddr

NewIndividualAddr3 generates a group address with format a/b/c.

func NewIndividualAddrString

func NewIndividualAddrString(addr string) (IndividualAddr, error)

NewIndividualAddrString parses the given string as a individual address. Supported formats are %d.%d.%d, %d.%d and %d.

func (IndividualAddr) String

func (addr IndividualAddr) String() string

String generates a string representation.

type Info

type Info []byte

Info is the additional info segment of a CEMI-encoded frame.

func (Info) Pack

func (info Info) Pack(buffer []byte)

Pack the info structure into the buffer.

func (Info) Size

func (info Info) Size() uint

Size returns the packed size.

func (*Info) Unpack

func (info *Info) Unpack(data []byte) (n uint, err error)

Unpack initializes the structure by parsing the given data.

type LBusmonInd

type LBusmonInd []byte

A LBusmonInd represents a L_Busmon.ind message.

func (LBusmonInd) MessageCode

func (LBusmonInd) MessageCode() MessageCode

MessageCode returns the message code for L_Busmon.ind.

func (LBusmonInd) Pack

func (lbm LBusmonInd) Pack(buffer []byte)

Pack the message body into the buffer.

func (LBusmonInd) Size

func (lbm LBusmonInd) Size() uint

Size returns the packed size.

func (*LBusmonInd) Unpack

func (lbm *LBusmonInd) Unpack(data []byte) (n uint, err error)

Unpack initializes the structure by parsing the given data.

type LData

type LData struct {
	Info        Info
	Control1    ControlField1
	Control2    ControlField2
	Source      IndividualAddr
	Destination uint16
	Data        TransportUnit
}

A LData is a link-layer data frame. L_Data.req, L_Data.con and L_Data.ind share this structure.

func (*LData) Pack

func (ldata *LData) Pack(buffer []byte)

Pack the message body into the buffer.

func (*LData) Size

func (ldata *LData) Size() uint

Size returns the packed size.

func (*LData) Unpack

func (ldata *LData) Unpack(data []byte) (n uint, err error)

Unpack initializes the structure by parsing the given data.

type LDataCon

type LDataCon struct {
	LData
}

A LDataCon represents a L_Data.con message body.

func (LDataCon) MessageCode

func (LDataCon) MessageCode() MessageCode

MessageCode returns the message code for L_Data.con.

type LDataInd

type LDataInd struct {
	LData
}

A LDataInd represents a L_Data.ind message body.

func (LDataInd) MessageCode

func (LDataInd) MessageCode() MessageCode

MessageCode returns the message code for L_Data.ind.

type LDataReq

type LDataReq struct {
	LData
}

A LDataReq represents a L_Data.req message body.

func (LDataReq) MessageCode

func (LDataReq) MessageCode() MessageCode

MessageCode returns the message code for L_Data.req.

type LRaw

type LRaw []byte

A LRaw is a raw link-layer frame. L_Raw.req, L_Raw.con and L_Raw.ind share this structure.

func (LRaw) Pack

func (lraw LRaw) Pack(buffer []byte)

Pack the message body into the buffer.

func (LRaw) Size

func (lraw LRaw) Size() uint

Size returns the packed size.

func (*LRaw) Unpack

func (lraw *LRaw) Unpack(data []byte) (n uint, err error)

Unpack initializes the structure by parsing the given data.

type LRawCon

type LRawCon struct {
	LRaw
}

A LRawCon represents a L_Raw.con message body.

func (LRawCon) MessageCode

func (LRawCon) MessageCode() MessageCode

MessageCode returns the message code for L_Raw.con.

type LRawInd

type LRawInd struct {
	LRaw
}

A LRawInd represents a L_Raw.ind message body.

func (LRawInd) MessageCode

func (LRawInd) MessageCode() MessageCode

MessageCode returns the message code for L_Raw.ind.

type LRawReq

type LRawReq struct {
	LRaw
}

A LRawReq represents a L_Raw.req message body.

func (LRawReq) MessageCode

func (LRawReq) MessageCode() MessageCode

MessageCode returns the message code for L_Raw.req.

type Message

type Message interface {
	util.Packable
	MessageCode() MessageCode
}

Message is the body of a CEMI-encoded frame.

type MessageCode

type MessageCode uint8

MessageCode is used to identify the type of message inside a CEMI-encoded frame.

const (
	// LBusmonIndCode is the message code for L_Busmon.ind.
	LBusmonIndCode MessageCode = 0x2B

	// LDataReqCode is the message code for L_Data.req.
	LDataReqCode MessageCode = 0x11

	// LDataIndCode is the message code for L_Data.ind.
	LDataIndCode MessageCode = 0x29

	// LDataConCode is the message code for L_Data.con.
	LDataConCode MessageCode = 0x2E

	// LRawReqCode is the message code for L_Raw.req.
	LRawReqCode MessageCode = 0x10

	// LRawIndCode is the message code for L_Raw.ind.
	LRawIndCode MessageCode = 0x2D

	// LRawConCode is the message code for L_Raw.con.
	LRawConCode MessageCode = 0x2F
)

func (MessageCode) String

func (code MessageCode) String() string

String converts the message code to a string.

type Priority

type Priority uint8

A Priority determines the priority.

const (
	// PrioSystem is for high priority, configuration and management frames.
	PrioSystem Priority = 0

	// PrioNormal indicates normal priority. Ideal for short frames.
	PrioNormal Priority = 1

	// PrioUrgent indicates urgent priority.
	PrioUrgent Priority = 2

	// PrioLow indicates low priority. Ideal for long frames.
	PrioLow Priority = 3
)

type TransportUnit

type TransportUnit interface {
	util.Packable
}

A TransportUnit is responsible to transport data.

type UnsupportedMessage

type UnsupportedMessage struct {
	Code MessageCode
	Data []byte
}

An UnsupportedMessage is the raw representation of a message inside a CEMI-encoded frame.

func (*UnsupportedMessage) MessageCode

func (body *UnsupportedMessage) MessageCode() MessageCode

MessageCode returns the message code.

func (*UnsupportedMessage) Pack

func (body *UnsupportedMessage) Pack(buffer []byte)

Pack the message body into the buffer.

func (*UnsupportedMessage) Size

func (body *UnsupportedMessage) Size() uint

Size returns the packed size.

func (*UnsupportedMessage) Unpack

func (body *UnsupportedMessage) Unpack(data []byte) (uint, error)

Unpack initializes the structure by parsing the given data.

Jump to

Keyboard shortcuts

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