From 718a9bfa8479972f6ea25c939153ba9b0b25af33 Mon Sep 17 00:00:00 2001 From: lihua <531456470@qq.com> Date: Fri, 22 Nov 2019 15:15:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E7=BB=88=E7=AB=AF=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LoRaMoteConf.json | 37 +++++++++++++++++++++++++++---------- LoRaMoteMock.go | 20 +++++++++++++------- model.go | 2 +- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/LoRaMoteConf.json b/LoRaMoteConf.json index 9b74567..05ba84c 100644 --- a/LoRaMoteConf.json +++ b/LoRaMoteConf.json @@ -1,12 +1,29 @@ { - "otaa": true, - "gatewayId": "0102030405060708", - "devEui": "b92fd5d497cfcdbd", - "devAddr": "00530747", - "appKey": "fe80c1f94e6cc62d5d6f72630b43c177", - "appSKey": "2bc9217655160b2c1229b5ecb469242f", - "nwkSKey": "4f862983a453cc50336284fd3c62aba5", - "fPort": 2, - "fCnt": 8, - "freq": 470.3 + "current": "mote2", + "configs": { + "mote1": { + "otaa": true, + "gatewayId": "0102030405060708", + "devEui": "b92fd5d497cfcdbd", + "devAddr": "00530747", + "appKey": "fe80c1f94e6cc62d5d6f72630b43c177", + "nwkSKey": "4f862983a453cc50336284fd3c62aba5", + "appSKey": "2bc9217655160b2c1229b5ecb469242f", + "fPort": 2, + "fCnt": 375, + "freq": 470.3 + }, + "mote2": { + "otaa": false, + "gatewayId": "0102030405060708", + "devEui": "6ef1881ba5541419", + "devAddr": "00c18699", + "appKey": "", + "nwkSKey": "33998df974421457437d986eff739ffa", + "appSKey": "33998df974421457437d986eff739ffa", + "fPort": 2, + "fCnt": 1194, + "freq": 470.3 + } + } } \ No newline at end of file diff --git a/LoRaMoteMock.go b/LoRaMoteMock.go index 5b78ee5..cfc5be2 100644 --- a/LoRaMoteMock.go +++ b/LoRaMoteMock.go @@ -176,6 +176,11 @@ func main() { mw.currentMoteConf = mw.motesConf.Configs[mw.motesConf.Current] } mw.Run() + var confData bytes.Buffer + mw.motesConf.Configs[mw.motesConf.Current] = mw.currentMoteConf + d,_ := json.Marshal(&mw.motesConf) + _ = json.Indent(&confData, d, "", "\t") + _ = ioutil.WriteFile(mw.moteConfFileName,confData.Bytes(),0644) } @@ -489,7 +494,9 @@ func (mw *MoteMainWindow) HandleData(client paho.Client, message paho.Message){ case lorawan.JoinAccept: mw.HandleJoinAccept(&phy) case lorawan.ConfirmedDataDown,lorawan.UnconfirmedDataDown: - mw.HandleDataDown(&phy) + if !mw.HandleDataDown(&phy) { + return + } default: fmt.Println("未处理的帧") } @@ -552,7 +559,7 @@ func (mw *MoteMainWindow) HandleJoinAccept(phy *lorawan.PHYPayload){ } } -func (mw *MoteMainWindow) HandleDataDown(phy *lorawan.PHYPayload){ +func (mw *MoteMainWindow) HandleDataDown(phy *lorawan.PHYPayload) bool{ mpl := phy.MACPayload.(*lorawan.MACPayload) key := mw.currentMoteConf.AppSKey if mpl.FPort != nil && *mpl.FPort == 0 { @@ -563,8 +570,11 @@ func (mw *MoteMainWindow) HandleDataDown(phy *lorawan.PHYPayload){ _ = aseKey.UnmarshalText([]byte(key)) err := phy.DecryptFRMPayload(aseKey) if err == nil { - mw.currentMoteConf.DevAddr = mpl.FHDR.DevAddr.String() + if mw.currentMoteConf.DevAddr == mpl.FHDR.DevAddr.String() { + return true + } } + return false } func (mw *MoteMainWindow) PushData(gatewayEUI string,event string, msg proto.Message) { @@ -674,10 +684,6 @@ func (mw *MoteMainWindow) sendMsg() error{ mw.PushData(mw.currentMoteConf.GatewayId,"up",&frames[j]) } mw.currentMoteConf.FCnt ++ - var confData bytes.Buffer - d,_ := json.Marshal(&mw.currentMoteConf) - _ = json.Indent(&confData, d, "", "\t") - _ = ioutil.WriteFile(mw.moteConfFileName,confData.Bytes(),0644) return nil } diff --git a/model.go b/model.go index 0bc3cb8..afcf196 100644 --- a/model.go +++ b/model.go @@ -22,8 +22,8 @@ type MoteConfig struct { DevEui string `json:"devEui"` DevAddr string `json:"devAddr"` AppKey string `json:"appKey"` - AppSKey string `json:"appSKey"` NwkSKey string `json:"nwkSKey"` + AppSKey string `json:"appSKey"` FPort uint8 `json:"fPort"` FCnt uint32 `json:"fCnt"` Freq float64 `json:"freq"`