hamlib 0.2.2 → 0.2.4

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/index.d.ts CHANGED
@@ -542,9 +542,10 @@ declare class HamLib {
542
542
  /**
543
543
  * Get radio level
544
544
  * @param levelType Level type ('AF', 'RF', 'SQL', 'STRENGTH', etc.)
545
+ * @param vfo Optional VFO ('VFO-A', 'VFO-B', 'currVFO'). Defaults to currVFO.
545
546
  * @returns Level value
546
547
  */
547
- getLevel(levelType: LevelType): Promise<number>;
548
+ getLevel(levelType: LevelType, vfo?: string): Promise<number>;
548
549
 
549
550
  /**
550
551
  * Get list of supported level types
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hamlib",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
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
Binary file
Binary file
Binary file
Binary file
package/src/hamlib.cpp CHANGED
@@ -307,13 +307,13 @@ private:
307
307
 
308
308
  class GetLevelAsyncWorker : public HamLibAsyncWorker {
309
309
  public:
310
- GetLevelAsyncWorker(Napi::Env env, NodeHamLib* hamlib_instance, uint64_t level_type)
311
- : HamLibAsyncWorker(env, hamlib_instance), level_type_(level_type), value_(0.0f) {}
310
+ GetLevelAsyncWorker(Napi::Env env, NodeHamLib* hamlib_instance, uint64_t level_type, int vfo = SHIM_RIG_VFO_CURR)
311
+ : HamLibAsyncWorker(env, hamlib_instance), level_type_(level_type), vfo_(vfo), value_(0.0f) {}
312
312
 
313
313
  void Execute() override {
314
314
  CHECK_RIG_VALID();
315
315
 
316
- result_code_ = shim_rig_get_level_f(hamlib_instance_->my_rig, SHIM_RIG_VFO_CURR, level_type_, &value_);
316
+ result_code_ = shim_rig_get_level_f(hamlib_instance_->my_rig, vfo_, level_type_, &value_);
317
317
  if (result_code_ != SHIM_RIG_OK) {
318
318
  error_message_ = shim_rigerror(result_code_);
319
319
  }
@@ -335,6 +335,7 @@ public:
335
335
 
336
336
  private:
337
337
  uint64_t level_type_;
338
+ int vfo_;
338
339
  float value_;
339
340
  };
340
341
 
@@ -2972,9 +2973,20 @@ Napi::Value NodeHamLib::GetLevel(const Napi::CallbackInfo & info) {
2972
2973
  return env.Null();
2973
2974
  }
2974
2975
 
2975
- GetLevelAsyncWorker* worker = new GetLevelAsyncWorker(env, this, levelType);
2976
+ // Optional second parameter: VFO string ('VFO-A', 'VFO-B', 'currVFO')
2977
+ int vfo = SHIM_RIG_VFO_CURR;
2978
+ if (info.Length() >= 2 && info[1].IsString()) {
2979
+ std::string vfoStr = info[1].As<Napi::String>().Utf8Value();
2980
+ if (vfoStr == "VFO-A") {
2981
+ vfo = SHIM_RIG_VFO_A;
2982
+ } else if (vfoStr == "VFO-B") {
2983
+ vfo = SHIM_RIG_VFO_B;
2984
+ }
2985
+ }
2986
+
2987
+ GetLevelAsyncWorker* worker = new GetLevelAsyncWorker(env, this, levelType, vfo);
2976
2988
  worker->Queue();
2977
-
2989
+
2978
2990
  return worker->GetPromise();
2979
2991
  }
2980
2992
 
@@ -345,10 +345,27 @@ SHIM_API int shim_rig_set_level_i(hamlib_shim_handle_t h, int vfo, uint64_t leve
345
345
  return rig_set_level((RIG*)h, (vfo_t)vfo, (setting_t)level, val);
346
346
  }
347
347
 
348
+ /*
349
+ * get_level with automatic fallback:
350
+ * 1. Try standard rig_get_level() (with VFO handling, locking, caching)
351
+ * 2. If it fails with RIG_EINVAL (-1), fall back to direct backend call
352
+ * to bypass VFO switching issues (e.g. ICOM serial rigs where
353
+ * icom_set_vfo fails with "unsupported VFO")
354
+ */
355
+ static int shim_get_level_with_fallback(hamlib_shim_handle_t h, int vfo, uint64_t level, value_t* val) {
356
+ RIG* rig = (RIG*)h;
357
+ int ret = rig_get_level(rig, (vfo_t)vfo, (setting_t)level, val);
358
+ if (ret == -1 && rig->caps->get_level) {
359
+ /* RIG_EINVAL: VFO switching failed, try direct backend call */
360
+ ret = rig->caps->get_level(rig, (vfo_t)vfo, (setting_t)level, val);
361
+ }
362
+ return ret;
363
+ }
364
+
348
365
  SHIM_API int shim_rig_get_level_f(hamlib_shim_handle_t h, int vfo, uint64_t level, float* value) {
349
366
  value_t val;
350
367
  val.f = 0.0f;
351
- int ret = rig_get_level((RIG*)h, (vfo_t)vfo, (setting_t)level, &val);
368
+ int ret = shim_get_level_with_fallback(h, vfo, level, &val);
352
369
  if (value) *value = val.f;
353
370
  return ret;
354
371
  }
@@ -356,7 +373,7 @@ SHIM_API int shim_rig_get_level_f(hamlib_shim_handle_t h, int vfo, uint64_t leve
356
373
  SHIM_API int shim_rig_get_level_i(hamlib_shim_handle_t h, int vfo, uint64_t level, int* value) {
357
374
  value_t val;
358
375
  val.i = 0;
359
- int ret = rig_get_level((RIG*)h, (vfo_t)vfo, (setting_t)level, &val);
376
+ int ret = shim_get_level_with_fallback(h, vfo, level, &val);
360
377
  if (value) *value = val.i;
361
378
  return ret;
362
379
  }