Browse Source

增加随机配置值

master
lihua 5 years ago
parent
commit
535067e115
  1. 14
      LoRaMoteConf.json
  2. 38
      LoRaMoteMock.go
  3. 11
      utils.go

14
LoRaMoteConf.json

@ -3,13 +3,13 @@
"configs": { "configs": {
"mote1": { "mote1": {
"otaa": true, "otaa": true,
"gatewayEui": "0102030405060708", "gatewayEui": "819dc403b3bb8bf7",
"appEui": "0102030405060708", "appEui": "7fe62e3c77ac72f5",
"devEui": "b92fd5d497cfcdbd", "devEui": "189514bef70e7e83",
"devAddr": "01c6f8db", "devAddr": "b99115f5",
"appKey": "fe80c1f94e6cc62d5d6f72630b43c177", "appKey": "0f23b930b1b8a6be4e09ba1b33736835",
"nwkSKey": "953f0cc2031d5fa30a6bb3bdc7e61fb8", "nwkSKey": "cbc53a0c740c34cc5f194546c1df23ef",
"appSKey": "3361732618283cc6097d564b83c257ca", "appSKey": "b5954d98f317617dd5f27cae16e8354d",
"fCnt": 14, "fCnt": 14,
"fPort": 2, "fPort": 2,
"freq": 470.3, "freq": 470.3,

38
LoRaMoteMock.go

@ -299,13 +299,13 @@ func (mw *MoteMainWindow) MoteConfig() {
}, },
DefaultButton: &acceptPB, DefaultButton: &acceptPB,
CancelButton: &cancelPB, CancelButton: &cancelPB,
MinSize: Size{400, 200}, MinSize: Size{420, 400},
Children: []Widget{ Children: []Widget{
TabWidget{ TabWidget{
Pages:[]TabPage{ Pages:[]TabPage{
{ {
Title:"基础配置", Title:"基础配置",
Layout:Grid{Columns: 2}, Layout:Grid{Columns: 3},
Children:[]Widget{ Children:[]Widget{
Label{Text: "配置名称:"}, Label{Text: "配置名称:"},
ComboBox{AssignTo: &name,Editable: true, OnCurrentIndexChanged: func() { ComboBox{AssignTo: &name,Editable: true, OnCurrentIndexChanged: func() {
@ -313,6 +313,7 @@ func (mw *MoteMainWindow) MoteConfig() {
mw.currentMoteConf = mw.motesConf.Configs[mw.motesConf.Current] mw.currentMoteConf = mw.motesConf.Configs[mw.motesConf.Current]
_ = db.Reset() _ = db.Reset()
}}, }},
HSpacer{},
Label{Text:"入网方式:"}, Label{Text:"入网方式:"},
Composite{ Composite{
Layout: HBox{}, Layout: HBox{},
@ -321,7 +322,7 @@ func (mw *MoteMainWindow) MoteConfig() {
mw.currentMoteConf.OTAA = otaa.Checked() mw.currentMoteConf.OTAA = otaa.Checked()
_ = db.Reset() _ = db.Reset()
}}, }},
CheckBox{AssignTo:&join,Text:"是否重新入网",Enabled:Bind("OTAA"),OnCheckStateChanged: func() { CheckBox{AssignTo:&join,Text:"重新入网",Enabled:Bind("OTAA"),OnCheckStateChanged: func() {
if mw.currentMoteConf.OTAA && join.Checked() { if mw.currentMoteConf.OTAA && join.Checked() {
mw.currentMoteConf.DevAddr = "" mw.currentMoteConf.DevAddr = ""
mw.currentMoteConf.NwkSKey = "" mw.currentMoteConf.NwkSKey = ""
@ -332,23 +333,52 @@ func (mw *MoteMainWindow) MoteConfig() {
}}, }},
}, },
}, },
HSpacer{},
Label{Text:"网关EUI:"}, Label{Text:"网关EUI:"},
LineEdit{Text:Bind("GatewayEui",Regexp{Pattern:"^[0-9a-fA-F]{16,16}$"})}, LineEdit{Text:Bind("GatewayEui",Regexp{Pattern:"^[0-9a-fA-F]{16,16}$"})},
PushButton{Text:"随机",OnClicked: func() {
mw.currentMoteConf.GatewayEui = GetRandomHexString(16)
_ = db.Reset()
}},
Label{Text:"应用EUI:",Visible:Bind("OTAA")}, Label{Text:"应用EUI:",Visible:Bind("OTAA")},
LineEdit{Text:Bind("AppEui"),Visible:Bind("OTAA")}, LineEdit{Text:Bind("AppEui"),Visible:Bind("OTAA")},
PushButton{Text:"随机",Visible:Bind("OTAA"),OnClicked: func() {
mw.currentMoteConf.AppEui = GetRandomHexString(16)
_ = db.Reset()
}},
Label{Text:"终端EUI:"}, Label{Text:"终端EUI:"},
LineEdit{Text:Bind("DevEui",Regexp{Pattern:"^[0-9a-fA-F]{16,16}$"})}, LineEdit{Text:Bind("DevEui",Regexp{Pattern:"^[0-9a-fA-F]{16,16}$"})},
PushButton{Text:"随机",OnClicked: func() {
mw.currentMoteConf.DevEui = GetRandomHexString(16)
_ = db.Reset()
}},
Label{Text:"应用秘钥:",Visible:Bind("OTAA")}, Label{Text:"应用秘钥:",Visible:Bind("OTAA")},
LineEdit{Text:Bind("AppKey"),Visible:Bind("OTAA")}, LineEdit{Text:Bind("AppKey"),Visible:Bind("OTAA")},
PushButton{Text:"随机",Visible:Bind("OTAA"),OnClicked: func() {
mw.currentMoteConf.AppKey = GetRandomHexString(32)
_ = db.Reset()
}},
Label{Text:"终端地址:"}, Label{Text:"终端地址:"},
LineEdit{Text:Bind("DevAddr"),ReadOnly:Bind("OTAA")}, LineEdit{Text:Bind("DevAddr"),ReadOnly:Bind("OTAA")},
PushButton{Text:"随机",OnClicked: func() {
mw.currentMoteConf.DevAddr = GetRandomHexString(8)
_ = db.Reset()
}},
Label{Text:"网络会话秘钥:"}, Label{Text:"网络会话秘钥:"},
LineEdit{Text:Bind("NwkSKey"),ReadOnly:Bind("OTAA")}, LineEdit{Text:Bind("NwkSKey"),ReadOnly:Bind("OTAA")},
PushButton{Text:"随机",OnClicked: func() {
mw.currentMoteConf.NwkSKey = GetRandomHexString(32)
_ = db.Reset()
}},
Label{Text:"应用会话秘钥:"}, Label{Text:"应用会话秘钥:"},
LineEdit{Text:Bind("AppSKey"),ReadOnly:Bind("OTAA")}, LineEdit{Text:Bind("AppSKey"),ReadOnly:Bind("OTAA")},
PushButton{Text:"随机",OnClicked: func() {
mw.currentMoteConf.AppSKey = GetRandomHexString(32)
_ = db.Reset()
}},
Label{Text:"上行计数:"}, Label{Text:"上行计数:"},
NumberEdit{Value:Bind("FCnt")}, NumberEdit{Value:Bind("FCnt")},
HSpacer{},
}, },
}, },
{ {

11
utils.go

@ -14,6 +14,17 @@ import (
"time" "time"
) )
func GetRandomHexString(length int) string{
str := "0123456789abcdef"
bytes := []byte(str)
result := []byte{}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < length; i++ {
result = append(result, bytes[r.Intn(len(bytes))])
}
return string(result)
}
func BytesToString(b []byte) string { func BytesToString(b []byte) string {
_,err := syscall.UTF16FromString(string(b)) _,err := syscall.UTF16FromString(string(b))
if err == nil { if err == nil {

Loading…
Cancel
Save