-
Notifications
You must be signed in to change notification settings - Fork 190
Ability to pick tinygo vs go-ble impl #400
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
Open
zlymeda
wants to merge
14
commits into
teslamotors:main
Choose a base branch
from
zlymeda:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
65e42ea
replace go-ble
zlymeda 3e597ed
ble: extract common code and have go-ble + tinygo implementations
zlymeda 5f00d5b
upgrade to go 1.24.2; upgrade linter to 2.1.5, migrate linter config …
zlymeda ad9f2af
tinygo: fix InitAdapter not setting the global device
zlymeda a7ee89d
test: fix race condition
zlymeda e594dd0
ble: use goble by default, allow switching the impl during runtime, m…
zlymeda c4bd391
review changes
zlymeda 48118e2
Redesign
zlymeda eb22be8
close: make sure it can be called multiple times without seg. fault
zlymeda cede070
cli: use enum for ble impl
zlymeda 97e163a
tinygo adapter: fix the case when device.Scan returns err
zlymeda f8b08ef
mod: updates
zlymeda 4811b91
flags: update descriptions
zlymeda cd6da64
fix: MacOS uses UUID instead of MACAddress
zlymeda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,83 @@ | ||
| --- | ||
| run: | ||
| timeout: 4m | ||
|
|
||
| issues: | ||
| exclude-dirs: | ||
| - temp | ||
| exclude: | ||
| - "Error return value of `w.Write` is not checked" | ||
| - "Error return value of `fmt.Fprintf` is not checked" | ||
| - "Error return value of `fmt.Fprintln` is not checked" | ||
| - "Error return value of `file.Close` is not checked" | ||
| - "Error return value of `os.Setenv` is not checked" | ||
| # ECDH code needs to support a Go 1.21 toolchain | ||
| - "elliptic.([A-Za-z]+) has been deprecated since Go 1.21: for ECDH" | ||
| version: "2" | ||
|
|
||
| linters: | ||
| enable: | ||
| - errcheck | ||
| - gofmt | ||
| - gosimple | ||
| - govet | ||
| - misspell | ||
| - revive | ||
| - unused | ||
|
|
||
| linters-settings: | ||
| revive: | ||
| settings: | ||
| revive: | ||
| rules: | ||
| - name: blank-imports | ||
| - name: context-as-argument | ||
| - name: context-keys-type | ||
| - name: dot-imports | ||
| arguments: | ||
| - allowedPackages: | ||
| - github.com/onsi/ginkgo | ||
| - github.com/onsi/ginkgo/v2 | ||
| - github.com/onsi/gomega | ||
| - name: empty-block | ||
| - name: error-naming | ||
| - name: error-return | ||
| - name: error-strings | ||
| - name: errorf | ||
| - name: increment-decrement | ||
| - name: indent-error-flow | ||
| - name: package-comments | ||
| disabled: true | ||
| - name: range | ||
| - name: receiver-naming | ||
| - name: redefines-builtin-id | ||
| - name: superfluous-else | ||
| - name: time-naming | ||
| - name: unexported-return | ||
| - name: unreachable-code | ||
| - name: unused-parameter | ||
| - name: var-declaration | ||
| - name: var-naming | ||
| - name: exported | ||
|
|
||
| staticcheck: | ||
| checks: | ||
| - "-QF1008" | ||
|
|
||
| exclusions: | ||
| generated: lax | ||
| presets: | ||
| - comments | ||
| - common-false-positives | ||
| - legacy | ||
| - std-error-handling | ||
| rules: | ||
| - name: blank-imports | ||
| - name: context-as-argument | ||
| - name: context-keys-type | ||
| - name: dot-imports | ||
| arguments: | ||
| - allowedPackages: | ||
| - "github.com/onsi/ginkgo" | ||
| - "github.com/onsi/ginkgo/v2" | ||
| - "github.com/onsi/gomega" | ||
| - name: empty-block | ||
| - name: error-naming | ||
| - name: error-return | ||
| - name: error-strings | ||
| - name: errorf | ||
| # Uncomment when all issues are fixed | ||
| # - name: exported | ||
| - name: increment-decrement | ||
| - name: indent-error-flow | ||
| - name: package-comments | ||
| disabled: true | ||
| - name: range | ||
| - name: receiver-naming | ||
| - name: redefines-builtin-id | ||
| - name: superfluous-else | ||
| - name: time-naming | ||
| - name: unexported-return | ||
| - name: unreachable-code | ||
| - name: unused-parameter | ||
| - name: var-declaration | ||
| - name: var-naming | ||
| - path: (.+)\.go$ | ||
| text: Error return value of `w.Write` is not checked | ||
| - path: (.+)\.go$ | ||
| text: Error return value of `fmt.Fprintf` is not checked | ||
| - path: (.+)\.go$ | ||
| text: Error return value of `fmt.Fprintln` is not checked | ||
| - path: (.+)\.go$ | ||
| text: Error return value of `file.Close` is not checked | ||
| - path: (.+)\.go$ | ||
| text: Error return value of `os.Setenv` is not checked | ||
| - path: (.+)\.go$ # ECDH code needs to support a Go 1.21 toolchain | ||
| text: 'elliptic.([A-Za-z]+) has been deprecated since Go 1.21: for ECDH' | ||
| paths: | ||
| - temp | ||
| - third_party$ | ||
| - builtin$ | ||
| - examples$ | ||
|
|
||
| formatters: | ||
| enable: | ||
| - gofmt | ||
| exclusions: | ||
| generated: lax | ||
| paths: | ||
| - temp | ||
| - third_party$ | ||
| - builtin$ | ||
| - examples$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ import ( | |
| debugger "github.com/teslamotors/vehicle-command/internal/log" | ||
|
|
||
| "github.com/teslamotors/vehicle-command/pkg/connector/ble" | ||
| "github.com/teslamotors/vehicle-command/pkg/connector/ble/goble" | ||
| "github.com/teslamotors/vehicle-command/pkg/connector/ble/tinygo" | ||
| "github.com/teslamotors/vehicle-command/pkg/protocol" | ||
| "github.com/teslamotors/vehicle-command/pkg/vehicle" | ||
| ) | ||
|
|
@@ -23,6 +25,7 @@ func main() { | |
| logger := log.New(os.Stderr, "", 0) | ||
| status := 1 | ||
| debug := false | ||
| useTinyGo := false | ||
| defer func() { | ||
| os.Exit(status) | ||
| }() | ||
|
|
@@ -38,6 +41,7 @@ func main() { | |
| flag.StringVar(&privateKeyFile, "key", "", "Private key `file` for authorizing commands (PEM PKCS8 NIST-P256)") | ||
| flag.StringVar(&vin, "vin", "", "Vehicle Identification Number (`VIN`) of the car") | ||
| flag.BoolVar(&debug, "debug", false, "Enable debugging of TX/RX BLE packets") | ||
| flag.BoolVar(&useTinyGo, "tinygo", false, "Use tinygo ble impl (go-ble is the default") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if runtime.GOOS == "linux" { | ||
| flag.StringVar(&btAdapter, "bt-adapter", "", "Optional ID of Bluetooth adapter to use") | ||
| } | ||
|
|
@@ -48,13 +52,21 @@ func main() { | |
| debugger.SetLevel(debugger.LevelDebug) | ||
| } | ||
|
|
||
| err := ble.InitAdapterWithID(btAdapter) | ||
| if err != nil { | ||
| if ble.IsAdapterError(err) { | ||
| logger.Print(ble.AdapterErrorHelpMessage(err)) | ||
| } else { | ||
| logger.Printf("Failed to initialize BLE adapter: %s", err) | ||
| var adapter ble.Adapter | ||
| var err error | ||
|
|
||
| if useTinyGo { | ||
| adapter, err = tinygo.NewAdapter(btAdapter) | ||
| } else { | ||
| adapter, err = goble.NewAdapter(btAdapter) | ||
| if err != nil && goble.IsAdapterError(err) { | ||
| logger.Print(goble.AdapterErrorHelpMessage(err)) | ||
| return | ||
| } | ||
| } | ||
|
|
||
| if err != nil { | ||
| logger.Printf("Failed to initialize BLE adapter: %s", err) | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -68,7 +80,7 @@ func main() { | |
| defer cancel() | ||
| doneChan := make(chan struct{}) | ||
| go func() { | ||
| _, err := ble.ScanVehicleBeacon(ctx, vin) | ||
| _, err := ble.ScanVehicleBeacon(ctx, vin, adapter) | ||
| if err != nil && ctx.Err() == nil { | ||
| logger.Printf("Scan failed: %s", err) | ||
| } else if ctx.Err() == nil { | ||
|
|
@@ -105,14 +117,14 @@ func main() { | |
| } | ||
| } | ||
|
|
||
| scan, err := ble.ScanVehicleBeacon(ctx, vin) | ||
| beacon, err := ble.ScanVehicleBeacon(ctx, vin, adapter) | ||
| if err != nil { | ||
| logger.Println(err) | ||
| return | ||
| } | ||
| logger.Printf("Found vehicle: %s (%s) %ddBm", scan.LocalName, scan.Address, scan.RSSI) | ||
| logger.Printf("Found vehicle: %s (%s) %ddBm", beacon.LocalName, beacon.Address, beacon.RSSI) | ||
|
|
||
| conn, err := ble.NewConnectionFromScanResult(ctx, vin, scan) | ||
| conn, err := ble.NewConnectionFromBeacon(ctx, vin, beacon, adapter) | ||
| if err != nil { | ||
| logger.Printf("Failed to connect to vehicle: %s", err) | ||
| return | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,39 @@ | ||
| module github.com/teslamotors/vehicle-command | ||
|
|
||
| go 1.23.0 | ||
| go 1.24 | ||
|
|
||
| require ( | ||
| github.com/99designs/keyring v1.2.2 | ||
| github.com/cronokirby/saferith v0.33.0 | ||
| github.com/go-ble/ble v0.0.0-20240122180141-8c5522f54333 | ||
| github.com/golang-jwt/jwt/v5 v5.2.2 | ||
| github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 | ||
| golang.org/x/term v0.5.0 | ||
| google.golang.org/protobuf v1.34.2 | ||
| github.com/zlymeda/go-ble v0.0.0-20250503163836-ac689226ee0c | ||
| golang.org/x/term v0.32.0 | ||
| google.golang.org/protobuf v1.36.6 | ||
| tinygo.org/x/bluetooth v0.11.1-0.20250505124847-38847b0d22b1 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect | ||
| github.com/JuulLabs-OSS/cbgo v0.0.1 // indirect | ||
| github.com/danieljoos/wincred v1.2.0 // indirect | ||
| github.com/dvsekhvalnov/jose2go v1.6.0 // indirect | ||
| github.com/danieljoos/wincred v1.2.2 // indirect | ||
| github.com/dvsekhvalnov/jose2go v1.8.0 // indirect | ||
| github.com/go-ole/go-ole v1.3.0 // indirect | ||
| github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect | ||
| github.com/google/go-cmp v0.5.8 // indirect | ||
| github.com/godbus/dbus/v5 v5.1.0 // indirect | ||
| github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect | ||
| github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect | ||
| github.com/mattn/go-colorable v0.1.6 // indirect | ||
| github.com/mattn/go-isatty v0.0.12 // indirect | ||
| github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect | ||
| github.com/mattn/go-colorable v0.1.14 // indirect | ||
| github.com/mattn/go-isatty v0.0.20 // indirect | ||
| github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect | ||
| github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab // indirect | ||
| github.com/mtibben/percent v0.2.1 // indirect | ||
| github.com/pkg/errors v0.8.1 // indirect | ||
| github.com/raff/goble v0.0.0-20190909174656-72afc67d6a99 // indirect | ||
| github.com/sirupsen/logrus v1.5.0 // indirect | ||
| golang.org/x/sys v0.8.0 // indirect | ||
| github.com/pkg/errors v0.9.1 // indirect | ||
| github.com/raff/goble v0.0.0-20200327175727-d63360dcfd80 // indirect | ||
| github.com/saltosystems/winrt-go v0.0.0-20241223121953-98e32661f6ff // indirect | ||
| github.com/sirupsen/logrus v1.9.3 // indirect | ||
| github.com/soypat/cyw43439 v0.0.0-20250505012923-830110c8f4af // indirect | ||
| github.com/soypat/seqs v0.0.0-20250124201400-0d65bc7c1710 // indirect | ||
| github.com/tinygo-org/cbgo v0.0.4 // indirect | ||
| github.com/tinygo-org/pio v0.2.0 // indirect | ||
| golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect | ||
| golang.org/x/sys v0.33.0 // indirect | ||
| ) | ||
|
|
||
| replace github.com/JuulLabs-OSS/cbgo => github.com/tinygo-org/cbgo v0.0.4 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.