misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2019-02-14 11:06:05 +01:00
commit 7f68d0d82c
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
4 changed files with 19 additions and 19 deletions

View file

@ -115,7 +115,7 @@ func (mod *BLERecon) Configure() (err error) {
if mod.Running() {
return session.ErrAlreadyStarted
} else if mod.gattDevice == nil {
mod.Info("Initializing BLE device ...")
mod.Info("initializing device ...")
// hey Paypal GATT library, could you please just STFU?!
golog.SetOutput(ioutil.Discard)
@ -145,7 +145,7 @@ func (mod *BLERecon) Start() error {
<-mod.quit
mod.Info("Stopping BLE scan ...")
mod.Info("stopping scan ...")
mod.gattDevice.StopScanning()
@ -161,7 +161,7 @@ func (mod *BLERecon) Stop() error {
}
func (mod *BLERecon) pruner() {
mod.Debug("Started BLE devices pruner ...")
mod.Debug("started devices pruner ...")
for mod.Running() {
for _, dev := range mod.Session.BLE.Devices() {
@ -198,7 +198,7 @@ func (mod *BLERecon) enumAllTheThings(mac string) error {
return err
}
mod.Info("Connecting to %s ...", mac)
mod.Info("connecting to %s ...", mac)
go func() {
time.Sleep(mod.connTimeout)

View file

@ -8,19 +8,19 @@ import (
)
func (mod *BLERecon) onStateChanged(dev gatt.Device, s gatt.State) {
mod.Info("BLE state changed to %v", s)
mod.Info("state changed to %v", s)
switch s {
case gatt.StatePoweredOn:
if mod.currDevice == nil {
mod.Info("Starting BLE discovery ...")
mod.Info("starting discovery ...")
dev.Scan([]gatt.UUID{}, true)
}
case gatt.StatePoweredOff:
mod.gattDevice = nil
default:
mod.Warning("Unexpected BLE state: %v", s)
mod.Warning("unexpected state: %v", s)
}
}
@ -31,7 +31,7 @@ func (mod *BLERecon) onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement
func (mod *BLERecon) onPeriphDisconnected(p gatt.Peripheral, err error) {
if mod.Running() {
// restore scanning
mod.Info("Device disconnected, restoring BLE discovery.")
mod.Info("device disconnected, restoring discovery.")
mod.setCurrentDevice(nil)
mod.gattDevice.Scan([]gatt.UUID{}, true)
}
@ -39,31 +39,31 @@ func (mod *BLERecon) onPeriphDisconnected(p gatt.Peripheral, err error) {
func (mod *BLERecon) onPeriphConnected(p gatt.Peripheral, err error) {
if err != nil {
mod.Warning("Connected to %s but with error: %s", p.ID(), err)
mod.Warning("connected to %s but with error: %s", p.ID(), err)
return
} else if mod.currDevice == nil {
// timed out
mod.Warning("Connected to %s but after the timeout :(", p.ID())
mod.Warning("connected to %s but after the timeout :(", p.ID())
return
}
mod.connected = true
defer func(per gatt.Peripheral) {
mod.Info("Disconnecting from %s ...", per.ID())
mod.Info("disconnecting from %s ...", per.ID())
per.Device().CancelConnection(per)
}(p)
mod.Session.Events.Add("ble.device.connected", mod.currDevice)
if err := p.SetMTU(500); err != nil {
mod.Warning("Failed to set MTU: %s", err)
mod.Warning("failed to set MTU: %s", err)
}
mod.Info("Connected, enumerating all the things for %s!", p.ID())
mod.Info("connected, enumerating all the things for %s!", p.ID())
services, err := p.DiscoverServices(nil)
if err != nil {
mod.Error("Error discovering services: %s", err)
mod.Error("error discovering services: %s", err)
return
}

View file

@ -228,7 +228,7 @@ func (mod *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
chars, err := p.DiscoverCharacteristics(nil, svc)
if err != nil {
mod.Error("Error while enumerating chars for service %s: %s", svc.UUID(), err)
mod.Error("error while enumerating chars for service %s: %s", svc.UUID(), err)
continue
}
@ -247,14 +247,14 @@ func (mod *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
if wantsToWrite && mod.writeUUID.Equal(ch.UUID()) {
foundToWrite = true
if isWritable {
mod.Info("Writing %d bytes to characteristics %s ...", len(mod.writeData), mod.writeUUID)
mod.Info("writing %d bytes to characteristics %s ...", len(mod.writeData), mod.writeUUID)
} else {
mod.Warning("Attempt to write %d bytes to non writable characteristics %s ...", len(mod.writeData), mod.writeUUID)
mod.Warning("attempt to write %d bytes to non writable characteristics %s ...", len(mod.writeData), mod.writeUUID)
}
err := p.WriteCharacteristic(ch, mod.writeData, !withResponse)
if err != nil {
mod.Error("Error while writing: %s", err)
mod.Error("error while writing: %s", err)
}
}
@ -280,7 +280,7 @@ func (mod *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
}
if wantsToWrite && !foundToWrite {
mod.Error("Writable characteristics %s not found.", mod.writeUUID)
mod.Error("writable characteristics %s not found.", mod.writeUUID)
} else {
tui.Table(os.Stdout, columns, rows)
mod.Session.Refresh()