Skip to content

Commit 24e491e

Browse files
boybookclaude
andcommitted
fix: add VFO switching bypass for get_func/set_func/vfo_op on ICOM serial rigs
ICOM rigs (e.g. IC-705) fail when rig_get_func/rig_set_func are called because Hamlib internally calls icom_set_vfo which returns "unsupported VFO". For get_func/set_func: set RIG_TARGETABLE_FUNC flag to skip VFO switching, same approach as the RIG_TARGETABLE_LEVEL fix for getLevel/setLevel. For vfo_op: use fallback pattern (try standard call, then direct backend call on RIG_EINVAL) since there is no RIG_TARGETABLE for vfo_op. This fixes antenna tuner (ATU) control via Hamlib for IC-705. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ee0c4bf commit 24e491e

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hamlib",
3-
"version": "0.2.5",
3+
"version": "0.2.6",
44
"description": "Node.js wrapper for hamlib radio control library",
55
"main": "index.js",
66
"module": "lib/index.mjs",

src/shim/hamlib_shim.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,32 @@ SHIM_API int shim_rig_get_level_auto(hamlib_shim_handle_t h, int vfo, uint64_t l
405405

406406
/* ===== Function control ===== */
407407

408+
/*
409+
* Ensure RIG_TARGETABLE_FUNC is set so rig_get_func()/rig_set_func()
410+
* skip VFO switching. Same fix as RIG_TARGETABLE_LEVEL for ICOM serial
411+
* rigs where icom_set_vfo fails with "unsupported VFO".
412+
*
413+
* RIG_TARGETABLE_FUNC = (1<<4) tells Hamlib: "this rig can get/set
414+
* functions without needing to switch VFO first".
415+
*/
416+
#ifndef RIG_TARGETABLE_FUNC
417+
#define RIG_TARGETABLE_FUNC (1<<4)
418+
#endif
419+
420+
static void shim_ensure_targetable_func(hamlib_shim_handle_t h) {
421+
RIG* rig = (RIG*)h;
422+
if (rig && rig->caps && !(rig->caps->targetable_vfo & RIG_TARGETABLE_FUNC)) {
423+
rig->caps->targetable_vfo |= RIG_TARGETABLE_FUNC;
424+
}
425+
}
426+
408427
SHIM_API int shim_rig_set_func(hamlib_shim_handle_t h, int vfo, uint64_t func, int enable) {
428+
shim_ensure_targetable_func(h);
409429
return rig_set_func((RIG*)h, (vfo_t)vfo, (setting_t)func, enable);
410430
}
411431

412432
SHIM_API int shim_rig_get_func(hamlib_shim_handle_t h, int vfo, uint64_t func, int* state) {
433+
shim_ensure_targetable_func(h);
413434
int s = 0;
414435
int ret = rig_get_func((RIG*)h, (vfo_t)vfo, (setting_t)func, &s);
415436
if (state) *state = s;
@@ -612,8 +633,20 @@ SHIM_API int shim_rig_scan(hamlib_shim_handle_t h, int vfo, int scan_type, int c
612633

613634
/* ===== VFO operations ===== */
614635

636+
/*
637+
* vfo_op with fallback for rigs with VFO switching issues.
638+
* There is no RIG_TARGETABLE for vfo_op, so we use the same
639+
* fallback pattern as the old getLevel fix: try standard call
640+
* first, then direct backend call if RIG_EINVAL (-1).
641+
*/
615642
SHIM_API int shim_rig_vfo_op(hamlib_shim_handle_t h, int vfo, int op) {
616-
return rig_vfo_op((RIG*)h, (vfo_t)vfo, (vfo_op_t)op);
643+
RIG* rig = (RIG*)h;
644+
int ret = rig_vfo_op(rig, (vfo_t)vfo, (vfo_op_t)op);
645+
if (ret == -1 && rig->caps->vfo_op) {
646+
/* RIG_EINVAL: VFO switching failed, try direct backend call */
647+
ret = rig->caps->vfo_op(rig, (vfo_t)vfo, (vfo_op_t)op);
648+
}
649+
return ret;
617650
}
618651

619652
/* ===== Antenna control ===== */

0 commit comments

Comments
 (0)