]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/gmc-mh-1x-2x/protocol.c
Fix log varargs bugs indicated by -Wformat
[libsigrok.git] / src / hardware / gmc-mh-1x-2x / protocol.c
index 719a225f30b3f550563df3dfde5d6a112b557e39..6cd8694fb55603547da9d6a62549e04b87abb1e1 100644 (file)
@@ -27,7 +27,7 @@
 #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 +856,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 +872,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,11 +896,11 @@ 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;
 
-       for (chs = 0, cnt = 0; cnt < 13; cnt++)
+       for (chs = 0, cnt = 0; cnt < (GMC_REPLY_SIZE - 1); cnt++)
                chs += dta[cnt];
 
        return (64 - chs) & MASK_6BITS;
@@ -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,9 +1261,9 @@ 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[14];        /* Unencoded message */
+       uint8_t dta[GMC_REPLY_SIZE];    /* Unencoded message */
        int cnt;
 
        if (!params || !buf)
@@ -1279,17 +1279,17 @@ void create_cmd_14(guchar addr, guchar func, guchar* params, guchar* buf)
 
        /* 4-12: Copy further parameters */
        for (cnt = 0; cnt < 9; cnt++)
-               dta[cnt+4] = (params[cnt] & MASK_6BITS);
+               dta[cnt + 4] = (params[cnt] & MASK_6BITS);
 
        /* 13: Checksum (b complement) */
        dta[13] = calc_chksum_14(dta);
 
        /* The whole message is packed into 3 bytes per byte now (lower 6 bits only) the most
         * peculiar way I have ever seen. Possibly to improve IR communication? */
-       for (cnt = 0; cnt < 14; cnt++) {
-               buf[3*cnt] = (dta[cnt] & 0x01 ? 0x0f : 0) | (dta[cnt] & 0x02 ? 0xf0 : 0);
-               buf[3*cnt + 1] = (dta[cnt] & 0x04 ? 0x0f : 0) | (dta[cnt] & 0x08 ? 0xf0 : 0);
-               buf[3*cnt + 2] = (dta[cnt] & 0x10 ? 0x0f : 0) | (dta[cnt] & 0x20 ? 0xf0 : 0);
+       for (cnt = 0; cnt < GMC_REPLY_SIZE; cnt++) {
+               buf[(3 * cnt) + 0] = (dta[cnt] & 0x01 ? 0x0f : 0) | (dta[cnt] & 0x02 ? 0xf0 : 0);
+               buf[(3 * cnt) + 1] = (dta[cnt] & 0x04 ? 0x0f : 0) | (dta[cnt] & 0x08 ? 0xf0 : 0);
+               buf[(3 * cnt) + 2] = (dta[cnt] & 0x10 ? 0x0f : 0) | (dta[cnt] & 0x20 ? 0xf0 : 0);
        }
 }