コード例 #1
0
ファイル: mem.c プロジェクト: DF4OR/hamlib
/*
 * 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;
}
コード例 #2
0
ファイル: hamlib-test.c プロジェクト: AmatCoder/mxe
int main(int argc, char *argv[]) {
    RIG *my_rig;
    char *rig_file, *info_buf, *mm;
    freq_t freq;
    value_t rawstrength, power, strength;
    float s_meter, rig_raw2val();
    int status, retcode, isz;
    unsigned int mwpower;
    rmode_t mode;
    pbwidth_t width;
    rig_model_t myrig_model;
    char portname[64];
    port_t myport;

    strncpy(portname, argv[2], 63);
    portname[63] = '\0';

    if ((strcmp(argv[2], "--help") == 0) || (argc < 2)) {
        printf("use like: ./%s <portname>\n", argv[0]);
        printf("example:  ./%s /dev/ttyS0\n", argv[0]);
        return 0;
    }

    /* Try to detect rig */
    /* may be overridden 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, portname, FILPATHLEN);

    rig_load_all_backends();
    myrig_model = rig_probe(&myport);
    /* Set verbosity level - errors only */
    rig_set_debug(RIG_DEBUG_ERR);
    /* Instantiate a rig - your rig */
    /* my_rig = rig_init(RIG_MODEL_TT565); */
    my_rig = rig_init(myrig_model);
    /* Set up serial port, baud rate - serial device + baudrate */
    rig_file = "/dev/ttyUSB0";
    strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
    my_rig->state.rigport.parm.serial.rate = 57600;
    my_rig->state.rigport.parm.serial.rate = 9600;
    /* Open my rig */
    retcode = rig_open(my_rig);
    printf("retcode of rig_open = %d \n", retcode);
    /* Give me ID info, e.g., firmware version. */
    info_buf = (char *)rig_get_info(my_rig);
    printf("Rig_info: '%s'\n", info_buf);

    /* Note: As a general practice, we should check to see if a given
     * function is within the rig's capabilities before calling it, but
     * we are simplifying here. Also, we should check each call's returned
     * status in case of error. (That's an inelegant way to catch an unsupported
     * operation.)
     */

    /* Main VFO frequency */
    status = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
    printf("status of rig_get_freq = %d \n", status);
    printf("VFO freq. = %.1f Hz\n", freq);
    /* Current mode */
    status = rig_get_mode(my_rig, RIG_VFO_CURR, &mode, &width);
    printf("status of rig_get_mode = %d \n", status);
    switch(mode) {
        case RIG_MODE_USB: mm = "USB"; break;
        case RIG_MODE_LSB: mm = "LSB"; break;
        case RIG_MODE_CW:  mm = "CW"; break;
        case RIG_MODE_CWR: mm = "CWR"; break;
        case RIG_MODE_AM:  mm = "AM"; break;
        case RIG_MODE_FM:  mm = "FM"; break;
        case RIG_MODE_WFM: mm = "WFM"; break;
        case RIG_MODE_RTTY:mm = "RTTY"; break;
        default: mm = "unrecognized"; break; /* there are more possibilities! */
        }
    printf("Current mode = 0x%X = %s, width = %d\n", mode, mm, (int) width);
    /* rig power output */
    status = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, &power);
    printf("RF Power relative setting = %.3f (0.0 - 1.0)\n", power.f);
    /* Convert power reading to watts */
    status = rig_power2mW(my_rig, &mwpower, power.f, freq, mode);
    printf("RF Power calibrated = %.1f Watts\n", mwpower/1000.);
    /* Raw and calibrated S-meter values */
    status = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RAWSTR, &rawstrength);
    printf("Raw receive strength = %d\n", rawstrength.i);
    isz = my_rig->caps->str_cal.size;
    printf("isz = %d \n", isz);
    s_meter = rig_raw2val(rawstrength.i, &my_rig->caps->str_cal);
    printf("S-meter value = %.2f dB relative to S9\n", s_meter);
    /* now try using RIG_LEVEL_STRENGTH itself */
    status = rig_get_strength(my_rig, RIG_VFO_CURR, &strength);
    printf("status of rig_get_strength = %d \n", status);
    printf("LEVEL_STRENGTH returns %d\n", strength.i);
return 0;
}