fix(tci server): split armed on the frequency asked for, in either order
Audit prompted by "are we sure the commands are implemented — split, Fake It, Split rig?". The rigctl server is complete and hardened; the TCI one, three days old, had reintroduced a bug rigctld had already paid for. A client working split says two things — where to transmit, and that split is on — and nothing obliges it to say them in that order. A write to channel B while the rig was still simplex was DISCARDED, on the sound principle that preparing a transmit frequency is not a request to QSY. But then the split was armed on whatever the transmit VFO held, which is the receive frequency: the operator transmits straight onto the DX while their software shows exactly what they asked for. The frequency is now remembered and used when the split arrives, which is what rigctld does with set_split_vfo / set_split_freq. Two more from the same source: Asking for a split state the rig is already in touches nothing. A client in Fake It uses no split but still says so to be sure, and answering an error to a request that was already true is what made JTDX abandon a transmission a second into the frame through the rigctl server. A repeated PTT command is not re-sent. One client restated it sixteen times a second, and the Flex's own "xmit 1" was overwritten between two of them inside a millisecond. The same radio sits behind this server — the operator reporting this is on the Flex API backend. Fake It itself needs nothing but channel A, and now has a test saying so.
This commit is contained in:
@@ -75,6 +75,27 @@ type Server struct {
|
||||
conns map[*client]struct{}
|
||||
closed bool
|
||||
|
||||
// pendingTxHz is a transmit frequency a client set on channel B while the rig
|
||||
// was still simplex.
|
||||
//
|
||||
// It must be REMEMBERED, not discarded. A client working split sends two
|
||||
// commands and is free to send them in either order; when the frequency comes
|
||||
// first, throwing it away means the split is then armed on whatever the
|
||||
// transmit VFO happened to hold — the receive frequency — and the operator
|
||||
// transmits straight onto the DX while their software shows exactly what they
|
||||
// asked for. rigctld learned this the same way, and pairs set_split_vfo with
|
||||
// set_split_freq for the same reason.
|
||||
pendingTxHz int64
|
||||
|
||||
// ptt mirrors the last PTT state a client commanded, so a repeat can be
|
||||
// recognised. A client is free to restate PTT as often as it likes, and one
|
||||
// does: through the rigctl server Nexus sent set_ptt 0 about sixteen times a
|
||||
// second, and the Flex's own "xmit 1" landed between two of them and was
|
||||
// overwritten inside a millisecond — a transmit request that simply did
|
||||
// nothing. The same radio sits behind this server.
|
||||
ptt bool
|
||||
pttKnown bool
|
||||
|
||||
// last is what the clients have been told, so only changes are sent. TCI
|
||||
// clients redraw on every command they receive; re-sending an unchanged
|
||||
// frequency four times a second makes a VFO readout flicker and, in some
|
||||
@@ -416,11 +437,15 @@ func (s *Server) handle(c *client, cmd string) string {
|
||||
return ""
|
||||
}
|
||||
if arg(1) == "1" {
|
||||
// Channel B is the transmit frequency, and it only means anything
|
||||
// with split armed. Setting it while simplex would silently move the
|
||||
// rig's only VFO — the client asked to prepare a split TX frequency,
|
||||
// not to QSY.
|
||||
// Channel B is the transmit frequency. Setting it while simplex must
|
||||
// not move the rig's only VFO — the client asked to prepare a split
|
||||
// transmit frequency, not to QSY — but it must not be thrown away
|
||||
// either: it is where the split will be armed a moment from now.
|
||||
s.mu.Lock()
|
||||
s.pendingTxHz = hz
|
||||
s.mu.Unlock()
|
||||
if !split {
|
||||
s.broadcast(fmt.Sprintf("vfo:0,1,%d;", hz))
|
||||
return ""
|
||||
}
|
||||
if err := s.rig.SetSplit(true, hz); err != nil {
|
||||
@@ -454,10 +479,22 @@ func (s *Server) handle(c *client, cmd string) string {
|
||||
return reply("trx:0,false;")
|
||||
}
|
||||
on := strings.EqualFold(arg(1), "true")
|
||||
// Only touch the radio on a CHANGE — restating a state is not a request
|
||||
// to change it. The first command always goes through, since there is no
|
||||
// knowing how the radio was left.
|
||||
s.mu.Lock()
|
||||
known, prev := s.pttKnown, s.ptt
|
||||
s.ptt, s.pttKnown = on, true
|
||||
s.mu.Unlock()
|
||||
if known && prev == on {
|
||||
s.broadcast(fmt.Sprintf("trx:0,%t;", on))
|
||||
return ""
|
||||
}
|
||||
if err := s.rig.SetPTT(on); err != nil {
|
||||
s.log("tci server: PTT %v refused: %v", on, err)
|
||||
return ""
|
||||
}
|
||||
s.log("tci server: PTT %s", map[bool]string{true: "ON", false: "off"}[on])
|
||||
s.broadcast(fmt.Sprintf("trx:0,%t;", on))
|
||||
return ""
|
||||
|
||||
@@ -466,13 +503,34 @@ func (s *Server) handle(c *client, cmd string) string {
|
||||
return reply(fmt.Sprintf("split_enable:0,%t;", split))
|
||||
}
|
||||
on := strings.EqualFold(arg(1), "true")
|
||||
if err := s.rig.SetSplit(on, tx); err != nil {
|
||||
// Already in the state asked for? Then it is done, and nothing goes to
|
||||
// the radio. This is the lesson the rigctl server paid for: JTDX in "Fake
|
||||
// It" uses no split but still says so to be sure, and a backend that
|
||||
// cannot set split answered an error to a request that was already true.
|
||||
// JTDX read that as rig control failing and abandoned the transmission a
|
||||
// second into the frame. A refusal is only honest when something actually
|
||||
// needed doing.
|
||||
if on == split {
|
||||
s.broadcast(fmt.Sprintf("split_enable:0,%t;", on))
|
||||
return ""
|
||||
}
|
||||
// Arm on the frequency the client gave for channel B, which it is free to
|
||||
// have sent before this command rather than after.
|
||||
s.mu.Lock()
|
||||
pending := s.pendingTxHz
|
||||
s.mu.Unlock()
|
||||
txHz := tx
|
||||
if on && pending > 0 {
|
||||
txHz = pending
|
||||
}
|
||||
if err := s.rig.SetSplit(on, txHz); err != nil {
|
||||
// The refusal is the useful part: a backend that cannot split says
|
||||
// so, and the client can tell the operator instead of transmitting
|
||||
// on the wrong frequency believing all is well.
|
||||
s.log("tci server: split %v refused: %v", on, err)
|
||||
return ""
|
||||
}
|
||||
s.log("tci server: split %s, TX %d Hz", map[bool]string{true: "ON", false: "off"}[on], txHz)
|
||||
s.broadcast(fmt.Sprintf("split_enable:0,%t;", on))
|
||||
return ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user