2016-07-14 01:19:03 +02:00
|
|
|
package data
|
|
|
|
|
2017-04-08 13:57:33 +02:00
|
|
|
import "math"
|
2016-07-14 17:22:26 +02:00
|
|
|
|
2017-01-20 22:27:44 +01:00
|
|
|
// Wireless struct
|
2016-07-14 01:19:03 +02: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 22:27:44 +01:00
|
|
|
// WirelessStatistics struct
|
2016-12-22 03:14:51 +01:00
|
|
|
type WirelessStatistics []*WirelessAirtime
|
2016-07-14 01:19:03 +02:00
|
|
|
|
2017-01-20 22:27:44 +01:00
|
|
|
// WirelessAirtime struct
|
2016-07-14 01:19:03 +02:00
|
|
|
type WirelessAirtime struct {
|
2017-03-14 08:54:46 +01:00
|
|
|
ChanUtil float32 `json:"chan_util"` // Channel utilization
|
|
|
|
RxUtil float32 `json:"rx_util"` // Receive utilization
|
|
|
|
TxUtil float32 `json:"tx_util"` // Transmit utilization
|
|
|
|
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-14 01:19:03 +02:00
|
|
|
}
|
|
|
|
|
2017-04-08 13:57:33 +02:00
|
|
|
// FrequencyName returns 11g or 11a
|
2016-12-22 03:14:51 +01:00
|
|
|
func (airtime WirelessAirtime) FrequencyName() string {
|
|
|
|
if airtime.Frequency < 5000 {
|
|
|
|
return "11g"
|
2016-07-14 12:38:32 +02:00
|
|
|
}
|
2017-01-20 22:27:44 +01:00
|
|
|
return "11a"
|
2016-12-22 03:14:51 +01:00
|
|
|
}
|
|
|
|
|
2017-04-08 13:57:33 +02:00
|
|
|
// SetUtilization calculates the utilization values in regard to the previous values
|
2016-12-22 03:14:51 +01:00
|
|
|
func (current WirelessStatistics) SetUtilization(previous WirelessStatistics) {
|
|
|
|
for _, c := range current {
|
|
|
|
for _, p := range previous {
|
2017-04-08 13:57:33 +02:00
|
|
|
// Same frequency and time passed?
|
|
|
|
if c.Frequency == p.Frequency && p.ActiveTime < c.ActiveTime {
|
|
|
|
c.setUtilization(p)
|
2016-12-22 03:14:51 +01:00
|
|
|
}
|
|
|
|
}
|
2016-07-14 12:38:32 +02:00
|
|
|
}
|
2016-07-14 01:19:03 +02:00
|
|
|
}
|
|
|
|
|
2017-04-08 13:57:33 +02:00
|
|
|
// setUtilization updates the utilization values in regard to the previous values
|
|
|
|
func (airtime *WirelessAirtime) setUtilization(prev *WirelessAirtime) {
|
|
|
|
// Calculate deltas
|
2017-01-20 22:27:44 +01:00
|
|
|
active := float64(airtime.ActiveTime) - float64(prev.ActiveTime)
|
|
|
|
busy := float64(airtime.BusyTime) - float64(prev.BusyTime)
|
2017-04-08 13:57:33 +02:00
|
|
|
rx := float64(airtime.RxTime) - float64(prev.RxTime)
|
|
|
|
tx := float64(airtime.TxTime) - float64(prev.TxTime)
|
2016-07-14 01:19:03 +02:00
|
|
|
|
2017-04-08 13:57:33 +02:00
|
|
|
// Update utilizations
|
|
|
|
airtime.ChanUtil = float32(math.Min(100, 100*busy/active))
|
|
|
|
airtime.RxUtil = float32(math.Min(100, 100*rx/active))
|
|
|
|
airtime.TxUtil = float32(math.Min(100, 100*tx/active))
|
2016-07-14 01:19:03 +02:00
|
|
|
}
|