hamlib 0.1.2
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/COPYING +339 -0
- package/Readme.md +253 -0
- package/binding.gyp +152 -0
- package/index.d.ts +165 -0
- package/index.js +5 -0
- package/lib/binary-loader.js +95 -0
- package/lib/index.js +138 -0
- package/lib/index.mjs +14 -0
- package/package.json +68 -0
- 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/addon.cpp +17 -0
- package/src/decoder.cpp +128 -0
- package/src/decoder.h +21 -0
- package/src/hamlib.cpp +476 -0
- package/src/hamlib.h +44 -0
package/binding.gyp
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "hamlib",
|
|
5
|
+
"sources": [
|
|
6
|
+
"src/hamlib.cpp",
|
|
7
|
+
"src/decoder.cpp",
|
|
8
|
+
"src/addon.cpp"
|
|
9
|
+
],
|
|
10
|
+
"include_dirs": [
|
|
11
|
+
"include",
|
|
12
|
+
"<!@(node -p \"require('node-addon-api').include\")"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": [
|
|
15
|
+
"<!(node -p \"require('node-addon-api').gyp\")"
|
|
16
|
+
],
|
|
17
|
+
"defines": [
|
|
18
|
+
"NAPI_DISABLE_CPP_EXCEPTIONS"
|
|
19
|
+
],
|
|
20
|
+
"cflags!": [ "-fno-exceptions" ],
|
|
21
|
+
"cflags_cc!": [ "-fno-exceptions" ],
|
|
22
|
+
"conditions": [
|
|
23
|
+
# Linux configuration
|
|
24
|
+
["OS==\"linux\"", {
|
|
25
|
+
"include_dirs": [
|
|
26
|
+
"/usr/include",
|
|
27
|
+
"/usr/local/include"
|
|
28
|
+
],
|
|
29
|
+
"libraries": [
|
|
30
|
+
"-L/usr/lib",
|
|
31
|
+
"-L/usr/local/lib",
|
|
32
|
+
"-lhamlib"
|
|
33
|
+
]
|
|
34
|
+
}],
|
|
35
|
+
# macOS configuration
|
|
36
|
+
["OS==\"mac\"", {
|
|
37
|
+
"include_dirs": [
|
|
38
|
+
"/usr/local/include",
|
|
39
|
+
"/opt/homebrew/include"
|
|
40
|
+
],
|
|
41
|
+
"libraries": [
|
|
42
|
+
"-L/usr/local/lib",
|
|
43
|
+
"-L/opt/homebrew/lib",
|
|
44
|
+
"-lhamlib"
|
|
45
|
+
],
|
|
46
|
+
"xcode_settings": {
|
|
47
|
+
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
48
|
+
"CLANG_CXX_LIBRARY": "libc++",
|
|
49
|
+
"MACOSX_DEPLOYMENT_TARGET": "10.15"
|
|
50
|
+
}
|
|
51
|
+
}],
|
|
52
|
+
# Windows configuration
|
|
53
|
+
["OS==\"win\"", {
|
|
54
|
+
"defines": [
|
|
55
|
+
"WIN32_LEAN_AND_MEAN",
|
|
56
|
+
"_WIN32_WINNT=0x0600"
|
|
57
|
+
],
|
|
58
|
+
"conditions": [
|
|
59
|
+
["target_arch==\"x64\"", {
|
|
60
|
+
"conditions": [
|
|
61
|
+
# Check if we're in MinGW environment (HAMLIB_ROOT is set to /mingw64)
|
|
62
|
+
["\"<!(node -e \"console.log(process.env.HAMLIB_ROOT || '')\")\"==\"/mingw64\"", {
|
|
63
|
+
"include_dirs": [
|
|
64
|
+
"/mingw64/include"
|
|
65
|
+
],
|
|
66
|
+
"library_dirs": [
|
|
67
|
+
"/mingw64/lib"
|
|
68
|
+
],
|
|
69
|
+
"libraries": [
|
|
70
|
+
"-lhamlib",
|
|
71
|
+
"-lws2_32",
|
|
72
|
+
"-lwinmm"
|
|
73
|
+
],
|
|
74
|
+
"cflags": [
|
|
75
|
+
"-I/mingw64/include"
|
|
76
|
+
],
|
|
77
|
+
"ldflags": [
|
|
78
|
+
"-L/mingw64/lib",
|
|
79
|
+
"-static-libgcc",
|
|
80
|
+
"-static-libstdc++"
|
|
81
|
+
]
|
|
82
|
+
}, {
|
|
83
|
+
# Traditional Windows build with Visual C++
|
|
84
|
+
"include_dirs": [
|
|
85
|
+
# Try environment variable in different formats
|
|
86
|
+
"<!(node -e \"console.log((process.env.HAMLIB_ROOT || 'C:/hamlib') + '/include')\")",
|
|
87
|
+
# Fallback paths
|
|
88
|
+
"C:/hamlib/include",
|
|
89
|
+
"C:/Program Files/Hamlib/include",
|
|
90
|
+
"C:/Program Files (x86)/Hamlib/include"
|
|
91
|
+
],
|
|
92
|
+
"library_dirs": [
|
|
93
|
+
# Try environment variable paths
|
|
94
|
+
"<!(node -e \"console.log((process.env.HAMLIB_ROOT || 'C:/hamlib') + '/bin')\")",
|
|
95
|
+
"<!(node -e \"console.log((process.env.HAMLIB_ROOT || 'C:/hamlib') + '/lib')\")",
|
|
96
|
+
"<!(node -e \"console.log((process.env.HAMLIB_ROOT || 'C:/hamlib') + '/lib/x64')\")",
|
|
97
|
+
"<!(node -e \"console.log((process.env.HAMLIB_ROOT || 'C:/hamlib') + '/lib/msvc')\")",
|
|
98
|
+
# Fallback paths
|
|
99
|
+
"C:/hamlib/bin",
|
|
100
|
+
"C:/hamlib/lib",
|
|
101
|
+
"C:/hamlib/lib/x64",
|
|
102
|
+
"C:/hamlib/lib/Release",
|
|
103
|
+
"C:/Program Files/Hamlib/bin",
|
|
104
|
+
"C:/Program Files/Hamlib/lib",
|
|
105
|
+
"C:/Program Files (x86)/Hamlib/bin",
|
|
106
|
+
"C:/Program Files (x86)/Hamlib/lib"
|
|
107
|
+
],
|
|
108
|
+
"libraries": [
|
|
109
|
+
# Try to link against the DLL import library
|
|
110
|
+
"libhamlib-4.dll.a",
|
|
111
|
+
"hamlib-4.dll.a",
|
|
112
|
+
"libhamlib.dll.a",
|
|
113
|
+
"hamlib.dll.a",
|
|
114
|
+
# Fallback to static libraries if available
|
|
115
|
+
"libhamlib-4.lib",
|
|
116
|
+
"hamlib-4.lib",
|
|
117
|
+
"libhamlib.lib",
|
|
118
|
+
"hamlib.lib"
|
|
119
|
+
],
|
|
120
|
+
"conditions": [
|
|
121
|
+
# Add pthread paths only if PTHREAD_ROOT is set
|
|
122
|
+
["\"<!(node -e \"console.log(process.env.PTHREAD_ROOT || '')\")\"!=\"\"", {
|
|
123
|
+
"include_dirs": [
|
|
124
|
+
"<!(node -e \"console.log((process.env.PTHREAD_ROOT || 'C:/pthread-win32'))\")"
|
|
125
|
+
],
|
|
126
|
+
"library_dirs": [
|
|
127
|
+
"<!(node -e \"console.log((process.env.PTHREAD_ROOT || 'C:/pthread-win32') + '/lib')\")",
|
|
128
|
+
"<!(node -e \"console.log((process.env.PTHREAD_ROOT || 'C:/pthread-win32') + '/lib/x64')\")"
|
|
129
|
+
],
|
|
130
|
+
"libraries": [
|
|
131
|
+
"pthreadVC2.lib",
|
|
132
|
+
"pthreadVCE2.lib",
|
|
133
|
+
"pthreadVSE2.lib",
|
|
134
|
+
"pthread.lib"
|
|
135
|
+
]
|
|
136
|
+
}]
|
|
137
|
+
],
|
|
138
|
+
"msvs_settings": {
|
|
139
|
+
"VCCLCompilerTool": {
|
|
140
|
+
"ExceptionHandling": 1,
|
|
141
|
+
"AdditionalOptions": ["/std:c++14"]
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}]
|
|
145
|
+
]
|
|
146
|
+
}]
|
|
147
|
+
]
|
|
148
|
+
}]
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection information interface
|
|
3
|
+
*/
|
|
4
|
+
interface ConnectionInfo {
|
|
5
|
+
/** Connection type: serial or network */
|
|
6
|
+
connectionType: 'serial' | 'network';
|
|
7
|
+
/** Port path or network address */
|
|
8
|
+
portPath: string;
|
|
9
|
+
/** Connection status */
|
|
10
|
+
connected: boolean;
|
|
11
|
+
/** Original model number */
|
|
12
|
+
originalModel: number;
|
|
13
|
+
/** Actual model number used */
|
|
14
|
+
actualModel: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Radio mode information interface
|
|
19
|
+
*/
|
|
20
|
+
interface ModeInfo {
|
|
21
|
+
/** Radio mode character */
|
|
22
|
+
mode: string;
|
|
23
|
+
/** Bandwidth width */
|
|
24
|
+
width: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* VFO type
|
|
29
|
+
*/
|
|
30
|
+
type VFO = 'VFO-A' | 'VFO-B';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Radio mode type
|
|
34
|
+
*/
|
|
35
|
+
type RadioMode = 'USB' | 'LSB' | 'FM' | 'PKTFM' | 'AM' | 'CW' | 'RTTY' | 'DIG' | string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* HamLib class - for controlling amateur radio devices
|
|
39
|
+
*/
|
|
40
|
+
declare class HamLib {
|
|
41
|
+
/**
|
|
42
|
+
* Constructor
|
|
43
|
+
* @param model Radio model number (execute rigctl -l to find your device model number)
|
|
44
|
+
* @param port Optional port path
|
|
45
|
+
* - Serial connection: '/dev/ttyUSB0' (Linux default), '/dev/cu.usbserial-XXXX' (macOS), 'COM1' (Windows)
|
|
46
|
+
* - Network connection: 'localhost:4532' or '192.168.1.100:4532' (automatically switches to NETRIGCTL mode)
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* // Use default serial port
|
|
50
|
+
* const rig = new HamLib(1035);
|
|
51
|
+
*
|
|
52
|
+
* // Use custom serial port
|
|
53
|
+
* const rig = new HamLib(1035, '/dev/ttyUSB1');
|
|
54
|
+
*
|
|
55
|
+
* // Network connection to rigctld
|
|
56
|
+
* const rig = new HamLib(1035, 'localhost:4532');
|
|
57
|
+
*/
|
|
58
|
+
constructor(model: number, port?: string);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Open connection to device
|
|
62
|
+
* Must be called before other operations
|
|
63
|
+
* @throws Throws error when connection fails
|
|
64
|
+
*/
|
|
65
|
+
open(): void;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Set VFO (Variable Frequency Oscillator)
|
|
69
|
+
* @param vfo VFO identifier, typically 'VFO-A' or 'VFO-B'
|
|
70
|
+
* @throws Throws error when device doesn't support or operation fails
|
|
71
|
+
*/
|
|
72
|
+
setVfo(vfo: VFO): void;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Set frequency
|
|
76
|
+
* @param frequency Frequency value in hertz
|
|
77
|
+
* @param vfo Optional VFO to set frequency on ('VFO-A' or 'VFO-B'). If not specified, uses current VFO
|
|
78
|
+
* @example
|
|
79
|
+
* rig.setFrequency(144390000); // Set to 144.39MHz on current VFO
|
|
80
|
+
* rig.setFrequency(144390000, 'VFO-A'); // Set to 144.39MHz on VFO-A
|
|
81
|
+
* rig.setFrequency(144390000, 'VFO-B'); // Set to 144.39MHz on VFO-B
|
|
82
|
+
*/
|
|
83
|
+
setFrequency(frequency: number, vfo?: VFO): void;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Set radio mode
|
|
87
|
+
* @param mode Radio mode (such as 'USB', 'LSB', 'FM', 'PKTFM')
|
|
88
|
+
* @param bandwidth Optional bandwidth setting ('narrow', 'wide', or default)
|
|
89
|
+
* @note Operates on the current VFO (RIG_VFO_CURR)
|
|
90
|
+
* @example
|
|
91
|
+
* rig.setMode('USB');
|
|
92
|
+
* rig.setMode('FM', 'narrow');
|
|
93
|
+
*/
|
|
94
|
+
setMode(mode: RadioMode, bandwidth?: 'narrow' | 'wide'): void;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Set PTT (Push-to-Talk) status
|
|
98
|
+
* @param state true to enable PTT, false to disable PTT
|
|
99
|
+
* @note Operates on the current VFO (RIG_VFO_CURR)
|
|
100
|
+
*/
|
|
101
|
+
setPtt(state: boolean): void;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Get current VFO
|
|
105
|
+
* @returns Current VFO identifier
|
|
106
|
+
*/
|
|
107
|
+
getVfo(): string;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get current frequency
|
|
111
|
+
* @param vfo Optional VFO to get frequency from ('VFO-A' or 'VFO-B'). If not specified, uses current VFO
|
|
112
|
+
* @returns Current frequency value in hertz
|
|
113
|
+
* @example
|
|
114
|
+
* rig.getFrequency(); // Get frequency from current VFO
|
|
115
|
+
* rig.getFrequency('VFO-A'); // Get frequency from VFO-A
|
|
116
|
+
* rig.getFrequency('VFO-B'); // Get frequency from VFO-B
|
|
117
|
+
*/
|
|
118
|
+
getFrequency(vfo?: VFO): number;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Get current radio mode
|
|
122
|
+
* @returns Object containing mode and bandwidth information
|
|
123
|
+
* @note Operates on the current VFO (RIG_VFO_CURR)
|
|
124
|
+
*/
|
|
125
|
+
getMode(): ModeInfo;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Get current signal strength
|
|
129
|
+
* @returns Signal strength value
|
|
130
|
+
* @note Operates on the current VFO (RIG_VFO_CURR)
|
|
131
|
+
*/
|
|
132
|
+
getStrength(): number;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Close connection to device
|
|
136
|
+
* Does not destroy object, can re-establish connection by calling open()
|
|
137
|
+
*/
|
|
138
|
+
close(): void;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Destroy connection to device
|
|
142
|
+
* Should delete object reference after calling to enable garbage collection
|
|
143
|
+
*/
|
|
144
|
+
destroy(): void;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Get connection information
|
|
148
|
+
* @returns Object containing connection type, port path, connection status, and model numbers
|
|
149
|
+
*/
|
|
150
|
+
getConnectionInfo(): ConnectionInfo;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* node-hamlib module export object
|
|
155
|
+
*/
|
|
156
|
+
declare const nodeHamlib: {
|
|
157
|
+
HamLib: typeof HamLib;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// Export types for use elsewhere
|
|
161
|
+
export { ConnectionInfo, ModeInfo, VFO, RadioMode, HamLib };
|
|
162
|
+
|
|
163
|
+
// Support both CommonJS and ES module exports
|
|
164
|
+
export = nodeHamlib;
|
|
165
|
+
export default nodeHamlib;
|
package/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get the platform-specific binary file name
|
|
7
|
+
* @returns {string} Platform-specific binary file name
|
|
8
|
+
*/
|
|
9
|
+
function getPlatformBinaryPath() {
|
|
10
|
+
const platform = os.platform();
|
|
11
|
+
const arch = os.arch();
|
|
12
|
+
|
|
13
|
+
let platformTarget;
|
|
14
|
+
|
|
15
|
+
switch (platform) {
|
|
16
|
+
case 'win32':
|
|
17
|
+
platformTarget = `win32-${arch}`;
|
|
18
|
+
break;
|
|
19
|
+
case 'darwin':
|
|
20
|
+
platformTarget = `darwin-${arch}`;
|
|
21
|
+
break;
|
|
22
|
+
case 'linux':
|
|
23
|
+
platformTarget = `linux-${arch}`;
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error(`Unsupported platform: ${platform}-${arch}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return path.join(__dirname, '..', 'prebuilds', platformTarget, 'hamlib.node');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Find and load the native hamlib module
|
|
34
|
+
* @returns {Object} Native hamlib module
|
|
35
|
+
*/
|
|
36
|
+
function loadNativeModule() {
|
|
37
|
+
const possiblePaths = [
|
|
38
|
+
// First try prebuilt binary
|
|
39
|
+
getPlatformBinaryPath(),
|
|
40
|
+
// Fallback to locally compiled binary
|
|
41
|
+
path.join(__dirname, '..', 'build', 'Release', 'hamlib.node'),
|
|
42
|
+
path.join(__dirname, '..', 'build', 'Debug', 'hamlib.node'),
|
|
43
|
+
// Try different possible locations
|
|
44
|
+
path.join(__dirname, '..', 'hamlib.node'),
|
|
45
|
+
path.join(process.cwd(), 'hamlib.node'),
|
|
46
|
+
path.join(process.cwd(), 'build', 'Release', 'hamlib.node'),
|
|
47
|
+
path.join(process.cwd(), 'build', 'Debug', 'hamlib.node')
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
let lastError;
|
|
51
|
+
|
|
52
|
+
for (const binaryPath of possiblePaths) {
|
|
53
|
+
try {
|
|
54
|
+
if (fs.existsSync(binaryPath)) {
|
|
55
|
+
console.log(`Loading hamlib native module from: ${binaryPath}`);
|
|
56
|
+
return require(binaryPath);
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
lastError = error;
|
|
60
|
+
console.warn(`Failed to load hamlib from ${binaryPath}: ${error.message}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// If we get here, we couldn't find any working binary
|
|
65
|
+
const errorMessage = [
|
|
66
|
+
'Failed to load hamlib native module.',
|
|
67
|
+
'Tried the following paths:',
|
|
68
|
+
...possiblePaths.map(p => ` - ${p}`),
|
|
69
|
+
'',
|
|
70
|
+
'This may be due to one of the following reasons:',
|
|
71
|
+
'1. The prebuilt binary is not available for your platform',
|
|
72
|
+
'2. The module needs to be compiled from source',
|
|
73
|
+
'3. Missing system dependencies (libhamlib)',
|
|
74
|
+
'',
|
|
75
|
+
'To compile from source, run:',
|
|
76
|
+
' npm run build',
|
|
77
|
+
'',
|
|
78
|
+
'To install system dependencies:',
|
|
79
|
+
' Linux: sudo apt-get install libhamlib-dev',
|
|
80
|
+
' macOS: brew install hamlib',
|
|
81
|
+
' Windows: Install hamlib via vcpkg or from source'
|
|
82
|
+
].join('\n');
|
|
83
|
+
|
|
84
|
+
const error = new Error(errorMessage);
|
|
85
|
+
if (lastError) {
|
|
86
|
+
error.originalError = lastError;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = {
|
|
93
|
+
loadNativeModule,
|
|
94
|
+
getPlatformBinaryPath
|
|
95
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const { loadNativeModule } = require('./binary-loader');
|
|
2
|
+
|
|
3
|
+
// Load the native module
|
|
4
|
+
const nativeModule = loadNativeModule();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* HamLib class for controlling amateur radio devices
|
|
8
|
+
*
|
|
9
|
+
* This is a wrapper around the native hamlib module that provides
|
|
10
|
+
* a consistent interface for controlling amateur radio devices.
|
|
11
|
+
*/
|
|
12
|
+
class HamLib {
|
|
13
|
+
/**
|
|
14
|
+
* Create a new HamLib instance
|
|
15
|
+
* @param {number} model - Radio model number (run `rigctl -l` to find your device model)
|
|
16
|
+
* @param {string} [port] - Optional port path or network address
|
|
17
|
+
* - Serial: '/dev/ttyUSB0' (Linux), '/dev/cu.usbserial-XXXX' (macOS), 'COM1' (Windows)
|
|
18
|
+
* - Network: 'localhost:4532' or '192.168.1.100:4532' (auto-switches to NETRIGCTL mode)
|
|
19
|
+
*/
|
|
20
|
+
constructor(model, port) {
|
|
21
|
+
this._nativeInstance = new nativeModule.HamLib(model, port);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Open connection to the radio device
|
|
26
|
+
* Must be called before other operations
|
|
27
|
+
* @throws {Error} Throws error when connection fails
|
|
28
|
+
*/
|
|
29
|
+
open() {
|
|
30
|
+
return this._nativeInstance.open();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Set VFO (Variable Frequency Oscillator)
|
|
35
|
+
* @param {string} vfo - VFO identifier ('VFO-A' or 'VFO-B')
|
|
36
|
+
* @throws {Error} Throws error when device doesn't support or operation fails
|
|
37
|
+
*/
|
|
38
|
+
setVfo(vfo) {
|
|
39
|
+
return this._nativeInstance.setVfo(vfo);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Set frequency
|
|
44
|
+
* @param {number} frequency - Frequency in hertz
|
|
45
|
+
* @param {string} [vfo] - Optional VFO ('VFO-A' or 'VFO-B')
|
|
46
|
+
*/
|
|
47
|
+
setFrequency(frequency, vfo) {
|
|
48
|
+
if (vfo) {
|
|
49
|
+
return this._nativeInstance.setFrequency(frequency, vfo);
|
|
50
|
+
}
|
|
51
|
+
return this._nativeInstance.setFrequency(frequency);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Set radio mode
|
|
56
|
+
* @param {string} mode - Radio mode ('USB', 'LSB', 'FM', 'PKTFM', etc.)
|
|
57
|
+
* @param {string} [bandwidth] - Optional bandwidth ('narrow', 'wide')
|
|
58
|
+
*/
|
|
59
|
+
setMode(mode, bandwidth) {
|
|
60
|
+
if (bandwidth) {
|
|
61
|
+
return this._nativeInstance.setMode(mode, bandwidth);
|
|
62
|
+
}
|
|
63
|
+
return this._nativeInstance.setMode(mode);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Set PTT (Push-to-Talk) status
|
|
68
|
+
* @param {boolean} state - true to enable PTT, false to disable
|
|
69
|
+
*/
|
|
70
|
+
setPtt(state) {
|
|
71
|
+
return this._nativeInstance.setPtt(state);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get current VFO
|
|
76
|
+
* @returns {string} Current VFO identifier
|
|
77
|
+
*/
|
|
78
|
+
getVfo() {
|
|
79
|
+
return this._nativeInstance.getVfo();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Get current frequency
|
|
84
|
+
* @param {string} [vfo] - Optional VFO ('VFO-A' or 'VFO-B')
|
|
85
|
+
* @returns {number} Current frequency in hertz
|
|
86
|
+
*/
|
|
87
|
+
getFrequency(vfo) {
|
|
88
|
+
if (vfo) {
|
|
89
|
+
return this._nativeInstance.getFrequency(vfo);
|
|
90
|
+
}
|
|
91
|
+
return this._nativeInstance.getFrequency();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get current radio mode
|
|
96
|
+
* @returns {Object} Object containing mode and bandwidth information
|
|
97
|
+
*/
|
|
98
|
+
getMode() {
|
|
99
|
+
return this._nativeInstance.getMode();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get current signal strength
|
|
104
|
+
* @returns {number} Signal strength value
|
|
105
|
+
*/
|
|
106
|
+
getStrength() {
|
|
107
|
+
return this._nativeInstance.getStrength();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Close connection to device
|
|
112
|
+
* Connection can be re-established by calling open()
|
|
113
|
+
*/
|
|
114
|
+
close() {
|
|
115
|
+
return this._nativeInstance.close();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Destroy connection to device
|
|
120
|
+
* Object reference should be deleted after calling this
|
|
121
|
+
*/
|
|
122
|
+
destroy() {
|
|
123
|
+
return this._nativeInstance.destroy();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get connection information
|
|
128
|
+
* @returns {Object} Connection info including type, port, status, and model numbers
|
|
129
|
+
*/
|
|
130
|
+
getConnectionInfo() {
|
|
131
|
+
return this._nativeInstance.getConnectionInfo();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Export for CommonJS
|
|
136
|
+
module.exports = { HamLib };
|
|
137
|
+
module.exports.HamLib = HamLib;
|
|
138
|
+
module.exports.default = { HamLib };
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// Import the CommonJS module
|
|
10
|
+
const { HamLib } = require('./index.js');
|
|
11
|
+
|
|
12
|
+
// Export for ES modules
|
|
13
|
+
export { HamLib };
|
|
14
|
+
export default { HamLib };
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hamlib",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Node.js wrapper for hamlib radio control library",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"module": "lib/index.mjs",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./lib/index.mjs",
|
|
11
|
+
"require": "./index.js",
|
|
12
|
+
"types": "./index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"gypfile": true,
|
|
16
|
+
"license": "LGPL",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/boybook/node-hamlib.git"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"ham",
|
|
23
|
+
"radio",
|
|
24
|
+
"hamlib",
|
|
25
|
+
"amateur-radio",
|
|
26
|
+
"transceiver",
|
|
27
|
+
"rig-control"
|
|
28
|
+
],
|
|
29
|
+
"files": [
|
|
30
|
+
"lib/",
|
|
31
|
+
"prebuilds/",
|
|
32
|
+
"src/",
|
|
33
|
+
"index.js",
|
|
34
|
+
"index.d.ts",
|
|
35
|
+
"binding.gyp",
|
|
36
|
+
"COPYING",
|
|
37
|
+
"Readme.md"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "node-gyp configure && node-gyp build",
|
|
41
|
+
"rebuild": "node-gyp rebuild",
|
|
42
|
+
"clean": "node-gyp clean",
|
|
43
|
+
"test": "node test/test_loader.js",
|
|
44
|
+
"test:network": "node test/test_network.js",
|
|
45
|
+
"install": "node scripts/install.js",
|
|
46
|
+
"postinstall": "node scripts/install.js",
|
|
47
|
+
"prepare": "npm run build",
|
|
48
|
+
"prepack": "npm run build"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"node-addon-api": "^4.3.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"node-gyp": "^9.4.0"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=12.0.0"
|
|
58
|
+
},
|
|
59
|
+
"os": [
|
|
60
|
+
"linux",
|
|
61
|
+
"darwin",
|
|
62
|
+
"win32"
|
|
63
|
+
],
|
|
64
|
+
"cpu": [
|
|
65
|
+
"x64",
|
|
66
|
+
"arm64"
|
|
67
|
+
]
|
|
68
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/addon.cpp
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#include <napi.h>
|
|
2
|
+
#include "hamlib.h"
|
|
3
|
+
#include "decoder.h"
|
|
4
|
+
|
|
5
|
+
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
6
|
+
|
|
7
|
+
Napi::String name = Napi::String::New(env, "HamLib");
|
|
8
|
+
exports.Set(name, NodeHamLib::GetClass(env));
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
// Napi::String decoder_name = Napi::String::New(env, "Decoder");
|
|
12
|
+
// exports.Set(decoder_name, Decoder::GetClass(env));
|
|
13
|
+
|
|
14
|
+
return exports;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
NODE_API_MODULE(radio, Init)
|