Ejemplo 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;
}
Ejemplo n.º 2
0
/*
 * Assumes rig!=NULL, rig->state.priv!=NULL
 *  and val points to a buffer big enough to hold the conf value.
 */
static int ic756pro2_get_ext_parm(RIG *rig, token_t token, value_t *val)
{
	const struct confparams *cfp;

	unsigned char resbuf[MAXFRAMELEN];
	int res_len, icom_val=0;
	int cmdhead;
	int retval;

	int ep_cmd = C_CTL_MEM;
	int ep_sc;             /* Subcommand in $1A $05xx */

	switch(token) {
	case TOK_SSBBASS:
		ep_sc = S_MEM_SBASS ;
		break;
	case TOK_MEMNAME:
		ep_sc = S_MEM_NAME;
		break;
	case TOK_SQLCTRL:
		ep_sc = S_MEM_SQL_CTL;
		break;
	case TOK_MYCALL:	/* max 10 ASCII char */
		ep_sc = S_MEM_MYCALL;
		break;
	case TOK_RTTY_FLTR:	/* RTTY filter mode 0 - 4 */
		ep_sc = S_MEM_RTTY_FL_PB;
		break;
	default:
		rig_debug(RIG_DEBUG_ERR,"Unsupported get_ext_parm %d", token);
		return -RIG_EINVAL;
	}

	retval = icom_transaction (rig, ep_cmd, ep_sc, NULL, 0,
					resbuf, &res_len);
	if (retval != RIG_OK)
            return retval;

	/*
	 * strbuf should contain Cn,Sc,Data area
	 */
	cmdhead = (ep_sc == -1) ? 1:S_MEM_SC_LEN + 1;
	res_len -= cmdhead;
/* should echo cmd, subcmd and then data, if you get an ack something is wrong */
	if (resbuf[0] != ep_cmd) {
		if (resbuf[0] == ACK) {
				rig_debug(RIG_DEBUG_ERR,"%s: protocol error (%#.2x), "
			"len=%d\n", __FUNCTION__,resbuf[0],res_len);
		return -RIG_EPROTO;
		}
		else {
			rig_debug(RIG_DEBUG_ERR,"%s: ack NG (%#.2x), "
				"len=%d\n", __FUNCTION__,resbuf[0],res_len);
		return -RIG_ERJCTED;
		}
	}
	cfp = rig_ext_lookup_tok(rig, token);
	switch(cfp->type) {
		case RIG_CONF_STRING:
		 memcpy(val->s, resbuf, res_len);
		break;
		case RIG_CONF_CHECKBUTTON:
		case RIG_CONF_COMBO:
		 val->i = from_bcd_be(resbuf+cmdhead, res_len*2);
		break;
		case RIG_CONF_NUMERIC:
		 val->f = from_bcd_be(resbuf+cmdhead, res_len*2);
		break;
		default:
		 rig_debug(RIG_DEBUG_ERR,"%s: protocol error (%#.2x), "
			"len=%d\n", __FUNCTION__,resbuf[0],res_len);
		return -RIG_EPROTO;

	}
	rig_debug(RIG_DEBUG_TRACE,"%s: %d %d %d %f\n",
			__FUNCTION__, res_len, icom_val, val->i, val->f);

	return RIG_OK;
}