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.
151 lines
2.7 KiB
151 lines
2.7 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"`
|
||
|
}
|
||
|
|
||
|
type DTUConfig struct {
|
||
|
OTAA bool `json:"otaa"`
|
||
|
GatewayId string `json:"gatewayId"`
|
||
|
DevEui string `json:"devEui"`
|
||
|
DevAddr string `json:"devAddr"`
|
||
|
AppKey string `json:"appKey"`
|
||
|
AppSKey string `json:"appSKey"`
|
||
|
NwkSKey string `json:"nwkSKey"`
|
||
|
FPort uint8 `json:"fPort"`
|
||
|
FCnt uint32 `json:"fCnt"`
|
||
|
Freq float64 `json:"freq"`
|
||
|
devNonce lorawan.DevNonce
|
||
|
}
|
||
|
|
||
|
type DTU 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 DTUModel struct {
|
||
5 years ago
|
walk.TableModelBase
|
||
|
walk.SorterBase
|
||
|
SortColumn int
|
||
|
SortOrder walk.SortOrder
|
||
5 years ago
|
Items []*DTU
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
func (m *DTUModel) RowCount() int {
|
||
5 years ago
|
return len(m.Items)
|
||
|
}
|
||
|
|
||
5 years ago
|
func (m *DTUModel) 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 *DTUModel) Checked(row int) bool {
|
||
5 years ago
|
return m.Items[row].checked
|
||
|
}
|
||
|
|
||
5 years ago
|
func (m *DTUModel) SetChecked(row int, checked bool) error {
|
||
5 years ago
|
m.Items[row].checked = checked
|
||
|
return nil
|
||
|
}
|
||
|
|
||
5 years ago
|
func (m *DTUModel) 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 *DTUModel) Len() int {
|
||
5 years ago
|
return len(m.Items)
|
||
|
}
|
||
|
|
||
5 years ago
|
func (m *DTUModel) 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 2:
|
||
|
return c(a.DevEUI < b.DevEUI)
|
||
|
case 4:
|
||
|
return c(a.Rssi < b.Rssi)
|
||
|
case 5:
|
||
|
return c(a.LoRaSNR < b.LoRaSNR)
|
||
|
case 6:
|
||
|
return c(a.Frequency < b.Frequency)
|
||
|
default:
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
func (m *DTUModel) Swap(i, j int) {
|
||
5 years ago
|
m.Items[i], m.Items[j] = m.Items[j], m.Items[i]
|
||
|
}
|
||
|
|
||
5 years ago
|
func NewDTUModel() *DTUModel {
|
||
|
return new(DTUModel)
|
||
|
}
|