Exemplo n.º 1
0
/* Support the FI command for reading the IF center frequency,
 * useful for panadapters and such that need to know the IF center.
 * TQ command is a quick transmit status query--K2/K3 only.
 *
 * token	Defined in elecraft.h or this file
 * val		Type depends on token type from confparams structure:
 * 		NUMERIC: val.f
 * 		COMBO: val.i, starting from 0 Index to a string table.
 * 		STRING: val.cs for set, val.s for get
 * 		CHECKBUTTON: val.i 0/1
 */
int k3_get_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t *val)
{
	rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);

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

	char buf[KENWOOD_MAX_BUF_LEN];
	int err;
	const struct confparams *cfp;

	cfp = rig_ext_lookup_tok(rig, token);

	switch(token) {
	case TOK_IF_FREQ:
		err = kenwood_safe_transaction(rig, "FI", buf, KENWOOD_MAX_BUF_LEN, 7);
		if (err != RIG_OK)
			return err;
		if (cfp->type == RIG_CONF_NUMERIC) {
			val->f = 8210000.0 + (float)atoi(&buf[2]);
		} else {
			rig_debug(RIG_DEBUG_ERR, "%s: protocol error, invalid token type\n",
				__func__);
			return -RIG_EPROTO;
		}
		break;
	case TOK_TX_STAT:
		err = kenwood_safe_transaction(rig, "TQ", buf, KENWOOD_MAX_BUF_LEN, 4);
		if (err != RIG_OK)
			return err;
		if (cfp->type == RIG_CONF_CHECKBUTTON) {
			val->i = atoi(&buf[2]);
		} else {
			rig_debug(RIG_DEBUG_ERR, "%s: protocol error, invalid token type\n",
				__func__);
			return -RIG_EPROTO;
		}
		break;
	default:
		rig_debug(RIG_DEBUG_WARN, "%s: Unsupported get_ext_level %d\n",
			__func__, token);
		return -RIG_EINVAL;
	}

	return RIG_OK;
}
Exemplo n.º 2
0
int
tmd710_get_vfo_char(RIG *rig, vfo_t *vfo, char *vfoch)
{
	char cmdbuf[10], buf[10], vfoc;
	size_t buf_size=10;
	int retval;

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

	/* Get VFO band */
	
	retval = kenwood_transaction(rig, "BC", 2, buf, &buf_size);
	if (retval != RIG_OK)
		return retval;
	switch (buf_size) {
	case 7: /*intended for D700 BC 0,0*/
	  if ((buf[0]=='B') &&(buf[1]=='C') && (buf[2]==' ') && (buf[4]=',')){
	    vfoc = buf[3];
	  } else {
	    rig_debug(RIG_DEBUG_ERR, "%s: Unexpected answer format '%s'\n", __func__, buf);
	    return -RIG_EPROTO;
	  }
	  break;
	default:
	  rig_debug(RIG_DEBUG_ERR, "%s: Unexpected answer length '%c'\n", __func__, buf_size);
	  return -RIG_EPROTO;
	  break;
	}


	switch (vfoc) {

	   	case '0': *vfo = RIG_VFO_A; break;
		case '1': *vfo = RIG_VFO_B; break;
		default:
		rig_debug(RIG_DEBUG_ERR, "%s: Unexpected VFO value '%c'\n", __func__, buf[3]);
		return -RIG_EVFO;

	}
	rig->state.current_vfo = *vfo;

	/* Get mode of the VFO band */
	
	snprintf(cmdbuf, 9, "VM %c", vfoc);

	retval = kenwood_safe_transaction(rig, cmdbuf, buf, 10, 7);
	if (retval != RIG_OK)
		return retval;

	*vfoch = buf[5];

    return RIG_OK;
}
Exemplo n.º 3
0
int
th_get_mem(RIG *rig, vfo_t vfo, int *ch)
{
	char *membuf, buf[10];
	int retval;
	vfo_t tvfo,cvfo;

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

	/* store current VFO */
	cvfo = rig->state.current_vfo;

	/* check if we should switch VFO */
	if (cvfo != RIG_VFO_MEM) {
		retval = rig_set_vfo(rig, RIG_VFO_MEM);
		if (retval != RIG_OK)
			return retval;
	}

	tvfo = (vfo == RIG_VFO_CURR) ? cvfo : vfo;

	switch (tvfo) {
	case RIG_VFO_VFO:
	case RIG_VFO_MEM:
	case RIG_VFO_A:
		membuf = "MC 0";
		break;
	case RIG_VFO_B:
		membuf = "MC 1";
		break;
	default:
		return kenwood_wrong_vfo(__func__, vfo);
	}

	retval = kenwood_safe_transaction(rig, membuf, buf, 10, 9);
	if (retval != RIG_OK)
		return retval;

	buf[8] = '\0';
	*ch = atoi(&buf[5]);

	/* switch back if appropriate */
	if (cvfo != RIG_VFO_MEM) {
		retval = rig_set_vfo(rig, cvfo);
		if (retval != RIG_OK)
			return retval;
	}

	return RIG_OK;
}
Exemplo n.º 4
0
/* push/pull language is uses for stuff inside 710 driver rather than get/set */
int 
tmd710_pull_fo(RIG * rig,vfo_t vfo, tmd710_fo *fo_struct) {
  char cmdbuf[50];
  char buf[50];
  int vfonum = 0;
  int retval;

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

  switch (vfo) {
  case (RIG_VFO_CURR):
    vfonum = rig->state.current_vfo==RIG_VFO_B;
    break;
  case (RIG_VFO_A):
    vfonum = 0;
    break;
  case (RIG_VFO_B):
    vfonum = 1;
    break;

  }
  
  
  // if (vfo != RIG_VFO_CURR && vfo != rig->state.current_vfo)
  //return kenwood_wrong_vfo(__func__, vfo);
  snprintf(cmdbuf,49,"FO %d",vfonum);
  
  retval = kenwood_safe_transaction(rig, cmdbuf, buf, sizeof(buf), 49);
  if (retval != RIG_OK)
    return retval;
  
  retval = num_sscanf(buf, "FO %x,%"SCNfreq",%x,%x,%x,%x,%x,%x,%d,%d,%d,%d,%d", 
		      &fo_struct->vfo, &fo_struct->freq, 
		      &fo_struct->step, &fo_struct->shift, 
		      &fo_struct->reverse, &fo_struct->tone, 
		      &fo_struct->ct, &fo_struct->dsc, 
		      &fo_struct->tone_freq, &fo_struct->ct_freq,
		      &fo_struct->dsc_val, &fo_struct->offset,
		      &fo_struct->mode);
  if (retval != 13) {
    rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, buf);
    return -RIG_ERJCTED;
  }
  return RIG_OK;
  
}
Exemplo n.º 5
0
/*
 * th_get_mode
 * Assumes rig!=NULL, mode!=NULL
 */
int
th_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
{
	char buf[ACKBUF_LEN];
	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);

	retval = kenwood_safe_transaction(rig, "MD", buf, sizeof(buf), 5);
	if (retval != RIG_OK)
		return retval;

	if (buf[3] < '0' || buf[3] > '9') {
		rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, buf);
		return -RIG_ERJCTED;
	}

	if (priv->mode_table)
	{
		*mode = kenwood2rmode(buf[3]-'0', priv->mode_table);
		if (*mode == RIG_MODE_NONE) {
				rig_debug(RIG_DEBUG_ERR, "%s: Unsupported Mode (table)value '%c'\n",
				__func__, buf[3]);
				return -RIG_EINVAL;
		}
	}
	else
	{
		switch (buf[3]) {
		case '0': *mode = RIG_MODE_FM; break;	 /* TH-D7A(G) modes */
		case '1': *mode = RIG_MODE_AM; break;
		default:
			rig_debug(RIG_DEBUG_ERR, "%s: Unsupported Mode value '%c'\n", __func__, buf[3]);
			return -RIG_EINVAL;
		}
	}

	if (width)
		*width = RIG_PASSBAND_NORMAL;

	return RIG_OK;
}
Exemplo n.º 6
0
int th_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
{
	char *cmd, buf[8];
	int retval;

	if (vfo == RIG_VFO_CURR) {
		retval = th_get_vfo(rig, &vfo);
		if (retval != RIG_OK)
			return retval;
	}

	switch (vfo) {
	case RIG_VFO_VFO:
	case RIG_VFO_A:
	case RIG_VFO_MAIN:
		cmd = "BY 0";
		break;
	case RIG_VFO_B:
	case RIG_VFO_SUB:
		cmd = "BY 1";
		break;
	default:
		return kenwood_wrong_vfo(__func__, vfo);
	}

	retval = kenwood_safe_transaction(rig, cmd, buf, sizeof(buf), 7);
	if (retval != RIG_OK)
		return retval;

	switch (buf[5]) {
	case '0' :
		*dcd = RIG_DCD_OFF;
		return RIG_OK;
	case '1' :
		*dcd = RIG_DCD_ON;
		return RIG_OK;
	default :
		rig_debug(RIG_DEBUG_ERR, "%s: unexpected reply '%s', len=%d\n",
			__func__, buf);
	}

	return -RIG_ERJCTED;
}
Exemplo n.º 7
0
/*
 * th_get_kenwood_func
 * Assumes rig!=NULL, status!=NULL
 */
static int
th_get_kenwood_func(RIG *rig, const char *cmd, int *status)
{
	char buf[8];
	int retval, len, expected;

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

	len = strlen(cmd);
	expected = len + 3;

	retval = kenwood_safe_transaction(rig, cmd, buf, sizeof(buf), expected);
	if (retval != RIG_OK)
		return retval;

	if (status)
		*status = (buf[len+1] == '0') ? 0 : 1;

	return RIG_OK;
};
Exemplo n.º 8
0
/*
 * get the aerial/antenna in use
 */
int th_get_ant(RIG * rig, vfo_t vfo, ant_t * ant)
{
	char buf[8];
	int retval;

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

	retval = kenwood_safe_transaction(rig, "ANT", buf, sizeof(buf), 6);
	if (retval != RIG_OK)
		return retval;

	if (buf[4] < '0' || buf[4] > '9')
		return -RIG_EPROTO;

	*ant = RIG_ANT_N(buf[4] - '0');

	rig_debug(RIG_DEBUG_TRACE, "%s: ant = %d\n", __func__, *ant);

	return RIG_OK;
}
Exemplo n.º 9
0
/*
 * th_set_mem
 * Assumes rig!=NULL
 */
int
th_set_mem(RIG *rig, vfo_t vfo, int ch)
{
	unsigned char vsel;
	char membuf[10], ackbuf[10];
	int retval;
	vfo_t tvfo;

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

	tvfo = (vfo == RIG_VFO_CURR) ? rig->state.current_vfo : vfo;

	switch (tvfo) {
	case RIG_VFO_VFO:
	case RIG_VFO_MEM:
	case RIG_VFO_A:
		vsel = '0';
		break;
	case RIG_VFO_B:
		vsel = '1';
		break;
	default:
		return kenwood_wrong_vfo(__func__, vfo);
	}

	retval = rig_set_vfo(rig, RIG_VFO_MEM);
	if (retval != RIG_OK)
		return retval;

	sprintf(membuf, "MC %c,%03i", vsel, ch);

	retval = kenwood_safe_transaction(rig, membuf, ackbuf, 10, 9);
	if (retval != RIG_OK)
		return retval;

	return RIG_OK;
}
Exemplo n.º 10
0
int k3_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;

	char buf[KENWOOD_MAX_BUF_LEN];
	int err;
	rmode_t temp_m;
	pbwidth_t temp_w;

	err = kenwood_get_mode(rig, vfo, &temp_m, &temp_w);
	if (err != RIG_OK)
		return err;

	if (temp_m == RIG_MODE_RTTY) {
		err = kenwood_safe_transaction(rig, "DT", buf, KENWOOD_MAX_BUF_LEN, 4);
		if (err != RIG_OK) {
			rig_debug(RIG_DEBUG_VERBOSE, "%s: Cannot read K3 DT value\n",
						__func__);
			return err;
		}
		switch(atoi(&buf[2])) {
		case K3_MODE_DATA_A:
			*mode = RIG_MODE_PKTUSB;
			break;
		case K3_MODE_AFSK_A:
			*mode = RIG_MODE_RTTY;
			break;
		default:
			rig_debug(RIG_DEBUG_VERBOSE, "%s: unsupported data sub-mode %c\n",
						__func__, buf[2]);
			return -RIG_EINVAL;
		}
	} else if (temp_m == RIG_MODE_RTTYR) {
		err = kenwood_safe_transaction(rig, "DT", buf, KENWOOD_MAX_BUF_LEN, 4);
		if (err != RIG_OK) {
			rig_debug(RIG_DEBUG_VERBOSE, "%s: Cannot read K3 DT value\n",
						__func__);
			return err;
		}
		switch(atoi(&buf[2])) {
		case K3_MODE_DATA_A:
			*mode = RIG_MODE_PKTLSB;
			break;
		case K3_MODE_AFSK_A:
			*mode = RIG_MODE_RTTYR;
			break;
		default:
			rig_debug(RIG_DEBUG_VERBOSE, "%s: unsupported data sub-mode %c\n",
						__func__, buf[2]);
			return -RIG_EINVAL;
		}
	} else {
		*mode = temp_m;
	}

	/* The K3 is not limited to specific filter widths so we can query
	 * the actual bandwidth using the BW command
	 */
	err = kenwood_safe_transaction(rig, "BW", buf, KENWOOD_MAX_BUF_LEN, 7);
	if (err != RIG_OK) {
		rig_debug(RIG_DEBUG_VERBOSE, "%s: Cannot read K3 BW value\n", __func__);
		return err;
	}
	*width = atoi(&buf[2]) * 10;

	return RIG_OK;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
0
int ts990s_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
{
	char lvlbuf[50];
	int lvl, retval = RIG_OK;

	if (RIG_VFO_CURR == vfo || RIG_VFO_VFO == vfo)
		{
			if (RIG_OK != (retval = kenwood_get_vfo_main_sub (rig, &vfo)))
				{
					return retval;
				}
		}

	switch (level) {

	case RIG_LEVEL_PREAMP:
		retval = kenwood_safe_transaction (rig, "PA", lvlbuf, sizeof (lvlbuf), 4);
		if (retval != RIG_OK)
			return retval;
		switch (vfo)
			{
			case RIG_VFO_MAIN:
				val->i = '1' == lvlbuf[2] ? rig->state.preamp[0] : 0;
				break;
					
			case RIG_VFO_SUB:
				val->i = '1' == lvlbuf[3] ? rig->state.preamp[0] : 0;
				break;

			default:
				rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %d\n", __func__, vfo);
				return -RIG_EINVAL;
			}
		break;

	case RIG_LEVEL_ATT:
		{
			char v;
			char cmd[4];
			switch (vfo)
				{
				case RIG_VFO_MAIN: v = '0'; break;
				case RIG_VFO_SUB: v = '1'; break;
				default:
					rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %d\n", __func__, vfo);
					return -RIG_EINVAL;
				}
			sprintf (cmd, "RA%c", v);
			retval = kenwood_safe_transaction (rig, cmd, lvlbuf, sizeof (lvlbuf), 4);
			if (retval != RIG_OK)
				return retval;

			if ('0' == lvlbuf[3])
				{
					val->i = 0;
				}
			else
				{
					val->i = rig->state.attenuator[lvlbuf[3] - '1'];
				}
		}
		break;

	case RIG_LEVEL_VOX:
		retval = kenwood_safe_transaction (rig, "VD0", lvlbuf, sizeof (lvlbuf), 6);
		if (retval != RIG_OK)
			return retval;
		sscanf(lvlbuf + 3, "%d", &lvl);
		val->i = lvl * 3 / 2;				/* 150ms units converted to 100ms units */
		break;

	case RIG_LEVEL_AF:
		{
			char v;
			char cmd[4];
			switch (vfo)
				{
				case RIG_VFO_MAIN: v = '0'; break;
				case RIG_VFO_SUB: v = '1'; break;
				default:
					rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %d\n", __func__, vfo);
					return -RIG_EINVAL;
				}
			sprintf (cmd, "AG%c", v);
			retval = kenwood_safe_transaction (rig, cmd, lvlbuf, sizeof (lvlbuf), 6);
			if (retval != RIG_OK)
				return retval;
			sscanf(lvlbuf + 3, "%d", &lvl);
			val->f = lvl / 255.0;
		}
		break;

	case RIG_LEVEL_RF:
		{
			char v;
			char cmd[4];
			switch (vfo)
				{
				case RIG_VFO_MAIN: v = '0'; break;
				case RIG_VFO_SUB: v = '1'; break;
				default:
					rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %d\n", __func__, vfo);
					return -RIG_EINVAL;
				}
			sprintf (cmd, "RG%c", v);
			retval = kenwood_safe_transaction (rig, cmd, lvlbuf, sizeof (lvlbuf), 6);
			if (retval != RIG_OK)
				return retval;
			sscanf(lvlbuf + 3, "%d", &lvl);
			val->f = lvl / 255.0;
		}
		break;

	case RIG_LEVEL_SQL:
		{
			char v;
			char cmd[4];
			switch (vfo)
				{
				case RIG_VFO_MAIN: v = '0'; break;
				case RIG_VFO_SUB: v = '1'; break;
				default:
					rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %d\n", __func__, vfo);
					return -RIG_EINVAL;
				}
			sprintf (cmd, "SQ%c", v);
			retval = kenwood_safe_transaction (rig, cmd, lvlbuf, sizeof (lvlbuf), 6);
			if (retval != RIG_OK)
				return retval;
			sscanf(lvlbuf + 3, "%d", &lvl);
			val->f = lvl / 255.0;
		}
		break;

	case RIG_LEVEL_CWPITCH:
		retval = kenwood_safe_transaction (rig, "PT", lvlbuf, sizeof (lvlbuf), 5);
		if (retval != RIG_OK)
			return retval;
		sscanf(lvlbuf + 2, "%d", &lvl);
		val->i = 300 + lvl * 10;
		break;

	case RIG_LEVEL_RFPOWER:
		retval = kenwood_safe_transaction (rig, "PC", lvlbuf, sizeof (lvlbuf), 5);
		if (retval != RIG_OK)
			return retval;
		sscanf(lvlbuf + 2, "%d", &lvl);
		val->f = lvl / 200.0;				/* TODO: should we detect AM and scale? */
		break;

	case RIG_LEVEL_MICGAIN:
		retval = get_kenwood_level (rig, "MG", &val->f);
		if (retval != RIG_OK)
			return retval;
		break;

	case RIG_LEVEL_KEYSPD:
		retval = kenwood_safe_transaction (rig, "KS", lvlbuf, sizeof (lvlbuf), 5);
		if (retval != RIG_OK)
			return retval;
		sscanf(lvlbuf + 2, "%d", &lvl);
		val->i = lvl;
		break;

	case RIG_LEVEL_COMP:
		retval = kenwood_safe_transaction (rig, "PL", lvlbuf, sizeof (lvlbuf), 8);
		if (retval != RIG_OK)
			return retval;
		sscanf(lvlbuf + 2, "%d", &lvl);
		lvl = lvl / 1000;						/* report input level */
		val->f = lvl / 255.0;
		break;

	case RIG_LEVEL_AGC:
		{
			char v;
			char cmd[4];
			switch (vfo)
				{
				case RIG_VFO_MAIN: v = '0'; break;
				case RIG_VFO_SUB: v = '1'; break;
				default:
					rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %d\n", __func__, vfo);
					return -RIG_EINVAL;
				}
			sprintf (cmd, "GC%c", v);
			if (RIG_OK != (retval = kenwood_safe_transaction (rig, cmd, lvlbuf, sizeof (lvlbuf), 4)))
				{
					return retval;
				}
			switch (lvlbuf[3])
				{
				case '0': val->i = RIG_AGC_OFF; break;
				case '1': val->i = RIG_AGC_SLOW; break;
				case '2': val->i = RIG_AGC_MEDIUM; break;
				case '3': val->i = RIG_AGC_FAST; break;
				}
		}
		break;

	case RIG_LEVEL_BKINDL:
		retval = kenwood_safe_transaction (rig, "SD", lvlbuf, sizeof (lvlbuf), 6);
		if (retval != RIG_OK)
			return retval;
		sscanf(lvlbuf + 2, "%d", &lvl);
		val->i = lvl / 100;
		break;

	case RIG_LEVEL_METER:
		retval = kenwood_safe_transaction (rig, "RM", lvlbuf, sizeof (lvlbuf), 7);
		if (retval != RIG_OK)
			return retval;
		switch (lvlbuf[2])
			{
			case '1': val->i = RIG_METER_ALC; break;
			case '2': val->i = RIG_METER_SWR; break;
			case '3': val->i = RIG_METER_COMP; break;
			case '4': val->i = RIG_METER_IC; break;
			case '5': val->i = RIG_METER_VDD; break;
			default: val->i = RIG_METER_NONE; break;
			}
		break;

	case RIG_LEVEL_VOXGAIN:
		retval = get_kenwood_level (rig, "VG00", &val->f);
		if (retval != RIG_OK)
			return retval;
		break;

	case RIG_LEVEL_ANTIVOX:
		retval = get_kenwood_level (rig, "VG00", &val->f);
		if (retval != RIG_OK)
			return retval;
		val->f = val->f * 255. / 20.;
		break;

	case RIG_LEVEL_RAWSTR:
	case RIG_LEVEL_STRENGTH:
		{
			char v;
			char cmd[4];
			switch (vfo)
				{
				case RIG_VFO_MAIN: v = '0'; break;
				case RIG_VFO_SUB: v = '1'; break;
				default:
					rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %d\n", __func__, vfo);
					return -RIG_EINVAL;
				}
			sprintf (cmd, "SM%c", v);
			retval = kenwood_safe_transaction (rig, cmd, lvlbuf, sizeof (lvlbuf), 7);
			if (retval != RIG_OK)
				return retval;
			/* Frontend expects:  -54 = S0, 0 = S9  */
			sscanf(lvlbuf + 3, "%d", &val->i);
			/* TS-990s returns values from 0 - 70 */
			/* so scale the value */
			if (level == RIG_LEVEL_STRENGTH)
				val->i = (val->i * 54. / 70.) - 54;
		}
		break;

	default:
		rig_debug(RIG_DEBUG_ERR,"Unsupported get_level %d", level);
		return -RIG_EINVAL;
	}

	return retval;
}
Exemplo n.º 13
0
/*
 * th_get_level
 * Assumes rig!=NULL, val!=NULL
 */
int
th_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
{
	char vch, buf[10], ackbuf[20];
	int retval, v, l;

	size_t ack_len = sizeof(ackbuf);
	vfo_t tvfo;

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

	tvfo = (vfo == RIG_VFO_CURR) ? rig->state.current_vfo : vfo;

	switch (tvfo) {
		case RIG_VFO_A:
		case RIG_VFO_VFO:
		case RIG_VFO_MEM:
			vch = '0'; break;
		case RIG_VFO_B:
			vch = '1'; break;
		default:
			return kenwood_wrong_vfo(__func__, vfo);
	}

	switch (level) {
	case RIG_LEVEL_RAWSTR:
		sprintf(buf, "SM %c", vch);

		// XXX use kenwood_safe_transaction
		retval = kenwood_transaction(rig, buf, strlen(buf), ackbuf, &ack_len);
		if (retval != RIG_OK)
			return retval;

		retval = sscanf(ackbuf, "SM %d,%d", &v, &l);
		if (retval != 2 || l < rig->caps->level_gran[LVL_RAWSTR].min.i || l > rig->caps->level_gran[LVL_RAWSTR].max.i) {
			rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, ackbuf);
			return -RIG_ERJCTED;
		}

		val->i = l;
		break;

	case RIG_LEVEL_SQL:
		sprintf(buf, "SQ %c", vch);
		retval = kenwood_safe_transaction(rig, buf, ackbuf, 10, 8);
		if (retval != RIG_OK)
			return retval;

		retval = sscanf(ackbuf, "SQ %d,%x", &v, &l);
		if (retval != 2 || l < rig->caps->level_gran[LVL_SQL].min.i || l > rig->caps->level_gran[LVL_SQL].max.i) {
					rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, ackbuf);
			return -RIG_ERJCTED;
		}

		/* range [0.0 ... 1.0] */
		val->f = (float)(l-rig->caps->level_gran[LVL_SQL].min.i) /
			(float)(rig->caps->level_gran[LVL_SQL].max.i-rig->caps->level_gran[LVL_SQL].min.i);
		break;

	case RIG_LEVEL_AF:
		sprintf(buf, "AG %c", vch);
		retval = kenwood_transaction(rig, buf, strlen(buf), ackbuf, &ack_len);
		if (retval != RIG_OK)
			return retval;

			retval = sscanf(ackbuf, "AG %d,%x", &v, &l);
			if (retval != 2 || l < rig->caps->level_gran[LVL_AF].min.i || l > rig->caps->level_gran[LVL_AF].max.i) {
				rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, ackbuf);
				return -RIG_ERJCTED;
			}

			/* range [0.0 ... 1.0] */
			val->f = (float)(l-rig->caps->level_gran[LVL_AF].min.i) /
		(float)(rig->caps->level_gran[LVL_AF].max.i-rig->caps->level_gran[LVL_AF].min.i);
		break;

	case RIG_LEVEL_RFPOWER:
		sprintf(buf, "PC %c",vch);
		retval = kenwood_transaction(rig, buf, strlen(buf), ackbuf, &ack_len);
		if (retval != RIG_OK)
			return retval;

		retval = sscanf(ackbuf, "PC %d,%d", &v, &l);
		if (retval != 2 || l < 0 || l > 3) {
			rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, ackbuf);
			return -RIG_ERJCTED;
		}

		/* range [0.0 ... 1.0] */
		val->f = (float)(l-rig->caps->level_gran[LVL_RFPOWER].min.i) /
		(float)(rig->caps->level_gran[LVL_RFPOWER].max.i-rig->caps->level_gran[LVL_RFPOWER].min.i);
		break;

	case RIG_LEVEL_BALANCE:
		retval = kenwood_safe_transaction(rig, "BAL", ackbuf, 10, 6);
		if (retval != RIG_OK)
			return retval;

		if (ackbuf[4] < '0' || ackbuf[4] > '9')
			return -RIG_EPROTO;

		val->f = (float)('4'-ackbuf[4])/('4'-'0');
		break;

	case RIG_LEVEL_ATT:
		retval = kenwood_safe_transaction(rig, "ATT", ackbuf, 10, 6);
		if (retval != RIG_OK)
			return retval;

		if (ackbuf[4] < '0' || ackbuf[4] > '9')
			return -RIG_EPROTO;

		if (ackbuf[4] == '0')
			val->i = 0;
		else
			val->i = rig->state.attenuator[ackbuf[4]-'1'];
		break;

	case RIG_LEVEL_VOXGAIN:
		retval = kenwood_safe_transaction(rig, "VXG", ackbuf, 10, 6);
		if (retval != RIG_OK)
			return retval;

		if (ackbuf[4] < '0' || ackbuf[4] > '9')
			return -RIG_EPROTO;

		val->f = (ackbuf[4] == '0') / 9;
		break;

	case RIG_LEVEL_VOXDELAY: /* "VXD" */
		return -RIG_ENIMPL;

	default:
		rig_debug(RIG_DEBUG_ERR, "%s: Unsupported Level %d\n", __func__, level);
		return -RIG_EINVAL;
	}
	return RIG_OK;
}
Exemplo n.º 14
0
int
th_get_vfo_char(RIG *rig, vfo_t *vfo, char *vfoch)
{
	char cmdbuf[10], buf[10], vfoc;
	size_t buf_size=10;
	int retval;

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

	/* Get VFO band */

	retval = kenwood_transaction(rig, "BC", 2, buf, &buf_size);
	if (retval != RIG_OK)
		return retval;
	switch (buf_size) {
	case 5: /*original case BC 0*/
	  vfoc = buf[3];
	  break;
	case 7: /*intended for D700 BC 0,0*/
	  if ((buf[0]=='B') &&(buf[1]=='C') && (buf[2]==' ') && (buf[4]=',')){
	    vfoc = buf[3];
	  } else {
	    rig_debug(RIG_DEBUG_ERR, "%s: Unexpected answer format '%s'\n", __func__, buf);
	    return -RIG_EPROTO;
	  }
	  break;
	default:
	  rig_debug(RIG_DEBUG_ERR, "%s: Unexpected answer length '%c'\n", __func__, buf_size);
	  return -RIG_EPROTO;
	  break;
	}


	switch (vfoc) {

	   	case '0': *vfo = RIG_VFO_A; break;
		case '1': *vfo = RIG_VFO_B; break;
		default:
		rig_debug(RIG_DEBUG_ERR, "%s: Unexpected VFO value '%c'\n", __func__, buf[3]);
		return -RIG_EVFO;

	}

    /* No "VMC" on THD72A */
    if (rig->caps->rig_model == RIG_MODEL_THD72A) {
        *vfoch = '0'; /* FIXME: fake */

        return RIG_OK;
    }

	/* Get mode of the VFO band */

	sprintf(cmdbuf, "VMC %c", vfoc);

	retval = kenwood_safe_transaction(rig, cmdbuf, buf, 10, 8);
	if (retval != RIG_OK)
		return retval;

	*vfoch = buf[6];

	return RIG_OK;
}