Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
htdvisser committed Feb 7, 2017
2 parents e976838 + 5df4b88 commit 8ed4769
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 11 deletions.
9 changes: 5 additions & 4 deletions api/broker/client_streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/TheThingsNetwork/go-utils/log"
"github.com/TheThingsNetwork/ttn/api/fields"
"github.com/TheThingsNetwork/ttn/utils/backoff"
"github.com/golang/protobuf/ptypes/empty"
"golang.org/x/net/context"
Expand Down Expand Up @@ -83,7 +84,7 @@ func NewMonitoredRouterStream(client BrokerClient, getContextFunc func() context
for {
message, err := client.Recv()
if message != nil {
s.ctx.Debug("Receiving Downlink message")
s.ctx.WithFields(fields.Get(message)).Debug("Receiving Downlink message")
if err := message.Validate(); err != nil {
s.ctx.WithError(err).Warn("Invalid Downlink")
continue
Expand All @@ -108,7 +109,7 @@ func NewMonitoredRouterStream(client BrokerClient, getContextFunc func() context
// Send uplink
go func() {
for message := range up {
s.ctx.Debug("Sending Uplink message")
s.ctx.WithFields(fields.Get(message)).Debug("Sending Uplink message")
if err := client.Send(message); err != nil {
s.ctx.WithError(err).Warn("Error sending Uplink message")
break
Expand Down Expand Up @@ -237,7 +238,7 @@ func NewMonitoredHandlerPublishStream(client BrokerClient, getContextFunc func()
// Send
go func() {
for message := range ch {
s.ctx.Debug("Sending Downlink message")
s.ctx.WithFields(fields.Get(message)).Debug("Sending Downlink message")
if err := client.Send(message); err != nil {
s.ctx.WithError(err).Warn("Error sending Downlink message")
break
Expand Down Expand Up @@ -351,7 +352,7 @@ func NewMonitoredHandlerSubscribeStream(client BrokerClient, getContextFunc func
for {
message, err = client.Recv()
if message != nil {
s.ctx.Debug("Receiving Uplink message")
s.ctx.WithFields(fields.Get(message)).Debug("Receiving Uplink message")
if err := message.Validate(); err != nil {
s.ctx.WithError(err).Warn("Invalid Uplink")
continue
Expand Down
16 changes: 12 additions & 4 deletions api/fields/log_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ func fillProtocol(m interface{}, f log.Fields) {
}
}
if m, ok := m.(hasProtocolConfiguration); ok {
fillProtocolConfig(m.GetProtocolConfiguration(), f)
if cfg := m.GetProtocolConfiguration(); cfg != nil {
fillProtocolConfig(cfg, f)
}
}
if m, ok := m.(hasProtocolConfig); ok {
fillProtocolConfig(m.GetProtocolConfig(), f)
if cfg := m.GetProtocolConfig(); cfg != nil {
fillProtocolConfig(cfg, f)
}
}
}

Expand Down Expand Up @@ -183,10 +187,14 @@ func fillGateway(m interface{}, f log.Fields) {
}
}
if m, ok := m.(hasGatewayConfiguration); ok {
fillGatewayConfig(m.GetGatewayConfiguration(), f)
if cfg := m.GetGatewayConfiguration(); cfg != nil {
fillGatewayConfig(cfg, f)
}
}
if m, ok := m.(hasGatewayConfig); ok {
fillGatewayConfig(m.GetGatewayConfig(), f)
if cfg := m.GetGatewayConfig(); cfg != nil {
fillGatewayConfig(cfg, f)
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions api/router/client_streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/TheThingsNetwork/go-utils/log"
"github.com/TheThingsNetwork/ttn/api/fields"
"github.com/TheThingsNetwork/ttn/api/gateway"
"github.com/TheThingsNetwork/ttn/utils/backoff"
"github.com/golang/protobuf/ptypes/empty"
Expand Down Expand Up @@ -211,7 +212,7 @@ func NewMonitoredUplinkStream(client RouterClientForGateway) UplinkStream {
// Send
go func() {
for message := range ch {
s.ctx.Debug("Sending Uplink message")
s.ctx.WithFields(fields.Get(message)).Debug("Sending Uplink message")
if err := client.Send(message); err != nil {
s.ctx.WithError(err).Warn("Error sending Uplink message")
break
Expand Down Expand Up @@ -332,7 +333,7 @@ func NewMonitoredDownlinkStream(client RouterClientForGateway) DownlinkStream {
for {
message, err = client.Recv()
if message != nil {
s.ctx.Debug("Receiving Downlink message")
s.ctx.WithFields(fields.Get(message)).Debug("Receiving Downlink message")
if err := message.Validate(); err != nil {
s.ctx.WithError(err).Warn("Invalid Downlink")
continue
Expand Down
3 changes: 3 additions & 0 deletions core/handler/downlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ func (h *handler) HandleDownlink(appDownlink *types.DownlinkMessage, downlink *p
}
}

downlink.Message = nil
downlink.UnmarshalPayload()

h.status.downlink.Mark(1)

ctx.Debug("Send Downlink")
Expand Down
10 changes: 10 additions & 0 deletions core/networkserver/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,15 @@ func (n *networkServer) HandleActivate(activation *pb_handler.DeviceActivationRe
if err != nil {
return nil, err
}

frames, err := n.devices.Frames(dev.AppEUI, dev.DevEUI)
if err != nil {
return nil, err
}
err = frames.Clear()
if err != nil {
return nil, err
}

return activation, nil
}
2 changes: 1 addition & 1 deletion core/networkserver/adr.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (n *networkServer) handleDownlinkADR(message *pb_broker.DownlinkMessage, de
powerIdx, _ = fp.GetTxPowerIndexFor(fp.DefaultTXPower)
}

if dev.ADR.DataRate == dataRate && dev.ADR.TxPower == txPower {
if dev.ADR.DataRate == dataRate && dev.ADR.TxPower == txPower && !dev.Options.DisableFCntCheck {
lossPercentage := lossPercentage(frames)
switch {
case lossPercentage <= 5:
Expand Down
9 changes: 9 additions & 0 deletions core/networkserver/manager_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ func (n *networkServerManager) SetDevice(ctx context.Context, in *pb_lorawan.Dev
return nil, err
}

frames, err := n.networkServer.devices.Frames(dev.AppEUI, dev.DevEUI)
if err != nil {
return nil, err
}
err = frames.Clear()
if err != nil {
return nil, err
}

return &empty.Empty{}, nil
}

Expand Down

0 comments on commit 8ed4769

Please sign in to comment.