forked from brocaar/chirpstack-application-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
123 lines (110 loc) · 4.29 KB
/
models.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package handler
import (
"encoding/gob"
"encoding/json"
"time"
"github.com/brocaar/lorawan"
)
func init() {
gob.Register(DataUpPayload{})
gob.Register(JoinNotification{})
gob.Register(ACKNotification{})
gob.Register(ErrorNotification{})
gob.Register(StatusNotification{})
gob.Register(LocationNotification{})
}
// Location details.
type Location struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Altitude float64 `json:"altitude"`
}
// RXInfo contains the RX information.
type RXInfo struct {
GatewayID lorawan.EUI64 `json:"gatewayID"`
Name string `json:"name"`
Time *time.Time `json:"time,omitempty"`
RSSI int `json:"rssi"`
LoRaSNR float64 `json:"loRaSNR"`
Location *Location `json:"location"`
}
// TXInfo contains the TX information.
type TXInfo struct {
Frequency int `json:"frequency"`
DR int `json:"dr"`
}
// DataUpPayload represents a data-up payload.
type DataUpPayload struct {
ApplicationID int64 `json:"applicationID,string"`
ApplicationName string `json:"applicationName"`
DeviceName string `json:"deviceName"`
DevEUI lorawan.EUI64 `json:"devEUI"`
RXInfo []RXInfo `json:"rxInfo,omitempty"`
TXInfo TXInfo `json:"txInfo"`
ADR bool `json:"adr"`
FCnt uint32 `json:"fCnt"`
FPort uint8 `json:"fPort"`
Data []byte `json:"data"`
Object interface{} `json:"object,omitempty"`
}
// DataDownPayload represents a data-down payload.
type DataDownPayload struct {
ApplicationID int64 `json:"applicationID,string"`
DevEUI lorawan.EUI64 `json:"devEUI"`
Confirmed bool `json:"confirmed"`
FPort uint8 `json:"fPort"`
Data []byte `json:"data"`
Object json.RawMessage `json:"object"`
}
// JoinNotification defines the payload sent to the application on
// a JoinNotificationType event.
type JoinNotification struct {
ApplicationID int64 `json:"applicationID,string"`
ApplicationName string `json:"applicationName"`
DeviceName string `json:"deviceName"`
DevEUI lorawan.EUI64 `json:"devEUI"`
DevAddr lorawan.DevAddr `json:"devAddr"`
}
// ACKNotification defines the payload sent to the application
// on an ACK event.
type ACKNotification struct {
ApplicationID int64 `json:"applicationID,string"`
ApplicationName string `json:"applicationName"`
DeviceName string `json:"deviceName"`
DevEUI lorawan.EUI64 `json:"devEUI"`
Acknowledged bool `json:"acknowledged"`
FCnt uint32 `json:"fCnt"`
}
// ErrorNotification defines the payload sent to the application
// on an error event.
type ErrorNotification struct {
ApplicationID int64 `json:"applicationID,string"`
ApplicationName string `json:"applicationName"`
DeviceName string `json:"deviceName"`
DevEUI lorawan.EUI64 `json:"devEUI"`
Type string `json:"type"`
Error string `json:"error"`
FCnt uint32 `json:"fCnt,omitempty"`
}
// StatusNotification defines the payload sent to the application
// on a device-status reporting.
type StatusNotification struct {
ApplicationID int64 `json:"applicationID,string"`
ApplicationName string `json:"applicationName"`
DeviceName string `json:"deviceName"`
DevEUI lorawan.EUI64 `json:"devEUI"`
Battery int `json:"battery"`
Margin int `json:"margin"`
ExternalPowerSource bool `json:"externalPowerSource"`
BatteryLevel float32 `json:"batteryLevel"`
BatteryLevelUnavailable bool `json:"batteryLevelUnavailable"`
}
// LocationNotification defines the payload sent to the application after
// the device location has been resolved by a geolocation-server.
type LocationNotification struct {
ApplicationID int64 `json:"applicationID,string"`
ApplicationName string `json:"applicationName"`
DeviceName string `json:"deviceName"`
DevEUI lorawan.EUI64 `json:"devEUI"`
Location Location `json:"location"`
}