From: Paul Kasemir Date: Mon, 12 Dec 2022 19:00:18 +0000 (-0700) Subject: link-mso19: Rename variables to be more descriptive X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6d0e682e7e1d7ff8eb31e453d22dfd000eddea52;p=libsigrok.git link-mso19: Rename variables to be more descriptive --- diff --git a/src/hardware/link-mso19/protocol.c b/src/hardware/link-mso19/protocol.c index 299e6f00..3f5c99a7 100644 --- a/src/hardware/link-mso19/protocol.c +++ b/src/hardware/link-mso19/protocol.c @@ -34,30 +34,33 @@ static const char mso_foot[] = { 0x7e }; static int mso_send_control_message(struct sr_serial_dev_inst *serial, uint16_t payload[], int n) { - int w, ret; - int payload_s = n * sizeof(*payload); - int s = payload_s + sizeof(mso_head) + sizeof(mso_foot); - char *p, *buf; + int written, ret, payload_size, total_size; + char *copy_ptr, *buf; + payload_size = n * sizeof(*payload); + total_size = payload_size + sizeof(mso_head) + sizeof(mso_foot); ret = SR_ERR; - buf = g_malloc(s); - - p = buf; - memcpy(p, mso_head, sizeof(mso_head)); - p += sizeof(mso_head); - memcpy(p, payload, payload_s); - p += payload_s; - memcpy(p, mso_foot, sizeof(mso_foot)); - - w = 0; - while (w < s) { - ret = serial_write_blocking(serial, buf + w, s - w, 10); + buf = g_malloc(total_size); + + copy_ptr = buf; + memcpy(copy_ptr, mso_head, sizeof(mso_head)); + copy_ptr += sizeof(mso_head); + memcpy(copy_ptr, payload, payload_size); + copy_ptr += payload_size; + memcpy(copy_ptr, mso_foot, sizeof(mso_foot)); + + written = 0; + while (written < total_size) { + ret = serial_write_blocking(serial, + buf + written, + total_size - written, + 10); if (ret < 0) { ret = SR_ERR; goto free; } - w += ret; + written += ret; } ret = SR_OK; free: @@ -173,23 +176,23 @@ SR_PRIV uint16_t mso_calc_trigger_threshold(struct dev_context *devc) devc->vbit)); } -SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct, +SR_PRIV int mso_parse_serial(const char *serial_num, const char *product, struct dev_context *devc) { unsigned int u1, u2, u3, u4, u5, u6; - (void)iProduct; + (void)product; /* FIXME: This code is in the original app, but I think its * used only for the GUI */ - /* if (strstr(iProduct, "REV_02") || strstr(iProduct, "REV_03")) + /* if (strstr(product, "REV_02") || strstr(product, "REV_03")) devc->num_sample_rates = 0x16; else devc->num_sample_rates = 0x10; */ /* parse iSerial */ - if (iSerial[0] != '4' || sscanf(iSerial, "%5u%3u%3u%1u%1u%6u", - &u1, &u2, &u3, &u4, &u5, &u6) != 6) + if (serial_num[0] != '4' || sscanf(serial_num, "%5u%3u%3u%1u%1u%6u", + &u1, &u2, &u3, &u4, &u5, &u6) != 6) return SR_ERR; if (u1 == 0) u1 = 42874; @@ -205,7 +208,7 @@ SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct, /* * FIXME: There is more code on the original software to handle - * bigger iSerial strings, but as I can't test on my device + * bigger serial_num strings, but as I can't test on my device * I will not implement it yet */ diff --git a/src/hardware/link-mso19/protocol.h b/src/hardware/link-mso19/protocol.h index 56ec45f3..487d7d2c 100644 --- a/src/hardware/link-mso19/protocol.h +++ b/src/hardware/link-mso19/protocol.h @@ -114,7 +114,7 @@ struct dev_context { char buffer[4096]; }; -SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct, +SR_PRIV int mso_parse_serial(const char *serial_num, const char *product, struct dev_context *ctx); SR_PRIV int mso_read_status(struct sr_serial_dev_inst *serial, uint8_t *status);