X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fdmm%2Fvc870.c;h=d9c3d5ac77199b8897958933053a403e090e0f8b;hb=830e24b68f87f51d4bdc8067704219e0956fba90;hp=2663260bc48ca9464d0fe23928446156d33214e3;hpb=3591481e871eec154a764e1c78004095144de5b5;p=libsigrok.git
diff --git a/src/dmm/vc870.c b/src/dmm/vc870.c
index 2663260b..d9c3d5ac 100644
--- a/src/dmm/vc870.c
+++ b/src/dmm/vc870.c
@@ -14,8 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see .
*/
#include
@@ -28,39 +27,39 @@
#define LOG_PREFIX "vc870"
-/* Factors for the respective measurement mode (0 means "invalid"). */
-static const float factors[][8] = {
- {1e-4, 1e-3, 1e-2, 1e-1, 0, 0, 0, 0}, /* DCV */
- {1e-3, 1e-2, 1e-1, 1, 0, 0, 0, 0}, /* ACV */
- {1e-5, 0, 0, 0, 0, 0, 0, 0}, /* DCmV */
- {1e-1, 0, 0, 0, 0, 0, 0, 0}, /* Temperature (C) */
-// {1e-2, 0, 0, 0, 0, 0, 0, 0}, /* TODO: Temperature (F) */
+/* Exponents for the respective measurement mode. */
+static const int exponents[][8] = {
+ { -4, -3, -2, -1, 0, 0, 0, 0 }, /* DCV */
+ { -3, -2, -1, 0, 0, 0, 0, 0 }, /* ACV */
+ { -5, 0, 0, 0, 0, 0, 0, 0 }, /* DCmV */
+ { -1, 0, 0, 0, 0, 0, 0, 0 }, /* Temperature (C) */
+// { -2, 0, 0, 0, 0, 0, 0, 0 }, /* TODO: Temperature (F) */
/*
- * Note: The sequence 1e-1 -> 1e1 for the resistance
+ * Note: The sequence -1 -> 1 for the resistance
* value is correct and verified in practice!
* Don't trust the vendor docs on this.
*/
- {1e-2, 1e-1, 1e1, 1e2, 1e3, 1e4, 0, 0}, /* Resistance */
- {1e-2, 0, 0, 0, 0, 0, 0, 0}, /* Continuity */
- {1e-12, 1e-11, 1e-10, 1e-9, 1e-8, 1e-7, 1e-6, 0}, /* Capacitance */
- {1e-4, 0, 0, 0, 0, 0, 0, 0}, /* Diode */
- {1e-3, 1e-2, 1e-1, 1, 1e1, 1e2, 1e3, 1e4}, /* Frequency */
- {1e-2, 0, 0, 0, 0, 0, 0, 0}, /* Loop current */
+ { -2, -1, 1, 2, 3, 4, 0, 0 }, /* Resistance */
+ { -2, 0, 0, 0, 0, 0, 0, 0 }, /* Continuity */
+ { -12, -11, -10, -9, -8, -7, -6, 0 }, /* Capacitance */
+ { -4, 0, 0, 0, 0, 0, 0, 0 }, /* Diode */
+ { -3, -2, -1, 0, 1, 2, 3, 4 }, /* Frequency */
+ { -2, 0, 0, 0, 0, 0, 0, 0 }, /* Loop current */
/*
* Note: Measurements showed that AC and DC differ
- * in the factors used, although docs say they should
+ * in the exponents used, although docs say they should
* be the same.
*/
- {1e-8, 1e-7, 0, 0, 0, 0, 0, 0}, /* DCµA */
- {1e-7, 1e-6, 0, 0, 0, 0, 0, 0}, /* ACµA */
- {1e-6, 1e-5, 0, 0, 0, 0, 0, 0}, /* DCmA */
- {1e-5, 1e-4, 0, 0, 0, 0, 0, 0}, /* ACmA */
- {1e-3, 0, 0, 0, 0, 0, 0, 0}, /* DCA */
- /* TODO: Verify factor for ACA */
- {1e-3, 0, 0, 0, 0, 0, 0, 0}, /* ACA */
- {1e-1, 0, 0, 0, 0, 0, 0, 0}, /* Act+apparent power */
- {1e-3, 0, 0, 0, 0, 0, 0, 0}, /* Power factor / freq */
- {1e-1, 0, 0, 0, 0, 0, 0, 0}, /* V eff + A eff */
+ { -8, -7, 0, 0, 0, 0, 0, 0 }, /* DCµA */
+ { -7, -6, 0, 0, 0, 0, 0, 0 }, /* ACµA */
+ { -6, -5, 0, 0, 0, 0, 0, 0 }, /* DCmA */
+ { -5, -4, 0, 0, 0, 0, 0, 0 }, /* ACmA */
+ { -3, 0, 0, 0, 0, 0, 0, 0 }, /* DCA */
+ /* TODO: Verify exponent for ACA */
+ { -3, 0, 0, 0, 0, 0, 0, 0 }, /* ACA */
+ { -1, 0, 0, 0, 0, 0, 0, 0 }, /* Act+apparent power */
+ { -3, 0, 0, 0, 0, 0, 0, 0 }, /* Power exponent / freq */
+ { -1, 0, 0, 0, 0, 0, 0, 0 }, /* V eff + A eff */
};
static int parse_value(const uint8_t *buf, struct vc870_info *info,
@@ -100,11 +99,10 @@ static int parse_value(const uint8_t *buf, struct vc870_info *info,
return SR_OK;
}
-static int parse_range(uint8_t b, float *floatval,
+static int parse_range(uint8_t b, float *floatval, int *exponent,
const struct vc870_info *info)
{
int idx, mode;
- float factor = 0;
idx = b - '0';
@@ -157,23 +155,18 @@ static int parse_range(uint8_t b, float *floatval,
return SR_ERR;
}
- factor = factors[mode][idx];
+ *exponent = exponents[mode][idx];
- if (factor == 0) {
- sr_dbg("Invalid factor for range byte: 0x%02x (mode=%d, idx=%d).", b, mode, idx);
- return SR_ERR;
- }
-
- /* Apply respective factor (mode-dependent) on the value. */
- *floatval *= factor;
- sr_dbg("Applying factor %f, new value is %f.", factor, *floatval);
+ /* Apply respective exponent (mode-dependent) on the value. */
+ *floatval *= powf(10, *exponent);
+ sr_dbg("Applying exponent %d, new value is %f.", *exponent, *floatval);
return SR_OK;
}
static void parse_flags(const uint8_t *buf, struct vc870_info *info)
{
- /* Bytes 0/1: Function / function select */
+ /* Bytes 0/1: Function / function select */
/* Note: Some of these mappings are fixed up later. */
switch (buf[0]) {
case 0x30: /* DCV / ACV */
@@ -282,105 +275,105 @@ static void parse_flags(const uint8_t *buf, struct vc870_info *info)
info->is_auto = !info->is_manu;
}
-static void handle_flags(struct sr_datafeed_analog_old *analog,
+static void handle_flags(struct sr_datafeed_analog *analog,
float *floatval, const struct vc870_info *info)
{
/*
* Note: is_micro etc. are not used directly to multiply/divide
- * floatval, this is handled via parse_range() and factors[][].
+ * floatval, this is handled via parse_range() and exponents[][].
*/
/* Measurement modes */
if (info->is_voltage) {
- analog->mq = SR_MQ_VOLTAGE;
- analog->unit = SR_UNIT_VOLT;
+ analog->meaning->mq = SR_MQ_VOLTAGE;
+ analog->meaning->unit = SR_UNIT_VOLT;
}
if (info->is_current) {
- analog->mq = SR_MQ_CURRENT;
- analog->unit = SR_UNIT_AMPERE;
+ analog->meaning->mq = SR_MQ_CURRENT;
+ analog->meaning->unit = SR_UNIT_AMPERE;
}
if (info->is_resistance) {
- analog->mq = SR_MQ_RESISTANCE;
- analog->unit = SR_UNIT_OHM;
+ analog->meaning->mq = SR_MQ_RESISTANCE;
+ analog->meaning->unit = SR_UNIT_OHM;
}
if (info->is_frequency) {
- analog->mq = SR_MQ_FREQUENCY;
- analog->unit = SR_UNIT_HERTZ;
+ analog->meaning->mq = SR_MQ_FREQUENCY;
+ analog->meaning->unit = SR_UNIT_HERTZ;
}
if (info->is_capacitance) {
- analog->mq = SR_MQ_CAPACITANCE;
- analog->unit = SR_UNIT_FARAD;
+ analog->meaning->mq = SR_MQ_CAPACITANCE;
+ analog->meaning->unit = SR_UNIT_FARAD;
}
if (info->is_temperature) {
- analog->mq = SR_MQ_TEMPERATURE;
- analog->unit = SR_UNIT_CELSIUS;
+ analog->meaning->mq = SR_MQ_TEMPERATURE;
+ analog->meaning->unit = SR_UNIT_CELSIUS;
/* TODO: Handle Fahrenheit in auxiliary display. */
- // analog->unit = SR_UNIT_FAHRENHEIT;
+ // analog->meaning->unit = SR_UNIT_FAHRENHEIT;
}
if (info->is_continuity) {
- analog->mq = SR_MQ_CONTINUITY;
- analog->unit = SR_UNIT_BOOLEAN;
+ analog->meaning->mq = SR_MQ_CONTINUITY;
+ analog->meaning->unit = SR_UNIT_BOOLEAN;
/* Vendor docs: "< 20 Ohm acoustic" */
*floatval = (*floatval < 0.0 || *floatval > 20.0) ? 0.0 : 1.0;
}
if (info->is_diode) {
- analog->mq = SR_MQ_VOLTAGE;
- analog->unit = SR_UNIT_VOLT;
+ analog->meaning->mq = SR_MQ_VOLTAGE;
+ analog->meaning->unit = SR_UNIT_VOLT;
}
if (info->is_loop_current) {
/* 4mA = 0%, 20mA = 100% */
- analog->mq = SR_MQ_CURRENT;
- analog->unit = SR_UNIT_PERCENTAGE;
+ analog->meaning->mq = SR_MQ_CURRENT;
+ analog->meaning->unit = SR_UNIT_PERCENTAGE;
}
if (info->is_power) {
- analog->mq = SR_MQ_POWER;
- analog->unit = SR_UNIT_WATT;
+ analog->meaning->mq = SR_MQ_POWER;
+ analog->meaning->unit = SR_UNIT_WATT;
}
if (info->is_power_apparent_power) {
- analog->mq = SR_MQ_POWER;
- analog->unit = SR_UNIT_WATT;
+ analog->meaning->mq = SR_MQ_POWER;
+ analog->meaning->unit = SR_UNIT_WATT;
/* TODO: Handle apparent power. */
- // analog->mq = SR_MQ_APPARENT_POWER;
- // analog->unit = SR_UNIT_VOLT_AMPERE;
+ // analog->meaning->mq = SR_MQ_APPARENT_POWER;
+ // analog->meaning->unit = SR_UNIT_VOLT_AMPERE;
}
if (info->is_power_factor_freq) {
- analog->mq = SR_MQ_POWER_FACTOR;
- analog->unit = SR_UNIT_UNITLESS;
+ analog->meaning->mq = SR_MQ_POWER_FACTOR;
+ analog->meaning->unit = SR_UNIT_UNITLESS;
/* TODO: Handle frequency. */
- // analog->mq = SR_MQ_FREQUENCY;
- // analog->unit = SR_UNIT_HERTZ;
+ // analog->meaning->mq = SR_MQ_FREQUENCY;
+ // analog->meaning->unit = SR_UNIT_HERTZ;
}
if (info->is_v_a_rms_value) {
- analog->mqflags |= SR_MQFLAG_RMS;
- analog->mq = SR_MQ_VOLTAGE;
- analog->unit = SR_UNIT_VOLT;
+ analog->meaning->mqflags |= SR_MQFLAG_RMS;
+ analog->meaning->mq = SR_MQ_VOLTAGE;
+ analog->meaning->unit = SR_UNIT_VOLT;
/* TODO: Handle effective current value */
- // analog->mq = SR_MQ_CURRENT;
- // analog->unit = SR_UNIT_AMPERE;
+ // analog->meaning->mq = SR_MQ_CURRENT;
+ // analog->meaning->unit = SR_UNIT_AMPERE;
}
/* Measurement related flags */
if (info->is_ac)
- analog->mqflags |= SR_MQFLAG_AC;
+ analog->meaning->mqflags |= SR_MQFLAG_AC;
if (info->is_dc)
- analog->mqflags |= SR_MQFLAG_DC;
+ analog->meaning->mqflags |= SR_MQFLAG_DC;
if (info->is_auto)
- analog->mqflags |= SR_MQFLAG_AUTORANGE;
+ analog->meaning->mqflags |= SR_MQFLAG_AUTORANGE;
if (info->is_diode)
- analog->mqflags |= SR_MQFLAG_DIODE;
+ analog->meaning->mqflags |= SR_MQFLAG_DIODE | SR_MQFLAG_DC;
if (info->is_hold)
/*
* Note: HOLD only affects the number displayed on the LCD,
* but not the value sent via the protocol! It also does not
* affect the bargraph on the LCD.
*/
- analog->mqflags |= SR_MQFLAG_HOLD;
+ analog->meaning->mqflags |= SR_MQFLAG_HOLD;
if (info->is_max)
- analog->mqflags |= SR_MQFLAG_MAX;
+ analog->meaning->mqflags |= SR_MQFLAG_MAX;
if (info->is_min)
- analog->mqflags |= SR_MQFLAG_MIN;
+ analog->meaning->mqflags |= SR_MQFLAG_MIN;
if (info->is_rel)
- analog->mqflags |= SR_MQFLAG_RELATIVE;
+ analog->meaning->mqflags |= SR_MQFLAG_RELATIVE;
/* Other flags */
if (info->is_batt)
@@ -412,12 +405,12 @@ SR_PRIV gboolean sr_vc870_packet_valid(const uint8_t *buf)
}
SR_PRIV int sr_vc870_parse(const uint8_t *buf, float *floatval,
- struct sr_datafeed_analog_old *analog, void *info)
+ struct sr_datafeed_analog *analog, void *info)
{
- int ret;
+ int ret, exponent = 0;
struct vc870_info *info_local;
- info_local = (struct vc870_info *)info;
+ info_local = info;
memset(info_local, 0, sizeof(struct vc870_info));
if (!sr_vc870_packet_valid(buf))
@@ -430,10 +423,13 @@ SR_PRIV int sr_vc870_parse(const uint8_t *buf, float *floatval,
return ret;
}
- if ((ret = parse_range(buf[2], floatval, info_local)) != SR_OK)
+ if ((ret = parse_range(buf[2], floatval, &exponent, info_local)) != SR_OK)
return ret;
handle_flags(analog, floatval, info_local);
+ analog->encoding->digits = -exponent;
+ analog->spec->spec_digits = -exponent;
+
return SR_OK;
}