本文整理汇总了Golang中github.com/brocaar/lorawan.PHYPayload.DecryptJoinAcceptPayload方法的典型用法代码示例。如果您正苦于以下问题:Golang PHYPayload.DecryptJoinAcceptPayload方法的具体用法?Golang PHYPayload.DecryptJoinAcceptPayload怎么用?Golang PHYPayload.DecryptJoinAcceptPayload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/brocaar/lorawan.PHYPayload
的用法示例。
在下文中一共展示了PHYPayload.DecryptJoinAcceptPayload方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestHandleJoinRequestPackets
func TestHandleJoinRequestPackets(t *testing.T) {
conf := common.GetTestConfig()
Convey("Given a dummy gateway and application backend and a clean Postgres and Redis database", t, func() {
a := &testApplicationBackend{
rxPayloadChan: make(chan models.RXPayload, 1),
notificationPayloadChan: make(chan interface{}, 10),
}
g := &testGatewayBackend{
rxPacketChan: make(chan models.RXPacket, 1),
txPacketChan: make(chan models.TXPacket, 1),
}
p := storage.NewRedisPool(conf.RedisURL)
common.MustFlushRedis(p)
db, err := storage.OpenDatabase(conf.PostgresDSN)
So(err, ShouldBeNil)
common.MustResetDB(db)
ctx := Context{
RedisPool: p,
Gateway: g,
Application: a,
DB: db,
}
Convey("Given a node and application in the database", func() {
app := models.Application{
AppEUI: [8]byte{1, 2, 3, 4, 5, 6, 7, 8},
Name: "test app",
}
So(storage.CreateApplication(ctx.DB, app), ShouldBeNil)
node := models.Node{
DevEUI: [8]byte{8, 7, 6, 5, 4, 3, 2, 1},
AppEUI: app.AppEUI,
AppKey: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
RXDelay: 3,
RX1DROffset: 2,
}
So(storage.CreateNode(ctx.DB, node), ShouldBeNil)
Convey("Given a JoinRequest with correct DevEUI but incorrect AppEUI", func() {
phy := lorawan.PHYPayload{
MHDR: lorawan.MHDR{
MType: lorawan.JoinRequest,
Major: lorawan.LoRaWANR1,
},
MACPayload: &lorawan.JoinRequestPayload{
AppEUI: [8]byte{1, 2, 3, 4, 5, 6, 7, 9},
DevEUI: node.DevEUI,
DevNonce: [2]byte{1, 2},
},
}
So(phy.SetMIC(node.AppKey), ShouldBeNil)
rxPacket := models.RXPacket{
PHYPayload: phy,
RXInfo: models.RXInfo{
Frequency: common.Band.UplinkChannels[0].Frequency,
DataRate: common.Band.DataRates[common.Band.UplinkChannels[0].DataRates[0]],
},
}
Convey("then handleRXPacket returns an error", func() {
So(handleRXPacket(ctx, rxPacket), ShouldResemble, errors.New("node 0807060504030201 belongs to application 0102030405060708, 0102030405060709 was given"))
})
})
Convey("Given a JoinRequest packet", func() {
phy := lorawan.PHYPayload{
MHDR: lorawan.MHDR{
MType: lorawan.JoinRequest,
Major: lorawan.LoRaWANR1,
},
MACPayload: &lorawan.JoinRequestPayload{
AppEUI: app.AppEUI,
DevEUI: node.DevEUI,
DevNonce: [2]byte{1, 2},
},
}
So(phy.SetMIC(node.AppKey), ShouldBeNil)
rxPacket := models.RXPacket{
PHYPayload: phy,
RXInfo: models.RXInfo{
Frequency: common.Band.UplinkChannels[0].Frequency,
DataRate: common.Band.DataRates[common.Band.UplinkChannels[0].DataRates[0]],
},
}
Convey("When calling handleRXPacket", func() {
So(handleRXPacket(ctx, rxPacket), ShouldBeNil)
Convey("Then a JoinAccept was sent to the node", func() {
txPacket := <-g.txPacketChan
phy := txPacket.PHYPayload
So(phy.DecryptJoinAcceptPayload(node.AppKey), ShouldBeNil)
So(phy.MHDR.MType, ShouldEqual, lorawan.JoinAccept)
//.........这里部分代码省略.........