/
ble_show_sort.go
33 lines (25 loc) · 961 Bytes
/
ble_show_sort.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// +build !windows
// +build !darwin
package ble
import (
"github.com/bettercap/bettercap/network"
)
type ByBLERSSISorter []*network.BLEDevice
func (a ByBLERSSISorter) Len() int { return len(a) }
func (a ByBLERSSISorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByBLERSSISorter) Less(i, j int) bool {
if a[i].RSSI == a[j].RSSI {
return a[i].Device.ID() < a[j].Device.ID()
}
return a[i].RSSI > a[j].RSSI
}
type ByBLEMacSorter []*network.BLEDevice
func (a ByBLEMacSorter) Len() int { return len(a) }
func (a ByBLEMacSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByBLEMacSorter) Less(i, j int) bool {
return a[i].Device.ID() < a[j].Device.ID()
}
type ByBLESeenSorter []*network.BLEDevice
func (a ByBLESeenSorter) Len() int { return len(a) }
func (a ByBLESeenSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByBLESeenSorter) Less(i, j int) bool { return a[i].LastSeen.Before(a[j].LastSeen) }