netrigctl-node
This project is a Node.js class designed to interface with rigctld, the Hamlib TCP server for controlling amateur radio transceivers.
Features
- TCP connection to
rigctld.
- Command queuing mechanism to handle sequential commands.
- Support for various rigctld commands (
get_freq, set_freq, get_mode, set_mode, get_level, set_level, etc.).
- Event emitters for connection status (
connect, end, close, error) and successful dump state parsing (dumpStateParsed).
Installation
npm install netrigctl-node
Then, in your code:
const { RigClient } = require('netrigctl-node');
Make sure you have rigctld running and accessible from the host where your Node.js application is running.
Usage
-
Instantiate the client:
const rigClient = new RigClient('your_rigctld_host', 4532);
-
Set up event listeners:
Listen for the dumpStateParsed event before sending commands that rely on rig capabilities.
rigClient.on('dumpStateParsed', async (dumpState) => {
try {
const freq = await rigClient.get_freq();
console.log('Current Frequency:', freq);
const pttStatus = await rigClient.get_ptt();
console.log('Current PTT Status:', pttStatus);
await rigClient.set_freq(14270000);
console.log('Set frequency to 14.27 MHz');
const newFreq = await rigClient.get_freq();
console.log('New Frequency:', newFreq);
await rigClient.set_mode('USB', 3000);
console.log('Set mode to USB 3000');
const { mode, passband } = await rigClient.get_mode();
console.log('Current Mode:', mode, 'Passband:', passband);
const nr = await rigClient.get_level('NR');
console.log('Current NR:', nr);
} catch (error) {
console.error('Command execution error:', error);
} finally {
rigClient.disconnect();
}
});
rigClient.on('error', (err) => {
console.error('RigClient Error:', err);
});
rigClient.on('close', (hadError) => {
console.log('RigClient connection closed.');
});
-
Connect to rigctld:
rigClient.connect()
.then(() => console.log('Connected to rigctld'))
.catch(err => console.error('Connection failed:', err));
-
Disconnect:
rigClient.disconnect();
Command Timeout
Commands queued via queueCommand have a default timeout of 10 seconds. If a response is not received within this time, the command's Promise will be rejected with a timeout error. You can specify a different timeout when calling queueCommand (although the public methods like get_freq do not currently expose this option, it's available internally).
Dump State Parsing
The RigClient automatically parses the \dump_state output into a structured object available via rigClient.getDumpStateData() after the dumpStateParsed event. This data includes supported frequency ranges, modes, filters, and capability bitmasks, which are used internally for the checkCapability method.
Error Handling
Errors (connection errors, rigctld errors, command timeouts) are emitted via the 'error' event and also cause the specific command's Promise to be rejected.