feat(rotator): one list of rotator interfaces, and ERC-M

The satellite page configured its own EasyComm or PstRotator link while five
other backends were configured in the rotator list. An operator with one az/el
mast therefore described it twice, and could describe it differently the second
time — a station that works on HF and not on a pass, for no reason visible
anywhere on screen.

Now every interface lives in Settings ▸ Rotator, once, and the satellite page
stores only a KEY into that list plus the tracking policy that is genuinely its
own (minimum elevation, step, park). The key and not the index: deleting the
first rotor must not silently point the tracker at a different mast.
migrateSatRotator() turns an existing satellite link into a real entry in the
list, selects it, and clears the old keys so it cannot run twice.

Which rotors have an elevation axis is now a question with one answer, in Go:
rotatorTypes plus rotorHasElevation, exposed to the panel by GetRotatorTypes.
The dropdown, the labels, each backend's default port and default baud all come
from there, so TypeScript no longer keeps a second copy of the same knowledge to
drift out of step. Three cases do not follow from the type alone and are treated
as such: PstRotator forwards elevation to a mast that may not have any, so the
operator says; a SPID's dialect decides (Rot1Prog has no elevation in its reply
format); and an ARCO and an ERC-M speak the same GS-232 while only one of them
lifts.

Each interface carries an Az / Az+El badge beside it. The satellite rotor
dropdown LISTS the azimuth-only ones, disabled, rather than hiding them: an
operator who owns one rotator and does not see it concludes OpsLog cannot find
it, where a greyed row saying "azimuth only" teaches the actual thing.

ERC-M by DF9GR is new — the az/el interface for a Yaesu G-5500. It emulates
GS-232, so internal/rotator/gs232 grew the elevation half: W for a two-axis
move, C2 to read both, falling back to C+B for the firmware that answers C2 with
the azimuth alone. That fallback is the point of the parser tests: reading such
a reply as "elevation zero" would put the antenna on the horizon, which is the
one wrong answer that looks plausible.

EasyComm II is promoted to an ordinary rotator interface, so it can also turn
the antenna from the compass and from a spot click.

The ERC-M is UNTESTED on hardware. Its Test button reads BOTH axes rather than
just the azimuth, so a controller wired for azimuth alone says so there instead
of during a pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
2026-09-09 11:04:04 +02:00
co-authored by Claude Opus 5
parent 8b1dff581b
commit ca81d4fc68
14 changed files with 1027 additions and 305 deletions
+161 -39
View File
@@ -1,16 +1,18 @@
package main
// The two ways a satellite station points its antenna.
// How a satellite station points its antenna.
//
// Some operators drive their az/el rotator directly — EasyComm II, what
// SatPC32 and Gpredict speak. Others already run PstRotator, which sits between
// them and a dozen different controllers and handles az AND el; for those,
// OpsLog talking to the controller itself would be a second program fighting
// PstRotator over the same cable.
// It does NOT configure a rotator. Every rotator interface OpsLog knows lives in
// Settings ▸ Rotator, once, and the satellite page only CHOOSES one of them.
// The two used to be separate: EasyComm and PstRotator were described inside the
// satellite settings while five other backends were described in the rotator
// list, so an operator with one mast described it twice — and could describe it
// differently the second time, which is a station that works on HF and not on a
// pass, for no reason anyone can see.
//
// So both, behind one small interface, chosen in Settings. Neither is more
// "correct" than the other: the right one is whichever the station already has
// working.
// What remains here is the adapter: turning whichever backend the operator
// picked into the three things a pass needs — point it, ask where it is, let go
// of it at the end.
import (
"fmt"
@@ -18,8 +20,9 @@ import (
"strings"
"sync"
"hamlog/internal/rotator/easycomm"
"hamlog/internal/rotator/gs232"
"hamlog/internal/rotator/pst"
"hamlog/internal/rotator/spid"
)
// satRotator is what the tracker needs of an antenna: point it, ask where it
@@ -33,41 +36,165 @@ type satRotator interface {
Close()
}
// The rotator kinds, as stored.
// The legacy satellite-only rotator kinds. They are no longer stored; they
// survive only so migrateSatRotator can read what an operator configured before
// the rotator list existed.
const (
satRotEasycomm = "easycomm"
satRotPst = "pstrotator"
)
// newSatRotator builds the configured controller.
func newSatRotator(s SatSettings) (satRotator, error) {
switch s.RotType {
case satRotPst:
if strings.TrimSpace(s.RotHost) == "" && s.RotPort <= 0 {
return nil, fmt.Errorf("no address for PstRotator")
}
return &pstSatRotator{c: pst.New(s.RotHost, s.RotPstPort), maxAz: s.RotMaxAz}, nil
default:
if s.RotTransport == "tcp" {
if strings.TrimSpace(s.RotHost) == "" {
return nil, fmt.Errorf("no address for the rotator")
}
return easycomm.New(s.RotHost, s.RotPort, s.RotMaxAz), nil
}
if strings.TrimSpace(s.RotCOM) == "" {
return nil, fmt.Errorf("no COM port for the rotator")
}
return easycomm.NewSerial(s.RotCOM, s.RotBaud, s.RotMaxAz), nil
// newSatRotator builds a controller for the rotor the satellite page selected.
func (a *App) newSatRotator(s SatSettings) (satRotator, error) {
if strings.TrimSpace(s.RotID) == "" {
return nil, fmt.Errorf("no rotator chosen for satellite tracking — pick one in Settings ▸ Satellite")
}
lr, ok := a.rotorByKey(s.RotID)
if !ok {
// The rotor was deleted from the list after being chosen here. Say that,
// rather than failing to connect to an address nobody can see any more.
return nil, fmt.Errorf("the rotator chosen for satellite tracking no longer exists in Settings ▸ Rotator")
}
if !lr.HasEl {
name := strings.TrimSpace(lr.Name)
if name == "" {
name = "this rotator"
}
return nil, fmt.Errorf("%s has no elevation axis — a satellite pass needs one", name)
}
l := lr.Link
switch l.Type {
case "pst":
return &pstSatRotator{c: pst.New(l.Host, l.Port), maxAz: l.MaxAz}, nil
case "easycomm":
return easycommClient(l), nil
case "erc":
return &gs232SatRotator{c: ercClient(l), maxAz: l.MaxAz}, nil
case "spid":
return &spidSatRotator{c: spidClient(l)}, nil
default:
return nil, fmt.Errorf("the %s backend cannot be pointed in elevation", l.Type)
}
}
// SatelliteRotorChoice is one entry in the satellite page's rotator dropdown.
type SatelliteRotorChoice struct {
Key string `json:"key"`
// Name is the operator's label; Type is the backend's, for the rotors left
// unnamed (a list of three blank rows is a list of one rotor as far as
// anybody can tell).
Name string `json:"name"`
Type string `json:"type"`
HasEl bool `json:"has_el"`
}
// ListSatelliteRotors returns every configured rotor, elevation-capable or not.
//
// Not filtered to the az/el ones, deliberately. An operator who owns exactly one
// rotator and does not see it in this list concludes OpsLog cannot find it; shown
// with "azimuth only" beside it, they learn the actual thing — that the tracker
// needs an elevation axis and this mast has none.
func (a *App) ListSatelliteRotors() ([]SatelliteRotorChoice, error) {
devs, err := a.GetRotators()
if err != nil {
return nil, err
}
out := []SatelliteRotorChoice{}
for _, r := range flattenRotors(devs) {
out = append(out, SatelliteRotorChoice{
Key: r.Key, Name: r.Name, Type: rotorTypeInfo(r.Link.Type).Label, HasEl: r.HasEl,
})
}
return out, nil
}
// gs232SatRotator points an ERC-M (or any GS-232 az/el controller) through the
// W command.
//
// The 450° overlap is handled HERE and not in the package, the same way the
// EasyComm client does it: a controller reports 0-450 and takes 0-450, but the
// tracker works in true bearings, and which of the two ways round to reach 010°
// depends on where the mast currently is.
type gs232SatRotator struct {
c *gs232.Client
maxAz int
}
func (g *gs232SatRotator) Point(az, el float64) error {
return g.c.GoToAzEl(int(math.Round(satWrapAz(az, g.maxAz))), int(math.Round(clampEl(el))))
}
func (g *gs232SatRotator) Heading() (float64, float64, bool, error) {
az, el, _, err := g.c.Position()
if err != nil {
return 0, 0, false, err
}
return float64(az), float64(el), true, nil
}
// Close: nothing to release. The serial port is held by the gs232 package, which
// keeps it open across the whole session on purpose — an Arduino-based
// controller reboots every time its port is opened.
func (g *gs232SatRotator) Close() {}
// spidSatRotator points a SPID Rot2Prog. Its protocol is absolute and binary,
// with no overlap notion to manage: the controller is told a bearing and a
// resolution and works out its own path.
type spidSatRotator struct{ c *spid.Client }
func (s *spidSatRotator) Point(az, el float64) error {
a := math.Mod(az, 360)
if a < 0 {
a += 360
}
return s.c.GoTo(int(math.Round(a)), int(math.Round(clampEl(el))))
}
func (s *spidSatRotator) Heading() (float64, float64, bool, error) {
az, el, err := s.c.Heading()
if err != nil {
return 0, 0, false, err
}
return float64(az), float64(el), true, nil
}
func (s *spidSatRotator) Close() {}
// satWrapAz maps a true bearing onto what the controller accepts. On a 450°
// mast the far end of the overlap is reachable two ways and the higher number is
// chosen for the last 90°, which is what keeps a pass crossing north from
// unwinding the cable in the middle of it.
func satWrapAz(az float64, maxAz int) float64 {
a := math.Mod(az, 360)
if a < 0 {
a += 360
}
if maxAz == 450 && a < 90 {
return a + 360
}
return a
}
// clampEl keeps the elevation inside what a mast will accept. 180 and not 90: a
// G-5500 goes past the zenith and keeps counting, which is how an overhead pass
// is followed without swinging the azimuth 180° through the middle of it.
func clampEl(el float64) float64 {
if el < 0 {
return 0
}
if el > 180 {
return 180
}
return el
}
// pstSatRotator points the antenna through PstRotator.
//
// PstRotator takes whole degrees and does its own overlap handling for a 450°
// rotator — it knows which controller is on the other end, and OpsLog does not.
// So the azimuth is sent plainly, and the 450° logic that EasyComm needs is
// deliberately NOT applied here: two programs each deciding to go the long way
// round is how an antenna ends up unwinding in the middle of a pass.
// So the azimuth is sent plainly, and the 450° logic that the direct backends
// need is deliberately NOT applied here: two programs each deciding to go the
// long way round is how an antenna ends up unwinding in the middle of a pass.
type pstSatRotator struct {
c *pst.Client
maxAz int
@@ -87,12 +214,7 @@ func (p *pstSatRotator) Point(az, el float64) error {
if a < 0 {
a += 360
}
if el < 0 {
el = 0
}
if el > 180 {
el = 180
}
el = clampEl(el)
if err := p.c.GoTo(int(math.Round(a)), true, int(math.Round(el))); err != nil {
return err
}