hamlib 0.2.4 → 0.2.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hamlib",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
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
@@ -308,12 +308,14 @@ private:
308
308
  class GetLevelAsyncWorker : public HamLibAsyncWorker {
309
309
  public:
310
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) {}
311
+ : HamLibAsyncWorker(env, hamlib_instance), level_type_(level_type), vfo_(vfo), value_(0.0) {}
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, vfo_, level_type_, &value_);
316
+ // Use auto-detect to handle int levels (STRENGTH, RAWSTR) and
317
+ // float levels (SWR, ALC, RFPOWER_METER, etc.) correctly
318
+ result_code_ = shim_rig_get_level_auto(hamlib_instance_->my_rig, vfo_, level_type_, &value_);
317
319
  if (result_code_ != SHIM_RIG_OK) {
318
320
  error_message_ = shim_rigerror(result_code_);
319
321
  }
@@ -336,7 +338,7 @@ public:
336
338
  private:
337
339
  uint64_t level_type_;
338
340
  int vfo_;
339
- float value_;
341
+ double value_;
340
342
  };
341
343
 
342
344
  class SetFunctionAsyncWorker : public HamLibAsyncWorker {
@@ -346,38 +346,63 @@ SHIM_API int shim_rig_set_level_i(hamlib_shim_handle_t h, int vfo, uint64_t leve
346
346
  }
347
347
 
348
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")
349
+ * Ensure RIG_TARGETABLE_LEVEL is set so rig_get_level() skips VFO
350
+ * switching but still performs calibration and type conversion.
351
+ * This fixes ICOM serial rigs where icom_set_vfo fails with
352
+ * "unsupported VFO" during get_level calls.
353
+ *
354
+ * RIG_TARGETABLE_LEVEL = (1<<5) tells Hamlib: "this rig can read
355
+ * levels without needing to switch VFO first".
354
356
  */
355
- static int shim_get_level_with_fallback(hamlib_shim_handle_t h, int vfo, uint64_t level, value_t* val) {
357
+ #ifndef RIG_TARGETABLE_LEVEL
358
+ #define RIG_TARGETABLE_LEVEL (1<<5)
359
+ #endif
360
+
361
+ static void shim_ensure_targetable_level(hamlib_shim_handle_t h) {
356
362
  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);
363
+ if (rig && rig->caps && !(rig->caps->targetable_vfo & RIG_TARGETABLE_LEVEL)) {
364
+ rig->caps->targetable_vfo |= RIG_TARGETABLE_LEVEL;
361
365
  }
362
- return ret;
363
366
  }
364
367
 
365
368
  SHIM_API int shim_rig_get_level_f(hamlib_shim_handle_t h, int vfo, uint64_t level, float* value) {
369
+ shim_ensure_targetable_level(h);
366
370
  value_t val;
367
371
  val.f = 0.0f;
368
- int ret = shim_get_level_with_fallback(h, vfo, level, &val);
372
+ int ret = rig_get_level((RIG*)h, (vfo_t)vfo, (setting_t)level, &val);
369
373
  if (value) *value = val.f;
370
374
  return ret;
371
375
  }
372
376
 
373
377
  SHIM_API int shim_rig_get_level_i(hamlib_shim_handle_t h, int vfo, uint64_t level, int* value) {
378
+ shim_ensure_targetable_level(h);
374
379
  value_t val;
375
380
  val.i = 0;
376
- int ret = shim_get_level_with_fallback(h, vfo, level, &val);
381
+ int ret = rig_get_level((RIG*)h, (vfo_t)vfo, (setting_t)level, &val);
377
382
  if (value) *value = val.i;
378
383
  return ret;
379
384
  }
380
385
 
386
+ /*
387
+ * Auto-detect int/float level type using RIG_LEVEL_IS_FLOAT macro.
388
+ * Returns the value as double regardless of the underlying type.
389
+ * This avoids the common bug where STRENGTH (int) is read as float.
390
+ */
391
+ SHIM_API int shim_rig_get_level_auto(hamlib_shim_handle_t h, int vfo, uint64_t level, double* value) {
392
+ shim_ensure_targetable_level(h);
393
+ value_t val;
394
+ memset(&val, 0, sizeof(val));
395
+ int ret = rig_get_level((RIG*)h, (vfo_t)vfo, (setting_t)level, &val);
396
+ if (value) {
397
+ if (RIG_LEVEL_IS_FLOAT((setting_t)level)) {
398
+ *value = (double)val.f;
399
+ } else {
400
+ *value = (double)val.i;
401
+ }
402
+ }
403
+ return ret;
404
+ }
405
+
381
406
  /* ===== Function control ===== */
382
407
 
383
408
  SHIM_API int shim_rig_set_func(hamlib_shim_handle_t h, int vfo, uint64_t func, int enable) {
@@ -182,15 +182,24 @@ typedef void* hamlib_shim_handle_t;
182
182
  #define SHIM_RIG_LEVEL_METER (1ULL << 20)
183
183
  #define SHIM_RIG_LEVEL_VOXGAIN (1ULL << 21)
184
184
  #define SHIM_RIG_LEVEL_ANTIVOX (1ULL << 22)
185
- #define SHIM_RIG_LEVEL_STRENGTH (1ULL << 26)
186
- #define SHIM_RIG_LEVEL_RAWSTR (1ULL << 28)
187
- #define SHIM_RIG_LEVEL_SWR (1ULL << 29)
188
- #define SHIM_RIG_LEVEL_ALC (1ULL << 30)
189
- #define SHIM_RIG_LEVEL_RFPOWER_METER (1ULL << 33)
190
- #define SHIM_RIG_LEVEL_COMP_METER (1ULL << 34)
191
- #define SHIM_RIG_LEVEL_VD_METER (1ULL << 35)
192
- #define SHIM_RIG_LEVEL_ID_METER (1ULL << 36)
193
- #define SHIM_RIG_LEVEL_TEMP_METER (1ULL << 42)
185
+ #define SHIM_RIG_LEVEL_SLOPE_LOW (1ULL << 23)
186
+ #define SHIM_RIG_LEVEL_SLOPE_HIGH (1ULL << 24)
187
+ #define SHIM_RIG_LEVEL_BKIN_DLYMS (1ULL << 25)
188
+ #define SHIM_RIG_LEVEL_RAWSTR (1ULL << 26)
189
+ /* bit 27 reserved (was SQLSTAT, deprecated) */
190
+ #define SHIM_RIG_LEVEL_SWR (1ULL << 28)
191
+ #define SHIM_RIG_LEVEL_ALC (1ULL << 29)
192
+ #define SHIM_RIG_LEVEL_STRENGTH (1ULL << 30)
193
+ /* bit 31 reserved */
194
+ #define SHIM_RIG_LEVEL_RFPOWER_METER (1ULL << 32)
195
+ #define SHIM_RIG_LEVEL_COMP_METER (1ULL << 33)
196
+ #define SHIM_RIG_LEVEL_VD_METER (1ULL << 34)
197
+ #define SHIM_RIG_LEVEL_ID_METER (1ULL << 35)
198
+ #define SHIM_RIG_LEVEL_NOTCHF_RAW (1ULL << 36)
199
+ #define SHIM_RIG_LEVEL_MONITOR_GAIN (1ULL << 37)
200
+ #define SHIM_RIG_LEVEL_NB (1ULL << 38)
201
+ #define SHIM_RIG_LEVEL_RFPOWER_METER_WATTS (1ULL << 39)
202
+ #define SHIM_RIG_LEVEL_TEMP_METER (1ULL << 48)
194
203
 
195
204
  /* ===== Function constants (bit positions for setting_t / uint64_t) ===== */
196
205
  #define SHIM_RIG_FUNC_FAGC (1ULL << 0)
@@ -383,6 +392,8 @@ SHIM_API int shim_rig_set_level_f(hamlib_shim_handle_t h, int vfo, uint64_t leve
383
392
  SHIM_API int shim_rig_set_level_i(hamlib_shim_handle_t h, int vfo, uint64_t level, int value);
384
393
  SHIM_API int shim_rig_get_level_f(hamlib_shim_handle_t h, int vfo, uint64_t level, float* value);
385
394
  SHIM_API int shim_rig_get_level_i(hamlib_shim_handle_t h, int vfo, uint64_t level, int* value);
395
+ /* Auto-detect int/float level type, returns value as double */
396
+ SHIM_API int shim_rig_get_level_auto(hamlib_shim_handle_t h, int vfo, uint64_t level, double* value);
386
397
 
387
398
  /* ===== Function control ===== */
388
399