Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3f966f5b7 | ||
|
|
38c838d232 | ||
|
|
7eb734d86f | ||
|
|
b49599150c | ||
|
|
331db58705 | ||
|
|
62e20de69c | ||
|
|
480d24384b | ||
|
|
c2ff0f714a | ||
|
|
fe2affc72f | ||
|
|
be0326c862 | ||
|
|
8113557015 | ||
|
|
3def789742 | ||
|
|
92ea98bcfa | ||
|
|
15649a4e92 | ||
|
|
a6842382b2 | ||
|
|
5bf7eb45d7 | ||
|
|
09f3ddaacb | ||
|
|
ca8617c891 |
@@ -59,6 +59,7 @@ import (
|
|||||||
"hamlog/internal/rotator/dcu1"
|
"hamlog/internal/rotator/dcu1"
|
||||||
"hamlog/internal/rotator/gs232"
|
"hamlog/internal/rotator/gs232"
|
||||||
"hamlog/internal/rotator/pst"
|
"hamlog/internal/rotator/pst"
|
||||||
|
"hamlog/internal/rotator/spid"
|
||||||
"hamlog/internal/rotgenius"
|
"hamlog/internal/rotgenius"
|
||||||
"hamlog/internal/scp"
|
"hamlog/internal/scp"
|
||||||
"hamlog/internal/settings"
|
"hamlog/internal/settings"
|
||||||
@@ -14119,8 +14120,9 @@ func (a *App) ActivateProfile(id int64) error {
|
|||||||
|
|
||||||
// reloadAfterProfileSwitch re-applies all settings-derived state for the newly
|
// reloadAfterProfileSwitch re-applies all settings-derived state for the newly
|
||||||
// active profile: lookup providers, upload-service accounts, CAT connection,
|
// active profile: lookup providers, upload-service accounts, CAT connection,
|
||||||
// and the QSO recorder (audio devices). The Winkeyer stays as-is (the operator
|
// the station hardware, and the QSO recorder (audio devices). The Winkeyer
|
||||||
// connects it explicitly). The frontend reloads its panels via profile:changed.
|
// stays as-is (the operator connects it explicitly). The frontend reloads its
|
||||||
|
// panels via profile:changed.
|
||||||
func (a *App) reloadAfterProfileSwitch() {
|
func (a *App) reloadAfterProfileSwitch() {
|
||||||
a.reloadLookupProviders()
|
a.reloadLookupProviders()
|
||||||
if a.extsvc != nil {
|
if a.extsvc != nil {
|
||||||
@@ -14130,6 +14132,21 @@ func (a *App) reloadAfterProfileSwitch() {
|
|||||||
// runs from ActivateProfile, a click, and a rig that is slow to release would
|
// runs from ActivateProfile, a click, and a rig that is slow to release would
|
||||||
// otherwise freeze the switch.
|
// otherwise freeze the switch.
|
||||||
a.restartAsync("cat", a.reloadCAT)
|
a.restartAsync("cat", a.reloadCAT)
|
||||||
|
// Every device below is configured PER PROFILE, and none of them used to
|
||||||
|
// follow the profile: they were built once at startup and again only when
|
||||||
|
// Settings was saved. An operator with an SPE on COM9 for HF and another on
|
||||||
|
// COM10 for 6 m — one amplifier per profile, which is the whole point of
|
||||||
|
// having two — switched profile and stayed connected to the previous port,
|
||||||
|
// then had to open Settings and press Save to get the right one. Save is not
|
||||||
|
// a connect button; switching profile is what asks for this hardware.
|
||||||
|
//
|
||||||
|
// Unconditional, exactly as a save is: the alternative is comparing every
|
||||||
|
// device's configuration between profiles, and a needless reconnect on a
|
||||||
|
// profile switch costs a second, while a missed one costs the amplifier.
|
||||||
|
a.restartAsync("amp", a.startAmps)
|
||||||
|
a.restartAsync("antenna", a.startUltrabeam)
|
||||||
|
a.restartAsync("antgenius", a.startAntGenius)
|
||||||
|
a.restartAsync("tuner", a.startTunerGenius)
|
||||||
a.startQSORecorderIfEnabled()
|
a.startQSORecorderIfEnabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14186,6 +14203,10 @@ type RotatorDevice struct {
|
|||||||
Transport string `json:"transport"` // ARCO: "tcp" (LAN) | "serial" (USB COM)
|
Transport string `json:"transport"` // ARCO: "tcp" (LAN) | "serial" (USB COM)
|
||||||
ComPort string `json:"com_port"` // GS-232 serial transport
|
ComPort string `json:"com_port"` // GS-232 serial transport
|
||||||
Baud int `json:"baud"` // GS-232 serial baud (an ERC needs it; an ARCO ignores it)
|
Baud int `json:"baud"` // GS-232 serial baud (an ERC needs it; an ARCO ignores it)
|
||||||
|
// SpidModel picks the SPID dialect: "rot2prog" (RAS/BIG-RAS/MD-01/MD-02,
|
||||||
|
// azimuth + elevation) or "rot1prog" (the older azimuth-only controller).
|
||||||
|
// They differ in reply length and baud rate, so guessing is not an option.
|
||||||
|
SpidModel string `json:"spid_model,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// logicalRotor is one addressable rotor. Flattening the device list expands a
|
// logicalRotor is one addressable rotor. Flattening the device list expands a
|
||||||
@@ -14198,7 +14219,7 @@ type logicalRotor struct {
|
|||||||
|
|
||||||
// normRotorType clamps a rotor type to a known backend.
|
// normRotorType clamps a rotor type to a known backend.
|
||||||
func normRotorType(t string) string {
|
func normRotorType(t string) string {
|
||||||
if t == "rotgenius" || t == "arco" || t == "dcu1" {
|
if t == "rotgenius" || t == "arco" || t == "dcu1" || t == "spid" {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
return "pst"
|
return "pst"
|
||||||
@@ -14224,6 +14245,7 @@ func deviceLink(d RotatorDevice, sub int) rotorLink {
|
|||||||
l := rotorLink{
|
l := rotorLink{
|
||||||
Type: normRotorType(d.Type), Host: d.Host, Port: d.Port,
|
Type: normRotorType(d.Type), Host: d.Host, Port: d.Port,
|
||||||
Transport: d.Transport, ComPort: d.ComPort, Baud: d.Baud, HasElevation: d.HasElevation,
|
Transport: d.Transport, ComPort: d.ComPort, Baud: d.Baud, HasElevation: d.HasElevation,
|
||||||
|
SpidModel: d.SpidModel,
|
||||||
}
|
}
|
||||||
if l.Host == "" {
|
if l.Host == "" {
|
||||||
l.Host = "127.0.0.1"
|
l.Host = "127.0.0.1"
|
||||||
@@ -14232,8 +14254,13 @@ func deviceLink(d RotatorDevice, sub int) rotorLink {
|
|||||||
l.Port = rotatorDefaultPort(l.Type)
|
l.Port = rotatorDefaultPort(l.Type)
|
||||||
}
|
}
|
||||||
if l.Baud <= 0 {
|
if l.Baud <= 0 {
|
||||||
|
// A SPID runs at 600 or 1200 baud depending on the dialect; 0 lets its
|
||||||
|
// driver pick, and forcing 9600 here would have made every controller
|
||||||
|
// mute for a reason nobody would guess.
|
||||||
|
if l.Type != "spid" {
|
||||||
l.Baud = 9600
|
l.Baud = 9600
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if l.Transport != "serial" {
|
if l.Transport != "serial" {
|
||||||
l.Transport = "tcp"
|
l.Transport = "tcp"
|
||||||
}
|
}
|
||||||
@@ -14368,6 +14395,7 @@ type rotorLink struct {
|
|||||||
ComPort string
|
ComPort string
|
||||||
Baud int
|
Baud int
|
||||||
HasElevation bool
|
HasElevation bool
|
||||||
|
SpidModel string // SPID: "rot2prog" (default) | "rot1prog"
|
||||||
}
|
}
|
||||||
|
|
||||||
// activeRotorIndex returns the compass-selected rotor index, clamped to the
|
// activeRotorIndex returns the compass-selected rotor index, clamped to the
|
||||||
@@ -14415,6 +14443,22 @@ func dcu1Client(l rotorLink) *dcu1.Client {
|
|||||||
return dcu1.New(l.Host, l.Port)
|
return dcu1.New(l.Host, l.Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// spidClient builds the SPID (AlfaSpid) client for a rotor.
|
||||||
|
//
|
||||||
|
// Serial only, and that is the point: these controllers have a COM port and
|
||||||
|
// nothing else. The request this answers was to drive them WITHOUT PstRotator
|
||||||
|
// sitting in between, so there is no network transport to offer.
|
||||||
|
//
|
||||||
|
// Baud 0 lets the driver take the dialect's documented default — 600 baud for
|
||||||
|
// Rot2Prog, 1200 for Rot1Prog. Those numbers look wrong and are not.
|
||||||
|
func spidClient(l rotorLink) *spid.Client {
|
||||||
|
m := spid.Rot2Prog
|
||||||
|
if l.SpidModel == string(spid.Rot1Prog) {
|
||||||
|
m = spid.Rot1Prog
|
||||||
|
}
|
||||||
|
return spid.New(l.ComPort, l.Baud, m)
|
||||||
|
}
|
||||||
|
|
||||||
// RotatorHeading is the live antenna heading for the status bar and compass.
|
// RotatorHeading is the live antenna heading for the status bar and compass.
|
||||||
type RotatorHeading struct {
|
type RotatorHeading struct {
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
@@ -14481,6 +14525,16 @@ func (a *App) GetRotatorHeading() RotatorHeading {
|
|||||||
base.Azimuth = az
|
base.Azimuth = az
|
||||||
base.Raw = raw
|
base.Raw = raw
|
||||||
return base
|
return base
|
||||||
|
case "spid":
|
||||||
|
az, _, herr := spidClient(link).Heading()
|
||||||
|
if herr != nil {
|
||||||
|
base.Raw = herr.Error()
|
||||||
|
return base
|
||||||
|
}
|
||||||
|
base.OK = true
|
||||||
|
base.Azimuth = az
|
||||||
|
base.Raw = fmt.Sprintf("%d°", az)
|
||||||
|
return base
|
||||||
case "dcu1":
|
case "dcu1":
|
||||||
az, raw, herr := dcu1Client(link).Heading()
|
az, raw, herr := dcu1Client(link).Heading()
|
||||||
if herr != nil {
|
if herr != nil {
|
||||||
@@ -14531,6 +14585,8 @@ func (a *App) RotatorGoToPath(az int, el int, path string) error {
|
|||||||
return rotgenius.New(link.Host, link.Port).GoTo(link.Num, az)
|
return rotgenius.New(link.Host, link.Port).GoTo(link.Num, az)
|
||||||
case "arco":
|
case "arco":
|
||||||
return arcoClient(link).GoTo(az)
|
return arcoClient(link).GoTo(az)
|
||||||
|
case "spid":
|
||||||
|
return spidClient(link).GoTo(az, el)
|
||||||
case "dcu1":
|
case "dcu1":
|
||||||
return dcu1Client(link).GoTo(az)
|
return dcu1Client(link).GoTo(az)
|
||||||
default:
|
default:
|
||||||
@@ -14550,6 +14606,8 @@ func (a *App) RotatorStop() error {
|
|||||||
return rotgenius.New(link.Host, link.Port).Stop()
|
return rotgenius.New(link.Host, link.Port).Stop()
|
||||||
case "arco":
|
case "arco":
|
||||||
return arcoClient(link).Stop()
|
return arcoClient(link).Stop()
|
||||||
|
case "spid":
|
||||||
|
return spidClient(link).Stop()
|
||||||
case "dcu1":
|
case "dcu1":
|
||||||
return dcu1Client(link).Stop()
|
return dcu1Client(link).Stop()
|
||||||
default:
|
default:
|
||||||
@@ -14570,6 +14628,8 @@ func (a *App) RotatorPark() error {
|
|||||||
return fmt.Errorf("park is a PstRotator feature; not available on the Rotator Genius")
|
return fmt.Errorf("park is a PstRotator feature; not available on the Rotator Genius")
|
||||||
case "arco":
|
case "arco":
|
||||||
return fmt.Errorf("park is a PstRotator feature; not available over the ARCO GS-232 link")
|
return fmt.Errorf("park is a PstRotator feature; not available over the ARCO GS-232 link")
|
||||||
|
case "spid":
|
||||||
|
return fmt.Errorf("park is a PstRotator feature; a SPID controller has no park command")
|
||||||
case "dcu1":
|
case "dcu1":
|
||||||
return fmt.Errorf("park is a PstRotator feature; not available over the DCU-1 link")
|
return fmt.Errorf("park is a PstRotator feature; not available over the DCU-1 link")
|
||||||
default:
|
default:
|
||||||
@@ -14610,6 +14670,15 @@ func testRotorLink(l rotorLink) error {
|
|||||||
// GS-232 — without moving the antenna.
|
// GS-232 — without moving the antenna.
|
||||||
_, _, err := arcoClient(l).Heading()
|
_, _, err := arcoClient(l).Heading()
|
||||||
return err
|
return err
|
||||||
|
case "spid":
|
||||||
|
if strings.TrimSpace(l.ComPort) == "" {
|
||||||
|
return fmt.Errorf("select the SPID controller's COM port first")
|
||||||
|
}
|
||||||
|
// A status read proves the port, the baud rate and the dialect at once,
|
||||||
|
// without moving anything — and a wrong dialect shows up here as a reply
|
||||||
|
// of the wrong length rather than as an antenna that turns oddly later.
|
||||||
|
_, _, err := spidClient(l).Heading()
|
||||||
|
return err
|
||||||
case "dcu1":
|
case "dcu1":
|
||||||
if l.Transport == "serial" && strings.TrimSpace(l.ComPort) == "" {
|
if l.Transport == "serial" && strings.TrimSpace(l.ComPort) == "" {
|
||||||
return fmt.Errorf("select the DCU-1 controller's COM port first")
|
return fmt.Errorf("select the DCU-1 controller's COM port first")
|
||||||
@@ -14704,6 +14773,13 @@ func buildDeviceDriver(d StationDevice) relaydev.Device {
|
|||||||
case "usbrelay":
|
case "usbrelay":
|
||||||
// Host carries the COM port (e.g. "COM5"); CH340/LCUS "A0" serial protocol.
|
// Host carries the COM port (e.g. "COM5"); CH340/LCUS "A0" serial protocol.
|
||||||
return relaydev.NewSerialRelay(d.Host, deviceRelayCount(d))
|
return relaydev.NewSerialRelay(d.Host, deviceRelayCount(d))
|
||||||
|
case "httpgen":
|
||||||
|
// The whole board lives in its URLs — Host is not used at all, which is
|
||||||
|
// why it may be left empty. Leaving this case out is what made the
|
||||||
|
// generic board fall through to the WebSwitch driver below: it answered
|
||||||
|
// the WebSwitch's own address, never sent one configured URL, and
|
||||||
|
// reported itself offline so every relay button stayed greyed out.
|
||||||
|
return relaydev.NewHTTPGeneric(d.OnURLs, d.OffURLs, d.OnPat, d.OffPat, d.User, d.Pass, deviceRelayCount(d), d.Labels)
|
||||||
default:
|
default:
|
||||||
return relaydev.NewWebswitch(d.Host)
|
return relaydev.NewWebswitch(d.Host)
|
||||||
}
|
}
|
||||||
@@ -14712,7 +14788,20 @@ func buildDeviceDriver(d StationDevice) relaydev.Device {
|
|||||||
// deviceKey is the config signature that, when unchanged, lets us reuse a device's
|
// deviceKey is the config signature that, when unchanged, lets us reuse a device's
|
||||||
// open driver (and its OS handle) instead of rebuilding it every poll.
|
// open driver (and its OS handle) instead of rebuilding it every poll.
|
||||||
func deviceKey(d StationDevice) string {
|
func deviceKey(d StationDevice) string {
|
||||||
return fmt.Sprintf("%s|%s|%s|%s|%d", d.Type, d.Host, d.User, d.Pass, deviceRelayCount(d))
|
k := fmt.Sprintf("%s|%s|%s|%s|%d", d.Type, d.Host, d.User, d.Pass, deviceRelayCount(d))
|
||||||
|
if d.Type == "httpgen" {
|
||||||
|
// The generic board's entire configuration is its URLs, and none of it is
|
||||||
|
// in the signature above. Correcting a typo in one of them would have
|
||||||
|
// handed back the cached driver still holding the wrong address, so the
|
||||||
|
// fix appeared to do nothing until OpsLog was restarted.
|
||||||
|
k += "|" + d.OnPat + "|" + d.OffPat +
|
||||||
|
"|" + strings.Join(d.OnURLs, "\x1f") + "|" + strings.Join(d.OffURLs, "\x1f") +
|
||||||
|
// The labels are part of the wire format here: {value} sends them.
|
||||||
|
// Renaming a relay re-addresses it, and the cached driver would keep
|
||||||
|
// commanding the old name.
|
||||||
|
"|" + strings.Join(d.Labels, "\x1f")
|
||||||
|
}
|
||||||
|
return k
|
||||||
}
|
}
|
||||||
|
|
||||||
// driverFor returns the cached, still-open driver for a device, building it once
|
// driverFor returns the cached, still-open driver for a device, building it once
|
||||||
@@ -15811,13 +15900,24 @@ func (a *App) restartMotorFollow(s UltrabeamSettings) {
|
|||||||
close(a.ubFollowStop)
|
close(a.ubFollowStop)
|
||||||
a.ubFollowStop = nil
|
a.ubFollowStop = nil
|
||||||
}
|
}
|
||||||
if !s.Follow || a.motorAnt == nil {
|
// Say WHICH of the two reasons it is. "follow loop stopped" covered both, and
|
||||||
applog.Printf("ultrabeam: follow loop stopped")
|
// at startup — where nothing was running to stop — it read as a fault. An
|
||||||
|
// operator whose antenna sat at 21050 while the rig worked 21074 sent a log
|
||||||
|
// that said the antenna had started, answered every poll, and had its follow
|
||||||
|
// loop "stopped": three lines that together looked like a link going dead,
|
||||||
|
// when tracking was simply switched off and the antenna was waiting to be
|
||||||
|
// tuned by hand.
|
||||||
|
if a.motorAnt == nil {
|
||||||
|
applog.Printf("antenna: tracking not started — no antenna connected")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !s.Follow {
|
||||||
|
applog.Printf("antenna: %s connected, but TRACKING IS OFF in Settings — it will not follow the rig, and only moves when you tune it by hand", s.Type)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
stop := make(chan struct{})
|
stop := make(chan struct{})
|
||||||
a.ubFollowStop = stop
|
a.ubFollowStop = stop
|
||||||
applog.Printf("ultrabeam: follow loop restarting — covered bands %v, mode %s, step %d kHz", s.Bands, normMotorTrackMode(s.TrackMode), s.StepKHz)
|
applog.Printf("antenna: %s tracking the rig — covered bands %v, mode %s, step %d kHz", s.Type, s.Bands, normMotorTrackMode(s.TrackMode), s.StepKHz)
|
||||||
go a.ultrabeamFollowLoop(a.motorAnt, s.TrackMode, s.StepKHz, s.Bands, stop)
|
go a.ultrabeamFollowLoop(a.motorAnt, s.TrackMode, s.StepKHz, s.Bands, stop)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,48 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"version": "0.25.5",
|
||||||
|
"date": "",
|
||||||
|
"en": [
|
||||||
|
"DX cluster: when spots arrive and every one is filtered out, the panel says so, names the filters doing it and offers to clear them — it used to say “waiting for spots” beside a counter reading 76 live.",
|
||||||
|
"DX cluster: the log times the connection and the first spot, so a slow first launch can be told apart from a quiet node.",
|
||||||
|
"Generic HTTP relay: its URLs were never actually sent — fixed. {value} sends the relay's label, {relay-1} counts from zero, no host needed.",
|
||||||
|
"Switching profile now reconnects the amplifier, antenna, Antenna Genius and tuner — they stayed on the previous profile's ports until you saved Settings.",
|
||||||
|
"SteppIR: one missed reply used to wedge the link — the antenna stopped responding, with nothing at all in the log. It now recovers on its own.",
|
||||||
|
"The log now says when a motorized antenna is connected but tracking is off, instead of a line that read like a fault.",
|
||||||
|
"DXHunter spot clicks tune the rig again: the frequency it sends is read in whatever unit it uses, not always as MHz."
|
||||||
|
],
|
||||||
|
"fr": [
|
||||||
|
"Cluster DX : quand des spots arrivent et que tout est filtré, le panneau le dit, nomme les filtres responsables et propose de les effacer — il affichait « en attente de spots » à côté d’un compteur à 76 en direct.",
|
||||||
|
"Cluster DX : le journal chronomètre la connexion et le premier spot, pour distinguer un premier lancement lent d’un nœud silencieux.",
|
||||||
|
"Relais HTTP générique : ses URL n’étaient jamais envoyées — corrigé. {value} envoie le libellé du relais, {relay-1} compte de zéro, hôte inutile.",
|
||||||
|
"Changer de profil reconnecte l’ampli, l’antenne, l’Antenna Genius et le tuner — ils restaient sur les ports du profil précédent jusqu’à un Enregistrer.",
|
||||||
|
"SteppIR : une seule réponse manquée bloquait la liaison — l’antenne ne répondait plus, sans rien dans le journal. Elle se rétablit maintenant seule.",
|
||||||
|
"Le journal indique désormais qu’une antenne motorisée est connectée mais que le suivi est désactivé, au lieu d’une ligne qui ressemblait à une panne.",
|
||||||
|
"Les clics de spot DXHunter accordent à nouveau le rig : la fréquence envoyée est lue dans son unité réelle, plus toujours en MHz."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.25.4",
|
||||||
|
"date": "",
|
||||||
|
"en": [
|
||||||
|
"WinKeyer: the opening probe goes out as one write, matching a capture of a client that talks to the same K3NG keyer, and the handshake bytes are always logged so a keyer that stays silent can be diagnosed."
|
||||||
|
],
|
||||||
|
"fr": [
|
||||||
|
"WinKeyer : la sonde d’ouverture part en un seul envoi, calquée sur la capture d’un client qui dialogue avec le même manipulateur K3NG, et les octets de la poignée de main sont toujours journalisés pour diagnostiquer un manipulateur muet."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.25.3",
|
||||||
|
"date": "",
|
||||||
|
"en": [
|
||||||
|
"Confirmations: a LoTW contact marked V (verified) counted for the awards but nowhere else — the band/mode matrix, the slot statistics, the row colours and the QSL Info table all read it as unconfirmed, the last one showing it as “No”. It now reads as Verified everywhere.",
|
||||||
|
"Rotators: SPID / AlfaSpid controllers are driven natively over their own COM port — Rot2Prog and Rot1Prog — so PstRotator is no longer needed in between. Two towers means two rotors, as before."
|
||||||
|
],
|
||||||
|
"fr": [
|
||||||
|
"Confirmations : un contact LoTW marqué V (vérifié) comptait pour les diplômes et nulle part ailleurs — la matrice bande/mode, les statistiques de créneaux, la coloration des lignes et le tableau Infos QSL le lisaient comme non confirmé, le dernier l’affichant même « Non ». Il s’affiche désormais « Vérifié » partout.",
|
||||||
|
"Rotors : les contrôleurs SPID / AlfaSpid sont pilotés nativement par leur propre port COM — Rot2Prog et Rot1Prog — sans passer par PstRotator. Deux pylônes restent deux rotors, comme avant."
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"version": "0.25.2",
|
"version": "0.25.2",
|
||||||
"date": "",
|
"date": "",
|
||||||
|
|||||||
+2
-2
@@ -109,9 +109,9 @@ func probeWB(conn *sql.DB, call string, dxcc int) {
|
|||||||
SELECT band, mode,
|
SELECT band, mode,
|
||||||
MAX(CASE WHEN callsign = ? THEN 1 ELSE 0 END),
|
MAX(CASE WHEN callsign = ? THEN 1 ELSE 0 END),
|
||||||
MAX(CASE WHEN callsign = ?
|
MAX(CASE WHEN callsign = ?
|
||||||
AND (lotw_rcvd = 'Y' OR qsl_rcvd = 'Y' OR eqsl_rcvd = 'Y')
|
AND (lotw_rcvd IN ('Y','V') OR qsl_rcvd IN ('Y','V') OR eqsl_rcvd IN ('Y','V'))
|
||||||
THEN 1 ELSE 0 END),
|
THEN 1 ELSE 0 END),
|
||||||
MAX(CASE WHEN lotw_rcvd = 'Y' OR qsl_rcvd = 'Y' OR eqsl_rcvd = 'Y'
|
MAX(CASE WHEN lotw_rcvd IN ('Y','V') OR qsl_rcvd IN ('Y','V') OR eqsl_rcvd IN ('Y','V')
|
||||||
THEN 1 ELSE 0 END)
|
THEN 1 ELSE 0 END)
|
||||||
FROM qso WHERE dxcc = ?
|
FROM qso WHERE dxcc = ?
|
||||||
GROUP BY band, mode
|
GROUP BY band, mode
|
||||||
|
|||||||
+64
-2
@@ -1539,6 +1539,41 @@ export default function App() {
|
|||||||
// Hide spots already worked (exact call worked, or this band+mode slot done).
|
// Hide spots already worked (exact call worked, or this band+mode slot done).
|
||||||
const [clusterHideWorked, setClusterHideWorked] = useState(() => lsBool('opslog.clusterHideWorked', false));
|
const [clusterHideWorked, setClusterHideWorked] = useState(() => lsBool('opslog.clusterHideWorked', false));
|
||||||
|
|
||||||
|
// Everything currently narrowing the spot list, in words. Shown when spots
|
||||||
|
// arrived and none survived — the operator needs to know WHICH filter to
|
||||||
|
// loosen, and the two locks are the least memorable because they follow the
|
||||||
|
// rig rather than a click.
|
||||||
|
const clusterActiveFilterSummary = useMemo(() => {
|
||||||
|
const on: string[] = [];
|
||||||
|
if (clusterLockBand) on.push(t('clg2.fBandLock'));
|
||||||
|
else if (clusterBands.size > 0) on.push(t('clg2.fBands', { list: [...clusterBands].join(', ') }));
|
||||||
|
if (clusterLockMode) on.push(t('clg2.fModeLock'));
|
||||||
|
else if (clusterModeFilter.size > 0) on.push(t('clg2.fModes', { list: [...clusterModeFilter].join(', ') }));
|
||||||
|
if (clusterStatusFilter.size > 0) on.push(t('clg2.fStatus'));
|
||||||
|
if (clusterHideWorked) on.push(t('clg2.fHideWorked'));
|
||||||
|
if (clusterLotwOnly) on.push(t('clg2.fLotwOnly'));
|
||||||
|
if (clusterSpotterConts.size > 0) on.push(t('clg2.fSpotterCont'));
|
||||||
|
if (clusterFilterSource) on.push(t('clg2.fSource'));
|
||||||
|
if (clusterSearch.trim()) on.push(t('clg2.fSearch', { q: clusterSearch.trim() }));
|
||||||
|
return on.join(' · ');
|
||||||
|
}, [t, clusterLockBand, clusterBands, clusterLockMode, clusterModeFilter, clusterStatusFilter,
|
||||||
|
clusterHideWorked, clusterLotwOnly, clusterSpotterConts, clusterFilterSource, clusterSearch]);
|
||||||
|
|
||||||
|
// Undo every one of them at once. A list of ten switches spread down a panel
|
||||||
|
// is not something to walk back by hand when the answer is "show me anything".
|
||||||
|
const clearClusterFilters = useCallback(() => {
|
||||||
|
setClusterLockBand(false);
|
||||||
|
setClusterBands(new Set());
|
||||||
|
setClusterLockMode(false);
|
||||||
|
setClusterModeFilter(new Set());
|
||||||
|
setClusterStatusFilter(new Set());
|
||||||
|
setClusterHideWorked(false);
|
||||||
|
setClusterLotwOnly(false);
|
||||||
|
setClusterSpotterConts(new Set());
|
||||||
|
setClusterFilterSource('');
|
||||||
|
setClusterSearch('');
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Persist every cluster filter selection whenever it changes, so it is still
|
// Persist every cluster filter selection whenever it changes, so it is still
|
||||||
// set after a close/reopen.
|
// set after a close/reopen.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -6738,14 +6773,41 @@ export default function App() {
|
|||||||
// pane). All the filter state lives in the right-side panel.
|
// pane). All the filter state lives in the right-side panel.
|
||||||
const rendered = clusterRenderedRows;
|
const rendered = clusterRenderedRows;
|
||||||
if (rendered.length === 0) {
|
if (rendered.length === 0) {
|
||||||
|
const connected = clusterServerStatuses.some((s) => s.state === 'connected');
|
||||||
|
// Spots HAVE arrived and the filters ate every one of them.
|
||||||
|
//
|
||||||
|
// This used to say "Waiting for spots…" regardless, which is a
|
||||||
|
// lie the moment the counter beside it reads 76 live: an
|
||||||
|
// operator reads the two together and goes looking for a
|
||||||
|
// connection fault instead of at the filter panel. The band and
|
||||||
|
// mode locks are the usual culprits and the least visible —
|
||||||
|
// they follow the rig, so nobody remembers switching them on.
|
||||||
|
if (connected && spots.length > 0) {
|
||||||
|
return (
|
||||||
|
<div className="flex-1 flex flex-col items-center justify-center text-muted-foreground gap-2 py-12 px-6 text-center">
|
||||||
|
<SlidersHorizontal className="size-10 opacity-30" />
|
||||||
|
<div className="text-sm font-semibold text-foreground/70">
|
||||||
|
{t('clg2.allFiltered', { n: spots.length })}
|
||||||
|
</div>
|
||||||
|
{clusterActiveFilterSummary && (
|
||||||
|
<div className="text-xs max-w-md leading-relaxed">
|
||||||
|
{t('clg2.activeFilters')} <span className="font-medium text-foreground/80">{clusterActiveFilterSummary}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<Button size="sm" variant="outline" className="mt-1" onClick={clearClusterFilters}>
|
||||||
|
{t('clg2.clearAllFilters')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="flex-1 flex flex-col items-center justify-center text-muted-foreground gap-2 py-12">
|
<div className="flex-1 flex flex-col items-center justify-center text-muted-foreground gap-2 py-12">
|
||||||
<Hash className="size-10 opacity-30" />
|
<Hash className="size-10 opacity-30" />
|
||||||
<div className="text-sm font-semibold text-foreground/70">
|
<div className="text-sm font-semibold text-foreground/70">
|
||||||
{clusterServerStatuses.some((s) => s.state === 'connected') ? 'Waiting for spots…' : 'No active connection'}
|
{connected ? 'Waiting for spots…' : 'No active connection'}
|
||||||
</div>
|
</div>
|
||||||
<div className="text-xs">
|
<div className="text-xs">
|
||||||
{clusterServerStatuses.some((s) => s.state === 'connected')
|
{connected
|
||||||
? 'Spots will appear as the cluster sends them.'
|
? 'Spots will appear as the cluster sends them.'
|
||||||
: 'Use Connect all (or configure a cluster in Settings → DX Cluster).'}
|
: 'Use Connect all (or configure a cluster in Settings → DX Cluster).'}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { Button } from '@/components/ui/button';
|
|||||||
import { Checkbox } from '@/components/ui/checkbox';
|
import { Checkbox } from '@/components/ui/checkbox';
|
||||||
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '@/components/ui/select';
|
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '@/components/ui/select';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
import { isQSLConfirmed } from '@/lib/qsl';
|
||||||
import { AwardEditor } from '@/components/AwardEditor';
|
import { AwardEditor } from '@/components/AwardEditor';
|
||||||
import { useI18n } from '@/lib/i18n';
|
import { useI18n } from '@/lib/i18n';
|
||||||
import { writeUiPref } from '@/lib/uiPref';
|
import { writeUiPref } from '@/lib/uiPref';
|
||||||
@@ -818,7 +819,7 @@ function CellQSOModal({ code, cell, modeClass, onClose }: { code: string; cell:
|
|||||||
<td className="py-1 pr-2 font-mono font-semibold">{q.callsign}</td>
|
<td className="py-1 pr-2 font-mono font-semibold">{q.callsign}</td>
|
||||||
<td className="py-1 pr-2">{q.band}</td>
|
<td className="py-1 pr-2">{q.band}</td>
|
||||||
<td className="py-1 pr-2">{q.mode}</td>
|
<td className="py-1 pr-2">{q.mode}</td>
|
||||||
<td className="py-1 pr-3 text-muted-foreground">{[q.lotw_rcvd === 'Y' && 'LoTW', q.qsl_rcvd === 'Y' && 'QSL', q.eqsl_rcvd === 'Y' && 'eQSL'].filter(Boolean).join(', ')}</td>
|
<td className="py-1 pr-3 text-muted-foreground">{[isQSLConfirmed(q.lotw_rcvd) && 'LoTW', isQSLConfirmed(q.qsl_rcvd) && 'QSL', isQSLConfirmed(q.eqsl_rcvd) && 'eQSL'].filter(Boolean).join(', ')}</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Star, Radio, Sunrise, Sunset, X, Loader2 } from 'lucide-react';
|
|||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { sunTimes } from '@/lib/sun';
|
import { sunTimes } from '@/lib/sun';
|
||||||
|
import { isQSLConfirmed } from '@/lib/qsl';
|
||||||
import { BandSlotQSOs } from '../../wailsjs/go/main/App';
|
import { BandSlotQSOs } from '../../wailsjs/go/main/App';
|
||||||
import type { WorkedBeforeView } from '@/types';
|
import type { WorkedBeforeView } from '@/types';
|
||||||
|
|
||||||
@@ -426,7 +427,7 @@ function SlotQSOModal({ call, dxcc, entity, band, cls, onClose, onEdit }: {
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{rows.map((q, i) => {
|
{rows.map((q, i) => {
|
||||||
const cfm = q.lotw_rcvd === 'Y' || q.eqsl_rcvd === 'Y' || q.qsl_rcvd === 'Y';
|
const cfm = isQSLConfirmed(q.lotw_rcvd) || isQSLConfirmed(q.eqsl_rcvd) || isQSLConfirmed(q.qsl_rcvd);
|
||||||
const mine = q.callsign === call;
|
const mine = q.callsign === call;
|
||||||
return (
|
return (
|
||||||
<tr key={q.id ?? i} className="border-t border-border/40 even:bg-muted/[0.06] hover:bg-primary/[0.06] transition-colors">
|
<tr key={q.id ?? i} className="border-t border-border/40 even:bg-muted/[0.06] hover:bg-primary/[0.06] transition-colors">
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Star } from 'lucide-react';
|
import { Star } from 'lucide-react';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { useI18n } from '@/lib/i18n';
|
import { useI18n } from '@/lib/i18n';
|
||||||
|
import { isQSLConfirmed } from '@/lib/qsl';
|
||||||
import type { WorkedBeforeView } from '@/types';
|
import type { WorkedBeforeView } from '@/types';
|
||||||
|
|
||||||
type WorkedBefore = WorkedBeforeView;
|
type WorkedBefore = WorkedBeforeView;
|
||||||
@@ -97,10 +98,10 @@ export function CallHistoryPanel({ wb, busy, currentCall }: Props) {
|
|||||||
<td className="px-2 py-1 font-mono border-b border-border/40 whitespace-nowrap">{e.rst_sent ?? ''}</td>
|
<td className="px-2 py-1 font-mono border-b border-border/40 whitespace-nowrap">{e.rst_sent ?? ''}</td>
|
||||||
<td className="px-2 py-1 font-mono border-b border-border/40 whitespace-nowrap">{e.rst_rcvd ?? ''}</td>
|
<td className="px-2 py-1 font-mono border-b border-border/40 whitespace-nowrap">{e.rst_rcvd ?? ''}</td>
|
||||||
<td className="px-2 py-1 border-b border-border/40 whitespace-nowrap text-muted-foreground">
|
<td className="px-2 py-1 border-b border-border/40 whitespace-nowrap text-muted-foreground">
|
||||||
{e.lotw_rcvd === 'Y' && (
|
{isQSLConfirmed(e.lotw_rcvd) && (
|
||||||
<span className="inline-block w-[14px] h-[14px] rounded text-center leading-[14px] text-[9px] font-bold text-info-foreground bg-info mr-0.5" title={t('chp.lotwRcvd')}>L</span>
|
<span className="inline-block w-[14px] h-[14px] rounded text-center leading-[14px] text-[9px] font-bold text-info-foreground bg-info mr-0.5" title={t('chp.lotwRcvd')}>L</span>
|
||||||
)}
|
)}
|
||||||
{e.qsl_rcvd === 'Y' && (
|
{isQSLConfirmed(e.qsl_rcvd) && (
|
||||||
<span className="inline-block w-[14px] h-[14px] rounded text-center leading-[14px] text-[9px] font-bold text-success-foreground bg-success mr-0.5" title={t('chp.bureauRcvd')}>B</span>
|
<span className="inline-block w-[14px] h-[14px] rounded text-center leading-[14px] text-[9px] font-bold text-success-foreground bg-success mr-0.5" title={t('chp.bureauRcvd')}>B</span>
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -41,9 +41,14 @@ function pfxOf(call: string): string {
|
|||||||
const BANDS = ['2190m','630m','160m','80m','60m','40m','30m','20m','17m','15m','12m','10m','6m','4m','2m','1.25m','70cm','33cm','23cm','13cm','9cm','6cm','3cm','1.25cm','6mm','4mm','2.5mm','2mm','1mm'];
|
const BANDS = ['2190m','630m','160m','80m','60m','40m','30m','20m','17m','15m','12m','10m','6m','4m','2m','1.25m','70cm','33cm','23cm','13cm','9cm','6cm','3cm','1.25cm','6mm','4mm','2.5mm','2mm','1mm'];
|
||||||
const MODES = ['SSB','CW','FT8','FT4','RTTY','PSK31','AM','FM','DIGITALVOICE','MFSK','OLIVIA','JS8','JT65','JT9'];
|
const MODES = ['SSB','CW','FT8','FT4','RTTY','PSK31','AM','FM','DIGITALVOICE','MFSK','OLIVIA','JS8','JT65','JT9'];
|
||||||
// label holds an i18n key (resolved with t() at render time).
|
// label holds an i18n key (resolved with t() at render time).
|
||||||
|
// V is in the list because the log HOLDS it: a LoTW download writes "verified"
|
||||||
|
// rather than "yes". A dropdown without it renders a verified contact as blank,
|
||||||
|
// which reads as "nothing recorded" — and the operator's next click would replace
|
||||||
|
// the strongest confirmation they have with whatever they picked instead.
|
||||||
const QSL_STATUSES = [
|
const QSL_STATUSES = [
|
||||||
{ value: '_', label: 'qedit.qslDash' },
|
{ value: '_', label: 'qedit.qslDash' },
|
||||||
{ value: 'Y', label: 'qedit.qslYes' },
|
{ value: 'Y', label: 'qedit.qslYes' },
|
||||||
|
{ value: 'V', label: 'qedit.qslVerified' },
|
||||||
{ value: 'N', label: 'qedit.qslNo' },
|
{ value: 'N', label: 'qedit.qslNo' },
|
||||||
{ value: 'R', label: 'qedit.qslRequested' },
|
{ value: 'R', label: 'qedit.qslRequested' },
|
||||||
{ value: 'I', label: 'qedit.qslIgnore' },
|
{ value: 'I', label: 'qedit.qslIgnore' },
|
||||||
@@ -99,9 +104,14 @@ function StatusCell({ value }: { value?: string }) {
|
|||||||
// every row; painting that orange (as it used to be, in the
|
// every row; painting that orange (as it used to be, in the
|
||||||
// same orange as Requested) made the table shout about a
|
// same orange as Requested) made the table shout about a
|
||||||
// non-problem and told you nothing apart.
|
// non-problem and told you nothing apart.
|
||||||
|
// Verified green — ADIF's V: confirmed AND validated by the awarding body.
|
||||||
|
// It is what a LoTW download writes, and this table used
|
||||||
|
// to fall through to "No" for it — reporting a verified
|
||||||
|
// contact as unconfirmed, in the one place an operator
|
||||||
|
// goes to check.
|
||||||
// Ignore dashed — deliberately excluded, on purpose.
|
// Ignore dashed — deliberately excluded, on purpose.
|
||||||
const label = v === 'Y' ? t('qedit.qslYes') : v === 'R' ? t('qedit.qslRequested') : v === 'I' ? t('qedit.qslIgnore') : v === 'M' ? t('qedit.statusModified') : t('qedit.qslNo');
|
const label = v === 'Y' ? t('qedit.qslYes') : v === 'V' ? t('qedit.qslVerified') : v === 'R' ? t('qedit.qslRequested') : v === 'I' ? t('qedit.qslIgnore') : v === 'M' ? t('qedit.statusModified') : t('qedit.qslNo');
|
||||||
const cls = v === 'Y' ? 'bg-success text-success-foreground border border-success'
|
const cls = v === 'Y' || v === 'V' ? 'bg-success text-success-foreground border border-success'
|
||||||
: v === 'R' ? 'bg-info-muted text-info-muted-foreground border border-info-border'
|
: v === 'R' ? 'bg-info-muted text-info-muted-foreground border border-info-border'
|
||||||
: v === 'M' ? 'bg-warning text-warning-foreground border border-warning'
|
: v === 'M' ? 'bg-warning text-warning-foreground border border-warning'
|
||||||
: v === 'I' ? 'bg-muted text-muted-foreground border border-dashed border-border italic'
|
: v === 'I' ? 'bg-muted text-muted-foreground border border-dashed border-border italic'
|
||||||
|
|||||||
@@ -3674,7 +3674,10 @@ export function SettingsModal({ onClose, onSaved, initialSection, onMainPaneChan
|
|||||||
const isRG = dev.type === 'rotgenius';
|
const isRG = dev.type === 'rotgenius';
|
||||||
const isARCO = dev.type === 'arco';
|
const isARCO = dev.type === 'arco';
|
||||||
const isDCU1 = dev.type === 'dcu1';
|
const isDCU1 = dev.type === 'dcu1';
|
||||||
const isSerialCap = isARCO || isDCU1; // COM-port or serial-over-IP controllers
|
// A SPID has a COM port and nothing else — no network transport to
|
||||||
|
// offer, which is the whole point of driving it without PstRotator.
|
||||||
|
const isSPID = dev.type === 'spid';
|
||||||
|
const isSerialCap = isARCO || isDCU1 || isSPID; // COM-port or serial-over-IP controllers
|
||||||
const transport = dev.transport ?? 'tcp';
|
const transport = dev.transport ?? 'tcp';
|
||||||
return (
|
return (
|
||||||
<div key={dev.id || i} className="rounded-xl border border-border bg-card/40 p-3 space-y-3">
|
<div key={dev.id || i} className="rounded-xl border border-border bg-card/40 p-3 space-y-3">
|
||||||
@@ -3693,13 +3696,14 @@ export function SettingsModal({ onClose, onSaved, initialSection, onMainPaneChan
|
|||||||
{/* Each backend gets its default port: Rotator Genius 9006, ARCO 4001
|
{/* Each backend gets its default port: Rotator Genius 9006, ARCO 4001
|
||||||
(placeholder — must match the ARCO's LAN menu), PstRotator 12000. */}
|
(placeholder — must match the ARCO's LAN menu), PstRotator 12000. */}
|
||||||
<Select value={dev.type ?? 'pst'}
|
<Select value={dev.type ?? 'pst'}
|
||||||
onValueChange={(v) => patch(i, { type: v as any, port: v === 'rotgenius' ? 9006 : (v === 'arco' || v === 'dcu1') ? 4001 : 12000, ...(v === 'dcu1' ? { transport: 'serial' } : {}) })}>
|
onValueChange={(v) => patch(i, { type: v as any, port: v === 'rotgenius' ? 9006 : (v === 'arco' || v === 'dcu1') ? 4001 : 12000, ...(v === 'dcu1' || v === 'spid' ? { transport: 'serial' } : {}), ...(v === 'spid' ? { baud: 600, spid_model: 'rot2prog' } : {}) })}>
|
||||||
<SelectTrigger className="h-9"><SelectValue /></SelectTrigger>
|
<SelectTrigger className="h-9"><SelectValue /></SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="pst">PstRotator (UDP)</SelectItem>
|
<SelectItem value="pst">PstRotator (UDP)</SelectItem>
|
||||||
<SelectItem value="rotgenius">Rotator Genius (4O3A, native)</SelectItem>
|
<SelectItem value="rotgenius">Rotator Genius (4O3A, native)</SelectItem>
|
||||||
<SelectItem value="arco">GS-232A controller (microHAM ARCO, ERC…)</SelectItem>
|
<SelectItem value="arco">GS-232A controller (microHAM ARCO, ERC…)</SelectItem>
|
||||||
<SelectItem value="dcu1">Hy-Gain DCU-1 (RotorCard DXA, Rotor-EZ, Green Heron)</SelectItem>
|
<SelectItem value="dcu1">Hy-Gain DCU-1 (RotorCard DXA, Rotor-EZ, Green Heron)</SelectItem>
|
||||||
|
<SelectItem value="spid">SPID / AlfaSpid (RAS, BIG-RAS, MD-01, MD-02)</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
@@ -3716,8 +3720,24 @@ export function SettingsModal({ onClose, onSaved, initialSection, onMainPaneChan
|
|||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{/* SPID: pick the dialect. They differ in reply length AND baud
|
||||||
|
rate, so this cannot be detected — a wrong choice is a
|
||||||
|
controller that never answers. */}
|
||||||
|
{isSPID && (
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Label>{t('rot.spidModel')}</Label>
|
||||||
|
<Select value={dev.spid_model || 'rot2prog'}
|
||||||
|
onValueChange={(v) => patch(i, { spid_model: v as any, baud: v === 'rot1prog' ? 1200 : 600 })}>
|
||||||
|
<SelectTrigger className="h-9"><SelectValue /></SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="rot2prog">Rot2Prog (RAS, BIG-RAS/HR, MD-01, MD-02)</SelectItem>
|
||||||
|
<SelectItem value="rot1prog">Rot1Prog (azimuth only)</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{/* ARCO and DCU-1 controllers reach over the LAN (TCP) or a serial COM. */}
|
{/* ARCO and DCU-1 controllers reach over the LAN (TCP) or a serial COM. */}
|
||||||
{isSerialCap && (
|
{isSerialCap && !isSPID && (
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Label>Connection</Label>
|
<Label>Connection</Label>
|
||||||
<Select value={transport} onValueChange={(v) => patch(i, { transport: v as any })}>
|
<Select value={transport} onValueChange={(v) => patch(i, { transport: v as any })}>
|
||||||
@@ -3751,10 +3771,13 @@ export function SettingsModal({ onClose, onSaved, initialSection, onMainPaneChan
|
|||||||
<Button size="sm" variant="outline" className="h-9" onClick={() => ListSerialPorts().then((p) => setWkPorts((p ?? []) as string[])).catch(() => {})}>
|
<Button size="sm" variant="outline" className="h-9" onClick={() => ListSerialPorts().then((p) => setWkPorts((p ?? []) as string[])).catch(() => {})}>
|
||||||
<ArrowDown className="size-3.5 rotate-90" />
|
<ArrowDown className="size-3.5 rotate-90" />
|
||||||
</Button>
|
</Button>
|
||||||
<Select value={String(dev.baud || 9600)} onValueChange={(v) => patch(i, { baud: Number(v) })}>
|
{/* A SPID runs at 600 or 1200 baud — not a typo, a pulse
|
||||||
|
controller has nothing to say quickly. Offering only the
|
||||||
|
usual rates would have left it permanently mute. */}
|
||||||
|
<Select value={String(dev.baud || (isSPID ? 600 : 9600))} onValueChange={(v) => patch(i, { baud: Number(v) })}>
|
||||||
<SelectTrigger className="h-9 w-28"><SelectValue /></SelectTrigger>
|
<SelectTrigger className="h-9 w-28"><SelectValue /></SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{[4800, 9600, 19200, 38400, 57600].map((b) => (
|
{(isSPID ? [600, 1200, 2400, 4800, 9600] : [4800, 9600, 19200, 38400, 57600]).map((b) => (
|
||||||
<SelectItem key={b} value={String(b)}>{b} baud</SelectItem>
|
<SelectItem key={b} value={String(b)}>{b} baud</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
@@ -3784,6 +3807,7 @@ export function SettingsModal({ onClose, onSaved, initialSection, onMainPaneChan
|
|||||||
{isRG && <p className="text-xs text-muted-foreground">{t('rot.rgHint')}</p>}
|
{isRG && <p className="text-xs text-muted-foreground">{t('rot.rgHint')}</p>}
|
||||||
{isARCO && <p className="text-xs text-muted-foreground">{t('rot.arcoHint')}</p>}
|
{isARCO && <p className="text-xs text-muted-foreground">{t('rot.arcoHint')}</p>}
|
||||||
{isDCU1 && <p className="text-xs text-muted-foreground">{t('rot.dcu1Hint')}</p>}
|
{isDCU1 && <p className="text-xs text-muted-foreground">{t('rot.dcu1Hint')}</p>}
|
||||||
|
{isSPID && <p className="text-xs text-muted-foreground">{t('rot.spidHint')}</p>}
|
||||||
{/* Which antenna this rotor carries — only relevant with >1 rotor. */}
|
{/* Which antenna this rotor carries — only relevant with >1 rotor. */}
|
||||||
{multi && (
|
{multi && (
|
||||||
<div className="space-y-1 max-w-xs">
|
<div className="space-y-1 max-w-xs">
|
||||||
|
|||||||
@@ -527,16 +527,25 @@ export function StationControlPanel({ centerLat, centerLon, bearing }: RotatorPr
|
|||||||
const deviceCard = (dev: Device) => {
|
const deviceCard = (dev: Device) => {
|
||||||
const st = status[dev.id];
|
const st = status[dev.id];
|
||||||
const relays = st?.relays ?? dev.labels.map((label, i) => ({ number: i + 1, label, on: false }));
|
const relays = st?.relays ?? dev.labels.map((label, i) => ({ number: i + 1, label, on: false }));
|
||||||
|
// The generic HTTP board has no address of its own and nothing to poll: its
|
||||||
|
// relays can each live on a different box, and no status endpoint is read
|
||||||
|
// back. So no host under the name, no online dot, and the buttons are never
|
||||||
|
// greyed out waiting for a connection that is never made.
|
||||||
|
const fireAndForget = dev.type === 'httpgen';
|
||||||
return (
|
return (
|
||||||
<div className="rounded-xl border border-border bg-card shadow-sm overflow-hidden h-full">
|
<div className="rounded-xl border border-border bg-card shadow-sm overflow-hidden h-full">
|
||||||
<div className="flex items-center gap-2 px-3 py-2 border-b border-border/60 bg-muted/30">
|
<div className="flex items-center gap-2 px-3 py-2 border-b border-border/60 bg-muted/30">
|
||||||
<PlugZap className="size-4 text-primary" />
|
<PlugZap className="size-4 text-primary" />
|
||||||
<div className="min-w-0">
|
<div className="min-w-0">
|
||||||
<div className="text-sm font-semibold truncate">{dev.name || TYPE_LABEL[dev.type]}</div>
|
<div className="text-sm font-semibold truncate">{dev.name || TYPE_LABEL[dev.type]}</div>
|
||||||
<div className="text-[10px] text-muted-foreground font-mono truncate">{TYPE_LABEL[dev.type]} · {dev.host}</div>
|
<div className="text-[10px] text-muted-foreground font-mono truncate">
|
||||||
|
{TYPE_LABEL[dev.type]}{fireAndForget || !dev.host ? '' : ` · ${dev.host}`}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
{fireAndForget ? <span className="ml-auto" /> : (
|
||||||
<span className={cn('ml-auto size-2 rounded-full shrink-0', st?.connected ? 'bg-success' : 'bg-muted-foreground/40')}
|
<span className={cn('ml-auto size-2 rounded-full shrink-0', st?.connected ? 'bg-success' : 'bg-muted-foreground/40')}
|
||||||
title={st?.connected ? t('station.online') : (st?.error || t('station.offline'))} />
|
title={st?.connected ? t('station.online') : (st?.error || t('station.offline'))} />
|
||||||
|
)}
|
||||||
<button className="text-muted-foreground hover:text-foreground" title={t('station.edit')}
|
<button className="text-muted-foreground hover:text-foreground" title={t('station.edit')}
|
||||||
onClick={() => setEditing({ ...dev, labels: [...dev.labels] })}><Pencil className="size-3.5" /></button>
|
onClick={() => setEditing({ ...dev, labels: [...dev.labels] })}><Pencil className="size-3.5" /></button>
|
||||||
<button className="text-muted-foreground hover:text-destructive" title={t('station.delete')}
|
<button className="text-muted-foreground hover:text-destructive" title={t('station.delete')}
|
||||||
@@ -549,7 +558,7 @@ export function StationControlPanel({ centerLat, centerLon, bearing }: RotatorPr
|
|||||||
const key = `${dev.id}:${r.number}`;
|
const key = `${dev.id}:${r.number}`;
|
||||||
const label = r.label || `${t('station.relay')} ${r.number}`;
|
const label = r.label || `${t('station.relay')} ${r.number}`;
|
||||||
return (
|
return (
|
||||||
<button key={r.number} type="button" disabled={!st?.connected}
|
<button key={r.number} type="button" disabled={!fireAndForget && !st?.connected}
|
||||||
title={label}
|
title={label}
|
||||||
onClick={() => toggle(dev, r.number, !r.on)}
|
onClick={() => toggle(dev, r.number, !r.on)}
|
||||||
className={cn('w-[150px] flex items-center gap-1.5 rounded-md border px-2 py-1 text-left transition-colors disabled:opacity-40',
|
className={cn('w-[150px] flex items-center gap-1.5 rounded-md border px-2 py-1 text-left transition-colors disabled:opacity-40',
|
||||||
@@ -687,6 +696,13 @@ function DeviceEditor({ device, onChange, onSave, onCancel, t }: {
|
|||||||
const isDenkovi = device.type === 'denkovi';
|
const isDenkovi = device.type === 'denkovi';
|
||||||
const isUsbRelay = device.type === 'usbrelay';
|
const isUsbRelay = device.type === 'usbrelay';
|
||||||
const isHTTPGen = device.type === 'httpgen';
|
const isHTTPGen = device.type === 'httpgen';
|
||||||
|
// {value} sends a relay's label, so a URL using it on an unnamed relay would
|
||||||
|
// go out with an empty parameter. Warn while it is being typed rather than at
|
||||||
|
// the moment an antenna fails to switch.
|
||||||
|
const valueNeedsLabels = isHTTPGen
|
||||||
|
&& [...(device.on_urls ?? []), ...(device.off_urls ?? []), device.on_pattern ?? '', device.off_pattern ?? '']
|
||||||
|
.some((s) => (s ?? '').includes('{value}'))
|
||||||
|
&& device.labels.some((l) => !l.trim());
|
||||||
// COM ports for the generic USB-serial relay picker.
|
// COM ports for the generic USB-serial relay picker.
|
||||||
const [serialPorts, setSerialPorts] = useState<string[]>([]);
|
const [serialPorts, setSerialPorts] = useState<string[]>([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -795,7 +811,12 @@ function DeviceEditor({ device, onChange, onSave, onCancel, t }: {
|
|||||||
</div>
|
</div>
|
||||||
<p className="text-[10px] text-muted-foreground">{t('station.usbRelayHint')}</p>
|
<p className="text-[10px] text-muted-foreground">{t('station.usbRelayHint')}</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : isHTTPGen ? null : (
|
||||||
|
/* No Host for the generic board: its driver never reads one. Each URL
|
||||||
|
below carries its own address, and they need not even share it — one
|
||||||
|
relay can sit on a different box from the next. A field that changes
|
||||||
|
nothing is worse than no field: it reads as the thing to fill in first,
|
||||||
|
and then the URLs look like they should be relative to it. */
|
||||||
<div className={cn('grid gap-3', (isKM || isDingtian) ? 'grid-cols-3' : 'grid-cols-1')}>
|
<div className={cn('grid gap-3', (isKM || isDingtian) ? 'grid-cols-3' : 'grid-cols-1')}>
|
||||||
<div className={cn('space-y-1', (isKM || isDingtian) ? '' : 'max-w-xs')}>
|
<div className={cn('space-y-1', (isKM || isDingtian) ? '' : 'max-w-xs')}>
|
||||||
<Label>{t('station.host')}</Label>
|
<Label>{t('station.host')}</Label>
|
||||||
@@ -886,6 +907,10 @@ function DeviceEditor({ device, onChange, onSave, onCancel, t }: {
|
|||||||
|
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Label>{t('station.labels')}</Label>
|
<Label>{t('station.labels')}</Label>
|
||||||
|
{/* {value} sends the label, so an unnamed relay would go out as "?on=".
|
||||||
|
Said here, beside the empty box, rather than when the antenna fails
|
||||||
|
to switch and the log is the only place that explains why. */}
|
||||||
|
{valueNeedsLabels && <p className="text-[10px] text-warning">{t('station.valueNeedsLabels')}</p>}
|
||||||
<div className="grid grid-cols-4 gap-2">
|
<div className="grid grid-cols-4 gap-2">
|
||||||
{device.labels.map((lab, i) => (
|
{device.labels.map((lab, i) => (
|
||||||
<Input key={i} value={lab} placeholder={`${t('station.relay')} ${i + 1}`} className="h-8 text-xs"
|
<Input key={i} value={lab} placeholder={`${t('station.relay')} ${i + 1}`} className="h-8 text-xs"
|
||||||
@@ -901,12 +926,20 @@ function DeviceEditor({ device, onChange, onSave, onCancel, t }: {
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<div className="ml-auto flex gap-2">
|
<div className="ml-auto flex gap-2">
|
||||||
|
{/* No connection test for the generic board, and no host required to
|
||||||
|
save it. There is nothing to test: it has no address of its own and
|
||||||
|
no status to read — its URLs are fired and forgotten. A button that
|
||||||
|
can only ever say "OK, 4 relays" tests nothing, and a Save greyed
|
||||||
|
out for a missing host made a perfectly complete configuration —
|
||||||
|
four full URLs — impossible to store. */}
|
||||||
|
{!isHTTPGen && (
|
||||||
<Button size="sm" variant="outline" onClick={testDevice} disabled={testing || !device.host.trim()}>
|
<Button size="sm" variant="outline" onClick={testDevice} disabled={testing || !device.host.trim()}>
|
||||||
{testing ? <Loader2 className="size-3.5 mr-1 animate-spin" /> : <PlugZap className="size-3.5 mr-1" />}
|
{testing ? <Loader2 className="size-3.5 mr-1 animate-spin" /> : <PlugZap className="size-3.5 mr-1" />}
|
||||||
{t('station.test')}
|
{t('station.test')}
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
<Button size="sm" variant="ghost" onClick={onCancel}><X className="size-3.5 mr-1" />{t('station.cancel')}</Button>
|
<Button size="sm" variant="ghost" onClick={onCancel}><X className="size-3.5 mr-1" />{t('station.cancel')}</Button>
|
||||||
<Button size="sm" onClick={onSave} disabled={!device.host.trim()}><Check className="size-3.5 mr-1" />{t('station.save')}</Button>
|
<Button size="sm" onClick={onSave} disabled={!isHTTPGen && !device.host.trim()}><Check className="size-3.5 mr-1" />{t('station.save')}</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,17 @@
|
|||||||
|
// One answer to "is this QSL received".
|
||||||
|
//
|
||||||
|
// ADIF's QSL_Rcvd enumeration has BOTH Y and V: Y is "received", V is
|
||||||
|
// "verified" — and V is what a LoTW download writes for a confirmation the ARRL
|
||||||
|
// has validated. Testing for 'Y' alone therefore misses exactly the
|
||||||
|
// confirmations an operator cares most about.
|
||||||
|
//
|
||||||
|
// It showed on screen: the Awards panel had Morocco validated on five bands
|
||||||
|
// while the band/mode matrix beside it showed the entity as merely worked. The
|
||||||
|
// award engine accepted Y or V; every other test in the app accepted Y.
|
||||||
|
//
|
||||||
|
// The Go side has the same rule twice over — award.isYes and qso.ConfirmedValues
|
||||||
|
// — and all three have to agree. If you add a value here, add it there.
|
||||||
|
export function isQSLConfirmed(v: unknown): boolean {
|
||||||
|
const s = String(v ?? '').trim().toUpperCase();
|
||||||
|
return s === 'Y' || s === 'V';
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { isQSLConfirmed } from '@/lib/qsl';
|
||||||
// Row colouring for the log grid, by QSL status.
|
// Row colouring for the log grid, by QSL status.
|
||||||
//
|
//
|
||||||
// Four categories, each scoped to the channels the operator cares about —
|
// Four categories, each scoped to the channels the operator cares about —
|
||||||
@@ -32,7 +33,9 @@ const FIELDS: Record<string, { sent: string; rcvd: string }> = {
|
|||||||
// ADIF QSL fields are single letters. Y is the only one that means "yes";
|
// ADIF QSL fields are single letters. Y is the only one that means "yes";
|
||||||
// R (requested) and Q (queued) mean it has not gone out yet — a different state,
|
// R (requested) and Q (queued) mean it has not gone out yet — a different state,
|
||||||
// and the one an operator looks for when deciding what to send.
|
// and the one an operator looks for when deciding what to send.
|
||||||
const yes = (v: any) => String(v ?? '').trim().toUpperCase() === 'Y';
|
// Y or V — see lib/qsl. A LoTW-verified contact is confirmed, and colouring it
|
||||||
|
// as unconfirmed is the same bug the band/mode matrix had.
|
||||||
|
const yes = (v: any) => isQSLConfirmed(v);
|
||||||
const owed = (v: any) => {
|
const owed = (v: any) => {
|
||||||
const s = String(v ?? '').trim().toUpperCase();
|
const s = String(v ?? '').trim().toUpperCase();
|
||||||
return s === 'R' || s === 'Q';
|
return s === 'R' || s === 'Q';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Single source of truth for the app version shown in the UI (header + About).
|
// Single source of truth for the app version shown in the UI (header + About).
|
||||||
// Bump this on a release (the release script updates it alongside telemetry.go).
|
// Bump this on a release (the release script updates it alongside telemetry.go).
|
||||||
export const APP_VERSION = '0.25.2';
|
export const APP_VERSION = '0.25.5';
|
||||||
|
|
||||||
// Author / credits, shown in Help -> About.
|
// Author / credits, shown in Help -> About.
|
||||||
export const APP_AUTHOR = 'F4BPO';
|
export const APP_AUTHOR = 'F4BPO';
|
||||||
|
|||||||
@@ -3033,6 +3033,7 @@ export namespace main {
|
|||||||
transport: string;
|
transport: string;
|
||||||
com_port: string;
|
com_port: string;
|
||||||
baud: number;
|
baud: number;
|
||||||
|
spid_model?: string;
|
||||||
|
|
||||||
static createFrom(source: any = {}) {
|
static createFrom(source: any = {}) {
|
||||||
return new RotatorDevice(source);
|
return new RotatorDevice(source);
|
||||||
@@ -3054,6 +3055,7 @@ export namespace main {
|
|||||||
this.transport = source["transport"];
|
this.transport = source["transport"];
|
||||||
this.com_port = source["com_port"];
|
this.com_port = source["com_port"];
|
||||||
this.baud = source["baud"];
|
this.baud = source["baud"];
|
||||||
|
this.spid_model = source["spid_model"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class RotatorHeading {
|
export class RotatorHeading {
|
||||||
|
|||||||
@@ -369,10 +369,21 @@ func (s *session) runOnce() (time.Time, error) {
|
|||||||
// failure surfaces as an error on Read — which is the only thing that ends
|
// failure surfaces as an error on Read — which is the only thing that ends
|
||||||
// a session below.
|
// a session below.
|
||||||
d := net.Dialer{Timeout: 10 * time.Second, KeepAlive: 30 * time.Second}
|
d := net.Dialer{Timeout: 10 * time.Second, KeepAlive: 30 * time.Second}
|
||||||
|
// TIMED, and reported. An operator sees "connected" and no spots for a
|
||||||
|
// minute on the first launch, then an instant connection when the program is
|
||||||
|
// restarted — which is the signature of a slow name resolution rather than a
|
||||||
|
// slow cluster (the OS caches the answer, so the second run skips it). The
|
||||||
|
// only way to tell that from a node that simply had nothing to say is to
|
||||||
|
// know how long the dial itself took.
|
||||||
|
dialStart := time.Now()
|
||||||
conn, err := d.Dial("tcp", addr)
|
conn, err := d.Dial("tcp", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
applog.Printf("cluster[%s] dial %s failed after %s: %v", s.cfg.Name, addr, time.Since(dialStart).Round(time.Millisecond), err)
|
||||||
return time.Time{}, fmt.Errorf("dial %s: %w", addr, err)
|
return time.Time{}, fmt.Errorf("dial %s: %w", addr, err)
|
||||||
}
|
}
|
||||||
|
applog.Printf("cluster[%s] connected to %s in %s", s.cfg.Name, addr, time.Since(dialStart).Round(time.Millisecond))
|
||||||
|
linkUpAt := time.Now()
|
||||||
|
firstSpotLogged := false
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
s.conn = conn
|
s.conn = conn
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
@@ -556,6 +567,13 @@ func (s *session) runOnce() (time.Time, error) {
|
|||||||
}
|
}
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
if s.onSpot != nil {
|
if s.onSpot != nil {
|
||||||
|
if !firstSpotLogged {
|
||||||
|
firstSpotLogged = true
|
||||||
|
// The gap between the socket opening and the first spot is the
|
||||||
|
// other half of the answer: a long dial is the network, a quick
|
||||||
|
// dial and a long silence is the node (or the login) instead.
|
||||||
|
applog.Printf("cluster[%s] first spot %s after connecting", s.cfg.Name, time.Since(linkUpAt).Round(time.Millisecond))
|
||||||
|
}
|
||||||
s.onSpot(spot)
|
s.onSpot(spot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package udp
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
// A remote-call <FREQ> arrives in whatever unit the sender happens to use, and
|
||||||
|
// the same sender uses more than one. Every form has to land on the same dial
|
||||||
|
// frequency, because the alternative is a rig sent to the wrong band.
|
||||||
|
func TestRemoteTuneUnits(t *testing.T) {
|
||||||
|
const m20 = 14_074_000
|
||||||
|
for _, c := range []struct {
|
||||||
|
in string
|
||||||
|
want int64
|
||||||
|
why string
|
||||||
|
}{
|
||||||
|
{"14.074", m20, "MHz, the documented DXHunter form"},
|
||||||
|
{"10.136", 10_136_000, "MHz, 30 m"},
|
||||||
|
{"14074", m20, "kHz"},
|
||||||
|
{"14074.0", m20, "kHz with a decimal point"},
|
||||||
|
{"1407400", m20, "tens of Hz — what N1MM RadioInfo publishes, echoed back"},
|
||||||
|
{"2107400", 21_074_000, "the value from the field log that failed every time"},
|
||||||
|
{"14074000", m20, "Hz"},
|
||||||
|
{"7000000", 7_000_000, "Hz on 40 m, not tens of Hz on 4 m"},
|
||||||
|
{"0", 0, "no frequency"},
|
||||||
|
{"999999999999", 0, "nothing plausible — tune nothing rather than guess"},
|
||||||
|
{"abc", 0, "not a number"},
|
||||||
|
} {
|
||||||
|
if got := remoteTuneHz(c.in); got != c.want {
|
||||||
|
t.Errorf("remoteTuneHz(%q) = %d, want %d (%s)", c.in, got, c.want, c.why)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,38 @@ import (
|
|||||||
"hamlog/internal/applog"
|
"hamlog/internal/applog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// remoteTuneHz turns a <FREQ> value from a remote-call packet into Hz.
|
||||||
|
//
|
||||||
|
// The field has NO agreed unit, and the same sender uses two of them. DXHunter
|
||||||
|
// documents "<FREQ>10.136" — MHz — but a log from a working station showed it
|
||||||
|
// echoing "<FREQ>2107400" straight back: the frequency OpsLog had just
|
||||||
|
// published to it in the N1MM RadioInfo broadcast, whose <Freq> is in units of
|
||||||
|
// 10 Hz. Read as MHz, that asked the rig for 2 107 400 MHz, and every tune
|
||||||
|
// request failed with "out of the 11-digit CAT range" from the first second
|
||||||
|
// after launch.
|
||||||
|
//
|
||||||
|
// So the unit is inferred: try each one and keep the first that lands on an
|
||||||
|
// amateur band. Anything a station is asked to tune to is, by definition, in
|
||||||
|
// one. Hz is tried before 10 Hz because the one overlap between them — a 40 m
|
||||||
|
// frequency in Hz reads as a 4 m one in tens of Hz — is far more likely to be
|
||||||
|
// 40 m. Nothing plausible means nothing is tuned: a wrong band is worse than a
|
||||||
|
// request that visibly did nothing.
|
||||||
|
func remoteTuneHz(s string) int64 {
|
||||||
|
v, err := strconv.ParseFloat(s, 64)
|
||||||
|
if err != nil || v <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
for _, hz := range []int64{int64(v * 1e6), int64(v * 1e3), int64(v), int64(v * 10)} {
|
||||||
|
if bandFromHz(hz) != "" {
|
||||||
|
return hz
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Refusing in silence is how the previous version's failure looked from the
|
||||||
|
// outside: a spot clicked in another program, and nothing happening here.
|
||||||
|
applog.Printf("udp: remote_call <FREQ>%s is not a frequency in any amateur band in MHz, kHz or Hz — not tuning\n", s)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
// remoteFreqRe / remoteModeRe pull the optional tune request out of a
|
// remoteFreqRe / remoteModeRe pull the optional tune request out of a
|
||||||
// ServiceRemoteCall packet: "<FREQ>10.136" (MHz) and "<MODE>FT8". Both accept
|
// ServiceRemoteCall packet: "<FREQ>10.136" (MHz) and "<MODE>FT8". Both accept
|
||||||
// an optional closing tag for proper-XML senders.
|
// an optional closing tag for proper-XML senders.
|
||||||
@@ -397,9 +429,7 @@ func (s *Server) handle(pkt []byte, remote *net.UDPAddr) {
|
|||||||
// otherwise leave their values as stray tokens and corrupt the
|
// otherwise leave their values as stray tokens and corrupt the
|
||||||
// "last token = callsign" heuristic.
|
// "last token = callsign" heuristic.
|
||||||
if m := remoteFreqRe.FindStringSubmatch(text); m != nil {
|
if m := remoteFreqRe.FindStringSubmatch(text); m != nil {
|
||||||
if mhz, err := strconv.ParseFloat(m[1], 64); err == nil && mhz > 0 {
|
ev.TuneFreqHz = remoteTuneHz(m[1])
|
||||||
ev.TuneFreqHz = int64(mhz * 1e6)
|
|
||||||
}
|
|
||||||
text = strings.Replace(text, m[0], " ", 1)
|
text = strings.Replace(text, m[0], " ", 1)
|
||||||
}
|
}
|
||||||
if m := remoteModeRe.FindStringSubmatch(text); m != nil {
|
if m := remoteModeRe.FindStringSubmatch(text); m != nil {
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package qso
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
_ "modernc.org/sqlite"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A LoTW confirmation the ARRL has validated arrives as V, not Y — ADIF's
|
||||||
|
// QSL_Rcvd enumeration has both. Every SQL query here compared against 'Y'
|
||||||
|
// alone, so the band/mode matrix showed an entity as merely worked while the
|
||||||
|
// Awards panel beside it showed the same entity validated on five bands.
|
||||||
|
//
|
||||||
|
// This drives the real queries against a real database rather than asserting on
|
||||||
|
// the constant: the constant being right is not the point, the queries using it
|
||||||
|
// is.
|
||||||
|
func TestConfirmedCountsVerifiedNotJustYes(t *testing.T) {
|
||||||
|
db, err := sql.Open("sqlite", "file:confirmedvalues?mode=memory&cache=shared")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
if _, err := db.Exec(`CREATE TABLE qso (
|
||||||
|
id INTEGER PRIMARY KEY, callsign TEXT, dxcc INTEGER, band TEXT, mode TEXT,
|
||||||
|
lotw_rcvd TEXT, qsl_rcvd TEXT, eqsl_rcvd TEXT)`); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// Two Morocco contacts: one verified through LoTW, one not confirmed at all.
|
||||||
|
if _, err := db.Exec(`INSERT INTO qso (callsign, dxcc, band, mode, lotw_rcvd, qsl_rcvd, eqsl_rcvd)
|
||||||
|
VALUES ('CN8ABC', 446, '30m', 'FT8', 'V', '', ''),
|
||||||
|
('CN8XYZ', 446, '20m', 'FT8', 'N', '', '')`); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var confirmed30, confirmed20 int
|
||||||
|
q := `SELECT band, MAX(CASE WHEN lotw_rcvd IN ` + ConfirmedValues +
|
||||||
|
` OR qsl_rcvd IN ` + ConfirmedValues + ` OR eqsl_rcvd IN ` + ConfirmedValues +
|
||||||
|
` THEN 1 ELSE 0 END) FROM qso WHERE dxcc = 446 GROUP BY band`
|
||||||
|
rows, err := db.QueryContext(context.Background(), q)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
for rows.Next() {
|
||||||
|
var band string
|
||||||
|
var c int
|
||||||
|
if err := rows.Scan(&band, &c); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
switch band {
|
||||||
|
case "30m":
|
||||||
|
confirmed30 = c
|
||||||
|
case "20m":
|
||||||
|
confirmed20 = c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if confirmed30 != 1 {
|
||||||
|
t.Error("a LoTW 'V' (verified) was not counted as confirmed — the matrix would show the entity as merely worked")
|
||||||
|
}
|
||||||
|
if confirmed20 != 0 {
|
||||||
|
t.Error("an 'N' was counted as confirmed")
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
-3
@@ -1907,9 +1907,9 @@ func (r *Repo) WorkedBefore(ctx context.Context, callsign string, dxccHint int,
|
|||||||
SELECT band, mode,
|
SELECT band, mode,
|
||||||
MAX(CASE WHEN callsign = ? THEN 1 ELSE 0 END),
|
MAX(CASE WHEN callsign = ? THEN 1 ELSE 0 END),
|
||||||
MAX(CASE WHEN callsign = ?
|
MAX(CASE WHEN callsign = ?
|
||||||
AND (lotw_rcvd = 'Y' OR qsl_rcvd = 'Y' OR eqsl_rcvd = 'Y')
|
AND (lotw_rcvd IN `+ConfirmedValues+` OR qsl_rcvd IN `+ConfirmedValues+` OR eqsl_rcvd IN `+ConfirmedValues+`)
|
||||||
THEN 1 ELSE 0 END),
|
THEN 1 ELSE 0 END),
|
||||||
MAX(CASE WHEN lotw_rcvd = 'Y' OR qsl_rcvd = 'Y' OR eqsl_rcvd = 'Y'
|
MAX(CASE WHEN lotw_rcvd IN `+ConfirmedValues+` OR qsl_rcvd IN `+ConfirmedValues+` OR eqsl_rcvd IN `+ConfirmedValues+`
|
||||||
THEN 1 ELSE 0 END)
|
THEN 1 ELSE 0 END)
|
||||||
FROM qso
|
FROM qso
|
||||||
WHERE dxcc = ?
|
WHERE dxcc = ?
|
||||||
@@ -2792,12 +2792,27 @@ type SlotStats struct {
|
|||||||
DIGConfirmed int `json:"dig_confirmed"`
|
DIGConfirmed int `json:"dig_confirmed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConfirmedValues is what a QSL-received field holds when the contact IS
|
||||||
|
// confirmed, as an SQL list.
|
||||||
|
//
|
||||||
|
// Y AND V. ADIF's QSL_Rcvd enumeration has both: Y is "received", V is
|
||||||
|
// "verified" — and that is what a LoTW download writes for a confirmation the
|
||||||
|
// ARRL has validated. Testing only = 'Y' therefore misses exactly the
|
||||||
|
// confirmations an operator cares most about.
|
||||||
|
//
|
||||||
|
// This was visible on screen: the Awards panel showed Morocco validated on five
|
||||||
|
// bands while the band/mode matrix beside it showed the entity as merely worked,
|
||||||
|
// because the award engine's isYes accepts "Y" or "V" and every SQL query here
|
||||||
|
// compared against 'Y' alone. One definition of confirmed, in one place, is the
|
||||||
|
// only way those two agree.
|
||||||
|
const ConfirmedValues = "('Y','V')"
|
||||||
|
|
||||||
// GetSlotStats computes the worked/confirmed slot and DXCC tallies in one pass.
|
// GetSlotStats computes the worked/confirmed slot and DXCC tallies in one pass.
|
||||||
// "Confirmed" = LoTW or paper QSL received (the award-valid sources).
|
// "Confirmed" = LoTW or paper QSL received (the award-valid sources).
|
||||||
func (r *Repo) GetSlotStats(ctx context.Context) (SlotStats, error) {
|
func (r *Repo) GetSlotStats(ctx context.Context) (SlotStats, error) {
|
||||||
rows, err := r.db.QueryContext(ctx, `
|
rows, err := r.db.QueryContext(ctx, `
|
||||||
SELECT COALESCE(dxcc,0), LOWER(COALESCE(band,'')), UPPER(COALESCE(mode,'')),
|
SELECT COALESCE(dxcc,0), LOWER(COALESCE(band,'')), UPPER(COALESCE(mode,'')),
|
||||||
CASE WHEN lotw_rcvd='Y' OR qsl_rcvd='Y' THEN 1 ELSE 0 END
|
CASE WHEN lotw_rcvd IN `+ConfirmedValues+` OR qsl_rcvd IN `+ConfirmedValues+` THEN 1 ELSE 0 END
|
||||||
FROM qso`)
|
FROM qso`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SlotStats{}, err
|
return SlotStats{}, err
|
||||||
|
|||||||
+118
-18
@@ -3,6 +3,8 @@ package relaydev
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -20,13 +22,28 @@ import (
|
|||||||
//
|
//
|
||||||
// - one URL pair with {relay} in it, used for every relay:
|
// - one URL pair with {relay} in it, used for every relay:
|
||||||
// http://192.168.1.9/relay?n={relay}&state=on
|
// http://192.168.1.9/relay?n={relay}&state=on
|
||||||
// - or one pair per relay, when the box has no pattern to speak of:
|
// - one pair per relay, when the box has no pattern to speak of:
|
||||||
// relay 1 → http://192.168.1.9/FF0101 , relay 2 → .../FF0201
|
// relay 1 → http://192.168.1.9/FF0101 , relay 2 → .../FF0201
|
||||||
//
|
//
|
||||||
// The second is the reason this driver exists. A hand-made switch often has
|
// The second is the reason this driver exists. A hand-made switch often has
|
||||||
// URLs with nothing in common between channels, and a template with {relay}
|
// URLs with nothing in common between channels, and a template with {relay}
|
||||||
// cannot express that.
|
// cannot express that.
|
||||||
//
|
//
|
||||||
|
// TWO SUBSTITUTIONS are available in either form:
|
||||||
|
//
|
||||||
|
// {relay} the relay number, 1-based. {relay-1} for a board that counts its
|
||||||
|
// channels from zero — otherwise the whole pattern has to be given
|
||||||
|
// up for eight hand-typed URLs over one missing offset.
|
||||||
|
// {value} that relay's LABEL, the name given to it in Relay labels. A switch
|
||||||
|
// addressed by antenna name rather than by channel number
|
||||||
|
// (…/relay?on=Ant1) is then one pattern instead of eight URLs, and
|
||||||
|
// renaming the antenna re-addresses it — the name the operator reads
|
||||||
|
// on the button and the name on the wire cannot drift apart because
|
||||||
|
// they are the same string.
|
||||||
|
//
|
||||||
|
// The label is percent-encoded, so a name with a space or an accent goes out as
|
||||||
|
// a valid URL rather than a request the board rejects without saying why.
|
||||||
|
//
|
||||||
// STATE IS REMEMBERED, NOT READ. Most of these boxes have no status endpoint,
|
// STATE IS REMEMBERED, NOT READ. Most of these boxes have no status endpoint,
|
||||||
// or answer with a web page nobody can parse reliably. Status therefore returns
|
// or answer with a web page nobody can parse reliably. Status therefore returns
|
||||||
// what we last commanded — see the method for what that costs.
|
// what we last commanded — see the method for what that costs.
|
||||||
@@ -35,6 +52,7 @@ type httpGen struct {
|
|||||||
offURLs []string
|
offURLs []string
|
||||||
onPat string // pattern with {relay}, used when the per-relay URL is empty
|
onPat string // pattern with {relay}, used when the per-relay URL is empty
|
||||||
offPat string
|
offPat string
|
||||||
|
labels []string // index 0 = relay 1; what {value} resolves to
|
||||||
user string
|
user string
|
||||||
pass string
|
pass string
|
||||||
count int
|
count int
|
||||||
@@ -45,8 +63,8 @@ type httpGen struct {
|
|||||||
|
|
||||||
// NewHTTPGeneric builds the driver. onURLs/offURLs are per relay (index 0 =
|
// NewHTTPGeneric builds the driver. onURLs/offURLs are per relay (index 0 =
|
||||||
// relay 1) and may be short or hold empty entries; onPat/offPat are the
|
// relay 1) and may be short or hold empty entries; onPat/offPat are the
|
||||||
// fallback patterns.
|
// fallback patterns; labels are the relay names {value} substitutes.
|
||||||
func NewHTTPGeneric(onURLs, offURLs []string, onPat, offPat, user, pass string, count int) Device {
|
func NewHTTPGeneric(onURLs, offURLs []string, onPat, offPat, user, pass string, count int, labels []string) Device {
|
||||||
if count <= 0 {
|
if count <= 0 {
|
||||||
count = len(onURLs)
|
count = len(onURLs)
|
||||||
}
|
}
|
||||||
@@ -55,7 +73,7 @@ func NewHTTPGeneric(onURLs, offURLs []string, onPat, offPat, user, pass string,
|
|||||||
}
|
}
|
||||||
return &httpGen{
|
return &httpGen{
|
||||||
onURLs: onURLs, offURLs: offURLs,
|
onURLs: onURLs, offURLs: offURLs,
|
||||||
onPat: onPat, offPat: offPat,
|
onPat: onPat, offPat: offPat, labels: labels,
|
||||||
user: user, pass: pass, count: count,
|
user: user, pass: pass, count: count,
|
||||||
state: make([]bool, count),
|
state: make([]bool, count),
|
||||||
}
|
}
|
||||||
@@ -64,38 +82,120 @@ func NewHTTPGeneric(onURLs, offURLs []string, onPat, offPat, user, pass string,
|
|||||||
func (h *httpGen) Count() int { return h.count }
|
func (h *httpGen) Count() int { return h.count }
|
||||||
func (h *httpGen) Close() error { return nil } // stateless HTTP, nothing to release
|
func (h *httpGen) Close() error { return nil } // stateless HTTP, nothing to release
|
||||||
|
|
||||||
// urlFor picks the per-relay URL, falling back to the pattern.
|
// patFor returns the pattern for a direction, trimmed.
|
||||||
func (h *httpGen) urlFor(relay int, on bool) string {
|
func (h *httpGen) patFor(on bool) string {
|
||||||
list, pat := h.offURLs, h.offPat
|
|
||||||
if on {
|
if on {
|
||||||
list, pat = h.onURLs, h.onPat
|
return strings.TrimSpace(h.onPat)
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(h.offPat)
|
||||||
|
}
|
||||||
|
|
||||||
|
// entryFor returns what was typed in the per-relay box for a direction.
|
||||||
|
func (h *httpGen) entryFor(relay int, on bool) string {
|
||||||
|
list := h.offURLs
|
||||||
|
if on {
|
||||||
|
list = h.onURLs
|
||||||
}
|
}
|
||||||
if i := relay - 1; i >= 0 && i < len(list) {
|
if i := relay - 1; i >= 0 && i < len(list) {
|
||||||
if u := strings.TrimSpace(list[i]); u != "" {
|
return strings.TrimSpace(list[i])
|
||||||
return u
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if pat = strings.TrimSpace(pat); pat == "" {
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return strings.ReplaceAll(pat, "{relay}", strconv.Itoa(relay))
|
|
||||||
|
// labelFor returns the relay's name, as typed in Relay labels.
|
||||||
|
func (h *httpGen) labelFor(relay int) string {
|
||||||
|
if i := relay - 1; i >= 0 && i < len(h.labels) {
|
||||||
|
return strings.TrimSpace(h.labels[i])
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// urlFor builds the request for one relay in one direction: the per-relay URL
|
||||||
|
// if there is one, the pattern otherwise, with both substitutions applied.
|
||||||
|
func (h *httpGen) urlFor(relay int, on bool) string {
|
||||||
|
u := h.entryFor(relay, on)
|
||||||
|
if u == "" {
|
||||||
|
u = h.patFor(on)
|
||||||
|
}
|
||||||
|
if u == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return expand(u, relay, h.labelFor(relay))
|
||||||
|
}
|
||||||
|
|
||||||
|
// escapeValue percent-encodes a relay label for use anywhere in a URL.
|
||||||
|
//
|
||||||
|
// url.QueryEscape alone is wrong: it writes a space as "+", which is a space
|
||||||
|
// only in a query string and a literal plus sign in a path. Encoding it as %20
|
||||||
|
// instead is correct in both, and {value} may land in either.
|
||||||
|
func escapeValue(s string) string {
|
||||||
|
return strings.ReplaceAll(url.QueryEscape(s), "+", "%20")
|
||||||
|
}
|
||||||
|
|
||||||
|
// withScheme supplies http:// when none was typed, and leaves https:// alone.
|
||||||
|
//
|
||||||
|
// The same rule the named boards get from relayBase, and it has to be here too:
|
||||||
|
// this driver takes whole URLs rather than a host, and a line typed as
|
||||||
|
// "192.168.1.9/Set0/1" would otherwise fail with "unsupported protocol scheme"
|
||||||
|
// — an error about a scheme, for a field where nobody knew one was expected.
|
||||||
|
// An https:// board (a reverse proxy fronting the shack, most often) is passed
|
||||||
|
// through untouched and needs no other handling: it is the same HTTP client.
|
||||||
|
func withScheme(u string) string {
|
||||||
|
if u == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if l := strings.ToLower(u); strings.HasPrefix(l, "http://") || strings.HasPrefix(l, "https://") {
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
return "http://" + u
|
||||||
|
}
|
||||||
|
|
||||||
|
// relayToken matches {relay} and its offset forms, {relay-1} / {relay+2}.
|
||||||
|
var relayToken = regexp.MustCompile(`\{relay([+-]\d+)?\}`)
|
||||||
|
|
||||||
|
// expand substitutes {value} with the relay's label and {relay} with its
|
||||||
|
// number, honouring an offset. A board that numbers its channels from zero is
|
||||||
|
// written {relay-1}; without that the whole pattern has to be abandoned for
|
||||||
|
// four hand-typed URLs.
|
||||||
|
func expand(s string, relay int, label string) string {
|
||||||
|
s = strings.ReplaceAll(s, "{value}", escapeValue(label))
|
||||||
|
return relayToken.ReplaceAllStringFunc(s, func(m string) string {
|
||||||
|
n := relay
|
||||||
|
if i := strings.IndexAny(m, "+-"); i >= 0 {
|
||||||
|
if off, err := strconv.Atoi(m[i : len(m)-1]); err == nil {
|
||||||
|
n += off
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strconv.Itoa(n)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpGen) Set(ctx context.Context, relay int, on bool) error {
|
func (h *httpGen) Set(ctx context.Context, relay int, on bool) error {
|
||||||
if relay < 1 || relay > h.count {
|
if relay < 1 || relay > h.count {
|
||||||
return fmt.Errorf("relay %d out of range 1..%d", relay, h.count)
|
return fmt.Errorf("relay %d out of range 1..%d", relay, h.count)
|
||||||
}
|
}
|
||||||
u := h.urlFor(relay, on)
|
// Naming the direction matters: an operator who filled the ON URLs and left
|
||||||
if u == "" {
|
// OFF empty gets a switch that latches, and "no URL configured" alone would
|
||||||
// Naming the direction matters: an operator who filled the ON URLs and
|
// not say which half is missing.
|
||||||
// left OFF empty gets a switch that latches, and "no URL configured"
|
|
||||||
// alone would not say which half is missing.
|
|
||||||
dir := "OFF"
|
dir := "OFF"
|
||||||
if on {
|
if on {
|
||||||
dir = "ON"
|
dir = "ON"
|
||||||
}
|
}
|
||||||
|
tmpl := h.entryFor(relay, on)
|
||||||
|
if tmpl == "" {
|
||||||
|
tmpl = h.patFor(on)
|
||||||
|
}
|
||||||
|
if tmpl == "" {
|
||||||
return fmt.Errorf("no %s URL configured for relay %d", dir, relay)
|
return fmt.Errorf("no %s URL configured for relay %d", dir, relay)
|
||||||
}
|
}
|
||||||
|
// {value} with no label would send "?on=" — an empty parameter to an antenna
|
||||||
|
// switch, which most boards answer with a cheerful 200 and no movement. Say
|
||||||
|
// what is missing instead of firing it.
|
||||||
|
if strings.Contains(tmpl, "{value}") && h.labelFor(relay) == "" {
|
||||||
|
return fmt.Errorf("the %s URL for relay %d uses {value}, but relay %d has no label to put there", dir, relay, relay)
|
||||||
|
}
|
||||||
|
u := h.urlFor(relay, on)
|
||||||
|
u = withScheme(u)
|
||||||
if _, err := get(ctx, u, h.user, h.pass); err != nil {
|
if _, err := get(ctx, u, h.user, h.pass); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func TestHTTPGenericPattern(t *testing.T) {
|
|||||||
|
|
||||||
d := NewHTTPGeneric(nil, nil,
|
d := NewHTTPGeneric(nil, nil,
|
||||||
srv.URL+"/relay?n={relay}&state=on",
|
srv.URL+"/relay?n={relay}&state=on",
|
||||||
srv.URL+"/relay?n={relay}&state=off", "", "", 4)
|
srv.URL+"/relay?n={relay}&state=off", "", "", 4, nil)
|
||||||
if err := d.Set(context.Background(), 2, true); err != nil {
|
if err := d.Set(context.Background(), 2, true); err != nil {
|
||||||
t.Fatalf("Set on: %v", err)
|
t.Fatalf("Set on: %v", err)
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ func TestHTTPGenericPerRelayURLsWinOverThePattern(t *testing.T) {
|
|||||||
d := NewHTTPGeneric(
|
d := NewHTTPGeneric(
|
||||||
[]string{srv.URL + "/FF0101", "", srv.URL + "/weird/on"},
|
[]string{srv.URL + "/FF0101", "", srv.URL + "/weird/on"},
|
||||||
[]string{srv.URL + "/FF0100", "", ""},
|
[]string{srv.URL + "/FF0100", "", ""},
|
||||||
srv.URL+"/pattern/on/{relay}", srv.URL+"/pattern/off/{relay}", "", "", 3)
|
srv.URL+"/pattern/on/{relay}", srv.URL+"/pattern/off/{relay}", "", "", 3, nil)
|
||||||
|
|
||||||
_ = d.Set(context.Background(), 1, true) // its own URL
|
_ = d.Set(context.Background(), 1, true) // its own URL
|
||||||
_ = d.Set(context.Background(), 2, true) // empty → falls back to the pattern
|
_ = d.Set(context.Background(), 2, true) // empty → falls back to the pattern
|
||||||
@@ -66,10 +66,90 @@ func TestHTTPGenericPerRelayURLsWinOverThePattern(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// {value} is the relay's LABEL: a switch addressed by antenna name rather than
|
||||||
|
// by channel number is one pattern instead of eight URLs.
|
||||||
|
func TestHTTPGenericValueIsTheRelayLabel(t *testing.T) {
|
||||||
|
var mu sync.Mutex
|
||||||
|
var got []string
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
mu.Lock()
|
||||||
|
got = append(got, r.URL.String())
|
||||||
|
mu.Unlock()
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
d := NewHTTPGeneric(
|
||||||
|
[]string{srv.URL + "/relay?on={value}"}, // per-relay URL
|
||||||
|
nil,
|
||||||
|
"", srv.URL+"/relay?off={value}", // and the pattern, for the other direction
|
||||||
|
"", "", 3, []string{"Ant1", "Beam 20m", ""})
|
||||||
|
_ = d.Set(context.Background(), 1, true)
|
||||||
|
_ = d.Set(context.Background(), 2, false)
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
// The space in "Beam 20m" must go out as %20 — a "+" would be a literal plus
|
||||||
|
// in a path, and this substitution can land in either half of a URL.
|
||||||
|
want := []string{"/relay?on=Ant1", "/relay?off=Beam%2020m"}
|
||||||
|
if strings.Join(got, " ") != strings.Join(want, " ") {
|
||||||
|
t.Errorf("requested %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// {relay-1} for a board whose channels are numbered from zero.
|
||||||
|
func TestHTTPGenericRelayOffset(t *testing.T) {
|
||||||
|
var mu sync.Mutex
|
||||||
|
var got []string
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
mu.Lock()
|
||||||
|
got = append(got, r.URL.Path)
|
||||||
|
mu.Unlock()
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
d := NewHTTPGeneric(nil, nil,
|
||||||
|
srv.URL+"/set0/{relay-1}/1", srv.URL+"/set0/{relay-1}/0", "", "", 4, nil)
|
||||||
|
_ = d.Set(context.Background(), 1, true)
|
||||||
|
_ = d.Set(context.Background(), 4, false)
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
want := []string{"/set0/0/1", "/set0/3/0"}
|
||||||
|
if strings.Join(got, " ") != strings.Join(want, " ") {
|
||||||
|
t.Errorf("requested %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A URL that uses {value} on an unlabelled relay would go out as "?on=" — an
|
||||||
|
// empty parameter, which most boards answer with a cheerful 200 and no
|
||||||
|
// movement. It must be refused, and the message must say the label is what is
|
||||||
|
// missing.
|
||||||
|
func TestHTTPGenericRefusesValueWithoutALabel(t *testing.T) {
|
||||||
|
d := NewHTTPGeneric(nil, nil, "http://x/relay?on={value}", "", "", "", 2, []string{"", ""})
|
||||||
|
err := d.Set(context.Background(), 1, true)
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "label") {
|
||||||
|
t.Errorf("err = %v, want it to name the missing label", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A URL typed without a scheme must still be sent — the named boards take a
|
||||||
|
// bare host and add http:// themselves, and this one has to behave the same.
|
||||||
|
// https:// is left exactly as typed.
|
||||||
|
func TestHTTPGenericSuppliesTheScheme(t *testing.T) {
|
||||||
|
for _, c := range []struct{ in, want string }{
|
||||||
|
{"192.168.1.9/Set0/1", "http://192.168.1.9/Set0/1"},
|
||||||
|
{"http://192.168.1.9/x", "http://192.168.1.9/x"},
|
||||||
|
{"https://relay.example.com/x", "https://relay.example.com/x"},
|
||||||
|
{"HTTPS://relay.example.com/x", "HTTPS://relay.example.com/x"},
|
||||||
|
} {
|
||||||
|
if got := withScheme(c.in); got != c.want {
|
||||||
|
t.Errorf("withScheme(%q) = %q, want %q", c.in, got, c.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// A switch with the ON URLs filled and OFF left empty latches. The error has to
|
// A switch with the ON URLs filled and OFF left empty latches. The error has to
|
||||||
// name the direction, or the operator cannot tell which half is missing.
|
// name the direction, or the operator cannot tell which half is missing.
|
||||||
func TestHTTPGenericNamesTheMissingDirection(t *testing.T) {
|
func TestHTTPGenericNamesTheMissingDirection(t *testing.T) {
|
||||||
d := NewHTTPGeneric([]string{"http://x/on"}, nil, "", "", "", "", 1)
|
d := NewHTTPGeneric([]string{"http://x/on"}, nil, "", "", "", "", 1, nil)
|
||||||
err := d.Set(context.Background(), 1, false)
|
err := d.Set(context.Background(), 1, false)
|
||||||
if err == nil || !strings.Contains(err.Error(), "OFF") {
|
if err == nil || !strings.Contains(err.Error(), "OFF") {
|
||||||
t.Errorf("err = %v, want it to name the OFF direction", err)
|
t.Errorf("err = %v, want it to name the OFF direction", err)
|
||||||
@@ -80,7 +160,7 @@ func TestHTTPGenericNamesTheMissingDirection(t *testing.T) {
|
|||||||
func TestHTTPGenericRemembersWhatItCommanded(t *testing.T) {
|
func TestHTTPGenericRemembersWhatItCommanded(t *testing.T) {
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
|
srv := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
d := NewHTTPGeneric(nil, nil, srv.URL+"/on/{relay}", srv.URL+"/off/{relay}", "", "", 3)
|
d := NewHTTPGeneric(nil, nil, srv.URL+"/on/{relay}", srv.URL+"/off/{relay}", "", "", 3, nil)
|
||||||
_ = d.Set(context.Background(), 2, true)
|
_ = d.Set(context.Background(), 2, true)
|
||||||
st, err := d.Status(context.Background())
|
st, err := d.Status(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,257 @@
|
|||||||
|
// Package spid drives a SPID (AlfaSpid) rotator over its own serial protocol,
|
||||||
|
// Rot1Prog or Rot2Prog — the controllers sold as RAS, RAK, BIG-RAS/HR, MD-01
|
||||||
|
// and MD-02.
|
||||||
|
//
|
||||||
|
// It exists so an operator with SPID rotators does not need PstRotator running
|
||||||
|
// just to turn an antenna. Two towers with a controller each is the ordinary
|
||||||
|
// case; each one is a separate serial port and a separate rotor in OpsLog.
|
||||||
|
//
|
||||||
|
// WIRE FORMAT
|
||||||
|
//
|
||||||
|
// Every command is 13 bytes:
|
||||||
|
//
|
||||||
|
// 0 1 2 3 4 5 6 7 8 9 10 11 12
|
||||||
|
// 0x57 H1 H2 H3 H4 PH V1 V2 V3 V4 PV K 0x20
|
||||||
|
//
|
||||||
|
// K is the command: 0x0F stop, 0x1F status, 0x2F set.
|
||||||
|
//
|
||||||
|
// The DIGITS ARE ASCII in a command ('0'+d) and RAW BYTES in a reply (0..9).
|
||||||
|
// That asymmetry is the whole trap in this protocol: send raw digits and the
|
||||||
|
// controller ignores you, read them as ASCII and every heading is 48 degrees
|
||||||
|
// times a hundred out. It is pinned by the tests beside this file.
|
||||||
|
//
|
||||||
|
// PH and PV are the resolution in pulses per degree — 1, 2 or 4 — and are raw
|
||||||
|
// in both directions. The target is scaled by it:
|
||||||
|
//
|
||||||
|
// u_az = PH × (360 + az) and the four decimal digits of u_az are sent
|
||||||
|
//
|
||||||
|
// A reply is 12 bytes for Rot2Prog (azimuth and elevation) or 5 for Rot1Prog
|
||||||
|
// (azimuth only, three digits):
|
||||||
|
//
|
||||||
|
// az = H1×100 + H2×10 + H3 + H4/10 − 360
|
||||||
|
//
|
||||||
|
// The 360 offset is what lets the controller report a rotator that has turned
|
||||||
|
// past north in either direction, which is the point of a pulse-counting
|
||||||
|
// rotator: −180…540 rather than 0…359.
|
||||||
|
//
|
||||||
|
// Serial is 8N1 at 600 baud for Rot2Prog and 1200 for Rot1Prog. Those are not
|
||||||
|
// typos — a pulse controller has nothing to say quickly.
|
||||||
|
//
|
||||||
|
// Verified against Hamlib's spid.c (rotators/spid/spid.c), which is the
|
||||||
|
// reference implementation, and SPID's published protocol note. NOT yet run
|
||||||
|
// against real hardware here; the tests pin the frames, the controller is the
|
||||||
|
// only thing that can confirm the rest.
|
||||||
|
package spid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.bug.st/serial"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Model selects the dialect.
|
||||||
|
type Model string
|
||||||
|
|
||||||
|
const (
|
||||||
|
Rot1Prog Model = "rot1prog" // azimuth only, 5-byte reply, 1200 baud
|
||||||
|
Rot2Prog Model = "rot2prog" // azimuth + elevation, 12-byte reply, 600 baud
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
cmdStop = 0x0F
|
||||||
|
cmdStatus = 0x1F
|
||||||
|
cmdSet = 0x2F
|
||||||
|
|
||||||
|
frameStart = 0x57
|
||||||
|
frameEnd = 0x20
|
||||||
|
)
|
||||||
|
|
||||||
|
// Client is one controller on one serial port.
|
||||||
|
//
|
||||||
|
// The port is opened per exchange rather than held: a rotator is polled every
|
||||||
|
// few seconds at most, and holding a COM port open for the life of the program
|
||||||
|
// is what stops an operator from using their controller's own software
|
||||||
|
// alongside — which they will want while they are still trusting this.
|
||||||
|
type Client struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
port string
|
||||||
|
baud int
|
||||||
|
model Model
|
||||||
|
// resolution is pulses per degree: 1, 2 or 4. The controller is configured
|
||||||
|
// for one of them and answers with it, so a wrong value here corrects itself
|
||||||
|
// on the first status read.
|
||||||
|
resolution byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// New builds a client. baud 0 takes the model's documented default.
|
||||||
|
func New(comPort string, baud int, model Model) *Client {
|
||||||
|
if model != Rot1Prog {
|
||||||
|
model = Rot2Prog
|
||||||
|
}
|
||||||
|
if baud <= 0 {
|
||||||
|
baud = 600
|
||||||
|
if model == Rot1Prog {
|
||||||
|
baud = 1200
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &Client{port: strings.TrimSpace(comPort), baud: baud, model: model, resolution: 1}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuildStatus frames the "where are you" command.
|
||||||
|
func BuildStatus() []byte { return buildCmd(0, 0, 0, 0, cmdStatus) }
|
||||||
|
|
||||||
|
// BuildStop frames the "stop now" command.
|
||||||
|
func BuildStop() []byte { return buildCmd(0, 0, 0, 0, cmdStop) }
|
||||||
|
|
||||||
|
// BuildSet frames a target. resolution is the controller's pulses per degree.
|
||||||
|
//
|
||||||
|
// Azimuth is offset by 360 before scaling, so a target of −10° and one of 350°
|
||||||
|
// are different instructions: the first turns anticlockwise past north, the
|
||||||
|
// second does not. Feeding a 0…359 heading in is therefore always safe.
|
||||||
|
func BuildSet(az, el float64, resolution byte) []byte {
|
||||||
|
if resolution == 0 {
|
||||||
|
resolution = 1
|
||||||
|
}
|
||||||
|
uaz := int(float64(resolution)*(360+az) + 0.5)
|
||||||
|
uel := int(float64(resolution)*(360+el) + 0.5)
|
||||||
|
return buildCmd(uaz, uel, resolution, resolution, cmdSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildCmd(uaz, uel int, ph, pv byte, k byte) []byte {
|
||||||
|
c := make([]byte, 13)
|
||||||
|
c[0] = frameStart
|
||||||
|
if k == cmdSet {
|
||||||
|
c[1] = '0' + byte(uaz/1000%10)
|
||||||
|
c[2] = '0' + byte(uaz/100%10)
|
||||||
|
c[3] = '0' + byte(uaz/10%10)
|
||||||
|
c[4] = '0' + byte(uaz%10)
|
||||||
|
c[5] = ph
|
||||||
|
c[6] = '0' + byte(uel/1000%10)
|
||||||
|
c[7] = '0' + byte(uel/100%10)
|
||||||
|
c[8] = '0' + byte(uel/10%10)
|
||||||
|
c[9] = '0' + byte(uel%10)
|
||||||
|
c[10] = pv
|
||||||
|
}
|
||||||
|
c[11] = k
|
||||||
|
c[12] = frameEnd
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseStatus decodes a reply. Returns the azimuth, the elevation (0 for
|
||||||
|
// Rot1Prog) and the resolution the controller reported.
|
||||||
|
func ParseStatus(buf []byte, model Model) (az, el float64, resolution byte, err error) {
|
||||||
|
want := 12
|
||||||
|
if model == Rot1Prog {
|
||||||
|
want = 5
|
||||||
|
}
|
||||||
|
if len(buf) < want {
|
||||||
|
return 0, 0, 0, fmt.Errorf("spid: short reply (%d bytes, want %d)", len(buf), want)
|
||||||
|
}
|
||||||
|
if buf[0] != frameStart || buf[want-1] != frameEnd {
|
||||||
|
return 0, 0, 0, fmt.Errorf("spid: not a reply frame: % X", buf[:want])
|
||||||
|
}
|
||||||
|
az = float64(buf[1])*100 + float64(buf[2])*10 + float64(buf[3])
|
||||||
|
if model == Rot1Prog {
|
||||||
|
return az - 360, 0, 1, nil
|
||||||
|
}
|
||||||
|
az += float64(buf[4]) / 10
|
||||||
|
el = float64(buf[6])*100 + float64(buf[7])*10 + float64(buf[8]) + float64(buf[9])/10
|
||||||
|
resolution = buf[5]
|
||||||
|
if resolution == 0 {
|
||||||
|
resolution = 1
|
||||||
|
}
|
||||||
|
return az - 360, el - 360, resolution, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GoTo points the rotator at az (and el, on a Rot2Prog with elevation).
|
||||||
|
func (c *Client) GoTo(az int, el int) error {
|
||||||
|
c.mu.Lock()
|
||||||
|
res := c.resolution
|
||||||
|
c.mu.Unlock()
|
||||||
|
e := 0.0
|
||||||
|
if el >= 0 && c.model == Rot2Prog {
|
||||||
|
e = float64(el)
|
||||||
|
}
|
||||||
|
_, err := c.exchange(BuildSet(float64(az), e, res), 0)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop interrupts a rotation in progress.
|
||||||
|
func (c *Client) Stop() error {
|
||||||
|
// The controller answers a stop with its position, like a status — read it
|
||||||
|
// so the reply does not sit in the buffer and get taken for the ANSWER to
|
||||||
|
// the next poll, which would report a heading one command stale for ever.
|
||||||
|
_, err := c.exchange(BuildStop(), c.replyLen())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Heading reads the current position.
|
||||||
|
func (c *Client) Heading() (az int, el int, err error) {
|
||||||
|
buf, err := c.exchange(BuildStatus(), c.replyLen())
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, err
|
||||||
|
}
|
||||||
|
a, e, res, err := ParseStatus(buf, c.model)
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, err
|
||||||
|
}
|
||||||
|
// Believe the controller about its own resolution: it is configured on the
|
||||||
|
// front panel, and a wrong guess here would scale every target we send.
|
||||||
|
c.mu.Lock()
|
||||||
|
c.resolution = res
|
||||||
|
c.mu.Unlock()
|
||||||
|
return int(a + 0.5), int(e + 0.5), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) replyLen() int {
|
||||||
|
if c.model == Rot1Prog {
|
||||||
|
return 5
|
||||||
|
}
|
||||||
|
return 12
|
||||||
|
}
|
||||||
|
|
||||||
|
// exchange opens the port, writes one frame and reads the expected reply.
|
||||||
|
func (c *Client) exchange(cmd []byte, wantBytes int) ([]byte, error) {
|
||||||
|
if c.port == "" {
|
||||||
|
return nil, fmt.Errorf("spid: no serial port configured")
|
||||||
|
}
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
p, err := serial.Open(c.port, &serial.Mode{
|
||||||
|
BaudRate: c.baud, DataBits: 8, Parity: serial.NoParity, StopBits: serial.OneStopBit,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("spid: open %s: %w", c.port, err)
|
||||||
|
}
|
||||||
|
defer p.Close()
|
||||||
|
// 600 baud is 60 bytes a second: a 12-byte reply takes a fifth of a second
|
||||||
|
// to arrive on the wire alone, before the controller has thought about it.
|
||||||
|
_ = p.SetReadTimeout(2 * time.Second)
|
||||||
|
if _, err := p.Write(cmd); err != nil {
|
||||||
|
return nil, fmt.Errorf("spid: write: %w", err)
|
||||||
|
}
|
||||||
|
if wantBytes == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
buf := make([]byte, 0, wantBytes)
|
||||||
|
tmp := make([]byte, wantBytes)
|
||||||
|
deadline := time.Now().Add(3 * time.Second)
|
||||||
|
for len(buf) < wantBytes && time.Now().Before(deadline) {
|
||||||
|
n, err := p.Read(tmp)
|
||||||
|
if n > 0 {
|
||||||
|
buf = append(buf, tmp[:n]...)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(buf) < wantBytes {
|
||||||
|
return nil, fmt.Errorf("spid: no reply from %s (%d of %d bytes) — check the port, the baud rate (%d) and that nothing else holds the controller",
|
||||||
|
c.port, len(buf), wantBytes, c.baud)
|
||||||
|
}
|
||||||
|
return buf, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package spid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The frames are pinned against Hamlib's spid.c, the reference implementation.
|
||||||
|
// This protocol has one trap and it is here: digits go out as ASCII and come
|
||||||
|
// back RAW. Getting that backwards points an antenna at a heading nobody asked
|
||||||
|
// for, and nothing in the app would notice.
|
||||||
|
func TestSetFrameMatchesTheReference(t *testing.T) {
|
||||||
|
// Hamlib: u_az = PH × (360 + az), then the four decimal digits as ASCII;
|
||||||
|
// PH and PV raw; K = 0x2F.
|
||||||
|
got := BuildSet(0, 0, 1) // 360 → "0360"
|
||||||
|
want := []byte{0x57, '0', '3', '6', '0', 0x01, '0', '3', '6', '0', 0x01, 0x2F, 0x20}
|
||||||
|
assertBytes(t, "az 0 res 1", got, want)
|
||||||
|
|
||||||
|
// 90° at half-degree resolution: 2 × 450 = 900 → "0900".
|
||||||
|
got = BuildSet(90, 0, 2)
|
||||||
|
want = []byte{0x57, '0', '9', '0', '0', 0x02, '0', '7', '2', '0', 0x02, 0x2F, 0x20}
|
||||||
|
assertBytes(t, "az 90 res 2", got, want)
|
||||||
|
|
||||||
|
// A quarter-degree controller, 359°: 4 × 719 = 2876.
|
||||||
|
got = BuildSet(359, 0, 4)
|
||||||
|
want = []byte{0x57, '2', '8', '7', '6', 0x04, '1', '4', '4', '0', 0x04, 0x2F, 0x20}
|
||||||
|
assertBytes(t, "az 359 res 4", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status and stop carry no position: every data byte is zero, only K differs.
|
||||||
|
func TestStatusAndStopFrames(t *testing.T) {
|
||||||
|
assertBytes(t, "status", BuildStatus(),
|
||||||
|
[]byte{0x57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1F, 0x20})
|
||||||
|
assertBytes(t, "stop", BuildStop(),
|
||||||
|
[]byte{0x57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0F, 0x20})
|
||||||
|
}
|
||||||
|
|
||||||
|
// A reply's digits are RAW, and the 360 offset is what lets a pulse-counting
|
||||||
|
// controller report a rotator that has turned past north — the whole reason
|
||||||
|
// these rotators exist.
|
||||||
|
func TestParseStatusRot2Prog(t *testing.T) {
|
||||||
|
// 0x57 H1 H2 H3 H4 PH V1 V2 V3 V4 PV 0x20
|
||||||
|
// az digits 4,5,1,5 → 451.5 − 360 = 91.5
|
||||||
|
frame := []byte{0x57, 4, 5, 1, 5, 0x02, 3, 6, 0, 0, 0x02, 0x20}
|
||||||
|
az, el, res, err := ParseStatus(frame, Rot2Prog)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseStatus: %v", err)
|
||||||
|
}
|
||||||
|
if math.Abs(az-91.5) > 0.001 {
|
||||||
|
t.Errorf("az = %v, want 91.5", az)
|
||||||
|
}
|
||||||
|
if math.Abs(el-0) > 0.001 {
|
||||||
|
t.Errorf("el = %v, want 0", el)
|
||||||
|
}
|
||||||
|
if res != 2 {
|
||||||
|
t.Errorf("resolution = %d, want 2 — the controller's own value must win", res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rot1Prog: five bytes, three digits, no elevation.
|
||||||
|
func TestParseStatusRot1Prog(t *testing.T) {
|
||||||
|
az, el, res, err := ParseStatus([]byte{0x57, 4, 5, 1, 0x20}, Rot1Prog)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseStatus: %v", err)
|
||||||
|
}
|
||||||
|
if math.Abs(az-91) > 0.001 {
|
||||||
|
t.Errorf("az = %v, want 91", az)
|
||||||
|
}
|
||||||
|
if el != 0 || res != 1 {
|
||||||
|
t.Errorf("el = %v, res = %d — Rot1Prog has neither", el, res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A truncated or foreign frame must be refused rather than decoded into a
|
||||||
|
// heading: half a reply read as a position turns an antenna somewhere real.
|
||||||
|
func TestParseStatusRefusesRubbish(t *testing.T) {
|
||||||
|
for name, frame := range map[string][]byte{
|
||||||
|
"short": {0x57, 4, 5, 1},
|
||||||
|
"no start": {0x00, 4, 5, 1, 5, 1, 3, 6, 0, 0, 1, 0x20},
|
||||||
|
"no end": {0x57, 4, 5, 1, 5, 1, 3, 6, 0, 0, 1, 0x00},
|
||||||
|
"empty": {},
|
||||||
|
} {
|
||||||
|
if _, _, _, err := ParseStatus(frame, Rot2Prog); err == nil {
|
||||||
|
t.Errorf("%s: decoded without complaint", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertBytes(t *testing.T, what string, got, want []byte) {
|
||||||
|
t.Helper()
|
||||||
|
if len(got) != len(want) {
|
||||||
|
t.Fatalf("%s: % X\nwant % X", what, got, want)
|
||||||
|
}
|
||||||
|
for i := range want {
|
||||||
|
if got[i] != want[i] {
|
||||||
|
t.Fatalf("%s: % X\nwant % X", what, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package steppir
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// silentPort is a serial port that has stopped answering: every read times out.
|
||||||
|
// On Windows that is reported as (0, nil) — a timeout is not an error on this
|
||||||
|
// transport — which is precisely what io.ReadFull cannot survive.
|
||||||
|
type silentPort struct{ reads int }
|
||||||
|
|
||||||
|
func (p *silentPort) Read(b []byte) (int, error) {
|
||||||
|
p.reads++
|
||||||
|
time.Sleep(5 * time.Millisecond) // stand in for the port's read timeout
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
func (p *silentPort) Write(b []byte) (int, error) { return len(b), nil }
|
||||||
|
func (p *silentPort) Close() error { return nil }
|
||||||
|
|
||||||
|
// A controller that goes quiet must make the read FAIL, not hang. Hanging held
|
||||||
|
// the io mutex, so the poll loop never reported a fault and every operator
|
||||||
|
// command blocked behind it: the antenna stopped responding and the log had
|
||||||
|
// nothing in it.
|
||||||
|
func TestReadFrameGivesUpOnASilentController(t *testing.T) {
|
||||||
|
done := make(chan error, 1)
|
||||||
|
go func() {
|
||||||
|
done <- readFrame(&silentPort{}, make([]byte, 11), 100*time.Millisecond)
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case err := <-done:
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("a silent controller was reported as a good frame")
|
||||||
|
}
|
||||||
|
case <-time.After(3 * time.Second):
|
||||||
|
t.Fatal("readFrame never returned — the driver is wedged exactly as it was in the field")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// dribblePort delivers the frame a few bytes at a time, with empty reads in
|
||||||
|
// between — a slow 4800-baud link, which must still assemble one frame.
|
||||||
|
type dribblePort struct {
|
||||||
|
data []byte
|
||||||
|
step int
|
||||||
|
idle int // empty reads before each chunk
|
||||||
|
n int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *dribblePort) Read(b []byte) (int, error) {
|
||||||
|
if p.n < p.idle {
|
||||||
|
p.n++
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
p.n = 0
|
||||||
|
if len(p.data) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
k := p.step
|
||||||
|
if k > len(p.data) {
|
||||||
|
k = len(p.data)
|
||||||
|
}
|
||||||
|
if k > len(b) {
|
||||||
|
k = len(b)
|
||||||
|
}
|
||||||
|
copy(b, p.data[:k])
|
||||||
|
p.data = p.data[k:]
|
||||||
|
return k, nil
|
||||||
|
}
|
||||||
|
func (p *dribblePort) Write(b []byte) (int, error) { return len(b), nil }
|
||||||
|
func (p *dribblePort) Close() error { return nil }
|
||||||
|
|
||||||
|
func TestReadFrameAssemblesASlowFrame(t *testing.T) {
|
||||||
|
want := []byte{'@', 'A', 0x00, 0x20, 0x1E, 0xA8, 0x00, 0x05, 0x30, 0x37, 0x0D}
|
||||||
|
p := &dribblePort{data: append([]byte(nil), want...), step: 3, idle: 2}
|
||||||
|
buf := make([]byte, 11)
|
||||||
|
if err := readFrame(p, buf, time.Second); err != nil {
|
||||||
|
t.Fatalf("readFrame: %v", err)
|
||||||
|
}
|
||||||
|
for i := range want {
|
||||||
|
if buf[i] != want[i] {
|
||||||
|
t.Fatalf("read % X, want % X", buf, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A truncated frame is a failure, not a frame. The controller sending 5 bytes
|
||||||
|
// and stopping used to spin forever on the missing 6.
|
||||||
|
func TestReadFrameRejectsATruncatedFrame(t *testing.T) {
|
||||||
|
p := &dribblePort{data: []byte{'@', 'A', 0x00, 0x20, 0x1E}, step: 5}
|
||||||
|
err := readFrame(p, make([]byte, 11), 100*time.Millisecond)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("a 5-byte frame was accepted as 11")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A real error still comes straight back.
|
||||||
|
func TestReadFrameReturnsPortErrors(t *testing.T) {
|
||||||
|
want := errors.New("port closed")
|
||||||
|
p := errPort{err: want}
|
||||||
|
if err := readFrame(p, make([]byte, 11), time.Second); !errors.Is(err, want) {
|
||||||
|
t.Fatalf("err = %v, want %v", err, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type errPort struct{ err error }
|
||||||
|
|
||||||
|
func (p errPort) Read([]byte) (int, error) { return 0, p.err }
|
||||||
|
func (p errPort) Write(b []byte) (int, error) { return len(b), nil }
|
||||||
|
func (p errPort) Close() error { return nil }
|
||||||
|
|
||||||
|
var _ io.ReadWriteCloser = errPort{}
|
||||||
@@ -419,6 +419,45 @@ func drain(conn io.ReadWriteCloser) int {
|
|||||||
return total
|
return total
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// frameTimeout bounds the wait for one 11-byte status reply. At 4800 baud the
|
||||||
|
// frame itself takes ~23 ms; three seconds is a controller that is not going to
|
||||||
|
// answer this query.
|
||||||
|
const frameTimeout = 3 * time.Second
|
||||||
|
|
||||||
|
// readFrame reads exactly len(buf) bytes, or gives up.
|
||||||
|
//
|
||||||
|
// io.ReadFull CANNOT be used on a serial port, and using it here is what made an
|
||||||
|
// antenna "stop responding after a while" with nothing whatsoever in the log.
|
||||||
|
//
|
||||||
|
// On Windows a serial read that times out returns (0, nil) — a timeout is not an
|
||||||
|
// error on this transport. io.ReadFull loops while err == nil, so a controller
|
||||||
|
// that goes quiet, or sends a truncated frame, spins it forever. It holds ioMu
|
||||||
|
// the whole time, and that is the part the operator sees: the poll goroutine
|
||||||
|
// never returns to report a fault, so the last status stays on screen and the
|
||||||
|
// link still looks connected — while every command blocks on the same mutex.
|
||||||
|
// The trace line used to sit AFTER that lock, so even the attempt went unlogged.
|
||||||
|
// One dropped reply on a 4800-baud link wedged the driver until OpsLog restarted.
|
||||||
|
//
|
||||||
|
// Giving up returns an error, which the poll loop already knows how to handle:
|
||||||
|
// it says so in the log and reconnects.
|
||||||
|
func readFrame(conn io.ReadWriteCloser, buf []byte, d time.Duration) error {
|
||||||
|
deadline := time.Now().Add(d)
|
||||||
|
for n := 0; n < len(buf); {
|
||||||
|
m, err := conn.Read(buf[n:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
n += m
|
||||||
|
if n >= len(buf) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if time.Now().After(deadline) {
|
||||||
|
return fmt.Errorf("timed out after %s with %d of %d bytes", d, n, len(buf))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) queryStatus() (*Status, error) {
|
func (c *Client) queryStatus() (*Status, error) {
|
||||||
c.connMu.Lock()
|
c.connMu.Lock()
|
||||||
conn := c.conn
|
conn := c.conn
|
||||||
@@ -438,7 +477,7 @@ func (c *Client) queryStatus() (*Status, error) {
|
|||||||
return nil, fmt.Errorf("write status cmd: %w", err)
|
return nil, fmt.Errorf("write status cmd: %w", err)
|
||||||
}
|
}
|
||||||
buf := make([]byte, 11)
|
buf := make([]byte, 11)
|
||||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
if err := readFrame(conn, buf, frameTimeout); err != nil {
|
||||||
return nil, fmt.Errorf("read status: %w", err)
|
return nil, fmt.Errorf("read status: %w", err)
|
||||||
}
|
}
|
||||||
// Reject anything that isn't a framed reply rather than decoding garbage into
|
// Reject anything that isn't a framed reply rather than decoding garbage into
|
||||||
@@ -523,9 +562,14 @@ func (c *Client) writeCmd(pkt []byte) error {
|
|||||||
if conn == nil {
|
if conn == nil {
|
||||||
return fmt.Errorf("steppir: not connected")
|
return fmt.Errorf("steppir: not connected")
|
||||||
}
|
}
|
||||||
|
// Traced BEFORE taking the lock, not after. A command waits here for the poll
|
||||||
|
// in flight, and when that wait was unbounded the log showed no sign the
|
||||||
|
// operator had asked for anything at all — the one fact that would have named
|
||||||
|
// the fault. The line now means "asked for"; a failure to write is reported
|
||||||
|
// by the caller.
|
||||||
|
log.Printf("steppir: → % X", pkt)
|
||||||
c.ioMu.Lock()
|
c.ioMu.Lock()
|
||||||
defer c.ioMu.Unlock()
|
defer c.ioMu.Unlock()
|
||||||
log.Printf("steppir: → % X", pkt)
|
|
||||||
setDeadline(conn, 3*time.Second)
|
setDeadline(conn, 3*time.Second)
|
||||||
if _, err := conn.Write(pkt); err != nil {
|
if _, err := conn.Write(pkt); err != nil {
|
||||||
c.closeConn()
|
c.closeConn()
|
||||||
|
|||||||
@@ -95,18 +95,25 @@ func hostOpenOnce(p serial.Port, boot time.Duration) (int, error) {
|
|||||||
time.Sleep(boot)
|
time.Sleep(boot)
|
||||||
drain(p)
|
drain(p)
|
||||||
|
|
||||||
// Resync the command parser before asking it anything.
|
// The resync nulls and the echo probe go out as ONE write.
|
||||||
if _, err := p.Write([]byte{cmdNull, cmdNull, cmdNull}); err != nil {
|
//
|
||||||
return 0, fmt.Errorf("resync: %w", err)
|
// Copied byte for byte from a Logger32 capture against the K3NG keyer that
|
||||||
}
|
// would not answer OpsLog: "Sent: 13 13 13 00 04 55 / Rcvd: 55". Same keyer,
|
||||||
time.Sleep(50 * time.Millisecond)
|
// same port, same six bytes — the only difference was that we sent them as
|
||||||
drain(p)
|
// two writes with a pause and a buffer purge in between, and Logger32 sends
|
||||||
|
// them as one. On a keyer that reboots when the port opens, that pause is a
|
||||||
// Is anything actually there?
|
// window for it to come up mid-sequence and swallow half of it.
|
||||||
if _, err := p.Write([]byte{cmdAdmin, adminEcho, echoProbe}); err != nil {
|
//
|
||||||
|
// There is nothing to wait for between the two halves anyway: a null produces
|
||||||
|
// no reply, so the pause was only ever giving the keyer a chance to change
|
||||||
|
// its mind.
|
||||||
|
probe := []byte{cmdNull, cmdNull, cmdNull, cmdAdmin, adminEcho, echoProbe}
|
||||||
|
traceHandshake("TX", probe, 0, false)
|
||||||
|
if _, err := p.Write(probe); err != nil {
|
||||||
return 0, fmt.Errorf("echo test: %w", err)
|
return 0, fmt.Errorf("echo test: %w", err)
|
||||||
}
|
}
|
||||||
b, ok := readByte(p, echoTimeout)
|
b, ok := readByte(p, echoTimeout)
|
||||||
|
traceHandshake("RX", nil, b, ok)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, errNoKeyer
|
return 0, errNoKeyer
|
||||||
}
|
}
|
||||||
@@ -116,16 +123,37 @@ func hostOpenOnce(p serial.Port, boot time.Duration) (int, error) {
|
|||||||
return 0, fmt.Errorf("echo test: expected 0x%02X, got 0x%02X — is this the keyer's port?", echoProbe, b)
|
return 0, fmt.Errorf("echo test: expected 0x%02X, got 0x%02X — is this the keyer's port?", echoProbe, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := p.Write([]byte{cmdAdmin, adminOpen}); err != nil {
|
open := []byte{cmdAdmin, adminOpen}
|
||||||
|
traceHandshake("TX", open, 0, false)
|
||||||
|
if _, err := p.Write(open); err != nil {
|
||||||
return 0, fmt.Errorf("host open: %w", err)
|
return 0, fmt.Errorf("host open: %w", err)
|
||||||
}
|
}
|
||||||
ver, ok := readByte(p, openTimeout)
|
ver, ok := readByte(p, openTimeout)
|
||||||
|
traceHandshake("RX", nil, ver, ok)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, errors.New("host open: the keyer echoed but did not return its firmware version")
|
return 0, errors.New("host open: the keyer echoed but did not return its firmware version")
|
||||||
}
|
}
|
||||||
return int(ver), nil
|
return int(ver), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// traceHandshake puts the opening exchange in the log, ALWAYS — unlike the
|
||||||
|
// running trace beside it, which is behind the diagnostic option.
|
||||||
|
//
|
||||||
|
// A failure that says only "no WinKeyer answered" cannot be told apart from a
|
||||||
|
// wrong port, a wrong baud rate, a keyer still rebooting, or another program
|
||||||
|
// holding the line. The bytes can. It is four lines per connect, and only when
|
||||||
|
// the connect is attempted.
|
||||||
|
func traceHandshake(dir string, b []byte, got byte, ok bool) {
|
||||||
|
switch {
|
||||||
|
case dir == "TX":
|
||||||
|
applog.Printf("winkeyer: handshake TX % 02X", b)
|
||||||
|
case ok:
|
||||||
|
applog.Printf("winkeyer: handshake RX %02X", got)
|
||||||
|
default:
|
||||||
|
applog.Printf("winkeyer: handshake RX — nothing came back")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// readByte waits up to d for one byte. The serial read timeout is per-call and
|
// readByte waits up to d for one byte. The serial read timeout is per-call and
|
||||||
// can return 0 bytes without an error, so this loops until the deadline rather
|
// can return 0 bytes without an error, so this loops until the deadline rather
|
||||||
// than trusting a single Read.
|
// than trusting a single Read.
|
||||||
|
|||||||
@@ -102,6 +102,8 @@ func TestHostOpenFollowsK1ELSequence(t *testing.T) {
|
|||||||
if ver != 23 {
|
if ver != 23 {
|
||||||
t.Errorf("version = %d, want 23", ver)
|
t.Errorf("version = %d, want 23", ver)
|
||||||
}
|
}
|
||||||
|
// One write for the six probe bytes, then Host Open — the order and the
|
||||||
|
// grouping of a Logger32 capture against a real K3NG.
|
||||||
want := []byte{
|
want := []byte{
|
||||||
cmdNull, cmdNull, cmdNull,
|
cmdNull, cmdNull, cmdNull,
|
||||||
cmdAdmin, adminEcho, echoProbe,
|
cmdAdmin, adminEcho, echoProbe,
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Every setting in OpsLog is per profile, station hardware included. A device
|
||||||
|
// started at boot and never again therefore stays on the PREVIOUS profile's
|
||||||
|
// port until Settings is opened and saved — which is how an operator running an
|
||||||
|
// SPE on COM9 for HF and another on COM10 for 6 m, one per profile, found the
|
||||||
|
// amplifier still on the old port after switching. Save is not a connect
|
||||||
|
// button.
|
||||||
|
//
|
||||||
|
// This test keeps startup and reloadAfterProfileSwitch in lockstep: anything
|
||||||
|
// started at boot must either be re-applied on a profile switch or be listed
|
||||||
|
// below with the reason it must not be. Adding a device makes the choice
|
||||||
|
// explicit instead of leaving the fifth one to be found by a user.
|
||||||
|
func TestProfileSwitchReappliesEveryStartupDevice(t *testing.T) {
|
||||||
|
src, err := os.ReadFile("app.go")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("read app.go: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Started at boot but deliberately NOT re-run on a profile switch:
|
||||||
|
notPerProfile := map[string]string{
|
||||||
|
"startAllEnabledClusters": "the cluster panel reconnects itself; its servers are a global list",
|
||||||
|
"startGridCache": "a shared on-disk grid cache, not a profile's",
|
||||||
|
"startBandOpenFeed": "PSK Reporter, keyed on the operator grid it re-reads itself",
|
||||||
|
}
|
||||||
|
|
||||||
|
startup := body(t, string(src), "func (a *App) startup(ctx context.Context) {")
|
||||||
|
reload := body(t, string(src), "func (a *App) reloadAfterProfileSwitch() {")
|
||||||
|
|
||||||
|
call := regexp.MustCompile(`a\.(start[A-Z][A-Za-z]*)\b`)
|
||||||
|
seen := map[string]bool{}
|
||||||
|
for _, m := range call.FindAllStringSubmatch(startup, -1) {
|
||||||
|
name := m[1]
|
||||||
|
if seen[name] || notPerProfile[name] != "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[name] = true
|
||||||
|
if !strings.Contains(reload, "a."+name) {
|
||||||
|
t.Errorf("%s runs at startup but not on a profile switch — the device stays on the previous profile's settings.\n"+
|
||||||
|
"Add it to reloadAfterProfileSwitch, or to notPerProfile here with the reason it must not follow the profile.", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(seen) == 0 {
|
||||||
|
t.Fatal("no startup device starters found — this test has stopped checking anything")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// body returns the source of the function opening with the given signature,
|
||||||
|
// up to the closing brace in column 0.
|
||||||
|
func body(t *testing.T, src, signature string) string {
|
||||||
|
t.Helper()
|
||||||
|
i := strings.Index(src, signature)
|
||||||
|
if i < 0 {
|
||||||
|
t.Fatalf("%q not found in app.go", signature)
|
||||||
|
}
|
||||||
|
rest := src[i+len(signature):]
|
||||||
|
if j := strings.Index(rest, "\n}"); j >= 0 {
|
||||||
|
return rest[:j]
|
||||||
|
}
|
||||||
|
return rest
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The generic HTTP board must actually be built from its URLs.
|
||||||
|
//
|
||||||
|
// It was not: buildDeviceDriver had no case for it, so it fell through to the
|
||||||
|
// WebSwitch driver. The board was configured, saved, listed — and every command
|
||||||
|
// went to a WebSwitch address that did not exist, which also left the device
|
||||||
|
// reported as offline and every relay button on the panel greyed out. Nothing in
|
||||||
|
// the UI said so; the URLs were simply never sent.
|
||||||
|
func TestGenericHTTPBoardSendsItsConfiguredURL(t *testing.T) {
|
||||||
|
hit := make(chan string, 4)
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
hit <- r.URL.Path
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
// Host deliberately empty — this board's whole address is in the URLs.
|
||||||
|
d := StationDevice{
|
||||||
|
Type: "httpgen",
|
||||||
|
Channels: 2,
|
||||||
|
OnURLs: []string{srv.URL + "/relay1/on", srv.URL + "/relay2/on"},
|
||||||
|
OffURLs: []string{srv.URL + "/relay1/off", srv.URL + "/relay2/off"},
|
||||||
|
}
|
||||||
|
if err := buildDeviceDriver(d).Set(context.Background(), 2, true); err != nil {
|
||||||
|
t.Fatalf("Set: %v", err)
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case got := <-hit:
|
||||||
|
if got != "/relay2/on" {
|
||||||
|
t.Errorf("board was asked for %q, want /relay2/on", got)
|
||||||
|
}
|
||||||
|
case <-time.After(3 * time.Second):
|
||||||
|
t.Fatal("the configured URL was never requested — the board is not using its own driver")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Editing a URL must rebuild the driver. The cached one is keyed by the device's
|
||||||
|
// configuration, and the URLs used not to be part of that key: correcting a typo
|
||||||
|
// handed back the driver still holding the old address, so the fix looked like it
|
||||||
|
// had done nothing until OpsLog was restarted.
|
||||||
|
func TestGenericHTTPBoardKeyCoversItsURLs(t *testing.T) {
|
||||||
|
a := StationDevice{Type: "httpgen", Channels: 2, OnURLs: []string{"http://box/a"}}
|
||||||
|
b := StationDevice{Type: "httpgen", Channels: 2, OnURLs: []string{"http://box/b"}}
|
||||||
|
if deviceKey(a) == deviceKey(b) {
|
||||||
|
t.Error("two boards with different URLs share a cache key — an edited URL would not take effect")
|
||||||
|
}
|
||||||
|
c := a
|
||||||
|
c.OnPat = "http://box/{relay}"
|
||||||
|
if deviceKey(a) == deviceKey(c) {
|
||||||
|
t.Error("changing the ON pattern left the cache key unchanged")
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// appVersion is stamped on every heartbeat (and could feed the About box).
|
// appVersion is stamped on every heartbeat (and could feed the About box).
|
||||||
appVersion = "0.25.2"
|
appVersion = "0.25.5"
|
||||||
|
|
||||||
// posthogHost is the PostHog ingestion endpoint. EU cloud by default; change
|
// posthogHost is the PostHog ingestion endpoint. EU cloud by default; change
|
||||||
// to https://us.i.posthog.com for a US project.
|
// to https://us.i.posthog.com for a US project.
|
||||||
|
|||||||
Reference in New Issue
Block a user