You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/07/19 20:30:21 UTC
[1/9] incubator-mynewt-newt git commit: MYNEWT-266 newtmgr over BLE
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop c33896135 -> 4c8ed1cf2
MYNEWT-266 newtmgr over BLE
- Adding OS specific BLE option files
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/4c8ed1cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/4c8ed1cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/4c8ed1cf
Branch: refs/heads/develop
Commit: 4c8ed1cf28e95878249371b7a27fdc8cf0df3352
Parents: 5cbba8e
Author: Vipul Rahane <vi...@runtime.io>
Authored: Mon Jul 18 22:41:28 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue Jul 19 13:06:58 2016 -0700
----------------------------------------------------------------------
newtmgr/transport/conn.go | 9 +++------
newtmgr/transport/connble.go | 12 ++----------
newtmgr/transport/connble_darwin.go | 23 +++++++++++++++++++++++
newtmgr/transport/connble_linux.go | 26 ++++++++++++++++++++++++++
4 files changed, 54 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4c8ed1cf/newtmgr/transport/conn.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/conn.go b/newtmgr/transport/conn.go
index 2f89783..2410ab6 100644
--- a/newtmgr/transport/conn.go
+++ b/newtmgr/transport/conn.go
@@ -84,19 +84,16 @@ func newConn(cp config.NewtmgrConnProfile, readTimeout time.Duration) (Conn, err
switch cp.Type() {
case "serial":
c = &ConnSerial{}
- if err := c.Open(cp, readTimeout); err != nil {
- return nil, err
- }
case "ble":
c = &ConnBLE{}
- if err := c.Open(cp, readTimeout); err != nil {
- return nil, err
- }
default:
return nil, util.NewNewtError("Invalid conn profile " + cp.Type() +
" not implemented")
}
+ if err := c.Open(cp, readTimeout); err != nil {
+ return nil, err
+ }
return c, nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4c8ed1cf/newtmgr/transport/connble.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connble.go b/newtmgr/transport/connble.go
index 755c6df..247752b 100644
--- a/newtmgr/transport/connble.go
+++ b/newtmgr/transport/connble.go
@@ -1,9 +1,5 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
-<<<<<<< 1a13676c8d37c07184d7e0f0e56221203e2110ad
- iog.Debugf("Writing %+v to data channel", bytes)
-=======
->>>>>>> Initial commit - newtmgr BLE
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
@@ -19,8 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
-*/
-
+ */
package transport
import (
@@ -143,10 +138,7 @@ func onPeriphDisconnected(p gatt.Peripheral, err error) {
func (cb *ConnBLE) Open(cp config.NewtmgrConnProfile, readTimeout time.Duration) error {
var err error
- var DefaultClientOptions = []gatt.Option{
- gatt.LnxMaxConnections(1),
- gatt.LnxDeviceID(-1, false),
- }
+ var DefaultClientOptions = BleOptions
deviceName = cp.ConnString()
deviceAddress = reverseBytes(cp.DeviceAddress())
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4c8ed1cf/newtmgr/transport/connble_darwin.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connble_darwin.go b/newtmgr/transport/connble_darwin.go
new file mode 100644
index 0000000..8708cb7
--- /dev/null
+++ b/newtmgr/transport/connble_darwin.go
@@ -0,0 +1,23 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package transport
+
+import "github.com/runtimeinc/gatt"
+
+var BleOptions = []gatt.Option{}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4c8ed1cf/newtmgr/transport/connble_linux.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connble_linux.go b/newtmgr/transport/connble_linux.go
new file mode 100644
index 0000000..4074a5b
--- /dev/null
+++ b/newtmgr/transport/connble_linux.go
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package transport
+
+import "github.com/runtimeinc/gatt"
+
+var BleOptions = []gatt.Option{
+ gatt.LnxMaxConnections(1),
+ gatt.LnxDeviceID(-1, false),
+}
[8/9] incubator-mynewt-newt git commit: MYNEWT-266 newtmgr over BLE
Posted by cc...@apache.org.
MYNEWT-266 newtmgr over BLE
- Adding offset printf back to show upload process
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/5cbba8e5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/5cbba8e5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/5cbba8e5
Branch: refs/heads/develop
Commit: 5cbba8e53a883c0f21437e51ff365088bd9eef69
Parents: a34f129
Author: admin <vr...@gmail.com>
Authored: Mon Jul 18 14:19:07 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue Jul 19 13:06:58 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/image.go | 2 ++
newtmgr/transport/connble.go | 31 +++++++++++++++++--------------
2 files changed, 19 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5cbba8e5/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index c638408..31b147a 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -239,6 +239,8 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, err)
}
currOff = ersp.Offset
+
+ fmt.Println(currOff)
}
if (profile.Type() == "serial") {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5cbba8e5/newtmgr/transport/connble.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connble.go b/newtmgr/transport/connble.go
index 18dcf1c..755c6df 100644
--- a/newtmgr/transport/connble.go
+++ b/newtmgr/transport/connble.go
@@ -1,6 +1,9 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
+<<<<<<< 1a13676c8d37c07184d7e0f0e56221203e2110ad
iog.Debugf("Writing %+v to data channel", bytes)
+=======
+>>>>>>> Initial commit - newtmgr BLE
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
@@ -16,7 +19,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+*/
package transport
@@ -76,31 +79,31 @@ func onStateChanged(d gatt.Device, s gatt.State) {
func onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
var matched bool = false
- if (len(deviceName) > 0) {
+ if len(deviceName) > 0 {
matched = a.LocalName == deviceName
- if (matched == false) {
+ if matched == false {
return
}
}
- if (len(deviceAddress) > 0) {
+ if len(deviceAddress) > 0 {
var deviceAddrArr [6]byte
copy(deviceAddrArr[:], deviceAddress[0:6])
matched = a.Address == deviceAddrArr && a.AddressType == deviceAddressType
}
- if (matched == true) {
+ if matched == true {
log.Debugf("Peripheral Discovered: %s, Address:%+v Address Type:%+v",
- p.Name(), a.Address, a.AddressType)
+ p.Name(), a.Address, a.AddressType)
p.Device().StopScanning()
p.Device().Connect(p)
}
}
func newtmgrNotifyCB(c *gatt.Characteristic, incomingDatabuf []byte, err error) {
- err = nil
- rxBLEPkt <- incomingDatabuf
- return
+ err = nil
+ rxBLEPkt <- incomingDatabuf
+ return
}
func onPeriphConnected(p gatt.Peripheral, err error) {
@@ -177,8 +180,8 @@ func (cb *ConnBLE) ReadPacket() (*Packet, error) {
cb.currentPacket.AddBytes(bleRxData)
log.Debugf("Read BLE Packet:buf::%+v len::%+v", cb.currentPacket.buffer,
- cb.currentPacket.expectedLen)
- bleRxData = bleRxData[:0]
+ cb.currentPacket.expectedLen)
+ bleRxData = bleRxData[:0]
pkt := cb.currentPacket
cb.currentPacket = nil
return pkt, err
@@ -191,14 +194,14 @@ func (cb *ConnBLE) writeData() error {
func (cb *ConnBLE) WritePacket(pkt *Packet) error {
log.Debugf("Write BLE Packet:buf::%+v len::%+v", pkt.buffer,
- pkt.expectedLen)
+ pkt.expectedLen)
bleTxData = pkt.GetBytes()
cb.writeData()
return nil
}
-func (cb *ConnBLE) Close () error {
+func (cb *ConnBLE) Close() error {
log.Debugf("Closing Connection %+v", cb)
- cb.bleDevice.CancelConnection(devicePerph)
+ cb.bleDevice.CancelConnection(devicePerph)
return nil
}
[7/9] incubator-mynewt-newt git commit: MYNEWT-266
Posted by cc...@apache.org.
MYNEWT-266
- Add address checking functionality to BLE newtmgr transport by making it support in GATT
- Currently the byte order is inverted, will be fixed shortly.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/88405e0a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/88405e0a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/88405e0a
Branch: refs/heads/develop
Commit: 88405e0aee9e0a03cbb7eafabb294e4e6b0e39e8
Parents: fe4de7b
Author: admin <vr...@gmail.com>
Authored: Thu Jul 14 19:47:59 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue Jul 19 13:06:58 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/connprofile.go | 38 ++++++++++++++++++++++++++++++++++++--
newtmgr/config/connprofile.go | 12 ++++++++++++
newtmgr/transport/connble.go | 22 ++++++++++++++++++++--
3 files changed, 68 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/88405e0a/newtmgr/cli/connprofile.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/connprofile.go b/newtmgr/cli/connprofile.go
index 35a059e..fa2a9af 100644
--- a/newtmgr/cli/connprofile.go
+++ b/newtmgr/cli/connprofile.go
@@ -22,6 +22,8 @@ package cli
import (
"fmt"
"strings"
+ "strconv"
+ "encoding/hex"
"mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/util"
@@ -29,6 +31,20 @@ import (
"github.com/spf13/cobra"
)
+func isAddressValid(cp *config.ConnProfile, addrlen int) bool {
+ if cp.MyType == "ble" && addrlen != 6 {
+ return true
+ }
+ return false
+}
+
+func isAddressTypeValid(cp *config.ConnProfile, addrtype uint64) bool {
+ if cp.MyType == "ble" && addrtype < 4 {
+ return true
+ }
+ return false
+}
+
func connProfileAddCmd(cmd *cobra.Command, args []string) {
cpm, err := config.NewConnProfileMgr()
if err != nil {
@@ -50,6 +66,18 @@ func connProfileAddCmd(cmd *cobra.Command, args []string) {
cp.MyType = s[1]
case "connstring":
cp.MyConnString = s[1]
+ case "addr":
+ deviceAddr,err := hex.DecodeString(s[1])
+ if err != nil && isAddressValid(cp, len(deviceAddr)) != true {
+ nmUsage(cmd, util.NewNewtError("Invalid address"+s[1]))
+ }
+ copy(cp.MyDeviceAddress[:], deviceAddr[0:6])
+ case "addrtype":
+ deviceAddrType64, err := strconv.ParseUint(s[1], 10, 8)
+ if err != nil && isAddressTypeValid(cp, deviceAddrType64) {
+ nmUsage(cmd, util.NewNewtError("Invalid address type"+s[1]))
+ }
+ cp.MyDeviceAddressType = uint8(deviceAddrType64)
default:
nmUsage(cmd, util.NewNewtError("Unknown variable "+s[0]))
}
@@ -90,8 +118,14 @@ func connProfileShowCmd(cmd *cobra.Command, args []string) {
found = true
fmt.Printf("Connection profiles: \n")
}
- fmt.Printf(" %s: type=%s, connstring='%s'\n", cp.MyName, cp.MyType,
- cp.MyConnString)
+ fmt.Printf(" %s: type=%s, connstring='%s'", cp.MyName, cp.MyType,
+ cp.MyConnString)
+ //if (len(cp.MyDeviceAddress) > 0) {
+ fmt.Printf(" addr=%x, addrtype=%+v", cp.MyDeviceAddress,
+ cp.MyDeviceAddressType)
+// }
+
+ fmt.Printf("\n")
}
if !found {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/88405e0a/newtmgr/config/connprofile.go
----------------------------------------------------------------------
diff --git a/newtmgr/config/connprofile.go b/newtmgr/config/connprofile.go
index b0203cb..ea3e3a1 100644
--- a/newtmgr/config/connprofile.go
+++ b/newtmgr/config/connprofile.go
@@ -37,12 +37,16 @@ type NewtmgrConnProfile interface {
Name() string
Type() string
ConnString() string
+ DeviceAddress() [6]byte
+ DeviceAddressType() uint8
}
type ConnProfile struct {
MyName string
MyType string
MyConnString string
+ MyDeviceAddress [6]byte
+ MyDeviceAddressType uint8
}
func NewConnProfileMgr() (*ConnProfileMgr, error) {
@@ -180,6 +184,14 @@ func (cp *ConnProfile) ConnString() string {
return cp.MyConnString
}
+func (cp *ConnProfile) DeviceAddressType() uint8 {
+ return cp.MyDeviceAddressType
+}
+
+func (cp *ConnProfile) DeviceAddress() [6]byte {
+ return cp.MyDeviceAddress
+}
+
func NewConnProfile(pName string) (*ConnProfile, error) {
cp := &ConnProfile{}
cp.MyName = pName
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/88405e0a/newtmgr/transport/connble.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connble.go b/newtmgr/transport/connble.go
index 724801c..c5970cc 100644
--- a/newtmgr/transport/connble.go
+++ b/newtmgr/transport/connble.go
@@ -39,6 +39,8 @@ var CharDisc = make(chan bool)
var newtmgrServiceId = gatt.MustParseUUID("8D53DC1D-1DB7-4CD3-868B-8A527460AA84")
var newtmgrServiceCharId = gatt.MustParseUUID("DA2E7828-FBCE-4E01-AE9E-261174997C48")
var deviceName string
+var deviceAddress [6]byte
+var deviceAddressType uint8
type ConnBLE struct {
connProfile config.NewtmgrConnProfile
@@ -65,8 +67,22 @@ func onStateChanged(d gatt.Device, s gatt.State) {
}
func onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
- if a.LocalName == deviceName {
- log.Debugf("Peripheral Discovered: %s", p.Name())
+ var matched bool = false
+
+ if (len(deviceName) > 0) {
+ matched = a.LocalName == deviceName
+ if (matched == false) {
+ return
+ }
+ }
+
+ if (len(deviceAddress) > 0) {
+ matched = a.Address == deviceAddress && a.AddressType == deviceAddressType
+ }
+
+ if (matched == true) {
+ log.Debugf("Peripheral Discovered: %s, Address:%+v Address Type:%+v",
+ p.Name(), a.Address, a.AddressType)
p.Device().StopScanning()
p.Device().Connect(p)
}
@@ -122,6 +138,8 @@ func (cb *ConnBLE) Open(cp config.NewtmgrConnProfile, readTimeout time.Duration)
}
deviceName = cp.ConnString()
+ deviceAddress = cp.DeviceAddress()
+ deviceAddressType = cp.DeviceAddressType()
cb.bleDevice, err = gatt.NewDevice(DefaultClientOptions...)
if err != nil {
return util.NewNewtError(err.Error())
[9/9] incubator-mynewt-newt git commit: MYNEWT-266 newtmgr over BLE
Posted by cc...@apache.org.
MYNEWT-266 newtmgr over BLE
- Support generic addressing for the connection manager
- Advertisement address will be matched with inverted byte order
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/101612ce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/101612ce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/101612ce
Branch: refs/heads/develop
Commit: 101612ce7e6e4f6d5804f14da7b978791eba5e10
Parents: 88405e0
Author: admin <vr...@gmail.com>
Authored: Fri Jul 15 20:40:20 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue Jul 19 13:06:58 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/connprofile.go | 40 +++++++++++++++++++++++++++-----------
newtmgr/config/connprofile.go | 6 +++---
newtmgr/transport/connble.go | 17 ++++++++++++----
3 files changed, 45 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/101612ce/newtmgr/cli/connprofile.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/connprofile.go b/newtmgr/cli/connprofile.go
index fa2a9af..701dacf 100644
--- a/newtmgr/cli/connprofile.go
+++ b/newtmgr/cli/connprofile.go
@@ -31,11 +31,22 @@ import (
"github.com/spf13/cobra"
)
-func isAddressValid(cp *config.ConnProfile, addrlen int) bool {
- if cp.MyType == "ble" && addrlen != 6 {
- return true
+func copyValidAddress(cp *config.ConnProfile, addrString string) bool {
+ switch(cp.MyType) {
+ case "ble" :
+ deviceAddr,err := hex.DecodeString(strings.Replace(addrString, ":", "", -1))
+ if err != nil {
+ return false
+ }
+ if (len(deviceAddr) > 6) {
+ return false
+ }
+ cp.MyDeviceAddress = deviceAddr
+ default:
+ return false
}
- return false
+
+ return true
}
func isAddressTypeValid(cp *config.ConnProfile, addrtype uint64) bool {
@@ -67,11 +78,9 @@ func connProfileAddCmd(cmd *cobra.Command, args []string) {
case "connstring":
cp.MyConnString = s[1]
case "addr":
- deviceAddr,err := hex.DecodeString(s[1])
- if err != nil && isAddressValid(cp, len(deviceAddr)) != true {
+ if copyValidAddress(cp, s[1]) != true {
nmUsage(cmd, util.NewNewtError("Invalid address"+s[1]))
}
- copy(cp.MyDeviceAddress[:], deviceAddr[0:6])
case "addrtype":
deviceAddrType64, err := strconv.ParseUint(s[1], 10, 8)
if err != nil && isAddressTypeValid(cp, deviceAddrType64) {
@@ -90,6 +99,15 @@ func connProfileAddCmd(cmd *cobra.Command, args []string) {
fmt.Printf("Connection profile %s successfully added\n", name)
}
+func print_addr_hex(addr []byte, sep string) string {
+ var str string = ""
+ for _, a:= range addr {
+ str += fmt.Sprintf("%02x", a)
+ str += fmt.Sprintf(sep)
+ }
+ return str[:len(addr)*3 - 1]
+}
+
func connProfileShowCmd(cmd *cobra.Command, args []string) {
cpm, err := config.NewConnProfileMgr()
if err != nil {
@@ -120,10 +138,10 @@ func connProfileShowCmd(cmd *cobra.Command, args []string) {
}
fmt.Printf(" %s: type=%s, connstring='%s'", cp.MyName, cp.MyType,
cp.MyConnString)
- //if (len(cp.MyDeviceAddress) > 0) {
- fmt.Printf(" addr=%x, addrtype=%+v", cp.MyDeviceAddress,
- cp.MyDeviceAddressType)
-// }
+ if (len(cp.MyDeviceAddress) > 0) {
+ fmt.Printf("addr=%s", print_addr_hex(cp.MyDeviceAddress, ":"))
+ fmt.Printf(" addrtype=%+v", cp.MyDeviceAddressType)
+ }
fmt.Printf("\n")
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/101612ce/newtmgr/config/connprofile.go
----------------------------------------------------------------------
diff --git a/newtmgr/config/connprofile.go b/newtmgr/config/connprofile.go
index ea3e3a1..d03c536 100644
--- a/newtmgr/config/connprofile.go
+++ b/newtmgr/config/connprofile.go
@@ -37,7 +37,7 @@ type NewtmgrConnProfile interface {
Name() string
Type() string
ConnString() string
- DeviceAddress() [6]byte
+ DeviceAddress() []byte
DeviceAddressType() uint8
}
@@ -45,7 +45,7 @@ type ConnProfile struct {
MyName string
MyType string
MyConnString string
- MyDeviceAddress [6]byte
+ MyDeviceAddress []byte
MyDeviceAddressType uint8
}
@@ -188,7 +188,7 @@ func (cp *ConnProfile) DeviceAddressType() uint8 {
return cp.MyDeviceAddressType
}
-func (cp *ConnProfile) DeviceAddress() [6]byte {
+func (cp *ConnProfile) DeviceAddress() []byte {
return cp.MyDeviceAddress
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/101612ce/newtmgr/transport/connble.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connble.go b/newtmgr/transport/connble.go
index c5970cc..18dcf1c 100644
--- a/newtmgr/transport/connble.go
+++ b/newtmgr/transport/connble.go
@@ -39,7 +39,7 @@ var CharDisc = make(chan bool)
var newtmgrServiceId = gatt.MustParseUUID("8D53DC1D-1DB7-4CD3-868B-8A527460AA84")
var newtmgrServiceCharId = gatt.MustParseUUID("DA2E7828-FBCE-4E01-AE9E-261174997C48")
var deviceName string
-var deviceAddress [6]byte
+var deviceAddress []byte
var deviceAddressType uint8
type ConnBLE struct {
@@ -54,6 +54,13 @@ var devicePerph gatt.Peripheral
var bleTxData []byte
+func reverseBytes(arr []byte) []byte {
+ if len(arr) == 0 {
+ return arr
+ }
+ return append(reverseBytes(arr[1:]), arr[0])
+}
+
func onStateChanged(d gatt.Device, s gatt.State) {
log.Debugf("State:%+v", s)
switch s {
@@ -77,7 +84,9 @@ func onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
}
if (len(deviceAddress) > 0) {
- matched = a.Address == deviceAddress && a.AddressType == deviceAddressType
+ var deviceAddrArr [6]byte
+ copy(deviceAddrArr[:], deviceAddress[0:6])
+ matched = a.Address == deviceAddrArr && a.AddressType == deviceAddressType
}
if (matched == true) {
@@ -89,7 +98,6 @@ func onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
}
func newtmgrNotifyCB(c *gatt.Characteristic, incomingDatabuf []byte, err error) {
- log.Debugf("BLE Newtmgr rx data:%+v", incomingDatabuf)
err = nil
rxBLEPkt <- incomingDatabuf
return
@@ -138,7 +146,8 @@ func (cb *ConnBLE) Open(cp config.NewtmgrConnProfile, readTimeout time.Duration)
}
deviceName = cp.ConnString()
- deviceAddress = cp.DeviceAddress()
+ deviceAddress = reverseBytes(cp.DeviceAddress())
+ log.Debugf("BLE Connection devaddr:%+v", deviceAddress)
deviceAddressType = cp.DeviceAddressType()
cb.bleDevice, err = gatt.NewDevice(DefaultClientOptions...)
if err != nil {
[3/9] incubator-mynewt-newt git commit: MYNEWT-266 newtmgr over BLE
Posted by cc...@apache.org.
MYNEWT-266 newtmgr over BLE
- Add BLE MTU to transport
- default mtu is 120 if transport is not BLE
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/b3a8cc84
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/b3a8cc84
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/b3a8cc84
Branch: refs/heads/develop
Commit: b3a8cc84ca89b5ac95f1ea82858ec7834a44fd80
Parents: d2660af
Author: admin <vr...@gmail.com>
Authored: Mon Jul 11 16:47:55 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue Jul 19 13:06:58 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/image.go | 9 +++++++--
newtmgr/transport/connble.go | 7 +++++--
2 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b3a8cc84/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index f68f980..c638408 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -36,7 +36,6 @@ import (
"github.com/spf13/cobra"
)
-const bleMTU = 240
var (
coreElfify bool
@@ -169,9 +168,16 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
}
}
var currOff uint32 = 0
+ var mtu uint32 = 0
imageSz := uint32(len(imageFile))
rexmits := 0
+ if (profile.Type() == "ble") {
+ mtu = uint32((transport.BleMTU - 33) * 3/4)
+ } else {
+ mtu = 120
+ }
+
for currOff < imageSz {
imageUpload, err := protocol.NewImageUpload()
if err != nil {
@@ -179,7 +185,6 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
}
blockSz := imageSz - currOff
- mtu := uint32((bleMTU - 33) * 3/4)
if blockSz > mtu {
blockSz = mtu
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b3a8cc84/newtmgr/transport/connble.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connble.go b/newtmgr/transport/connble.go
index 4a49780..bd38474 100644
--- a/newtmgr/transport/connble.go
+++ b/newtmgr/transport/connble.go
@@ -24,12 +24,15 @@ import (
log "github.com/Sirupsen/logrus"
"time"
- "github.com/paypal/gatt"
+ "github.com/runtimeinc/gatt"
"mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/util"
)
+/* This is used by different command handlers */
+var BleMTU uint16 = 180
+
var rxBLEPkt = make(chan []byte)
var CharDisc = make(chan bool)
@@ -98,7 +101,7 @@ func onPeriphConnected(p gatt.Peripheral, err error) {
p.SetNotifyValue(c, newtmgrNotifyCB)
deviceChar = c
devicePerph = p
- p.SetMTU(240)
+ p.SetMTU(BleMTU)
<-CharDisc
}
}
[5/9] incubator-mynewt-newt git commit: MYNEWT-266 newtmgr over BLE
Posted by cc...@apache.org.
MYNEWT-266 newtmgr over BLE
- Use globally unique UUIDs for newtmgr
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/fe4de7b6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/fe4de7b6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/fe4de7b6
Branch: refs/heads/develop
Commit: fe4de7b6d765e250d6f4ece9eeadd18f00ac4e5d
Parents: b3a8cc8
Author: admin <vr...@gmail.com>
Authored: Tue Jul 12 18:04:00 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue Jul 19 13:06:58 2016 -0700
----------------------------------------------------------------------
newtmgr/transport/connble.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe4de7b6/newtmgr/transport/connble.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connble.go b/newtmgr/transport/connble.go
index bd38474..724801c 100644
--- a/newtmgr/transport/connble.go
+++ b/newtmgr/transport/connble.go
@@ -36,8 +36,8 @@ var BleMTU uint16 = 180
var rxBLEPkt = make(chan []byte)
var CharDisc = make(chan bool)
-var newtmgrServiceId = gatt.MustParseUUID("59462f12-9543-9999-12c8-58b459a27120")
-var newtmgrServiceCharId = gatt.MustParseUUID("5c3a659e-897e-45e1-b016-007107c96d00")
+var newtmgrServiceId = gatt.MustParseUUID("8D53DC1D-1DB7-4CD3-868B-8A527460AA84")
+var newtmgrServiceCharId = gatt.MustParseUUID("DA2E7828-FBCE-4E01-AE9E-261174997C48")
var deviceName string
type ConnBLE struct {
[2/9] incubator-mynewt-newt git commit: MYNEWT-266 newtmgr over BLE
Posted by cc...@apache.org.
MYNEWT-266 newtmgr over BLE
- Cleanup
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/a34f129a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/a34f129a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/a34f129a
Branch: refs/heads/develop
Commit: a34f129ae299ec4cd406fe3b0f36f9f5e3c66cce
Parents: 101612c
Author: admin <vr...@gmail.com>
Authored: Fri Jul 15 20:51:22 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue Jul 19 13:06:58 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/connprofile.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a34f129a/newtmgr/cli/connprofile.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/connprofile.go b/newtmgr/cli/connprofile.go
index 701dacf..2bd5ea7 100644
--- a/newtmgr/cli/connprofile.go
+++ b/newtmgr/cli/connprofile.go
@@ -139,8 +139,8 @@ func connProfileShowCmd(cmd *cobra.Command, args []string) {
fmt.Printf(" %s: type=%s, connstring='%s'", cp.MyName, cp.MyType,
cp.MyConnString)
if (len(cp.MyDeviceAddress) > 0) {
- fmt.Printf("addr=%s", print_addr_hex(cp.MyDeviceAddress, ":"))
- fmt.Printf(" addrtype=%+v", cp.MyDeviceAddressType)
+ fmt.Printf(", addr=%s", print_addr_hex(cp.MyDeviceAddress, ":"))
+ fmt.Printf(", addrtype=%+v", cp.MyDeviceAddressType)
}
fmt.Printf("\n")
[4/9] incubator-mynewt-newt git commit: MYNEWT-266 newtmgr over BLE
Posted by cc...@apache.org.
MYNEWT-266 newtmgr over BLE
- Initial commit - newtmgr BLE
- Make newtmgr work over BLE(type:ble connstring:<nameofdevice>)
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/bf66388a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/bf66388a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/bf66388a
Branch: refs/heads/develop
Commit: bf66388a7d3ce49f8e7d478ac838bafe16226bf6
Parents: c338961
Author: Vipul Rahane <vi...@runtime.io>
Authored: Tue Jun 21 15:54:59 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue Jul 19 13:06:58 2016 -0700
----------------------------------------------------------------------
newtmgr/transport/conn.go | 5 ++
newtmgr/transport/connble.go | 164 +++++++++++++++++++++++++++++++++++
newtmgr/transport/connserial.go | 4 +-
3 files changed, 171 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/bf66388a/newtmgr/transport/conn.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/conn.go b/newtmgr/transport/conn.go
index 42d22a4..835be99 100644
--- a/newtmgr/transport/conn.go
+++ b/newtmgr/transport/conn.go
@@ -86,6 +86,11 @@ func newConn(cp config.NewtmgrConnProfile, readTimeout time.Duration) (Conn, err
if err := c.Open(cp, readTimeout); err != nil {
return nil, err
}
+ case "ble":
+ c = &ConnBLE{}
+ if err := c.Open(cp, readTimeout); err != nil {
+ return nil, err
+ }
default:
return nil, util.NewNewtError("Invalid conn profile " + cp.Type() +
" not implemented")
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/bf66388a/newtmgr/transport/connble.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connble.go b/newtmgr/transport/connble.go
new file mode 100644
index 0000000..2e5c058
--- /dev/null
+++ b/newtmgr/transport/connble.go
@@ -0,0 +1,164 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package transport
+
+import (
+ "fmt"
+ "time"
+
+ log "github.com/Sirupsen/logrus"
+ "github.com/paypal/gatt"
+
+ "mynewt.apache.org/newt/newtmgr/config"
+ "mynewt.apache.org/newt/util"
+)
+
+var done = make(chan struct{})
+var newtmgrServiceId = gatt.MustParseUUID("59462f12-9543-9999-12c8-58b459a27120")
+var newtmgrServiceCharId = gatt.MustParseUUID("5c3a659e-897e-45e1-b016-007107c96d00")
+var deviceName string
+
+type ConnBLE struct {
+ connProfile config.NewtmgrConnProfile
+ currentPacket *Packet
+
+ bleDevice gatt.Device
+}
+
+var pktData []byte
+
+func onStateChanged(d gatt.Device, s gatt.State) {
+ fmt.Println("State:", s)
+ switch s {
+ case gatt.StatePoweredOn:
+ fmt.Println("scanning...")
+ d.Scan([]gatt.UUID{}, false)
+ return
+ default:
+ d.StopScanning()
+ }
+}
+
+func onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
+ if a.LocalName == deviceName {
+ fmt.Printf("Peripheral Discovered: %s \n", p.Name())
+ p.Device().StopScanning()
+ p.Device().Connect(p)
+ }
+}
+
+func newtmgrNotifyCB(c *gatt.Characteristic, incomingDatabuf []byte, err error) {
+ fmt.Printf("Newtmgr response rxd:%+v", incomingDatabuf)
+}
+
+func onPeriphConnected(p gatt.Peripheral, err error) {
+ fmt.Printf("Peripheral connected\n")
+
+ services, err := p.DiscoverServices(nil)
+ if err != nil {
+ fmt.Printf("Failed to discover services, err: %s\n", err)
+ return
+ }
+
+ for _, service := range services {
+
+ if service.UUID().Equal(newtmgrServiceId) {
+ fmt.Printf("Newtmgr Service Found %s\n", service.Name())
+
+ cs, _ := p.DiscoverCharacteristics(nil, service)
+
+ for _, c := range cs {
+ if c.UUID().Equal(newtmgrServiceCharId) {
+ fmt.Printf("Newtmgr Characteristic Found %+v", c)
+ p.SetNotifyValue(c, newtmgrNotifyCB)
+ log.Debugf("Writing %+v to ble", pktData)
+ p.WriteCharacteristic(c, pktData, true)
+ }
+ }
+ }
+ }
+}
+
+func onPeriphDisconnected(p gatt.Peripheral, err error) {
+ fmt.Println("Disconnected")
+}
+
+func (cb *ConnBLE) Open(cp config.NewtmgrConnProfile, readTimeout time.Duration) error {
+ var err error
+
+ var DefaultClientOptions = []gatt.Option{
+ gatt.LnxMaxConnections(1),
+ gatt.LnxDeviceID(-1, false),
+ }
+
+ deviceName = cp.ConnString()
+ cb.bleDevice, err = gatt.NewDevice(DefaultClientOptions...)
+ if err != nil {
+ return util.NewNewtError(err.Error())
+ }
+ //defer cs.serialChannel.Close()
+
+ cb.bleDevice.Handle(
+ gatt.PeripheralDiscovered(onPeriphDiscovered),
+ gatt.PeripheralConnected(onPeriphConnected),
+ gatt.PeripheralDisconnected(onPeriphDisconnected),
+ )
+ return nil
+}
+
+func (cb *ConnBLE) ReadPacket() (*Packet, error) {
+ var err error
+ /*
+ pktLen := binary.BigEndian.Uint16(data[0:2])
+ cb.currentPacket, err = NewPacket(pktLen)
+ if err != nil {
+ return nil, err
+ }
+ data = data[2:]
+
+ if cs.currentPacket == nil {
+ continue
+ }
+
+ full := cs.currentPacket.AddBytes(data)
+ if full {
+ if crc16.Crc16(cs.currentPacket.GetBytes()) != 0 {
+ return nil, util.NewNewtError("CRC error")
+ }
+
+ /*
+ * Trim away the 2 bytes of CRC
+ */
+ /* cs.currentPacket.TrimEnd(2)
+ pkt := cs.currentPacket
+ cs.currentPacket = nil
+ return pkt, nil
+ }
+ }
+ */
+ return nil, err
+}
+
+func (cb *ConnBLE) WritePacket(pkt *Packet) error {
+ pktData = pkt.GetBytes()
+ cb.bleDevice.Init(onStateChanged)
+ <-done
+ return nil
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/bf66388a/newtmgr/transport/connserial.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connserial.go b/newtmgr/transport/connserial.go
index 8e230ce..993650b 100644
--- a/newtmgr/transport/connserial.go
+++ b/newtmgr/transport/connserial.go
@@ -166,9 +166,9 @@ func (cs *ConnSerial) WritePacket(pkt *Packet) error {
cs.writeData([]byte{4, 20})
}
- writeLen := util.Min(120, totlen - written)
+ writeLen := util.Min(120, totlen-written)
- writeBytes := base64Data[written:written+writeLen]
+ writeBytes := base64Data[written : written+writeLen]
cs.writeData(writeBytes)
cs.writeData([]byte{'\n'})
[6/9] incubator-mynewt-newt git commit: MYNEWT-266 newtmgr over BLE
Posted by cc...@apache.org.
MYNEWT-266 newtmgr over BLE
- Newtmgr add BLE transport
-Add BLE transport
-Add close() method and call it from individual command handlers
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/d2660af4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/d2660af4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/d2660af4
Branch: refs/heads/develop
Commit: d2660af472888ec5e844aac8eb74acc5851d81d8
Parents: bf66388
Author: admin <vr...@gmail.com>
Authored: Fri Jul 8 14:38:31 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue Jul 19 13:06:58 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/config.go | 1 +
newtmgr/cli/crash.go | 1 +
newtmgr/cli/datetime.go | 1 +
newtmgr/cli/echo.go | 1 +
newtmgr/cli/image.go | 30 +++++++----
newtmgr/cli/logs.go | 7 ++-
newtmgr/cli/mpstats.go | 1 +
newtmgr/cli/reset.go | 1 +
newtmgr/cli/stats.go | 2 +
newtmgr/cli/taskstats.go | 2 +-
newtmgr/protocol/cmdrunner.go | 8 +--
newtmgr/transport/conn.go | 6 +++
newtmgr/transport/connble.go | 100 +++++++++++++++++++----------------
newtmgr/transport/connserial.go | 4 ++
14 files changed, 103 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/cli/config.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/config.go b/newtmgr/cli/config.go
index 13bb6ca..20f819d 100644
--- a/newtmgr/cli/config.go
+++ b/newtmgr/cli/config.go
@@ -37,6 +37,7 @@ func configRunCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ defer runner.Conn.Close()
config, err := protocol.NewConfig()
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/cli/crash.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/crash.go b/newtmgr/cli/crash.go
index 08f7a9d..9f8e6b2 100644
--- a/newtmgr/cli/crash.go
+++ b/newtmgr/cli/crash.go
@@ -49,6 +49,7 @@ func crashRunCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ defer conn.Close()
runner, err := protocol.NewCmdRunner(conn)
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/cli/datetime.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/datetime.go b/newtmgr/cli/datetime.go
index 88632cf..c04122f 100644
--- a/newtmgr/cli/datetime.go
+++ b/newtmgr/cli/datetime.go
@@ -32,6 +32,7 @@ func dateTimeCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ defer runner.Conn.Close()
dateTime, err := protocol.NewDateTime()
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/cli/echo.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/echo.go b/newtmgr/cli/echo.go
index 9f6f189..5104478 100644
--- a/newtmgr/cli/echo.go
+++ b/newtmgr/cli/echo.go
@@ -32,6 +32,7 @@ func echoRunCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ defer runner.Conn.Close()
echo, err := protocol.NewEcho()
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index aa9eff5..f68f980 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -36,6 +36,8 @@ import (
"github.com/spf13/cobra"
)
+const bleMTU = 240
+
var (
coreElfify bool
coreOffset uint32
@@ -57,6 +59,7 @@ func imageListCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(nil, err)
}
+ defer conn.Close()
runner, err := protocol.NewCmdRunner(conn)
if err != nil {
@@ -90,6 +93,7 @@ func imageListCmd(cmd *cobra.Command, args []string) {
for i := 0; i < len(iRsp.Images); i++ {
fmt.Println(" ", i, ": "+iRsp.Images[i])
}
+
}
func imageListCmd2(cmd *cobra.Command, args []string) {
@@ -151,20 +155,23 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(nil, err)
}
+ defer conn.Close()
runner, err := protocol.NewCmdRunner(conn)
if err != nil {
nmUsage(cmd, err)
}
- err = echoCtrl(runner, "0")
- if err != nil {
- nmUsage(cmd, err)
+
+ if (profile.Type() == "serial") {
+ err = echoCtrl(runner, "0")
+ if err != nil {
+ nmUsage(cmd, err)
+ }
}
var currOff uint32 = 0
imageSz := uint32(len(imageFile))
rexmits := 0
- fmt.Println(currOff)
for currOff < imageSz {
imageUpload, err := protocol.NewImageUpload()
if err != nil {
@@ -172,8 +179,9 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
}
blockSz := imageSz - currOff
- if blockSz > 36 {
- blockSz = 36
+ mtu := uint32((bleMTU - 33) * 3/4)
+ if blockSz > mtu {
+ blockSz = mtu
}
if currOff == 0 {
blockSz = 33
@@ -226,11 +234,13 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, err)
}
currOff = ersp.Offset
- fmt.Println(currOff)
}
- err = echoCtrl(runner, "1")
- if err != nil {
- nmUsage(cmd, err)
+
+ if (profile.Type() == "serial") {
+ err = echoCtrl(runner, "1")
+ if err != nil {
+ nmUsage(cmd, err)
+ }
}
if rexmits != 0 {
fmt.Printf(" %d retransmits\n", rexmits)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/cli/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/logs.go b/newtmgr/cli/logs.go
index f5c892b..e3bae23 100644
--- a/newtmgr/cli/logs.go
+++ b/newtmgr/cli/logs.go
@@ -117,6 +117,7 @@ func logsShowCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ defer runner.Conn.Close()
req, err := protocol.NewLogsShowReq()
if err != nil {
@@ -179,6 +180,7 @@ func logsModuleListCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ defer runner.Conn.Close()
req, err := protocol.NewLogsModuleListReq()
if err != nil {
@@ -214,7 +216,7 @@ func logsListCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
-
+ defer runner.Conn.Close()
req, err := protocol.NewLogsListReq()
if err != nil {
nmUsage(cmd, err)
@@ -248,7 +250,7 @@ func logsLevelListCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
-
+ defer runner.Conn.Close()
req, err := protocol.NewLogsLevelListReq()
if err != nil {
nmUsage(cmd, err)
@@ -282,6 +284,7 @@ func logsClearCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ defer runner.Conn.Close()
req, err := protocol.NewLogsClearReq()
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/cli/mpstats.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/mpstats.go b/newtmgr/cli/mpstats.go
index 3dc7772..2a02023 100644
--- a/newtmgr/cli/mpstats.go
+++ b/newtmgr/cli/mpstats.go
@@ -32,6 +32,7 @@ func mempoolStatsRunCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ defer runner.Conn.Close()
srr, err := protocol.NewMempoolStatsReadReq()
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/cli/reset.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/reset.go b/newtmgr/cli/reset.go
index 8710a63..77a9578 100644
--- a/newtmgr/cli/reset.go
+++ b/newtmgr/cli/reset.go
@@ -31,6 +31,7 @@ func resetRunCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ defer runner.Conn.Close()
reset, err := protocol.NewReset()
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/cli/stats.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/stats.go b/newtmgr/cli/stats.go
index 6014797..45434af 100644
--- a/newtmgr/cli/stats.go
+++ b/newtmgr/cli/stats.go
@@ -32,6 +32,7 @@ func statsListRunCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ defer runner.Conn.Close()
slr, err := protocol.NewStatsListReq()
if err != nil {
@@ -66,6 +67,7 @@ func statsRunCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
+ defer runner.Conn.Close()
srr, err := protocol.NewStatsReadReq()
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/cli/taskstats.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/taskstats.go b/newtmgr/cli/taskstats.go
index e36f988..98225de 100644
--- a/newtmgr/cli/taskstats.go
+++ b/newtmgr/cli/taskstats.go
@@ -32,7 +32,7 @@ func taskStatsRunCmd(cmd *cobra.Command, args []string) {
if err != nil {
nmUsage(cmd, err)
}
-
+ defer runner.Conn.Close()
srr, err := protocol.NewTaskStatsReadReq()
if err != nil {
nmUsage(cmd, err)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/protocol/cmdrunner.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/cmdrunner.go b/newtmgr/protocol/cmdrunner.go
index 198a83a..5b7d31a 100644
--- a/newtmgr/protocol/cmdrunner.go
+++ b/newtmgr/protocol/cmdrunner.go
@@ -26,12 +26,12 @@ import (
)
type CmdRunner struct {
- conn transport.Conn
+ Conn transport.Conn
}
func (cr *CmdRunner) ReadResp() (*NmgrReq, error) {
for {
- pkt, err := cr.conn.ReadPacket()
+ pkt, err := cr.Conn.ReadPacket()
if err != nil {
return nil, err
}
@@ -68,7 +68,7 @@ func (cr *CmdRunner) WriteReq(nmr *NmgrReq) error {
pkt.AddBytes(data)
- if err := cr.conn.WritePacket(pkt); err != nil {
+ if err := cr.Conn.WritePacket(pkt); err != nil {
return err
}
@@ -77,7 +77,7 @@ func (cr *CmdRunner) WriteReq(nmr *NmgrReq) error {
func NewCmdRunner(conn transport.Conn) (*CmdRunner, error) {
cmd := &CmdRunner{
- conn: conn,
+ Conn: conn,
}
return cmd, nil
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/transport/conn.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/conn.go b/newtmgr/transport/conn.go
index 835be99..2f89783 100644
--- a/newtmgr/transport/conn.go
+++ b/newtmgr/transport/conn.go
@@ -31,6 +31,7 @@ type Conn interface {
Open(cp config.NewtmgrConnProfile, timeout time.Duration) error
ReadPacket() (*Packet, error)
WritePacket(pkt *Packet) error
+ Close() error
}
type Packet struct {
@@ -98,3 +99,8 @@ func newConn(cp config.NewtmgrConnProfile, readTimeout time.Duration) (Conn, err
return c, nil
}
+
+func CloseConn(c Conn) error {
+ c.Close()
+ return nil
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/transport/connble.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connble.go b/newtmgr/transport/connble.go
index 2e5c058..4a49780 100644
--- a/newtmgr/transport/connble.go
+++ b/newtmgr/transport/connble.go
@@ -1,5 +1,6 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
+ iog.Debugf("Writing %+v to data channel", bytes)
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
@@ -20,17 +21,18 @@
package transport
import (
- "fmt"
+ log "github.com/Sirupsen/logrus"
"time"
- log "github.com/Sirupsen/logrus"
"github.com/paypal/gatt"
"mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/util"
)
-var done = make(chan struct{})
+var rxBLEPkt = make(chan []byte)
+var CharDisc = make(chan bool)
+
var newtmgrServiceId = gatt.MustParseUUID("59462f12-9543-9999-12c8-58b459a27120")
var newtmgrServiceCharId = gatt.MustParseUUID("5c3a659e-897e-45e1-b016-007107c96d00")
var deviceName string
@@ -42,13 +44,16 @@ type ConnBLE struct {
bleDevice gatt.Device
}
-var pktData []byte
+var deviceChar *gatt.Characteristic
+var devicePerph gatt.Peripheral
+
+var bleTxData []byte
func onStateChanged(d gatt.Device, s gatt.State) {
- fmt.Println("State:", s)
+ log.Debugf("State:%+v", s)
switch s {
case gatt.StatePoweredOn:
- fmt.Println("scanning...")
+ log.Debugf("scanning...")
d.Scan([]gatt.UUID{}, false)
return
default:
@@ -58,38 +63,43 @@ func onStateChanged(d gatt.Device, s gatt.State) {
func onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
if a.LocalName == deviceName {
- fmt.Printf("Peripheral Discovered: %s \n", p.Name())
+ log.Debugf("Peripheral Discovered: %s", p.Name())
p.Device().StopScanning()
p.Device().Connect(p)
}
}
func newtmgrNotifyCB(c *gatt.Characteristic, incomingDatabuf []byte, err error) {
- fmt.Printf("Newtmgr response rxd:%+v", incomingDatabuf)
+ log.Debugf("BLE Newtmgr rx data:%+v", incomingDatabuf)
+ err = nil
+ rxBLEPkt <- incomingDatabuf
+ return
}
func onPeriphConnected(p gatt.Peripheral, err error) {
- fmt.Printf("Peripheral connected\n")
+ log.Debugf("Peripheral Connected")
services, err := p.DiscoverServices(nil)
if err != nil {
- fmt.Printf("Failed to discover services, err: %s\n", err)
+ log.Debugf("Failed to discover services, err: %s", err)
return
}
for _, service := range services {
if service.UUID().Equal(newtmgrServiceId) {
- fmt.Printf("Newtmgr Service Found %s\n", service.Name())
+ log.Debugf("Newtmgr Service Found %s", service.Name())
cs, _ := p.DiscoverCharacteristics(nil, service)
for _, c := range cs {
if c.UUID().Equal(newtmgrServiceCharId) {
- fmt.Printf("Newtmgr Characteristic Found %+v", c)
+ log.Debugf("Newtmgr Characteristic Found")
p.SetNotifyValue(c, newtmgrNotifyCB)
- log.Debugf("Writing %+v to ble", pktData)
- p.WriteCharacteristic(c, pktData, true)
+ deviceChar = c
+ devicePerph = p
+ p.SetMTU(240)
+ <-CharDisc
}
}
}
@@ -97,7 +107,7 @@ func onPeriphConnected(p gatt.Peripheral, err error) {
}
func onPeriphDisconnected(p gatt.Peripheral, err error) {
- fmt.Println("Disconnected")
+ log.Debugf("Disconnected", err)
}
func (cb *ConnBLE) Open(cp config.NewtmgrConnProfile, readTimeout time.Duration) error {
@@ -113,52 +123,52 @@ func (cb *ConnBLE) Open(cp config.NewtmgrConnProfile, readTimeout time.Duration)
if err != nil {
return util.NewNewtError(err.Error())
}
- //defer cs.serialChannel.Close()
cb.bleDevice.Handle(
gatt.PeripheralDiscovered(onPeriphDiscovered),
gatt.PeripheralConnected(onPeriphConnected),
gatt.PeripheralDisconnected(onPeriphDisconnected),
)
+ cb.bleDevice.Init(onStateChanged)
+ CharDisc <- true
+
return nil
}
func (cb *ConnBLE) ReadPacket() (*Packet, error) {
var err error
- /*
- pktLen := binary.BigEndian.Uint16(data[0:2])
- cb.currentPacket, err = NewPacket(pktLen)
- if err != nil {
- return nil, err
- }
- data = data[2:]
-
- if cs.currentPacket == nil {
- continue
- }
- full := cs.currentPacket.AddBytes(data)
- if full {
- if crc16.Crc16(cs.currentPacket.GetBytes()) != 0 {
- return nil, util.NewNewtError("CRC error")
- }
+ bleRxData := <-rxBLEPkt
- /*
- * Trim away the 2 bytes of CRC
- */
- /* cs.currentPacket.TrimEnd(2)
- pkt := cs.currentPacket
- cs.currentPacket = nil
- return pkt, nil
- }
+ cb.currentPacket, err = NewPacket(uint16(len(bleRxData)))
+ if err != nil {
+ return nil, err
}
- */
- return nil, err
+
+ cb.currentPacket.AddBytes(bleRxData)
+ log.Debugf("Read BLE Packet:buf::%+v len::%+v", cb.currentPacket.buffer,
+ cb.currentPacket.expectedLen)
+ bleRxData = bleRxData[:0]
+ pkt := cb.currentPacket
+ cb.currentPacket = nil
+ return pkt, err
+}
+
+func (cb *ConnBLE) writeData() error {
+ devicePerph.WriteCharacteristic(deviceChar, bleTxData, true)
+ return nil
}
func (cb *ConnBLE) WritePacket(pkt *Packet) error {
- pktData = pkt.GetBytes()
- cb.bleDevice.Init(onStateChanged)
- <-done
+ log.Debugf("Write BLE Packet:buf::%+v len::%+v", pkt.buffer,
+ pkt.expectedLen)
+ bleTxData = pkt.GetBytes()
+ cb.writeData()
+ return nil
+}
+
+func (cb *ConnBLE) Close () error {
+ log.Debugf("Closing Connection %+v", cb)
+ cb.bleDevice.CancelConnection(devicePerph)
return nil
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2660af4/newtmgr/transport/connserial.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connserial.go b/newtmgr/transport/connserial.go
index 993650b..5c5c6e8 100644
--- a/newtmgr/transport/connserial.go
+++ b/newtmgr/transport/connserial.go
@@ -177,3 +177,7 @@ func (cs *ConnSerial) WritePacket(pkt *Packet) error {
return nil
}
+
+func (cs *ConnSerial) Close() error {
+ return nil
+}