X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fkern-scale%2Fprotocol.c;h=722e06256ee3a177464e404409205f2d3be359f8;hb=2cff7a2ba7d516db7f1f0c376bddd2852abfc52c;hp=28ebe717cbfbf635f35a019d5ceafafd7fa01803;hpb=607dcdeae13d04fd5c6d41da46d9c29a04206a86;p=libsigrok.git
diff --git a/src/hardware/kern-scale/protocol.c b/src/hardware/kern-scale/protocol.c
index 28ebe717..722e0625 100644
--- a/src/hardware/kern-scale/protocol.c
+++ b/src/hardware/kern-scale/protocol.c
@@ -14,10 +14,10 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see .
*/
+#include
#include
#include
#include
@@ -33,27 +33,31 @@ static void handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi,
float floatval;
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;
struct dev_context *devc;
scale = (struct scale_info *)sdi->driver;
devc = sdi->priv;
- memset(&analog, 0, sizeof(struct sr_datafeed_analog));
+ /* Note: digits/spec_digits will be overridden later. */
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 0);
- analog.channels = sdi->channels;
+ analog.meaning->channels = sdi->channels;
analog.num_samples = 1;
- analog.mq = -1;
+ analog.meaning->mq = 0;
scale->packet_parse(buf, &floatval, &analog, info);
analog.data = &floatval;
- 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->limits, 1);
}
}
@@ -61,7 +65,7 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info)
{
struct scale_info *scale;
struct dev_context *devc;
- int len, i, offset = 0;
+ int len, offset;
struct sr_serial_dev_inst *serial;
scale = (struct scale_info *)sdi->driver;
@@ -81,6 +85,7 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info)
devc->buflen += len;
/* Now look for packets in that data. */
+ offset = 0;
while ((devc->buflen - offset) >= scale->packet_size) {
if (scale->packet_valid(devc->buf + offset)) {
handle_packet(devc->buf + offset, sdi, info);
@@ -91,8 +96,8 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info)
}
/* If we have any data left, move it to the beginning of our buffer. */
- for (i = 0; i < devc->buflen - offset; i++)
- devc->buf[i] = devc->buf[offset + i];
+ if (offset < devc->buflen)
+ memmove(devc->buf, devc->buf + offset, devc->buflen - offset);
devc->buflen -= offset;
}
@@ -101,7 +106,6 @@ SR_PRIV int kern_scale_receive_data(int fd, int revents, void *cb_data)
struct sr_dev_inst *sdi;
struct dev_context *devc;
struct scale_info *scale;
- int64_t time;
void *info;
(void)fd;
@@ -121,20 +125,8 @@ SR_PRIV int kern_scale_receive_data(int fd, int revents, void *cb_data)
g_free(info);
}
- 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;
- }
- }
+ if (sr_sw_limits_check(&devc->limits))
+ sr_dev_acquisition_stop(sdi);
return TRUE;
}