tekpower-dmm: Cosmetics, coding-style, consistency fixes.
This commit is contained in:
parent
7dc55d930f
commit
bbabddbd64
|
@ -189,7 +189,7 @@ if test "x$HW_RADIOSHACK_DMM" = "xyes"; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_ARG_ENABLE(tekpower-dmm, AC_HELP_STRING([--enable-tekpower-dmm],
|
AC_ARG_ENABLE(tekpower-dmm, AC_HELP_STRING([--enable-tekpower-dmm],
|
||||||
[enable Tekpower DMM support. [default=yes]]),
|
[enable TekPower DMM support [default=yes]]),
|
||||||
[HW_TEKPOWER_DMM="$enableval"],
|
[HW_TEKPOWER_DMM="$enableval"],
|
||||||
[HW_TEKPOWER_DMM=yes])
|
[HW_TEKPOWER_DMM=yes])
|
||||||
AM_CONDITIONAL(HW_TEKPOWER_DMM, test x$HW_TEKPOWER_DMM = xyes)
|
AM_CONDITIONAL(HW_TEKPOWER_DMM, test x$HW_TEKPOWER_DMM = xyes)
|
||||||
|
@ -380,7 +380,7 @@ echo " - Hantek DSO...................... $HW_HANTEK_DSO"
|
||||||
echo " - Link MSO-19..................... $LA_LINK_MSO19"
|
echo " - Link MSO-19..................... $LA_LINK_MSO19"
|
||||||
echo " - Openbench Logic Sniffer......... $LA_OLS"
|
echo " - Openbench Logic Sniffer......... $LA_OLS"
|
||||||
echo " - Radioshack DMM.................. $HW_RADIOSHACK_DMM"
|
echo " - Radioshack DMM.................. $HW_RADIOSHACK_DMM"
|
||||||
echo " - Tekpower DMM.................... $HW_TEKPOWER_DMM"
|
echo " - TekPower DMM.................... $HW_TEKPOWER_DMM"
|
||||||
echo " - ZEROPLUS Logic Cube............. $LA_ZEROPLUS_LOGIC_CUBE"
|
echo " - ZEROPLUS Logic Cube............. $LA_ZEROPLUS_LOGIC_CUBE"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include "libsigrok.h"
|
|
||||||
#include "libsigrok-internal.h"
|
|
||||||
#include "protocol.h"
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include "libsigrok.h"
|
||||||
|
#include "libsigrok-internal.h"
|
||||||
|
#include "protocol.h"
|
||||||
|
|
||||||
static const int hwopts[] = {
|
static const int hwopts[] = {
|
||||||
SR_HWOPT_CONN,
|
SR_HWOPT_CONN,
|
||||||
|
@ -46,8 +46,8 @@ static const char *probe_names[] = {
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
SR_PRIV struct sr_dev_driver tekpower_driver_info;
|
SR_PRIV struct sr_dev_driver tekpower_dmm_driver_info;
|
||||||
static struct sr_dev_driver *di = &tekpower_driver_info;
|
static struct sr_dev_driver *di = &tekpower_dmm_driver_info;
|
||||||
|
|
||||||
/* Properly close and free all devices. */
|
/* Properly close and free all devices. */
|
||||||
static int clear_instances(void)
|
static int clear_instances(void)
|
||||||
|
@ -80,8 +80,8 @@ static int hw_init(void)
|
||||||
struct drv_context *drvc;
|
struct drv_context *drvc;
|
||||||
|
|
||||||
if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
|
if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
|
||||||
sr_err("driver context malloc failed.");
|
sr_err("Driver context malloc failed.");
|
||||||
return SR_ERR;
|
return SR_ERR_MALLOC;
|
||||||
}
|
}
|
||||||
|
|
||||||
di->priv = drvc;
|
di->priv = drvc;
|
||||||
|
@ -89,7 +89,7 @@ static int hw_init(void)
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int serial_readline(int fd, char **buf, size_t *buflen,
|
static int serial_readline(int fd, char **buf, int *buflen,
|
||||||
uint64_t timeout_ms)
|
uint64_t timeout_ms)
|
||||||
{
|
{
|
||||||
uint64_t start;
|
uint64_t start;
|
||||||
|
@ -129,38 +129,37 @@ static GSList *lcd14_scan(const char *conn, const char *serialcomm)
|
||||||
struct drv_context *drvc;
|
struct drv_context *drvc;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct sr_probe *probe;
|
struct sr_probe *probe;
|
||||||
|
struct lcd14_packet *packet;
|
||||||
GSList *devices;
|
GSList *devices;
|
||||||
int fd, retry;
|
int i, len, fd, retry, good_packets = 0, dropped, ret;
|
||||||
size_t len;
|
|
||||||
char buf[128], *b;
|
char buf[128], *b;
|
||||||
|
|
||||||
if ((fd = serial_open(conn, O_RDONLY | O_NONBLOCK)) == -1) {
|
if ((fd = serial_open(conn, O_RDONLY | O_NONBLOCK)) == -1) {
|
||||||
sr_err("unable to open %s: %s",
|
sr_err("Unable to open %s: %s.", conn, strerror(errno));
|
||||||
conn, strerror(errno));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (serial_set_paramstr(fd, serialcomm) != SR_OK) {
|
if ((ret = serial_set_paramstr(fd, serialcomm)) != SR_OK) {
|
||||||
sr_err("unable to set serial parameters");
|
sr_err("Unable to set serial parameters: %d", ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sr_info("probing port %s readonly", conn);
|
sr_info("Probing port %s readonly.", conn);
|
||||||
|
|
||||||
drvc = di->priv;
|
drvc = di->priv;
|
||||||
b = buf;
|
b = buf;
|
||||||
retry = 0;
|
retry = 0;
|
||||||
devices = NULL;
|
devices = NULL;
|
||||||
serial_flush(fd);
|
serial_flush(fd);
|
||||||
/* There's no way to get an ID from the multimeter. It just sends data
|
|
||||||
* periodically, so the best we can do is check if the packets match the
|
/*
|
||||||
* expected format. */
|
* There's no way to get an ID from the multimeter. It just sends data
|
||||||
while (!devices && retry < 3)
|
* periodically, so the best we can do is check if the packets match
|
||||||
{
|
* the expected format.
|
||||||
size_t i;
|
*/
|
||||||
size_t good_packets = 0;
|
while (!devices && retry < 3) {
|
||||||
retry++;
|
retry++;
|
||||||
|
|
||||||
/* Let's get a bit of data and see if we can find a packet */
|
/* Let's get a bit of data and see if we can find a packet. */
|
||||||
len = sizeof(buf);
|
len = sizeof(buf);
|
||||||
serial_readline(fd, &b, &len, 500);
|
serial_readline(fd, &b, &len, 500);
|
||||||
if ((len == 0) || (len < LCD14_PACKET_SIZE)) {
|
if ((len == 0) || (len < LCD14_PACKET_SIZE)) {
|
||||||
|
@ -170,10 +169,8 @@ static GSList *lcd14_scan(const char *conn, const char *serialcomm)
|
||||||
|
|
||||||
/* Let's treat our buffer like a stream, and find any
|
/* Let's treat our buffer like a stream, and find any
|
||||||
* valid packets */
|
* valid packets */
|
||||||
for( i = 0; i < len - LCD14_PACKET_SIZE + 1;
|
for (i = 0; i < len - LCD14_PACKET_SIZE + 1;) {
|
||||||
/* don't increment i here */ )
|
packet = (void *)(&buf[i]);
|
||||||
{
|
|
||||||
const lcd14_packet *packet = (void *)(&buf[i]);
|
|
||||||
if (!lcd14_is_packet_valid(packet, NULL)) {
|
if (!lcd14_is_packet_valid(packet, NULL)) {
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -182,27 +179,28 @@ static GSList *lcd14_scan(const char *conn, const char *serialcomm)
|
||||||
i += LCD14_PACKET_SIZE;
|
i += LCD14_PACKET_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we dropped more than two packets worth of data, something
|
/*
|
||||||
* is wrong */
|
* If we dropped more than two packets worth of data,
|
||||||
size_t dropped = len - (good_packets * LCD14_PACKET_SIZE);
|
* something is wrong.
|
||||||
|
*/
|
||||||
|
dropped = len - (good_packets * LCD14_PACKET_SIZE);
|
||||||
if (dropped > 2 * LCD14_PACKET_SIZE)
|
if (dropped > 2 * LCD14_PACKET_SIZE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Let's see if we have anything good */
|
/* Let's see if we have anything good. */
|
||||||
if (good_packets == 0)
|
if (good_packets == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sr_info("found device on port %s", conn);
|
sr_info("Found device on port %s.", conn);
|
||||||
|
|
||||||
if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "TekPower",
|
if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "TekPower",
|
||||||
"TP4000ZC", "")))
|
"TP4000ZC", "")))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
|
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
|
||||||
sr_dbg("failed to malloc devc");
|
sr_err("Device context malloc failed.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* devc->profile = RADIOSHACK_22_812; */
|
|
||||||
devc->serial = sr_serial_dev_inst_new(conn, -1);
|
devc->serial = sr_serial_dev_inst_new(conn, -1);
|
||||||
devc->serialcomm = g_strdup(serialcomm);
|
devc->serialcomm = g_strdup(serialcomm);
|
||||||
|
|
||||||
|
@ -245,7 +243,7 @@ static GSList *hw_scan(GSList *options)
|
||||||
/* Use the provided comm specs. */
|
/* Use the provided comm specs. */
|
||||||
devices = lcd14_scan(conn, serialcomm);
|
devices = lcd14_scan(conn, serialcomm);
|
||||||
} else {
|
} else {
|
||||||
/* Then try the default 2400 8n1 */
|
/* Try the default 2400/8n1. */
|
||||||
devices = lcd14_scan(conn, "2400/8n1");
|
devices = lcd14_scan(conn, "2400/8n1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,6 +261,7 @@ static GSList *hw_dev_list(void)
|
||||||
|
|
||||||
static int hw_dev_open(struct sr_dev_inst *sdi)
|
static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
|
||||||
if (!(devc = sdi->priv)) {
|
if (!(devc = sdi->priv)) {
|
||||||
|
@ -272,12 +271,13 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
|
|
||||||
devc->serial->fd = serial_open(devc->serial->port, O_RDONLY);
|
devc->serial->fd = serial_open(devc->serial->port, O_RDONLY);
|
||||||
if (devc->serial->fd == -1) {
|
if (devc->serial->fd == -1) {
|
||||||
sr_err("Couldn't open serial port '%s'.",
|
sr_err("Couldn't open serial port '%s'.", devc->serial->port);
|
||||||
devc->serial->port);
|
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
if (serial_set_paramstr(devc->serial->fd, devc->serialcomm) != SR_OK) {
|
|
||||||
sr_err("unable to set serial parameters");
|
ret = serial_set_paramstr(devc->serial->fd, devc->serialcomm);
|
||||||
|
if (ret != SR_OK) {
|
||||||
|
sr_err("Unable to set serial parameters: %d.", ret);
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
sdi->status = SR_ST_ACTIVE;
|
sdi->status = SR_ST_ACTIVE;
|
||||||
|
@ -313,7 +313,7 @@ static int hw_cleanup(void)
|
||||||
static int hw_info_get(int info_id, const void **data,
|
static int hw_info_get(int info_id, const void **data,
|
||||||
const struct sr_dev_inst *sdi)
|
const struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
(void)sdi; /* Does nothing. prevents "unused parameter" warning */
|
(void)sdi;
|
||||||
|
|
||||||
switch (info_id) {
|
switch (info_id) {
|
||||||
case SR_DI_HWOPTS:
|
case SR_DI_HWOPTS:
|
||||||
|
@ -380,9 +380,11 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
|
|
||||||
devc->cb_data = cb_data;
|
devc->cb_data = cb_data;
|
||||||
|
|
||||||
/* Reset the number of samples to take. If we've already collected our
|
/*
|
||||||
|
* Reset the number of samples to take. If we've already collected our
|
||||||
* quota, but we start a new session, and don't reset this, we'll just
|
* quota, but we start a new session, and don't reset this, we'll just
|
||||||
* quit without aquiring any new samples */
|
* quit without acquiring any new samples.
|
||||||
|
*/
|
||||||
devc->num_samples = 0;
|
devc->num_samples = 0;
|
||||||
|
|
||||||
/* Send header packet to the session bus. */
|
/* Send header packet to the session bus. */
|
||||||
|
@ -400,9 +402,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
meta.num_probes = 1;
|
meta.num_probes = 1;
|
||||||
sr_session_send(devc->cb_data, &packet);
|
sr_session_send(devc->cb_data, &packet);
|
||||||
|
|
||||||
/* Poll every 100ms, or whenever some data comes in. */
|
/* Poll every 50ms, or whenever some data comes in. */
|
||||||
sr_source_add(devc->serial->fd, G_IO_IN, 50,
|
sr_source_add(devc->serial->fd, G_IO_IN, 50,
|
||||||
lcd14_receive_data, (void *)sdi );
|
tekpower_dmm_receive_data, (void *)sdi);
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
@ -434,9 +436,9 @@ static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
SR_PRIV struct sr_dev_driver tekpower_driver_info = {
|
SR_PRIV struct sr_dev_driver tekpower_dmm_driver_info = {
|
||||||
.name = "tekpower-dmm",
|
.name = "tekpower-dmm",
|
||||||
.longname = "TekPower/Digitek 4000ZC",
|
.longname = "TekPower/Digitek TP4000ZC/DT4000ZC DMM",
|
||||||
.api_version = 1,
|
.api_version = 1,
|
||||||
.init = hw_init,
|
.init = hw_init,
|
||||||
.cleanup = hw_cleanup,
|
.cleanup = hw_cleanup,
|
||||||
|
|
|
@ -18,33 +18,32 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include "libsigrok.h"
|
|
||||||
#include "libsigrok-internal.h"
|
|
||||||
#include "config.h"
|
|
||||||
#include "protocol.h"
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include "libsigrok.h"
|
||||||
|
#include "libsigrok-internal.h"
|
||||||
|
#include "protocol.h"
|
||||||
|
|
||||||
|
static gboolean lcd14_is_sync_valid(const struct lcd14_packet *packet)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
uint8_t sync;
|
||||||
|
|
||||||
static gboolean lcd14_is_sync_valid(const lcd14_packet *packet)
|
/* Check the syncronization nibbles, and make sure they all match. */
|
||||||
{
|
for (i = 0; i < LCD14_PACKET_SIZE; i++) {
|
||||||
size_t i;
|
sync = (packet->raw[i] & LCD14_SYNC_MASK) >> 4;
|
||||||
/* Check the syncronization nibbles, and make sure they all match */
|
|
||||||
for(i = 0; i < LCD14_PACKET_SIZE; i++)
|
|
||||||
{
|
|
||||||
uint8_t sync = (packet->raw[i] & LCD14_SYNC_MASK) >> 4;
|
|
||||||
if (sync != (i + 1))
|
if (sync != (i + 1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean lcd14_is_selection_good(const lcd14_data *data)
|
static gboolean lcd14_is_selection_good(const struct lcd14_data *data)
|
||||||
{
|
{
|
||||||
int n_postfix = 0;
|
int n_postfix = 0, n_type = 0;
|
||||||
int n_type = 0;
|
|
||||||
/* Does the packet have more than one multiplier? */
|
/* Does the packet have more than one multiplier? */
|
||||||
if (data->flags & LCD14_NANO)
|
if (data->flags & LCD14_NANO)
|
||||||
n_postfix++;
|
n_postfix++;
|
||||||
|
@ -75,7 +74,7 @@ static gboolean lcd14_is_selection_good(const lcd14_data *data)
|
||||||
n_type++;
|
n_type++;
|
||||||
if (data->flags & LCD14_CELSIUS)
|
if (data->flags & LCD14_CELSIUS)
|
||||||
n_type++;
|
n_type++;
|
||||||
/* Do not test for hFE. hFE is not implemented and always '1' */
|
/* Do not test for hFE. hFE is not implemented and always '1'. */
|
||||||
if (n_type > 1)
|
if (n_type > 1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
@ -83,24 +82,24 @@ static gboolean lcd14_is_selection_good(const lcd14_data *data)
|
||||||
if ((data->flags & LCD14_AC) && (data->flags & LCD14_DC))
|
if ((data->flags & LCD14_AC) && (data->flags & LCD14_DC))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* OK, no duplicates */
|
/* OK, no duplicates. */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We "cook" a raw lcd14_pcaket into a more pallatable form, lcd14_data */
|
/* We "cook" a raw lcd14_pcaket into a more pallatable form, lcd14_data. */
|
||||||
static void lcd14_cook_raw(const lcd14_packet *packet, lcd14_data * data)
|
static void lcd14_cook_raw(const struct lcd14_packet *packet,
|
||||||
|
struct lcd14_data *data)
|
||||||
{
|
{
|
||||||
size_t i;
|
int i, j;
|
||||||
|
|
||||||
/* Get the digits out */
|
/* Get the digits out. */
|
||||||
for(i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++) {
|
||||||
{
|
j = (i << 1) + 1;
|
||||||
size_t j = (i << 1) + 1;
|
|
||||||
data->digit[i] = ((packet->raw[j] & ~LCD14_SYNC_MASK) << 4) |
|
data->digit[i] = ((packet->raw[j] & ~LCD14_SYNC_MASK) << 4) |
|
||||||
((packet->raw[j + 1] & ~LCD14_SYNC_MASK));
|
((packet->raw[j + 1] & ~LCD14_SYNC_MASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now extract the flags */
|
/* Now extract the flags. */
|
||||||
data->flags = ((packet->raw[0] & ~LCD14_SYNC_MASK) << 20) |
|
data->flags = ((packet->raw[0] & ~LCD14_SYNC_MASK) << 20) |
|
||||||
((packet->raw[9] & ~LCD14_SYNC_MASK) << 16) |
|
((packet->raw[9] & ~LCD14_SYNC_MASK) << 16) |
|
||||||
((packet->raw[10] & ~LCD14_SYNC_MASK) << 12) |
|
((packet->raw[10] & ~LCD14_SYNC_MASK) << 12) |
|
||||||
|
@ -109,20 +108,21 @@ static void lcd14_cook_raw(const lcd14_packet *packet, lcd14_data * data)
|
||||||
((packet->raw[13] & ~LCD14_SYNC_MASK));
|
((packet->raw[13] & ~LCD14_SYNC_MASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/* Since the DMM does not identify itslef in any way shape, or form, we really
|
* Since the DMM does not identify itself in any way shape, or form, we really
|
||||||
* don't know for sure who is sending the data. We must use every possible
|
* don't know for sure who is sending the data. We must use every possible
|
||||||
* check to filter out bad packets, especially since detection mechanism depends
|
* check to filter out bad packets, especially since the detection mechanism
|
||||||
* on how well we can filter out bad packets packets */
|
* depends on how well we can filter out bad packets packets.
|
||||||
SR_PRIV gboolean lcd14_is_packet_valid(const lcd14_packet *packet,
|
*/
|
||||||
lcd14_data *data)
|
SR_PRIV gboolean lcd14_is_packet_valid(const struct lcd14_packet *packet,
|
||||||
|
struct lcd14_data *data)
|
||||||
{
|
{
|
||||||
/* Callers not interested in the data, pass NULL */
|
struct lcd14_data placeholder;
|
||||||
lcd14_data placeholder;
|
|
||||||
|
/* Callers not interested in the data, pass NULL. */
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
data = &placeholder;
|
data = &placeholder;
|
||||||
/* We start with our syncronization nibbles, then move to more advanced
|
|
||||||
* checks */
|
|
||||||
if (!lcd14_is_sync_valid(packet))
|
if (!lcd14_is_sync_valid(packet))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
@ -131,16 +131,16 @@ SR_PRIV gboolean lcd14_is_packet_valid(const lcd14_packet *packet,
|
||||||
if (!lcd14_is_selection_good(data))
|
if (!lcd14_is_selection_good(data))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Made it here, huh? Then this looks to be a valid packet */
|
/* If we made it here, this looks to be a valid packet. */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t lcd14_to_digit(uint8_t raw_digit)
|
static uint8_t lcd14_to_digit(uint8_t raw_digit)
|
||||||
{
|
{
|
||||||
/* Take out the decimal point, so we can use a simple switch() */
|
/* Take out the decimal point, so we can use a simple switch(). */
|
||||||
raw_digit &= ~LCD14_DP_MASK;
|
raw_digit &= ~LCD14_DP_MASK;
|
||||||
switch(raw_digit)
|
|
||||||
{
|
switch (raw_digit) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
case LCD14_LCD_0:
|
case LCD14_LCD_0:
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -167,73 +167,77 @@ static uint8_t lcd14_to_digit(uint8_t raw_digit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static double lcdraw_to_double(lcd14_data *data)
|
/* Get a raw floating point value from the data. */
|
||||||
|
static double lcdraw_to_double(struct lcd14_data *data)
|
||||||
{
|
{
|
||||||
/* *********************************************************************
|
|
||||||
* Get a raw floating point value from the data
|
|
||||||
**********************************************************************/
|
|
||||||
double rawval;
|
double rawval;
|
||||||
double multiplier = 1;
|
double multiplier = 1;
|
||||||
uint8_t digit;
|
uint8_t digit, raw_digit;
|
||||||
gboolean dp_reached = FALSE;
|
gboolean dp_reached = FALSE;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* We have 4 digits, and we start from the most significant */
|
/* We have 4 digits, and we start from the most significant. */
|
||||||
for(i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++) {
|
||||||
{
|
raw_digit = data->digit[i];
|
||||||
uint8_t raw_digit = data->digit[i];
|
|
||||||
digit = lcd14_to_digit(raw_digit);
|
digit = lcd14_to_digit(raw_digit);
|
||||||
if (digit == LCD14_LCD_INVALID) {
|
if (digit == LCD14_LCD_INVALID) {
|
||||||
rawval = NAN;
|
rawval = NAN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Digit 1 does not have a decimal point. Instead, the decimal
|
|
||||||
* point is used to indicate MAX, so we must avoid testing it */
|
/*
|
||||||
|
* Digit 1 does not have a decimal point. Instead, the decimal
|
||||||
|
* point is used to indicate MAX, so we must avoid testing it.
|
||||||
|
*/
|
||||||
if ((i > 0) && (raw_digit & LCD14_DP_MASK))
|
if ((i > 0) && (raw_digit & LCD14_DP_MASK))
|
||||||
dp_reached = TRUE;
|
dp_reached = TRUE;
|
||||||
if(dp_reached) multiplier /= 10;
|
if (dp_reached)
|
||||||
|
multiplier /= 10;
|
||||||
rawval = rawval * 10 + digit;
|
rawval = rawval * 10 + digit;
|
||||||
}
|
}
|
||||||
rawval *= multiplier;
|
rawval *= multiplier;
|
||||||
if (data->digit[0] & LCD14_D0_NEG)
|
if (data->digit[0] & LCD14_D0_NEG)
|
||||||
rawval *= -1;
|
rawval *= -1;
|
||||||
|
|
||||||
/* See if we need to multiply our raw value by anything */
|
/* See if we need to multiply our raw value by anything. */
|
||||||
if(data->flags & LCD14_NANO) {
|
if (data->flags & LCD14_NANO)
|
||||||
rawval *= 1E-9;
|
rawval *= 1E-9;
|
||||||
} else if(data->flags & LCD14_MICRO) {
|
else if (data->flags & LCD14_MICRO)
|
||||||
rawval *= 1E-6;
|
rawval *= 1E-6;
|
||||||
} else if(data->flags & LCD14_MILLI) {
|
else if (data->flags & LCD14_MILLI)
|
||||||
rawval *= 1E-3;
|
rawval *= 1E-3;
|
||||||
} else if(data->flags & LCD14_KILO) {
|
else if (data->flags & LCD14_KILO)
|
||||||
rawval *= 1E3;
|
rawval *= 1E3;
|
||||||
} else if(data->flags & LCD14_MEGA) {
|
else if (data->flags & LCD14_MEGA)
|
||||||
rawval *= 1E6;
|
rawval *= 1E6;
|
||||||
}
|
|
||||||
|
|
||||||
return rawval;
|
return rawval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lcd14_handle_packet(lcd14_data *data, struct dev_context *devc)
|
/* Now see what the value means, and pass that on. */
|
||||||
|
static void lcd14_handle_packet(struct lcd14_data *data,
|
||||||
|
struct dev_context *devc)
|
||||||
{
|
{
|
||||||
double rawval = lcdraw_to_double(data);
|
double rawval;
|
||||||
/* *********************************************************************
|
|
||||||
* Now see what the value means, and pass that on
|
|
||||||
**********************************************************************/
|
|
||||||
struct sr_datafeed_packet packet;
|
struct sr_datafeed_packet packet;
|
||||||
struct sr_datafeed_analog *analog;
|
struct sr_datafeed_analog *analog;
|
||||||
|
|
||||||
if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog)))) {
|
if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog)))) {
|
||||||
sr_err("failed to malloc packet");
|
sr_err("Failed to malloc packet.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
analog->num_samples = 1;
|
|
||||||
if (!(analog->data = g_try_malloc(sizeof(float)))) {
|
if (!(analog->data = g_try_malloc(sizeof(float)))) {
|
||||||
sr_err("failed to malloc data");
|
sr_err("Failed to malloc data.");
|
||||||
g_free(analog);
|
g_free(analog);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rawval = lcdraw_to_double(data);
|
||||||
|
|
||||||
|
analog->num_samples = 1;
|
||||||
*analog->data = (float)rawval;
|
*analog->data = (float)rawval;
|
||||||
|
|
||||||
analog->mq = -1;
|
analog->mq = -1;
|
||||||
|
|
||||||
/* What does the data mean? */
|
/* What does the data mean? */
|
||||||
|
@ -244,16 +248,14 @@ static void lcd14_handle_packet(lcd14_data *data, struct dev_context *devc)
|
||||||
analog->mqflags |= SR_MQFLAG_AC;
|
analog->mqflags |= SR_MQFLAG_AC;
|
||||||
else
|
else
|
||||||
analog->mqflags |= SR_MQFLAG_DC;
|
analog->mqflags |= SR_MQFLAG_DC;
|
||||||
}
|
} else if (data->flags & LCD14_AMP) {
|
||||||
else if(data->flags & LCD14_AMP) {
|
|
||||||
analog->mq = SR_MQ_CURRENT;
|
analog->mq = SR_MQ_CURRENT;
|
||||||
analog->unit = SR_UNIT_AMPERE;
|
analog->unit = SR_UNIT_AMPERE;
|
||||||
if (data->flags & LCD14_AC)
|
if (data->flags & LCD14_AC)
|
||||||
analog->mqflags |= SR_MQFLAG_AC;
|
analog->mqflags |= SR_MQFLAG_AC;
|
||||||
else
|
else
|
||||||
analog->mqflags |= SR_MQFLAG_DC;
|
analog->mqflags |= SR_MQFLAG_DC;
|
||||||
}
|
} else if (data->flags & LCD14_OHM) {
|
||||||
else if(data->flags & LCD14_OHM) {
|
|
||||||
if (data->flags & LCD14_BEEP)
|
if (data->flags & LCD14_BEEP)
|
||||||
analog->mq = SR_MQ_CONTINUITY;
|
analog->mq = SR_MQ_CONTINUITY;
|
||||||
else
|
else
|
||||||
|
@ -264,81 +266,70 @@ static void lcd14_handle_packet(lcd14_data *data, struct dev_context *devc)
|
||||||
analog->unit = SR_UNIT_BOOLEAN;
|
analog->unit = SR_UNIT_BOOLEAN;
|
||||||
*analog->data = FALSE;
|
*analog->data = FALSE;
|
||||||
}
|
}
|
||||||
}
|
} else if (data->flags & LCD14_FARAD) {
|
||||||
else if(data->flags & LCD14_FARAD) {
|
|
||||||
analog->mq = SR_MQ_CAPACITANCE;
|
analog->mq = SR_MQ_CAPACITANCE;
|
||||||
analog->unit = SR_UNIT_FARAD;
|
analog->unit = SR_UNIT_FARAD;
|
||||||
}
|
} else if (data->flags & LCD14_CELSIUS) {
|
||||||
else if(data->flags & LCD14_CELSIUS) {
|
|
||||||
analog->mq = SR_MQ_TEMPERATURE;
|
analog->mq = SR_MQ_TEMPERATURE;
|
||||||
/* No Kelvin or Fahrenheit from the deive, just Celsius */
|
/* No Kelvin or Fahrenheit from the device, just Celsius. */
|
||||||
analog->unit = SR_UNIT_CELSIUS;
|
analog->unit = SR_UNIT_CELSIUS;
|
||||||
}
|
} else if (data->flags & LCD14_HZ) {
|
||||||
else if(data->flags & LCD14_HZ) {
|
|
||||||
analog->mq = SR_MQ_FREQUENCY;
|
analog->mq = SR_MQ_FREQUENCY;
|
||||||
analog->unit = SR_UNIT_HERTZ;
|
analog->unit = SR_UNIT_HERTZ;
|
||||||
}
|
} else if (data->flags & LCD14_DUTY) {
|
||||||
else if(data->flags & LCD14_DUTY) {
|
|
||||||
analog->mq = SR_MQ_DUTY_CYCLE;
|
analog->mq = SR_MQ_DUTY_CYCLE;
|
||||||
analog->unit = SR_UNIT_PERCENTAGE;
|
analog->unit = SR_UNIT_PERCENTAGE;
|
||||||
}
|
} else if (data->flags & LCD14_HFE) {
|
||||||
else if(data->flags & LCD14_HFE) {
|
|
||||||
analog->mq = SR_MQ_GAIN;
|
analog->mq = SR_MQ_GAIN;
|
||||||
analog->unit = SR_UNIT_UNITLESS;
|
analog->unit = SR_UNIT_UNITLESS;
|
||||||
}
|
} else if (data->flags & LCD14_DIODE) {
|
||||||
else if(data->flags & LCD14_DIODE) {
|
|
||||||
analog->mq = SR_MQ_VOLTAGE;
|
analog->mq = SR_MQ_VOLTAGE;
|
||||||
analog->unit = SR_UNIT_VOLT;
|
analog->unit = SR_UNIT_VOLT;
|
||||||
analog->mqflags |= SR_MQFLAG_DIODE | SR_MQFLAG_DC;
|
analog->mqflags |= SR_MQFLAG_DIODE | SR_MQFLAG_DC;
|
||||||
}
|
} else {
|
||||||
else {
|
sr_warn("Unable to identify measurement mode.");
|
||||||
sr_warn("unable to identify measurement mode");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* What other flags are associated with the data? */
|
/* What other flags are associated with the data? */
|
||||||
if(data->flags & LCD14_HOLD) {
|
if (data->flags & LCD14_HOLD)
|
||||||
analog->mqflags |= SR_MQFLAG_HOLD;
|
analog->mqflags |= SR_MQFLAG_HOLD;
|
||||||
}
|
if (data->flags & LCD14_AUTO)
|
||||||
if(data->flags & LCD14_AUTO) {
|
|
||||||
analog->mqflags |= SR_MQFLAG_AUTORANGE;
|
analog->mqflags |= SR_MQFLAG_AUTORANGE;
|
||||||
}
|
if (data->flags & LCD14_REL)
|
||||||
if(data->flags & LCD14_REL) {
|
|
||||||
analog->mqflags |= SR_MQFLAG_RELATIVE;
|
analog->mqflags |= SR_MQFLAG_RELATIVE;
|
||||||
}
|
|
||||||
|
|
||||||
if (analog->mq != -1) {
|
if (analog->mq != -1) {
|
||||||
/* Got a measurement. */
|
/* Got a measurement. */
|
||||||
sr_spew("val %f", rawval);
|
sr_spew("Measurement value is %f.", rawval);
|
||||||
packet.type = SR_DF_ANALOG;
|
packet.type = SR_DF_ANALOG;
|
||||||
packet.payload = analog;
|
packet.payload = analog;
|
||||||
sr_session_send(devc->cb_data, &packet);
|
sr_session_send(devc->cb_data, &packet);
|
||||||
devc->num_samples++;
|
devc->num_samples++;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(analog->data);
|
g_free(analog->data);
|
||||||
g_free(analog);
|
g_free(analog);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_new_data(struct dev_context *devc, int fd)
|
static void handle_new_data(struct dev_context *devc, int fd)
|
||||||
{
|
{
|
||||||
int len;
|
int len, i, offset = 0;
|
||||||
size_t i;
|
struct lcd14_packet *packet;
|
||||||
size_t offset = 0;
|
struct lcd14_data data;
|
||||||
/* Try to get as much data as the buffer can hold */
|
|
||||||
|
/* Try to get as much data as the buffer can hold. */
|
||||||
len = DMM_BUFSIZE - devc->buflen;
|
len = DMM_BUFSIZE - devc->buflen;
|
||||||
len = serial_read(fd, devc->buf + devc->buflen, len);
|
len = serial_read(fd, devc->buf + devc->buflen, len);
|
||||||
if (len < 1) {
|
if (len < 1) {
|
||||||
sr_err("serial port read error!");
|
sr_err("Serial port read error: %d.", len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
devc->buflen += len;
|
devc->buflen += len;
|
||||||
|
|
||||||
/* Now look for packets in that data */
|
/* Now look for packets in that data. */
|
||||||
while((devc->buflen - offset) >= LCD14_PACKET_SIZE)
|
while ((devc->buflen - offset) >= LCD14_PACKET_SIZE) {
|
||||||
{
|
packet = (void *)(devc->buf + offset);
|
||||||
lcd14_packet * packet = (void *)(devc->buf + offset);
|
if (lcd14_is_packet_valid(packet, &data)) {
|
||||||
lcd14_data data;
|
|
||||||
if( lcd14_is_packet_valid(packet, &data) )
|
|
||||||
{
|
|
||||||
lcd14_handle_packet(&data, devc);
|
lcd14_handle_packet(&data, devc);
|
||||||
offset += LCD14_PACKET_SIZE;
|
offset += LCD14_PACKET_SIZE;
|
||||||
} else {
|
} else {
|
||||||
|
@ -346,13 +337,13 @@ static void handle_new_data(struct dev_context *devc, int fd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we have any data left, move it to the beginning of our buffer */
|
/* If we have any data left, move it to the beginning of our buffer. */
|
||||||
for (i = 0; i < devc->buflen - offset; i++)
|
for (i = 0; i < devc->buflen - offset; i++)
|
||||||
devc->buf[i] = devc->buf[offset + i];
|
devc->buf[i] = devc->buf[offset + i];
|
||||||
devc->buflen -= offset;
|
devc->buflen -= offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
SR_PRIV int lcd14_receive_data(int fd, int revents, void *cb_data)
|
SR_PRIV int tekpower_dmm_receive_data(int fd, int revents, void *cb_data)
|
||||||
{
|
{
|
||||||
const struct sr_dev_inst *sdi;
|
const struct sr_dev_inst *sdi;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
@ -363,8 +354,7 @@ SR_PRIV int lcd14_receive_data(int fd, int revents, void *cb_data)
|
||||||
if (!(devc = sdi->priv))
|
if (!(devc = sdi->priv))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (revents == G_IO_IN)
|
if (revents == G_IO_IN) {
|
||||||
{
|
|
||||||
/* Serial data arrived. */
|
/* Serial data arrived. */
|
||||||
handle_new_data(devc, fd);
|
handle_new_data(devc, fd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,11 +57,11 @@
|
||||||
#define LCD14_RSVD1 (1 << 1)
|
#define LCD14_RSVD1 (1 << 1)
|
||||||
#define LCD14_RSVD0 (0 << 0)
|
#define LCD14_RSVD0 (0 << 0)
|
||||||
|
|
||||||
/* mask to remove the decimal point from a digit */
|
/* Mask used to remove the decimal point from a digit. */
|
||||||
#define LCD14_DP_MASK (0x80)
|
#define LCD14_DP_MASK 0x80
|
||||||
#define LCD14_D0_NEG LCD14_DP_MASK
|
#define LCD14_D0_NEG LCD14_DP_MASK
|
||||||
/* mask to remove the syncronization nibble */
|
/* Mask used to remove the syncronization nibble. */
|
||||||
#define LCD14_SYNC_MASK (0xF0)
|
#define LCD14_SYNC_MASK 0xf0
|
||||||
|
|
||||||
/* What the LCD values represent */
|
/* What the LCD values represent */
|
||||||
#define LCD14_LCD_0 0x7d
|
#define LCD14_LCD_0 0x7d
|
||||||
|
@ -75,40 +75,41 @@
|
||||||
#define LCD14_LCD_8 0x7f
|
#define LCD14_LCD_8 0x7f
|
||||||
#define LCD14_LCD_9 0x3f
|
#define LCD14_LCD_9 0x3f
|
||||||
|
|
||||||
|
|
||||||
#define LCD14_LCD_INVALID 0xff
|
#define LCD14_LCD_INVALID 0xff
|
||||||
|
|
||||||
typedef struct {
|
#define LCD14_PACKET_SIZE 14
|
||||||
uint8_t raw[14];
|
|
||||||
} lcd14_packet;
|
|
||||||
|
|
||||||
typedef struct {
|
struct lcd14_packet {
|
||||||
|
uint8_t raw[LCD14_PACKET_SIZE];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct lcd14_data {
|
||||||
uint8_t digit[4];
|
uint8_t digit[4];
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
} lcd14_data;
|
};
|
||||||
|
|
||||||
#define LCD14_PACKET_SIZE (sizeof(lcd14_packet))
|
SR_PRIV gboolean lcd14_is_packet_valid(const struct lcd14_packet *packet,
|
||||||
|
struct lcd14_data *data);
|
||||||
|
|
||||||
SR_PRIV gboolean lcd14_is_packet_valid(const lcd14_packet *packet,
|
/** Private, per-device-instance driver context. */
|
||||||
lcd14_data *data);
|
|
||||||
|
|
||||||
/* Private, per-device-instance driver context. */
|
|
||||||
struct dev_context {
|
struct dev_context {
|
||||||
|
/** The current sampling limit (in number of samples). */
|
||||||
uint64_t limit_samples;
|
uint64_t limit_samples;
|
||||||
|
|
||||||
|
/** Opaque pointer passed in by the frontend. */
|
||||||
|
void *cb_data;
|
||||||
|
|
||||||
|
/** The current number of already received samples. */
|
||||||
|
uint64_t num_samples;
|
||||||
|
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
char *serialcomm;
|
char *serialcomm;
|
||||||
|
|
||||||
/* Opaque pointer passed in by the frontend. */
|
|
||||||
void *cb_data;
|
|
||||||
|
|
||||||
/* Runtime. */
|
|
||||||
uint64_t num_samples;
|
|
||||||
uint8_t buf[DMM_BUFSIZE];
|
uint8_t buf[DMM_BUFSIZE];
|
||||||
size_t bufoffset;
|
int bufoffset;
|
||||||
size_t buflen;
|
int buflen;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SR_PRIV int tekpower_dmm_receive_data(int fd, int revents, void *cb_data);
|
||||||
|
|
||||||
SR_PRIV int lcd14_receive_data(int fd, int revents, void *cb_data);
|
#endif
|
||||||
|
|
||||||
#endif /* LIBSIGROK_HARDWARE_TEKPOWER_DMM_PROTOCOL_H */
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ extern SR_PRIV struct sr_dev_driver flukedmm_driver_info;
|
||||||
extern SR_PRIV struct sr_dev_driver radioshackdmm_driver_info;
|
extern SR_PRIV struct sr_dev_driver radioshackdmm_driver_info;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_HW_TEKPOWER_DMM
|
#ifdef HAVE_HW_TEKPOWER_DMM
|
||||||
extern SR_PRIV struct sr_dev_driver tekpower_driver_info;
|
extern SR_PRIV struct sr_dev_driver tekpower_dmm_driver_info;
|
||||||
#endif
|
#endif
|
||||||
/** @endcond */
|
/** @endcond */
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ static struct sr_dev_driver *drivers_list[] = {
|
||||||
&radioshackdmm_driver_info,
|
&radioshackdmm_driver_info,
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_HW_TEKPOWER_DMM
|
#ifdef HAVE_HW_TEKPOWER_DMM
|
||||||
&tekpower_driver_info,
|
&tekpower_dmm_driver_info,
|
||||||
#endif
|
#endif
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue