Skip to content

Commit

Permalink
ns: Add LastBatteryPercentage to the ApplicationUplink message
Browse files Browse the repository at this point in the history
  • Loading branch information
halimi committed Dec 18, 2024
1 parent 9d6e011 commit 3ddac1b
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions pkg/networkserver/grpc_gsns.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,18 @@ const (
initialDeduplicationRound = iota
)

func lastBatteryPercentage(dev *ttnpb.EndDevice) *ttnpb.LastBatteryPercentage {
if dev.MacState == nil || dev.BatteryPercentage == nil || dev.LastDevStatusReceivedAt == nil {
return nil
}

return &ttnpb.LastBatteryPercentage{
FCnt: dev.MacState.LastDevStatusFCntUp,
Value: dev.BatteryPercentage,
ReceivedAt: dev.LastDevStatusReceivedAt,
}
}

func (ns *NetworkServer) handleDataUplink(ctx context.Context, up *ttnpb.UplinkMessage) (err error) {
defer trace.StartRegion(ctx, "handle data uplink").End()

Expand Down Expand Up @@ -1141,17 +1153,18 @@ func (ns *NetworkServer) handleDataUplink(ctx context.Context, up *ttnpb.UplinkM
CorrelationIds: up.CorrelationIds,
Up: &ttnpb.ApplicationUp_UplinkMessage{
UplinkMessage: &ttnpb.ApplicationUplink{
Confirmed: up.Payload.MHdr.MType == ttnpb.MType_CONFIRMED_UP,
FCnt: pld.FullFCnt,
FPort: pld.FPort,
FrmPayload: frmPayload,
RxMetadata: up.RxMetadata,
SessionKeyId: stored.Session.Keys.SessionKeyId,
Settings: up.Settings,
ReceivedAt: up.ReceivedAt,
ConsumedAirtime: up.ConsumedAirtime,
PacketErrorRate: mac.LossRate(stored.MacState, matched.phy),
NetworkIds: ns.networkIdentifiers(ctx),
Confirmed: up.Payload.MHdr.MType == ttnpb.MType_CONFIRMED_UP,
FCnt: pld.FullFCnt,
FPort: pld.FPort,
FrmPayload: frmPayload,
RxMetadata: up.RxMetadata,
SessionKeyId: stored.Session.Keys.SessionKeyId,
Settings: up.Settings,
ReceivedAt: up.ReceivedAt,
ConsumedAirtime: up.ConsumedAirtime,
PacketErrorRate: mac.LossRate(stored.MacState, matched.phy),
NetworkIds: ns.networkIdentifiers(ctx),
LastBatteryPercentage: lastBatteryPercentage(stored),
},
},
})
Expand Down

0 comments on commit 3ddac1b

Please sign in to comment.