Skip to content

Commit b948547

Browse files
committed
Assume lat/lon/alt = 0 means no GPS location is available.
As some gateways leave these fields blank (0), this would constantly overwrite a manual set gateway location in LoRa Server. Closes #126.
1 parent 2877fc6 commit b948547

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

internal/backend/semtechudp/backend_test.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,17 @@ func (ts *BackendTestSuite) TestPushData() {
208208
UplinkFrames []gw.UplinkFrame
209209
}{
210210
{
211-
Name: "stats",
211+
Name: "stats with location",
212212
GatewayPacket: packets.PushDataPacket{
213213
ProtocolVersion: packets.ProtocolVersion2,
214214
RandomToken: 1234,
215215
GatewayMAC: [8]byte{1, 2, 3, 4, 5, 6, 7, 8},
216216
Payload: packets.PushDataPayload{
217217
Stat: &packets.Stat{
218218
Time: packets.ExpandedTime(now.UTC()),
219-
Lati: &latitude,
220-
Long: &longitude,
221-
Alti: &altitude,
219+
Lati: latitude,
220+
Long: longitude,
221+
Alti: altitude,
222222
RXNb: 1,
223223
RXOK: 2,
224224
RXFW: 3,
@@ -243,6 +243,33 @@ func (ts *BackendTestSuite) TestPushData() {
243243
TxPacketsEmitted: 5,
244244
},
245245
},
246+
{
247+
Name: "stats without location",
248+
GatewayPacket: packets.PushDataPacket{
249+
ProtocolVersion: packets.ProtocolVersion2,
250+
RandomToken: 1234,
251+
GatewayMAC: [8]byte{1, 2, 3, 4, 5, 6, 7, 8},
252+
Payload: packets.PushDataPayload{
253+
Stat: &packets.Stat{
254+
Time: packets.ExpandedTime(now.UTC()),
255+
RXNb: 1,
256+
RXOK: 2,
257+
RXFW: 3,
258+
ACKR: 33.3,
259+
DWNb: 4,
260+
TXNb: 5,
261+
},
262+
},
263+
},
264+
Stats: &gw.GatewayStats{
265+
GatewayId: []byte{1, 2, 3, 4, 5, 6, 7, 8},
266+
Time: nowPB,
267+
RxPacketsReceived: 1,
268+
RxPacketsReceivedOk: 2,
269+
TxPacketsReceived: 4,
270+
TxPacketsEmitted: 5,
271+
},
272+
},
246273
{
247274
Name: "rxpk",
248275
GatewayPacket: packets.PushDataPacket{

internal/backend/semtechudp/packets/push_data.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ func (p PushDataPacket) GetGatewayStats() (*gw.GatewayStats, error) {
6666
stats.Time = ts
6767

6868
// location
69-
if p.Payload.Stat.Lati != nil && p.Payload.Stat.Long != nil && p.Payload.Stat.Alti != nil {
69+
if p.Payload.Stat.Lati != 0 && p.Payload.Stat.Long != 0 && p.Payload.Stat.Alti != 0 {
7070
stats.Location = &common.Location{
71-
Latitude: *p.Payload.Stat.Lati,
72-
Longitude: *p.Payload.Stat.Long,
73-
Altitude: float64(*p.Payload.Stat.Alti),
71+
Latitude: p.Payload.Stat.Lati,
72+
Longitude: p.Payload.Stat.Long,
73+
Altitude: float64(p.Payload.Stat.Alti),
7474
Source: common.LocationSource_GPS,
7575
}
7676
}
@@ -241,9 +241,9 @@ type PushDataPayload struct {
241241
// Stat contains the status of the gateway.
242242
type Stat struct {
243243
Time ExpandedTime `json:"time"` // UTC 'system' time of the gateway, ISO 8601 'expanded' format (e.g 2014-01-12 08:59:28 GMT)
244-
Lati *float64 `json:"lati"` // GPS latitude of the gateway in degree (float, N is +)
245-
Long *float64 `json:"long"` // GPS latitude of the gateway in degree (float, E is +)
246-
Alti *int32 `json:"alti"` // GPS altitude of the gateway in meter RX (integer)
244+
Lati float64 `json:"lati"` // GPS latitude of the gateway in degree (float, N is +)
245+
Long float64 `json:"long"` // GPS latitude of the gateway in degree (float, E is +)
246+
Alti int32 `json:"alti"` // GPS altitude of the gateway in meter RX (integer)
247247
RXNb uint32 `json:"rxnb"` // Number of radio packets received (unsigned integer)
248248
RXOK uint32 `json:"rxok"` // Number of radio packets received with a valid PHY CRC
249249
RXFW uint32 `json:"rxfw"` // Number of radio packets forwarded (unsigned integer)

internal/backend/semtechudp/packets/push_data_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ func TestGetGatewayStats(t *testing.T) {
7474
Payload: PushDataPayload{
7575
Stat: &Stat{
7676
Time: ecNow,
77-
Long: &long,
78-
Lati: &lat,
79-
Alti: &alti,
77+
Long: long,
78+
Lati: lat,
79+
Alti: alti,
8080
RXNb: 1,
8181
RXOK: 2,
8282
RXFW: 3,

0 commit comments

Comments
 (0)