Skip to content

Commit

Permalink
Merge pull request #42 from shirou/master
Browse files Browse the repository at this point in the history
add Getter/Setter of the service, characteristic, and descriptor.
  • Loading branch information
roylee17 committed Aug 19, 2015
2 parents a8c7745 + fc39add commit b9fc93c
Showing 1 changed file with 71 additions and 0 deletions.
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

0 comments on commit b9fc93c

Please sign in to comment.