chore: release v0.22.9
This commit is contained in:
@@ -9,6 +9,7 @@ package powergenius
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -36,6 +37,16 @@ type Status struct {
|
||||
FanMode string `json:"fan_mode,omitempty"` // STANDARD / CONTEST / BROADCAST
|
||||
Temperature float64 `json:"temperature"`
|
||||
Operate bool `json:"operate"` // OPERATE vs STANDBY (optimistic until the amp reports it)
|
||||
|
||||
// Live power, read straight from the amplifier's own status frame rather
|
||||
// than sampled off the FlexRadio meter stream. PeakW is the amp's own peak
|
||||
// detector: a poll catches one instant of the envelope, so the plain forward
|
||||
// figure lands between syllables as often as on a peak.
|
||||
FwdW float64 `json:"fwd_w"` // forward power [W] (the frame reports dBm)
|
||||
PeakW float64 `json:"peak_w"` // peak forward power [W]
|
||||
Vswr float64 `json:"vswr"` // VSWR, derived from the frame's return loss in dB
|
||||
Id float64 `json:"id"` // drain current [A]
|
||||
PeakId float64 `json:"peak_id"` // peak drain current [A]
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
@@ -226,9 +237,9 @@ func (c *Client) parse(resp string) {
|
||||
c.statusMu.Lock()
|
||||
c.status.Connected = true
|
||||
c.status.LastError = ""
|
||||
// Log each DISTINCT status payload once: the PGXL's field set isn't fully
|
||||
// documented, so this is how we learn the real key for e.g. operate/standby.
|
||||
if data != c.lastRaw {
|
||||
// One raw frame per session is enough to learn the field set — the frames
|
||||
// carry live meter values, so "log on change" logged every frame.
|
||||
if c.lastRaw == "" {
|
||||
c.lastRaw = data
|
||||
applog.Printf("pgxl: status raw=%q", data)
|
||||
}
|
||||
@@ -252,7 +263,50 @@ func (c *Client) parse(resp string) {
|
||||
c.status.FanMode = dev
|
||||
case "temp":
|
||||
c.status.Temperature, _ = strconv.ParseFloat(kv[1], 64)
|
||||
case "fwd":
|
||||
if v, err := strconv.ParseFloat(kv[1], 64); err == nil {
|
||||
c.status.FwdW = dbmToWatts(v)
|
||||
}
|
||||
case "peakfwd":
|
||||
if v, err := strconv.ParseFloat(kv[1], 64); err == nil {
|
||||
c.status.PeakW = dbmToWatts(v)
|
||||
}
|
||||
case "swr":
|
||||
if v, err := strconv.ParseFloat(kv[1], 64); err == nil {
|
||||
c.status.Vswr = returnLossToVswr(v)
|
||||
}
|
||||
case "id":
|
||||
c.status.Id, _ = strconv.ParseFloat(kv[1], 64)
|
||||
case "peakid":
|
||||
c.status.PeakId, _ = strconv.ParseFloat(kv[1], 64)
|
||||
}
|
||||
}
|
||||
c.statusMu.Unlock()
|
||||
}
|
||||
|
||||
// dbmToWatts converts a power reading in dBm to watts (0 dBm = 1 mW). The amp
|
||||
// reports power that way — "fwd=60.5" is 1122 W, not 60 W.
|
||||
func dbmToWatts(dbm float64) float64 {
|
||||
if dbm <= 0 {
|
||||
return 0
|
||||
}
|
||||
return math.Pow(10, (dbm-30)/10)
|
||||
}
|
||||
|
||||
// returnLossToVswr converts the amp's "swr" field — a return loss in dB, sent
|
||||
// negative for a good match — into the VSWR ratio an operator reads.
|
||||
func returnLossToVswr(swrDb float64) float64 {
|
||||
rl := math.Abs(swrDb)
|
||||
if rl <= 0 {
|
||||
return 0
|
||||
}
|
||||
rho := math.Pow(10, -rl/20)
|
||||
if rho >= 1 {
|
||||
return 0
|
||||
}
|
||||
vswr := (1 + rho) / (1 - rho)
|
||||
if vswr > 99.9 || math.IsInf(vswr, 0) || math.IsNaN(vswr) {
|
||||
return 0
|
||||
}
|
||||
return vswr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user