diff options
Diffstat (limited to 'inform/tx_messages.go')
-rw-r--r-- | inform/tx_messages.go | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/inform/tx_messages.go b/inform/tx_messages.go deleted file mode 100644 index 8962cad..0000000 --- a/inform/tx_messages.go +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | package inform | ||
2 | |||
3 | // Messages we send to devices | ||
4 | |||
5 | import ( | ||
6 | "strconv" | ||
7 | "time" | ||
8 | ) | ||
9 | |||
10 | type CommandMessage struct { | ||
11 | Id string `json:"_id,omitempty"` | ||
12 | Type string `json:"_type"` | ||
13 | Command string `json:"cmd"` | ||
14 | DateTime string `json:"datetime"` | ||
15 | DeviceId string `json:"device_id,omitempty"` | ||
16 | MacAddress string `json:"mac,omitempty"` | ||
17 | Model string `json:"model,omitempty"` | ||
18 | OffVoltage int `json:"off_volt,omitempty"` | ||
19 | Port int `json:"port"` | ||
20 | SensorId string `json:"sId,omitempty"` | ||
21 | ServerTime string `json:"server_time_in_utc"` | ||
22 | Time int64 `json:"time"` | ||
23 | Timer int `json:"timer"` | ||
24 | Value int `json:"val"` | ||
25 | Voltage int `json:"volt,omitempty"` | ||
26 | } | ||
27 | |||
28 | // Freshen timestamps | ||
29 | func (m *CommandMessage) Freshen() { | ||
30 | m.DateTime = time.Now().Format(time.RFC3339) | ||
31 | m.ServerTime = unixMicroPSTString() | ||
32 | m.Time = unixMicroPST() | ||
33 | } | ||
34 | |||
35 | func NewOutputCommand(port int, val bool, timer int) *CommandMessage { | ||
36 | m := &CommandMessage{ | ||
37 | Type: "cmd", | ||
38 | Command: "mfi-output", | ||
39 | DateTime: time.Now().Format(time.RFC3339), | ||
40 | Port: port, | ||
41 | ServerTime: unixMicroPSTString(), | ||
42 | Time: unixMicroPST(), | ||
43 | Timer: timer, | ||
44 | } | ||
45 | |||
46 | if val { | ||
47 | m.Value = 1 | ||
48 | } else { | ||
49 | m.Value = 0 | ||
50 | } | ||
51 | |||
52 | return m | ||
53 | } | ||
54 | |||
55 | type NoopMessage struct { | ||
56 | Type string `json:"_type"` | ||
57 | Interval int `json:"interval"` | ||
58 | ServerTimeUTC string `json:"server_time_in_utc"` | ||
59 | } | ||
60 | |||
61 | func unixMicroPST() int64 { | ||
62 | l, _ := time.LoadLocation("America/Los_Angeles") | ||
63 | tnano := time.Now().In(l).UnixNano() | ||
64 | return tnano / int64(time.Millisecond) | ||
65 | } | ||
66 | |||
67 | func unixMicroPSTString() string { | ||
68 | return strconv.FormatInt(unixMicroPST(), 10) | ||
69 | } | ||
70 | |||
71 | func unixMicroUTCString() string { | ||
72 | tnano := time.Now().UTC().UnixNano() | ||
73 | t := tnano / int64(time.Millisecond) | ||
74 | return strconv.FormatInt(t, 10) | ||
75 | } | ||
76 | |||
77 | func NewNoop(interval int) *NoopMessage { | ||
78 | return &NoopMessage{ | ||
79 | Type: "noop", | ||
80 | Interval: interval, | ||
81 | ServerTimeUTC: unixMicroUTCString(), | ||
82 | } | ||
83 | } | ||