]> sigrok.org Git - libsigrok.git/commitdiff
rdtech-tc: use literal string for poll command instead of array
authorGerhard Sittig <redacted>
Thu, 16 Mar 2023 01:31:37 +0000 (02:31 +0100)
committerGerhard Sittig <redacted>
Thu, 16 Mar 2023 13:29:30 +0000 (14:29 +0100)
Use a char pointer for the poll command which is a string literal. Which
eliminates the "necessity" to strip the NUL terminator from an array
after its construction. The strlen() for literals also gets resolved at
compile time. Which means that execution cost remains identical.

Rename the variable to lower case, it's not a preprocessor symbol.

src/hardware/rdtech-tc/protocol.c

index 46d0e83e0510d301071707e4ce8c1e539436d076..0c126b14b3f660f59b95ee989888089035948783 100644 (file)
@@ -35,7 +35,7 @@
 #define TC_POLL_PERIOD_MS 100
 #define TC_TIMEOUT_MS 1000
 
-static const char POLL_CMD[] = "getva";
+static const char *poll_cmd = "getva";
 
 #define MAGIC_PAC1 0x31636170UL
 #define MAGIC_PAC2 0x32636170UL
@@ -122,7 +122,7 @@ SR_PRIV int rdtech_tc_probe(struct sr_serial_dev_inst *serial, struct dev_contex
        int len;
        uint8_t poll_pkt[TC_POLL_LEN];
 
-       if (serial_write_blocking(serial, &POLL_CMD, sizeof(POLL_CMD) - 1,
+       if (serial_write_blocking(serial, poll_cmd, strlen(poll_cmd),
                        SERIAL_WRITE_TIMEOUT_MS) < 0) {
                sr_err("Unable to send probe request.");
                return SR_ERR;
@@ -152,7 +152,7 @@ SR_PRIV int rdtech_tc_poll(const struct sr_dev_inst *sdi)
        struct dev_context *devc = sdi->priv;
        struct sr_serial_dev_inst *serial = sdi->conn;
 
-       if (serial_write_blocking(serial, &POLL_CMD, sizeof(POLL_CMD) - 1,
+       if (serial_write_blocking(serial, poll_cmd, strlen(poll_cmd),
                        SERIAL_WRITE_TIMEOUT_MS) < 0) {
                sr_err("Unable to send poll request.");
                return SR_ERR;