Members
currentMode
Application state variables.
currentMode
: Tracks the currently selected mode (e.g., single, multi-station).inputs
: Stores the user-provided inputs retrieved from the form.currentStations
: An array of stations currently active in multi-station mode.currentStation
: The single active station in single mode.activeStationIndex
: Tracks the index of the current active station in multi-station mode.readyForTU
: Boolean indicating if the "TU" step is ready to proceed.currentStationAttempts
: Counter for the number of attempts with the current station.currentStationStartTime
: Timestamp for when the current station interaction started.totalContacts
: Counter for the total number of completed contacts.yourStation
: Stores the user's station configuration.lastRespondingStations
: An array of stations that last responded to the user's call.farnsworthLowerBy
: The amount to increase the Farnsworth spacing when using QRS.
(constant) modeLogicConfig
modeLogicConfig centralizes the message construction logic for various modes. Each mode’s functions define how CQ calls, exchanges, and final messages are generated, removing the need for conditional branching (e.g., if/else statements) elsewhere. Instead of embedding placeholders, these functions use template literals and accept the necessary parameters directly.
The extraInfoFieldKey and extraInfoFieldKey2 properties specify which callingStation attributes are compared against the user's input during the TU step.
(constant) modeUIConfig
modeUIConfig defines the UI-related aspects of each mode, including whether one or two info fields are displayed, their placeholders, and result headers. Additionally, it specifies what the extra column header should be.
Methods
addStations(stations, inputs) → {Array.<Object>}
Adds new stations if the current count is below the maximum allowed.
Uses a weighted random selection to determine how many new stations to add, logs details about each new station, updates the total active station count, and returns the updated array.
Parameters:
Name | Type | Description |
---|---|---|
stations |
Array.<Object> | Current list of stations. |
inputs |
Object | Configuration object containing |
Returns:
The updated list of stations.
- Type
- Array.<Object>
addTableRow(tableName, index, callsign, wpm, attempts, totalTime, extraopt)
Inserts a new row at the top of a specified HTML table body with provided data.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
tableName |
string | The ID of the HTML table element. |
||
index |
number | A numeric index or sequence number. |
||
callsign |
string | The callsign or identifier to display. |
||
wpm |
string | The words per minute speed (and Farnsworth spacing) to display. |
||
attempts |
number | The number of attempts to record. |
||
totalTime |
number | The total time taken, displayed to two decimal places. |
||
extra |
string | null |
<optional> |
null | Optional additional information to include in a fifth cell. |
applyModeSettings(mode)
Updates the UI to reflect the current mode's configuration.
Adjusts visibility, placeholders, and content of various UI elements like the "TU" button, input fields, and results table. Also modifies extra columns in the results table based on mode-specific requirements.
Parameters:
Name | Type | Description |
---|---|---|
mode |
string | The mode to apply settings for. |
changeMode()
Handles changes to the operating mode.
Updates the currentMode
variable, saves the new mode to local storage,
resets the game state, clears invalid states, and applies the new mode's settings.
clearAllInvalidStates()
Clears the invalid state from all form fields.
Targets all elements with the .is-invalid
class and removes it to reset
the visual state of the form.
clearFieldInvalid(inputId)
Clears the invalid state from a specific input field.
Removes the CSS class for invalid state and resets any associated error message.
Parameters:
Name | Type | Description |
---|---|---|
inputId |
string | The ID of the input field to clear. |
clearTable(tableName)
Removes all rows from the specified table body.
Parameters:
Name | Type | Description |
---|---|---|
tableName |
string | The ID of the HTML table element. |
compareExtraInfo(fieldKey, userInput, callingStation) → {string}
Compares the user's input against a station's corresponding property.
Matches the input to attributes like name, state, or serial number, and returns a string indicating correctness. For incorrect matches, shows the expected value.
Parameters:
Name | Type | Description |
---|---|---|
fieldKey |
string | The station attribute to compare (e.g., name, state). |
userInput |
string | The user's input value. |
callingStation |
Object | The station object to compare against. |
Returns:
A string indicating correctness or showing the expected value.
- Type
- string
compareStrings(source, query) → {string}
Compares the source and query strings based on specific fuzzy match criteria.
Parameters:
Name | Type | Description |
---|---|---|
source |
string | The source string to compare against. |
query |
string | The query string to compare with the source. |
Returns:
- "perfect", "partial", or "none" based on the match.
- Type
- string
cq()
Handles the "CQ" button click to call stations.
- In multi-station modes, calling CQ adds more stations if enabled.
- In single mode, calling CQ fetches a new station if none is active.
- Plays the CQ message using the user's station configuration.
createBackgroundStatic()
Creates a background static noise track for QRN simulation.
Configures a looping audio source based on the selected QRN level (e.g., normal, moderate, heavy). Adjusts gain to match the QRN intensity and connects the source to the audio context.
Ensures only one static track is active at a time.
createMorsePlayer(station, volumeOverride) → {Object|null}
Creates a Morse code audio player for a specified station.
Configures an oscillator and gain node to produce audio signals representing
Morse code. Supports Farnsworth timing adjustments and simulates QSB (fading)
effects if enabled. Includes mappings for letters, numbers, punctuation, and
prosigns. Exposes a playSentence
method for playing Morse sequences.
Parameters:
Name | Type | Description |
---|---|---|
station |
Object | The station configuration with attributes like volume, frequency, and WPM. |
volumeOverride |
number | null | Optional override for the station's volume. |
Returns:
An object with methods to play Morse sequences or null if inputs are invalid.
- Type
- Object | null
generateRandomLetters(length) → {string}
Creates a random sequence of letters.
Utilizes the English alphabet to generate a string of random uppercase letters with the specified length.
Parameters:
Name | Type | Description |
---|---|---|
length |
number | The number of letters to generate. |
- Source:
Returns:
A string of random uppercase letters.
- Type
- string
getAudioLock() → {boolean}
Checks whether the audio lock is currently active.
Compares the current audio context time with the lock time to determine if new audio playback is allowed.
Returns:
True if the audio lock is active, false otherwise.
- Type
- boolean
getCallingStation() → {Object|null}
Generates a random calling station configuration.
Uses getInputs
to pull user-defined constraints like speed, volume, and tone ranges.
Determines if the station is US-based or international with a 40% likelihood for US stations
(unless usOnly
is true). The station's attributes, including callsign, name, state,
serial number, and CWOPS number, are randomly generated within the specified constraints.
Additionally, introduces optional QSB (fading) parameters like frequency and depth.
- Source:
Returns:
The calling station configuration or null if inputs are unavailable.
- Type
- Object | null
getDOMInputs() → {Object}
Extracts values from DOM elements representing the form inputs.
Collects various input types, including text, dropdowns, checkboxes, and dynamically selected formats. Converts specific fields to standardized formats (e.g., uppercase, float values) to maintain consistency.
Returns:
An object containing raw input values from the DOM.
- Type
- Object
getInputs() → {Object|null}
Retrieves and validates all input values from the form.
Combines DOM input extraction with validation to ensure all required fields
meet specified criteria. If the inputs are valid, the collected data is returned;
otherwise, it returns null
.
Returns:
An object containing validated form inputs or null if invalid.
- Type
- Object | null
getModeConfig() → {Object}
Retrieves the logic configuration for the current mode.
Returns the object containing mode-specific logic and rules, such as message templates and exchange formats, based on the selected mode.
Returns:
The configuration object for the current mode.
- Type
- Object
getRandomNonUSCallsign(formats) → {string}
Generates a random non-US amateur radio callsign.
Combines a random international prefix with a digit and a sequence of letters according to the specified format. Ensures compatibility between prefix length and format requirements. Retries until a valid combination is found for prefixes and formats. Leverages predefined international prefixes.
Parameters:
Name | Type | Description |
---|---|---|
formats |
Array.<string> | An array of valid callsign formats. |
- Source:
Returns:
A randomly generated non-US callsign.
- Type
- string
getRandomUSCallsign(formats) → {string}
Generates a random US amateur radio callsign.
Based on the provided format (e.g., '1x1', '2x3'), this function builds a valid US callsign by combining a prefix, a digit, and a random sequence of letters. Defaults to a '1x3' format if an unknown format is passed. Utilizes predefined US callsign prefixes.
Parameters:
Name | Type | Description |
---|---|---|
formats |
Array.<string> | An array of valid callsign formats. |
- Source:
Returns:
A randomly generated US callsign.
- Type
- string
getSelectedCutNumbers() → {Object.<string, string>}
Collects the selected cut-number mappings from the form.
For each digit the user has chosen to "cut," we store an entry in the returned object that maps that digit to the corresponding letter. For example, if the user checked "T/0" in the UI, then the returned object might include { '0': 'T' }.
Returns:
A dictionary mapping each selected digit to its cut letter. Digits not selected are omitted.
- Type
- Object.<string, string>
Example
// Suppose checkboxes for T/0 and N/9 are selected.
const cutMap = getSelectedCutNumbers();
// cutMap -> { '0': 'T', '9': 'N' }
// You can then easily replace digits in a string:
const original = '80091';
const replaced = original.replace(/\d/g, digit => cutMap[digit] || digit);
// replaced -> '8TTN1'
getSelectedFormats() → {Array.<string>}
Collects the selected callsign formats from the form.
Checks the state of specific checkboxes to determine the selected formats and returns them as an array. Useful for dynamically gathering user preferences for callsign generation.
Returns:
An array of selected callsign formats.
- Type
- Array.<string>
getYourStation() → {Object|null}
Retrieves the current user's station configuration.
This function pulls data from the getInputs
module to retrieve user-specific
parameters like callsign, speed (WPM), volume, sidetone frequency, and name.
If no inputs are available, it returns null
. It also sets default values
for player
and qsb
.
- Source:
Returns:
The user's station configuration or null if inputs are unavailable.
- Type
- Object | null
isBackgroundStaticPlaying() → {boolean}
Checks whether the background static noise is currently playing.
Returns:
True if the static noise source is active, false otherwise.
- Type
- boolean
markFieldInvalid(inputId, errorMessage)
Marks a specific input field as invalid and displays an error message.
Adds a CSS class for invalid state and updates the associated error message
within a .invalid-feedback
element if present.
Parameters:
Name | Type | Description |
---|---|---|
inputId |
string | The ID of the input field to mark as invalid. |
errorMessage |
string | The error message to display. |
nextSingleStation(responseStartTime)
Fetches and sets up a new station in single mode after a completed QSO.
Creates a new station object, initializes it with a Morse player, and plays the station's callsign. Updates the game state and refocuses on the response field.
Parameters:
Name | Type | Description |
---|---|---|
responseStartTime |
number | The time at which the next station interaction begins. |
normalizeStationGain(stations) → {Array.<Object>}
Normalize the volume levels of a collection of station objects and create Morse players for each.
This function takes in an array of station objects, each containing at least a volume
property
(a numeric value) and other station-specific properties (such as callsign
). It calculates
the total volume of all stations combined. If the total volume exceeds 1, the function normalizes
all volumes so that the total does not surpass 1. This normalization ensures that multiple
stations can play audio simultaneously without any single station dominating the output.
After computing the normalization factor (scaling factor), it adjusts each station's volume by
multiplying it by this factor. Then it creates a Morse player instance (createMorsePlayer
) for
each station at the new normalized volume. The resulting array of station objects, each with a
player
property containing the corresponding Morse player instance, is returned.
Parameters:
Name | Type | Description |
---|---|---|
stations |
Array.<Object> | The array of station objects. Each station must have a |
Returns:
The array of station objects with their volumes normalized and a player
instance created for each one.
- Type
- Array.<Object>
Example
const stations = [
{ callsign: 'ABC', volume: 0.7 },
{ callsign: 'XYZ', volume: 0.6 }
];
const normalized = normalizeStationGain(stations);
// If total volume (1.3) is greater than 1, volumes are scaled down.
// For example, ABC might now have a volume of 0.538 and XYZ might have 0.462
// Each station in `normalized` now includes a `player` property.
openAccordionSection(sectionId)
Programmatically opens an accordion section.
Ensures that the specified accordion section is visible by checking its current
state and toggling it if necessary. Leverages Bootstrap's Collapse
API.
Parameters:
Name | Type | Description |
---|---|---|
sectionId |
string | The ID of the accordion section to open. |
printStation(station)
Prints out a station's information in a formatted manner.
Parameters:
Name | Type | Description |
---|---|---|
station |
Object | The station object to display. |
randomDigit() → {number}
Generates a random single-digit number.
Returns a random integer between 0 and 9 inclusive.
- Source:
Returns:
A random single-digit number.
- Type
- number
randomElement(array) → {*}
Selects a random element from an array.
Picks and returns one random element from the given array using a uniform distribution.
Parameters:
Name | Type | Description |
---|---|---|
array |
Array | The array to select a random element from. |
- Source:
Returns:
A random element from the array.
- Type
- *
reset()
Performs a full reset of the application.
Clears the results table, resets all variables, stops audio playback, and focuses on the response field. Adjusts the CQ button based on mode logic.
resetGameState()
Resets the game state and clears all UI elements.
Resets variables related to stations, attempts, and contacts. Clears the results table, disables the CQ button, stops all audio, and reinitializes the response field.
respondWithAllStations(stations, audioLock)
Responds by playing each station's Morse callsign after normalizing their volumes.
Logs the callsigns, normalizes their volumes, and then uses each station's player
to play their callsign. The audioLock
parameter controls the start timing of playback.
Parameters:
Name | Type | Description |
---|---|---|
stations |
Array.<Object> | Stations to respond to, each with a |
audioLock |
number | Base time offset for playback start. |
send()
Sends the user's response to a station or stations.
Matches the user's input against active stations, handles repeat requests, and processes partial or perfect matches. Plays responses and exchanges based on the mode's configuration. Adjusts the game state for each scenario.
stop()
Stops all audio playback and resets the CQ button.
Clears the game state for single mode, ensuring no active station remains. Leaves multi-station mode state untouched.
stopAllAudio()
Stops all audio playback and resets the audio context.
Closes the current audio context, clears the audio lock, and stops any active background static noise. Reinitializes a new audio context.
stopBackgroundStatic(noFade)
Stops the background static noise track.
Optionally applies a fade-out effect before stopping the audio source. Disconnects all related audio nodes and cleans up resources after stopping.
Parameters:
Name | Type | Description |
---|---|---|
noFade |
boolean | If true, stops the static immediately without fading. |
tu()
Finalizes a QSO (contact) in multi-station modes.
Compares the user's input in extra info fields against the current station's attributes. Logs results, updates the UI, and optionally fetches new stations. Plays the user's and station's sign-off messages.
updateActiveStations(numStations)
Updates the displayed number of active stations.
Parameters:
Name | Type | Description |
---|---|---|
numStations |
number | The current count of active stations. |
updateAudioLock(time)
Updates the audio lock time.
Prevents overlapping playback by ensuring no new audio can play until after the specified lock time.
Parameters:
Name | Type | Description |
---|---|---|
time |
number | The new lock time in seconds. |
updateStaticIntensity()
Updates the intensity of the background static noise.
Stops any currently playing static noise and attempts to recreate it with the updated QRN settings.
updateSummaryRow(tableName, extraopt)
Computes totals and averages for the current rows (excluding the very first row), and inserts/updates a summary row at the bottom. If there are fewer than 2 data rows, no summary row is shown.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
tableName |
string | The ID of the HTML table element. |
||
extra |
string | null |
<optional> |
null | Optional additional information to include in a fifth cell. |
validateInputs(inputs) → {boolean}
Validates the collected form inputs and ensures their logical consistency.
Performs checks for required fields, numerical range constraints, and mode-specific requirements. Marks invalid fields visually and expands the relevant sections of the form for easier user correction.
Parameters:
Name | Type | Description |
---|---|---|
inputs |
Object | The collected input data to validate. |
Returns:
True if all inputs are valid; false otherwise.
- Type
- boolean
weightedRandom(maxStations) → {number}
Generates a weighted random number based on the number of stations. Lower-numbered stations have higher probabilities.
Parameters:
Name | Type | Description |
---|---|---|
maxStations |
number | The total number of stations. |
Returns:
- A station number (1 to maxStations) based on weighted probability.
- Type
- number
weightedRandomElement(weightedArray) → {*}
Selects a random element from an array using weighted values.
Each object in the array should have:
- value: the item you want to pick
- weight: the numeric weight (or percentage) of that item
Example usage:
const fruits = [
{ value: 'apple', weight: 50 }, // 50% chance
{ value: 'banana', weight: 30 }, // 30% chance
{ value: 'mango', weight: 20 }, // 20% chance
];
const pickedFruit = weightedRandomElement(fruits);
console.log(pickedFruit); // Logs 'apple', 'banana', or 'mango' based on weights
Parameters:
Name | Type | Description |
---|---|---|
weightedArray |
Array | The array of objects to select from. |
- Source:
Returns:
A random element's value
from the array, based on the weights.
- Type
- *