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

@ -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
}