]> sigrok.org Git - libsigrok.git/blobdiff - hardware/serial-dmm/protocol.c
serial-dmm: Add UNI-T UT61E support (UT-D02 cable).
[libsigrok.git] / hardware / serial-dmm / protocol.c
index eabca4865c88f0053a2108586afdcd8a72daadb8..15ddc74db641d6ec5fffde0fd70b294d7660b1c1 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <glib.h>
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
 #include <errno.h>
+#include <glib.h>
 #include "libsigrok.h"
 #include "libsigrok-internal.h"
 #include "protocol.h"
@@ -35,6 +35,11 @@ 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 void dmm_details_dt4000zc(struct sr_datafeed_analog *analog, void *info)
+{
+       dmm_details_tp4000zc(analog, info); /* Same as TP4000ZC. */
+}
+
 SR_PRIV void dmm_details_tp4000zc(struct sr_datafeed_analog *analog, void *info)
 {
        struct fs9721_info *info_local;
@@ -44,7 +49,38 @@ 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;
+       }
+}
+
+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;
        }
 }
@@ -69,7 +105,9 @@ static void handle_packet(const uint8_t *buf, struct dev_context *devc,
        dmms[dmm].packet_parse(buf, &floatval, analog, info);
        analog->data = &floatval;
 
-       dmms[dmm].dmm_details(analog, info);
+       /* If this DMM needs additional handling, call the resp. function. */
+       if (dmms[dmm].dmm_details)
+               dmms[dmm].dmm_details(analog, info);
 
        if (analog->mq != -1) {
                /* Got a measurement. */
@@ -115,6 +153,8 @@ 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;
 
@@ -127,20 +167,52 @@ 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);
+       } else {
+               /* Timeout, send another packet request (if DMM needs it). */
+               if (dmms[dmm].packet_request) {
+                       ret = dmms[dmm].packet_request(devc->serial);
+                       if (ret < 0) {
+                               sr_err("Failed to request packet: %d.", ret);
+                               return FALSE;
+                       }
+               }
        }
 
-       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;
        }
 
+       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 TRUE;
 }
 
-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);
-}
+#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_812, rs9lcd)
+RECEIVE_DATA(VOLTCRAFT_VC820_SER, fs9721)
+RECEIVE_DATA(VOLTCRAFT_VC840_SER, fs9721)
+RECEIVE_DATA(UNI_T_UT61E_SER, es51922)