#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,
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)
{
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;
/* 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;
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;
}
return SR_OK;
}
-static int hw_init(void)
+static int hw_init(int dmm)
{
int ret;
struct drv_context *drvc;
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;
(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);
}
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;
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)
{
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_ut61d,
+ .cleanup = hw_cleanup,
+ .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_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,
+ .init = hw_init_vc820,
.cleanup = hw_cleanup,
- .scan = hw_scan,
- .dev_list = hw_dev_list,
+ .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,
+ .dev_acquisition_start = hw_dev_acquisition_start_vc820,
.dev_acquisition_stop = hw_dev_acquisition_stop,
.priv = NULL,
};
* - ...
*/
-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;
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;
}
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;
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.");
}
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);
}
}
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);
+}