znp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Implements a Controller for Texas Instrument's CC253X-based dongles.

For documentation of the serial protocol, please refer to the following documents: "ZNP Interface Specification", "Z-Stack Monitor and Test API".

Index

Constants

View Source
const (
	ResetReasonPowerUp  = 0x00
	ResetReasonExternal = 0x01
	ResetReasonWatchDog = 0x02
)
View Source
const (
	LatencyReqNoLatency   = 0x00
	LatencyReqFastBeacons = 0x01
	LatencyReqSlowBeacons = 0x02
)
View Source
const (
	CapabilitiesAlternatePanCoordinator = 1 << 0
	CapabilitiesRouter                  = 1 << 1
	CapabilitiesMainPowered             = 1 << 2
	CapabilitiesReceiverOnWhenIdle      = 1 << 3
	CapabilitiesSecurityCapability      = 1 << 6
)
View Source
const FRAME_MAX_DATA_LENGTH = 250
View Source
const SOF = 0xFE // start of frame

Variables

View Source
var (
	ErrCommandUnknownFrameHeader = errors.New("unknown serial frame header")
	ErrCommandInvalidFrame       = errors.New("invalid serial frame")
)
View Source
var (
	ErrInvalidFrame = errors.New("invalid frame")
	ErrGarbage      = errors.New("garbage")
)
View Source
var DeviceStateNames = []string{
	"InitializedNotStarted",
	"InitializedNotConnected",
	"Discovering",
	"Joining",
	"Rejoining",
	"JoinedNotAuthenticated",
	"EndDevice",
	"Router",
	"CoordinatorStarting",
	"Coordinator",
	"Orphan",
}
View Source
var ErrTimeout = errors.New("command timed out")

Functions

This section is empty.

Types

type AfDataConfirm

type AfDataConfirm struct {
	Status         byte
	Endpoint       uint8
	TransSeqNumber uint8
}

type AfDataRequest

type AfDataRequest struct {
	DstAddr        uint16
	DstEndpoint    uint8
	SrcEndpoint    uint8
	ClusterID      uint16
	TransSeqNumber uint8
	Options        uint8
	Radius         uint8
	Data           []byte
}

type AfDataResponse

type AfDataResponse struct {
	Status byte
}

type AfIncomingMsg

type AfIncomingMsg struct {
	GroupID        uint16
	ClusterID      uint16
	SrcAddr        uint16
	SrcEndpoint    uint8
	DstEndpoint    uint8
	WasBroadcast   uint8
	LinkQuality    uint8
	SecureUse      uint8
	TimeStamp      uint32
	TransSeqNumber uint8
	Data           []byte
}

type AfRegisterRequest

type AfRegisterRequest struct {
	Endpoint       uint8
	AppProfID      uint16
	AppDeviceID    uint16
	AddDevVer      uint8
	LatencyReq     uint8
	AppInClusters  []uint16
	AppOutClusters []uint16
}

type AfRegisterResponse

type AfRegisterResponse struct {
	Status byte
}

type Callbacks

type Callbacks struct {
	BeforeWrite func(command interface{})
	AfterRead   func(command interface{})

	OnReadError  func(err error) ErrorHandling
	OnParseError func(err error, frame Frame) ErrorHandling
}

type Controller

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

func NewController

func NewController(settings zigbee.ControllerSettings) (*Controller, error)

func (*Controller) Close

func (c *Controller) Close() error

func (*Controller) PermitJoining

func (c *Controller) PermitJoining(enabled bool) error

func (*Controller) RegisterPermanentHandler

func (c *Controller) RegisterPermanentHandler(commandPrototype interface{}) *Handler

func (*Controller) Send

func (c *Controller) Send(message zigbee.OutgoingMessage) error

func (*Controller) Start

func (c *Controller) Start() (chan zigbee.IncomingMessage, error)

func (*Controller) WriteCommand

func (c *Controller) WriteCommand(command interface{}) (interface{}, error)

func (*Controller) WriteCommandTimeout

func (c *Controller) WriteCommandTimeout(command interface{}, timeout time.Duration) (interface{}, error)

type DeviceState

type DeviceState uint8
const (
	DeviceStateInitializedNotStarted   DeviceState = 0x00 // Initialized - not started automatically
	DeviceStateInitializedNotConnected DeviceState = 0x01 // Initialized - not connected to anything
	DeviceStateDiscovering             DeviceState = 0x02 // Discovering PANs to join
	DeviceStateJoining                 DeviceState = 0x03 // Joining a PAN
	DeviceStateRejoining               DeviceState = 0x04 // Rejoining a PAN, only for end devices
	DeviceStateJoinedNotAuthenticated  DeviceState = 0x05 // Joined but not yet authenticated by trust center
	DeviceStateEndDevice               DeviceState = 0x06 // Started as device after authentication
	DeviceStateRouter                  DeviceState = 0x07 // Device joined, authenticated and is a router
	DeviceStateCoordinatorStarting     DeviceState = 0x08 // Starting as ZigBee Coordinator
	DeviceStateCoordinator             DeviceState = 0x09 // Started as ZigBee Coordinator
	DeviceStateOrphan                  DeviceState = 0x0A // Device has lost information about its parent
)

func (DeviceState) String

func (state DeviceState) String() string

type Endpoint

type Endpoint struct {
	Endpoint  uint8
	AppProfID uint16
}

type ErrorHandling

type ErrorHandling int
const (
	ErrorHandlingPanic    ErrorHandling = 0
	ErrorHandlingStop     ErrorHandling = 1
	ErrorHandlingContinue ErrorHandling = 2
)

type Frame

type Frame struct {
	FrameHeader
	Data []byte
}

One frame of the Z-Stack serial protocol.

type FrameHeader

type FrameHeader struct {
	Type      FrameType
	Subsystem FrameSubsystem
	ID        FrameID
}

type FrameID

type FrameID byte

func (FrameID) String

func (id FrameID) String() string

type FrameSubsystem

type FrameSubsystem byte
const (
	FRAME_SUBSYSTEM_RPC_ERROR FrameSubsystem = 0
	FRAME_SUBSYSTEM_SYS       FrameSubsystem = 1
	FRAME_SUBSYSTEM_MAC       FrameSubsystem = 2
	FRAME_SUBSYSTEM_NWK       FrameSubsystem = 3
	FRAME_SUBSYSTEM_AF        FrameSubsystem = 4 // application framework
	FRAME_SUBSYSTEM_ZDO       FrameSubsystem = 5 // zigbee device object
	FRAME_SUBSYSTEM_SAPI      FrameSubsystem = 6 // simple api
	FRAME_SUBSYSTEM_UTIL      FrameSubsystem = 7
	FRAME_SUBSYSTEM_DEBUG     FrameSubsystem = 8
	FRAME_SUBSYSTEM_APP       FrameSubsystem = 9
)

func (FrameSubsystem) String

func (s FrameSubsystem) String() string

type FrameType

type FrameType byte
const (
	FRAME_TYPE_POLL FrameType = 0
	FRAME_TYPE_SREQ FrameType = 1 // synchronous request
	FRAME_TYPE_AREQ FrameType = 2 // asynchronous reqest
	FRAME_TYPE_SRSP FrameType = 3 // synchronous response
)

func (FrameType) String

func (t FrameType) String() string

type Handler

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

func (*Handler) Receive

func (h *Handler) Receive() (interface{}, error)

type Port

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

func NewPort

func NewPort(name string, callbacks Callbacks) (*Port, error)

func (*Port) Close

func (p *Port) Close() error

func (*Port) RegisterOneOffHandler

func (p *Port) RegisterOneOffHandler(commandPrototype interface{}) *Handler

func (*Port) RegisterPermanentHandler

func (p *Port) RegisterPermanentHandler(commandPrototype interface{}) *Handler

func (*Port) WriteCommand

func (p *Port) WriteCommand(command interface{}) (interface{}, error)

func (*Port) WriteCommandTimeout

func (p *Port) WriteCommandTimeout(command interface{}, timeout time.Duration) (interface{}, error)

func (*Port) WriteMagicByteForBootloader

func (p *Port) WriteMagicByteForBootloader() error

type SysOsalNvReadRequest

type SysOsalNvReadRequest struct {
	ID     uint16
	Offset uint8
}

type SysOsalNvReadResponse

type SysOsalNvReadResponse struct {
	Status byte
	Value  []byte
}

type SysOsalNvWriteRequest

type SysOsalNvWriteRequest struct {
	ID     uint16
	Offset uint8
	Value  []byte
}

type SysOsalNvWriteResponse

type SysOsalNvWriteResponse struct {
	Status byte
}

type SysResetInd

type SysResetInd struct {
	Reason       uint8
	TransportRev uint8
	Product      uint8
	MajorRel     uint8
	MinorRel     uint8
	MaintRel     uint8
}

type SysVersionRequest

type SysVersionRequest struct{}

type SysVersionResponse

type SysVersionResponse struct {
	TransportRev uint8
	Product      uint8
	MajorRel     uint8
	MinorRel     uint8
	MaintRel     uint8
	Revision     uint32
}

type UtilGetDeviceInfoRequest

type UtilGetDeviceInfoRequest struct{}

type UtilGetDeviceInfoResponse

type UtilGetDeviceInfoResponse struct {
	Status       byte
	IEEEAddr     uint64
	ShortAddr    uint16
	DeviceType   uint8
	DeviceState  DeviceState
	AssocDevices []uint16
}

type ZBReadConfigurationResponse

type ZBReadConfigurationResponse struct {
	Status   byte
	ConfigID uint8
	Value    []byte
}

type ZbReadConfigurationRequest

type ZbReadConfigurationRequest struct {
	ConfigID uint8
}

type ZbWriteConfigurationRequest

type ZbWriteConfigurationRequest struct {
	ConfigID uint8
	Value    []byte
}

type ZbWriteConfigurationResponse

type ZbWriteConfigurationResponse struct {
	Status byte
}

type ZdoActiveEP

type ZdoActiveEP struct {
	SrcAddr   uint16
	Status    byte
	NWKAddr   uint16
	ActiveEPs []uint8
}

type ZdoActiveEPRequest

type ZdoActiveEPRequest struct {
	DstAddr           uint16
	NWKAddrOfInterest uint16
}

type ZdoActiveEPResponse

type ZdoActiveEPResponse struct {
	Status byte
}

type ZdoEndDeviceAnnceInd

type ZdoEndDeviceAnnceInd struct {
	SrcAddr      uint16
	NwkAddr      uint16
	IEEEAddr     uint64
	Capabilities byte
}

type ZdoExtNwkInfoRequest

type ZdoExtNwkInfoRequest struct{}

type ZdoExtNwkInfoResponse

type ZdoExtNwkInfoResponse struct {
	ShortAddress          uint16
	PanID                 uint16
	ParentAddress         uint16
	ExtendedPanID         uint64
	ExtendedParentAddress uint64
	Channel               uint16
}

type ZdoMgmtPermitJoin

type ZdoMgmtPermitJoin struct {
	SrcAddr uint16
	Status  byte
}

type ZdoMgmtPermitJoinRequest

type ZdoMgmtPermitJoinRequest struct {
	AddrMode       byte
	DstAddr        uint16
	Duration       byte
	TCSignificance byte
}

type ZdoMgmtPermitJoinResponse

type ZdoMgmtPermitJoinResponse struct {
	Status byte
}

type ZdoPermitJoinInd

type ZdoPermitJoinInd struct {
	Duration byte
}

type ZdoSrcRtgInd

type ZdoSrcRtgInd struct {
	DstAddr   uint16
	RelayList []uint16
}

Informs the host device about the receipt of a source route to a given device.

type ZdoStartupFromAppRequest

type ZdoStartupFromAppRequest struct {
	StartDelay uint16
}

type ZdoStartupFromAppResponse

type ZdoStartupFromAppResponse struct {
	Status byte
}

type ZdoStateChangeInd

type ZdoStateChangeInd struct {
	State DeviceState
}

type ZdoTcDevInd

type ZdoTcDevInd struct {
	SrcNwkAddr    uint16
	WasBroadcast  uint64
	ParentNwkAddr uint16
}

Trust Center Device Indication.

Jump to

Keyboard shortcuts

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