hamlib 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,8 @@ Control amateur radio transceivers from Node.js using the [Hamlib](https://hamli
5
5
  ## Features
6
6
 
7
7
  - **300+ Supported Radios** - Yaesu, Icom, Kenwood, Elecraft, FlexRadio, and more
8
- - **Full Async/Promise API** - Non-blocking operations with async/await support
8
+ - **Full Async/Promise API** - Non-blocking operations with async/await support
9
+ - **Comprehensive Serial Control** - 13 parameters for complete serial port configuration
9
10
  - **Multiple Connections** - Serial ports, network (rigctld), direct control
10
11
  - **TypeScript Ready** - Complete type definitions included
11
12
  - **Cross-platform** - Windows, Linux, macOS
@@ -13,7 +14,7 @@ Control amateur radio transceivers from Node.js using the [Hamlib](https://hamli
13
14
  ## Installation
14
15
 
15
16
  ```bash
16
- npm install node-hamlib
17
+ npm install hamlib
17
18
  ```
18
19
 
19
20
  ## Quick Start
@@ -155,17 +156,42 @@ const offset = await rig.getRepeaterOffset();
155
156
 
156
157
  ### Serial Configuration
157
158
 
159
+ Node-hamlib provides **comprehensive serial port configuration** with **13 parameters** covering all aspects of serial communication from basic data format to advanced timing control and device-specific features.
160
+
158
161
  ```javascript
159
- // Basic serial settings
160
- await rig.setSerialConfig('data_bits', '8');
161
- await rig.setSerialConfig('stop_bits', '1');
162
- await rig.setSerialConfig('serial_parity', 'None');
163
-
164
- // PTT/DCD methods
165
- await rig.setPttType('RIG'); // Use CAT command
166
- await rig.setDcdType('RIG'); // Use software squelch
162
+ // Configure serial parameters
163
+ await rig.setSerialConfig('rate', '115200'); // Baud rate: 150 to 4000000 bps
164
+ await rig.setSerialConfig('data_bits', '8'); // Data bits: 5, 6, 7, 8
165
+ await rig.setSerialConfig('serial_parity', 'None'); // Parity: None, Even, Odd, Mark, Space
166
+ await rig.setSerialConfig('timeout', '1000'); // Timeout in milliseconds
167
+ await rig.setSerialConfig('write_delay', '10'); // Inter-byte delay (ms)
168
+
169
+ // Read current settings
170
+ const rate = await rig.getSerialConfig('rate');
171
+ const parity = await rig.getSerialConfig('serial_parity');
172
+
173
+ // PTT/DCD configuration
174
+ await rig.setPttType('DTR'); // PTT: RIG, DTR, RTS, NONE, etc.
175
+ await rig.setDcdType('RIG'); // DCD: RIG, DSR, CTS, NONE, etc.
167
176
  ```
168
177
 
178
+ #### Complete Serial Configuration Reference
179
+
180
+ | Category | Parameter | Description | Supported Values |
181
+ |----------|-----------|-------------|------------------|
182
+ | **Basic Serial** | `data_bits` | Number of data bits | `5`, `6`, `7`, `8` |
183
+ | | `stop_bits` | Number of stop bits | `1`, `2` |
184
+ | | `serial_parity` | Parity checking | `None`, `Even`, `Odd`, `Mark`, `Space` |
185
+ | | `serial_handshake` | Flow control | `None`, `Hardware`, `Software` |
186
+ | **Control Signals** | `rts_state` | RTS line state | `ON`, `OFF`, `UNSET` |
187
+ | | `dtr_state` | DTR line state | `ON`, `OFF`, `UNSET` |
188
+ | **Communication** | `rate` | Baud rate (bps) | `150` to `4000000` |
189
+ | | `timeout` | I/O timeout (ms) | Any non-negative integer |
190
+ | | `retry` | Max retry count | Any non-negative integer |
191
+ | **Timing** | `write_delay` | Inter-byte delay (ms) | Any non-negative integer |
192
+ | | `post_write_delay` | Inter-command delay (ms) | Any non-negative integer |
193
+ | **Advanced** | `flushx` | MicroHam flush mode | `true`, `false` |
194
+
169
195
  ## Complete Example
170
196
 
171
197
  ```javascript
package/index.d.ts CHANGED
@@ -156,11 +156,43 @@ type VfoOperationType = 'CPY' | 'XCHG' | 'FROM_VFO' | 'TO_VFO' | 'MCL' | 'UP' |
156
156
  'DOWN' | 'BAND_UP' | 'BAND_DOWN' | 'LEFT' | 'RIGHT' |
157
157
  'TUNE' | 'TOGGLE';
158
158
 
159
+ /**
160
+ * Supported baud rates for serial communication
161
+ */
162
+ type SerialBaudRate = '150' | '300' | '600' | '1200' | '2400' | '4800' | '9600' | '19200' |
163
+ '38400' | '57600' | '115200' | '230400' | '460800' | '500000' |
164
+ '576000' | '921600' | '1000000' | '1152000' | '1500000' | '2000000' |
165
+ '2500000' | '3000000' | '3500000' | '4000000';
166
+
167
+ /**
168
+ * Serial parity values
169
+ */
170
+ type SerialParity = 'None' | 'Even' | 'Odd' | 'Mark' | 'Space';
171
+
172
+ /**
173
+ * Serial handshake values
174
+ */
175
+ type SerialHandshake = 'None' | 'Hardware' | 'Software';
176
+
177
+ /**
178
+ * Serial control signal states
179
+ */
180
+ type SerialControlState = 'ON' | 'OFF' | 'UNSET';
181
+
159
182
  /**
160
183
  * Serial configuration parameter names
161
184
  */
162
- type SerialConfigParam = 'data_bits' | 'stop_bits' | 'serial_parity' | 'serial_handshake' |
163
- 'rts_state' | 'dtr_state';
185
+ type SerialConfigParam =
186
+ // Basic serial settings
187
+ 'data_bits' | 'stop_bits' | 'serial_parity' | 'serial_handshake' |
188
+ // Control signals
189
+ 'rts_state' | 'dtr_state' |
190
+ // Communication settings
191
+ 'rate' | 'timeout' | 'retry' |
192
+ // Timing control
193
+ 'write_delay' | 'post_write_delay' |
194
+ // Advanced features
195
+ 'flushx';
164
196
 
165
197
  /**
166
198
  * PTT (Push-to-Talk) types
@@ -523,30 +555,55 @@ declare class HamLib {
523
555
 
524
556
  /**
525
557
  * Set serial port configuration parameter
526
- * @param paramName Parameter name ('data_bits', 'stop_bits', 'serial_parity', 'serial_handshake', 'rts_state', 'dtr_state')
527
- * @param paramValue Parameter value
558
+ * @param paramName Parameter name for serial configuration
559
+ * @param paramValue Parameter value as string
528
560
  * @example
529
- * // Set data bits to 8
561
+ * // Basic serial settings
530
562
  * await hamlib.setSerialConfig('data_bits', '8');
531
- *
532
- * // Set parity to even
563
+ * await hamlib.setSerialConfig('stop_bits', '1');
533
564
  * await hamlib.setSerialConfig('serial_parity', 'Even');
534
- *
535
- * // Set handshake to hardware
536
565
  * await hamlib.setSerialConfig('serial_handshake', 'Hardware');
566
+ *
567
+ * // Control signals
568
+ * await hamlib.setSerialConfig('rts_state', 'ON');
569
+ * await hamlib.setSerialConfig('dtr_state', 'OFF');
570
+ *
571
+ * // Communication settings
572
+ * await hamlib.setSerialConfig('rate', '115200');
573
+ * await hamlib.setSerialConfig('timeout', '1000');
574
+ * await hamlib.setSerialConfig('retry', '3');
575
+ *
576
+ * // Timing control
577
+ * await hamlib.setSerialConfig('write_delay', '10');
578
+ * await hamlib.setSerialConfig('post_write_delay', '50');
579
+ *
580
+ * // Advanced features
581
+ * await hamlib.setSerialConfig('flushx', 'true');
537
582
  */
538
583
  setSerialConfig(paramName: SerialConfigParam, paramValue: string): Promise<number>;
539
584
 
540
585
  /**
541
586
  * Get serial port configuration parameter
542
- * @param paramName Parameter name to retrieve
543
- * @returns Parameter value
587
+ * @param paramName Parameter name to retrieve (any SerialConfigParam)
588
+ * @returns Parameter value as string
544
589
  * @example
545
- * // Get current data bits setting
590
+ * // Get basic serial settings
546
591
  * const dataBits = await hamlib.getSerialConfig('data_bits');
547
- *
548
- * // Get current parity setting
549
592
  * const parity = await hamlib.getSerialConfig('serial_parity');
593
+ * const handshake = await hamlib.getSerialConfig('serial_handshake');
594
+ *
595
+ * // Get communication settings
596
+ * const rate = await hamlib.getSerialConfig('rate');
597
+ * const timeout = await hamlib.getSerialConfig('timeout');
598
+ * const retry = await hamlib.getSerialConfig('retry');
599
+ *
600
+ * // Get control signals
601
+ * const rtsState = await hamlib.getSerialConfig('rts_state');
602
+ * const dtrState = await hamlib.getSerialConfig('dtr_state');
603
+ *
604
+ * // Get timing and advanced settings
605
+ * const writeDelay = await hamlib.getSerialConfig('write_delay');
606
+ * const flushx = await hamlib.getSerialConfig('flushx');
550
607
  */
551
608
  getSerialConfig(paramName: SerialConfigParam): Promise<string>;
552
609
 
@@ -1045,7 +1102,8 @@ declare const nodeHamlib: {
1045
1102
  // Export types for use elsewhere
1046
1103
  export { ConnectionInfo, ModeInfo, SupportedRigInfo, AntennaInfo, VFO, RadioMode, MemoryChannelData,
1047
1104
  MemoryChannelInfo, SplitModeInfo, SplitStatusInfo, LevelType, FunctionType,
1048
- ScanType, VfoOperationType, SerialConfigParam, PttType, DcdType, SerialConfigOptions, HamLib };
1105
+ ScanType, VfoOperationType, SerialConfigParam, SerialBaudRate, SerialParity,
1106
+ SerialHandshake, SerialControlState, PttType, DcdType, SerialConfigOptions, HamLib };
1049
1107
 
1050
1108
  // Support both CommonJS and ES module exports
1051
1109
  // @ts-ignore
package/lib/index.js CHANGED
@@ -418,17 +418,35 @@ class HamLib {
418
418
 
419
419
  /**
420
420
  * Set serial port configuration parameter
421
- * @param {string} paramName - Parameter name ('data_bits', 'stop_bits', 'serial_parity', 'serial_handshake', 'rts_state', 'dtr_state')
421
+ * @param {string} paramName - Parameter name:
422
+ * - Serial settings: 'data_bits', 'stop_bits', 'serial_parity', 'serial_handshake'
423
+ * - Control signals: 'rts_state', 'dtr_state'
424
+ * - Communication: 'rate', 'timeout', 'retry'
425
+ * - Timing: 'write_delay', 'post_write_delay'
426
+ * - Advanced: 'flushx'
422
427
  * @param {string} paramValue - Parameter value
423
428
  * @example
424
- * // Set data bits to 8
429
+ * // Basic serial settings
425
430
  * hamlib.setSerialConfig('data_bits', '8');
426
- *
427
- * // Set parity to even
431
+ * hamlib.setSerialConfig('stop_bits', '1');
428
432
  * hamlib.setSerialConfig('serial_parity', 'Even');
429
- *
430
- * // Set handshake to hardware
431
433
  * hamlib.setSerialConfig('serial_handshake', 'Hardware');
434
+ *
435
+ * // Control signals
436
+ * hamlib.setSerialConfig('rts_state', 'ON');
437
+ * hamlib.setSerialConfig('dtr_state', 'OFF');
438
+ *
439
+ * // Communication settings
440
+ * hamlib.setSerialConfig('rate', '115200');
441
+ * hamlib.setSerialConfig('timeout', '1000');
442
+ * hamlib.setSerialConfig('retry', '3');
443
+ *
444
+ * // Timing control
445
+ * hamlib.setSerialConfig('write_delay', '10');
446
+ * hamlib.setSerialConfig('post_write_delay', '50');
447
+ *
448
+ * // Advanced features
449
+ * hamlib.setSerialConfig('flushx', 'true');
432
450
  */
433
451
  async setSerialConfig(paramName, paramValue) {
434
452
  return this._nativeInstance.setSerialConfig(paramName, paramValue);
@@ -436,14 +454,25 @@ class HamLib {
436
454
 
437
455
  /**
438
456
  * Get serial port configuration parameter
439
- * @param {string} paramName - Parameter name to retrieve
457
+ * @param {string} paramName - Parameter name to retrieve (same as setSerialConfig)
440
458
  * @returns {string} Parameter value
441
459
  * @example
442
- * // Get current data bits setting
460
+ * // Get basic serial settings
443
461
  * const dataBits = hamlib.getSerialConfig('data_bits');
444
- *
445
- * // Get current parity setting
446
462
  * const parity = hamlib.getSerialConfig('serial_parity');
463
+ * const handshake = hamlib.getSerialConfig('serial_handshake');
464
+ *
465
+ * // Get communication settings
466
+ * const rate = hamlib.getSerialConfig('rate');
467
+ * const timeout = hamlib.getSerialConfig('timeout');
468
+ *
469
+ * // Get control signals state
470
+ * const rtsState = hamlib.getSerialConfig('rts_state');
471
+ * const dtrState = hamlib.getSerialConfig('dtr_state');
472
+ *
473
+ * // Get timing settings
474
+ * const writeDelay = hamlib.getSerialConfig('write_delay');
475
+ * const flushx = hamlib.getSerialConfig('flushx');
447
476
  */
448
477
  async getSerialConfig(paramName) {
449
478
  return this._nativeInstance.getSerialConfig(paramName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hamlib",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Node.js wrapper for hamlib radio control library",
5
5
  "main": "index.js",
6
6
  "module": "lib/index.mjs",
Binary file
Binary file
Binary file
package/src/hamlib.cpp CHANGED
@@ -3,6 +3,7 @@
3
3
  #include <string>
4
4
  #include <vector>
5
5
  #include <memory>
6
+ #include <algorithm>
6
7
 
7
8
  // Cross-platform compatibility for hamlib token types
8
9
  // Linux versions use token_t, some others use hamlib_token_t
@@ -1185,6 +1186,66 @@ public:
1185
1186
  }
1186
1187
  hamlib_instance_->my_rig->state.rigport.parm.serial.dtr_state = state;
1187
1188
  result_code_ = RIG_OK;
1189
+ } else if (param_name_ == "rate") {
1190
+ int rate = std::stoi(param_value_);
1191
+ // Validate supported baud rates based on common values in Hamlib
1192
+ std::vector<int> valid_rates = {150, 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200,
1193
+ 230400, 460800, 500000, 576000, 921600, 1000000, 1152000, 1500000,
1194
+ 2000000, 2500000, 3000000, 3500000, 4000000};
1195
+ if (std::find(valid_rates.begin(), valid_rates.end(), rate) != valid_rates.end()) {
1196
+ hamlib_instance_->my_rig->state.rigport.parm.serial.rate = rate;
1197
+ result_code_ = RIG_OK;
1198
+ } else {
1199
+ result_code_ = -RIG_EINVAL;
1200
+ error_message_ = "Invalid baud rate value";
1201
+ }
1202
+ } else if (param_name_ == "timeout") {
1203
+ int timeout_val = std::stoi(param_value_);
1204
+ if (timeout_val >= 0) {
1205
+ hamlib_instance_->my_rig->state.rigport.timeout = timeout_val;
1206
+ result_code_ = RIG_OK;
1207
+ } else {
1208
+ result_code_ = -RIG_EINVAL;
1209
+ error_message_ = "Timeout must be non-negative";
1210
+ }
1211
+ } else if (param_name_ == "retry") {
1212
+ int retry_val = std::stoi(param_value_);
1213
+ if (retry_val >= 0) {
1214
+ hamlib_instance_->my_rig->state.rigport.retry = (short)retry_val;
1215
+ result_code_ = RIG_OK;
1216
+ } else {
1217
+ result_code_ = -RIG_EINVAL;
1218
+ error_message_ = "Retry count must be non-negative";
1219
+ }
1220
+ } else if (param_name_ == "write_delay") {
1221
+ int delay = std::stoi(param_value_);
1222
+ if (delay >= 0) {
1223
+ hamlib_instance_->my_rig->state.rigport.write_delay = delay;
1224
+ result_code_ = RIG_OK;
1225
+ } else {
1226
+ result_code_ = -RIG_EINVAL;
1227
+ error_message_ = "Write delay must be non-negative";
1228
+ }
1229
+ } else if (param_name_ == "post_write_delay") {
1230
+ int delay = std::stoi(param_value_);
1231
+ if (delay >= 0) {
1232
+ hamlib_instance_->my_rig->state.rigport.post_write_delay = delay;
1233
+ result_code_ = RIG_OK;
1234
+ } else {
1235
+ result_code_ = -RIG_EINVAL;
1236
+ error_message_ = "Post write delay must be non-negative";
1237
+ }
1238
+ } else if (param_name_ == "flushx") {
1239
+ if (param_value_ == "true" || param_value_ == "1") {
1240
+ hamlib_instance_->my_rig->state.rigport.flushx = 1;
1241
+ result_code_ = RIG_OK;
1242
+ } else if (param_value_ == "false" || param_value_ == "0") {
1243
+ hamlib_instance_->my_rig->state.rigport.flushx = 0;
1244
+ result_code_ = RIG_OK;
1245
+ } else {
1246
+ result_code_ = -RIG_EINVAL;
1247
+ error_message_ = "Flushx must be true/false or 1/0";
1248
+ }
1188
1249
  } else {
1189
1250
  result_code_ = -RIG_EINVAL;
1190
1251
  error_message_ = "Unknown serial configuration parameter";
@@ -1278,6 +1339,24 @@ public:
1278
1339
  break;
1279
1340
  }
1280
1341
  result_code_ = RIG_OK;
1342
+ } else if (param_name_ == "rate") {
1343
+ param_value_ = std::to_string(hamlib_instance_->my_rig->state.rigport.parm.serial.rate);
1344
+ result_code_ = RIG_OK;
1345
+ } else if (param_name_ == "timeout") {
1346
+ param_value_ = std::to_string(hamlib_instance_->my_rig->state.rigport.timeout);
1347
+ result_code_ = RIG_OK;
1348
+ } else if (param_name_ == "retry") {
1349
+ param_value_ = std::to_string(hamlib_instance_->my_rig->state.rigport.retry);
1350
+ result_code_ = RIG_OK;
1351
+ } else if (param_name_ == "write_delay") {
1352
+ param_value_ = std::to_string(hamlib_instance_->my_rig->state.rigport.write_delay);
1353
+ result_code_ = RIG_OK;
1354
+ } else if (param_name_ == "post_write_delay") {
1355
+ param_value_ = std::to_string(hamlib_instance_->my_rig->state.rigport.post_write_delay);
1356
+ result_code_ = RIG_OK;
1357
+ } else if (param_name_ == "flushx") {
1358
+ param_value_ = hamlib_instance_->my_rig->state.rigport.flushx ? "true" : "false";
1359
+ result_code_ = RIG_OK;
1281
1360
  } else {
1282
1361
  result_code_ = -RIG_EINVAL;
1283
1362
  error_message_ = "Unknown serial configuration parameter";