X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fscpi%2Fscpi_serial.c;h=ef507bb499170f67a277f60d88fa16109b3ad861;hb=04229f7bfc750f2b67e8dd54ac82ae6bb7eae1e4;hp=4f6e067887c9135298b6512837cdf9f4abb33d09;hpb=406e0c79cfbc5893635bbdece6f5c8b2ca9c9b25;p=libsigrok.git diff --git a/src/scpi/scpi_serial.c b/src/scpi/scpi_serial.c index 4f6e0678..ef507bb4 100644 --- a/src/scpi/scpi_serial.c +++ b/src/scpi/scpi_serial.c @@ -18,12 +18,13 @@ * along with this program. If not, see . */ -#include "libsigrok.h" -#include "libsigrok-internal.h" - +#include #include #include #include +#include +#include "libsigrok-internal.h" +#include "scpi.h" #define LOG_PREFIX "scpi_serial" @@ -36,7 +37,7 @@ struct scpi_serial { size_t read; }; -static struct { +static const struct { uint16_t vendor_id; uint16_t product_id; const char *serialcomm; @@ -54,8 +55,8 @@ static GSList *scpi_serial_scan(struct drv_context *drvc) (void)drvc; for (i = 0; i < ARRAY_SIZE(scpi_serial_usb_ids); i++) { - if ((l = sr_serial_find_usb(scpi_serial_usb_ids[i].vendor_id, - scpi_serial_usb_ids[i].product_id)) == NULL) + if (!(l = sr_serial_find_usb(scpi_serial_usb_ids[i].vendor_id, + scpi_serial_usb_ids[i].product_id))) continue; for (r = l; r; r = r->next) { if (scpi_serial_usb_ids[i].serialcomm) @@ -79,15 +80,14 @@ static int scpi_serial_dev_inst_new(void *priv, struct drv_context *drvc, (void)drvc; (void)params; - if (!(sscpi->serial = sr_serial_dev_inst_new(resource, serialcomm))) - return SR_ERR; + sscpi->serial = sr_serial_dev_inst_new(resource, serialcomm); return SR_OK; } -static int scpi_serial_open(void *priv) +static int scpi_serial_open(struct sr_scpi_dev_inst *scpi) { - struct scpi_serial *sscpi = priv; + struct scpi_serial *sscpi = scpi->priv; struct sr_serial_dev_inst *serial = sscpi->serial; if (serial_open(serial, SERIAL_RDWR) != SR_OK) @@ -163,7 +163,7 @@ static int scpi_serial_read_data(void *priv, char *buf, int maxlen) /* Try to read new data into the buffer if there is space. */ if (len > 0) { - ret = serial_read_nonblocking(sscpi->serial, sscpi->buffer + sscpi->read, + ret = serial_read_nonblocking(sscpi->serial, sscpi->buffer + sscpi->count, BUFFER_SIZE - sscpi->count); if (ret < 0) @@ -209,9 +209,9 @@ static int scpi_serial_read_complete(void *priv) } } -static int scpi_serial_close(void *priv) +static int scpi_serial_close(struct sr_scpi_dev_inst *scpi) { - struct scpi_serial *sscpi = priv; + struct scpi_serial *sscpi = scpi->priv; return serial_close(sscpi->serial); }