Skip to content

Commit e810fce

Browse files
committed
feat: add getSupportedModes method to retrieve supported radio modes
1 parent fc4ddea commit e810fce

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,15 @@ declare class HamLib {
482482
*/
483483
getSupportedFunctions(): string[];
484484

485+
/**
486+
* Get list of supported radio modes
487+
* @returns Array of supported mode strings
488+
* @example
489+
* const modes = rig.getSupportedModes();
490+
* console.log('Supported modes:', modes); // ['USB', 'LSB', 'CW', 'FM', 'AM', ...]
491+
*/
492+
getSupportedModes(): string[];
493+
485494
// Split Operations
486495

487496
/**

lib/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,17 @@ class HamLib {
307307
return this._nativeInstance.getSupportedFunctions();
308308
}
309309

310+
/**
311+
* Get list of supported radio modes
312+
* @returns {Array<string>} Array of supported mode strings
313+
* @example
314+
* const modes = rig.getSupportedModes();
315+
* console.log('Supported modes:', modes); // ['USB', 'LSB', 'CW', 'FM', 'AM', ...]
316+
*/
317+
getSupportedModes() {
318+
return this._nativeInstance.getSupportedModes();
319+
}
320+
310321
// Split Operations
311322

312323
/**

src/hamlib.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3246,6 +3246,32 @@ Napi::Value NodeHamLib::GetSupportedFunctions(const Napi::CallbackInfo & info) {
32463246
return funcArray;
32473247
}
32483248

3249+
// Mode Query
3250+
Napi::Value NodeHamLib::GetSupportedModes(const Napi::CallbackInfo & info) {
3251+
Napi::Env env = info.Env();
3252+
3253+
// Get mode list from rig state (populated during rig_open from rx/tx range lists)
3254+
rmode_t modes = my_rig->state.mode_list;
3255+
Napi::Array modeArray = Napi::Array::New(env);
3256+
uint32_t index = 0;
3257+
3258+
// Iterate through all possible mode bits (similar to rig_sprintf_mode)
3259+
for (unsigned int i = 0; i < HAMLIB_MAX_MODES; i++) {
3260+
rmode_t mode_bit = modes & (1ULL << i);
3261+
3262+
if (mode_bit) {
3263+
const char* mode_str = rig_strrmode(mode_bit);
3264+
3265+
// Skip empty or unknown modes
3266+
if (mode_str && mode_str[0] != '\0') {
3267+
modeArray[index++] = Napi::String::New(env, mode_str);
3268+
}
3269+
}
3270+
}
3271+
3272+
return modeArray;
3273+
}
3274+
32493275
// Split Operations
32503276
Napi::Value NodeHamLib::SetSplitFreq(const Napi::CallbackInfo & info) {
32513277
Napi::Env env = info.Env();
@@ -3600,7 +3626,10 @@ Napi::Function NodeHamLib::GetClass(Napi::Env env) {
36003626
NodeHamLib::InstanceMethod("setFunction", & NodeHamLib::SetFunction),
36013627
NodeHamLib::InstanceMethod("getFunction", & NodeHamLib::GetFunction),
36023628
NodeHamLib::InstanceMethod("getSupportedFunctions", & NodeHamLib::GetSupportedFunctions),
3603-
3629+
3630+
// Mode Query
3631+
NodeHamLib::InstanceMethod("getSupportedModes", & NodeHamLib::GetSupportedModes),
3632+
36043633
// Split Operations
36053634
NodeHamLib::InstanceMethod("setSplitFreq", & NodeHamLib::SetSplitFreq),
36063635
NodeHamLib::InstanceMethod("getSplitFreq", & NodeHamLib::GetSplitFreq),

src/hamlib.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ class NodeHamLib : public Napi::ObjectWrap<NodeHamLib> {
7171
Napi::Value SetFunction(const Napi::CallbackInfo&);
7272
Napi::Value GetFunction(const Napi::CallbackInfo&);
7373
Napi::Value GetSupportedFunctions(const Napi::CallbackInfo&);
74-
74+
75+
// Mode Query
76+
Napi::Value GetSupportedModes(const Napi::CallbackInfo&);
77+
7578
// Split Operations
7679
Napi::Value SetSplitFreq(const Napi::CallbackInfo&);
7780
Napi::Value GetSplitFreq(const Napi::CallbackInfo&);

test/test_loader.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ try {
9090
.filter(name => typeof HamLib[name] === 'function');
9191

9292
const totalMethods = instanceMethods.length + staticMethods.length;
93-
94-
test(`实例方法数量正确 (79个)`, () => instanceMethods.length === 79);
93+
94+
test(`实例方法数量正确 (80个)`, () => instanceMethods.length === 80);
9595
test(`静态方法数量正确 (1个)`, () => staticMethods.length === 1);
96-
test(`总方法数量正确 (80个)`, () => totalMethods === 80);
96+
test(`总方法数量正确 (81个)`, () => totalMethods === 81);
9797

9898
console.log(` 📊 实例方法: ${instanceMethods.length}个`);
9999
console.log(` 📊 静态方法: ${staticMethods.length}个`);

0 commit comments

Comments
 (0)