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": {
"mote1": {
"otaa": true,
"gatewayEui": "0102030405060708",
"appEui": "0102030405060708",
"devEui": "b92fd5d497cfcdbd",
"devAddr": "01c6f8db",
"appKey": "fe80c1f94e6cc62d5d6f72630b43c177",
"nwkSKey": "953f0cc2031d5fa30a6bb3bdc7e61fb8",
"appSKey": "3361732618283cc6097d564b83c257ca",
"gatewayEui": "819dc403b3bb8bf7",
"appEui": "7fe62e3c77ac72f5",
"devEui": "189514bef70e7e83",
"devAddr": "b99115f5",
"appKey": "0f23b930b1b8a6be4e09ba1b33736835",
"nwkSKey": "cbc53a0c740c34cc5f194546c1df23ef",
"appSKey": "b5954d98f317617dd5f27cae16e8354d",
"fCnt": 14,
"fPort": 2,
"freq": 470.3,

38
LoRaMoteMock.go

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

11
utils.go

@ -14,6 +14,17 @@ import (
"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 {
_,err := syscall.UTF16FromString(string(b))
if err == nil {

Loading…
Cancel
Save