* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <config.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <glib.h>
-#include "libsigrok.h"
+#include <libsigrok/libsigrok.h>
#include "libsigrok-internal.h"
#define LOG_PREFIX "vc870"
{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 */
+ /*
+ * Note: Measurements showed that AC and DC differ
+ * in the factors used, although docs say they should
+ * be the same.
+ */
{1e-8, 1e-7, 0, 0, 0, 0, 0, 0}, /* DCµA */
- {1e-8, 1e-7, 0, 0, 0, 0, 0, 0}, /* ACµ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-6, 1e-5, 0, 0, 0, 0, 0, 0}, /* ACmA */
+ {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-1, 0, 0, 0, 0, 0, 0, 0}, /* Power factor / freq */
+ {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 */
};
float *result)
{
int i, intval;
- float floatval;
/* Bytes 3-7: Main display value (5 decimal digits) */
if (info->is_open || info->is_ol1) {
} else if (!isdigit(buf[3]) || !isdigit(buf[4]) ||
!isdigit(buf[5]) || !isdigit(buf[6]) || !isdigit(buf[7])) {
sr_dbg("Invalid digits: %02x %02x %02x %02x %02X "
- "(%c %c %c %c %c).", buf[3], buf[4], buf[5], buf[6],
- buf[7]);
+ "(%c %c %c %c %c).",
+ buf[3], buf[4], buf[5], buf[6], buf[7],
+ buf[3], buf[4], buf[5], buf[6], buf[7]);
return SR_ERR;
}
intval *= info->is_sign1 ? -1 : 1;
// intval *= info->is_sign2 ? -1 : 1; /* TODO: Fahrenheit / aux display. */
- floatval = (float)intval;
-
/* Note: The decimal point position will be parsed later. */
- sr_spew("The display value is %f.", floatval);
+ sr_spew("The display value without comma is %05d.", intval);
- *result = floatval;
+ *result = (float)intval;
return SR_OK;
}
mode = 16; /* Act+apparent power */
else if (info->is_power_factor_freq)
mode = 17; /* Power factor / freq */
- else if (info->is_v_a_eff_value)
+ else if (info->is_v_a_rms_value)
mode = 18; /* V eff + A eff */
else {
sr_dbg("Invalid mode, range byte was: 0x%02x.", b);
info->is_power_factor_freq = TRUE;
else if (buf[1] == 0x32)
/* Voltage effective value + current effective value */
- info->is_v_a_eff_value = TRUE;
+ info->is_v_a_rms_value = TRUE;
break;
default:
sr_dbg("Invalid function bytes: %02x %02x.", buf[0], buf[1]);
/* Byte 22: Always '\n' (newline, 0x0a, 10) */
info->is_auto = !info->is_manu;
- info->is_rms = TRUE;
}
static void handle_flags(struct sr_datafeed_analog *analog,
/* 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;
- }
- if (info->is_power_factor_freq) {
- /* TODO: Handle power factor. */
- // analog->mq = SR_MQ_POWER_FACTOR;
- // analog->unit = SR_UNIT_UNITLESS;
- analog->mq = SR_MQ_FREQUENCY;
- analog->unit = SR_UNIT_HERTZ;
+ 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->meaning->mq = SR_MQ_POWER_FACTOR;
+ analog->meaning->unit = SR_UNIT_UNITLESS;
+ /* TODO: Handle frequency. */
+ // analog->meaning->mq = SR_MQ_FREQUENCY;
+ // analog->meaning->unit = SR_UNIT_HERTZ;
+ }
+ if (info->is_v_a_rms_value) {
+ analog->meaning->mqflags |= SR_MQFLAG_RMS;
+ analog->meaning->mq = SR_MQ_VOLTAGE;
+ analog->meaning->unit = SR_UNIT_VOLT;
+ /* TODO: Handle effective current value */
+ // 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;
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)
int ret;
struct vc870_info *info_local;
- info_local = (struct vc870_info *)info;
-
info_local = (struct vc870_info *)info;
memset(info_local, 0, sizeof(struct vc870_info));