diff options
Diffstat (limited to 'inform/tx_messages.go')
-rw-r--r-- | inform/tx_messages.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/inform/tx_messages.go b/inform/tx_messages.go index 0021ef3..8962cad 100644 --- a/inform/tx_messages.go +++ b/inform/tx_messages.go | |||
@@ -25,8 +25,15 @@ type CommandMessage struct { | |||
25 | Voltage int `json:"volt,omitempty"` | 25 | Voltage int `json:"volt,omitempty"` |
26 | } | 26 | } |
27 | 27 | ||
28 | func NewOutputCommand(port, val, timer int) *CommandMessage { | 28 | // Freshen timestamps |
29 | return &CommandMessage{ | 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{ | ||
30 | Type: "cmd", | 37 | Type: "cmd", |
31 | Command: "mfi-output", | 38 | Command: "mfi-output", |
32 | DateTime: time.Now().Format(time.RFC3339), | 39 | DateTime: time.Now().Format(time.RFC3339), |
@@ -34,8 +41,15 @@ func NewOutputCommand(port, val, timer int) *CommandMessage { | |||
34 | ServerTime: unixMicroPSTString(), | 41 | ServerTime: unixMicroPSTString(), |
35 | Time: unixMicroPST(), | 42 | Time: unixMicroPST(), |
36 | Timer: timer, | 43 | Timer: timer, |
37 | Value: val, | ||
38 | } | 44 | } |
45 | |||
46 | if val { | ||
47 | m.Value = 1 | ||
48 | } else { | ||
49 | m.Value = 0 | ||
50 | } | ||
51 | |||
52 | return m | ||
39 | } | 53 | } |
40 | 54 | ||
41 | type NoopMessage struct { | 55 | type NoopMessage struct { |