nmxact - Scan on each conn in case peer chgs addr.
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/ae52880d Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/tree/ae52880d Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/diff/ae52880d Branch: refs/heads/master Commit: ae52880d6b2048e9765f6870b5d5487a2ccda038 Parents: 06f33c0 Author: Christopher Collins <[email protected]> Authored: Tue Mar 28 11:51:05 2017 -0700 Committer: Christopher Collins <[email protected]> Committed: Tue Mar 28 15:38:36 2017 -0700 ---------------------------------------------------------------------- nmxact/nmble/ble_fsm.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/ae52880d/nmxact/nmble/ble_fsm.go ---------------------------------------------------------------------- diff --git a/nmxact/nmble/ble_fsm.go b/nmxact/nmble/ble_fsm.go index 411ce59..52f61b8 100644 --- a/nmxact/nmble/ble_fsm.go +++ b/nmxact/nmble/ble_fsm.go @@ -88,16 +88,6 @@ func NewBleFsm(p BleFsmParams) *BleFsm { attMtu: DFLT_ATT_MTU, } - // The peer spec contains one of: - // * Peer address; - // * Predicate function to call during scanning. - // If a peer address is specified, fill in the peer field now so the - // scanning step can be skipped. Otherwise, the peer field gets populated - // during scanning. - if bf.peerSpec.ScanPred == nil { - bf.peerDev = &bf.peerSpec.Dev - } - return bf } @@ -294,6 +284,7 @@ func (bf *BleFsm) connectListen(seq int) error { } bf.setState(SESN_STATE_UNCONNECTED) + bf.peerDev = nil bf.disconnectCb(err) return @@ -606,6 +597,23 @@ func (bf *BleFsm) subscribe() error { return nil } +// Tries to populate the FSM's peerDev field. This function succeeds if the +// client specified the address of the peer to connect to. +func (bf *BleFsm) tryFillPeerDev() bool { + // The peer spec contains one of: + // * Peer address; + // * Predicate function to call during scanning. + // If a peer address is specified, fill in the peer field now so the + // scanning step can be skipped. Otherwise, the peer field gets populated + // during scanning. + if bf.peerSpec.ScanPred == nil { + bf.peerDev = &bf.peerSpec.Dev + return true + } + + return false +} + func (bf *BleFsm) Start() error { if bf.getState() != SESN_STATE_UNCONNECTED { return nmxutil.NewSesnAlreadyOpenError( @@ -623,6 +631,7 @@ func (bf *BleFsm) Start() error { // address, or if we have already successfully scanned, we initiate // a connection now. Otherwise, we need to scan to determine which // peer meets the specified scan criteria. + bf.tryFillPeerDev() if bf.peerDev == nil { // Peer not inferred yet. Initiate scan. cb := func() error { return bf.scan() }
