Command Queues

wfview has three command queues, used to send traffic to the radio. The queues are used so that there is a central place where commands exit wfmain and enter rigCommander, and so that we can regulate the pace at which this happens. Polling rates that are too fast lead to congestion at the radio (especially older radios), and polling rates that are too slow lead to an unresponsive UI. The centralized exit point also prevents possible concurrent commands, which could come to the radio corrupted.

The Three Queues:

  • Periodic Command Queue:
    • Used for periodic (always happening) high-speed polling of the metering parameters
    • Runs every 2 polling ticks
    • Populated when a radio is first connected
    • Keep this queue lean so that the meters are responsive and quick
  • Slow Poll Command Queue:
    • Used for periodic (always happening) low-speed polling of radio parameters
    • Runs every 20 polling ticks, but will pause when there is an outgoing non-periodic command waiting at the same tick
    • Populated when a radio is first connected
    • Has commands like “what mode is this?” and “what antenna is selected”, which we want to make sure we’re in sync with.
  • Delayed Command Queue:
    • Used for user-interface commands such as “change mode” or “change frequency”
    • High-Speed
    • Runs every 2 polling ticks
    • Commands may be inserted top (“priority”) of the queue
    • Commands may be inserted as unique (meaning, any duplicate commands are removed).

Polling Action:

The master polling function is wfmain::sendRadioCommandLoop(), which is run by a QTimer at the prescribed polling speed (typically 25ms for LAN connections and 75ms for serial ports).

On even ticks:

  • Check for Delayed Commands, and run the first one
  • Every 10 ticks, run a Slow Poll Command, unless at that 10th tick there is a Delayed Command waiting, in which case the Delayed Command is run instead.

On odd ticks:

  • Run the high-speed Periodic Command Queue

On every tick, the tick counter is incremented by 1.

Queue Interaction Functions:

wfmain has several options for inserting commands. You may also see several functions with the same name; these are designed to use c++’s polymorphism capabilities which will match the function with the call parameters. For example, a parameter might be a frequency or mode to change to.

High Speed, Periodic:

insertPeriodicCommand(cmd, priority):
High-speed periodic queue for S-Meter and similar real-time-ish

insertPeriodicCommandUnique(cmd):
Removes duplicate commands and then inserts to the front of the high-speed periodic command queue

Low Speed, Periodic:

insertSlowPeriodicCommand(cmd, priority):
Low-speed periodic queue for regular polling of frequency/mode/antenna/preamp/etc. Priority < 10 goes to the front of the line. But it doesn’t mean much since it runs in a circle anyway.

One-Time High-Speed (for UI interaction):

issueCmd(cmd, argument):
Issue a one-time command with an argument, pushed to the back usually but sometimes the front for things like setting the time.

issueCmdUniquePriority(cmds, argument):
Insert a one-time command, to the front, and remove any existing command of the same type.

Polling Interval:

Upon radio discovery, the polling rate is read from the preferences (prefs.polling_ms), and if zero, then polling is calculated based on the radio’s interface speed, by the function wfmain::calculateTimingParameters().

Prior to radio discovery, the initial polling speed is set to 250ms just to be on the safe side and to make sure our initial commands get through.

Users can override the recommended polling rate using the Settings tab, on the User Interface page.

The queue objects (do not use directly):

std::deque <commandType> delayedCmdQue: one-time high-speed queue.
std::deque <cmds> periodicCmdQueue: periodic high-speed queue
std::deque <cmds> slowPollCmdQueue: periodic slow-speed queue

Data Types in the queues:

cmds: simple enumerated commands without parameters.
commandType: structure that holds cmds and parameters using a std::shared_ptr.

 

Helper Functions (do not use directly):

wfmain::sendRadioCommandLoop(): Run at regular polling intervals by the QTimer “delayedCommand”.

wfmain::doCmd(cmds cmd): Runs the specified simple command

wfmain::doCmd(commandType cmddata): Runs the specified command with parameters