Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Getter/Setter of the service, characteristic, and descriptor. #42

Merged
merged 1 commit into from
Aug 19, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 71 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ func (s *Service) Name() string {
return knownServices[s.uuid.String()].Name
}

// Handle returns the Handle of the service.
func (s *Service) Handle() uint16 { return s.h }

// EndHandle returns the End Handle of the service.
func (s *Service) EndHandle() uint16 { return s.endh }

// SetHandle sets the Handle of the service.
func (s *Service) SetHandle(h uint16) { s.h = h }

// SetEndHandle sets the End Handle of the service.
func (s *Service) SetEndHandle(endh uint16) { s.endh = endh }

// SetCharacteristics sets the Characteristics of the service.
func (s *Service) SetCharacteristics(chars []*Characteristic) { s.chars = chars }

// Characteristic returns the contained characteristic of this service.
func (s *Service) Characteristics() []*Characteristic { return s.chars }

Expand All @@ -125,6 +140,46 @@ type Characteristic struct {
endh uint16
}

// NewCharacteristic creates and returns a Characteristic.
func NewCharacteristic(u UUID, s *Service, props Property, h uint16, vh uint16) *Characteristic {
c := &Characteristic{
uuid: u,
svc: s,
props: props,
h: h,
vh: vh,
}

return c
}

// Handle returns the Handle of the characteristic.
func (c *Characteristic) Handle() uint16 { return c.h }

// VHandle returns the Value Handle of the characteristic.
func (c *Characteristic) VHandle() uint16 { return c.vh }

// EndHandle returns the End Handle of the characteristic.
func (c *Characteristic) EndHandle() uint16 { return c.endh }

// Descriptor returns the Descriptor of the characteristic.
func (c *Characteristic) Descriptor() *Descriptor { return c.cccd }

// SetHandle sets the Handle of the characteristic.
func (c *Characteristic) SetHandle(h uint16) { c.h = h }

// SetVHandle sets the Value Handle of the characteristic.
func (c *Characteristic) SetVHandle(vh uint16) { c.vh = vh }

// SetEndHandle sets the End Handle of the characteristic.
func (c *Characteristic) SetEndHandle(endh uint16) { c.endh = endh }

// SetDescriptor sets the Descriptor of the characteristic.
func (c *Characteristic) SetDescriptor(cccd *Descriptor) { c.cccd = cccd }

// SetDescriptors sets the list of Descriptor of the characteristic.
func (c *Characteristic) SetDescriptors(descs []*Descriptor) { c.descs = descs }

// UUID returns the UUID of the characteristic.
func (c *Characteristic) UUID() UUID {
return c.uuid
Expand Down Expand Up @@ -267,6 +322,22 @@ type Descriptor struct {
whandler WriteHandler
}

// Handle returns the Handle of the descriptor.
func (d *Descriptor) Handle() uint16 { return d.h }

// SetHandle sets the Handle of the descriptor.
func (d *Descriptor) SetHandle(h uint16) { d.h = h }

// NewDescriptor creates and returns a Descriptor.
func NewDescriptor(u UUID, h uint16, char *Characteristic) *Descriptor {
cd := &Descriptor{
uuid: u,
h: h,
char: char,
}
return cd
}

// UUID returns the UUID of the descriptor.
func (d *Descriptor) UUID() UUID {
return d.uuid
Expand Down