X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fbrymen-dmm%2Fprotocol.c;h=3dd8dd3137a3074ea2bbb397963f09cb1e991874;hb=4fff7b3c8a84a5593ddf780992355d9ebf434a90;hp=dff7b985bfe071a8c6f90af6e14719c8aff81fbe;hpb=155b680da482cea2381becb73c51cfb838bff31e;p=libsigrok.git
diff --git a/src/hardware/brymen-dmm/protocol.c b/src/hardware/brymen-dmm/protocol.c
index dff7b985..3dd8dd31 100644
--- a/src/hardware/brymen-dmm/protocol.c
+++ b/src/hardware/brymen-dmm/protocol.c
@@ -17,6 +17,7 @@
* along with this program. If not, see .
*/
+#include
#include "protocol.h"
static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi)
@@ -25,24 +26,30 @@ static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi)
struct dev_context *devc;
struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog;
+ struct sr_analog_encoding encoding;
+ struct sr_analog_meaning meaning;
+ struct sr_analog_spec spec;
devc = sdi->priv;
+ /* TODO: Use proper 'digits' value for this device (and its modes). */
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
+
analog.num_samples = 1;
- analog.mq = -1;
+ analog.meaning->mq = 0;
if (brymen_parse(buf, &floatval, &analog, NULL) != SR_OK)
return;
analog.data = &floatval;
- analog.channels = sdi->channels;
+ analog.meaning->channels = sdi->channels;
- if (analog.mq != -1) {
+ if (analog.meaning->mq != 0) {
/* Got a measurement. */
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
- sr_session_send(devc->cb_data, &packet);
- devc->num_samples++;
+ sr_session_send(sdi, &packet);
+ sr_sw_limits_update_samples_read(&devc->sw_limits, 1);
}
}
@@ -57,7 +64,7 @@ static void handle_new_data(struct sr_dev_inst *sdi)
/* Try to get as much data as the buffer can hold. */
len = DMM_BUFSIZE - devc->buflen;
- len = serial_read(serial, devc->buf + devc->buflen, len);
+ len = serial_read_nonblocking(serial, devc->buf + devc->buflen, len);
if (len < 1) {
sr_err("Serial port read error: %d.", len);
return;
@@ -113,7 +120,6 @@ SR_PRIV int brymen_dmm_receive_data(int fd, int revents, void *cb_data)
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
int ret;
- int64_t time;
(void)fd;
@@ -136,20 +142,8 @@ SR_PRIV int brymen_dmm_receive_data(int fd, int revents, void *cb_data)
}
}
- if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
- sr_info("Requested number of samples reached, stopping.");
- 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, stopping.");
- sdi->driver->dev_acquisition_stop(sdi, cb_data);
- return TRUE;
- }
- }
+ if (sr_sw_limits_check(&devc->sw_limits))
+ sr_dev_acquisition_stop(sdi);
return TRUE;
}
@@ -179,7 +173,9 @@ SR_PRIV int brymen_stream_detect(struct sr_serial_dev_inst *serial,
{
int64_t start, time, byte_delay_us;
size_t ibuf, i, maxlen;
- int status, len, packet_len, stream_len;
+ ssize_t len, stream_len;
+ int packet_len;
+ int status;
maxlen = *buflen;
@@ -187,15 +183,15 @@ SR_PRIV int brymen_stream_detect(struct sr_serial_dev_inst *serial,
"ms, baudrate = %d).", serial->port, timeout_ms, baudrate);
/* Assume 8n1 transmission. That is 10 bits for every byte. */
- byte_delay_us = 10 * (1000000 / baudrate);
+ byte_delay_us = 10 * ((1000 * 1000) / baudrate);
start = g_get_monotonic_time();
packet_len = i = ibuf = len = 0;
while (ibuf < maxlen) {
- len = serial_read(serial, &buf[ibuf], maxlen - ibuf);
+ len = serial_read_nonblocking(serial, &buf[ibuf], maxlen - ibuf);
if (len > 0) {
ibuf += len;
- sr_spew("Read %d bytes.", len);
+ sr_spew("Read %zd bytes.", len);
}
time = g_get_monotonic_time() - start;
@@ -206,7 +202,7 @@ SR_PRIV int brymen_stream_detect(struct sr_serial_dev_inst *serial,
/* How large of a packet are we expecting? */
packet_len = stream_len;
status = get_packet_size(&buf[i], &packet_len);
- switch(status) {
+ switch (status) {
case PACKET_HEADER_OK:
/* We know how much data we need to wait for. */
break;
@@ -247,14 +243,14 @@ SR_PRIV int brymen_stream_detect(struct sr_serial_dev_inst *serial,
if (time >= (int64_t)timeout_ms) {
/* Timeout */
- sr_dbg("Detection timed out after %dms.", time);
+ sr_dbg("Detection timed out after %" PRIi64 "ms.", time);
break;
}
g_usleep(byte_delay_us);
}
*buflen = ibuf;
- sr_err("Didn't find a valid packet (read %d bytes).", ibuf);
+ sr_err("Didn't find a valid packet (read %zu bytes).", ibuf);
return SR_ERR;
}