Repository: incubator-mynewt-newtmgr
Updated Branches:
  refs/heads/master ad32cdd3d -> 3b818c385


nmxact - Use uint32 for bhd sequence numbers.


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/f1e662fa
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/tree/f1e662fa
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/diff/f1e662fa

Branch: refs/heads/master
Commit: f1e662fa78aedbe0746edc602248de47cc39e2a8
Parents: e3144c6
Author: Christopher Collins <[email protected]>
Authored: Tue Apr 4 15:18:24 2017 -0700
Committer: Christopher Collins <[email protected]>
Committed: Tue Apr 4 18:09:43 2017 -0700

----------------------------------------------------------------------
 nmxact/nmble/ble_fsm.go   |  8 ++---
 nmxact/nmble/ble_proto.go | 67 ++++++++++++++++++++++--------------------
 nmxact/nmble/ble_util.go  |  4 +--
 nmxact/nmble/ble_xport.go |  4 +--
 nmxact/nmble/dispatch.go  | 14 ++++-----
 5 files changed, 50 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/f1e662fa/nmxact/nmble/ble_fsm.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_fsm.go b/nmxact/nmble/ble_fsm.go
index 39bfdfc..f9492c8 100644
--- a/nmxact/nmble/ble_fsm.go
+++ b/nmxact/nmble/ble_fsm.go
@@ -146,7 +146,7 @@ func (bf *BleFsm) addBleListener(base BleMsgBase) 
(*BleListener, error) {
        return bl, nil
 }
 
-func (bf *BleFsm) addBleSeqListener(seq int) (*BleListener, error) {
+func (bf *BleFsm) addBleSeqListener(seq BleSeq) (*BleListener, error) {
        base := BleMsgBase{
                Op:         -1,
                Type:       -1,
@@ -170,7 +170,7 @@ func (bf *BleFsm) removeBleListener(base BleMsgBase) {
        }
 }
 
-func (bf *BleFsm) removeBleSeqListener(seq int) {
+func (bf *BleFsm) removeBleSeqListener(seq BleSeq) {
        base := BleMsgBase{
                Op:         -1,
                Type:       -1,
@@ -240,7 +240,7 @@ func (bf *BleFsm) onDisconnect(err error) {
        bf.params.DisconnectCb(dt, peer, err)
 }
 
-func (bf *BleFsm) connectListen(seq int) error {
+func (bf *BleFsm) connectListen(seq BleSeq) error {
        bf.connChan = make(chan error, 1)
 
        bl, err := bf.addBleSeqListener(seq)
@@ -326,7 +326,7 @@ func (bf *BleFsm) nmpRspListen() error {
        base := BleMsgBase{
                Op:         MSG_OP_EVT,
                Type:       MSG_TYPE_NOTIFY_RX_EVT,
-               Seq:        -1,
+               Seq:        BLE_SEQ_NONE,
                ConnHandle: bf.connHandle,
        }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/f1e662fa/nmxact/nmble/ble_proto.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_proto.go b/nmxact/nmble/ble_proto.go
index fe9112d..8545335 100644
--- a/nmxact/nmble/ble_proto.go
+++ b/nmxact/nmble/ble_proto.go
@@ -13,6 +13,7 @@ import (
 
 type MsgOp int
 type MsgType int
+type BleSeq uint32
 
 type BleBytes struct {
        Bytes []byte
@@ -22,6 +23,8 @@ type BleUuid struct {
        Bytes [16]byte
 }
 
+const BLE_SEQ_NONE BleSeq = 0xffffffff
+
 const ERR_CODE_ATT_BASE = 0x100
 const ERR_CODE_HCI_BASE = 0x200
 const ERR_CODE_L2C_BASE = 0x300
@@ -274,7 +277,7 @@ var MsgTypeStringMap = map[MsgType]string{
 type BleHdr struct {
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 }
 
 type BleMsg interface{}
@@ -296,14 +299,14 @@ type BleSyncReq struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 }
 
 type BleConnectReq struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        OwnAddrType  BleAddrType `json:"own_addr_type"`
@@ -326,7 +329,7 @@ type BleConnectRsp struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int `json:"status"`
@@ -336,7 +339,7 @@ type BleConnectEvt struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status          int         `json:"status"`
@@ -355,7 +358,7 @@ type BleTerminateReq struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        ConnHandle int `json:"conn_handle"`
        HciReason  int `json:"hci_reason"`
@@ -365,7 +368,7 @@ type BleTerminateRsp struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int `json:"status"`
@@ -375,14 +378,14 @@ type BleConnCancelReq struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 }
 
 type BleConnCancelRsp struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int `json:"status"`
@@ -392,7 +395,7 @@ type BleDisconnectEvt struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Reason     int `json:"reason"`
@@ -403,7 +406,7 @@ type BleDiscSvcUuidReq struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        ConnHandle int     `json:"conn_handle"`
@@ -414,7 +417,7 @@ type BleDiscSvcUuidRsp struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int `json:"status"`
@@ -424,7 +427,7 @@ type BleDiscSvcEvt struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int    `json:"status"`
@@ -435,7 +438,7 @@ type BleDiscChrUuidReq struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        ConnHandle  int     `json:"conn_handle"`
@@ -448,7 +451,7 @@ type BleDiscAllChrsReq struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        ConnHandle  int `json:"conn_handle"`
@@ -460,7 +463,7 @@ type BleDiscAllChrsRsp struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int `json:"status"`
@@ -470,7 +473,7 @@ type BleErrRsp struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int    `json:"status"`
@@ -481,7 +484,7 @@ type BleSyncRsp struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Synced bool `json:"synced"`
@@ -491,7 +494,7 @@ type BleDiscChrUuidRsp struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int `json:"status"`
@@ -501,7 +504,7 @@ type BleDiscChrEvt struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int    `json:"status"`
@@ -512,7 +515,7 @@ type BleWriteCmdReq struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        ConnHandle int      `json:"conn_handle"`
@@ -524,7 +527,7 @@ type BleWriteCmdRsp struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int `json:"status"`
@@ -534,7 +537,7 @@ type BleSyncEvt struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Synced bool `json:"synced"`
@@ -544,7 +547,7 @@ type BleNotifyRxEvt struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        ConnHandle int      `json:"conn_handle"`
@@ -557,7 +560,7 @@ type BleExchangeMtuReq struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        ConnHandle int `json:"conn_handle"`
@@ -567,7 +570,7 @@ type BleExchangeMtuRsp struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int `json:"status"`
@@ -577,7 +580,7 @@ type BleMtuChangeEvt struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status     int `json:"status"`
@@ -589,7 +592,7 @@ type BleScanReq struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        OwnAddrType      BleAddrType         `json:"own_addr_type"`
@@ -606,7 +609,7 @@ type BleScanRsp struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int `json:"status"`
@@ -616,7 +619,7 @@ type BleScanEvt struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        EventType BleAdvEventType `json:"event_type"`
@@ -635,14 +638,14 @@ type BleScanCancelReq struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 }
 
 type BleScanCancelRsp struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Mandatory
        Status int `json:"status"`

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/f1e662fa/nmxact/nmble/ble_util.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_util.go b/nmxact/nmble/ble_util.go
index 31f0e62..07cd8c3 100644
--- a/nmxact/nmble/ble_util.go
+++ b/nmxact/nmble/ble_util.go
@@ -22,8 +22,8 @@ const NOTIFY_CMD_BASE_SZ = 3
 
 var nextSeq uint32
 
-func NextSeq() int {
-       return int(atomic.AddUint32(&nextSeq, 1))
+func NextSeq() BleSeq {
+       return BleSeq(atomic.AddUint32(&nextSeq, 1))
 }
 
 func ParseUuid(uuidStr string) (BleUuid, error) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/f1e662fa/nmxact/nmble/ble_xport.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_xport.go b/nmxact/nmble/ble_xport.go
index 335986f..8a8b909 100644
--- a/nmxact/nmble/ble_xport.go
+++ b/nmxact/nmble/ble_xport.go
@@ -113,7 +113,7 @@ func (bx *BleXport) addSyncListener() (*BleListener, error) 
{
        base := BleMsgBase{
                Op:         MSG_OP_EVT,
                Type:       MSG_TYPE_SYNC_EVT,
-               Seq:        -1,
+               Seq:        BLE_SEQ_NONE,
                ConnHandle: -1,
        }
        if err := bx.Bd.AddListener(base, bl); err != nil {
@@ -127,7 +127,7 @@ func (bx *BleXport) removeSyncListener() {
        base := BleMsgBase{
                Op:         MSG_OP_EVT,
                Type:       MSG_TYPE_SYNC_EVT,
-               Seq:        -1,
+               Seq:        BLE_SEQ_NONE,
                ConnHandle: -1,
        }
        bx.Bd.RemoveListener(base)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/f1e662fa/nmxact/nmble/dispatch.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/dispatch.go b/nmxact/nmble/dispatch.go
index c9ef39e..aba7504 100644
--- a/nmxact/nmble/dispatch.go
+++ b/nmxact/nmble/dispatch.go
@@ -37,7 +37,7 @@ type BleMsgBase struct {
        // Header
        Op   MsgOp   `json:"op"`
        Type MsgType `json:"type"`
-       Seq  int     `json:"seq"`
+       Seq  BleSeq  `json:"seq"`
 
        // Optional
        ConnHandle int `json:"conn_handle" json:",omitempty"`
@@ -77,7 +77,7 @@ func (bl *BleListener) Stop() {
 }
 
 type BleDispatcher struct {
-       seqMap  map[int]*BleListener
+       seqMap  map[BleSeq]*BleListener
        baseMap map[BleMsgBase]*BleListener
        mutex   sync.Mutex
 }
@@ -132,7 +132,7 @@ var msgCtorMap = map[OpTypePair]msgCtor{
 
 func NewBleDispatcher() *BleDispatcher {
        return &BleDispatcher{
-               seqMap:  map[int]*BleListener{},
+               seqMap:  map[BleSeq]*BleListener{},
                baseMap: map[BleMsgBase]*BleListener{},
        }
 }
@@ -162,7 +162,7 @@ func (bd *BleDispatcher) findBaseListener(base BleMsgBase) (
 func (bd *BleDispatcher) findDupListener(base BleMsgBase) (
        BleMsgBase, *BleListener) {
 
-       if base.Seq != -1 {
+       if base.Seq != BLE_SEQ_NONE {
                return base, bd.seqMap[base.Seq]
        }
 
@@ -172,7 +172,7 @@ func (bd *BleDispatcher) findDupListener(base BleMsgBase) (
 func (bd *BleDispatcher) findListener(base BleMsgBase) (
        BleMsgBase, *BleListener) {
 
-       if base.Seq != -1 {
+       if base.Seq != BLE_SEQ_NONE {
                if bl := bd.seqMap[base.Seq]; bl != nil {
                        return base, bl
                }
@@ -196,7 +196,7 @@ func (bd *BleDispatcher) AddListener(base BleMsgBase,
                        base.Op, base.Type, base.Seq, base.ConnHandle)
        }
 
-       if base.Seq != -1 {
+       if base.Seq != BLE_SEQ_NONE {
                if base.Op != -1 ||
                        base.Type != -1 ||
                        base.ConnHandle != -1 {
@@ -219,7 +219,7 @@ func (bd *BleDispatcher) RemoveListener(base BleMsgBase) 
*BleListener {
        base, bl := bd.findListener(base)
        if bl != nil {
                bl.Stop()
-               if base.Seq != -1 {
+               if base.Seq != BLE_SEQ_NONE {
                        delete(bd.seqMap, base.Seq)
                } else {
                        delete(bd.baseMap, base)

Reply via email to