本文整理汇总了Golang中github.com/brocaar/lorawan.PHYPayload.EncryptJoinAcceptPayload方法的典型用法代码示例。如果您正苦于以下问题:Golang PHYPayload.EncryptJoinAcceptPayload方法的具体用法?Golang PHYPayload.EncryptJoinAcceptPayload怎么用?Golang PHYPayload.EncryptJoinAcceptPayload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/brocaar/lorawan.PHYPayload
的用法示例。
在下文中一共展示了PHYPayload.EncryptJoinAcceptPayload方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleCollectedJoinRequestPackets
//.........这里部分代码省略.........
// get the (optional) CFList
cFList, err := getCFListForNode(ctx.DB, node)
if err != nil {
return fmt.Errorf("get CFList for node error: %s", err)
}
// get keys
nwkSKey, err := getNwkSKey(node.AppKey, ctx.NetID, appNonce, jrPL.DevNonce)
if err != nil {
return fmt.Errorf("get NwkSKey error: %s", err)
}
appSKey, err := getAppSKey(node.AppKey, ctx.NetID, appNonce, jrPL.DevNonce)
if err != nil {
return fmt.Errorf("get AppSKey error: %s", err)
}
ns := models.NodeSession{
DevAddr: devAddr,
DevEUI: jrPL.DevEUI,
AppSKey: appSKey,
NwkSKey: nwkSKey,
FCntUp: 0,
FCntDown: 0,
AppEUI: node.AppEUI,
RXDelay: node.RXDelay,
RX1DROffset: node.RX1DROffset,
}
if err = saveNodeSession(ctx.RedisPool, ns); err != nil {
return fmt.Errorf("save node-session error: %s", err)
}
// update the node (with updated used dev-nonces)
if err = updateNode(ctx.DB, node); err != nil {
return fmt.Errorf("update node error: %s", err)
}
// construct the lorawan packet
phy := lorawan.PHYPayload{
MHDR: lorawan.MHDR{
MType: lorawan.JoinAccept,
Major: lorawan.LoRaWANR1,
},
MACPayload: &lorawan.JoinAcceptPayload{
AppNonce: appNonce,
NetID: ctx.NetID,
DevAddr: ns.DevAddr,
RXDelay: ns.RXDelay,
DLSettings: lorawan.DLSettings{
RX2DataRate: uint8(Band.RX2DataRate),
RX1DROffset: ns.RX1DROffset,
},
CFList: cFList,
},
}
if err = phy.SetMIC(node.AppKey); err != nil {
return fmt.Errorf("set MIC error: %s", err)
}
if err = phy.EncryptJoinAcceptPayload(node.AppKey); err != nil {
return fmt.Errorf("encrypt join-accept error: %s", err)
}
// get TX DR
uplinkDR, err := Band.GetDataRate(rxPacket.RXInfo.DataRate)
if err != nil {
return err
}
// get TX channel
uplinkChannel, err := Band.GetChannel(rxPacket.RXInfo.Frequency, uplinkDR)
if err != nil {
return err
}
// get RX1 channel
rx1Channel := Band.GetRX1Channel(uplinkChannel)
// get RX1 DR
rx1DR := Band.RX1DataRate[uplinkDR][0]
txPacket := models.TXPacket{
TXInfo: models.TXInfo{
MAC: rxPacket.RXInfo.MAC,
Timestamp: rxPacket.RXInfo.Timestamp + uint32(Band.JoinAcceptDelay1/time.Microsecond),
Frequency: Band.DownlinkChannels[rx1Channel].Frequency,
Power: Band.DefaultTXPower,
DataRate: Band.DataRates[rx1DR],
CodeRate: rxPacket.RXInfo.CodeRate,
},
PHYPayload: phy,
}
// window 1
if err = ctx.Gateway.SendTXPacket(txPacket); err != nil {
return fmt.Errorf("send tx packet (rx window 1) to gateway error: %s", err)
}
// send a notification to the application that a node joined the network
return ctx.Application.SendNotification(ns.AppEUI, ns.DevEUI, models.JoinNotificationType, models.JoinNotification{
DevAddr: ns.DevAddr,
DevEUI: ns.DevEUI,
})
}