Skip to content

Commit

Permalink
Handle TX_ACK with nil payload (no error).
Browse files Browse the repository at this point in the history
  • Loading branch information
brocaar committed Dec 12, 2017
1 parent 485fbe8 commit 555c46f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gateway/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ func (b *Backend) handleTXACK(addr *net.UDPAddr, data []byte) error {
if p.Payload != nil {
txAck := newTXAckFromTXPKACK(p.GatewayMAC, p.RandomToken, p.Payload.TXPKACK)
b.txAckChan <- txAck
} else {
b.txAckChan <- gw.TXAck{
MAC: p.GatewayMAC,
Token: p.RandomToken,
}
}

return nil
Expand Down
61 changes: 61 additions & 0 deletions gateway/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,67 @@ func TestBackend(t *testing.T) {
})
})

Convey("When sending a TX_ACK packet (no error)", func() {
p := TXACKPacket{
ProtocolVersion: ProtocolVersion2,
RandomToken: 12345,
GatewayMAC: [8]byte{1, 2, 3, 4, 5, 6, 7, 8},
}
b, err := p.MarshalBinary()
So(err, ShouldBeNil)
_, err = gwConn.WriteToUDP(b, backendAddr)
So(err, ShouldBeNil)

Convey("Then the ack is returned by the ack channel", func() {
ack := <-backend.TXAckChan()
So(ack, ShouldResemble, gw.TXAck{MAC: p.GatewayMAC, Token: p.RandomToken})
})
})

Convey("When sending a TX_ACK packet (with error)", func() {
p := TXACKPacket{
ProtocolVersion: ProtocolVersion2,
RandomToken: 12345,
GatewayMAC: [8]byte{1, 2, 3, 4, 5, 6, 7, 8},
Payload: &TXACKPayload{
TXPKACK: TXPKACK{
Error: gw.ErrGPSUnlocked,
},
},
}
b, err := p.MarshalBinary()
So(err, ShouldBeNil)
_, err = gwConn.WriteToUDP(b, backendAddr)
So(err, ShouldBeNil)

Convey("Then the ack is returned by the ack channel", func() {
ack := <-backend.TXAckChan()
So(ack, ShouldResemble, gw.TXAck{MAC: p.GatewayMAC, Token: p.RandomToken, Error: gw.ErrGPSUnlocked})
})
})

Convey("When sending a TX_ACK packet (with error 'NONE')", func() {
p := TXACKPacket{
ProtocolVersion: ProtocolVersion2,
RandomToken: 12345,
GatewayMAC: [8]byte{1, 2, 3, 4, 5, 6, 7, 8},
Payload: &TXACKPayload{
TXPKACK: TXPKACK{
Error: "NONE",
},
},
}
b, err := p.MarshalBinary()
So(err, ShouldBeNil)
_, err = gwConn.WriteToUDP(b, backendAddr)
So(err, ShouldBeNil)

Convey("Then the ack is returned by the ack channel", func() {
ack := <-backend.TXAckChan()
So(ack, ShouldResemble, gw.TXAck{MAC: p.GatewayMAC, Token: p.RandomToken})
})
})

Convey("When sending a PUSH_DATA packet with stats", func() {
p := PushDataPacket{
ProtocolVersion: ProtocolVersion2,
Expand Down

0 comments on commit 555c46f

Please sign in to comment.