hamlib 0.1.4 → 0.1.6
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 +181 -45
- package/index.d.ts +144 -20
- package/lib/index.js +237 -31
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/hamlib.node +0 -0
- package/prebuilds/linux-arm64/hamlib.node +0 -0
- package/prebuilds/linux-x64/hamlib.node +0 -0
- package/src/hamlib.cpp +769 -138
- package/src/hamlib.h +26 -1
package/lib/index.js
CHANGED
|
@@ -35,8 +35,16 @@ class HamLib {
|
|
|
35
35
|
* Must be called before other operations
|
|
36
36
|
* @throws {Error} Throws error when connection fails
|
|
37
37
|
*/
|
|
38
|
-
open() {
|
|
39
|
-
return
|
|
38
|
+
async open() {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
this._nativeInstance.open((err, result) => {
|
|
41
|
+
if (err) {
|
|
42
|
+
reject(new Error(err.message || 'Failed to open connection'));
|
|
43
|
+
} else {
|
|
44
|
+
resolve(result);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
/**
|
|
@@ -44,8 +52,16 @@ class HamLib {
|
|
|
44
52
|
* @param {string} vfo - VFO identifier ('VFO-A' or 'VFO-B')
|
|
45
53
|
* @throws {Error} Throws error when device doesn't support or operation fails
|
|
46
54
|
*/
|
|
47
|
-
setVfo(vfo) {
|
|
48
|
-
return
|
|
55
|
+
async setVfo(vfo) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
this._nativeInstance.setVfo(vfo, (err, result) => {
|
|
58
|
+
if (err) {
|
|
59
|
+
reject(new Error(err.message || 'Failed to set VFO'));
|
|
60
|
+
} else {
|
|
61
|
+
resolve(result);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
49
65
|
}
|
|
50
66
|
|
|
51
67
|
/**
|
|
@@ -53,11 +69,26 @@ class HamLib {
|
|
|
53
69
|
* @param {number} frequency - Frequency in hertz
|
|
54
70
|
* @param {string} [vfo] - Optional VFO ('VFO-A' or 'VFO-B')
|
|
55
71
|
*/
|
|
56
|
-
setFrequency(frequency, vfo) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
72
|
+
async setFrequency(frequency, vfo) {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
if (vfo) {
|
|
75
|
+
this._nativeInstance.setFrequency(frequency, vfo, (err, result) => {
|
|
76
|
+
if (err) {
|
|
77
|
+
reject(new Error(err.message || 'Failed to set frequency'));
|
|
78
|
+
} else {
|
|
79
|
+
resolve(result);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
this._nativeInstance.setFrequency(frequency, (err, result) => {
|
|
84
|
+
if (err) {
|
|
85
|
+
reject(new Error(err.message || 'Failed to set frequency'));
|
|
86
|
+
} else {
|
|
87
|
+
resolve(result);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
61
92
|
}
|
|
62
93
|
|
|
63
94
|
/**
|
|
@@ -65,27 +96,58 @@ class HamLib {
|
|
|
65
96
|
* @param {string} mode - Radio mode ('USB', 'LSB', 'FM', 'PKTFM', etc.)
|
|
66
97
|
* @param {string} [bandwidth] - Optional bandwidth ('narrow', 'wide')
|
|
67
98
|
*/
|
|
68
|
-
setMode(mode, bandwidth) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
99
|
+
async setMode(mode, bandwidth) {
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
if (bandwidth) {
|
|
102
|
+
this._nativeInstance.setMode(mode, bandwidth, (err, result) => {
|
|
103
|
+
if (err) {
|
|
104
|
+
reject(new Error(err.message || 'Failed to set mode'));
|
|
105
|
+
} else {
|
|
106
|
+
resolve(result);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
} else {
|
|
110
|
+
this._nativeInstance.setMode(mode, (err, result) => {
|
|
111
|
+
if (err) {
|
|
112
|
+
reject(new Error(err.message || 'Failed to set mode'));
|
|
113
|
+
} else {
|
|
114
|
+
resolve(result);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
73
119
|
}
|
|
74
120
|
|
|
75
121
|
/**
|
|
76
122
|
* Set PTT (Push-to-Talk) status
|
|
77
123
|
* @param {boolean} state - true to enable PTT, false to disable
|
|
78
124
|
*/
|
|
79
|
-
setPtt(state) {
|
|
80
|
-
return
|
|
125
|
+
async setPtt(state) {
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
this._nativeInstance.setPtt(state, (err, result) => {
|
|
128
|
+
if (err) {
|
|
129
|
+
reject(new Error(err.message || 'Failed to set PTT'));
|
|
130
|
+
} else {
|
|
131
|
+
resolve(result);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
81
135
|
}
|
|
82
136
|
|
|
83
137
|
/**
|
|
84
138
|
* Get current VFO
|
|
85
139
|
* @returns {string} Current VFO identifier
|
|
86
140
|
*/
|
|
87
|
-
getVfo() {
|
|
88
|
-
return
|
|
141
|
+
async getVfo() {
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
this._nativeInstance.getVfo((err, result) => {
|
|
144
|
+
if (err) {
|
|
145
|
+
reject(new Error(err.message || 'Failed to get VFO'));
|
|
146
|
+
} else {
|
|
147
|
+
resolve(result);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
89
151
|
}
|
|
90
152
|
|
|
91
153
|
/**
|
|
@@ -93,43 +155,90 @@ class HamLib {
|
|
|
93
155
|
* @param {string} [vfo] - Optional VFO ('VFO-A' or 'VFO-B')
|
|
94
156
|
* @returns {number} Current frequency in hertz
|
|
95
157
|
*/
|
|
96
|
-
getFrequency(vfo) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
158
|
+
async getFrequency(vfo) {
|
|
159
|
+
return new Promise((resolve, reject) => {
|
|
160
|
+
if (vfo) {
|
|
161
|
+
this._nativeInstance.getFrequency(vfo, (err, result) => {
|
|
162
|
+
if (err) {
|
|
163
|
+
reject(new Error(err.message || 'Failed to get frequency'));
|
|
164
|
+
} else {
|
|
165
|
+
resolve(result);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
} else {
|
|
169
|
+
this._nativeInstance.getFrequency((err, result) => {
|
|
170
|
+
if (err) {
|
|
171
|
+
reject(new Error(err.message || 'Failed to get frequency'));
|
|
172
|
+
} else {
|
|
173
|
+
resolve(result);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
});
|
|
101
178
|
}
|
|
102
179
|
|
|
103
180
|
/**
|
|
104
181
|
* Get current radio mode
|
|
105
182
|
* @returns {Object} Object containing mode and bandwidth information
|
|
106
183
|
*/
|
|
107
|
-
getMode() {
|
|
108
|
-
return
|
|
184
|
+
async getMode() {
|
|
185
|
+
return new Promise((resolve, reject) => {
|
|
186
|
+
this._nativeInstance.getMode((err, result) => {
|
|
187
|
+
if (err) {
|
|
188
|
+
reject(new Error(err.message || 'Failed to get mode'));
|
|
189
|
+
} else {
|
|
190
|
+
resolve(result);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
109
194
|
}
|
|
110
195
|
|
|
111
196
|
/**
|
|
112
197
|
* Get current signal strength
|
|
113
198
|
* @returns {number} Signal strength value
|
|
114
199
|
*/
|
|
115
|
-
getStrength() {
|
|
116
|
-
return
|
|
200
|
+
async getStrength() {
|
|
201
|
+
return new Promise((resolve, reject) => {
|
|
202
|
+
this._nativeInstance.getStrength((err, result) => {
|
|
203
|
+
if (err) {
|
|
204
|
+
reject(new Error(err.message || 'Failed to get signal strength'));
|
|
205
|
+
} else {
|
|
206
|
+
resolve(result);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
117
210
|
}
|
|
118
211
|
|
|
119
212
|
/**
|
|
120
213
|
* Close connection to device
|
|
121
214
|
* Connection can be re-established by calling open()
|
|
122
215
|
*/
|
|
123
|
-
close() {
|
|
124
|
-
return
|
|
216
|
+
async close() {
|
|
217
|
+
return new Promise((resolve, reject) => {
|
|
218
|
+
this._nativeInstance.close((err, result) => {
|
|
219
|
+
if (err) {
|
|
220
|
+
reject(new Error(err.message || 'Failed to close connection'));
|
|
221
|
+
} else {
|
|
222
|
+
resolve(result);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
});
|
|
125
226
|
}
|
|
126
227
|
|
|
127
228
|
/**
|
|
128
229
|
* Destroy connection to device
|
|
129
230
|
* Object reference should be deleted after calling this
|
|
130
231
|
*/
|
|
131
|
-
destroy() {
|
|
132
|
-
return
|
|
232
|
+
async destroy() {
|
|
233
|
+
return new Promise((resolve, reject) => {
|
|
234
|
+
this._nativeInstance.destroy((err, result) => {
|
|
235
|
+
if (err) {
|
|
236
|
+
reject(new Error(err.message || 'Failed to destroy connection'));
|
|
237
|
+
} else {
|
|
238
|
+
resolve(result);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
});
|
|
133
242
|
}
|
|
134
243
|
|
|
135
244
|
/**
|
|
@@ -367,6 +476,103 @@ class HamLib {
|
|
|
367
476
|
getAntenna() {
|
|
368
477
|
return this._nativeInstance.getAntenna();
|
|
369
478
|
}
|
|
479
|
+
|
|
480
|
+
// Serial Port Configuration
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Set serial port configuration parameter
|
|
484
|
+
* @param {string} paramName - Parameter name ('data_bits', 'stop_bits', 'serial_parity', 'serial_handshake', 'rts_state', 'dtr_state')
|
|
485
|
+
* @param {string} paramValue - Parameter value
|
|
486
|
+
* @example
|
|
487
|
+
* // Set data bits to 8
|
|
488
|
+
* hamlib.setSerialConfig('data_bits', '8');
|
|
489
|
+
*
|
|
490
|
+
* // Set parity to even
|
|
491
|
+
* hamlib.setSerialConfig('serial_parity', 'Even');
|
|
492
|
+
*
|
|
493
|
+
* // Set handshake to hardware
|
|
494
|
+
* hamlib.setSerialConfig('serial_handshake', 'Hardware');
|
|
495
|
+
*/
|
|
496
|
+
setSerialConfig(paramName, paramValue) {
|
|
497
|
+
return this._nativeInstance.setSerialConfig(paramName, paramValue);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Get serial port configuration parameter
|
|
502
|
+
* @param {string} paramName - Parameter name to retrieve
|
|
503
|
+
* @returns {string} Parameter value
|
|
504
|
+
* @example
|
|
505
|
+
* // Get current data bits setting
|
|
506
|
+
* const dataBits = hamlib.getSerialConfig('data_bits');
|
|
507
|
+
*
|
|
508
|
+
* // Get current parity setting
|
|
509
|
+
* const parity = hamlib.getSerialConfig('serial_parity');
|
|
510
|
+
*/
|
|
511
|
+
getSerialConfig(paramName) {
|
|
512
|
+
return this._nativeInstance.getSerialConfig(paramName);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Set PTT (Push-to-Talk) type
|
|
517
|
+
* @param {string} pttType - PTT type ('RIG', 'DTR', 'RTS', 'PARALLEL', 'CM108', 'GPIO', 'GPION', 'NONE')
|
|
518
|
+
* @example
|
|
519
|
+
* // Use DTR line for PTT
|
|
520
|
+
* hamlib.setPttType('DTR');
|
|
521
|
+
*
|
|
522
|
+
* // Use RTS line for PTT
|
|
523
|
+
* hamlib.setPttType('RTS');
|
|
524
|
+
*
|
|
525
|
+
* // Use CAT command for PTT
|
|
526
|
+
* hamlib.setPttType('RIG');
|
|
527
|
+
*/
|
|
528
|
+
setPttType(pttType) {
|
|
529
|
+
return this._nativeInstance.setPttType(pttType);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Get current PTT type
|
|
534
|
+
* @returns {string} Current PTT type
|
|
535
|
+
*/
|
|
536
|
+
getPttType() {
|
|
537
|
+
return this._nativeInstance.getPttType();
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Set DCD (Data Carrier Detect) type
|
|
542
|
+
* @param {string} dcdType - DCD type ('RIG', 'DSR', 'CTS', 'CD', 'PARALLEL', 'CM108', 'GPIO', 'GPION', 'NONE')
|
|
543
|
+
* @example
|
|
544
|
+
* // Use DSR line for DCD
|
|
545
|
+
* hamlib.setDcdType('DSR');
|
|
546
|
+
*
|
|
547
|
+
* // Use CTS line for DCD
|
|
548
|
+
* hamlib.setDcdType('CTS');
|
|
549
|
+
*
|
|
550
|
+
* // Use CAT command for DCD
|
|
551
|
+
* hamlib.setDcdType('RIG');
|
|
552
|
+
*/
|
|
553
|
+
setDcdType(dcdType) {
|
|
554
|
+
return this._nativeInstance.setDcdType(dcdType);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Get current DCD type
|
|
559
|
+
* @returns {string} Current DCD type
|
|
560
|
+
*/
|
|
561
|
+
getDcdType() {
|
|
562
|
+
return this._nativeInstance.getDcdType();
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Get supported serial configuration options
|
|
567
|
+
* @returns {Object} Object containing all supported configuration parameters and their possible values
|
|
568
|
+
* @example
|
|
569
|
+
* const configs = hamlib.getSupportedSerialConfigs();
|
|
570
|
+
* console.log('Supported data bits:', configs.serial.data_bits);
|
|
571
|
+
* console.log('Supported PTT types:', configs.ptt_type);
|
|
572
|
+
*/
|
|
573
|
+
getSupportedSerialConfigs() {
|
|
574
|
+
return this._nativeInstance.getSupportedSerialConfigs();
|
|
575
|
+
}
|
|
370
576
|
}
|
|
371
577
|
|
|
372
578
|
// Export for CommonJS
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|