int th_set_split_vfo (RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) { struct kenwood_priv_data *priv = rig->state.priv; char vfobuf[16]; int vfonum, txvfonum; int retval; rig_debug(RIG_DEBUG_TRACE, "%s: called %s\n", __func__, rig_strvfo(vfo)); if (vfo == RIG_VFO_CURR) { retval = rig_get_vfo(rig, &vfo); if (retval != RIG_OK) return retval; } switch (vfo) { case RIG_VFO_A: case RIG_VFO_VFO: vfonum = 0; if (split == RIG_SPLIT_ON && txvfo != RIG_VFO_B) return -RIG_EINVAL; txvfonum = split == RIG_SPLIT_ON ? 1 : vfonum; break; case RIG_VFO_B: vfonum = 1; if (split == RIG_SPLIT_ON && txvfo != RIG_VFO_A) return -RIG_EINVAL; txvfonum = split == RIG_SPLIT_ON ? 0 : vfonum; break; default: return -RIG_EINVAL; } /* Set VFO mode. To be done for TX vfo also? */ sprintf(vfobuf, "VMC %d,0", vfonum); retval = kenwood_cmd(rig, vfobuf); if (retval != RIG_OK) return retval; sprintf(vfobuf, "BC %d,%d", vfonum, txvfonum); retval = kenwood_cmd(rig, vfobuf); if (retval != RIG_OK) return retval; /* Remember whether split is on, for th_set_vfo */ priv->split = split; return RIG_OK; }
int main(int argc, char *argv[]) { RIG *my_rig; /* handle to rig (nstance) */ freq_t freq; /* frequency */ rmode_t rmode; /* radio mode of operation */ pbwidth_t width; vfo_t vfo; /* vfo selection */ int strength; /* S-Meter level */ int rit = 0; /* RIT status */ int xit = 0; /* XIT status */ int retcode; /* generic return code from functions */ rig_model_t myrig_model; printf("testrig: Hello, I am your main() !\n"); /* Turn off backend debugging ouput */ rig_set_debug_level(RIG_DEBUG_NONE); /* * allocate memory, setup & open port */ if (argc < 2) { hamlib_port_t myport; /* may be overriden by backend probe */ myport.type.rig = RIG_PORT_SERIAL; myport.parm.serial.rate = 9600; myport.parm.serial.data_bits = 8; myport.parm.serial.stop_bits = 1; myport.parm.serial.parity = RIG_PARITY_NONE; myport.parm.serial.handshake = RIG_HANDSHAKE_NONE; strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN - 1); rig_load_all_backends(); myrig_model = rig_probe(&myport); } else { myrig_model = atoi(argv[1]); } my_rig = rig_init(myrig_model); if (!my_rig) { fprintf(stderr, "Unknown rig num: %d\n", myrig_model); fprintf(stderr, "Please check riglist.h\n"); exit(1); /* whoops! something went wrong (mem alloc?) */ } strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1); retcode = rig_open(my_rig); if (retcode != RIG_OK) { printf("rig_open: error = %s\n", rigerror(retcode)); exit(2); } printf("Port %s opened ok\n", SERIAL_PORT); /* * Below are examples of set/get routines. * Must add checking of functionality map prior to command execution -- FS * */ /* * Example of setting rig paameters * and some error checking on the return code. */ retcode = rig_set_vfo(my_rig, RIG_VFO_B); if (retcode != RIG_OK) { printf("rig_set_vfo: error = %s \n", rigerror(retcode)); } /* * Lets try some frequencies and modes. Return code is not checked. * Examples of checking return code are further down. * */ /* 10m FM Narrow */ printf("\nSetting 10m FM Narrow...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 29620000); /* 10m */ retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_FM, rig_passband_narrow(my_rig, RIG_MODE_FM)); if (retcode != RIG_OK) { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n", freq / 1000000, rig_strrmode(rmode), width / 1000.0); sleep(1); /* so you can see it -- FS */ /* 15m USB */ printf("Setting 15m USB...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 21235175); /* 15m */ retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_USB, rig_passband_normal(my_rig, RIG_MODE_USB)); if (retcode != RIG_OK) { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n", freq / 1000000, rig_strrmode(rmode), width / 1000.0); sleep(1); /* 40m LSB */ printf("Setting 40m LSB...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 7250100); /* 40m */ retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_LSB, RIG_PASSBAND_NORMAL); if (retcode != RIG_OK) { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n", freq / 1000000, rig_strrmode(rmode), width / 1000.0); sleep(1); /* 80m AM Narrow */ printf("Setting 80m AM Narrow...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 3885000); /* 80m */ retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_AM, rig_passband_narrow(my_rig, RIG_MODE_AM)); if (retcode != RIG_OK) { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n", freq / 1000000, rig_strrmode(rmode), width / 1000.0); sleep(1); /* 160m CW Normal */ printf("Setting 160m CW...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 1875000); /* 160m */ retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_CW, RIG_PASSBAND_NORMAL); if (retcode != RIG_OK) { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n", freq / 1000, rig_strrmode(rmode), width); sleep(1); /* 160m CW Narrow -- The band is noisy tonight -- FS*/ printf("Setting 160m CW Narrow...\n"); retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_CW, rig_passband_narrow(my_rig, RIG_MODE_CW)); if (retcode != RIG_OK) { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n", freq / 1000, rig_strrmode(rmode), width); sleep(1); /* AM Broadcast band */ printf("Setting Medium Wave AM...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 770000); /* KAAM */ retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_AM, RIG_PASSBAND_NORMAL); if (retcode != RIG_OK) { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); printf(" Freq: %.3f kHz, Mode: %s, Passband: %.3f kHz\n\n", freq / 1000, rig_strrmode(rmode), width / 1000.0); sleep(1); /* 20m USB on VFO_A */ printf("Setting 20m on VFO A with two functions...\n"); retcode = rig_set_vfo(my_rig, RIG_VFO_A); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 14250375); /* cq de vk3fcs */ if (retcode != RIG_OK) { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); rig_get_vfo(my_rig, &vfo); printf(" Freq: %.6f MHz, VFO: %s\n\n", freq / 1000000, rig_strvfo(vfo)); sleep(1); /* 20m USB on VFO_A , with only 1 call */ printf("Setting 20m on VFO A with one function...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_A, 14295125); /* cq de vk3fcs */ if (retcode != RIG_OK) { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); rig_get_vfo(my_rig, &vfo); printf(" Freq: %.6f MHz, VFO: %s\n\n", freq / 1000000, rig_strvfo(vfo)); sleep(1); #if 0 retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 145100000); /* 2m */ sleep(2); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 435125000); /* 70cm */ sleep(2); #endif printf("Setting rig Mode to LSB.\n"); retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_LSB, RIG_PASSBAND_NORMAL); if (retcode != RIG_OK) { printf("rig_set_mode: error = %s \n", rigerror(retcode)); } sleep(1); printf("Setting rig PTT ON.\n"); retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_ON); /* stand back ! */ if (retcode != RIG_OK) { printf("rig_set_ptt: error = %s \n", rigerror(retcode)); } sleep(1); printf("Setting rig PTT OFF.\n"); retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_OFF); /* phew ! */ if (retcode != RIG_OK) { printf("rig_set_ptt: error = %s \n", rigerror(retcode)); } sleep(1); /* * Simple examples of getting rig information -- FS * */ printf("\nGet various raw rig values:\n"); retcode = rig_get_vfo(my_rig, &vfo); /* try to get vfo info */ if (retcode == RIG_OK) { printf("rig_get_vfo: vfo = %i \n", vfo); } else { printf("rig_get_vfo: error = %s \n", rigerror(retcode)); } retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq); if (retcode == RIG_OK) { printf("rig_get_freq: freq = %"PRIfreq"\n", freq); } else { printf("rig_get_freq: error = %s \n", rigerror(retcode)); } retcode = rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); if (retcode == RIG_OK) { printf("rig_get_mode: mode = %"PRIll"\n", rmode); } else { printf("rig_get_mode: error = %s \n", rigerror(retcode)); } retcode = rig_get_strength(my_rig, RIG_VFO_CURR, &strength); if (retcode == RIG_OK) { printf("rig_get_strength: strength = %i \n", strength); } else { printf("rig_get_strength: error = %s \n", rigerror(retcode)); } if (rig_has_set_func(my_rig, RIG_FUNC_RIT)) { retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, 1); printf("rig_set_func: Setting RIT ON\n"); } if (rig_has_get_func(my_rig, RIG_FUNC_RIT)) { retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, &rit); printf("rig_get_func: RIT: %d\n", rit); } if (rig_has_set_func(my_rig, RIG_FUNC_XIT)) { retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, 1); printf("rig_set_func: Setting XIT ON\n"); } if (rig_has_get_func(my_rig, RIG_FUNC_XIT)) { retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, &xit); printf("rig_get_func: XIT: %d\n", xit); } rig_close(my_rig); /* close port */ rig_cleanup(my_rig); /* if you care about memory */ printf("port %s closed ok \n", SERIAL_PORT); return 0; }
/* * stores current VFO state into chan by emulating rig_get_channel */ static int generic_save_channel(RIG *rig, channel_t *chan) { int i, retval; int chan_num; vfo_t vfo; setting_t setting; const channel_cap_t *mem_cap = NULL; chan_num = chan->channel_num; vfo = chan->vfo; memset(chan, 0, sizeof(channel_t)); chan->channel_num = chan_num; chan->vfo = vfo; if (vfo == RIG_VFO_MEM) { const chan_t *chan_cap; chan_cap = rig_lookup_mem_caps(rig, chan_num); if (chan_cap) mem_cap = &chan_cap->mem_caps; } /* If vfo!=RIG_VFO_MEM or incomplete backend, try all properties */ if (mem_cap == NULL || rig_mem_caps_empty(mem_cap)) { mem_cap = &mem_cap_all; } if (mem_cap->freq) { retval = rig_get_freq(rig, RIG_VFO_CURR, &chan->freq); /* empty channel ? */ if (retval == -RIG_ENAVAIL || chan->freq == RIG_FREQ_NONE) return -RIG_ENAVAIL; } if (mem_cap->vfo) rig_get_vfo(rig, &chan->vfo); if (mem_cap->mode || mem_cap->width) rig_get_mode(rig, RIG_VFO_CURR, &chan->mode, &chan->width); chan->split = RIG_SPLIT_OFF; if (mem_cap->split) rig_get_split_vfo(rig, RIG_VFO_CURR, &chan->split, &chan->tx_vfo); if (chan->split != RIG_SPLIT_OFF) { if (mem_cap->tx_freq) rig_get_split_freq(rig, RIG_VFO_CURR, &chan->tx_freq); if (mem_cap->tx_mode || mem_cap->tx_width) rig_get_split_mode(rig, RIG_VFO_CURR, &chan->tx_mode, &chan->tx_width); } else { chan->tx_freq = chan->freq; chan->tx_mode = chan->mode; chan->tx_width = chan->width; } if (mem_cap->rptr_shift) rig_get_rptr_shift(rig, RIG_VFO_CURR, &chan->rptr_shift); if (mem_cap->rptr_offs) rig_get_rptr_offs(rig, RIG_VFO_CURR, &chan->rptr_offs); if (mem_cap->ant) rig_get_ant(rig, RIG_VFO_CURR, &chan->ant); if (mem_cap->tuning_step) rig_get_ts(rig, RIG_VFO_CURR, &chan->tuning_step); if (mem_cap->rit) rig_get_rit(rig, RIG_VFO_CURR, &chan->rit); if (mem_cap->xit) rig_get_xit(rig, RIG_VFO_CURR, &chan->xit); for (i=0; i<RIG_SETTING_MAX; i++) { setting = rig_idx2setting(i); if ((setting & mem_cap->levels) && RIG_LEVEL_SET(setting)) rig_get_level(rig, RIG_VFO_CURR, setting, &chan->levels[i]); } for (i=0; i<RIG_SETTING_MAX; i++) { int fstatus; setting = rig_idx2setting(i); if ((setting & mem_cap->funcs) && (rig_get_func(rig, RIG_VFO_CURR, setting, &fstatus) == RIG_OK)) chan->funcs |= fstatus ? setting : 0; } if (mem_cap->ctcss_tone) rig_get_ctcss_tone(rig, RIG_VFO_CURR, &chan->ctcss_tone); if (mem_cap->ctcss_sql) rig_get_ctcss_sql(rig, RIG_VFO_CURR, &chan->ctcss_sql); if (mem_cap->dcs_code) rig_get_dcs_code(rig, RIG_VFO_CURR, &chan->dcs_code); if (mem_cap->dcs_sql) rig_get_dcs_sql(rig, RIG_VFO_CURR, &chan->dcs_sql); /* * TODO: (missing calls) * - channel_desc * - bank_num * - scan_group * - flags */ rig_ext_level_foreach(rig, generic_retr_extl, (rig_ptr_t)chan); return RIG_OK; }