Пример #1
0
/*
 * Handle S-meter (SM, SMH) level locally and pass rest to kenwood_get_level()
 */
int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
{
	rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);

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

	char lvlbuf[50];
	int retval;
	struct kenwood_priv_data *priv = rig->state.priv;

	switch (level) {
	case RIG_LEVEL_STRENGTH:
		/* As of FW rev 4.37 the K3 supports an 'SMH' command that
		 * offers a higher resolution, 0-100 (mine went to 106),
		 * rawstr value for more precise S-meter reporting.
		 */
		retval = strncmp(priv->fw_rev, "4.37", 4);
		if (retval < 0) {
			cal_table_t str_cal = K3_SM_CAL;

			retval = kenwood_safe_transaction(rig, "SM", lvlbuf, 10, 7);
			if (retval != RIG_OK)
				return retval;

			sscanf(lvlbuf+2, "%d", &val->i);	/* rawstr */

			val->i = (int) rig_raw2val(val->i, &str_cal);
		} else if (retval >= 0) {
			cal_table_t str_cal = K3_SMH_CAL;

			retval = kenwood_safe_transaction(rig, "SMH", lvlbuf, 10, 7);
			if (retval != RIG_OK)
				return retval;

			sscanf(lvlbuf+3, "%d", &val->i);	/* rawstr */

			val->i = (int) rig_raw2val(val->i, &str_cal);
		} else {
			rig_debug(RIG_DEBUG_ERR, "%s: Firmware version comparison failed!\n",
				  __func__);
			return -RIG_EINVAL;
		}

		break;

	default:
		retval = kenwood_get_level(rig, vfo, level, val);
		if (retval != RIG_OK)
			return retval;
		break;
	}

	return RIG_OK;
}
Пример #2
0
/*
 * ts570_get_level
 * Assumes rig!=NULL, val!=NULL
 */
int
ts570_get_level (RIG * rig, vfo_t vfo, setting_t level, value_t * val)
{
  char ackbuf[50];
  size_t ack_len;
  int levelint;
  int retval;
  int i;

  switch (level)
    {
    case RIG_LEVEL_RFPOWER:
      /* ts570d returns 5..100 measured in watt */
      retval = kenwood_transaction (rig, "PC", ackbuf, sizeof (ackbuf));
      if (RIG_OK != retval)
	return retval;
			ack_len = strlen (ackbuf);
      if (5 != ack_len)
	return -RIG_EPROTO;
      if (1 != sscanf (&ackbuf[2], "%d", &levelint))
	return -RIG_EPROTO;
      val->f = (float) levelint / 100.;
      return RIG_OK;

    case RIG_LEVEL_MICGAIN:
      /* reads from 0..100 */
      retval = kenwood_transaction (rig, "MG", ackbuf, sizeof (ackbuf));
      if (RIG_OK != retval)
        return retval;
			ack_len = strlen (ackbuf);
      if (5 != ack_len)
        return -RIG_EPROTO;
      if (1 != sscanf (&ackbuf[2], "%d", &levelint))
	return -RIG_EPROTO;
      val->f = (float) levelint / 100.;
      return RIG_OK;

    case RIG_LEVEL_PREAMP:
			retval = kenwood_transaction (rig, "PA", ackbuf, sizeof (ackbuf));
	if (retval != RIG_OK)
	    return retval;
			ack_len = strlen (ackbuf);
	if (3  != ack_len) {
	    rig_debug(RIG_DEBUG_ERR,"%s: unexpected answer len=%d\n",
			__func__, ack_len);
	    return -RIG_ERJCTED;
	}

	sscanf(ackbuf+2, "%d", &levelint);
	if (levelint == 0) {
	    val->i = 0;
	} else {
	    for (i=0; i<levelint && i<MAXDBLSTSIZ; i++)
		if (rig->state.preamp[i] == 0) {
		    rig_debug(RIG_DEBUG_ERR,"%s: "
			    "unexpected att level %d\n",
			    __func__, levelint);
		    return -RIG_EPROTO;
		}
		if (i != levelint)
		    return -RIG_EINTERNAL;
		val->i = rig->state.preamp[i-1];
	}
	break;
    default:
 	return kenwood_get_level (rig, vfo, level, val);
    }

  return RIG_OK;		/* never reached */
}