ble_show_sort.go 943 B

1234567891011121314151617181920212223242526272829303132
  1. // +build !windows
  2. package ble
  3. import (
  4. "github.com/bettercap/bettercap/network"
  5. )
  6. type ByBLERSSISorter []*network.BLEDevice
  7. func (a ByBLERSSISorter) Len() int { return len(a) }
  8. func (a ByBLERSSISorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
  9. func (a ByBLERSSISorter) Less(i, j int) bool {
  10. if a[i].RSSI == a[j].RSSI {
  11. return a[i].Device.ID() < a[j].Device.ID()
  12. }
  13. return a[i].RSSI > a[j].RSSI
  14. }
  15. type ByBLEMacSorter []*network.BLEDevice
  16. func (a ByBLEMacSorter) Len() int { return len(a) }
  17. func (a ByBLEMacSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
  18. func (a ByBLEMacSorter) Less(i, j int) bool {
  19. return a[i].Device.ID() < a[j].Device.ID()
  20. }
  21. type ByBLESeenSorter []*network.BLEDevice
  22. func (a ByBLESeenSorter) Len() int { return len(a) }
  23. func (a ByBLESeenSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
  24. func (a ByBLESeenSorter) Less(i, j int) bool { return a[i].LastSeen.Before(a[j].LastSeen) }