-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-tinygo.go
69 lines (51 loc) · 3.15 KB
/
run-tinygo.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
68
69
//go:build tinygo
package hub
import (
"bytes"
"encoding/json"
"time"
"github.com/merliot/hub/tinynet"
)
var paramsMem = []byte("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
var root *device
func Run(maker Maker) {
var params uf2ParamsBlock
// wait a bit for serial
time.Sleep(2 * time.Second)
end := bytes.IndexByte(paramsMem, 0)
if err := json.Unmarshal(paramsMem[:end], ¶ms); err != nil {
panic(err)
}
if params.MagicStart != uf2Magic || params.MagicEnd != uf2Magic {
panic("UF2 magic incorrect")
}
tinynet.NetConnect(params.Ssid, params.Passphrase)
root = &device{
Id: params.Id,
Model: params.Model,
Name: params.Name,
DeployParams: params.DeployParams,
}
if err := root.build(maker); err != nil {
panic(err)
}
root.Set(flagOnline | flagMetal)
if err := root.Setup(); err != nil {
panic(err)
}
dialParents(params.DialURLs, params.User, params.Passwd)
// Poll right away and then on ticker
root.Lock()
root.Poll(&Packet{Dst: root.Id})
root.Unlock()
ticker := time.NewTicker(root.PollPeriod)
defer ticker.Stop()
for {
select {
case <-ticker.C:
root.Lock()
root.Poll(&Packet{Dst: root.Id})
root.Unlock()
}
}
}