2016-07-13 23:19:03 +00:00
|
|
|
package data
|
|
|
|
|
2016-07-14 15:22:26 +00:00
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
)
|
|
|
|
|
2017-01-20 21:27:44 +00:00
|
|
|
// Wireless struct
|
2016-07-13 23:19:03 +00:00
|
|
|
type Wireless struct {
|
|
|
|
TxPower24 uint32 `json:"txpower24,omitempty"`
|
|
|
|
Channel24 uint32 `json:"channel24,omitempty"`
|
|
|
|
TxPower5 uint32 `json:"txpower5,omitempty"`
|
|
|
|
Channel5 uint32 `json:"channel5,omitempty"`
|
|
|
|
}
|
|
|
|
|
2017-01-20 21:27:44 +00:00
|
|
|
// WirelessStatistics struct
|
2016-12-22 02:14:51 +00:00
|
|
|
type WirelessStatistics []*WirelessAirtime
|
2016-07-13 23:19:03 +00:00
|
|
|
|
2017-01-20 21:27:44 +00:00
|
|
|
// WirelessAirtime struct
|
2016-07-13 23:19:03 +00:00
|
|
|
type WirelessAirtime struct {
|
|
|
|
ChanUtil float32 // Channel utilization
|
|
|
|
RxUtil float32 // Receive utilization
|
|
|
|
TxUtil float32 // Transmit utilization
|
|
|
|
|
2017-01-20 21:27:44 +00:00
|
|
|
ActiveTime uint64 `json:"active"`
|
|
|
|
BusyTime uint64 `json:"busy"`
|
|
|
|
RxTime uint64 `json:"rx"`
|
|
|
|
TxTime uint64 `json:"tx"`
|
|
|
|
Noise uint32 `json:"noise"`
|
|
|
|
Frequency uint32 `json:"frequency"`
|
2016-07-13 23:19:03 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 21:27:44 +00:00
|
|
|
// FrequencyName to 11g or 11a
|
2016-12-22 02:14:51 +00:00
|
|
|
func (airtime WirelessAirtime) FrequencyName() string {
|
|
|
|
if airtime.Frequency < 5000 {
|
|
|
|
return "11g"
|
2016-07-14 10:38:32 +00:00
|
|
|
}
|
2017-01-20 21:27:44 +00:00
|
|
|
return "11a"
|
2016-12-22 02:14:51 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 21:27:44 +00:00
|
|
|
// SetUtilization Calculates the utilization values in regard to the previous values
|
2016-12-22 02:14:51 +00:00
|
|
|
func (current WirelessStatistics) SetUtilization(previous WirelessStatistics) {
|
|
|
|
for _, c := range current {
|
|
|
|
for _, p := range previous {
|
|
|
|
if c.Frequency == p.Frequency {
|
|
|
|
c.SetUtilization(p)
|
|
|
|
}
|
|
|
|
}
|
2016-07-14 10:38:32 +00:00
|
|
|
}
|
2016-07-13 23:19:03 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 21:27:44 +00:00
|
|
|
// SetUtilization Calculates the utilization values in regard to the previous values
|
|
|
|
func (airtime *WirelessAirtime) SetUtilization(prev *WirelessAirtime) {
|
|
|
|
if airtime.ActiveTime <= prev.ActiveTime {
|
2016-07-13 23:19:03 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-01-20 21:27:44 +00:00
|
|
|
active := float64(airtime.ActiveTime) - float64(prev.ActiveTime)
|
|
|
|
busy := float64(airtime.BusyTime) - float64(prev.BusyTime)
|
|
|
|
rx := float64(airtime.TxTime) - float64(prev.TxTime)
|
|
|
|
tx := float64(airtime.RxTime) - float64(prev.RxTime)
|
2016-07-13 23:19:03 +00:00
|
|
|
|
|
|
|
// Calculate utilizations
|
|
|
|
if active > 0 {
|
2017-01-20 21:27:44 +00:00
|
|
|
airtime.ChanUtil = float32(math.Min(100, 100*(busy+rx+tx)/active))
|
|
|
|
airtime.RxUtil = float32(math.Min(100, 100*rx/active))
|
|
|
|
airtime.TxUtil = float32(math.Min(100, 100*tx/active))
|
2016-07-13 23:19:03 +00:00
|
|
|
}
|
|
|
|
}
|