gatts

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EvtBase = 0x50
	EvtLast = 0x6F
)
View Source
const (
	EvtWrite          = EvtBase + 0 // write operation performed
	EvtRWAuthorizeReq = EvtBase + 1 // read/write authorization request
	EvtSysAttrMissing = EvtBase + 2 // persistent sys. attr. access is pending
	EvtHVC            = EvtBase + 3 // handle value confirmation
	EvtSCConfirm      = EvtBase + 4 // service changed confirmation
	EvtExchangeMTUReq = EvtBase + 5 // exchange MTU request
	EvtTimeout        = EvtBase + 6 // peer failed to resp. to ATT req. in time
	EvtHVNTxComplete  = EvtBase + 7 // handle val. notification Tx complete
)
View Source
const ErrorBase = ble.ErrorBase + 0x400

Variables

This section is empty.

Functions

func GetSysAttr

func GetSysAttr(connHandle ble.Handle, data []byte, flags SysAttrFlags) (int, error)

GetSysAttr retrieves the persistent system attributes.

func HVX

func HVX(connHandle ble.Handle, params *HVXParams, data ...byte) (int, error)

HVX handles value notification or indication. If len(data) != 0 the attribute will be updated before sending the notification or indication. HVX returns the number of bytes written to attribute.

func SetSysAttr

func SetSysAttr(connHandle ble.Handle, data []byte, flags SysAttrFlags) error

SetSysAttr sets the persistent system attributes for a connection.

Types

type Attr

type Attr struct {
	UUID     *ble.UUID // attribute UUID.
	Meta     *AttrMeta // metadata
	InitLen  uint16    // initial attribute value length in bytes
	InitOffs uint16    // initial attribute value offset in bytes
	MaxLen   uint16    // maximum attribute value length in bytes
	Value    *byte     // pointer to the attribute data
}

type AttrMeta

type AttrMeta struct {
	ReadPerm  gap.ConnSecMode
	WritePerm gap.ConnSecMode
	Options   AttrOptions
}

type AttrOptions

type AttrOptions uint8
const (
	VLenAttr  AttrOptions = 1 << 0 // variable length attribute
	ValLoc    AttrOptions = 3 << 1 // attribute value location
	ValStack  AttrOptions = 1 << 1 // attr. value located in stack memory
	ValUser   AttrOptions = 2 << 1 // attr. value located in user memory
	ReadAuth  AttrOptions = 1 << 3 // authoriz. requested on every read
	WriteAuth AttrOptions = 1 << 4 // authoriz. requested on every write
)

type CharHandles

type CharHandles struct {
	Value    Handle // handle to the characteristic value.
	UserDesc Handle // handle to the user description descriptor
	CCCD     Handle // handle to the client char. conf. descriptor
	SCCD     Handle // handle to the server char. conf. descriptor
}

func AddCharacteristic

func AddCharacteristic(service Handle, charMeta *CharMeta, charVal *Attr) (handles CharHandles, err error)

type CharMeta

type CharMeta struct {
	Props           gatt.CharProps    // characteristic properties
	ExtProps        gatt.CharExtProps // characteristic extended properties.
	UserDesc        *byte             // pointer to a UTF-8 encoded string
	UserDescMaxSize uint16
	UserDescSize    uint16
	PF              *CharPF   // presentation format (CPF descriptor)
	UserDescMeta    *AttrMeta // user description descriptor metadata
	CCCDMeta        *AttrMeta // client char. conf. descriptor metadeta
	SCCDMeta        *AttrMeta // server char. conf. descriptor metadata
}

type CharPF

type CharPF struct {
	Format    gatt.PF // format of the value
	Exponent  int8    // exponent for integer data types
	Unit      uint16  // unit from Bluetooth Assigned Numbers
	Namespace uint8   // namespace from Bluetooth Assigned Numbers
	Desc      uint16  // namespace description from Bluetooth Assigned Numbers
}

type Error

type Error uint32
const (
	ErrInvalidAttrType Error = ErrorBase + 0 // invalid attribute type
	ErrSysAttrMissing  Error = ErrorBase + 1 // system attributes missing
)

func (Error) Error

func (e Error) Error() string

type HVXParams

type HVXParams struct {
	Handle Handle       // characteristic value handle
	Type   gatt.HVXType // indication or notification
	Offset uint16       // field offset within the attribute value
	Len    uint16       // field length in bytes (0 means variable length)
}

type Handle

type Handle uint16

func AddService

func AddService(typ ServiceType, uuid *ble.UUID) (h Handle, err error)

AddService adds a service.

type Op

type Op uint8
const (
	OpInvalid            Op = 0 // invalid operation
	OpWriteReq           Op = 1 // write request
	OpWriteCmd           Op = 2 // write command
	OpSignWriteCmd       Op = 3 // signed write command
	OpPrepWriteReq       Op = 4 // prepare write request
	OpExecWriteReqCancel Op = 5 // cancel all prepared writes
	OpExecWriteReqNow    Op = 6 // immediately execute all prepared writes
)

type ServiceType

type ServiceType uint8
const (
	InvalidService   ServiceType = 0
	PrimaryService   ServiceType = 1
	SecondaryService ServiceType = 2
)

type SysAttrFlags

type SysAttrFlags uint32
const (
	SysAttrSys SysAttrFlags = 1 << 0 // restrict system attributes to system services
	SysAttrUsr SysAttrFlags = 1 << 1 // restrict system attributes to user services
)

type Write

type Write struct {
	ble.EvtHdr
	Handle       Handle   // attribute handle
	UUID         ble.UUID // attribute UUID
	Op           Op       // type of write operation
	AuthRequired bool     // writing operation deferred due to auth. requirement
	Offset       uint16   // offset for the write operation
	// contains filtered or unexported fields
}

func (*Write) Data

func (w *Write) Data() []byte

Jump to

Keyboard shortcuts

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