コード例 #1
0
ファイル: flex6xxx.c プロジェクト: W4AQL/hamlib
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;
}
コード例 #2
0
ファイル: th.c プロジェクト: JohannesKlug/hamlib
/*
 * th_set_mode
 * Assumes rig!=NULL
 */
int
th_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
{
	char kmode, mdbuf[8];
	int retval;
	const struct kenwood_priv_caps *priv=(const struct kenwood_priv_caps *)rig->caps->priv;

	rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__);

	if (vfo != RIG_VFO_CURR && vfo != rig->state.current_vfo)
		return kenwood_wrong_vfo(__func__, vfo);


	if (priv->mode_table) {

		kmode = rmode2kenwood(mode, priv->mode_table);
		if (kmode == -1) {
			rig_debug(RIG_DEBUG_WARN, "%s: Unsupported Mode value '%s'\n",
				__func__, rig_strrmode(mode));
			return -RIG_EINVAL;
		}
		kmode += '0';

	} else	{

		switch (mode) {
		case RIG_MODE_FM: kmode = '0'; break; /* TH-D7A(G) modes */
		case RIG_MODE_AM: kmode = '1'; break;
		default:
			rig_debug(RIG_DEBUG_ERR, "%s: Unsupported Mode %d\n", __func__, mode);
			return -RIG_EINVAL;
		}
	}

	sprintf(mdbuf, "MD %c", kmode);

	retval = kenwood_cmd(rig, mdbuf);
	if (retval != RIG_OK)
		return retval;

	return RIG_OK;
}
コード例 #3
0
ファイル: ts2000.c プロジェクト: mdblack98/hamlib
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;
}
コード例 #4
0
ファイル: th.c プロジェクト: JohannesKlug/hamlib
/* --------------------------------------------------------------------- */
int th_set_channel(RIG *rig, const channel_t *chan)
{
	char membuf[ACKBUF_LEN],ackbuf[ACKBUF_LEN];
	int retval;
	size_t ack_len;
	char req[64];
	char lockoutstr[8];
	int channel_num, step, shift, rev, tone, ctcss, tonefq, ctcssfq, dcs, dcscode, mode, lockout;
	const char *mr_extra;
	const struct kenwood_priv_caps *priv=(const struct kenwood_priv_caps *)rig->caps->priv;
	const chan_t *chan_caps;
	const char *channel_desc;

	channel_num = chan->channel_num;

	for (step=0; rig->state.tuning_steps[step].ts!=0;step++)
		if (chan->tuning_step<=rig->state.tuning_steps[step].ts)
			break;

	switch (chan->rptr_shift) {
	case RIG_RPT_SHIFT_NONE :
		shift=0;
		break;
	case  RIG_RPT_SHIFT_PLUS:
		shift=1;
		break;
	case RIG_RPT_SHIFT_MINUS:
		shift=2;
		break;
	default:
		rig_debug(RIG_DEBUG_ERR, "%s: not supported shift %d\n",
				__func__, chan->rptr_shift);
		return -RIG_EINVAL;
	}

	if (chan->ctcss_tone==0) {
		tone=0;
		tonefq=8;
	} else {
		tone=1;
		tonefq = find_tone_index(rig->caps->ctcss_list, chan->ctcss_tone);
		if (tonefq == -1)
			return -RIG_EINVAL;
		tonefq++;
	}

	if (chan->ctcss_sql==0) {
		ctcss=0;
		ctcssfq=8;
	} else {
		ctcss=1;
		ctcssfq = find_tone_index(rig->caps->ctcss_list, chan->ctcss_sql);
		if (tonefq == -1)
			return -RIG_EINVAL;
		ctcssfq++;
	}

	if (chan->dcs_code==0 && chan->dcs_sql==0) {
		dcs=0;
		dcscode=0;
	} else {
		dcs=1;
		dcscode = find_tone_index(rig->caps->dcs_list, chan->dcs_sql);
		if (dcscode == -1)
			return -RIG_EINVAL;
	}

	if (chan->vfo == RIG_VFO_MEM)
	{
		chan_caps = rig_lookup_mem_caps(rig, chan->channel_num);
		if (!chan_caps)
			return -RIG_ECONF;
		channel_num -= chan_caps->start;
	}
	else
		return -RIG_ENIMPL;

	if (rig->caps->rig_model == RIG_MODEL_THF7E ||
				rig->caps->rig_model == RIG_MODEL_THF6A)
		mr_extra = "";
	else
		mr_extra = "0, ";

	channel_desc = NULL;
	switch (chan_caps->type) {
	case RIG_MTYPE_MEM:
		if (chan_caps[1].type == RIG_MTYPE_PRIO) {
			/* Info */
			sprintf(req, "MW %s0,I-%01d",mr_extra,channel_num);
			channel_desc = chan->channel_desc;
		} else {
			/* Regular */
			sprintf(req, "MW %s0,%03d",mr_extra,channel_num);
			channel_desc = chan->channel_desc;
		}
		break;

	case RIG_MTYPE_EDGE:
		if (chan_caps[1].type == RIG_MTYPE_EDGE) {
			sprintf(req, "MW %s0,L%01d",mr_extra,channel_num);
		} else {
   			sprintf(req, "MW %s0,U%01d",mr_extra,channel_num);
		}
		break;

	case RIG_MTYPE_PRIO:
		if (chan_caps->start == chan_caps->end) {
   			sprintf(req, "MW %s0,PR",mr_extra);
		} else {
   			sprintf(req, "MW %s0,PR%01d",mr_extra,channel_num+1);
		}
		break;

	case RIG_MTYPE_CALL:
		sprintf(req, "CW 0,%01d",channel_num);
		break;

	case RIG_MTYPE_BAND:
		sprintf(req, "VW %01X",channel_num);
		break;

	default:
		return -RIG_EINVAL;
	}

	rev = chan->funcs & RIG_FUNC_REV ? 1 : 0;
	lockout = chan->flags & RIG_CHFLAG_SKIP ? 1 : 0;

	if (chan_caps->mem_caps.flags)
		sprintf(lockoutstr, ",%d", lockout);
	else
		strcpy(lockoutstr, "");

	if (chan_caps->mem_caps.flags && chan_caps->mem_caps.dcs_sql) {

		if (!priv->mode_table) {
			rig_debug(RIG_DEBUG_ERR, "%s: Buggy backend, no mode_table '%d'\n",
				__func__, chan->mode);
			return -RIG_ENIMPL;
		}

		mode = rmode2kenwood(chan->mode, priv->mode_table);
		if (mode == -1) {
			rig_debug(RIG_DEBUG_ERR, "%s: Unsupported Mode value '%d'\n",
				__func__, chan->mode);
			return -RIG_EINVAL;
		}

		/* Step can be hexa */
		retval = sprintf(membuf, "%s,%011"PRIll",%X,%d,%d,%d,%d,%d,%02d,%02d,%03d,%09"PRIll",%d%s",
			req, (int64_t)chan->freq, step, shift, rev, tone,
			ctcss, dcs, tonefq, ctcssfq, dcscode,
			(int64_t)abs(chan->rptr_offs), mode, lockoutstr
			);
	} else {

		/* Without DCS,mode */
		retval = sprintf(membuf, "%s,%011"PRIll",%X,%d,%d,%d,%d,,%02d,,%02d,%09"PRIll"%s",
			req, (int64_t)chan->freq, step, shift, rev, tone,
			ctcss, tonefq, ctcssfq,
			(int64_t)abs(chan->rptr_offs), lockoutstr
			);
	}

	ack_len = ACKBUF_LEN;

	retval = kenwood_transaction(rig, membuf, strlen(membuf), ackbuf, &ack_len);
	if (retval != RIG_OK)
		return retval;

	/* split ? */
	if (chan->tx_freq!=RIG_FREQ_NONE &&
			((chan_caps->type==RIG_MTYPE_MEM && chan_caps->start == 0) ||
				chan_caps->type==RIG_MTYPE_CALL)) {

		req[3+strlen(mr_extra)]='1';

		sprintf(membuf, "%s,%011"PRIll",%X", req,(int64_t)chan->tx_freq, step);
		ack_len=ACKBUF_LEN;

		retval = kenwood_transaction(rig, membuf, strlen(membuf), ackbuf, &ack_len);
		if (retval != RIG_OK)
			return retval;
	}

	if (channel_desc) {
		/* Memory name */
		ack_len=ACKBUF_LEN;
		/* TODO: check strlen(channel_desc) < rig->caps->chan_desc_sz */
		if (chan_caps[1].type == RIG_MTYPE_PRIO)
			sprintf(membuf, "MNA %sI-%01d,%s",mr_extra,channel_num,channel_desc);
		else
			sprintf(membuf, "MNA %s%03d,%s",mr_extra,channel_num,channel_desc);

		retval = kenwood_transaction(rig, membuf, strlen(membuf), ackbuf, &ack_len);
		if (retval != RIG_OK)
			return retval;
	}

	return RIG_OK;
}