-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic_linux.go
67 lines (56 loc) · 1.75 KB
/
logic_linux.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"os"
"time"
)
func (app *App) logic() {
for {
select {
case device := <- app.discovered:
uid := device.Address.String()
sd := &StoredDevice{
UID: uid,
CustomName: "?",
LocalName: device.LocalName(),
}
if len(sd.LocalName) > 0 {
println("skip device:", uid, device.RSSI, device.LocalName(), device.Address.String())
b, err := app.Marshal(sd)
if err != nil {
panic(err)
}
if err := os.WriteFile("./skipped/"+uid, b, 0666); err != nil {
panic(err)
}
continue
}
b, err := os.ReadFile("./seen/"+uid)
if err == nil {
// open existing file
err := app.Unmarshal(b, sd)
if err != nil {
panic(err)
}
sd.Seen++
} else {
println("found device:", uid, device.RSSI, device.LocalName(), device.Address.String())
}
// set correct time on the record
sd.LastSeen = time.Now().UTC()
d := time.Since(sd.LastSeen)
if d > (10 * time.Minute) {
println("THEY HAVE COME BACK TO US", d.String())
}
app.see(uid, sd)
// flush to file
b, err = app.Marshal(sd)
if err != nil {
panic(err)
}
if err := os.WriteFile("seen/"+uid, b, 0666); err != nil {
panic(err)
}
//case <- time.NewTicker(time.Second).C: println("ticker")
}
}
}