X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fmic-985xx%2Fprotocol.c;h=d7c69d0e315c9e49ae6e85fcc736e34886941a26;hb=c81069b33760f6de36466410ad4bbc9cb762e938;hp=9d0e603b1daffad54af5ecd1e42133ab47b5d4fe;hpb=3e2373247cf0b3c8557fb718d988b21a0299770c;p=libsigrok.git diff --git a/src/hardware/mic-985xx/protocol.c b/src/hardware/mic-985xx/protocol.c index 9d0e603b..d7c69d0e 100644 --- a/src/hardware/mic-985xx/protocol.c +++ b/src/hardware/mic-985xx/protocol.c @@ -18,13 +18,15 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include "protocol.h" static int mic_send(struct sr_serial_dev_inst *serial, const char *cmd) { int ret; - if ((ret = serial_write_blocking(serial, cmd, strlen(cmd))) < 0) { + if ((ret = serial_write_blocking(serial, cmd, strlen(cmd), + serial_timeout(serial, strlen(cmd)))) < 0) { sr_err("Error sending '%s' command: %d.", cmd, ret); return SR_ERR; } @@ -93,7 +95,10 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx) { float temperature, humidity; struct sr_datafeed_packet packet; - struct sr_datafeed_analog analog; + struct sr_datafeed_analog2 analog; + struct sr_analog_encoding encoding; + struct sr_analog_meaning meaning; + struct sr_analog_spec spec; struct dev_context *devc; GSList *l; int ret; @@ -108,20 +113,19 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx) return SR_ERR; } - /* Clear 'analog', otherwise it'll contain random garbage. */ - memset(&analog, 0, sizeof(struct sr_datafeed_analog)); + sr_analog_init(&analog, &encoding, &meaning, &spec, 3); /* Common values for both channels. */ - packet.type = SR_DF_ANALOG; + packet.type = SR_DF_ANALOG2; packet.payload = &analog; analog.num_samples = 1; /* Temperature. */ l = g_slist_copy(sdi->channels); l = g_slist_remove_link(l, g_slist_nth(l, 1)); - analog.channels = l; - analog.mq = SR_MQ_TEMPERATURE; - analog.unit = SR_UNIT_CELSIUS; /* TODO: Use C/F correctly. */ + meaning.channels = l; + meaning.mq = SR_MQ_TEMPERATURE; + meaning.unit = SR_UNIT_CELSIUS; /* TODO: Use C/F correctly. */ analog.data = &temperature; sr_session_send(devc->cb_data, &packet); g_slist_free(l); @@ -130,9 +134,9 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx) if (mic_devs[idx].has_humidity) { l = g_slist_copy(sdi->channels); l = g_slist_remove_link(l, g_slist_nth(l, 0)); - analog.channels = l; - analog.mq = SR_MQ_RELATIVE_HUMIDITY; - analog.unit = SR_UNIT_PERCENTAGE; + meaning.channels = l; + meaning.mq = SR_MQ_RELATIVE_HUMIDITY; + meaning.unit = SR_UNIT_PERCENTAGE; analog.data = &humidity; sr_session_send(devc->cb_data, &packet); g_slist_free(l);