X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fopenbench-logic-sniffer%2Fprotocol.c;h=75e0c8a6194123401f75727904762ed88daeea41;hb=32af282c5e1d64e878438aafe7c69efd2b4a4bd6;hp=00068ebdcb4e37145ce7f9363c6cf446b3c826c0;hpb=f4d3a4fb9ae62b4764cbb8181ab9bef95e7b6348;p=libsigrok.git diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index 00068ebd..75e0c8a6 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -18,10 +18,8 @@ */ #include "protocol.h" -#include extern SR_PRIV struct sr_dev_driver ols_driver_info; -static struct sr_dev_driver *di = &ols_driver_info; SR_PRIV int send_shortcommand(struct sr_serial_dev_inst *serial, uint8_t command) @@ -33,6 +31,9 @@ SR_PRIV int send_shortcommand(struct sr_serial_dev_inst *serial, if (serial_write_blocking(serial, buf, 1, serial_timeout(serial, 1)) != 1) return SR_ERR; + if (serial_drain(serial) != 0) + return SR_ERR; + return SR_OK; } @@ -51,6 +52,9 @@ SR_PRIV int send_longcommand(struct sr_serial_dev_inst *serial, if (serial_write_blocking(serial, buf, 5, serial_timeout(serial, 1)) != 5) return SR_ERR; + if (serial_drain(serial) != 0) + return SR_ERR; + return SR_OK; } @@ -118,10 +122,7 @@ SR_PRIV struct dev_context *ols_dev_new(void) { struct dev_context *devc; - if (!(devc = g_try_malloc(sizeof(struct dev_context)))) { - sr_err("Device context malloc failed."); - return NULL; - } + devc = g_malloc0(sizeof(struct dev_context)); /* Device-specific settings */ devc->max_samples = devc->max_samplerate = devc->protocol_version = 0; @@ -139,15 +140,15 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) { struct sr_dev_inst *sdi; struct dev_context *devc; - struct sr_channel *ch; uint32_t tmp_int, ui; uint8_t key, type, token; int delay_ms; GString *tmp_str, *devname, *version; guchar tmp_c; - sdi = sr_dev_inst_new(SR_ST_INACTIVE, NULL, NULL, NULL); - sdi->driver = di; + sdi = g_malloc0(sizeof(struct sr_dev_inst)); + sdi->status = SR_ST_INACTIVE; + sdi->driver = &ols_driver_info; devc = ols_dev_new(); sdi->priv = devc; @@ -211,12 +212,9 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) switch (token) { case 0x00: /* Number of usable channels */ - for (ui = 0; ui < tmp_int; ui++) { - if (!(ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, - ols_channel_names[ui]))) - return 0; - sdi->channels = g_slist_append(sdi->channels, ch); - } + for (ui = 0; ui < tmp_int; ui++) + sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE, + ols_channel_names[ui]); break; case 0x01: /* Amount of sample memory available (bytes) */ @@ -227,7 +225,7 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) /* what is this for? */ break; case 0x03: - /* Maximum sample rate (hz) */ + /* Maximum sample rate (Hz) */ devc->max_samplerate = tmp_int; break; case 0x04: @@ -250,12 +248,9 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) switch (token) { case 0x00: /* Number of usable channels */ - for (ui = 0; ui < tmp_c; ui++) { - if (!(ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, - ols_channel_names[ui]))) - return 0; - sdi->channels = g_slist_append(sdi->channels, ch); - } + for (ui = 0; ui < tmp_c; ui++) + sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE, + ols_channel_names[ui]); break; case 0x01: /* protocol version */