]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/gmc-mh-1x-2x/protocol.c
Fix a few "value never read" scan-build warnings.
[libsigrok.git] / src / hardware / gmc-mh-1x-2x / protocol.c
index 5e12e06f35d38f2b641d143fee30c698f4e1e388..68a409b4321b0ef72281388eb1c3ef251b97623f 100644 (file)
  *  @internal
  */
 
+#include <config.h>
 #include <math.h>
 #include <string.h>
 #include "protocol.h"
 
 /* Internal Headers */
-static guchar calc_chksum_14(guchardta);
+static guchar calc_chksum_14(guchar *dta);
 static int chk_msg14(struct sr_dev_inst *sdi);
 
 /** Set or clear flags in devc->mqflags. */
@@ -856,7 +857,7 @@ static void process_msg_inf_13(struct sr_dev_inst *sdi)
                devc->value += pow(10.0, cnt) * dgt;
        }
        sr_spew("process_msg_inf_13() value=%f scale=%f scale1000=%d mq=%d "
-               "unit=%d mqflags=0x%02llx", devc->value, devc->scale,
+               "unit=%d mqflags=0x%02" PRIx64, devc->value, devc->scale,
                devc->scale1000, devc->mq, devc->unit, devc->mqflags);
        if (devc->value != NAN)
                devc->value *= devc->scale * pow(1000.0, devc->scale1000);
@@ -872,7 +873,7 @@ static void process_msg_inf_13(struct sr_dev_inst *sdi)
  *  @param buf Pointer to array of 14 data bytes.
  *  @param[in] raw Write only data bytes, no interpretation.
  */
-void dump_msg14(gucharbuf, gboolean raw)
+void dump_msg14(guchar *buf, gboolean raw)
 {
        if (!buf)
                return;
@@ -896,7 +897,7 @@ void dump_msg14(guchar* buf, gboolean raw)
  *  @param[in] dta Pointer to array of 13 data bytes.
  *  @return Checksum.
  */
-static guchar calc_chksum_14(guchardta)
+static guchar calc_chksum_14(guchar *dta)
 {
        guchar cnt, chs;
 
@@ -937,7 +938,6 @@ static int chk_msg14(struct sr_dev_inst *sdi)
        }
 
        if (devc->buf[1] == 0) { /* Error msg from device! */
-               retc = SR_ERR_ARG;
                switch (devc->buf[2]) {
                case 1: /* Not used */
                        sr_err("Device: Illegal error code!");
@@ -1002,7 +1002,7 @@ SR_PRIV int process_msg14(struct sr_dev_inst *sdi)
                sr_spew("Cmd %d unimplemented!", devc->buf[3]);
                break;
        case 3: /* Read firmware version and status */
-               sr_spew("Cmd 3, Read firmware and status", devc->buf[3]);
+               sr_spew("Cmd 3, Read firmware and status");
                switch (devc->cmd_idx) {
                case 0:
                        devc->fw_ver_maj = devc->buf[5];
@@ -1073,7 +1073,7 @@ SR_PRIV int process_msg14(struct sr_dev_inst *sdi)
                        devc->value += pow(10.0, cnt) * dgt;
                }
                sr_spew("process_msg14() value=%f scale=%f scale1000=%d mq=%d "
-                       "unit=%d mqflags=0x%02llx", devc->value, devc->scale,
+                       "unit=%d mqflags=0x%02" PRIx64, devc->value, devc->scale,
                        devc->scale1000, devc->mq, devc->unit, devc->mqflags);
                if (devc->value != NAN)
                        devc->value *= devc->scale * pow(1000.0, devc->scale1000);
@@ -1261,7 +1261,7 @@ SR_PRIV int gmc_mh_2x_receive_data(int fd, int revents, void *cb_data)
  *  @param[in] params Further parameters (9 bytes)
  *  @param[out] buf Buffer to create msg in (42 bytes).
  */
-void create_cmd_14(guchar addr, guchar func, guchar* params, guchar* buf)
+void create_cmd_14(guchar addr, guchar func, guchar *params, guchar *buf)
 {
        uint8_t dta[GMC_REPLY_SIZE];    /* Unencoded message */
        int cnt;
@@ -1311,7 +1311,8 @@ int req_meas14(const struct sr_dev_inst *sdi)
        devc->cmd_idx = 0;
        create_cmd_14(devc->addr, 8, params, msg);
        devc->req_sent_at = g_get_monotonic_time();
-       if (serial_write_blocking(serial, msg, sizeof(msg), 0) < (int)sizeof(msg)) {
+       if (serial_write_blocking(serial, msg, sizeof(msg),
+                       serial_timeout(serial, sizeof(msg))) < (int)sizeof(msg)) {
                return SR_ERR;
        }
 
@@ -1340,13 +1341,16 @@ int req_stat14(const struct sr_dev_inst *sdi, gboolean power_on)
 
        if (power_on) {
                sr_info("Write some data and wait 3s to turn on powered off device...");
-               if (serial_write_blocking(serial, msg, sizeof(msg), 0) < 0)
+               if (serial_write_blocking(serial, msg, sizeof(msg),
+                               serial_timeout(serial, sizeof(msg))) < 0)
                        return SR_ERR;
                g_usleep(1 * 1000 * 1000);
-               if (serial_write_blocking(serial, msg, sizeof(msg), 0) < 0)
+               if (serial_write_blocking(serial, msg, sizeof(msg),
+                               serial_timeout(serial, sizeof(msg))) < 0)
                        return SR_ERR;
                g_usleep(1 * 1000 * 1000);
-               if (serial_write_blocking(serial, msg, sizeof(msg), 0) < 0)
+               if (serial_write_blocking(serial, msg, sizeof(msg),
+                               serial_timeout(serial, sizeof(msg))) < 0)
                        return SR_ERR;
                g_usleep(1 * 1000 * 1000);
                serial_flush(serial);
@@ -1354,7 +1358,8 @@ int req_stat14(const struct sr_dev_inst *sdi, gboolean power_on)
 
        /* Write message and wait for reply */
        devc->req_sent_at = g_get_monotonic_time();
-       if (serial_write_blocking(serial, msg, sizeof(msg), 0) < (int)sizeof(msg)) {
+       if (serial_write_blocking(serial, msg, sizeof(msg),
+                       serial_timeout(serial, sizeof(msg))) < (int)sizeof(msg)) {
                return SR_ERR;
        }
 
@@ -1531,7 +1536,8 @@ SR_PRIV int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *s
                params[0] = 5;
                params[1] = 5;
                create_cmd_14(devc->addr, 6, params, msg);
-               if (serial_write_blocking(sdi->conn, msg, sizeof(msg), 0) < 0)
+               if (serial_write_blocking(sdi->conn, msg, sizeof(msg),
+                               serial_timeout(sdi->conn, sizeof(msg))) < 0)
                        return SR_ERR;
                else
                        g_usleep(2 * 1000 * 1000); /* Wait to ensure transfer before interface switched off. */