hamlib 0.3.0 → 0.3.1

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.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Node.js bindings for Hamlib rig control with official spectrum streaming support",
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
@@ -286,7 +286,11 @@ public:
286
286
  void Execute() override {
287
287
  CHECK_RIG_VALID();
288
288
 
289
- result_code_ = shim_rig_set_level_f(hamlib_instance_->my_rig, SHIM_RIG_VFO_CURR, level_type_, value_);
289
+ if (shim_rig_level_is_float(level_type_)) {
290
+ result_code_ = shim_rig_set_level_f(hamlib_instance_->my_rig, SHIM_RIG_VFO_CURR, level_type_, value_);
291
+ } else {
292
+ result_code_ = shim_rig_set_level_i(hamlib_instance_->my_rig, SHIM_RIG_VFO_CURR, level_type_, static_cast<int>(value_));
293
+ }
290
294
  if (result_code_ != SHIM_RIG_OK) {
291
295
  error_message_ = shim_rigerror(result_code_);
292
296
  }
@@ -3004,11 +3008,33 @@ Napi::Value NodeHamLib::SetLevel(const Napi::CallbackInfo & info) {
3004
3008
  return env.Null();
3005
3009
  }
3006
3010
 
3007
- float val = static_cast<float>(levelValue);
3011
+ const bool isSpectrumLevel =
3012
+ levelType == SHIM_RIG_LEVEL_SPECTRUM_MODE
3013
+ || levelType == SHIM_RIG_LEVEL_SPECTRUM_SPAN
3014
+ || levelType == SHIM_RIG_LEVEL_SPECTRUM_EDGE_LOW
3015
+ || levelType == SHIM_RIG_LEVEL_SPECTRUM_EDGE_HIGH
3016
+ || levelType == SHIM_RIG_LEVEL_SPECTRUM_SPEED
3017
+ || levelType == SHIM_RIG_LEVEL_SPECTRUM_REF
3018
+ || levelType == SHIM_RIG_LEVEL_SPECTRUM_AVG
3019
+ || levelType == SHIM_RIG_LEVEL_SPECTRUM_ATT;
3020
+
3021
+ if (isSpectrumLevel) {
3022
+ Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(env);
3023
+ int result = shim_rig_level_is_float(levelType)
3024
+ ? shim_rig_set_level_f(my_rig, SHIM_RIG_VFO_CURR, levelType, static_cast<float>(levelValue))
3025
+ : shim_rig_set_level_i(my_rig, SHIM_RIG_VFO_CURR, levelType, static_cast<int>(levelValue));
3026
+
3027
+ if (result != SHIM_RIG_OK) {
3028
+ deferred.Reject(Napi::Error::New(env, shim_rigerror(result)).Value());
3029
+ } else {
3030
+ deferred.Resolve(Napi::Number::New(env, result));
3031
+ }
3032
+ return deferred.Promise();
3033
+ }
3008
3034
 
3035
+ float val = static_cast<float>(levelValue);
3009
3036
  SetLevelAsyncWorker* worker = new SetLevelAsyncWorker(env, this, levelType, val);
3010
3037
  worker->Queue();
3011
-
3012
3038
  return worker->GetPromise();
3013
3039
  }
3014
3040
 
@@ -5970,11 +5996,60 @@ Napi::Value NodeHamLib::GetSpectrumCapabilities(const Napi::CallbackInfo& info)
5970
5996
  Napi::Env env = info.Env();
5971
5997
  Napi::Object result = Napi::Object::New(env);
5972
5998
 
5973
- result.Set("asyncDataSupported", env.Undefined());
5974
- result.Set("scopes", Napi::Array::New(env));
5975
- result.Set("modes", Napi::Array::New(env));
5976
- result.Set("spans", Napi::Array::New(env));
5977
- result.Set("avgModes", Napi::Array::New(env));
5999
+ result.Set("asyncDataSupported", Napi::Boolean::New(env, shim_rig_is_async_data_supported(my_rig) != 0));
6000
+
6001
+ Napi::Array scopes = Napi::Array::New(env);
6002
+ int scopeCount = shim_rig_get_caps_spectrum_scope_count(my_rig);
6003
+ for (int i = 0; i < scopeCount; ++i) {
6004
+ shim_spectrum_scope_t scope{};
6005
+ if (shim_rig_get_caps_spectrum_scope(my_rig, i, &scope) != SHIM_RIG_OK) {
6006
+ continue;
6007
+ }
6008
+ Napi::Object scopeObject = Napi::Object::New(env);
6009
+ scopeObject.Set("id", Napi::Number::New(env, scope.id));
6010
+ scopeObject.Set("name", Napi::String::New(env, scope.name));
6011
+ scopes.Set(i, scopeObject);
6012
+ }
6013
+ result.Set("scopes", scopes);
6014
+
6015
+ Napi::Array modes = Napi::Array::New(env);
6016
+ int modeCount = shim_rig_get_caps_spectrum_mode_count(my_rig);
6017
+ for (int i = 0; i < modeCount; ++i) {
6018
+ int modeId = 0;
6019
+ if (shim_rig_get_caps_spectrum_mode(my_rig, i, &modeId) != SHIM_RIG_OK) {
6020
+ continue;
6021
+ }
6022
+ Napi::Object modeObject = Napi::Object::New(env);
6023
+ modeObject.Set("id", Napi::Number::New(env, modeId));
6024
+ modeObject.Set("name", Napi::String::New(env, shim_rig_str_spectrum_mode(modeId)));
6025
+ modes.Set(i, modeObject);
6026
+ }
6027
+ result.Set("modes", modes);
6028
+
6029
+ Napi::Array spans = Napi::Array::New(env);
6030
+ int spanCount = shim_rig_get_caps_spectrum_span_count(my_rig);
6031
+ for (int i = 0; i < spanCount; ++i) {
6032
+ double spanHz = 0;
6033
+ if (shim_rig_get_caps_spectrum_span(my_rig, i, &spanHz) != SHIM_RIG_OK) {
6034
+ continue;
6035
+ }
6036
+ spans.Set(i, Napi::Number::New(env, spanHz));
6037
+ }
6038
+ result.Set("spans", spans);
6039
+
6040
+ Napi::Array avgModes = Napi::Array::New(env);
6041
+ int avgModeCount = shim_rig_get_caps_spectrum_avg_mode_count(my_rig);
6042
+ for (int i = 0; i < avgModeCount; ++i) {
6043
+ shim_spectrum_avg_mode_t avgMode{};
6044
+ if (shim_rig_get_caps_spectrum_avg_mode(my_rig, i, &avgMode) != SHIM_RIG_OK) {
6045
+ continue;
6046
+ }
6047
+ Napi::Object avgModeObject = Napi::Object::New(env);
6048
+ avgModeObject.Set("id", Napi::Number::New(env, avgMode.id));
6049
+ avgModeObject.Set("name", Napi::String::New(env, avgMode.name));
6050
+ avgModes.Set(i, avgModeObject);
6051
+ }
6052
+ result.Set("avgModes", avgModes);
5978
6053
 
5979
6054
  return result;
5980
6055
  }
@@ -333,14 +333,20 @@ SHIM_API int shim_rig_get_strength(hamlib_shim_handle_t h, int vfo, int* strengt
333
333
 
334
334
  /* ===== Level control ===== */
335
335
 
336
+ static void shim_ensure_targetable_level(hamlib_shim_handle_t h);
337
+
336
338
  SHIM_API int shim_rig_set_level_f(hamlib_shim_handle_t h, int vfo, uint64_t level, float value) {
339
+ shim_ensure_targetable_level(h);
337
340
  value_t val;
341
+ memset(&val, 0, sizeof(val));
338
342
  val.f = value;
339
343
  return rig_set_level((RIG*)h, (vfo_t)vfo, (setting_t)level, val);
340
344
  }
341
345
 
342
346
  SHIM_API int shim_rig_set_level_i(hamlib_shim_handle_t h, int vfo, uint64_t level, int value) {
347
+ shim_ensure_targetable_level(h);
343
348
  value_t val;
349
+ memset(&val, 0, sizeof(val));
344
350
  val.i = value;
345
351
  return rig_set_level((RIG*)h, (vfo_t)vfo, (setting_t)level, val);
346
352
  }
@@ -383,6 +389,10 @@ SHIM_API int shim_rig_get_level_i(hamlib_shim_handle_t h, int vfo, uint64_t leve
383
389
  return ret;
384
390
  }
385
391
 
392
+ SHIM_API int shim_rig_level_is_float(uint64_t level) {
393
+ return RIG_LEVEL_IS_FLOAT((setting_t)level) ? 1 : 0;
394
+ }
395
+
386
396
  /*
387
397
  * Auto-detect int/float level type using RIG_LEVEL_IS_FLOAT macro.
388
398
  * Returns the value as double regardless of the underlying type.
@@ -434,6 +434,7 @@ SHIM_API int shim_rig_set_level_f(hamlib_shim_handle_t h, int vfo, uint64_t leve
434
434
  SHIM_API int shim_rig_set_level_i(hamlib_shim_handle_t h, int vfo, uint64_t level, int value);
435
435
  SHIM_API int shim_rig_get_level_f(hamlib_shim_handle_t h, int vfo, uint64_t level, float* value);
436
436
  SHIM_API int shim_rig_get_level_i(hamlib_shim_handle_t h, int vfo, uint64_t level, int* value);
437
+ SHIM_API int shim_rig_level_is_float(uint64_t level);
437
438
  /* Auto-detect int/float level type, returns value as double */
438
439
  SHIM_API int shim_rig_get_level_auto(hamlib_shim_handle_t h, int vfo, uint64_t level, double* value);
439
440