X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=hardware%2Fserial-dmm%2Fprotocol.c;h=cbbdcdcae75b8e2ab4b0a3baf861f06fcafaf632;hb=76e107d68c010ee3aaede5a1eec2893f82062184;hp=b98b698a8f1cb70176b04730d79aa0019fde9ccb;hpb=f0ac4929d3aaa83e32b0be0637ae1f22040ea724;p=libsigrok.git
diff --git a/hardware/serial-dmm/protocol.c b/hardware/serial-dmm/protocol.c
index b98b698a..cbbdcdca 100644
--- a/hardware/serial-dmm/protocol.c
+++ b/hardware/serial-dmm/protocol.c
@@ -18,11 +18,11 @@
* along with this program. If not, see .
*/
-#include
#include
#include
#include
#include
+#include
#include "libsigrok.h"
#include "libsigrok-internal.h"
#include "protocol.h"
@@ -49,49 +49,82 @@ SR_PRIV void dmm_details_tp4000zc(struct sr_datafeed_analog *analog, void *info)
/* User-defined FS9721_LP3 flag 'c2c1_10' means temperature. */
if (info_local->is_c2c1_10) {
analog->mq = SR_MQ_TEMPERATURE;
- /* No Kelvin or Fahrenheit from the device, just Celsius. */
analog->unit = SR_UNIT_CELSIUS;
}
}
-static void handle_packet(const uint8_t *buf, struct dev_context *devc,
+SR_PRIV void dmm_details_va18b(struct sr_datafeed_analog *analog, void *info)
+{
+ struct fs9721_info *info_local;
+
+ info_local = (struct fs9721_info *)info;
+
+ /* User-defined FS9721_LP3 flag 'c2c1_01' means temperature. */
+ if (info_local->is_c2c1_01) {
+ analog->mq = SR_MQ_TEMPERATURE;
+ analog->unit = SR_UNIT_CELSIUS;
+ }
+}
+
+SR_PRIV void dmm_details_pce_dm32(struct sr_datafeed_analog *analog, void *info)
+{
+ struct fs9721_info *info_local;
+
+ info_local = (struct fs9721_info *)info;
+
+ /* User-defined FS9721_LP3 flag 'c2c1_01' means temperature (F). */
+ if (info_local->is_c2c1_01) {
+ analog->mq = SR_MQ_TEMPERATURE;
+ analog->unit = SR_UNIT_FAHRENHEIT;
+ }
+
+ /* User-defined FS9721_LP3 flag 'c2c1_10' means temperature (C). */
+ if (info_local->is_c2c1_10) {
+ analog->mq = SR_MQ_TEMPERATURE;
+ analog->unit = SR_UNIT_CELSIUS;
+ }
+}
+
+static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi,
int dmm, void *info)
{
float floatval;
struct sr_datafeed_packet packet;
- struct sr_datafeed_analog *analog;
+ struct sr_datafeed_analog analog;
+ struct dev_context *devc;
log_dmm_packet(buf);
+ devc = sdi->priv;
- if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog)))) {
- sr_err("Analog packet malloc failed.");
- return;
- }
+ memset(&analog, 0, sizeof(struct sr_datafeed_analog));
- analog->num_samples = 1;
- analog->mq = -1;
+ analog.probes = sdi->probes;
+ analog.num_samples = 1;
+ analog.mq = -1;
- dmms[dmm].packet_parse(buf, &floatval, analog, info);
- analog->data = &floatval;
+ dmms[dmm].packet_parse(buf, &floatval, &analog, info);
+ analog.data = &floatval;
+ /* If this DMM needs additional handling, call the resp. function. */
if (dmms[dmm].dmm_details)
- dmms[dmm].dmm_details(analog, info);
+ dmms[dmm].dmm_details(&analog, info);
- if (analog->mq != -1) {
+ if (analog.mq != -1) {
/* Got a measurement. */
packet.type = SR_DF_ANALOG;
- packet.payload = analog;
+ packet.payload = &analog;
sr_session_send(devc->cb_data, &packet);
devc->num_samples++;
}
-
- g_free(analog);
}
-static void handle_new_data(struct dev_context *devc, int dmm, void *info)
+static void handle_new_data(struct sr_dev_inst *sdi, int dmm, void *info)
{
+ struct dev_context *devc;
int len, i, offset = 0;
+ devc = sdi->priv;
+
/* Try to get as much data as the buffer can hold. */
len = DMM_BUFSIZE - devc->buflen;
len = serial_read(devc->serial, devc->buf + devc->buflen, len);
@@ -104,7 +137,7 @@ static void handle_new_data(struct dev_context *devc, int dmm, void *info)
/* Now look for packets in that data. */
while ((devc->buflen - offset) >= dmms[dmm].packet_size) {
if (dmms[dmm].packet_valid(devc->buf + offset)) {
- handle_packet(devc->buf + offset, devc, dmm, info);
+ handle_packet(devc->buf + offset, sdi, dmm, info);
offset += dmms[dmm].packet_size;
} else {
offset++;
@@ -121,6 +154,7 @@ static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data)
{
struct sr_dev_inst *sdi;
struct dev_context *devc;
+ int64_t time;
int ret;
(void)fd;
@@ -133,7 +167,7 @@ static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data)
if (revents == G_IO_IN) {
/* Serial data arrived. */
- handle_new_data(devc, dmm, info);
+ handle_new_data(sdi, dmm, info);
} else {
/* Timeout, send another packet request (if DMM needs it). */
if (dmms[dmm].packet_request) {
@@ -145,39 +179,42 @@ static int receive_data(int fd, int revents, int dmm, void *info, void *cb_data)
}
}
- if (devc->num_samples >= devc->limit_samples) {
- sr_info("Requested number of samples reached, stopping.");
+ if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
+ sr_info("Requested number of samples reached.");
sdi->driver->dev_acquisition_stop(sdi, cb_data);
return TRUE;
}
- return TRUE;
-}
-
-SR_PRIV int digitek_dt4000zc_receive_data(int fd, int revents, void *cb_data)
-{
- struct fs9721_info info;
-
- return receive_data(fd, revents, DIGITEK_DT4000ZC, &info, cb_data);
-}
-
-SR_PRIV int tekpower_tp4000zc_receive_data(int fd, int revents, void *cb_data)
-{
- struct fs9721_info info;
-
- return receive_data(fd, revents, TEKPOWER_TP4000ZC, &info, cb_data);
-}
-
-SR_PRIV int metex_me31_receive_data(int fd, int revents, void *cb_data)
-{
- struct metex14_info info;
+ if (devc->limit_msec) {
+ time = (g_get_monotonic_time() - devc->starttime) / 1000;
+ if (time > (int64_t)devc->limit_msec) {
+ sr_info("Requested time limit reached.");
+ sdi->driver->dev_acquisition_stop(sdi, cb_data);
+ return TRUE;
+ }
+ }
- return receive_data(fd, revents, METEX_ME31, &info, cb_data);
+ return TRUE;
}
-SR_PRIV int peaktech_3410_receive_data(int fd, int revents, void *cb_data)
-{
- struct metex14_info info;
-
- return receive_data(fd, revents, PEAKTECH_3410, &info, cb_data);
-}
+#define RECEIVE_DATA(ID_UPPER, DMM_DRIVER) \
+SR_PRIV int receive_data_##ID_UPPER(int fd, int revents, void *cb_data) { \
+ struct DMM_DRIVER##_info info; \
+ return receive_data(fd, revents, ID_UPPER, &info, cb_data); }
+
+/* Driver-specific receive_data() wrappers */
+RECEIVE_DATA(DIGITEK_DT4000ZC, fs9721)
+RECEIVE_DATA(TEKPOWER_TP4000ZC, fs9721)
+RECEIVE_DATA(METEX_ME31, metex14)
+RECEIVE_DATA(PEAKTECH_3410, metex14)
+RECEIVE_DATA(MASTECH_MAS345, metex14)
+RECEIVE_DATA(VA_VA18B, fs9721)
+RECEIVE_DATA(METEX_M3640D, metex14)
+RECEIVE_DATA(PEAKTECH_4370, metex14)
+RECEIVE_DATA(PCE_PCE_DM32, fs9721)
+RECEIVE_DATA(RADIOSHACK_22_168, metex14)
+RECEIVE_DATA(RADIOSHACK_22_805, metex14)
+RECEIVE_DATA(RADIOSHACK_22_812, rs9lcd)
+RECEIVE_DATA(VOLTCRAFT_VC820_SER, fs9721)
+RECEIVE_DATA(VOLTCRAFT_VC840_SER, fs9721)
+RECEIVE_DATA(UNI_T_UT61E_SER, es51922)