Exemple #1
0
static int flex6k_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
{
  rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);

  if (!rig)
    return -RIG_EINVAL;

  struct kenwood_priv_caps *caps = kenwood_caps(rig);
  char buf[10];
  char kmode;
  int idx;
  int err;

  kmode = rmode2kenwood(mode, caps->mode_table);
  if (kmode < 0 ) {
    rig_debug(RIG_DEBUG_WARN, "%s: unsupported mode '%s'\n",
	      __func__, rig_strrmode(mode));
    return -RIG_EINVAL;
  }

  sprintf(buf, "MD%c", '0' + kmode);
  err = kenwood_simple_cmd(rig, buf);
  if (err != RIG_OK)
    return err;

  err = flex6k_find_width(mode, width, &idx);
  if (err != RIG_OK)
    return err;

  if ((vfo == RIG_VFO_VFO) || (vfo == RIG_VFO_CURR)) {
    vfo = rig->state.current_vfo;
    rig_debug(RIG_DEBUG_VERBOSE, "%s: setting VFO to current\n", __func__);
  }
  /*
   * The Flex CAT interface does not support FW for reading filter width,
   * so use the ZZFI or ZZFJ command
   */
  switch (vfo) {
  case RIG_VFO_A:
    sprintf(buf, "ZZFI%02d;", idx);
    break;
  case RIG_VFO_B:
    sprintf(buf, "ZZFJ%02d;", idx);
    break;
  default:
    rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %d\n", __func__, vfo);
    return -RIG_EINVAL;
  }

  err = kenwood_simple_cmd(rig, buf);
  if (err != RIG_OK)
    return err;
  return RIG_OK;
}
Exemple #2
0
int ts2000_set_channel(RIG *rig, const channel_t *chan)
{
	rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);

	if (!rig || !chan)
		return -RIG_EINVAL;

	char buf[128];
	char mode, tx_mode = 0;
	int err;
	int tone = 0;
	

	struct kenwood_priv_caps *caps = kenwood_caps(rig);

	mode = rmode2kenwood(chan->mode, caps->mode_table);
		if (mode < 0 ) {
				rig_debug(RIG_DEBUG_ERR, "%s: unsupported mode '%s'\n",
								   __func__, rig_strrmode(chan->mode));
				return -RIG_EINVAL;
		}

	if (chan->split == RIG_SPLIT_ON) {
		tx_mode = rmode2kenwood(chan->tx_mode, caps->mode_table);
			if (tx_mode < 0 ) {
					rig_debug(RIG_DEBUG_ERR, "%s: unsupported mode '%s'\n",
	   							   __func__, rig_strrmode(chan->tx_mode));
					return -RIG_EINVAL;
			}
	}

	/* find tone */
	char sqltype = '0';
	if (chan->ctcss_tone) {
		for (; rig->caps->ctcss_list[tone] != 0; tone++) {
			if (chan->ctcss_tone == rig->caps->ctcss_list[tone])
				break;
		}
		if (chan->ctcss_tone != rig->caps->ctcss_list[tone]) tone = -1;
		else sqltype = '1';
	}else{
	  tone = -1; /* -1 because we will add 1 when outputing; this is necessary as CTCSS codes are numbered from 1 */
	}
	/* find CTCSS code */
	short code = 0;
	if (chan->ctcss_sql) {
		for (; rig->caps->ctcss_list[code] != 0; code++) {
			if (chan->ctcss_sql == rig->caps->ctcss_list[code])
				break;
		}
		if (chan->ctcss_sql != rig->caps->ctcss_list[code]) code = -1;
		else sqltype = '2';
	}else{
	  code = -1;
	}
	/* find DCS code */
	short dcscode = 0;
	if (chan->dcs_code) {
		for (; rig->caps->dcs_list[dcscode] != 0; dcscode++) {
			if (chan->dcs_code == rig->caps->dcs_list[dcscode])
				break;
		}
		if (chan->dcs_code != rig->caps->dcs_list[dcscode]) dcscode = 0;
		else sqltype = '3';
	}else{
	  dcscode = 0;
	}
	
	char shift = '0';
	if( chan->rptr_shift == RIG_RPT_SHIFT_PLUS ){
	  shift = '1';
	}
	if( chan->rptr_shift ==  RIG_RPT_SHIFT_MINUS ){
	  shift = '2';
	}
	int tstep = 0;
    if(  (chan->mode == RIG_MODE_AM) || (chan->mode == RIG_MODE_FM) ){
       switch( chan->tuning_step ){
          case s_kHz(6.25):   tstep = 1; break;
          case s_kHz(10):     tstep = 2; break;
          case s_kHz(12.5):   tstep = 3; break;
          case s_kHz(15):     tstep = 4; break;
          case s_kHz(20):     tstep = 5; break;
          case s_kHz(25):     tstep = 6; break;
          case s_kHz(30):     tstep = 7; break;
          case s_kHz(50):     tstep = 8; break;
          case s_kHz(100):    tstep = 9; break;
          default:            tstep = 0;
       }
    }else{
       switch( chan->tuning_step ){
          case s_kHz(2.5):    tstep = 1; break;
          case s_kHz(5):      tstep = 2; break;
          case s_kHz(10):     tstep = 3; break;
          default:            tstep = 0;
       }
    }

    /* P-number       2-3    4 5 6 7   8   9  101112  13 141516  */
	snprintf(buf, sizeof(buf), "MW0%03d%011u%c%c%c%02d%02d%03d%c%c%09d0%c%c%s;", 
		chan->channel_num,
		(unsigned) chan->freq,		/*  4 - frequency */
		'0' + mode,					/*  5 - mode */
		(chan->flags & RIG_CHFLAG_SKIP) ? '1' : '0',    /*  6 - lockout status */
		sqltype,					/*  7 - squelch and tone type */
		tone+1,						/*  8 - tone code */
		code+1,						/*  9 - CTCSS code */
		dcscode,					/* 10 - DCS code */
		(chan->funcs & RIG_FUNC_REV ) ? '1' : '0',/* 11 - Reverse status */
		shift,						/* 12 - shift type */
		(int) chan->rptr_offs,				/* 13 - offset frequency */
		tstep + '0',   						/* 14 - Step size */
        chan->scan_group + '0',         /* 15 - Memory group no */
		chan->channel_desc 				/* 16 - description */
		);
	rig_debug( RIG_DEBUG_VERBOSE, "The command will be: %s\n", buf );

	err = kenwood_transaction(rig, buf, NULL, 0);
	if (err != RIG_OK)
		return err;
	
    if( chan->split == RIG_SPLIT_ON ){
	  sprintf(buf, "MW1%03d%011u%c%c%c%02d%02d%03d%c%c%09d0%c%c%s;\n", 
		chan->channel_num,
		(unsigned) chan->tx_freq, 		/*  4 - frequency */
		'0' + tx_mode,     				/*  5 - mode */
		(chan->flags & RIG_CHFLAG_SKIP) ? '1' : '0',    /*  6 - lockout status */
		sqltype,					/*  7 - squelch and tone type */
		tone+1,						/*  8 - tone code */
		code+1,						/*  9 - CTCSS code */
		dcscode+1,					/* 10 - DCS code */
		(chan->funcs & RIG_FUNC_REV ) ? '1' : '0',/* 11 - Reverse status */
		shift,						/* 12 - shift type */
		(int) chan->rptr_offs,				/* 13 - offset frequency */
		tstep + '0',   						/* 14 - Step size */
        chan->scan_group + '0',         /* Memory group no */
		chan->channel_desc 				/* 16 - description */
		);
	  rig_debug( RIG_DEBUG_VERBOSE, "Split, the command will be: %s\n", buf );
	
	  err = kenwood_transaction(rig, buf, NULL, 0);
	}
	return err;
}
Exemple #3
0
int ts2000_get_channel(RIG *rig, channel_t *chan)
{
	rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);

	if (!rig || !chan || chan->vfo != RIG_VFO_MEM)
		return -RIG_EINVAL;

	int err;
	char buf[52];
	char cmd[8];
	struct kenwood_priv_caps *caps = kenwood_caps(rig);

	/* put channel num in the command string */
	sprintf(cmd, "MR0%03d;", chan->channel_num);

	err = kenwood_transaction(rig, cmd, buf, sizeof (buf));
	if (err != RIG_OK)
		return err;
	size_t length = strlen (buf);
	memset(chan, 0x00, sizeof(channel_t));

	chan->vfo = RIG_VFO_MEM;

	/* parse from right to left */

	/* XXX based on the available documentation, there is no command
	 * to read out the filters of a given memory channel. The rig, however,
	 * stores this information.
	 */
	/* First check if a name is assigned.
	   Name is returned at positions 41-48 (counting from 0) */
	if( length > 41 ){
// 	  rig_debug(RIG_DEBUG_VERBOSE, "Copying channel description: %s\n", &buf[ 41 ] );
	  strcpy( chan->channel_desc, &buf[ 41 ] );
	}
    /* Memory group no */
    chan->scan_group = buf[ 40 ] - '0';
    /* Fileds 38-39 contain tuning step as a number 00 - 09.
       Tuning step depends on this number and the mode, 
       just save it for now */
    buf[ 40 ] = '\0';
    int tmp;
    tmp = atoi( &buf[ 38] );
	/* Offset frequency */
	buf[ 38 ] = '\0';
	chan->rptr_offs = atoi( &buf[ 29 ] );
	/* Shift type 
	   WARNING: '=' shift type not programmed */
	if( buf[ 28 ] == '1' ){
	  chan->rptr_shift = RIG_RPT_SHIFT_PLUS;
	}else{
	  if( buf[ 28 ] == '2' ){
	    chan->rptr_shift = RIG_RPT_SHIFT_MINUS;
	  }else{
	    chan->rptr_shift =  RIG_RPT_SHIFT_NONE;
	  }
	}
	/* Reverse status */
	if( buf[27] == '1' ){
	  chan->funcs |= RIG_FUNC_REV;
	}
	/* Check for tone, CTCSS and DCS */
	/* DCS code first */
	if( buf[ 19 ] == '3' ){
	  if( rig->caps->dcs_list ){
	    buf[ 27 ] = '\0';
	    chan->dcs_code = rig->caps->dcs_list[ atoi( &buf[ 24 ] ) ];
	    chan->dcs_sql = chan->dcs_code;
	    chan->ctcss_tone = 0;
	    chan->ctcss_sql = 0;
	  }
	}else{
	  chan->dcs_code = 0;
	  chan->dcs_sql = 0;
	  /* CTCSS code 
	     Caution, CTCSS codes, unlike DCS codes, are numbered from 1! */
          buf[ 24 ] = '\0';
	  if( buf[ 19 ] == '2' ){
		chan->funcs |= RIG_FUNC_TSQL;
		if (rig->caps->ctcss_list){
			chan->ctcss_sql = rig->caps->ctcss_list[ atoi( &buf[22] )-1 ];
		        chan->ctcss_tone = 0;
		}
	  }else{
	    chan->ctcss_sql = 0;
	    /* CTCSS tone */
	    if( buf[ 19 ] == '1' ){
	        chan->funcs |= RIG_FUNC_TONE;
	        buf[ 22 ] = '\0';
		if (rig->caps->ctcss_list)
			chan->ctcss_tone = rig->caps->ctcss_list[ atoi( &buf[20] )-1 ];
	    }else{
	      chan->ctcss_tone = 0;
	    }
	  }
	}
	

	/* memory lockout */
	if (buf[18] == '1')
		chan->flags |= RIG_CHFLAG_SKIP;

	/* mode */
	chan->mode = kenwood2rmode(buf[17] - '0', caps->mode_table);
    
    /* Now we have the mode, let's finish the tuning step */
    if(  (chan->mode == RIG_MODE_AM) || (chan->mode == RIG_MODE_FM) ){
       switch (tmp){
          case 0: chan->tuning_step = kHz(5); break;
          case 1: chan->tuning_step = kHz(6.25); break;
          case 2: chan->tuning_step = kHz(10); break;
          case 3: chan->tuning_step = kHz(12.5); break;
          case 4: chan->tuning_step = kHz(15); break;
          case 5: chan->tuning_step = kHz(20); break;
          case 6: chan->tuning_step = kHz(25); break;
          case 7: chan->tuning_step = kHz(30); break;
          case 8: chan->tuning_step = kHz(50); break;
          case 9: chan->tuning_step = kHz(100); break;
          default: chan->tuning_step = 0;
       }
    }else{
       switch (tmp){
          case 0: chan->tuning_step = kHz(1); break;
          case 1: chan->tuning_step = kHz(2.5); break;
          case 2: chan->tuning_step = kHz(5); break;
          case 3: chan->tuning_step = kHz(10); break;
          default: chan->tuning_step = 0;
       }
    }

	/* Frequency */
	buf[17] = '\0';
	chan->freq = atoi(&buf[6]);

	if (chan->freq == RIG_FREQ_NONE)
		return -RIG_ENAVAIL;

	buf[6] = '\0';
	chan->channel_num = atoi(&buf[3]);


	/* Check split freq */
	cmd[2] = '1';
	err = kenwood_transaction(rig, cmd, buf, sizeof (buf));
	if (err != RIG_OK)
		return err;

	chan->tx_mode = kenwood2rmode(buf[17] - '0', caps->mode_table);

	buf[17] = '\0';
	chan->tx_freq = atoi(&buf[6]);

	if (chan->freq == chan->tx_freq) {
		chan->tx_freq = RIG_FREQ_NONE;
		chan->tx_mode = RIG_MODE_NONE;
		chan->split = RIG_SPLIT_OFF;
	} else
		chan->split = RIG_SPLIT_ON;

	return RIG_OK;
}
Exemple #4
0
static int flex6k_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
{
  rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);

  if (!rig || !mode || !width)
    return -RIG_EINVAL;

  struct kenwood_priv_caps *caps = kenwood_caps(rig);

  char modebuf[10];
  int index;
  int retval;

  retval = kenwood_safe_transaction(rig, "MD", modebuf, 6, 4);
  if (retval != RIG_OK)
    return retval;

  *mode = kenwood2rmode(modebuf[2] - '0', caps->mode_table);

  if ((vfo == RIG_VFO_VFO) || (vfo == RIG_VFO_CURR)) {
    vfo = rig->state.current_vfo;
    rig_debug(RIG_DEBUG_VERBOSE, "%s: setting VFO to current\n", __func__);
  }

  /*
   * The Flex CAT interface does not support FW for reading filter width,
   * so use the ZZFI or ZZFJ command
   */
  switch (vfo) {
  case RIG_VFO_A:
    retval = kenwood_safe_transaction(rig, "ZZFI", modebuf, 10, 7);
    break;
  case RIG_VFO_B:
    retval = kenwood_safe_transaction(rig, "ZZFJ", modebuf, 10, 7);
    break;
  default:
    rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %d\n", __func__, vfo);
    return -RIG_EINVAL;
  }

  if (retval != RIG_OK)
    return retval;

  index = atoi(&modebuf[4]);
  if (index >= DSP_BW_NUM) {
    rig_debug(RIG_DEBUG_ERR,
	      "flex6k_get_mode: unexpected ZZF[IJ] answer, index=%d\n", index);
    return -RIG_ERJCTED;
  }

  switch (*mode) {
  case RIG_MODE_AM:
    *width = dsp_bw_am[index];
    break;
  case RIG_MODE_CW:
    *width = dsp_bw_cw[index];
    break;
  case RIG_MODE_USB:
  case RIG_MODE_LSB:
    *width = dsp_bw_ssb[index];
    break;
    //case RIG_MODE_FM:
    //*width = 3000; /* not supported yet, needs followup */
    //break;
  case RIG_MODE_PKTLSB:
  case RIG_MODE_PKTUSB:
    *width = dsp_bw_dig[index];
    break;
  default:
    rig_debug(RIG_DEBUG_ERR, "%s: unsupported mode %d, setting default BW\n", __func__, *mode);
    *width = 3000;
    break;
  }
  return RIG_OK;
}