netrigctl-node

1.0.0 • Public • Published

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'); // Adjust the path as needed

Make sure you have rigctld running and accessible from the host where your Node.js application is running.

Usage

  1. Instantiate the client:

    const rigClient = new RigClient('your_rigctld_host', 4532); // Replace with your host and port
  2. Set up event listeners:

    Listen for the dumpStateParsed event before sending commands that rely on rig capabilities.

    rigClient.on('dumpStateParsed', async (dumpState) => {
        //console.log('Dump State Parsing Complete:', dumpState);
        // Now you can access and use the parsed data in the dumpState object
        // e.g., console.log(dumpState.rxRanges);
    
        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(); // Disconnect when done
        }
    });
    
    rigClient.on('error', (err) => {
        console.error('RigClient Error:', err);
    });
    
    rigClient.on('close', (hadError) => {
        console.log('RigClient connection closed.');
    });
  3. Connect to rigctld:

    rigClient.connect()
        .then(() => console.log('Connected to rigctld'))
        .catch(err => console.error('Connection failed:', err));
  4. 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.

Package Sidebar

Install

npm i netrigctl-node

Weekly Downloads

11

Version

1.0.0

License

ISC

Unpacked Size

103 kB

Total Files

5

Last publish

Collaborators

  • rinkoqwq