Beispiel #1
0
static int icom_swap_bands(RIG* rig) {
    /* TODO: actually use retval! */
    int retval=0;
    rmode_t mmode, smode;        /* used to store the mode */
    pbwidth_t mwidth, swidth;    /* used to store the width */
    value_t mpreamp, spreamp;    /* used to store preamp */
    value_t matt, satt;          /* used to store attenuation */

    /* main band get values */
    icom_set_vfo(rig, RIG_VFO_MAIN);
    /* get the mode, width, preamp */
    icom_get_mode(rig, RIG_VFO_CURR, &mmode, &mwidth);
    icom_get_level(rig, RIG_VFO_CURR, RIG_LEVEL_PREAMP, &mpreamp);
    icom_get_level(rig, RIG_VFO_CURR, RIG_LEVEL_ATT, &matt);

    /* sub band get values */
    icom_set_vfo(rig, RIG_VFO_SUB);
    /* get the mode, width, preamp, att */
    icom_get_mode(rig, RIG_VFO_CURR, &smode, &swidth);
    icom_get_level(rig, RIG_VFO_CURR, RIG_LEVEL_PREAMP, &spreamp);
    icom_get_level(rig, RIG_VFO_CURR, RIG_LEVEL_ATT, &satt);

    /* now, we can exchange the bands */
    icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG);

    /* restore the sub vales NOTE: sub band is still active */
    /* set the mode, width, preamp */
    icom_set_mode(rig, RIG_VFO_CURR, smode, swidth);
    icom_set_level(rig, RIG_VFO_CURR, RIG_LEVEL_PREAMP, spreamp);
    icom_set_level(rig, RIG_VFO_CURR, RIG_LEVEL_ATT, satt);

    /* restore main band values */
    icom_set_vfo(rig, RIG_VFO_MAIN);
    /* set the mode, width, preamp */
    icom_set_mode(rig, RIG_VFO_CURR, mmode, mwidth);
    icom_set_level(rig, RIG_VFO_CURR, RIG_LEVEL_PREAMP, mpreamp);
    icom_set_level(rig, RIG_VFO_CURR, RIG_LEVEL_ATT, matt);

    return retval;
}
Beispiel #2
0
static int ic910_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
{
  int retval;
  freq_t otherfreq;
  freq_t origfreq;

  if ((retval = icom_get_freq(rig, RIG_VFO_CURR, &origfreq)) != RIG_OK) return retval;
  if (compareFrequencies (rig, freq, origfreq))
    {
      /* correct band already */
      if (RIG_VFO_A == vfo || RIG_VFO_B == vfo)
        {
          /* switch to desired VFO and read its frequency */
          if ((retval = icom_set_vfo (rig, vfo)) != RIG_OK) return retval;
          if ((retval = icom_get_freq(rig, vfo, &otherfreq)) != RIG_OK) return retval;
          retval = icom_set_freq (rig, RIG_VFO_CURR, freq);
          if (otherfreq != origfreq)
            {
              /* swap VFOs back as original was the other one */
              icom_set_vfo (rig, RIG_VFO_A == vfo ? RIG_VFO_B : RIG_VFO_A);
            }
        }
      else if (RIG_VFO_MAIN == vfo || RIG_VFO_SUB == vfo)
        {
          /* switch to the desired of MAIN and SUB and read its frequency */
          if ((retval = icom_set_vfo (rig, vfo)) != RIG_OK) return retval;
          if ((retval = icom_get_freq(rig, vfo, &otherfreq)) != RIG_OK) return retval;
          if (otherfreq != origfreq)
            {
              /* started on a different so band exchange MAIN and SUB */
              if ((retval = icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG)) != RIG_OK) return retval;
              retval = icom_set_freq (rig, RIG_VFO_CURR, freq);
              /* swap MAIN/SUB back as original was the other one */
              icom_set_vfo (rig, RIG_VFO_MAIN == vfo ? RIG_VFO_SUB : RIG_VFO_MAIN);
            }
          else
            {
              /* already correct one of MAIN and SUB */
              retval = icom_set_freq (rig, RIG_VFO_CURR, freq);
            }
        }
      else if (RIG_VFO_CURR == vfo)
        {
          retval = icom_set_freq (rig, RIG_VFO_CURR, freq);
        }
      else retval = -RIG_EVFO;
    }
  else
    {
      /* wrong band */
      if (RIG_VFO_A == vfo || RIG_VFO_B == vfo)
        {
          /* try and set frequency, may fail if band is already on other of MAIN/SUB */
          retval = icom_set_freq (rig, RIG_VFO_CURR, freq);
          if (-RIG_ERJCTED == retval)
            {
              /* exchange MAIN & SUB */
              if ((retval = icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG)) != RIG_OK) return retval;
              if ((retval = icom_get_freq(rig, vfo, &origfreq)) != RIG_OK) return retval;
              if ((retval = icom_set_vfo (rig, vfo)) != RIG_OK) return retval;
              if ((retval = icom_get_freq(rig, vfo, &otherfreq)) != RIG_OK) return retval;
              retval = icom_set_freq (rig, RIG_VFO_CURR, freq);
              if (-RIG_ERJCTED == retval)
                {
                  /* band not fitted so swap MAIN & SUB back and give up */
                  icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG);
                  return retval;
                }
              else if (retval != RIG_OK) return retval;
              if (otherfreq != origfreq)
                {
                  /* swap VFOs back as original was the other one */
                  icom_set_vfo (rig, RIG_VFO_A == vfo ? RIG_VFO_B : RIG_VFO_A);
                }
              /* we do not exchange bands back as this is taken to
                 mean set VFOA/B on MAIN to the specified frequency
                 as Hamlib does not recognize A on MAIN or B on SUB
                 etc. This is probably reasonable since we cannot Tx
                 on SUB */
              return retval;
            }
          /* we changed band to the "third band" which always makes
             VFO A current so just make the requested one the
             specified frequency as well if it is VFO B. There is no
             way of going to the "third band" without changing VFO
             A */
          if (RIG_VFO_B == vfo) {
            if ((retval = icom_set_vfo (rig, vfo)) != RIG_OK) return retval;
            retval = icom_set_freq (rig, RIG_VFO_CURR, freq);
            icom_set_vfo (rig, RIG_VFO_A);
          }
        }
      else if (RIG_VFO_MAIN == vfo || RIG_VFO_SUB == vfo)
        {
          if ((retval = icom_set_vfo (rig, vfo)) != RIG_OK) return retval;
          if ((retval = icom_get_freq(rig, vfo, &otherfreq)) != RIG_OK) return retval;
          retval = icom_set_freq (rig, RIG_VFO_CURR, freq);
          if (-RIG_ERJCTED == retval)
            {
              /* required band is on other of MAIN or SUB */
              if ((retval = icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG)) != RIG_OK) return retval;
              retval = icom_set_freq (rig, RIG_VFO_CURR, freq);
            }
          else if (retval != RIG_OK) return retval;
          if (otherfreq != origfreq)
            {
              /* started on other of MAIN & SUB so switch back */
              icom_set_vfo (rig,
                            RIG_VFO_MAIN == vfo ?
                            RIG_VFO_SUB : RIG_VFO_MAIN);
            }
        }
      else if (RIG_VFO_CURR == vfo)
        {
          retval = icom_set_freq (rig, RIG_VFO_CURR, freq);
          if (-RIG_ERJCTED == retval)
            {
              /* exchange MAIN & SUB */
              if ((retval = icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG)) != RIG_OK) return retval;
              retval = icom_set_freq (rig, RIG_VFO_CURR, freq);
              if (-RIG_ERJCTED == retval)
                {
                  /* band not fitted so swap MAIN & SUB back and give up */
                  icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG);
                  return retval;
                }
            }
        }
      else retval = -RIG_EVFO;
    }
  return retval;
}