Draft: Make UT61D and VC-820 "first-class" drivers.
The 'uni-t-dmm' driver/directory will not appear as a "driver" to frontends anymore, it's just an internal thing. The frontends will see a uni-t-ut61d and voltcraft-vc820 driver now, with the correct names and parsers etc. attached to them. This is not fully finished yet, but it's a start (and works mostly): $ sigrok-cli -D The following devices were found: UNI-T UT61D with 1 probe: P1 Voltcraft VC-820 with 1 probe: P1 $ sigrok-cli --driver voltcraft-vc820 -D The following devices were found: Voltcraft VC-820 with 1 probe: P1 $ sigrok-cli --driver uni-t-ut61d -D The following devices were found: UNI-T UT61D with 1 probe: P1 # Now attaching a UNI-T UT61D device via USB. $ sigrok-cli --driver uni-t-ut61d --samples 3 -O analog P1: -0.017800 V DC P1: -0.017600 V DC P1: -0.017700 V DC # Now attaching a Voltcraft VC-820 device via USB instead. $ sigrok-cli --driver voltcraft-vc820 --samples 3 -O analog P1: -0.319200 V DC P1: -0.319300 V DC P1: -0.319300 V DC
This commit is contained in:
parent
4ca378df88
commit
fdbcb86dba
|
@ -24,6 +24,12 @@
|
|||
#include "libsigrok-internal.h"
|
||||
#include "protocol.h"
|
||||
|
||||
/* Note: The order here must match the DMM/device enum in protocol.h. */
|
||||
static const char *dev_names[] = {
|
||||
"UNI-T UT61D",
|
||||
"Voltcraft VC-820",
|
||||
};
|
||||
|
||||
static const int hwcaps[] = {
|
||||
SR_HWCAP_MULTIMETER,
|
||||
SR_HWCAP_LIMIT_SAMPLES,
|
||||
|
@ -37,8 +43,11 @@ static const char *probe_names[] = {
|
|||
NULL,
|
||||
};
|
||||
|
||||
SR_PRIV struct sr_dev_driver uni_t_dmm_driver_info;
|
||||
static struct sr_dev_driver *di = &uni_t_dmm_driver_info;
|
||||
SR_PRIV struct sr_dev_driver uni_t_ut61d_driver_info;
|
||||
static struct sr_dev_driver *di_ut61d = &uni_t_ut61d_driver_info;
|
||||
|
||||
SR_PRIV struct sr_dev_driver voltcraft_vc820_driver_info;
|
||||
static struct sr_dev_driver *di_vc820 = &voltcraft_vc820_driver_info;
|
||||
|
||||
static int open_usb(struct sr_dev_inst *sdi)
|
||||
{
|
||||
|
@ -82,7 +91,7 @@ static int open_usb(struct sr_dev_inst *sdi)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static GSList *connect_usb(const char *conn)
|
||||
static GSList *connect_usb(const char *conn, int dmm)
|
||||
{
|
||||
struct sr_dev_inst *sdi;
|
||||
struct drv_context *drvc;
|
||||
|
@ -97,7 +106,10 @@ static GSList *connect_usb(const char *conn)
|
|||
|
||||
/* TODO: Use common code later, refactor. */
|
||||
|
||||
drvc = di->priv;
|
||||
if (dmm == UNI_T_UT61D)
|
||||
drvc = di_ut61d->priv;
|
||||
else if (dmm == VOLTCRAFT_VC820)
|
||||
drvc = di_vc820->priv;
|
||||
|
||||
/* Hardcoded for now. */
|
||||
vid = UT_D04_CABLE_USB_VID;
|
||||
|
@ -121,7 +133,7 @@ static GSList *connect_usb(const char *conn)
|
|||
|
||||
devcnt = g_slist_length(drvc->instances);
|
||||
if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_INACTIVE,
|
||||
"UNI-T DMM", NULL, NULL))) {
|
||||
dev_names[dmm], NULL, NULL))) {
|
||||
sr_err("sr_dev_inst_new returned NULL.");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -146,7 +158,7 @@ static int clear_instances(void)
|
|||
return SR_OK;
|
||||
}
|
||||
|
||||
static int hw_init(void)
|
||||
static int hw_init(int dmm)
|
||||
{
|
||||
int ret;
|
||||
struct drv_context *drvc;
|
||||
|
@ -162,12 +174,25 @@ static int hw_init(void)
|
|||
return SR_ERR;
|
||||
}
|
||||
|
||||
di->priv = drvc;
|
||||
if (dmm == UNI_T_UT61D)
|
||||
di_ut61d->priv = drvc;
|
||||
else if (dmm == VOLTCRAFT_VC820)
|
||||
di_vc820->priv = drvc;
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
static GSList *hw_scan(GSList *options)
|
||||
static int hw_init_ut61d(void)
|
||||
{
|
||||
return hw_init(UNI_T_UT61D);
|
||||
}
|
||||
|
||||
static int hw_init_vc820(void)
|
||||
{
|
||||
return hw_init(VOLTCRAFT_VC820);
|
||||
}
|
||||
|
||||
static GSList *hw_scan(GSList *options, int dmm)
|
||||
{
|
||||
GSList *l, *devices;
|
||||
struct sr_dev_inst *sdi;
|
||||
|
@ -175,29 +200,60 @@ static GSList *hw_scan(GSList *options)
|
|||
|
||||
(void)options;
|
||||
|
||||
drvc = di->priv;
|
||||
if (dmm == UNI_T_UT61D)
|
||||
drvc = di_ut61d->priv;
|
||||
else if (dmm == VOLTCRAFT_VC820)
|
||||
drvc = di_vc820->priv;
|
||||
|
||||
if (!(devices = connect_usb(NULL)))
|
||||
if (!(devices = connect_usb(NULL, dmm)))
|
||||
return NULL;
|
||||
|
||||
for (l = devices; l; l = l->next) {
|
||||
sdi = l->data;
|
||||
sdi->driver = di;
|
||||
|
||||
if (dmm == UNI_T_UT61D)
|
||||
sdi->driver = di_ut61d;
|
||||
else if (dmm == VOLTCRAFT_VC820)
|
||||
sdi->driver = di_vc820;
|
||||
|
||||
drvc->instances = g_slist_append(drvc->instances, l->data);
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
static GSList *hw_dev_list(void)
|
||||
static GSList *hw_scan_ut61d(GSList *options)
|
||||
{
|
||||
return hw_scan(options, UNI_T_UT61D);
|
||||
}
|
||||
|
||||
static GSList *hw_scan_vc820(GSList *options)
|
||||
{
|
||||
return hw_scan(options, VOLTCRAFT_VC820);
|
||||
}
|
||||
|
||||
static GSList *hw_dev_list(int dmm)
|
||||
{
|
||||
struct drv_context *drvc;
|
||||
|
||||
drvc = di->priv;
|
||||
if (dmm == UNI_T_UT61D)
|
||||
drvc = di_ut61d->priv;
|
||||
else if (dmm == VOLTCRAFT_VC820)
|
||||
drvc = di_vc820->priv;
|
||||
|
||||
return drvc->instances;
|
||||
}
|
||||
|
||||
static GSList *hw_dev_list_ut61d(void)
|
||||
{
|
||||
return hw_dev_list(UNI_T_UT61D);
|
||||
}
|
||||
|
||||
static GSList *hw_dev_list_vc820(void)
|
||||
{
|
||||
return hw_dev_list(VOLTCRAFT_VC820);
|
||||
}
|
||||
|
||||
static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||
{
|
||||
return open_usb(sdi);
|
||||
|
@ -299,7 +355,7 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
|||
}
|
||||
|
||||
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||
void *cb_data)
|
||||
int dmm, void *cb_data)
|
||||
{
|
||||
struct sr_datafeed_packet packet;
|
||||
struct sr_datafeed_header header;
|
||||
|
@ -327,12 +383,29 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
|||
meta.num_probes = 1;
|
||||
sr_session_send(devc->cb_data, &packet);
|
||||
|
||||
sr_source_add(0, 0, 10 /* poll_timeout */,
|
||||
uni_t_dmm_receive_data, (void *)sdi);
|
||||
if (dmm == UNI_T_UT61D) {
|
||||
sr_source_add(0, 0, 10 /* poll_timeout */,
|
||||
uni_t_ut61d_receive_data, (void *)sdi);
|
||||
} else if (dmm == VOLTCRAFT_VC820) {
|
||||
sr_source_add(0, 0, 10 /* poll_timeout */,
|
||||
voltcraft_vc820_receive_data, (void *)sdi);
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
static int hw_dev_acquisition_start_ut61d(const struct sr_dev_inst *sdi,
|
||||
void *cb_data)
|
||||
{
|
||||
return hw_dev_acquisition_start(sdi, UNI_T_UT61D, cb_data);
|
||||
}
|
||||
|
||||
static int hw_dev_acquisition_start_vc820(const struct sr_dev_inst *sdi,
|
||||
void *cb_data)
|
||||
{
|
||||
return hw_dev_acquisition_start(sdi, VOLTCRAFT_VC820, cb_data);
|
||||
}
|
||||
|
||||
static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
|
||||
void *cb_data)
|
||||
{
|
||||
|
@ -353,20 +426,38 @@ static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
|
|||
return SR_OK;
|
||||
}
|
||||
|
||||
SR_PRIV struct sr_dev_driver uni_t_dmm_driver_info = {
|
||||
.name = "uni-t-dmm",
|
||||
.longname = "UNI-T DMM series",
|
||||
SR_PRIV struct sr_dev_driver uni_t_ut61d_driver_info = {
|
||||
.name = "uni-t-ut61d",
|
||||
.longname = "UNI-T UT61D",
|
||||
.api_version = 1,
|
||||
.init = hw_init,
|
||||
.init = hw_init_ut61d,
|
||||
.cleanup = hw_cleanup,
|
||||
.scan = hw_scan,
|
||||
.dev_list = hw_dev_list,
|
||||
.scan = hw_scan_ut61d,
|
||||
.dev_list = hw_dev_list_ut61d,
|
||||
.dev_clear = clear_instances,
|
||||
.dev_open = hw_dev_open,
|
||||
.dev_close = hw_dev_close,
|
||||
.info_get = hw_info_get,
|
||||
.dev_config_set = hw_dev_config_set,
|
||||
.dev_acquisition_start = hw_dev_acquisition_start,
|
||||
.dev_acquisition_start = hw_dev_acquisition_start_ut61d,
|
||||
.dev_acquisition_stop = hw_dev_acquisition_stop,
|
||||
.priv = NULL,
|
||||
};
|
||||
|
||||
SR_PRIV struct sr_dev_driver voltcraft_vc820_driver_info = {
|
||||
.name = "voltcraft-vc820",
|
||||
.longname = "Voltcraft VC-820",
|
||||
.api_version = 1,
|
||||
.init = hw_init_vc820,
|
||||
.cleanup = hw_cleanup,
|
||||
.scan = hw_scan_vc820,
|
||||
.dev_list = hw_dev_list_vc820,
|
||||
.dev_clear = clear_instances,
|
||||
.dev_open = hw_dev_open,
|
||||
.dev_close = hw_dev_close,
|
||||
.info_get = hw_info_get,
|
||||
.dev_config_set = hw_dev_config_set,
|
||||
.dev_acquisition_start = hw_dev_acquisition_start_vc820,
|
||||
.dev_acquisition_stop = hw_dev_acquisition_stop,
|
||||
.priv = NULL,
|
||||
};
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
* - ...
|
||||
*/
|
||||
|
||||
static void decode_packet(struct dev_context *devc, const uint8_t *buf)
|
||||
static void decode_packet(struct dev_context *devc, int dmm, const uint8_t *buf)
|
||||
{
|
||||
struct sr_datafeed_packet packet;
|
||||
struct sr_datafeed_analog analog;
|
||||
|
@ -76,8 +76,11 @@ static void decode_packet(struct dev_context *devc, const uint8_t *buf)
|
|||
memset(&analog, 0, sizeof(struct sr_datafeed_analog));
|
||||
|
||||
/* Parse the protocol packet. */
|
||||
if ((ret = sr_dmm_parse_fs9922(buf, &floatval, &analog)) != SR_OK) {
|
||||
// if ((ret = sr_dmm_parse_fs9721(buf, &floatval, &analog)) != SR_OK) {
|
||||
if (dmm == UNI_T_UT61D)
|
||||
ret = sr_dmm_parse_fs9922(buf, &floatval, &analog);
|
||||
else if (dmm == VOLTCRAFT_VC820)
|
||||
ret = sr_dmm_parse_fs9721(buf, &floatval, &analog);
|
||||
if (ret != SR_OK) {
|
||||
sr_err("Invalid DMM packet, ignoring.");
|
||||
return;
|
||||
}
|
||||
|
@ -171,7 +174,7 @@ static void log_dmm_packet(const uint8_t *buf)
|
|||
buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13]);
|
||||
}
|
||||
|
||||
SR_PRIV int uni_t_dmm_receive_data(int fd, int revents, void *cb_data)
|
||||
static int uni_t_dmm_receive_data(int fd, int revents, int dmm, void *cb_data)
|
||||
{
|
||||
struct sr_dev_inst *sdi;
|
||||
struct dev_context *devc;
|
||||
|
@ -227,10 +230,15 @@ SR_PRIV int uni_t_dmm_receive_data(int fd, int revents, void *cb_data)
|
|||
if (buf[0] != 0xf0) {
|
||||
/* First time: Synchronize to the start of a packet. */
|
||||
if (!synced_on_first_packet) {
|
||||
/* Valid packets start with '+' or '-'. */
|
||||
if ((buf[1] != '+') && buf[1] != '-')
|
||||
// if ((buf[1] & 0xf0) != 0x10)
|
||||
return TRUE;
|
||||
if (dmm == UNI_T_UT61D) {
|
||||
/* Valid packets start with '+' or '-'. */
|
||||
if ((buf[1] != '+') && buf[1] != '-')
|
||||
return TRUE;
|
||||
} else if (dmm == VOLTCRAFT_VC820) {
|
||||
/* Valid packets have 0x1 as high nibble. */
|
||||
if ((buf[1] & 0xf0) != 0x10)
|
||||
return TRUE;
|
||||
}
|
||||
synced_on_first_packet = TRUE;
|
||||
sr_spew("Successfully synchronized on first packet.");
|
||||
}
|
||||
|
@ -243,7 +251,7 @@ SR_PRIV int uni_t_dmm_receive_data(int fd, int revents, void *cb_data)
|
|||
if (data_byte_counter == NUM_DATA_BYTES) {
|
||||
log_dmm_packet(pbuf);
|
||||
data_byte_counter = 0;
|
||||
decode_packet(devc, pbuf);
|
||||
decode_packet(devc, dmm, pbuf);
|
||||
memset(pbuf, 0x00, NUM_DATA_BYTES);
|
||||
}
|
||||
}
|
||||
|
@ -256,3 +264,13 @@ SR_PRIV int uni_t_dmm_receive_data(int fd, int revents, void *cb_data)
|
|||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
SR_PRIV int uni_t_ut61d_receive_data(int fd, int revents, void *cb_data)
|
||||
{
|
||||
return uni_t_dmm_receive_data(fd, revents, UNI_T_UT61D, cb_data);
|
||||
}
|
||||
|
||||
SR_PRIV int voltcraft_vc820_receive_data(int fd, int revents, void *cb_data)
|
||||
{
|
||||
return uni_t_dmm_receive_data(fd, revents, VOLTCRAFT_VC820, cb_data);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,12 @@
|
|||
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
|
||||
#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
|
||||
|
||||
/* Note: The order here must match dev_names[] in api.c. */
|
||||
enum {
|
||||
UNI_T_UT61D,
|
||||
VOLTCRAFT_VC820,
|
||||
};
|
||||
|
||||
#define UT_D04_CABLE_USB_VID 0x1a86
|
||||
#define UT_D04_CABLE_USB_DID 0xe008
|
||||
|
||||
|
@ -61,6 +67,7 @@ struct dev_context {
|
|||
uint8_t protocol_buf[14];
|
||||
};
|
||||
|
||||
SR_PRIV int uni_t_dmm_receive_data(int fd, int revents, void *cb_data);
|
||||
SR_PRIV int uni_t_ut61d_receive_data(int fd, int revents, void *cb_data);
|
||||
SR_PRIV int voltcraft_vc820_receive_data(int fd, int revents, void *cb_data);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -111,7 +111,8 @@ extern SR_PRIV struct sr_dev_driver radioshackdmm_driver_info;
|
|||
extern SR_PRIV struct sr_dev_driver tekpower_dmm_driver_info;
|
||||
#endif
|
||||
#ifdef HAVE_HW_UNI_T_DMM
|
||||
extern SR_PRIV struct sr_dev_driver uni_t_dmm_driver_info;
|
||||
extern SR_PRIV struct sr_dev_driver uni_t_ut61d_driver_info;
|
||||
extern SR_PRIV struct sr_dev_driver voltcraft_vc820_driver_info;
|
||||
#endif
|
||||
/** @endcond */
|
||||
|
||||
|
@ -159,7 +160,8 @@ static struct sr_dev_driver *drivers_list[] = {
|
|||
&tekpower_dmm_driver_info,
|
||||
#endif
|
||||
#ifdef HAVE_HW_UNI_T_DMM
|
||||
&uni_t_dmm_driver_info,
|
||||
&uni_t_ut61d_driver_info,
|
||||
&voltcraft_vc820_driver_info,
|
||||
#endif
|
||||
NULL,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue