Skip to content

Commit

Permalink
Parse optional 'meta' in Stat.
Browse files Browse the repository at this point in the history
  • Loading branch information
brocaar committed Dec 6, 2022
1 parent 2f0d5b7 commit 2ef079d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
22 changes: 12 additions & 10 deletions internal/backend/semtechudp/packets/push_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (p PushDataPacket) GetGatewayStats() (*gw.GatewayStats, error) {
RxPacketsReceivedOk: p.Payload.Stat.RXOK,
TxPacketsEmitted: p.Payload.Stat.TXNb,
TxPacketsReceived: p.Payload.Stat.DWNb,
Metadata: p.Payload.Stat.Meta,
}

// time
Expand Down Expand Up @@ -331,16 +332,17 @@ type PushDataPayload struct {

// Stat contains the status of the gateway.
type Stat struct {
Time ExpandedTime `json:"time"` // UTC 'system' time of the gateway, ISO 8601 'expanded' format (e.g 2014-01-12 08:59:28 GMT)
Lati float64 `json:"lati"` // GPS latitude of the gateway in degree (float, N is +)
Long float64 `json:"long"` // GPS latitude of the gateway in degree (float, E is +)
Alti int32 `json:"alti"` // GPS altitude of the gateway in meter RX (integer)
RXNb uint32 `json:"rxnb"` // Number of radio packets received (unsigned integer)
RXOK uint32 `json:"rxok"` // Number of radio packets received with a valid PHY CRC
RXFW uint32 `json:"rxfw"` // Number of radio packets forwarded (unsigned integer)
ACKR float64 `json:"ackr"` // Percentage of upstream datagrams that were acknowledged
DWNb uint32 `json:"dwnb"` // Number of downlink datagrams received (unsigned integer)
TXNb uint32 `json:"txnb"` // Number of packets emitted (unsigned integer)
Time ExpandedTime `json:"time"` // UTC 'system' time of the gateway, ISO 8601 'expanded' format (e.g 2014-01-12 08:59:28 GMT)
Lati float64 `json:"lati"` // GPS latitude of the gateway in degree (float, N is +)
Long float64 `json:"long"` // GPS latitude of the gateway in degree (float, E is +)
Alti int32 `json:"alti"` // GPS altitude of the gateway in meter RX (integer)
RXNb uint32 `json:"rxnb"` // Number of radio packets received (unsigned integer)
RXOK uint32 `json:"rxok"` // Number of radio packets received with a valid PHY CRC
RXFW uint32 `json:"rxfw"` // Number of radio packets forwarded (unsigned integer)
ACKR float64 `json:"ackr"` // Percentage of upstream datagrams that were acknowledged
DWNb uint32 `json:"dwnb"` // Number of downlink datagrams received (unsigned integer)
TXNb uint32 `json:"txnb"` // Number of packets emitted (unsigned integer)
Meta map[string]string `json:"meta"` // Custom meta-data (Optional, not part of PROTOCOL.TXT)
}

// RXPK contain a RF packet and associated metadata.
Expand Down
31 changes: 31 additions & 0 deletions internal/backend/semtechudp/packets/push_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,37 @@ func TestGetGatewayStats(t *testing.T) {
TxPacketsEmitted: 6,
},
},
{
PushDataPacket: PushDataPacket{
ProtocolVersion: ProtocolVersion2,
GatewayMAC: lorawan.EUI64{1, 2, 3, 4, 5, 6, 7, 8},
Payload: PushDataPayload{
Stat: &Stat{
Time: ecNow,
RXNb: 1,
RXOK: 2,
RXFW: 3,
ACKR: 4,
DWNb: 5,
TXNb: 6,
Meta: map[string]string{
"gateway_name": "test-gateway",
},
},
},
},
GatewayStats: &gw.GatewayStats{
GatewayId: "0102030405060708",
Time: pbTime,
RxPacketsReceived: 1,
RxPacketsReceivedOk: 2,
TxPacketsReceived: 5,
TxPacketsEmitted: 6,
Metadata: map[string]string{
"gateway_name": "test-gateway",
},
},
},
}

for _, test := range testTable {
Expand Down

0 comments on commit 2ef079d

Please sign in to comment.