This commit is contained in:
2026-01-10 03:26:17 +01:00
parent bceac40518
commit 8de9a0dd87
20 changed files with 179 additions and 1636 deletions

View File

@@ -79,10 +79,7 @@ func (dm *DeviceManager) Initialize() error {
)
// Initialize Rotator Genius
<<<<<<< HEAD
log.Printf("Initializing RotatorGenius: host=%s port=%d", dm.config.Devices.RotatorGenius.Host, dm.config.Devices.RotatorGenius.Port)
=======
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
dm.rotatorGenius = rotatorgenius.New(
dm.config.Devices.RotatorGenius.Host,
dm.config.Devices.RotatorGenius.Port,
@@ -98,7 +95,6 @@ func (dm *DeviceManager) Initialize() error {
dm.config.Location.Longitude,
)
<<<<<<< HEAD
// Start device polling in background (non-blocking)
go func() {
if err := dm.powerGenius.Start(); err != nil {
@@ -126,12 +122,6 @@ func (dm *DeviceManager) Initialize() error {
}
}()
log.Println("RotatorGenius goroutine launched")
=======
// Start PowerGenius continuous polling
if err := dm.powerGenius.Start(); err != nil {
log.Printf("Warning: Failed to start PowerGenius polling: %v", err)
}
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
log.Println("Device manager initialized")
return nil
@@ -196,7 +186,6 @@ func (dm *DeviceManager) updateStatus() {
log.Printf("Power Genius error: %v", err)
}
<<<<<<< HEAD
// Tuner Genius
if tgStatus, err := dm.tunerGenius.GetStatus(); err == nil {
status.TunerGenius = tgStatus
@@ -217,28 +206,6 @@ func (dm *DeviceManager) updateStatus() {
} else {
log.Printf("Rotator Genius error: %v", err)
}
=======
// // Tuner Genius
// if tgStatus, err := dm.tunerGenius.GetStatus(); err == nil {
// status.TunerGenius = tgStatus
// } else {
// log.Printf("Tuner Genius error: %v", err)
// }
// // Antenna Genius
// if agStatus, err := dm.antennaGenius.GetStatus(); err == nil {
// status.AntennaGenius = agStatus
// } else {
// log.Printf("Antenna Genius error: %v", err)
// }
// // Rotator Genius
// if rgStatus, err := dm.rotatorGenius.GetStatus(); err == nil {
// status.RotatorGenius = rgStatus
// } else {
// log.Printf("Rotator Genius error: %v", err)
// }
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
// Solar Data (fetched every 15 minutes, cached)
if solarData, err := dm.solarClient.GetSolarData(); err == nil {

View File

@@ -49,18 +49,13 @@ func (s *Server) SetupRoutes() *http.ServeMux {
mux.HandleFunc("/api/webswitch/all/off", s.handleWebSwitchAllOff)
// Rotator endpoints
<<<<<<< HEAD
mux.HandleFunc("/api/rotator/heading", s.handleRotatorHeading)
=======
mux.HandleFunc("/api/rotator/move", s.handleRotatorMove)
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
mux.HandleFunc("/api/rotator/cw", s.handleRotatorCW)
mux.HandleFunc("/api/rotator/ccw", s.handleRotatorCCW)
mux.HandleFunc("/api/rotator/stop", s.handleRotatorStop)
// Tuner endpoints
mux.HandleFunc("/api/tuner/operate", s.handleTunerOperate)
<<<<<<< HEAD
mux.HandleFunc("/api/tuner/bypass", s.handleTunerBypass)
mux.HandleFunc("/api/tuner/autotune", s.handleTunerAutoTune)
@@ -71,19 +66,8 @@ func (s *Server) SetupRoutes() *http.ServeMux {
// Power Genius endpoints
mux.HandleFunc("/api/power/fanmode", s.handlePowerFanMode)
mux.HandleFunc("/api/power/operate", s.handlePowerOperate)
=======
mux.HandleFunc("/api/tuner/tune", s.handleTunerAutoTune)
mux.HandleFunc("/api/tuner/antenna", s.handleTunerAntenna)
// Antenna Genius endpoints
mux.HandleFunc("/api/antenna/set", s.handleAntennaSet)
// Power Genius endpoints
mux.HandleFunc("/api/power/fanmode", s.handlePowerFanMode)
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
// Static files (will be frontend)
mux.Handle("/", http.FileServer(http.Dir("./web/dist")))
// Note: Static files are now served from embedded FS in main.go
return mux
}
@@ -196,23 +180,14 @@ func (s *Server) handleWebSwitchAllOff(w http.ResponseWriter, r *http.Request) {
}
// Rotator handlers
<<<<<<< HEAD
func (s *Server) handleRotatorHeading(w http.ResponseWriter, r *http.Request) {
=======
func (s *Server) handleRotatorMove(w http.ResponseWriter, r *http.Request) {
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
var req struct {
<<<<<<< HEAD
Heading int `json:"heading"`
=======
Rotator int `json:"rotator"`
Azimuth int `json:"azimuth"`
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
@@ -220,11 +195,7 @@ func (s *Server) handleRotatorMove(w http.ResponseWriter, r *http.Request) {
return
}
<<<<<<< HEAD
if err := s.deviceManager.RotatorGenius().SetHeading(req.Heading); err != nil {
=======
if err := s.deviceManager.RotatorGenius().MoveToAzimuth(req.Rotator, req.Azimuth); err != nil {
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -238,17 +209,7 @@ func (s *Server) handleRotatorCW(w http.ResponseWriter, r *http.Request) {
return
}
<<<<<<< HEAD
if err := s.deviceManager.RotatorGenius().RotateCW(); err != nil {
=======
rotator, err := strconv.Atoi(r.URL.Query().Get("rotator"))
if err != nil || rotator < 1 || rotator > 2 {
http.Error(w, "Invalid rotator number", http.StatusBadRequest)
return
}
if err := s.deviceManager.RotatorGenius().RotateCW(rotator); err != nil {
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -262,17 +223,7 @@ func (s *Server) handleRotatorCCW(w http.ResponseWriter, r *http.Request) {
return
}
<<<<<<< HEAD
if err := s.deviceManager.RotatorGenius().RotateCCW(); err != nil {
=======
rotator, err := strconv.Atoi(r.URL.Query().Get("rotator"))
if err != nil || rotator < 1 || rotator > 2 {
http.Error(w, "Invalid rotator number", http.StatusBadRequest)
return
}
if err := s.deviceManager.RotatorGenius().RotateCCW(rotator); err != nil {
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -302,11 +253,7 @@ func (s *Server) handleTunerOperate(w http.ResponseWriter, r *http.Request) {
}
var req struct {
<<<<<<< HEAD
Value int `json:"value"`
=======
Operate bool `json:"operate"`
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
@@ -314,7 +261,6 @@ func (s *Server) handleTunerOperate(w http.ResponseWriter, r *http.Request) {
return
}
<<<<<<< HEAD
if err := s.deviceManager.TunerGenius().SetOperate(req.Value); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -339,9 +285,6 @@ func (s *Server) handleTunerBypass(w http.ResponseWriter, r *http.Request) {
}
if err := s.deviceManager.TunerGenius().SetBypass(req.Value); err != nil {
=======
if err := s.deviceManager.TunerGenius().SetOperate(req.Operate); err != nil {
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -363,22 +306,15 @@ func (s *Server) handleTunerAutoTune(w http.ResponseWriter, r *http.Request) {
s.sendJSON(w, map[string]string{"status": "ok"})
}
<<<<<<< HEAD
// Antenna Genius handlers
func (s *Server) handleAntennaSelect(w http.ResponseWriter, r *http.Request) {
=======
func (s *Server) handleTunerAntenna(w http.ResponseWriter, r *http.Request) {
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
var req struct {
<<<<<<< HEAD
Port int `json:"port"`
=======
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
Antenna int `json:"antenna"`
}
@@ -387,11 +323,7 @@ func (s *Server) handleTunerAntenna(w http.ResponseWriter, r *http.Request) {
return
}
<<<<<<< HEAD
if err := s.deviceManager.AntennaGenius().SetAntenna(req.Port, req.Antenna); err != nil {
=======
if err := s.deviceManager.TunerGenius().ActivateAntenna(req.Antenna); err != nil {
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -399,32 +331,13 @@ func (s *Server) handleTunerAntenna(w http.ResponseWriter, r *http.Request) {
s.sendJSON(w, map[string]string{"status": "ok"})
}
<<<<<<< HEAD
func (s *Server) handleAntennaReboot(w http.ResponseWriter, r *http.Request) {
=======
// Antenna Genius handlers
func (s *Server) handleAntennaSet(w http.ResponseWriter, r *http.Request) {
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
<<<<<<< HEAD
if err := s.deviceManager.AntennaGenius().Reboot(); err != nil {
=======
var req struct {
Radio int `json:"radio"`
Antenna int `json:"antenna"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, "Invalid request body", http.StatusBadRequest)
return
}
if err := s.deviceManager.AntennaGenius().SetRadioAntenna(req.Radio, req.Antenna); err != nil {
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -456,7 +369,6 @@ func (s *Server) handlePowerFanMode(w http.ResponseWriter, r *http.Request) {
s.sendJSON(w, map[string]string{"status": "ok"})
}
<<<<<<< HEAD
func (s *Server) handlePowerOperate(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
@@ -480,8 +392,6 @@ func (s *Server) handlePowerOperate(w http.ResponseWriter, r *http.Request) {
s.sendJSON(w, map[string]string{"status": "ok"})
}
=======
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
func (s *Server) sendJSON(w http.ResponseWriter, data interface{}) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)

View File

@@ -3,7 +3,6 @@ package antennagenius
import (
"bufio"
"fmt"
<<<<<<< HEAD
"log"
"net"
"strconv"
@@ -53,43 +52,17 @@ type Antenna struct {
RX string `json:"rx"`
InBand string `json:"in_band"`
Hotkey int `json:"hotkey"`
=======
"net"
"strconv"
"strings"
"time"
. "git.rouggy.com/rouggy/ShackMaster/internal/devices"
)
type Client struct {
host string
port int
conn net.Conn
}
type Status struct {
Radio1Antenna int `json:"radio1_antenna"` // 0-7 (antenna index)
Radio2Antenna int `json:"radio2_antenna"` // 0-7 (antenna index)
Connected bool `json:"connected"`
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
}
func New(host string, port int) *Client {
return &Client{
<<<<<<< HEAD
host: host,
port: port,
stopChan: make(chan struct{}),
=======
host: host,
port: port,
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
}
}
func (c *Client) Connect() error {
<<<<<<< HEAD
c.connMu.Lock()
defer c.connMu.Unlock()
@@ -97,26 +70,20 @@ func (c *Client) Connect() error {
return nil
}
=======
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", c.host, c.port), 5*time.Second)
if err != nil {
return fmt.Errorf("failed to connect: %w", err)
}
c.conn = conn
<<<<<<< HEAD
c.reader = bufio.NewReader(c.conn)
// Read and discard banner
_, _ = c.reader.ReadString('\n')
=======
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
return nil
}
func (c *Client) Close() error {
<<<<<<< HEAD
c.connMu.Lock()
defer c.connMu.Unlock()
@@ -124,15 +91,12 @@ func (c *Client) Close() error {
close(c.stopChan)
}
=======
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
if c.conn != nil {
return c.conn.Close()
}
return nil
}
<<<<<<< HEAD
func (c *Client) Start() error {
if c.running {
return nil
@@ -299,46 +263,10 @@ func (c *Client) sendCommand(cmd string) (string, error) {
func (c *Client) getAntennaList() ([]Antenna, error) {
resp, err := c.sendCommand("antenna list")
=======
func (c *Client) sendCommand(cmd string) (string, error) {
if c.conn == nil {
if err := c.Connect(); err != nil {
return "", err
}
}
// Get next command ID from global counter
cmdID := GetGlobalCommandID().GetNextID()
// Format command with ID: C<id>|<command>
fullCmd := fmt.Sprintf("C%d|%s\n", cmdID, cmd)
// Send command
_, err := c.conn.Write([]byte(fullCmd))
if err != nil {
c.conn = nil
return "", fmt.Errorf("failed to send command: %w", err)
}
// Read response
reader := bufio.NewReader(c.conn)
response, err := reader.ReadString('\n')
if err != nil {
c.conn = nil
return "", fmt.Errorf("failed to read response: %w", err)
}
return strings.TrimSpace(response), nil
}
func (c *Client) GetStatus() (*Status, error) {
resp, err := c.sendCommand("status")
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
if err != nil {
return nil, err
}
<<<<<<< HEAD
var antennas []Antenna
// Response format: R<id>|0|antenna <num> name=<name> tx=<hex> rx=<hex> inband=<hex> hotkey=<num>
@@ -405,58 +333,10 @@ func (c *Client) parseAntennaLine(line string) Antenna {
func (c *Client) subscribeToPortUpdates() error {
resp, err := c.sendCommand("sub port all")
=======
return c.parseStatus(resp)
}
func (c *Client) parseStatus(resp string) (*Status, error) {
status := &Status{
Connected: true,
}
// Parse response format from 4O3A API
// Expected format will vary - this is a basic parser
pairs := strings.Fields(resp)
for _, pair := range pairs {
parts := strings.SplitN(pair, "=", 2)
if len(parts) != 2 {
continue
}
key := parts[0]
value := parts[1]
switch key {
case "radio1", "r1":
status.Radio1Antenna, _ = strconv.Atoi(value)
case "radio2", "r2":
status.Radio2Antenna, _ = strconv.Atoi(value)
}
}
return status, nil
}
// SetRadioAntenna sets which antenna a radio should use
// radio: 1 or 2
// antenna: 0-7 (antenna index)
func (c *Client) SetRadioAntenna(radio int, antenna int) error {
if radio < 1 || radio > 2 {
return fmt.Errorf("radio must be 1 or 2")
}
if antenna < 0 || antenna > 7 {
return fmt.Errorf("antenna must be between 0 and 7")
}
cmd := fmt.Sprintf("set radio%d=%d", radio, antenna)
resp, err := c.sendCommand(cmd)
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
if err != nil {
return err
}
<<<<<<< HEAD
// Parse initial port status from subscription response
// The response may contain S0|port messages with current status
lines := strings.Split(resp, "\n")
@@ -465,18 +345,11 @@ func (c *Client) SetRadioAntenna(radio int, antenna int) error {
if strings.HasPrefix(line, "S0|port") {
c.parsePortStatus(line)
}
=======
// Check response for success
if !strings.Contains(strings.ToLower(resp), "ok") && resp != "" {
// If response doesn't contain "ok" but isn't empty, assume success
// (some devices may return the new state instead of "ok")
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
}
return nil
}
<<<<<<< HEAD
func (c *Client) parsePortStatus(line string) {
// Format: S0|port <id> auto=<0|1> source=<src> band=<n> freq=<f> nickname=<name> rxant=<n> txant=<n> inband=<n> tx=<0|1> inhibit=<n>
@@ -561,21 +434,4 @@ func (c *Client) SetAntenna(port, antenna int) error {
func (c *Client) Reboot() error {
_, err := c.sendCommand("reboot")
return err
=======
// GetRadioAntenna gets which antenna a radio is currently using
func (c *Client) GetRadioAntenna(radio int) (int, error) {
if radio < 1 || radio > 2 {
return -1, fmt.Errorf("radio must be 1 or 2")
}
status, err := c.GetStatus()
if err != nil {
return -1, err
}
if radio == 1 {
return status.Radio1Antenna, nil
}
return status.Radio2Antenna, nil
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
}

View File

@@ -3,10 +3,7 @@ package powergenius
import (
"bufio"
"fmt"
<<<<<<< HEAD
=======
"log"
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
"math"
"net"
"strconv"
@@ -26,6 +23,10 @@ type Client struct {
statusMu sync.RWMutex
stopChan chan struct{}
running bool
// Auto fan management
autoFanEnabled bool
lastFanMode string // Remember last manual mode
}
type Status struct {
@@ -45,17 +46,19 @@ type Status struct {
BandB string `json:"band_b"`
FaultPresent bool `json:"fault_present"`
Connected bool `json:"connected"`
<<<<<<< HEAD
=======
Meffa string `json:"meffa"`
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
// Peak hold for display (internal)
displayPower float64
peakTime time.Time
}
func New(host string, port int) *Client {
return &Client{
host: host,
port: port,
stopChan: make(chan struct{}),
host: host,
port: port,
stopChan: make(chan struct{}),
autoFanEnabled: true, // Auto fan management enabled by default
lastFanMode: "Contest", // Default to Contest mode
}
}
@@ -96,24 +99,14 @@ func (c *Client) Close() error {
// Start begins continuous polling of the device
func (c *Client) Start() error {
<<<<<<< HEAD
=======
if err := c.Connect(); err != nil {
return err
}
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
if c.running {
return nil
}
<<<<<<< HEAD
// Try to connect, but don't fail if it doesn't work
// The poll loop will keep trying
_ = c.Connect()
=======
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
c.running = true
go c.pollLoop()
@@ -128,7 +121,6 @@ func (c *Client) pollLoop() {
for {
select {
case <-ticker.C:
<<<<<<< HEAD
// Try to reconnect if not connected
c.connMu.Lock()
if c.conn == nil {
@@ -152,12 +144,6 @@ func (c *Client) pollLoop() {
status, err := c.queryStatus()
if err != nil {
// Connection lost, close and retry next tick
=======
status, err := c.queryStatus()
if err != nil {
log.Printf("PowerGenius query error: %v", err)
// Try to reconnect
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
c.connMu.Lock()
if c.conn != nil {
c.conn.Close()
@@ -165,7 +151,6 @@ func (c *Client) pollLoop() {
}
c.connMu.Unlock()
<<<<<<< HEAD
// Mark as disconnected and reset all values
c.statusMu.Lock()
c.lastStatus = &Status{
@@ -178,21 +163,37 @@ func (c *Client) pollLoop() {
// Mark as connected
status.Connected = true
=======
if err := c.Connect(); err != nil {
log.Printf("PowerGenius reconnect failed: %v", err)
// Peak hold logic - keep highest power for 1 second
now := time.Now()
if c.lastStatus != nil {
// If new power is higher, update peak
if status.PowerForward > c.lastStatus.displayPower {
status.displayPower = status.PowerForward
status.peakTime = now
} else {
// Check if peak has expired (1 second)
if now.Sub(c.lastStatus.peakTime) < 1*time.Second {
// Keep old peak
status.displayPower = c.lastStatus.displayPower
status.peakTime = c.lastStatus.peakTime
} else {
// Peak expired, use current value
status.displayPower = status.PowerForward
status.peakTime = now
}
}
continue
} else {
status.displayPower = status.PowerForward
status.peakTime = now
}
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
// Override PowerForward with display power for frontend
status.PowerForward = status.displayPower
// Merge with existing status (spontaneous messages may only update some fields)
c.statusMu.Lock()
if c.lastStatus != nil {
// Keep existing values for fields not in the new status
if status.PowerForward == 0 && c.lastStatus.PowerForward != 0 {
status.PowerForward = c.lastStatus.PowerForward
}
if status.Temperature == 0 && c.lastStatus.Temperature != 0 {
status.Temperature = c.lastStatus.Temperature
}
@@ -215,6 +216,32 @@ func (c *Client) pollLoop() {
c.lastStatus = status
c.statusMu.Unlock()
// Auto fan management based on temperature
if c.autoFanEnabled {
temp := status.Temperature
currentMode := status.FanMode
// If temp >= 60°C, switch to Broadcast
if temp >= 60.0 && currentMode != "Broadcast" {
log.Printf("PowerGenius: Temperature %.1f°C >= 60°C, switching fan to Broadcast mode", temp)
if err := c.SetFanMode("Broadcast"); err != nil {
log.Printf("PowerGenius: Failed to set fan mode: %v", err)
}
}
// If temp <= 55°C, switch back to Contest (or last manual mode)
if temp <= 55.0 && currentMode == "Broadcast" {
targetMode := c.lastFanMode
if targetMode == "" || targetMode == "Broadcast" {
targetMode = "Contest"
}
log.Printf("PowerGenius: Temperature %.1f°C <= 55°C, switching fan back to %s mode", temp, targetMode)
if err := c.SetFanMode(targetMode); err != nil {
log.Printf("PowerGenius: Failed to set fan mode: %v", err)
}
}
}
case <-c.stopChan:
return
}
@@ -361,11 +388,6 @@ func (c *Client) parseStatus(resp string) (*Status, error) {
}
case "vac":
status.Voltage, _ = strconv.ParseFloat(value, 64)
<<<<<<< HEAD
=======
case "meffa":
status.Meffa = value
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
case "vdd":
status.VDD, _ = strconv.ParseFloat(value, 64)
case "id":
@@ -430,15 +452,20 @@ func (c *Client) SetFanMode(mode string) error {
"BROADCAST": true,
}
if !validModes[mode] {
// Normalize mode to title case for comparison
modeUpper := strings.ToUpper(mode)
if !validModes[modeUpper] {
return fmt.Errorf("invalid fan mode: %s (must be STANDARD, CONTEST, or BROADCAST)", mode)
}
cmd := fmt.Sprintf("setup fanmode=%s", mode)
// Remember last manual mode (if not triggered by auto-fan)
// We store it in title case: "Standard", "Contest", "Broadcast"
c.lastFanMode = strings.Title(strings.ToLower(mode))
cmd := fmt.Sprintf("setup fanmode=%s", modeUpper)
_, err := c.sendCommand(cmd)
return err
}
<<<<<<< HEAD
// SetOperate sets the operate mode
// value can be: 0 (STANDBY) or 1 (OPERATE)
@@ -451,5 +478,3 @@ func (c *Client) SetOperate(value int) error {
_, err := c.sendCommand(cmd)
return err
}
=======
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7

View File

@@ -8,8 +8,6 @@ import (
"strings"
"sync"
"time"
. "git.rouggy.com/rouggy/ShackMaster/internal/devices"
)
type Client struct {
@@ -151,18 +149,7 @@ func (c *Client) sendCommand(cmd string) error {
return fmt.Errorf("not connected")
}
<<<<<<< HEAD
_, err := c.conn.Write([]byte(cmd))
=======
// Get next command ID from global counter
cmdID := GetGlobalCommandID().GetNextID()
// Format command with ID: C<id>|<command>
fullCmd := fmt.Sprintf("C%d%s", cmdID, cmd)
// Send command
_, err := c.conn.Write([]byte(fullCmd))
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
if err != nil {
c.conn = nil
c.reader = nil

View File

@@ -14,7 +14,6 @@ import (
)
type Client struct {
<<<<<<< HEAD
host string
port int
conn net.Conn
@@ -23,11 +22,6 @@ type Client struct {
statusMu sync.RWMutex
stopChan chan struct{}
running bool
=======
host string
port int
conn net.Conn
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
}
type Status struct {
@@ -54,18 +48,17 @@ type Status struct {
RelayC2 int `json:"c2"`
TuningStatus string `json:"tuning_status"`
Connected bool `json:"connected"`
// Peak hold for display (internal)
displayPower float64
peakTime time.Time
}
func New(host string, port int) *Client {
return &Client{
<<<<<<< HEAD
host: host,
port: port,
stopChan: make(chan struct{}),
=======
host: host,
port: port,
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
}
}
@@ -110,7 +103,6 @@ func (c *Client) Start() error {
return nil
}
<<<<<<< HEAD
// Try to connect, but don't fail if it doesn't work
// The poll loop will keep trying
_ = c.Connect()
@@ -171,6 +163,33 @@ func (c *Client) pollLoop() {
// Mark as connected
status.Connected = true
// Peak hold logic - keep highest power for 1 second
now := time.Now()
if c.lastStatus != nil {
// If new power is higher, update peak
if status.PowerForward > c.lastStatus.displayPower {
status.displayPower = status.PowerForward
status.peakTime = now
} else {
// Check if peak has expired (1 second)
if now.Sub(c.lastStatus.peakTime) < 1*time.Second {
// Keep old peak
status.displayPower = c.lastStatus.displayPower
status.peakTime = c.lastStatus.peakTime
} else {
// Peak expired, use current value
status.displayPower = status.PowerForward
status.peakTime = now
}
}
} else {
status.displayPower = status.PowerForward
status.peakTime = now
}
// Override PowerForward with display power for frontend
status.PowerForward = status.displayPower
c.statusMu.Lock()
c.lastStatus = status
c.statusMu.Unlock()
@@ -221,8 +240,6 @@ func (c *Client) sendCommand(cmd string) (string, error) {
return "", fmt.Errorf("not connected")
}
=======
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
// Get next command ID from global counter
cmdID := GetGlobalCommandID().GetNextID()

View File

@@ -142,12 +142,8 @@ func (c *Client) GetStatus() (*Status, error) {
// Parse response format: "1,1\n2,1\n3,1\n4,1\n5,0\n"
status := &Status{
<<<<<<< HEAD
Relays: make([]RelayState, 0, 5),
Connected: true,
=======
Relays: make([]RelayState, 0, 5),
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
}
lines := strings.Split(strings.TrimSpace(string(body)), "\n")