From: Gerhard Sittig Date: Sun, 20 Sep 2020 07:33:35 +0000 (+0200) Subject: brymen-dmm: style nits, apply comm param defaults, low battery warning X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=11addc897a86a039f72cefbebb5058611ad79102;p=libsigrok.git brymen-dmm: style nits, apply comm param defaults, low battery warning Rephrase how the default serial communication parameters get applied. Preset the variable to the default value and let optional user provided specs override these. This avoids an extra check which is difficult to read and highly redundant. Add a comment for raised awareness that a default port spec is undesirable because it's unreliable. Raise the severity of low battery messages. It's worth warning the user because measurements could be inaccurate. Reduce indentation in continuation lines of a long routine signature, and drop an empty line in a short struct while we are here. --- diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c index 230b6adf..dacbee88 100644 --- a/src/hardware/brymen-dmm/api.c +++ b/src/hardware/brymen-dmm/api.c @@ -111,7 +111,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devices = NULL; - conn = serialcomm = NULL; + /* + * BEWARE! Default 'conn' is not desirable when the device cannot + * reliably get detected. Insist that users specify the port. + */ + conn = NULL; + serialcomm = "9600/8n1/dtr=1/rts=1"; for (l = options; l; l = l->next) { src = l->data; switch (src->key) { @@ -126,10 +131,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (!conn) return NULL; - if (serialcomm) - devices = brymen_scan(di, conn, serialcomm); - else - devices = brymen_scan(di, conn, "9600/8n1/dtr=1/rts=1"); + devices = brymen_scan(di, conn, serialcomm); return devices; } diff --git a/src/hardware/brymen-dmm/parser.c b/src/hardware/brymen-dmm/parser.c index d42ff45a..7fcb3456 100644 --- a/src/hardware/brymen-dmm/parser.c +++ b/src/hardware/brymen-dmm/parser.c @@ -284,7 +284,7 @@ SR_PRIV int brymen_parse(const uint8_t *buf, float *floatval, analog->meaning->mqflags |= SR_MQFLAG_DC; if (flags.is_low_batt) - sr_info("Low battery!"); + sr_warn("Low battery!"); return SR_OK; } diff --git a/src/hardware/brymen-dmm/protocol.h b/src/hardware/brymen-dmm/protocol.h index d5090ee6..ec839d48 100644 --- a/src/hardware/brymen-dmm/protocol.h +++ b/src/hardware/brymen-dmm/protocol.h @@ -40,7 +40,6 @@ enum packet_len_status { struct dev_context { struct sr_sw_limits sw_limits; - uint8_t buf[DMM_BUFSIZE]; int bufoffset; int buflen; @@ -66,9 +65,9 @@ SR_PRIV int brymen_parse(const uint8_t *buf, float *floatval, struct sr_datafeed_analog *analog, void *info); SR_PRIV int brymen_stream_detect(struct sr_serial_dev_inst *serial, - uint8_t *buf, size_t *buflen, - packet_length_t get_packet_size, - packet_valid_callback is_valid, - uint64_t timeout_ms, int baudrate); + uint8_t *buf, size_t *buflen, + packet_length_t get_packet_size, + packet_valid_callback is_valid, + uint64_t timeout_ms, int baudrate); #endif