You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
3.2 KiB

5 years ago
package main
5 years ago
import (
5 years ago
"github.com/brocaar/lorawan"
5 years ago
"github.com/lxn/walk"
"sort"
)
5 years ago
type ConnectConfig struct {
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
CACert string `json:"ca_cert"`
TLSCert string `json:"tls_cert"`
TLSKey string `json:"tls_key"`
}
5 years ago
type MoteConfig struct {
5 years ago
OTAA bool `json:"otaa"`
GatewayId string `json:"gatewayId"`
AppEui string `json:"appEui"`
5 years ago
DevEui string `json:"devEui"`
DevAddr string `json:"devAddr"`
AppKey string `json:"appKey"`
NwkSKey string `json:"nwkSKey"`
AppSKey string `json:"appSKey"`
5 years ago
FCnt uint32 `json:"fCnt"`
FPort uint8 `json:"fPort"`
5 years ago
Freq float64 `json:"freq"`
DR uint8 `json:"dr"`
Chan uint8 `json:"chan"`
LSNR float64 `json:"lsnr"`
RSSI int16 `json:"rssi"`
MType uint8 `json:"mType"`
FCtrl lorawan.FCtrl `json:"fCtrl"`
5 years ago
devNonce lorawan.DevNonce
}
type MotesConfig struct {
Current string `json:"current"`
Configs map[string]MoteConfig `json:"configs"`
}
5 years ago
type Mote struct {
5 years ago
Index int
5 years ago
Direction string
5 years ago
DevEUI string
5 years ago
DevAddr string
5 years ago
MType string
GatewayID string
Rssi int16
LoRaSNR float64
Frequency float64
FCnt uint32
FPort uint8
HexData string
AsciiData string
Time string
checked bool
OrigData string
}
5 years ago
type MoteModel struct {
5 years ago
walk.TableModelBase
walk.SorterBase
SortColumn int
SortOrder walk.SortOrder
5 years ago
Items []*Mote
5 years ago
}
5 years ago
func (m *MoteModel) RowCount() int {
5 years ago
return len(m.Items)
}
5 years ago
func (m *MoteModel) Value(row, col int) interface{} {
5 years ago
item := m.Items[row]
switch col {
case 0:
return item.Index
case 1:
5 years ago
return item.Direction
5 years ago
case 2:
5 years ago
return item.DevEUI
5 years ago
case 3:
5 years ago
return item.DevAddr
5 years ago
case 4:
5 years ago
return item.MType
5 years ago
case 5:
5 years ago
return item.GatewayID
5 years ago
case 6:
5 years ago
return item.Rssi
5 years ago
case 7:
5 years ago
return item.LoRaSNR
5 years ago
case 8:
5 years ago
return item.Frequency
5 years ago
case 9:
5 years ago
return item.FCnt
5 years ago
case 10:
5 years ago
return item.FPort
5 years ago
case 11:
5 years ago
return item.HexData
case 12:
return item.AsciiData
case 13:
5 years ago
return item.Time
}
panic("unexpected col")
}
5 years ago
func (m *MoteModel) Checked(row int) bool {
5 years ago
return m.Items[row].checked
}
5 years ago
func (m *MoteModel) SetChecked(row int, checked bool) error {
5 years ago
m.Items[row].checked = checked
return nil
}
5 years ago
func (m *MoteModel) Sort(col int, order walk.SortOrder) error {
5 years ago
m.SortColumn, m.SortOrder = col, order
sort.Stable(m)
return m.SorterBase.Sort(col, order)
}
5 years ago
func (m *MoteModel) Len() int {
5 years ago
return len(m.Items)
}
5 years ago
func (m *MoteModel) Less(i, j int) bool {
5 years ago
a, b := m.Items[i], m.Items[j]
c := func(ls bool) bool {
if m.SortOrder == walk.SortAscending {
return ls
}
return !ls
}
switch m.SortColumn {
case 0:
return c(a.Index < b.Index)
case 1:
return c(a.Direction < b.Direction)
5 years ago
case 2:
return c(a.DevEUI < b.DevEUI)
case 3:
return c(a.DevAddr < b.DevAddr)
5 years ago
case 4:
return c(a.MType < b.MType)
5 years ago
case 5:
return c(a.GatewayID < b.GatewayID)
case 9:
return c(a.FCnt < b.FCnt)
case 10:
return c(a.FPort < b.FPort)
case 13:
return c(a.Time < b.Time)
5 years ago
default:
return false
}
}
5 years ago
func (m *MoteModel) Swap(i, j int) {
5 years ago
m.Items[i], m.Items[j] = m.Items[j], m.Items[i]
}
5 years ago
func NewMoteModel() *MoteModel {
return new(MoteModel)
5 years ago
}