2013-11-19 16:49:23 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the libsigrok project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Matthias Heidbrink <m-sigrok@heidbrink.biz>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-11-21 14:47:09 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
2013-11-19 16:49:23 +00:00
|
|
|
#include "protocol.h"
|
|
|
|
|
2013-11-21 14:47:09 +00:00
|
|
|
/** Set or clear flags in devc->mqflags. */
|
|
|
|
static void setmqf(struct dev_context *devc, uint64_t flags, gboolean set)
|
|
|
|
{
|
|
|
|
if (set)
|
|
|
|
devc->mqflags |= flags;
|
|
|
|
else
|
|
|
|
devc->mqflags &= ~flags;
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:51:18 +00:00
|
|
|
/** Decode current type and measured value, Metrahit 12-16. */
|
|
|
|
static void decode_ctmv_16(uint8_t ctmv, struct dev_context *devc)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
|
|
|
devc->mq = 0;
|
|
|
|
devc->unit = 0;
|
|
|
|
devc->mqflags = 0;
|
|
|
|
|
|
|
|
switch (ctmv) {
|
|
|
|
case 0x00: /* 0000 - */
|
|
|
|
break;
|
|
|
|
case 0x01: /* 0001 mV DC */
|
|
|
|
devc->scale1000 = -1; /* Fall through */
|
|
|
|
case 0x02: /* 0010 V DC */
|
|
|
|
case 0x03: /* 0011 V AC+DC */
|
|
|
|
case 0x04: /* 0100 V AC */
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_VOLT;
|
|
|
|
if (ctmv <= 0x03)
|
|
|
|
devc->mqflags |= SR_MQFLAG_DC;
|
|
|
|
if (ctmv >= 0x03) {
|
|
|
|
devc->mqflags |= SR_MQFLAG_AC;
|
2013-12-26 12:02:02 +00:00
|
|
|
if (devc->model >= METRAHIT_16S)
|
2013-11-21 14:47:09 +00:00
|
|
|
devc->mqflags |= SR_MQFLAG_RMS;
|
2013-12-26 11:51:18 +00:00
|
|
|
}
|
2013-11-21 14:47:09 +00:00
|
|
|
break;
|
|
|
|
case 0x05: /* 0101 Hz (15S/16S only) */
|
|
|
|
case 0x06: /* 0110 kHz (15S/16S only) */
|
|
|
|
devc->mq = SR_MQ_FREQUENCY;
|
|
|
|
devc->unit = SR_UNIT_HERTZ;
|
|
|
|
if (ctmv == 0x06)
|
|
|
|
devc->scale1000 = 1;
|
|
|
|
break;
|
|
|
|
case 0x07: /* 0111 % (15S/16S only) */
|
|
|
|
devc->mq = SR_MQ_DUTY_CYCLE;
|
|
|
|
devc->unit = SR_UNIT_PERCENTAGE;
|
|
|
|
break;
|
|
|
|
case 0x08: /* 1000 Diode */
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_VOLT;
|
|
|
|
devc->mqflags |= SR_MQFLAG_DIODE;
|
|
|
|
break;
|
|
|
|
case 0x09: /* 1001 Ohm, °C */
|
|
|
|
case 0x0a: /* 1010 kOhm */
|
|
|
|
case 0x0b: /* 1011 MOhm */
|
|
|
|
devc->mq = SR_MQ_RESISTANCE; /* Changed to temp. later if req.*/
|
|
|
|
devc->unit = SR_UNIT_OHM;
|
|
|
|
devc->scale1000 = ctmv - 0x09;
|
|
|
|
break;
|
|
|
|
case 0x0c: /* 1100 nF (15S/16S only) */
|
|
|
|
case 0x0d: /* 1101 µF (15S/16S only) */
|
|
|
|
devc->mq = SR_MQ_CAPACITANCE;
|
|
|
|
devc->unit = SR_UNIT_FARAD;
|
|
|
|
if (ctmv == 0x0c)
|
|
|
|
devc->scale1000 = -3;
|
|
|
|
else
|
|
|
|
devc->scale1000 = -2;
|
|
|
|
break;
|
|
|
|
case 0x0e: /* mA, µA */
|
|
|
|
devc->scale1000 = -1; /* Fall through. */
|
|
|
|
case 0x0f: /* A */
|
|
|
|
devc->mq = SR_MQ_CURRENT;
|
|
|
|
devc->unit = SR_UNIT_AMPERE;
|
2013-12-26 12:02:02 +00:00
|
|
|
if (devc->model == METRAHIT_16S)
|
2013-11-21 14:47:09 +00:00
|
|
|
devc->mqflags |= SR_MQFLAG_RMS;
|
|
|
|
/* 16I A only with clamp, RMS questionable. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:51:18 +00:00
|
|
|
/**
|
|
|
|
* Decode range/sign/acdc byte special chars (Metrahit 12-16).
|
|
|
|
*
|
|
|
|
* @param[in] spc Special characters 1 and 2 (s1 | (s2 << 4)).
|
2013-11-21 14:47:09 +00:00
|
|
|
*/
|
2013-12-26 11:51:18 +00:00
|
|
|
static void decode_rs_16(uint8_t rs, struct dev_context *devc)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
|
|
|
sr_spew("decode_rs_16(%d) scale = %f", rs, devc->scale);
|
|
|
|
|
|
|
|
if (rs & 0x08) /* Sign */
|
|
|
|
devc->scale *= -1.0;
|
|
|
|
|
|
|
|
if (devc->mq == SR_MQ_CURRENT) {
|
|
|
|
if (rs & 0x04) /* Current is AC */
|
|
|
|
devc->mqflags |= SR_MQFLAG_AC;
|
|
|
|
else
|
|
|
|
devc->mqflags |= SR_MQFLAG_DC;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (rs & 0x03) {
|
|
|
|
case 0:
|
2013-12-26 11:51:18 +00:00
|
|
|
if (devc->mq == SR_MQ_VOLTAGE) /* V */
|
2013-11-21 14:47:09 +00:00
|
|
|
devc->scale *= 0.1;
|
|
|
|
else if (devc->mq == SR_MQ_CURRENT) /* 000.0 µA */
|
|
|
|
devc->scale *= 0.0000001; /* Untested! */
|
|
|
|
else if (devc->mq == SR_MQ_RESISTANCE) {
|
|
|
|
if (devc->buflen >= 10) {
|
|
|
|
/* °C with 10 byte msg type, otherwise GOhm. */
|
|
|
|
devc->mq = SR_MQ_TEMPERATURE;
|
|
|
|
devc->unit = SR_UNIT_CELSIUS;
|
|
|
|
devc->scale *= 0.01;
|
2013-12-26 11:51:18 +00:00
|
|
|
} else if ((devc->scale1000 == 2)) {
|
2013-11-21 14:47:09 +00:00
|
|
|
/* 16I Iso 500/1000V 3 GOhm */
|
|
|
|
devc->scale *= 0.1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
devc->scale *= 0.0001;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
devc->scale *= 0.001;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
devc->scale *= 0.01;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:51:18 +00:00
|
|
|
/**
|
|
|
|
* Decode special chars, Metrahit 12-16.
|
|
|
|
*
|
|
|
|
* @param[in] spc Special characters 1 and 2 (s1 | (s2 << 4)).
|
2013-11-21 14:47:09 +00:00
|
|
|
*/
|
2013-12-26 11:51:18 +00:00
|
|
|
static void decode_spc_16(uint8_t spc, struct dev_context *devc)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
|
|
|
/* xxxx1xxx ON */
|
|
|
|
/* TODO: What does that mean? Power on? The 16I sets this. */
|
|
|
|
/* xxxxx1xx BEEP */
|
|
|
|
/* xxxxxx1x Low battery */
|
|
|
|
/* xxxxxxx1 FUSE */
|
|
|
|
/* 1xxxxxxx MIN */
|
|
|
|
setmqf(devc, SR_MQFLAG_MIN, spc & 0x80);
|
|
|
|
|
|
|
|
/* x1xxxxxx MAN */
|
|
|
|
setmqf(devc, SR_MQFLAG_AUTORANGE, !(spc & 0x40));
|
|
|
|
|
|
|
|
/* xx1xxxxx DATA */
|
|
|
|
setmqf(devc, SR_MQFLAG_HOLD, spc & 0x20);
|
|
|
|
|
|
|
|
/* xxx1xxxx MAX */
|
|
|
|
setmqf(devc, SR_MQFLAG_MAX, spc & 0x10);
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:51:18 +00:00
|
|
|
/** Decode current type and measured value, Metrahit 18. */
|
|
|
|
static void decode_ctmv_18(uint8_t ctmv, struct dev_context *devc)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
|
|
|
devc->mq = 0;
|
|
|
|
devc->unit = 0;
|
|
|
|
devc->mqflags = 0;
|
|
|
|
|
|
|
|
switch (ctmv) {
|
|
|
|
case 0x00: /* 0000 - */
|
|
|
|
break;
|
|
|
|
case 0x01: /* 0001 V AC */
|
|
|
|
case 0x02: /* 0010 V AC+DC */
|
|
|
|
case 0x03: /* 0011 V DC */
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_VOLT;
|
|
|
|
if (ctmv <= 0x02)
|
|
|
|
devc->mqflags |= (SR_MQFLAG_AC | SR_MQFLAG_RMS);
|
|
|
|
if (ctmv >= 0x02)
|
|
|
|
devc->mqflags |= SR_MQFLAG_DC;
|
|
|
|
break;
|
|
|
|
case 0x04: /* 0100 Ohm/Ohm with buzzer */
|
|
|
|
devc->mq = SR_MQ_RESISTANCE;
|
|
|
|
devc->unit = SR_UNIT_OHM;
|
|
|
|
break;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x05: /* 0101 Diode/Diode with buzzer */
|
2013-11-21 14:47:09 +00:00
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_VOLT;
|
|
|
|
devc->mqflags |= SR_MQFLAG_DIODE;
|
|
|
|
break;
|
|
|
|
case 0x06: /* 0110 °C */
|
|
|
|
devc->mq = SR_MQ_TEMPERATURE;
|
|
|
|
devc->unit = SR_UNIT_CELSIUS;
|
|
|
|
break;
|
|
|
|
case 0x07: /* 0111 F */
|
|
|
|
devc->mq = SR_MQ_CAPACITANCE;
|
|
|
|
devc->unit = SR_UNIT_FARAD;
|
|
|
|
break;
|
|
|
|
case 0x08: /* 1000 mA DC */
|
|
|
|
case 0x09: /* 1001 A DC */
|
|
|
|
case 0x0a: /* 1010 mA AC+DC */
|
|
|
|
case 0x0b: /* 1011 A AC+DC */
|
|
|
|
devc->mq = SR_MQ_CURRENT;
|
|
|
|
devc->unit = SR_UNIT_AMPERE;
|
|
|
|
devc->mqflags |= SR_MQFLAG_DC;
|
|
|
|
if (ctmv >= 0x0a)
|
|
|
|
devc->mqflags |= (SR_MQFLAG_AC | SR_MQFLAG_RMS);
|
|
|
|
if ((ctmv == 0x08) || (ctmv == 0x0a))
|
|
|
|
devc->scale1000 = -1;
|
|
|
|
break;
|
|
|
|
case 0x0c: /* 1100 Hz */
|
|
|
|
devc->mq = SR_MQ_FREQUENCY;
|
|
|
|
devc->unit = SR_UNIT_HERTZ;
|
|
|
|
break;
|
|
|
|
case 0x0d: /* 1101 dB */
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_DECIBEL_VOLT;
|
|
|
|
devc->mqflags |= SR_MQFLAG_AC; /* dB available for AC only */
|
|
|
|
break;
|
|
|
|
case 0x0e: /* 1110 Events AC, Events AC+DC. Actually delivers just
|
|
|
|
* current voltage via IR, nothing more. */
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_VOLT;
|
|
|
|
devc->mqflags |= SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS;
|
|
|
|
break;
|
|
|
|
case 0x0f: /* 1111 Clock */
|
|
|
|
devc->mq = SR_MQ_TIME;
|
|
|
|
devc->unit = SR_UNIT_SECOND;
|
|
|
|
devc->mqflags |= SR_MQFLAG_DURATION;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:51:18 +00:00
|
|
|
/**
|
|
|
|
* Decode range/sign/acdc byte special chars, Metrahit 18.
|
|
|
|
*
|
|
|
|
* @param[in] rs Rance/sign byte.
|
2013-11-21 14:47:09 +00:00
|
|
|
*/
|
2013-12-26 11:51:18 +00:00
|
|
|
static void decode_rs_18(uint8_t rs, struct dev_context *devc)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
|
|
|
int range;
|
|
|
|
|
|
|
|
/* Sign */
|
|
|
|
if (((devc->scale > 0) && (rs & 0x08)) ||
|
|
|
|
((devc->scale < 0) && !(rs & 0x08)))
|
|
|
|
devc->scale *= -1.0;
|
|
|
|
|
|
|
|
/* Range */
|
|
|
|
range = rs & 0x07;
|
|
|
|
switch (devc->mq) {
|
|
|
|
case SR_MQ_VOLTAGE:
|
|
|
|
if (devc->unit == SR_UNIT_DECIBEL_VOLT) {
|
|
|
|
devc->scale *= pow(10.0, -2);
|
2013-12-26 11:51:18 +00:00
|
|
|
/*
|
|
|
|
* When entering relative mode, the device switches
|
2013-11-21 14:47:09 +00:00
|
|
|
* from 10 byte to 6 byte msg format. Unfortunately
|
|
|
|
* it switches back to 10 byte when the second value
|
|
|
|
* is measured, so that's not sufficient to
|
|
|
|
* identify relative mode.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else if (devc->vmains_29S)
|
|
|
|
devc->scale *= pow(10.0, range - 2);
|
|
|
|
else
|
|
|
|
devc->scale *= pow(10.0, range - 5);
|
|
|
|
break;
|
|
|
|
case SR_MQ_CURRENT:
|
|
|
|
if (devc->scale1000 == -1)
|
|
|
|
devc->scale *= pow(10.0, range - 5);
|
|
|
|
else
|
|
|
|
devc->scale *= pow(10.0, range - 4);
|
|
|
|
break;
|
|
|
|
case SR_MQ_RESISTANCE:
|
|
|
|
devc->scale *= pow(10.0, range - 2);
|
|
|
|
break;
|
|
|
|
case SR_MQ_FREQUENCY:
|
|
|
|
devc->scale *= pow(10.0, range - 3);
|
|
|
|
break;
|
|
|
|
case SR_MQ_TEMPERATURE:
|
|
|
|
devc->scale *= pow(10.0, range - 2);
|
|
|
|
break;
|
|
|
|
case SR_MQ_CAPACITANCE:
|
|
|
|
devc->scale *= pow(10.0, range - 14);
|
|
|
|
break;
|
|
|
|
/* TODO: 29S Mains measurements. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:51:18 +00:00
|
|
|
/**
|
|
|
|
* Decode special chars, Metrahit 18.
|
|
|
|
*
|
|
|
|
* @param[in] spc Special characters 1 and 2 (s1 | (s2 << 4)).
|
2013-11-21 14:47:09 +00:00
|
|
|
*/
|
2013-12-26 11:51:18 +00:00
|
|
|
static void decode_spc_18(uint8_t spc, struct dev_context *devc)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
|
|
|
/* xxxx1xxx ZERO */
|
|
|
|
/* xxxxx1xx BEEP */
|
|
|
|
/* xxxxxx1x Low battery */
|
|
|
|
/* xxxxxxx1 Fuse */
|
|
|
|
|
|
|
|
if (devc->mq == SR_MQ_TIME) {
|
|
|
|
/* xxx1xxxx Clock running: 1; stop: 0 */
|
|
|
|
sr_spew("Clock running: %d", spc >> 4);
|
2013-12-26 11:51:18 +00:00
|
|
|
} else {
|
2013-11-21 14:47:09 +00:00
|
|
|
/* 1xxxxxxx MAN */
|
|
|
|
setmqf(devc, SR_MQFLAG_AUTORANGE, !(spc & 0x80));
|
|
|
|
|
|
|
|
/* x1xxxxxx MIN */
|
|
|
|
setmqf(devc, SR_MQFLAG_MIN, spc & 0x40);
|
|
|
|
|
|
|
|
/* xx1xxxxx MAX */
|
|
|
|
setmqf(devc, SR_MQFLAG_MAX, spc & 0x20);
|
|
|
|
|
|
|
|
/* xxx1xxxx DATA */
|
|
|
|
setmqf(devc, SR_MQFLAG_HOLD, spc & 0x10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:51:18 +00:00
|
|
|
/**
|
|
|
|
* Decode current type and measured value, Metrahit 2x.
|
|
|
|
*
|
|
|
|
* @param[in] ctmv Current type and measured value (v1 | (v2 << 4)).
|
2013-11-21 14:47:09 +00:00
|
|
|
*/
|
2013-12-26 11:51:18 +00:00
|
|
|
static void decode_ctmv_2x(uint8_t ctmv, struct dev_context *devc)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
|
|
|
if ((ctmv > 0x1c) || (!devc)) {
|
2013-12-26 11:51:18 +00:00
|
|
|
sr_err("decode_ctmv_2x(%d): invalid param(s)!", ctmv);
|
2013-11-21 14:47:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
devc->mq = 0;
|
|
|
|
devc->unit = 0;
|
|
|
|
devc->mqflags = 0;
|
|
|
|
|
|
|
|
switch (ctmv) {
|
|
|
|
/* 00000 unused */
|
|
|
|
case 0x01: /* 00001 V DC */
|
|
|
|
case 0x02: /* 00010 V AC+DC */
|
|
|
|
case 0x03: /* 00011 V AC */
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_VOLT;
|
|
|
|
if (ctmv <= 0x02)
|
|
|
|
devc->mqflags |= SR_MQFLAG_DC;
|
|
|
|
if (ctmv >= 0x02) {
|
|
|
|
devc->mqflags |= SR_MQFLAG_AC;
|
2013-12-26 12:02:02 +00:00
|
|
|
if (devc->model >= METRAHIT_24S)
|
2013-11-21 14:47:09 +00:00
|
|
|
devc->model |= SR_MQFLAG_RMS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x04: /* 00100 mA DC */
|
|
|
|
case 0x05: /* 00101 mA AC+DC */
|
|
|
|
devc->scale1000 = -1;
|
|
|
|
case 0x06: /* 00110 A DC */
|
|
|
|
case 0x07: /* 00111 A AC+DC */
|
|
|
|
devc->mq = SR_MQ_CURRENT;
|
|
|
|
devc->unit = SR_UNIT_AMPERE;
|
|
|
|
devc->mqflags |= SR_MQFLAG_DC;
|
|
|
|
if ((ctmv == 0x05) || (ctmv == 0x07)) {
|
|
|
|
devc->mqflags |= SR_MQFLAG_AC;
|
2013-12-26 12:02:02 +00:00
|
|
|
if (devc->model >= METRAHIT_24S)
|
2013-11-21 14:47:09 +00:00
|
|
|
devc->mqflags |= SR_MQFLAG_RMS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x08: /* 01000 Ohm */
|
|
|
|
devc->mq = SR_MQ_RESISTANCE;
|
|
|
|
devc->unit = SR_UNIT_OHM;
|
|
|
|
break;
|
|
|
|
case 0x09: /* 01001 F */
|
|
|
|
devc->mq = SR_MQ_CAPACITANCE;
|
|
|
|
devc->unit = SR_UNIT_FARAD;
|
|
|
|
devc->scale *= 0.1;
|
|
|
|
break;
|
|
|
|
case 0x0a: /* 01010 dB */
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_DECIBEL_VOLT;
|
|
|
|
devc->mqflags |= SR_MQFLAG_AC;
|
|
|
|
break;
|
|
|
|
case 0x0b: /* 01011 Hz U ACDC */
|
|
|
|
case 0x0c: /* 01100 Hz U AC */
|
|
|
|
devc->mq = SR_MQ_FREQUENCY;
|
|
|
|
devc->unit = SR_UNIT_HERTZ;
|
|
|
|
devc->mqflags |= SR_MQFLAG_AC;
|
|
|
|
if (ctmv <= 0x0b)
|
|
|
|
devc->mqflags |= SR_MQFLAG_DC;
|
|
|
|
break;
|
|
|
|
case 0x0d: /* 01101 W on power, mA range (29S only) */
|
|
|
|
case 0x0e: /* 01110 W on power, A range (29S only) */
|
|
|
|
/* TODO: Differences between Send Mode and bidir protocol here */
|
|
|
|
devc->mq = SR_MQ_POWER;
|
|
|
|
devc->unit = SR_UNIT_WATT;
|
|
|
|
break;
|
|
|
|
case 0x0f: /* 01111 Diode */
|
|
|
|
case 0x10: /* 10000 Diode with buzzer (actually cont. with voltage) */
|
|
|
|
devc->unit = SR_UNIT_VOLT;
|
|
|
|
if (ctmv == 0x0f) {
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->mqflags |= SR_MQFLAG_DIODE;
|
|
|
|
devc->scale *= 0.1;
|
2013-12-26 11:51:18 +00:00
|
|
|
} else {
|
2013-11-21 14:47:09 +00:00
|
|
|
devc->mq = SR_MQ_CONTINUITY;
|
|
|
|
devc->scale *= 0.00001;
|
|
|
|
}
|
|
|
|
devc->unit = SR_UNIT_VOLT;
|
|
|
|
break;
|
|
|
|
case 0x11: /* 10001 Ohm with buzzer */
|
|
|
|
devc->mq = SR_MQ_CONTINUITY;
|
|
|
|
devc->unit = SR_UNIT_OHM;
|
|
|
|
devc->scale1000 = -1;
|
|
|
|
break;
|
|
|
|
case 0x12: /* 10010 Temperature */
|
|
|
|
devc->mq = SR_MQ_TEMPERATURE;
|
|
|
|
devc->unit = SR_UNIT_CELSIUS;
|
|
|
|
/* This can be Fahrenheit. That is detected by range=4 later. */
|
|
|
|
break;
|
|
|
|
/* 0x13 10011, 0x14 10100 unsed */
|
|
|
|
case 0x15: /* 10101 Press (29S only) */
|
|
|
|
/* TODO: What does that mean? Possibly phase shift?
|
|
|
|
Then we need a unit/flag for it. */
|
|
|
|
devc->mq = SR_MQ_GAIN;
|
|
|
|
devc->unit = SR_UNIT_PERCENTAGE;
|
|
|
|
break;
|
|
|
|
case 0x16: /* 10110 Pulse W (29S only) */
|
|
|
|
/* TODO: Own unit and flag for this! */
|
|
|
|
devc->mq = SR_MQ_POWER;
|
|
|
|
devc->unit = SR_UNIT_WATT;
|
|
|
|
break;
|
|
|
|
case 0x17: /* 10111 TRMS V on mains (29S only) */
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_VOLT;
|
|
|
|
devc->mqflags |= (SR_MQFLAG_AC | SR_MQFLAG_RMS);
|
|
|
|
devc->vmains_29S = TRUE;
|
|
|
|
break;
|
|
|
|
case 0x18: /* 11000 Counter (zero crossings of a signal) */
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_UNITLESS;
|
|
|
|
break;
|
|
|
|
case 0x19: /* 11001 Events U ACDC */
|
|
|
|
case 0x1a: /* 11010 Events U AC */
|
|
|
|
/* TODO: No unit or flags for this yet! */
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_UNITLESS;
|
|
|
|
devc->mqflags |= SR_MQFLAG_AC;
|
|
|
|
if (ctmv <= 0x19)
|
|
|
|
devc->mqflags |= SR_MQFLAG_DC;
|
|
|
|
break;
|
|
|
|
case 0x1b: /* 11011 pulse on mains (29S only) */
|
|
|
|
/* TODO: No unit or flags for this yet! */
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_UNITLESS;
|
|
|
|
devc->mqflags |= SR_MQFLAG_AC;
|
|
|
|
break;
|
|
|
|
case 0x1c: /* 11100 dropout on mains (29S only) */
|
|
|
|
/* TODO: No unit or flags for this yet! */
|
|
|
|
devc->mq = SR_MQ_VOLTAGE;
|
|
|
|
devc->unit = SR_UNIT_UNITLESS;
|
|
|
|
devc->mqflags |= SR_MQFLAG_AC;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sr_err("decode_ctmv_2x(%d, ...): Unknown ctmv!");
|
2013-12-26 11:51:18 +00:00
|
|
|
break;
|
2013-11-21 14:47:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:51:18 +00:00
|
|
|
/**
|
|
|
|
* Decode range/sign/acdc byte special chars, Metrahit 2x.
|
|
|
|
*
|
|
|
|
* @param[in] rs Rance/sign byte.
|
2013-11-21 14:47:09 +00:00
|
|
|
*/
|
2013-12-26 11:51:18 +00:00
|
|
|
static void decode_rs_2x(uint8_t rs, struct dev_context *devc)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
2013-12-26 11:51:18 +00:00
|
|
|
int range;
|
2013-11-21 14:47:09 +00:00
|
|
|
|
|
|
|
/* Sign */
|
|
|
|
if (((devc->scale > 0) && (rs & 0x08)) ||
|
|
|
|
((devc->scale < 0) && !(rs & 0x08)))
|
|
|
|
devc->scale *= -1.0;
|
|
|
|
|
|
|
|
/* Range */
|
|
|
|
range = rs & 0x07;
|
|
|
|
switch (devc->mq) {
|
|
|
|
case SR_MQ_VOLTAGE:
|
2013-12-26 11:51:18 +00:00
|
|
|
if (devc->unit == SR_UNIT_DECIBEL_VOLT)
|
2013-11-21 14:47:09 +00:00
|
|
|
devc->scale *= pow(10.0, -3);
|
|
|
|
else if (devc->vmains_29S)
|
|
|
|
devc->scale *= pow(10.0, range - 2);
|
|
|
|
else if(devc->mqflags & SR_MQFLAG_AC)
|
|
|
|
devc->scale *= pow(10.0, range - 6);
|
|
|
|
else /* "Undocumented feature": Between AC and DC
|
|
|
|
scaling differs by 1. */
|
|
|
|
devc->scale *= pow(10.0, range - 5);
|
|
|
|
break;
|
|
|
|
case SR_MQ_CURRENT:
|
|
|
|
if (devc->scale1000 == -1)
|
|
|
|
devc->scale *= pow(10.0, range - 5);
|
|
|
|
else
|
|
|
|
devc->scale *= pow(10.0, range - 4);
|
|
|
|
break;
|
|
|
|
case SR_MQ_RESISTANCE:
|
|
|
|
devc->scale *= pow(10.0, range - 3);
|
|
|
|
break;
|
|
|
|
case SR_MQ_FREQUENCY:
|
|
|
|
devc->scale *= pow(10.0, range - 3);
|
|
|
|
break;
|
|
|
|
case SR_MQ_TEMPERATURE:
|
2013-12-26 11:51:18 +00:00
|
|
|
if (range == 4) /* Indicator for °F */
|
2013-11-21 14:47:09 +00:00
|
|
|
devc->unit = SR_UNIT_FAHRENHEIT;
|
|
|
|
devc->scale *= pow(10.0, - 2);
|
|
|
|
break;
|
|
|
|
case SR_MQ_CAPACITANCE:
|
|
|
|
devc->scale *= pow(10.0, range - 13);
|
|
|
|
break;
|
|
|
|
/* TODO: 29S Mains measurements. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:51:18 +00:00
|
|
|
/**
|
|
|
|
* Decode special chars (Metrahit 2x).
|
|
|
|
*
|
|
|
|
* @param[in] spc Special characters 1 and 2 (s1 | (s2 << 4)).
|
2013-11-21 14:47:09 +00:00
|
|
|
*/
|
2013-12-26 11:51:18 +00:00
|
|
|
static void decode_spc_2x(uint8_t spc, struct dev_context *devc)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
|
|
|
/* xxxxxxx1 Fuse */
|
|
|
|
|
|
|
|
/* xxxxxx1x Low battery */
|
|
|
|
|
|
|
|
/* xxxxx1xx BEEP */
|
|
|
|
|
|
|
|
/* xxxx1xxx ZERO */
|
|
|
|
|
|
|
|
/* xxx1xxxx DATA */
|
|
|
|
setmqf(devc, SR_MQFLAG_HOLD, spc & 0x10);
|
|
|
|
|
|
|
|
/* x11xxxxx unused */
|
|
|
|
/* 1xxxxxxx MAN */
|
|
|
|
setmqf(devc, SR_MQFLAG_AUTORANGE, !(spc & 0x80));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Clean range and sign. */
|
|
|
|
static void clean_rs_v(struct dev_context *devc)
|
|
|
|
{
|
|
|
|
devc->value = 0.0;
|
|
|
|
devc->scale = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Clean current type, measured variable, range and sign. */
|
|
|
|
static void clean_ctmv_rs_v(struct dev_context *devc)
|
|
|
|
{
|
|
|
|
devc->mq = 0;
|
|
|
|
devc->unit = 0;
|
|
|
|
devc->mqflags = 0;
|
|
|
|
devc->scale1000 = 0;
|
|
|
|
devc->vmains_29S = FALSE;
|
|
|
|
clean_rs_v(devc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Send prepared value. */
|
|
|
|
static void send_value(struct sr_dev_inst *sdi)
|
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
|
|
|
struct sr_datafeed_analog analog;
|
|
|
|
struct sr_datafeed_packet packet;
|
|
|
|
|
|
|
|
devc = sdi->priv;
|
|
|
|
|
|
|
|
memset(&analog, 0, sizeof(analog));
|
|
|
|
analog.probes = sdi->probes;
|
|
|
|
analog.num_samples = 1;
|
|
|
|
analog.mq = devc->mq;
|
|
|
|
analog.unit = devc->unit;
|
|
|
|
analog.mqflags = devc->mqflags;
|
|
|
|
analog.data = &devc->value;
|
|
|
|
|
|
|
|
memset(&packet, 0, sizeof(packet));
|
|
|
|
packet.type = SR_DF_ANALOG;
|
|
|
|
packet.payload = &analog;
|
|
|
|
sr_session_send(devc->cb_data, &packet);
|
|
|
|
|
|
|
|
devc->num_samples++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Process 6-byte data message, Metrahit 1x/2x. */
|
|
|
|
static void process_msg_dta_6(struct sr_dev_inst *sdi)
|
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
|
|
|
int cnt;
|
2013-12-26 11:51:18 +00:00
|
|
|
uint8_t dgt;
|
2013-11-21 14:47:09 +00:00
|
|
|
|
|
|
|
devc = sdi->priv;
|
|
|
|
clean_rs_v(devc);
|
|
|
|
|
|
|
|
/* Byte 0, range and sign */
|
2013-12-26 12:02:02 +00:00
|
|
|
if (devc->model <= METRAHIT_16X)
|
2013-11-21 14:47:09 +00:00
|
|
|
decode_rs_16(bc(devc->buf[0]), devc);
|
2013-12-26 12:02:02 +00:00
|
|
|
else if (devc->model < METRAHIT_2X)
|
2013-11-21 14:47:09 +00:00
|
|
|
decode_rs_18(bc(devc->buf[0]), devc);
|
2013-12-26 11:51:18 +00:00
|
|
|
else
|
2013-11-21 14:47:09 +00:00
|
|
|
decode_rs_2x(bc(devc->buf[0]), devc);
|
|
|
|
|
|
|
|
/* Bytes 1-5, digits (ls first). */
|
|
|
|
for (cnt = 0; cnt < 5; cnt++) {
|
|
|
|
dgt = bc(devc->buf[1 + cnt]);
|
|
|
|
if (dgt >= 10) {
|
|
|
|
/* 10 Overload; on model <= 16X also 11 possible. */
|
|
|
|
devc->value = NAN;
|
|
|
|
devc->scale = 1.0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
devc->value += pow(10.0, cnt) * dgt;
|
|
|
|
}
|
|
|
|
sr_spew("process_msg_dta_6() value=%f scale=%f scalet=%d",
|
|
|
|
devc->value, devc->scale, devc->scale1000);
|
|
|
|
if (devc->value != NAN)
|
|
|
|
devc->value *= devc->scale * pow(1000.0, devc->scale1000);
|
|
|
|
|
|
|
|
/* Create and send packet. */
|
|
|
|
send_value(sdi);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Process 5-byte info message, Metrahit 1x/2x. */
|
|
|
|
static void process_msg_inf_5(struct sr_dev_inst *sdi)
|
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
|
|
|
enum model model;
|
|
|
|
|
|
|
|
devc = sdi->priv;
|
|
|
|
|
|
|
|
clean_ctmv_rs_v(devc);
|
|
|
|
|
|
|
|
/* Process byte 0 */
|
2013-12-26 12:02:02 +00:00
|
|
|
model = gmc_decode_model_sm(bc(devc->buf[0]));
|
2013-11-21 14:47:09 +00:00
|
|
|
if (model != devc->model) {
|
|
|
|
sr_warn("Model mismatch in data: Detected %s, now %s",
|
2013-12-26 12:02:02 +00:00
|
|
|
gmc_model_str(devc->model), gmc_model_str(model));
|
2013-11-21 14:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process bytes 1-4 */
|
2013-12-26 12:02:02 +00:00
|
|
|
if (devc->model <= METRAHIT_16X) {
|
2013-11-21 14:47:09 +00:00
|
|
|
decode_ctmv_16(bc(devc->buf[1]), devc);
|
|
|
|
decode_spc_16(bc(devc->buf[2]) | (bc(devc->buf[3]) << 4), devc);
|
|
|
|
decode_rs_16(bc(devc->buf[4]), devc);
|
2013-12-26 12:02:02 +00:00
|
|
|
} else if (devc->model <= METRAHIT_18S) {
|
2013-11-21 14:47:09 +00:00
|
|
|
decode_ctmv_18(bc(devc->buf[1]), devc);
|
|
|
|
decode_spc_18(bc(devc->buf[2]) | (bc(devc->buf[3]) << 4), devc);
|
|
|
|
decode_rs_18(bc(devc->buf[4]), devc);
|
2013-12-26 11:51:18 +00:00
|
|
|
} else { /* Must be Metrahit 2x */
|
2013-11-21 14:47:09 +00:00
|
|
|
decode_ctmv_2x(bc(devc->buf[1]), devc);
|
|
|
|
decode_spc_2x(bc(devc->buf[2]) | (bc(devc->buf[3]) << 4), devc);
|
|
|
|
decode_rs_2x(bc(devc->buf[4]), devc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Process 10-byte info/data message, Metrahit 15+. */
|
|
|
|
static void process_msg_inf_10(struct sr_dev_inst *sdi)
|
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
|
|
|
int cnt;
|
2013-12-26 11:51:18 +00:00
|
|
|
uint8_t dgt;
|
2013-11-21 14:47:09 +00:00
|
|
|
|
|
|
|
devc = sdi->priv;
|
|
|
|
|
|
|
|
process_msg_inf_5(sdi);
|
|
|
|
|
|
|
|
/* Now decode numbers */
|
|
|
|
for (cnt = 0; cnt < 5; cnt++) {
|
|
|
|
dgt = bc(devc->buf[5 + cnt]);
|
|
|
|
if (dgt >= 10) { /* Overload */
|
|
|
|
devc->value = NAN;
|
|
|
|
devc->scale = 1.0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
devc->value += pow(10.0, cnt) * dgt;
|
|
|
|
}
|
|
|
|
sr_spew("process_msg_inf_10() value=%f scale=%f scalet=%d",
|
|
|
|
devc->value, devc->scale, devc->scale1000);
|
|
|
|
|
|
|
|
if (devc->value != NAN)
|
|
|
|
devc->value *= devc->scale * pow(1000.0, devc->scale1000);
|
|
|
|
|
|
|
|
/* Create and send packet. */
|
|
|
|
send_value(sdi);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Decode send interval (Metrahit 2x only). */
|
2013-12-26 11:51:18 +00:00
|
|
|
static const char *decode_send_interval(uint8_t si)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
|
|
|
switch (si) {
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x00:
|
|
|
|
return "0.05";
|
|
|
|
case 0x01:
|
|
|
|
return "0.1";
|
|
|
|
case 0x02:
|
|
|
|
return "0.2";
|
|
|
|
case 0x03:
|
|
|
|
return "0.5";
|
|
|
|
case 0x04:
|
|
|
|
return "00:01";
|
|
|
|
case 0x05:
|
|
|
|
return "00:02";
|
|
|
|
case 0x06:
|
|
|
|
return "00:05";
|
|
|
|
case 0x07:
|
|
|
|
return "00:10";
|
|
|
|
case 0x08:
|
|
|
|
return "00:20";
|
|
|
|
case 0x09:
|
|
|
|
return "00:30";
|
|
|
|
case 0x0a:
|
|
|
|
return "01:00";
|
|
|
|
case 0x0b:
|
|
|
|
return "02:00";
|
|
|
|
case 0x0c:
|
|
|
|
return "05:00";
|
|
|
|
case 0x0d:
|
|
|
|
return "10:00";
|
|
|
|
case 0x0e:
|
|
|
|
return "----";
|
|
|
|
case 0x0f:
|
|
|
|
return "data";
|
|
|
|
default:
|
|
|
|
return "Unknown value";
|
2013-11-21 14:47:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Process 13-byte info/data message, Metrahit 2x. */
|
|
|
|
static void process_msg_inf_13(struct sr_dev_inst *sdi)
|
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
|
|
|
enum model model;
|
|
|
|
int cnt;
|
2013-12-26 11:51:18 +00:00
|
|
|
uint8_t dgt;
|
2013-11-21 14:47:09 +00:00
|
|
|
|
|
|
|
devc = sdi->priv;
|
|
|
|
|
|
|
|
clean_ctmv_rs_v(devc);
|
|
|
|
|
|
|
|
/* Byte 0, model. */
|
2013-12-26 12:02:02 +00:00
|
|
|
model = gmc_decode_model_sm(bc(devc->buf[0]));
|
2013-11-21 14:47:09 +00:00
|
|
|
if (model != devc->model) {
|
|
|
|
sr_warn("Model mismatch in data: Detected %s, now %s",
|
2013-12-26 12:02:02 +00:00
|
|
|
gmc_model_str(devc->model), gmc_model_str(model));
|
2013-11-21 14:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Bytes 1-4, 11. */
|
|
|
|
decode_ctmv_2x(bc(devc->buf[1]) | (bc(devc->buf[11]) << 4), devc);
|
|
|
|
decode_spc_2x(bc(devc->buf[2]) | (bc(devc->buf[3]) << 4), devc);
|
|
|
|
decode_rs_2x(bc(devc->buf[4]), devc);
|
|
|
|
|
|
|
|
/* Bytes 5-10, digits (ls first). */
|
|
|
|
for (cnt = 0; cnt < 6; cnt++) {
|
|
|
|
dgt = bc(devc->buf[5 + cnt]);
|
|
|
|
if (dgt == 10) { /* Overload */
|
|
|
|
devc->value = NAN;
|
|
|
|
devc->scale = 1.0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
devc->value += pow(10.0, cnt) * dgt;
|
|
|
|
}
|
|
|
|
sr_spew("process_msg_inf_13() value=%f scale=%f scale1000=%d mq=%d "
|
|
|
|
"unit=%d mqflags=0x%02llx", devc->value, devc->scale,
|
|
|
|
devc->scale1000, devc->mq, devc->unit, devc->mqflags);
|
|
|
|
if (devc->value != NAN)
|
|
|
|
devc->value *= devc->scale * pow(1000.0, devc->scale1000);
|
|
|
|
|
|
|
|
/* Byte 12, Send Interval */
|
|
|
|
sr_spew("Send interval: %s", decode_send_interval(bc(devc->buf[12])));
|
|
|
|
|
|
|
|
/* Create and send packet. */
|
|
|
|
send_value(sdi);
|
|
|
|
}
|
|
|
|
|
2013-11-19 16:49:23 +00:00
|
|
|
SR_PRIV int gmc_mh_1x_2x_receive_data(int fd, int revents, void *cb_data)
|
|
|
|
{
|
2013-11-21 14:47:09 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
2013-11-19 16:49:23 +00:00
|
|
|
struct dev_context *devc;
|
2013-11-21 14:47:09 +00:00
|
|
|
struct sr_serial_dev_inst *serial;
|
2013-12-26 11:51:18 +00:00
|
|
|
uint8_t buf, msgt;
|
2013-11-21 14:47:09 +00:00
|
|
|
int len;
|
2013-12-26 11:51:18 +00:00
|
|
|
gdouble elapsed_s;
|
2013-11-19 16:49:23 +00:00
|
|
|
|
|
|
|
(void)fd;
|
|
|
|
|
|
|
|
if (!(sdi = cb_data))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!(devc = sdi->priv))
|
|
|
|
return TRUE;
|
|
|
|
|
2013-11-21 14:47:09 +00:00
|
|
|
serial = sdi->conn;
|
|
|
|
|
|
|
|
if (revents == G_IO_IN) { /* Serial data arrived. */
|
|
|
|
while (GMC_BUFSIZE - devc->buflen - 1 > 0) {
|
|
|
|
len = serial_read(serial, devc->buf + devc->buflen, 1);
|
|
|
|
if (len < 1)
|
|
|
|
break;
|
|
|
|
buf = *(devc->buf + devc->buflen);
|
|
|
|
sr_spew("read 0x%02x/%d/%d", buf, buf, buf & MSGC_MASK);
|
|
|
|
devc->buflen += len;
|
|
|
|
if (!devc->settings_ok) {
|
2013-12-26 11:51:18 +00:00
|
|
|
/*
|
|
|
|
* If no device type/settings record processed
|
|
|
|
* yet, wait for one.
|
|
|
|
*/
|
2013-11-21 14:47:09 +00:00
|
|
|
if ((devc->buf[0] & MSGID_MASK) != MSGID_INF) {
|
|
|
|
devc->buflen = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
devc->settings_ok = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
msgt = devc->buf[0] & MSGID_MASK;
|
|
|
|
switch (msgt) {
|
|
|
|
case MSGID_INF:
|
|
|
|
if (devc->buflen == 13) {
|
|
|
|
process_msg_inf_13(sdi);
|
|
|
|
devc->buflen = 0;
|
|
|
|
continue;
|
2013-12-26 11:51:18 +00:00
|
|
|
} else if ((devc->buflen == 10) &&
|
2013-12-26 12:02:02 +00:00
|
|
|
(devc->model <= METRAHIT_18S)) {
|
2013-11-21 14:47:09 +00:00
|
|
|
process_msg_inf_10(sdi);
|
|
|
|
devc->buflen = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if ((devc->buflen >= 5) &&
|
2013-12-26 11:51:18 +00:00
|
|
|
(devc->buf[devc->buflen - 1] &
|
2013-11-21 14:47:09 +00:00
|
|
|
MSGID_MASK) != MSGID_DATA) {
|
2013-12-26 11:51:18 +00:00
|
|
|
/*
|
|
|
|
* Char just received is beginning
|
|
|
|
* of next message.
|
|
|
|
*/
|
2013-11-21 14:47:09 +00:00
|
|
|
process_msg_inf_5(sdi);
|
2013-12-26 11:51:18 +00:00
|
|
|
devc->buf[0] =
|
|
|
|
devc->buf[devc->buflen - 1];
|
2013-11-21 14:47:09 +00:00
|
|
|
devc->buflen = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MSGID_DTA:
|
|
|
|
case MSGID_D10:
|
|
|
|
if (devc->buflen == 6) {
|
|
|
|
process_msg_dta_6(sdi);
|
|
|
|
devc->buflen = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MSGID_DATA:
|
|
|
|
sr_err("Comm error, unexpected data byte!");
|
|
|
|
devc->buflen = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If number of samples or time limit reached, stop aquisition. */
|
2013-12-26 11:51:18 +00:00
|
|
|
if (devc->limit_samples && (devc->num_samples >= devc->limit_samples))
|
2013-11-21 14:47:09 +00:00
|
|
|
sdi->driver->dev_acquisition_stop(sdi, cb_data);
|
|
|
|
|
|
|
|
if (devc->limit_msec) {
|
2013-12-26 11:51:18 +00:00
|
|
|
elapsed_s = g_timer_elapsed(devc->elapsed_msec, NULL);
|
|
|
|
if ((elapsed_s * 1000) >= devc->limit_msec)
|
2013-11-21 14:47:09 +00:00
|
|
|
sdi->driver->dev_acquisition_stop(sdi, cb_data);
|
2013-11-19 16:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-11-21 14:47:09 +00:00
|
|
|
|
2013-12-26 11:51:18 +00:00
|
|
|
/** Decode model in "send mode". */
|
2013-12-26 12:02:02 +00:00
|
|
|
SR_PRIV int gmc_decode_model_sm(uint8_t mcode)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
|
|
|
if (mcode > 0xf) {
|
|
|
|
sr_err("decode_model(%d): Model code 0..15 expected!", mcode);
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_NONE;
|
2013-11-21 14:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(mcode) {
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x04: /* 0100b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_12S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x08: /* 1000b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_13S14A;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x09: /* 1001b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_14S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x0A: /* 1010b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_15S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x0B: /* 1011b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_16S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x06: /* 0110b (undocumented by GMC!) */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_16I;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x0D: /* 1101b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_18S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x02: /* 0010b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_22SM;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x03: /* 0011b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_23S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x0f: /* 1111b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_24S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x05: /* 0101b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_25SM;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x01: /* 0001b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_26S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x0c: /* 1100b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_28S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 0x0e: /* 1110b */
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_29S;
|
2013-11-21 14:47:09 +00:00
|
|
|
default:
|
|
|
|
sr_err("Unknown model code %d!", mcode);
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_NONE;
|
2013-11-21 14:47:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:51:18 +00:00
|
|
|
/**
|
|
|
|
* Decode model in bidirectional mode.
|
|
|
|
*
|
|
|
|
* @param[in] mcode Model code.
|
|
|
|
*
|
|
|
|
* @return Model code.
|
|
|
|
*/
|
2013-12-26 12:02:02 +00:00
|
|
|
SR_PRIV int gmc_decode_model_bidi(uint8_t mcode)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
2013-12-26 11:51:18 +00:00
|
|
|
switch (mcode) {
|
|
|
|
case 2:
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_22SM;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 3:
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_23S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 4:
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_24S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 5:
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_25SM;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 1:
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_26S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 12:
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_28S;
|
2013-12-26 11:51:18 +00:00
|
|
|
case 14:
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_29S;
|
2013-11-21 14:47:09 +00:00
|
|
|
default:
|
|
|
|
sr_err("Unknown model code %d!", mcode);
|
2013-12-26 12:02:02 +00:00
|
|
|
return METRAHIT_NONE;
|
2013-11-21 14:47:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:02:02 +00:00
|
|
|
SR_PRIV const char *gmc_model_str(enum model mcode)
|
2013-11-21 14:47:09 +00:00
|
|
|
{
|
|
|
|
switch (mcode) {
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_NONE:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "-uninitialized model variable-";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_12S:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 12S";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_13S14A:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 13S/14A";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_14S:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 14S";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_15S:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 15S";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_16S:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 16S";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_16I:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 16I";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_18S:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 18S";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_22SM:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 22S/M";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_23S:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 23S";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_24S:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 24S";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_25SM:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 25S/M";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_26S:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 26S";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_28S:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 28S";
|
2013-12-26 12:02:02 +00:00
|
|
|
case METRAHIT_29S:
|
2013-11-21 14:47:09 +00:00
|
|
|
return "METRAHit 29S";
|
|
|
|
default:
|
|
|
|
return "Unknown model code";
|
|
|
|
}
|
|
|
|
}
|