forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalr.go
51 lines (47 loc) · 1.54 KB
/
alr.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
package nmea
const (
// TypeALR type for ALR sentences
TypeALR = "ALR"
)
// ALR set alarm state
// http://aprs.gids.nl/nmea/#hdt
type ALR struct {
BaseSentence `mapstructure:"-,omitempty" json:"base_sentence,omitempty"`
Time Time `mapstructure:"-,omitempty" json:"time,omitempty"` // time of alarm condition change, UTC
ID string `mapstructure:"id,omitempty" json:"id,omitempty"` // unique alarm number (identifier) at alarm source
Condition string `mapstructure:"condition,omitempty" json:"condition,omitempty"` // alarm condition
ACK string `mapstructure:"ack,omitempty" json:"ack,omitempty"` // alarm acknowledge state A=acknowledged, V=unacknowledged
Text string `mapstructure:"text,omitempty" json:"text,omitempty"` // alarm's description text
}
func (s ALR) ToMap() (map[string]interface{}, error) {
m := map[string]interface{}{
"time": s.Time.String(),
"time_valid": s.Time.Valid,
"id": s.ID,
"condition": s.Condition,
"ack": s.ACK,
"text": s.Text,
}
bm, err := s.BaseSentence.toMap()
if err != nil {
return m, err
}
for k, v := range bm {
m[k] = v
}
return m, nil
}
// newALR constructor
func newALR(s BaseSentence) (ALR, error) {
p := NewParser(s)
p.AssertType(TypeALR)
m := ALR{
BaseSentence: s,
Time: p.Time(0, "Time"),
ID: p.String(1, "ID"),
Condition: p.String(2, "Condition"),
ACK: p.String(3, "ACK"),
Text: p.String(4, "Text"),
}
return m, p.Err()
}