hunt down wrath bugs
This commit is contained in:
parent
413bbeb95a
commit
d535711880
18
cmd.go
18
cmd.go
@ -8,6 +8,7 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"os"
|
||||
"protomolecule/src/eros"
|
||||
// "protomolecule/src/wrath"
|
||||
projVars "protomolecule/src/vars"
|
||||
"strings"
|
||||
)
|
||||
@ -31,10 +32,10 @@ var suggestions = []cli.Suggest{
|
||||
|
||||
{"eros recall all",
|
||||
"Retrieve info on all devices"},
|
||||
/*
|
||||
{"",
|
||||
""},
|
||||
*/
|
||||
/*
|
||||
{"wrath",
|
||||
"attack by address"},
|
||||
*/
|
||||
{"exit",
|
||||
"Exit ProtoMolecule"},
|
||||
|
||||
@ -230,6 +231,15 @@ func executor(cmd string) {
|
||||
getHelp(getArgs(args))
|
||||
}
|
||||
|
||||
/*
|
||||
case "wrath":
|
||||
if len(args) < 2 {
|
||||
getHelp("wrath")
|
||||
return
|
||||
}
|
||||
wrath(args[1])
|
||||
*/
|
||||
|
||||
case "clear":
|
||||
print("\033[H\033[2J")
|
||||
//termenv.ClearScreen()
|
||||
|
1
go.mod
1
go.mod
@ -16,4 +16,5 @@ require (
|
||||
github.com/stretchr/testify v1.7.0 // indirect
|
||||
golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||
tinygo.org/x/bluetooth v0.3.0
|
||||
)
|
||||
|
3
go.sum
3
go.sum
@ -255,6 +255,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
@ -415,4 +416,6 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
tinygo.org/x/bluetooth v0.3.0 h1:xy6f1aCAA5VzaXcx+qs4od6ZpiNu6pa/ufnZP7Db2ss=
|
||||
tinygo.org/x/bluetooth v0.3.0/go.mod h1:zg3FxlQIY6vtbtpK5dU8h5BzQiLoE3hGthXTR0GNEn0=
|
||||
tinygo.org/x/drivers v0.15.1/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
||||
|
1
main.go
1
main.go
@ -106,6 +106,7 @@ func init() {
|
||||
// Initializing an instance of our scan manager to keep track of concurrent scans
|
||||
// NOTE: Devices are kept track of per Scan via a nested map of eros.Device instances
|
||||
//
|
||||
|
||||
// TODO: Get all of this management stuff into its own package (structs and maps and initialization of the former)
|
||||
// TODO: Name these structs and maps and instances more uniformly and idiomatically
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
package wrath
|
||||
|
||||
import (
|
||||
projVars "protomolecule/src/vars"
|
||||
|
||||
bluetooth "git.tcp.direct/kayos/prototooth"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/rs/zerolog"
|
||||
projVars "protomolecule/src/vars"
|
||||
"tinygo.org/x/bluetooth/rawterm"
|
||||
)
|
||||
|
||||
@ -33,7 +34,9 @@ func targetPicture() bluetooth.MAC {
|
||||
}
|
||||
*/
|
||||
|
||||
func wrath(bluetooth.Address) {
|
||||
func Start() {
|
||||
|
||||
var sublog zerolog.Logger
|
||||
|
||||
//bluetooth.DefaultAdapter.Connect(targetPicture(), bluetooth.ConnectionParams{})
|
||||
|
||||
@ -42,53 +45,57 @@ func wrath(bluetooth.Address) {
|
||||
// Enable BLE interface.
|
||||
err := projVars.ScanAdapter.Enable()
|
||||
if err != nil {
|
||||
println("could not enable the BLE stack:", err.Error())
|
||||
log.Error().
|
||||
Err(err).
|
||||
Msg("could not enable the BLE stack")
|
||||
return
|
||||
}
|
||||
|
||||
// The address to connect to. Set during scanning and read afterwards.
|
||||
var foundDevice bluetooth.ScanResult
|
||||
// Scan for NUS peripheral.
|
||||
println("Scanning...")
|
||||
err = projVars.ScanAdapter.Scan(func(adapter *bluetooth.Adapter, result bluetooth.ScanResult) {
|
||||
if !result.AdvertisementPayload.HasServiceUUID() {
|
||||
log.Info().Msg("Scanning...")
|
||||
err = projVars.ScanAdapter.Scan(func(adapter *bluetooth.Adapter, foundDevice bluetooth.ScanResult) {
|
||||
if !foundDevice.AdvertisementPayload.HasServiceUUID() {
|
||||
return
|
||||
}
|
||||
foundDevice = result
|
||||
|
||||
// Stop the scan.
|
||||
err := adapter.StopScan()
|
||||
err := projVars.ScanAdapter.StopScan()
|
||||
if err != nil {
|
||||
// Unlikely, but we can't recover from this.
|
||||
println("failed to stop the scan:", err.Error())
|
||||
log.Error().Err(err).
|
||||
Msg("failed to stop scan")
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
println("could not start a scan:", err.Error())
|
||||
log.Error().Err(err).
|
||||
Msg("failed to start scan")
|
||||
return
|
||||
}
|
||||
|
||||
// Found a device: print this event.
|
||||
if name := foundDevice.LocalName(); name == "" {
|
||||
print("Connecting to ", foundDevice.Address.String(), "...")
|
||||
println()
|
||||
sublog = log.With().Str("MAC", foundDevice.Address.String()).Logger()
|
||||
} else {
|
||||
print("Connecting to ", name, " (", foundDevice.Address.String(), ")...")
|
||||
println()
|
||||
sublog = log.With().Str("MAC", foundDevice.Address.String()).
|
||||
Str("Name", foundDevice.LocalName()).Logger()
|
||||
}
|
||||
|
||||
// Found a NUS peripheral. Connect to it.
|
||||
device, err := adapter.Connect(foundDevice.Address, bluetooth.ConnectionParams{})
|
||||
device, err := projVars.ScanAdapter.Connect(foundDevice.Address, bluetooth.ConnectionParams{})
|
||||
if err != nil {
|
||||
println("Failed to connect:", err.Error())
|
||||
sublog.Error().Err(err).
|
||||
Msg("Failed to connect")
|
||||
return
|
||||
}
|
||||
|
||||
// Connected. Look up the Nordic UART Service.
|
||||
println("Discovering service...")
|
||||
sublog.Info().Msg("Discovering services...")
|
||||
services, err := device.DiscoverServices([]bluetooth.UUID{serviceUUID})
|
||||
if err != nil {
|
||||
println("Failed to discover the Nordic UART Service:", err.Error())
|
||||
log.Error().Err(err).
|
||||
Msg("Failed to discover the Nordic UART Service")
|
||||
return
|
||||
}
|
||||
service := services[0]
|
||||
@ -96,7 +103,8 @@ func wrath(bluetooth.Address) {
|
||||
// Get the two characteristics present in this service.
|
||||
chars, err := service.DiscoverCharacteristics([]bluetooth.UUID{rxUUID, txUUID})
|
||||
if err != nil {
|
||||
println("Failed to discover RX and TX characteristics:", err.Error())
|
||||
log.Error().Err(err).
|
||||
Msg("Failed to discover RX and TX characteristics")
|
||||
return
|
||||
}
|
||||
rx := chars[0]
|
||||
@ -109,11 +117,12 @@ func wrath(bluetooth.Address) {
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
println("Failed to enable TX notifications:", err.Error())
|
||||
sublog.Error().Err(err).
|
||||
Msg("Failed to enable TX notifications")
|
||||
return
|
||||
}
|
||||
|
||||
println("Connected. Exit console using Ctrl-X.")
|
||||
sublog.Info().Msg("Connected. Exit console using Ctrl-X.")
|
||||
rawterm.Configure()
|
||||
defer rawterm.Restore()
|
||||
var line []byte
|
||||
@ -142,7 +151,8 @@ func wrath(bluetooth.Address) {
|
||||
// This performs a "write command" aka "write without response".
|
||||
_, err := rx.WriteWithoutResponse(part)
|
||||
if err != nil {
|
||||
println("could not send:", err.Error())
|
||||
sublog.Error().Err(err).
|
||||
Msg("could not send:")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user