Skip to content

Commit

Permalink
Merge pull request #66 from rigado/feat/readRssi
Browse files Browse the repository at this point in the history
Read RSSI
  • Loading branch information
estutzenberger authored Sep 2, 2022
2 parents 21fcab7 + c363527 commit 816f514
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Client interface {
WriteDescriptor(d *Descriptor, v []byte) error

// ReadRSSI retrieves the current RSSI value of remote peripheral. [Vol 2, Part E, 7.5.4]
ReadRSSI() int
ReadRSSI() (int8, error)

// ExchangeMTU set the ATT_MTU to the maximum possible value that can be supported by both devices [Vol 3, Part G, 4.3.1]
ExchangeMTU(rxMTU int) (txMTU int, err error)
Expand Down
3 changes: 3 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type Conn interface {
// RemoteAddr returns remote device's address.
RemoteAddr() Addr

// ReadRSSI returns the remote device's RSSI.
ReadRSSI() (int8, error)

// RxMTU returns the ATT_MTU which the local device is capable of accepting.
RxMTU() int

Expand Down
4 changes: 4 additions & 0 deletions linux/att/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func (c *Client) ExchangeMTU(clientRxMTU int) (serverRxMTU int, err error) {
return txMTU, nil
}

func (c *Client) ReadRSSI() (int8, error) {
return c.l2c.ReadRSSI()
}

// FindInformation obtains the mapping of attribute handles with their associated types.
// This allows a Client to discover the list of attributes and their types on a server.
// [Vol 3, Part F, 3.4.3.1 & 3.4.3.2]
Expand Down
6 changes: 3 additions & 3 deletions linux/gatt/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ func (p *Client) WriteDescriptor(d *ble.Descriptor, v []byte) error {
}

// ReadRSSI retrieves the current RSSI value of remote peripheral. [Vol 2, Part E, 7.5.4]
func (p *Client) ReadRSSI() int {
func (p *Client) ReadRSSI() (int8, error) {
p.Lock()
defer p.Unlock()
// TODO:
return 0

return p.ac.ReadRSSI()
}

// ExchangeMTU informs the server of the client’s maximum receive MTU size and
Expand Down
16 changes: 16 additions & 0 deletions linux/hci/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,22 @@ func (c *Conn) RemoteAddr() ble.Addr {
return ble.NewAddr(net.HardwareAddr([]byte{a[5], a[4], a[3], a[2], a[1], a[0]}).String())
}

func (c *Conn) ReadRSSI() (int8, error) {
read := &cmd.ReadRSSI{Handle: c.param.ConnectionHandle()}
readRsp := cmd.ReadRSSIRP{}

err := c.hci.Send(read, &readRsp)
if err != nil {
return 127, fmt.Errorf("failed to read rssi: %v", err)
}

if readRsp.Status != 0 {
return 127, fmt.Errorf("read rssi failed with status %x", readRsp.Status)
}

return readRsp.RSSI, nil
}

// RxMTU returns the MTU which the upper layer is capable of accepting.
func (c *Conn) RxMTU() int { return c.rxMTU }

Expand Down

0 comments on commit 816f514

Please sign in to comment.