Repository: incubator-mynewt-newtmgr
Updated Branches:
  refs/heads/master d42718972 -> f573ad10e


nmxact - Add missing BLE advertisement fields.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/commit/25097817
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/tree/25097817
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/diff/25097817

Branch: refs/heads/master
Commit: 25097817c6c8b1b2ce904082ddf4a25aa0ee40d7
Parents: d427189
Author: Christopher Collins <ccoll...@apache.org>
Authored: Thu Apr 6 12:37:53 2017 -0700
Committer: Christopher Collins <ccoll...@apache.org>
Committed: Fri Apr 7 10:09:56 2017 -0700

----------------------------------------------------------------------
 nmxact/bledefs/bledefs.go | 102 +++++++++++++++++++++++++++++++++++++++--
 nmxact/nmble/ble_proto.go |  72 ++++++++++-------------------
 nmxact/nmble/ble_util.go  |  58 ++++++++++-------------
 3 files changed, 147 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/25097817/nmxact/bledefs/bledefs.go
----------------------------------------------------------------------
diff --git a/nmxact/bledefs/bledefs.go b/nmxact/bledefs/bledefs.go
index b8d558c..a64da61 100644
--- a/nmxact/bledefs/bledefs.go
+++ b/nmxact/bledefs/bledefs.go
@@ -147,6 +147,81 @@ func (bd *BleDev) String() string {
                bd.Addr.String())
 }
 
+type BleUuid struct {
+       Bytes [16]byte
+}
+
+func (bu *BleUuid) String() string {
+       var buf bytes.Buffer
+       buf.Grow(len(bu.Bytes)*2 + 3)
+
+       // XXX: For now, only support 128-bit UUIDs.
+
+       for i, b := range bu.Bytes {
+               switch i {
+               case 4, 6, 8, 10:
+                       buf.WriteString("-")
+               }
+
+               fmt.Fprintf(&buf, "%02x", b)
+       }
+
+       return buf.String()
+}
+
+func ParseUuid(uuidStr string) (BleUuid, error) {
+       bu := BleUuid{}
+
+       if len(uuidStr) != 36 {
+               return bu, fmt.Errorf("Invalid UUID: %s", uuidStr)
+       }
+
+       boff := 0
+       for i := 0; i < 36; {
+               switch i {
+               case 8, 13, 18, 23:
+                       if uuidStr[i] != '-' {
+                               return bu, fmt.Errorf("Invalid UUID: %s", 
uuidStr)
+                       }
+                       i++
+
+               default:
+                       u64, err := strconv.ParseUint(uuidStr[i:i+2], 16, 8)
+                       if err != nil {
+                               return bu, fmt.Errorf("Invalid UUID: %s", 
uuidStr)
+                       }
+                       bu.Bytes[boff] = byte(u64)
+                       i += 2
+                       boff++
+               }
+       }
+
+       return bu, nil
+}
+
+func (bu *BleUuid) MarshalJSON() ([]byte, error) {
+       return json.Marshal(bu.String())
+}
+
+func (bu *BleUuid) UnmarshalJSON(data []byte) error {
+       var s string
+       if err := json.Unmarshal(data, &s); err != nil {
+               return err
+       }
+
+       var err error
+       *bu, err = ParseUuid(s)
+       if err != nil {
+               return err
+       }
+
+       return nil
+}
+
+func CompareUuids(a BleUuid, b BleUuid) int {
+       return bytes.Compare(a.Bytes[:], b.Bytes[:])
+}
+
 type BleScanFilterPolicy int
 
 const (
@@ -262,9 +337,30 @@ type BleAdvReport struct {
 
        // These fields are only present if the sender included them in its
        // advertisement.
-       Flags          uint8  // 0 if not present.
-       Name           string // "" if not present.
-       NameIsComplete bool   // false if not present.
+       Flags               uint8     // 0 if not present.
+       Uuids16             []uint16  // nil if not present
+       Uuids16IsComplete   bool      // false if not present
+       Uuids32             []uint32  // false if not present
+       Uuids32IsComplete   bool      // false if not present
+       Uuids128            []BleUuid // false if not present
+       Uuids128IsComplete  bool      // false if not present
+       Name                string    // "" if not present.
+       NameIsComplete      bool      // false if not present.
+       TxPwrLvl            int8      // Check TxPwrLvlIsPresent
+       TxPwrLvlIsPresent   bool      // false if not present
+       SlaveItvlMin        uint16    // Check SlaveItvlIsPresent
+       SlaveItvlMax        uint16    // Check SlaveItvlIsPresent
+       SlaveItvlIsPresent  bool      // false if not present
+       SvcDataUuid16       []byte    // false if not present
+       PublicTgtAddrs      []BleAddr // false if not present
+       Appearance          uint16    // Check AppearanceIsPresent
+       AppearanceIsPresent bool      // false if not present
+       AdvItvl             uint16    // Check AdvItvlIsPresent
+       AdvItvlIsPresent    bool      // false if not present
+       SvcDataUuid32       []byte    // false if not present
+       SvcDataUuid128      []byte    // false if not present
+       Uri                 []byte    // false if not present
+       MfgData             []byte    // false if not present
 }
 
 type BleAdvPredicate func(adv BleAdvReport) bool

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/25097817/nmxact/nmble/ble_proto.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_proto.go b/nmxact/nmble/ble_proto.go
index f955fab..69c456f 100644
--- a/nmxact/nmble/ble_proto.go
+++ b/nmxact/nmble/ble_proto.go
@@ -19,10 +19,6 @@ type BleBytes struct {
        Bytes []byte
 }
 
-type BleUuid struct {
-       Bytes [16]byte
-}
-
 const BLE_SEQ_NONE BleSeq = 0xffffffff
 
 const ERR_CODE_ATT_BASE = 0x100
@@ -671,9 +667,30 @@ type BleScanEvt struct {
        Data      BleBytes        `json:"data"`
 
        // Optional
-       DataFlags          uint8  `json:"data_flags"`
-       DataName           string `json:"data_name"`
-       DataNameIsComplete bool   `json:"data_name_is_complete"`
+       DataFlags               uint8     `json:"data_flags"`
+       DataUuids16             []uint16  `json:"data_uuids16"`
+       DataUuids16IsComplete   bool      `json:"data_uuids16_is_complete"`
+       DataUuids32             []uint32  `json:"data_uuids32"`
+       DataUuids32IsComplete   bool      `json:"data_uuids32_is_complete"`
+       DataUuids128            []BleUuid `json:"data_uuids128"`
+       DataUuids128IsComplete  bool      `json:"data_uuids128_is_complete"`
+       DataName                string    `json:"data_name"`
+       DataNameIsComplete      bool      `json:"data_name_is_complete"`
+       DataTxPwrLvl            int8      `json:"data_tx_pwr_lvl"`
+       DataTxPwrLvlIsPresent   bool
+       DataSlaveItvlMin        uint16 `json:"data_slave_itvl_min"`
+       DataSlaveItvlMax        uint16 `json:"data_slave_itvl_max"`
+       DataSlaveItvlIsPresent  bool
+       DataSvcDataUuid16       BleBytes  `json:"data_svc_data_uuid16"`
+       DataPublicTgtAddrs      []BleAddr `json:"data_public_tgt_addrs"`
+       DataAppearance          uint16    `json:"data_appearance"`
+       DataAppearanceIsPresent bool
+       DataAdvItvl             uint16 `json:"data_adv_itvl"`
+       DataAdvItvlIsPresent    bool
+       DataSvcDataUuid32       BleBytes `json:"data_svc_data_uuid32"`
+       DataSvcDataUuid128      BleBytes `json:"data_svc_data_uuid128"`
+       DataUri                 BleBytes `json:"data_uri"`
+       DataMfgData             BleBytes `json:"data_mfg_data"`
 }
 
 type BleScanCancelReq struct {
@@ -880,44 +897,3 @@ func (bb *BleBytes) UnmarshalJSON(data []byte) error {
 
        return nil
 }
-
-func (bu *BleUuid) String() string {
-       var buf bytes.Buffer
-       buf.Grow(len(bu.Bytes)*2 + 3)
-
-       // XXX: For now, only support 128-bit UUIDs.
-
-       for i, b := range bu.Bytes {
-               switch i {
-               case 4, 6, 8, 10:
-                       buf.WriteString("-")
-               }
-
-               fmt.Fprintf(&buf, "%02x", b)
-       }
-
-       return buf.String()
-}
-
-func (bu *BleUuid) MarshalJSON() ([]byte, error) {
-       return json.Marshal(bu.String())
-}
-
-func (bu *BleUuid) UnmarshalJSON(data []byte) error {
-       var s string
-       if err := json.Unmarshal(data, &s); err != nil {
-               return err
-       }
-
-       var err error
-       *bu, err = ParseUuid(s)
-       if err != nil {
-               return err
-       }
-
-       return nil
-}
-
-func CompareUuids(a BleUuid, b BleUuid) int {
-       return bytes.Compare(a.Bytes[:], b.Bytes[:])
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/25097817/nmxact/nmble/ble_util.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_util.go b/nmxact/nmble/ble_util.go
index 0cd17f3..f0a6c04 100644
--- a/nmxact/nmble/ble_util.go
+++ b/nmxact/nmble/ble_util.go
@@ -2,7 +2,6 @@ package nmble
 
 import (
        "fmt"
-       "strconv"
        "sync/atomic"
 
        log "github.com/Sirupsen/logrus"
@@ -26,36 +25,6 @@ func NextSeq() BleSeq {
        return BleSeq(atomic.AddUint32(&nextSeq, 1))
 }
 
-func ParseUuid(uuidStr string) (BleUuid, error) {
-       bu := BleUuid{}
-
-       if len(uuidStr) != 36 {
-               return bu, fmt.Errorf("Invalid UUID: %s", uuidStr)
-       }
-
-       boff := 0
-       for i := 0; i < 36; {
-               switch i {
-               case 8, 13, 18, 23:
-                       if uuidStr[i] != '-' {
-                               return bu, fmt.Errorf("Invalid UUID: %s", 
uuidStr)
-                       }
-                       i++
-
-               default:
-                       u64, err := strconv.ParseUint(uuidStr[i:i+2], 16, 8)
-                       if err != nil {
-                               return bu, fmt.Errorf("Invalid UUID: %s", 
uuidStr)
-                       }
-                       bu.Bytes[boff] = byte(u64)
-                       i += 2
-                       boff++
-               }
-       }
-
-       return bu, nil
-}
-
 func BhdTimeoutError(rspType MsgType) error {
        str := fmt.Sprintf("Timeout waiting for blehostd to send %s response",
                MsgTypeToString(rspType))
@@ -99,9 +68,30 @@ func BleAdvReportFromScanEvt(e *BleScanEvt) BleAdvReport {
                Rssi: e.Rssi,
                Data: e.Data.Bytes,
 
-               Flags:          e.DataFlags,
-               Name:           e.DataName,
-               NameIsComplete: e.DataNameIsComplete,
+               Flags:               e.DataFlags,
+               Uuids16:             e.DataUuids16,
+               Uuids16IsComplete:   e.DataUuids16IsComplete,
+               Uuids32:             e.DataUuids32,
+               Uuids32IsComplete:   e.DataUuids32IsComplete,
+               Uuids128:            e.DataUuids128,
+               Uuids128IsComplete:  e.DataUuids128IsComplete,
+               Name:                e.DataName,
+               NameIsComplete:      e.DataNameIsComplete,
+               TxPwrLvl:            e.DataTxPwrLvl,
+               TxPwrLvlIsPresent:   e.DataTxPwrLvlIsPresent,
+               SlaveItvlMin:        e.DataSlaveItvlMin,
+               SlaveItvlMax:        e.DataSlaveItvlMax,
+               SlaveItvlIsPresent:  e.DataSlaveItvlIsPresent,
+               SvcDataUuid16:       e.DataSvcDataUuid16.Bytes,
+               PublicTgtAddrs:      e.DataPublicTgtAddrs,
+               Appearance:          e.DataAppearance,
+               AppearanceIsPresent: e.DataAppearanceIsPresent,
+               AdvItvl:             e.DataAdvItvl,
+               AdvItvlIsPresent:    e.DataAdvItvlIsPresent,
+               SvcDataUuid32:       e.DataSvcDataUuid32.Bytes,
+               SvcDataUuid128:      e.DataSvcDataUuid128.Bytes,
+               Uri:                 e.DataUri.Bytes,
+               MfgData:             e.DataMfgData.Bytes,
        }
 }
 

Reply via email to