]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/gmc-mh-1x-2x/protocol.c
windows: Fix various compiler warnings.
[libsigrok.git] / src / hardware / gmc-mh-1x-2x / protocol.c
index 6f96d504601c1a65f227b7d63853997dbba40b46..5e12e06f35d38f2b641d143fee30c698f4e1e388 100644 (file)
@@ -257,7 +257,7 @@ static void decode_ctmv_18(uint8_t ctmv, struct dev_context *devc)
 /**
  * Decode range/sign/acdc byte special chars, Metrahit 18.
  *
- * @param[in] rs Rance/sign byte.
+ * @param[in] rs Range/sign byte.
  */
 static void decode_rs_18(uint8_t rs, struct dev_context *devc)
 {
@@ -900,7 +900,7 @@ 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;
@@ -1236,7 +1236,7 @@ SR_PRIV int gmc_mh_2x_receive_data(int fd, int revents, void *cb_data)
        if (sdi->status == SR_ST_ACTIVE) {
                if (devc->response_pending) {
                        gint64 elapsed_us = g_get_monotonic_time() - devc->req_sent_at;
-                       if (elapsed_us > 1*1000*1000) /* Timeout! */
+                       if (elapsed_us > (1 * 1000 * 1000)) /* Timeout! */
                                devc->response_pending = FALSE;
                }
                if (!devc->response_pending) {
@@ -1263,7 +1263,7 @@ SR_PRIV int gmc_mh_2x_receive_data(int fd, int revents, void *cb_data)
  */
 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);
        }
 }
 
@@ -1342,13 +1342,13 @@ int req_stat14(const struct sr_dev_inst *sdi, gboolean 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)
                        return SR_ERR;
-               g_usleep(1*1000*1000);
+               g_usleep(1 * 1000 * 1000);
                if (serial_write_blocking(serial, msg, sizeof(msg), 0) < 0)
                        return SR_ERR;
-               g_usleep(1*1000*1000);
+               g_usleep(1 * 1000 * 1000);
                if (serial_write_blocking(serial, msg, sizeof(msg), 0) < 0)
                        return SR_ERR;
-               g_usleep(1*1000*1000);
+               g_usleep(1 * 1000 * 1000);
                serial_flush(serial);
        }
 
@@ -1534,7 +1534,7 @@ SR_PRIV int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *s
                if (serial_write_blocking(sdi->conn, msg, sizeof(msg), 0) < 0)
                        return SR_ERR;
                else
-                       g_usleep(2000000); /* Wait to ensure transfer before interface switched off. */
+                       g_usleep(2 * 1000 * 1000); /* Wait to ensure transfer before interface switched off. */
                break;
        case SR_CONF_LIMIT_MSEC:
                devc->limit_msec = g_variant_get_uint64(data);