frame

package
v0.0.0-...-eab7a3e Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeaderData is a byte for a data frame.
	HeaderData byte = 0x01
	// HeaderAck is a byte for a ack frame.
	HeaderAck = 0x06
	// HeaderNak is a byte for a nak frame.
	HeaderNak = 0x15
	// HeaderCan is a byte for a can frame.
	HeaderCan = 0x18

	// TypeRequest is for a request frame.
	TypeRequest byte = 0x00
	// TypeResponse is for a response frame.
	TypeResponse = 0x01
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Frame

type Frame struct {

	// Header is one of FrameHeader*
	Header byte

	// Length = byte length of all fields, excluding Header and Checksum
	Length byte

	// Type is one of FrameType*
	Type byte

	// Payload is the command id and command payload
	Payload []byte

	// Checksum = 0xff XOR Type XOR Length XOR payload[0] XOR [...payload[n]]
	Checksum byte
}

Frame contains a frame.

func NewAckFrame

func NewAckFrame() *Frame

NewAckFrame returns a new ack frame.

func NewCanFrame

func NewCanFrame() *Frame

NewCanFrame returns a new can frame.

func NewNakFrame

func NewNakFrame() *Frame

NewNakFrame returns a new nak frame.

func NewRequestFrame

func NewRequestFrame(payload []byte) *Frame

NewRequestFrame will build a new request frame.

func UnmarshalFrame

func UnmarshalFrame(frame []byte) *Frame

UnmarshalFrame turns a byte slice into a Frame.

func (*Frame) CalcChecksum

func (z *Frame) CalcChecksum() byte

CalcChecksum calculates the checksum for this frame, given the current data. The Z-Wave checksum is calculated by taking 0xFF XOR Length XOR Type XOR Payload[0:n].

func (*Frame) IsAck

func (z *Frame) IsAck() bool

IsAck returns whether this is an ack frame.

func (*Frame) IsCan

func (z *Frame) IsCan() bool

IsCan returns whether this is an can frame.

func (*Frame) IsData

func (z *Frame) IsData() bool

IsData returns whether this is a data frame.

func (*Frame) IsNak

func (z *Frame) IsNak() bool

IsNak returns whether this is an nak frame.

func (*Frame) IsRequest

func (z *Frame) IsRequest() bool

IsRequest checks if the frame is a request frame.

func (*Frame) IsResponse

func (z *Frame) IsResponse() bool

IsResponse checks if the frame is a response frame.

func (*Frame) MarshalBinary

func (z *Frame) MarshalBinary() ([]byte, error)

MarshalBinary will marshal this frame into a byte slice.

func (*Frame) SetChecksum

func (z *Frame) SetChecksum()

SetChecksum calculates the frame checksum and saves it into the frame.

func (*Frame) VerifyChecksum

func (z *Frame) VerifyChecksum() error

VerifyChecksum calculates a checksum for the frame and compares it to the frame's checksum, returning an error if they do not agree.

type ILayer

type ILayer interface {
	Write(frame *Frame)
	GetOutputChannel() <-chan Frame
}

ILayer is an interface for a frame layer.

type Layer

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

Layer contains a frame layer.

func NewFrameLayer

func NewFrameLayer(ctx context.Context, transportLayer io.ReadWriter, logger *zap.Logger) (*Layer, error)

NewFrameLayer will return a new frame layer.

func (*Layer) GetOutputChannel

func (l *Layer) GetOutputChannel() <-chan Frame

GetOutputChannel will return the output channel.

func (*Layer) Write

func (l *Layer) Write(frame *Frame)

type ParseEvent

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

ParseEvent represents a parsed frame and whether it was successful.

type ParseStatus

type ParseStatus int

ParseStatus respresents an enum for the status parsing a frame.

const (
	// ParseOk means a frame was successfully parsed.
	ParseOk ParseStatus = iota
	// ParseNotOk means a frame was not successfully parsed.
	ParseNotOk
	// ParseTimeout means a frame timed out.
	ParseTimeout
)

type Parser

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

Parser contains a frame parser.

func NewParser

func NewParser(ctx context.Context, input <-chan byte, output chan<- *ParseEvent, acks, naks, cans chan bool, logger *zap.Logger) *Parser

NewParser will return a new parser

Jump to

Keyboard shortcuts

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