Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace currantlabs dep with go-ble. #53

Merged
merged 3 commits into from Feb 10, 2018
Merged

Replace currantlabs dep with go-ble. #53

merged 3 commits into from Feb 10, 2018

Conversation

ccollins476ad
Copy link
Contributor

@ccollins476ad ccollins476ad commented Nov 29, 2017

This replaces the native BLE library github.com/currantlabs/ble with a better maintained one: github.com/go-ble/ble. The go-ble library has support for macOS 10.13 (High Sierra).

@mkiiskila
Copy link
Contributor

I get this on my MacOS 10.13.1 from this branch:

newtmgr -c named_oic --name ci res get public /oic/d
2017/11/29 14:32:07 Unhandled event: xpc.Dict{"kCBMsgId":57, "kCBMsgArgs":xpc.Dict{"kCBMsgArgDeviceUUID":xpc.UUID{0xea, 0x2f, 0x60, 0x50, 0x37, 0xe4, 0x4c, 0xad, 0x8d, 0x9, 0x28, 0xf2, 0x5b, 0x32, 0xa0, 0xf1}, "kCBMsgArgATTMTU":256}}
2017/11/29 14:32:07 Unhandled event: xpc.Dict{"kCBMsgId":57, "kCBMsgArgs":xpc.Dict{"kCBMsgArgDeviceUUID":xpc.UUID{0xea, 0x2f, 0x60, 0x50, 0x37, 0xe4, 0x4c, 0xad, 0x8d, 0x9, 0x28, 0xf2, 0x5b, 0x32, 0xa0, 0xf1}, "kCBMsgArgATTMTU":256}}
Error: OIC timeout
exit status 1

@jacobrosenthal
Copy link
Member

Dont forget to update this projects readme doesnt need currantlabs ble anymore and any other dep changes. Also that PR you were waiting on is in

@ccollins476ad
Copy link
Contributor Author

Thanks, Jacob - correct on both points.

By the way, I am pretty sure this is close to fixing the High Sierra issue. It has been a little while so my memory is hazy, but I recall the remaining issue being that some XPC IDs just need to be reverse engineered:

        // TODO: find out the correct values for the following items.
        // They have all just been copied from Yosemite values
        evtAdvertisingStarted = 16
        evtAdvertisingStopped = 17
        evtServiceAdded = 18
        evtReadRequest = 19
        evtWriteRequest = 20
        evtSubscribe = 21
        evtUnsubscribe = 22
        evtConfirmation = 23
        evtATTMTU = 53
        evtSlaveConnectionComplete = 81
        evtMasterConnectionComplete = 82
        evtIncludedServicesDiscovered = 87

I don't recall which one it was, but at least one of these IDs has changed since Yosemite. I was going to figure out the IDs via trial and error on a High Sierra machine, but unfortunately I didn't get a chance.

@jacobrosenthal
Copy link
Member

Ill take a look, I think some noble folks have gotten them close to reversed.

Do you want to be using upstream go-ble now that the patch is in or are you trying to use your fork of it to lock the version

@mkiiskila
Copy link
Contributor

I did give this branch a run along with Jacob's updates to this branch and to runtimeco/ble.
It's looking good to me; I get no OS errors anymore.

While testing, I encountered a bug in OIC over BLE. Created a PR for that one.

@jacobrosenthal
Copy link
Member

jacobrosenthal commented Feb 1, 2018

My readme update is using upstream go-ble, while revendor is using runtimeco/ble so that actually needs to be changed.

@ccollins476ad
Copy link
Contributor Author

ccollins476ad commented Feb 1, 2018

Upstream go-ble merged the two outstanding patches, so I converted over to upstream rather than the runtimeco fork.

This should be ready to merge now.

@jacobrosenthal
Copy link
Member

Gave this a test myself after all these weeks and PRs. Working for me on high sierra:

Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image list -cnimble_bleprph
Images:
 slot=0
    version: 0.0.0
    bootable: true
    flags: active confirmed
    hash: cca86e274755ecc8dd03a251e6d1a45d9bc32f29a3c59c7d4784c649ac9c91af
 slot=1
    version: 0.0.0
    bootable: false
    flags: 
    hash: 8f9247cbe2d292d1b510b7807d3d4b49b44a480d3e8377bd33299cac03539d27
Split status: matching (2)

@jacobrosenthal
Copy link
Member

I dont have a go script that does a full upload does anyone? Otherwise Ill manually try an upload on one of my nrf52 devices

@ccollins476ad ccollins476ad changed the title [DO NOT MERGE] Replace currantlabs dep with go-ble. Replace currantlabs dep with go-ble. Feb 1, 2018
@jacobrosenthal
Copy link
Member

hrm. Might need some work yet. Havent succeeded to upload on like 10 attempts, but my chrome uploader succeeded the first time. Anyone remember the verbosity/debug flags?

Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blesplit/blesplit.img -cnimble_bleprph
 73 B / 3.66 KiB [==>------------------------------------------------------------------------------------------------------------]   1.95% 38sError: disconnected
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blesplit/blesplit.img -cnimble_bleprph
Error: Failed to connect to peer after 10s
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blesplit/blesplit.img -cnimble_bleprph
 0 B / 3.66 KiB [--------------------------------------------------------------------------------------------------------------------]   0.00%Error: disconnected
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blesplit/blesplit.img -cnimble_bleprph
Error: Failed to connect to peer after 10s
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blesplit/blesplit.img -cnimble_bleprph
 928 B / 3.66 KiB [============================>-------------------------------------------------------------------------------------]  24.79%^C
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blplit/blesplit.img -cnimble_bleprph
 3.12 KiB / 3.66 KiB [==============================================================================================>----------------]  85.47%Error: disconnected
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blesplit/blesplit.img -cnimble_bleprph
 1.11 KiB / 3.66 KiB [================================>---------------------------------------------------------------------------]  30.48% 1sError: disconnected
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blesplit/blesplit.img -cnimble_bleprph
 217 B / 3.66 KiB [======>-------------------------------------------------------------------------------------------------------]   5.80% 14s^C
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blplit/blesplit.img -cnimble_bleprph
 73 B / 3.66 KiB [==>------------------------------------------------------------------------------------------------------------]   1.95% 34s^C
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blplit/blesplit.img -cnimble_bleprph
 3.47 KiB / 3.66 KiB [=========================================================================================================>-----]  94.95%^C
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blplit/blesplit.img -cnimble_bleprph
 3.12 KiB / 3.66 KiB [==============================================================================================>----------------]  85.47%^C
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blplit/blesplit.img -cnimble_bleprph
 1.39 KiB / 3.66 KiB [=========================================>------------------------------------------------------------------]  38.06% 4s^C
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-thingy/app/apps/blplit/blesplit.img -cnimble_bleprph
 1.53 KiB / 3.66 KiB [=============================================>--------------------------------------------------------------]  41.85% 4s^C
Jacobs-MacBook-Air:newtmgr jacobrosenthal$ newtmgr imaglist -cnimble_bleprph

@jacobrosenthal
Copy link
Member

jacobrosenthal commented Feb 5, 2018

I havent seen those disconnects happen again (on the nrf51 anyway.) Ive done a bunch of complete upload cycles and further Ive got a little bash script to upload a (large) loader over and over again that might be helpful for testing that hasnt failed yet.

#!/bin/bash

# run an array of commands COUNTER times, exit if return code

declare -a arr=("newtmgr -c nimble_bleprph image erase" "newtmgr -c nimble_bleprph image list" "newtmgr -c nimble_bleprph image upload /Users/jacobrosenthal/Downloads/chippd3/bin/targets/split-microbit/loader/apps/bleprph/bleprph.img" "newtmgr -c nimble_bleprph image list")

COUNTER=20
while [  $COUNTER -gt 0 ]; do
    for (( i = 0; i < ${#arr[@]} ; i++ )); do
	    printf "\n**** Running: ${arr[$i]} *****\n\n"

	    # i=0, erase commmand, always returns error code so dont respect
	    eval "${arr[$i]}"
		if [ $? -ne 0 ] && [ $i -ne 0 ]
		then
	    	exit $?
		fi

	done
    let COUNTER-=1
done

LGTM

@adrien3d
Copy link

adrien3d commented Feb 12, 2018

On mac OS High Sierra, while doing a newtmgr image upload -c bleconn /path/to/nrf52_app/app/apps/bleprph/bleprph.img, I have a progress bar remaining at 0B, and an Error: disconnected:
newtmgr image upload -c bleconn /path/to/my/bleprph.img 0 B / 122.70 KiB [------------------------------------------------------------------------------------------------------------------------------------------------------] 0.00% Error: disconnected

Any idea of where the problem is coming from?

With the debug flag, I have:

DEBU[2018-02-12 15:52:54.823] Using connection profile: name=bleconn type=ble connstring=peer_name=klocz-ble
DEBU[2018-02-12 15:52:54.825] {add-oic-listener} [transceiver.go:62] token=[]
DEBU[2018-02-12 15:52:54.825] Connecting to peer
DEBU[2018-02-12 15:52:55.217] Exchanging MTU
DEBU[2018-02-12 15:52:55.218] Exchanged MTU; ATT MTU = 104
DEBU[2018-02-12 15:52:55.218] Discovering profile
DEBU[2018-02-12 15:52:55.929] Subscribing to NMP response characteristic
0 / 125640 [-------------------------------------------------------------------------------------------------------------------------------------------------------] 0.00%DEBU[2018-02-12 15:52:55.974] {add-nmp-listener} [bll_sesn.go:401] seq=66
DEBU[2018-02-12 15:52:55.975] Encoded &{NmpBase:{hdr:{Op:2 Flags:0 Len:0 Group:1 Seq:66 Id:5}}} to:
00000000 a0 |.|

DEBU[2018-02-12 15:52:55.975] Encoded:
00000000 02 00 00 01 00 01 42 05 a0 |......B..|

DEBU[2018-02-12 15:52:55.975] Tx NMP request: 00000000 02 00 00 01 00 01 42 05 a0 |......B..|

0 B / 122.70 KiB [-------------------------------------------------------------------------------------------------------------------------------------------------] 0.00%DEBU[2018-02-12 15:52:58.023] {remove-nmp-listener} [bll_sesn.go:401] seq=66
DEBU[2018-02-12 15:52:58.023] OIC error: disconnected
DEBU[2018-02-12 15:52:58.027] {remove-oic-listener} [.:0] token=[]
DEBU[2018-02-12 15:52:58.027] goroutine 1 [running]:
mynewt.apache.org/newtmgr/vendor/mynewt.apache.org/newt/util.NewNewtError(0xc420144120, 0xc, 0xc)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/mynewt.apache.org/newt/util/util.go:77 +0xe8
mynewt.apache.org/newtmgr/vendor/mynewt.apache.org/newt/util.ChildNewtError(0x4a5b0c0, 0xc42014c220, 0xc4201685a0)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/mynewt.apache.org/newt/util/util.go:103 +0x82
mynewt.apache.org/newtmgr/newtmgr/cli.imageUploadCmd(0xc4201bf200, 0xc4200848c0, 0x1, 0x5)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/newtmgr/cli/image.go:202 +0x40a
mynewt.apache.org/newtmgr/vendor/github.com/spf13/cobra.(*Command).execute(0xc4201bf200, 0xc420084870, 0x5, 0x5, 0xc4201bf200, 0xc420084870)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/github.com/spf13/cobra/command.go:654 +0x2a2
mynewt.apache.org/newtmgr/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc42008f8c0, 0xc420131f08, 0xc420131ef8, 0xc420041ab0)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/github.com/spf13/cobra/command.go:729 +0x2fe
mynewt.apache.org/newtmgr/vendor/github.com/spf13/cobra.(*Command).Execute(0xc42008f8c0, 0x473f778, 0xc420162240)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/github.com/spf13/cobra/command.go:688 +0x2b
main.main()
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/newtmgr/newtmgr.go:111 +0x119

goroutine 5 [syscall]:
os/signal.signal_recv(0x0)
/usr/local/Cellar/go/1.9.4/libexec/src/runtime/sigqueue.go:131 +0xa7
os/signal.loop()
/usr/local/Cellar/go/1.9.4/libexec/src/os/signal/signal_unix.go:22 +0x22
created by os/signal.init.0
/usr/local/Cellar/go/1.9.4/libexec/src/os/signal/signal_unix.go:28 +0x41

goroutine 18 [select, locked to thread]:
runtime.gopark(0x4741980, 0x0, 0x4719b96, 0x6, 0x18, 0x1)
/usr/local/Cellar/go/1.9.4/libexec/src/runtime/proc.go:287 +0x12c
runtime.selectgo(0xc420038f50, 0xc4201b4060)
/usr/local/Cellar/go/1.9.4/libexec/src/runtime/select.go:395 +0x1149
runtime.ensureSigM.func1()
/usr/local/Cellar/go/1.9.4/libexec/src/runtime/signal_unix.go:511 +0x1fe
runtime.goexit()
/usr/local/Cellar/go/1.9.4/libexec/src/runtime/asm_amd64.s:2337 +0x1

goroutine 7 [chan receive]:
main.main.func1(0xc420162240)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/newtmgr/newtmgr.go:97 +0x4b
created by main.main
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/newtmgr/newtmgr.go:95 +0x10f

goroutine 19 [runnable]:
syscall.Syscall(0x4, 0x2, 0xc42029e000, 0x55, 0x55, 0x0, 0x0)
/usr/local/Cellar/go/1.9.4/libexec/src/syscall/asm_darwin_amd64.s:16 +0x5
syscall.write(0x2, 0xc42029e000, 0x55, 0xa9, 0xc42003ba01, 0x0, 0x0)
/usr/local/Cellar/go/1.9.4/libexec/src/syscall/zsyscall_darwin_amd64.go:1328 +0x55
syscall.Write(0x2, 0xc42029e000, 0x55, 0xa9, 0x0, 0x8, 0x68)
/usr/local/Cellar/go/1.9.4/libexec/src/syscall/syscall_unix.go:181 +0x49
internal/poll.(*FD).Write(0xc4200840a0, 0xc42029e000, 0x55, 0xa9, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.9.4/libexec/src/internal/poll/fd_unix.go:219 +0x14f
os.(*File).write(0xc42000e020, 0xc42029e000, 0x55, 0xa9, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.9.4/libexec/src/os/file_unix.go:233 +0x4e
os.(*File).Write(0xc42000e020, 0xc42029e000, 0x55, 0xa9, 0xa9, 0x0, 0x0)
/usr/local/Cellar/go/1.9.4/libexec/src/os/file.go:140 +0x72
mynewt.apache.org/newtmgr/vendor/github.com/Sirupsen/logrus.Entry.log(0xc420084140, 0xc420146390, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, ...)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/github.com/Sirupsen/logrus/entry.go:114 +0x366
mynewt.apache.org/newtmgr/vendor/github.com/Sirupsen/logrus.(*Entry).Debug(0xc42014a140, 0xc42003bdb0, 0x1, 0x1)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/github.com/Sirupsen/logrus/entry.go:131 +0xac
mynewt.apache.org/newtmgr/vendor/github.com/Sirupsen/logrus.(*Entry).Debugf(0xc42014a140, 0x471e4be, 0xd, 0xc42003bec8, 0x1, 0x1)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/github.com/Sirupsen/logrus/entry.go:179 +0xf8
mynewt.apache.org/newtmgr/vendor/github.com/Sirupsen/logrus.(*Logger).Debugf(0xc420084140, 0x471e4be, 0xd, 0xc42003bec8, 0x1, 0x1)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/github.com/Sirupsen/logrus/logger.go:118 +0x86
mynewt.apache.org/newtmgr/vendor/github.com/Sirupsen/logrus.Debugf(0x471e4be, 0xd, 0xc42003bec8, 0x1, 0x1)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/github.com/Sirupsen/logrus/exported.go:117 +0x5f
mynewt.apache.org/newtmgr/nmxact/omp.(*Dispatcher).addOmpListener.func1(0xc42013d3e0, 0xc4201428a0)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/nmxact/omp/dispatch.go:83 +0x2b2
created by mynewt.apache.org/newtmgr/nmxact/omp.(*Dispatcher).addOmpListener
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/nmxact/omp/dispatch.go:67 +0xc0

goroutine 35 [select]:
mynewt.apache.org/newtmgr/vendor/github.com/go-ble/ble.trap.func1(0xc42021c180, 0xc42013e800, 0x4a63580, 0xc42013d4a0)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/github.com/go-ble/ble/gatt.go:173 +0xf2
created by mynewt.apache.org/newtmgr/vendor/github.com/go-ble/ble.trap
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/github.com/go-ble/ble/gatt.go:172 +0x192

goroutine 36 [semacquire]:
sync.runtime_Semacquire(0xc42013d404)
/usr/local/Cellar/go/1.9.4/libexec/src/runtime/sema.go:56 +0x39
sync.(*WaitGroup).Wait(0xc42013d3f8)
/usr/local/Cellar/go/1.9.4/libexec/src/sync/waitgroup.go:131 +0x72
mynewt.apache.org/newtmgr/nmxact/omp.(*Dispatcher).Stop(0xc42013d3e0)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/nmxact/omp/dispatch.go:101 +0x54
mynewt.apache.org/newtmgr/nmxact/mgmt.(*Transceiver).Stop(0xc42013d320)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/nmxact/mgmt/transceiver.go:326 +0x2f
mynewt.apache.org/newtmgr/newtmgr/bll.(*BllSesn).listenDisconnect.func1(0xc4201685a0)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/newtmgr/bll/bll_sesn.go:97 +0xda
created by mynewt.apache.org/newtmgr/newtmgr/bll.(*BllSesn).listenDisconnect
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/newtmgr/bll/bll_sesn.go:89 +0x3f

goroutine 37 [select]:
mynewt.apache.org/newtmgr/vendor/github.com/cheggaaa/pb.(*ProgressBar).refresher(0xc42026a000)
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/github.com/cheggaaa/pb/pb.go:462 +0x109
created by mynewt.apache.org/newtmgr/vendor/github.com/cheggaaa/pb.(*ProgressBar).Start
/private/tmp/mynewt-newtmgr-20180212-9841-nucs1p/gopath/src/mynewt.apache.org/newtmgr/vendor/github.com/cheggaaa/pb/pb.go:123 +0xc0

Error: disconnected```

@jacobrosenthal
Copy link
Member

Im tracking something similar here:
apache/mynewt-core#796

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants