X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=hardware%2Ftondaj-sl-814%2Fprotocol.c;h=feeec69aa559c7f947eacc111952aa991cc9aa2e;hp=57472520aa30313fbf33d9ec96423a5660581864;hb=ba7dd8bbb8168cba432a844259a3e239aa5f36d7;hpb=f4284934354bff761a74eee545e5a4b7911a8e8c diff --git a/hardware/tondaj-sl-814/protocol.c b/hardware/tondaj-sl-814/protocol.c index 57472520..feeec69a 100644 --- a/hardware/tondaj-sl-814/protocol.c +++ b/hardware/tondaj-sl-814/protocol.c @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the libsigrok project. * * Copyright (C) 2012 Uwe Hermann * @@ -85,17 +85,20 @@ static void parse_packet(const uint8_t *buf, float *floatval, (void)level; } -static void decode_packet(struct dev_context *devc) +static void decode_packet(struct sr_dev_inst *sdi) { struct sr_datafeed_packet packet; struct sr_datafeed_analog analog; + struct dev_context *devc; float floatval; + devc = sdi->priv; memset(&analog, 0, sizeof(struct sr_datafeed_analog)); parse_packet(devc->buf, &floatval, &analog); /* Send a sample packet with one analog value. */ + analog.channels = sdi->channels; analog.num_samples = 1; analog.data = &floatval; packet.type = SR_DF_ANALOG; @@ -109,6 +112,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; + struct sr_serial_dev_inst *serial; uint8_t buf[3]; int ret; @@ -116,6 +120,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data) (void)revents; sdi = cb_data; + serial = sdi->conn; devc = sdi->priv; /* TODO: Parts of this code need to be improved later. */ @@ -128,14 +133,14 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data) buf[2] = 0x0d; sr_spew("Sending init command: %02x %02x %02x.", buf[0], buf[1], buf[2]); - if ((ret = serial_write(devc->serial, buf, 3)) < 0) { + if ((ret = serial_write(serial, buf, 3)) < 0) { sr_err("Error sending init command: %d.", ret); return FALSE; } devc->state = GET_INIT_REPLY; } else if (devc->state == GET_INIT_REPLY) { /* If we just sent the "init" command, get its reply. */ - if ((ret = serial_read(devc->serial, buf, 2)) < 0) { + if ((ret = serial_read(serial, buf, 2)) < 0) { sr_err("Error reading init reply: %d.", ret); return FALSE; } @@ -154,7 +159,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data) buf[2] = 0x0d; sr_spew("Sending data request command: %02x %02x %02x.", buf[0], buf[1], buf[2]); - if ((ret = serial_write(devc->serial, buf, 3)) < 0) { + if ((ret = serial_write(serial, buf, 3)) < 0) { sr_err("Error sending request command: %d.", ret); return FALSE; } @@ -162,7 +167,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data) devc->state = GET_PACKET; } else if (devc->state == GET_PACKET) { /* Read a packet from the device. */ - ret = serial_read(devc->serial, devc->buf + devc->buflen, + ret = serial_read(serial, devc->buf + devc->buflen, 4 - devc->buflen); if (ret < 0) { sr_err("Error reading packet: %d.", ret); @@ -185,7 +190,7 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data) return TRUE; } - decode_packet(devc); + decode_packet(sdi); devc->state = SEND_PACKET_REQUEST; } else { @@ -194,11 +199,9 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data) } /* Stop acquisition if we acquired enough samples. */ - if (devc->limit_samples > 0) { - if (devc->num_samples >= devc->limit_samples) { - sr_info("Requested number of samples reached."); - sdi->driver->dev_acquisition_stop(sdi, cb_data); - } + 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;