From: Bert Vermeulen Date: Mon, 23 Dec 2013 00:53:30 +0000 (+0100) Subject: appa-55ii: Coding style fixes. X-Git-Tag: libsigrok-0.3.0~410 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7574e58c1a9f2c9665d9680a8b02ac30f407cdbc;p=libsigrok.git appa-55ii: Coding style fixes. --- diff --git a/hardware/appa-55ii/api.c b/hardware/appa-55ii/api.c index af8fdac2..18ed7397 100644 --- a/hardware/appa-55ii/api.c +++ b/hardware/appa-55ii/api.c @@ -53,13 +53,17 @@ static GSList *scan(GSList *options) struct sr_serial_dev_inst *serial; struct sr_dev_inst *sdi; struct sr_probe *probe; - GSList *devices = NULL, *l; - const char *conn = NULL, *serialcomm = NULL; + struct sr_config *src; + GSList *devices, *l; + const char *conn, *serialcomm; uint8_t buf[50]; - size_t len = sizeof(buf); + size_t len; + len = sizeof(buf); + devices = NULL; + conn = serialcomm = NULL; for (l = options; l; l = l->next) { - struct sr_config *src = l->data; + src = l->data; switch (src->key) { case SR_CONF_CONN: conn = g_variant_get_string(src->data, NULL); @@ -87,7 +91,7 @@ static GSList *scan(GSList *options) /* Let's get a bit of data and see if we can find a packet. */ if (serial_stream_detect(serial, buf, &len, 25, - appa_55ii_packet_valid, 500, 9600) != SR_OK) + appa_55ii_packet_valid, 500, 9600) != SR_OK) goto scan_cleanup; sr_info("Found device on port %s.", conn); @@ -139,7 +143,7 @@ static int cleanup(void) } static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_probe_group *probe_group) + const struct sr_probe_group *probe_group) { struct dev_context *devc = sdi->priv; @@ -166,6 +170,8 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_probe_group *probe_group) { struct dev_context *devc; + const char *tmp_str; + unsigned int i; (void)probe_group; @@ -187,9 +193,8 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec); break; case SR_CONF_DATA_SOURCE: { - const char *tmp_str = g_variant_get_string(data, NULL); - unsigned int i; - for (i=0; idata_source = i; break; @@ -231,11 +236,12 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, } static int dev_acquisition_start(const struct sr_dev_inst *sdi, - void *cb_data) + void *cb_data) { - struct sr_serial_dev_inst *serial = sdi->conn; + struct sr_serial_dev_inst *serial; struct dev_context *devc; + serial = sdi->conn; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; @@ -266,7 +272,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { return std_serial_dev_acquisition_stop(sdi, cb_data, std_serial_dev_close, - sdi->conn, LOG_PREFIX); + sdi->conn, LOG_PREFIX); } SR_PRIV struct sr_dev_driver appa_55ii_driver_info = { diff --git a/hardware/appa-55ii/protocol.c b/hardware/appa-55ii/protocol.c index c3a715be..5a5dda62 100644 --- a/hardware/appa-55ii/protocol.c +++ b/hardware/appa-55ii/protocol.c @@ -31,63 +31,84 @@ typedef enum { static gboolean appa_55ii_checksum(const uint8_t *buf) { - int i, size = buf[3]+4, checksum = 0; - for (i=0; ipriv; struct sr_datafeed_packet packet; - struct sr_datafeed_analog analog = { 0 }; - float values[APPA_55II_NUM_PROBES], *val_ptr = values; + struct sr_datafeed_analog analog; + struct sr_probe *probe; + float values[APPA_55II_NUM_PROBES], *val_ptr; int i; if (devc->data_source != DATA_SOURCE_LIVE) return; + val_ptr = values; + memset(&analog, 0, sizeof(analog)); analog.num_samples = 1; analog.mq = SR_MQ_TEMPERATURE; analog.unit = SR_UNIT_CELSIUS; analog.mqflags = appa_55ii_flags(buf); analog.data = values; - for (i=0; iprobes, i); + for (i = 0; i < APPA_55II_NUM_PROBES; i++) { + probe = g_slist_nth_data(sdi->probes, i); if (!probe->enabled) continue; analog.probes = g_slist_append(analog.probes, probe); @@ -104,33 +125,42 @@ static void appa_55ii_live_data(struct sr_dev_inst *sdi, const uint8_t *buf) static void appa_55ii_log_metadata(struct sr_dev_inst *sdi, const uint8_t *buf) { - struct dev_context *devc = sdi->priv; + struct dev_context *devc; + + devc = sdi->priv; devc->num_log_records = (buf[5] << 8) + buf[4]; } static void appa_55ii_log_data_parse(struct sr_dev_inst *sdi) { - struct dev_context *devc = sdi->priv; - int offset = 0; + struct dev_context *devc; + struct sr_datafeed_packet packet; + struct sr_datafeed_analog analog = { 0 }; + struct sr_probe *probe; + float values[APPA_55II_NUM_PROBES], *val_ptr; + const uint8_t *buf; + int16_t temp; + int offset, i; + + devc = sdi->priv; + offset = 0; while (devc->log_buf_len >= 20 && devc->num_log_records > 0) { - const uint8_t *buf = devc->log_buf + offset; - struct sr_datafeed_packet packet; - struct sr_datafeed_analog analog = { 0 }; - float values[APPA_55II_NUM_PROBES], *val_ptr = values; - int i; + buf = devc->log_buf + offset; + val_ptr = values; /* FIXME: timestamp should be sent in the packet */ sr_dbg("Timestamp: %02d:%02d:%02d", buf[2], buf[3], buf[4]); + memset(&analog, 0, sizeof(analog)); analog.num_samples = 1; analog.mq = SR_MQ_TEMPERATURE; analog.unit = SR_UNIT_CELSIUS; analog.data = values; - for (i=0; iprobes, i); + for (i = 0; i < APPA_55II_NUM_PROBES; i++) { + temp = RL16(buf + 12 + 2 * i); + probe = g_slist_nth_data(sdi->probes, i); if (!probe->enabled) continue; analog.probes = g_slist_append(analog.probes, probe); @@ -153,15 +183,19 @@ static void appa_55ii_log_data_parse(struct sr_dev_inst *sdi) static void appa_55ii_log_data(struct sr_dev_inst *sdi, const uint8_t *buf) { - struct dev_context *devc = sdi->priv; - const uint8_t *ptr = buf + 4;; - unsigned int size = buf[3]; + struct dev_context *devc; + const uint8_t *ptr; + unsigned int size; + int s; + devc = sdi->priv; if (devc->data_source != DATA_SOURCE_MEMORY) return; + ptr = buf + 4;; + size = buf[3]; while (size > 0) { - int s = MIN(size, sizeof(devc->log_buf) - devc->log_buf_len); + s = MIN(size, sizeof(devc->log_buf) - devc->log_buf_len); memcpy(devc->log_buf + devc->log_buf_len, ptr, s); devc->log_buf_len += s; size -= s; @@ -173,8 +207,9 @@ static void appa_55ii_log_data(struct sr_dev_inst *sdi, const uint8_t *buf) static void appa_55ii_log_end(struct sr_dev_inst *sdi) { - struct dev_context *devc = sdi->priv; + struct dev_context *devc; + devc = sdi->priv; if (devc->data_source != DATA_SOURCE_MEMORY) return; @@ -182,26 +217,39 @@ static void appa_55ii_log_end(struct sr_dev_inst *sdi) } static const uint8_t *appa_55ii_parse_data(struct sr_dev_inst *sdi, - const uint8_t *buf, int len) + const uint8_t *buf, int len) { if (len < 5) - return NULL; /* need more data */ + /* Need more data. */ + return NULL; if (buf[0] != 0x55 || buf[1] != 0x55) - return buf + 1; /* try to re-synchronize on a packet start */ + /* Try to re-synchronize on a packet start. */ + return buf + 1; - if (len < 5+buf[3]) - return NULL; /* need more data */ + if (len < 5 + buf[3]) + /* Need more data. */ + return NULL; if (!appa_55ii_checksum(buf)) - return buf + 4 + buf[3] + 1; /* skip broken packet */ + /* Skip broken packet. */ + return buf + 4 + buf[3] + 1; switch ((PacketType) buf[2]) { - case LIVE_DATA: appa_55ii_live_data(sdi, buf); break; - case LOG_METADATA: appa_55ii_log_metadata(sdi, buf); break; - case LOG_DATA: appa_55ii_log_data(sdi, buf); break; - case LOG_START: break; - case LOG_END: appa_55ii_log_end(sdi); break; + case LIVE_DATA: + appa_55ii_live_data(sdi, buf); + break; + case LOG_METADATA: + appa_55ii_log_metadata(sdi, buf); + break; + case LOG_DATA: + appa_55ii_log_data(sdi, buf); + break; + case LOG_START: + break; + case LOG_END: + appa_55ii_log_end(sdi); + break; } return buf + 4 + buf[3] + 1; @@ -212,6 +260,7 @@ SR_PRIV int appa_55ii_receive_data(int fd, int revents, void *cb_data) struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; + int64_t time; const uint8_t *ptr, *next_ptr, *end_ptr; int len; @@ -253,7 +302,7 @@ SR_PRIV int appa_55ii_receive_data(int fd, int revents, void *cb_data) } if (devc->limit_msec) { - int64_t time = (g_get_monotonic_time() - devc->start_time) / 1000; + time = (g_get_monotonic_time() - devc->start_time) / 1000; if (time > (int64_t)devc->limit_msec) { sr_info("Requested time limit reached."); sdi->driver->dev_acquisition_stop(sdi, devc->session_cb_data);