Skip to content

Commit

Permalink
Add gw.UplinkRXInfo and *gw.UplinkTXInfo to json_v3 marshaling.
Browse files Browse the repository at this point in the history
This makes it possible again to use the PostgreSQL integration with the
json_v3 marshaler. Please note that it is recommeded to use the json
marshaler.
  • Loading branch information
brocaar committed Jul 12, 2021
1 parent 4fd63e4 commit 7bd8c3c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions internal/integration/marshaler/marshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
log "github.com/sirupsen/logrus"

"github.com/brocaar/chirpstack-api/go/v3/as/integration"
"github.com/brocaar/chirpstack-api/go/v3/gw"
"github.com/brocaar/chirpstack-application-server/internal/integration/models"
"github.com/brocaar/chirpstack-application-server/internal/storage"
"github.com/brocaar/lorawan"
Expand Down Expand Up @@ -80,6 +81,10 @@ func marshalJSONV3(msg proto.Message) ([]byte, error) {
return jsonv3MarshalTxAckEvent(v)
case *integration.IntegrationEvent:
return jsonv3MarshalIntegrationEvent(v)
case *gw.UplinkRXInfo:
return jsonv3MarshalUplinkRXInfo(v)
case *gw.UplinkTXInfo:
return jsonv3MarshalUplinkTXInfo(v)
default:
return nil, fmt.Errorf("unknown message type: %T", msg)
}
Expand Down Expand Up @@ -154,6 +159,43 @@ func jsonv3MarshalUplinkEvent(msg *integration.UplinkEvent) ([]byte, error) {
return json.Marshal(m)
}

func jsonv3MarshalUplinkRXInfo(msg *gw.UplinkRXInfo) ([]byte, error) {
rxInfo := models.RXInfo{
RSSI: int(msg.Rssi),
LoRaSNR: float64(msg.LoraSnr),
}

copy(rxInfo.GatewayID[:], msg.GatewayId)
copy(rxInfo.UplinkID[:], msg.UplinkId)

if msg.Time != nil {
t, err := ptypes.Timestamp(msg.Time)
if err == nil {
rxInfo.Time = &t
}
}

if msg.Location != nil {
rxInfo.Location = &models.Location{
Latitude: msg.Location.Latitude,
Longitude: msg.Location.Longitude,
Altitude: msg.Location.Altitude,
}
}

if gw, err := storage.GetGateway(context.Background(), storage.DB(), rxInfo.GatewayID, false); err == nil {
rxInfo.Name = gw.Name
}

return json.Marshal(rxInfo)
}

func jsonv3MarshalUplinkTXInfo(msg *gw.UplinkTXInfo) ([]byte, error) {
return json.Marshal(models.TXInfo{
Frequency: int(msg.Frequency),
})
}

func jsonv3MarshalJoinEvent(msg *integration.JoinEvent) ([]byte, error) {
m := models.JoinNotification{
ApplicationID: int64(msg.ApplicationId),
Expand Down

0 comments on commit 7bd8c3c

Please sign in to comment.