From: Uwe Hermann Date: Tue, 30 Oct 2012 17:48:33 +0000 (+0100) Subject: fluke-dmm: Use message logging helpers. X-Git-Tag: dsupstream~613 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=31d84da3a22cc6fc9b2226ab3863e9235a3d5b87;p=libsigrok.git fluke-dmm: Use message logging helpers. --- diff --git a/hardware/fluke-dmm/api.c b/hardware/fluke-dmm/api.c index d6c322ac..69ce1724 100644 --- a/hardware/fluke-dmm/api.c +++ b/hardware/fluke-dmm/api.c @@ -86,7 +86,7 @@ static int hw_init(void) struct drv_context *drvc; if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { - sr_err("fluke-dmm: driver context malloc failed."); + sr_err("Driver context malloc failed."); return SR_ERR; } @@ -124,7 +124,7 @@ static int serial_readline(int fd, char **buf, int *buflen, uint64_t timeout_ms) break; g_usleep(2000); } - sr_dbg("fluke-dmm: received %d: '%s'", *buflen, *buf); + sr_dbg("Received %d: '%s'.", *buflen, *buf); return SR_OK; } @@ -140,11 +140,11 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) char buf[128], *b, **tokens; if ((fd = serial_open(conn, O_RDWR|O_NONBLOCK)) == -1) { - sr_err("fluke-dmm: unable to open %s: %s", conn, strerror(errno)); + sr_err("Unable to open %s: %s.", conn, strerror(errno)); return NULL; } if (serial_set_paramstr(fd, serialcomm) != SR_OK) { - sr_err("fluke-dmm: unable to set serial parameters"); + sr_err("Unable to set serial parameters."); return NULL; } @@ -158,8 +158,8 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) retry++; serial_flush(fd); if (serial_write(fd, "ID\r", 3) == -1) { - sr_err("fluke-dmm: unable to send ID string: %s", - strerror(errno)); + sr_err("Unable to send ID string: %s.", + strerror(errno)); continue; } @@ -189,7 +189,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) tokens[0] + 6, tokens[1] + s))) return NULL; if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { - sr_dbg("fluke-dmm: failed to malloc devc"); + sr_err("Device context malloc failed."); return NULL; } devc->profile = &supported_flukedmm[i]; @@ -261,18 +261,17 @@ static int hw_dev_open(struct sr_dev_inst *sdi) struct dev_context *devc; if (!(devc = sdi->priv)) { - sr_err("fluke-dmm: sdi->priv was NULL."); + sr_err("sdi->priv was NULL."); return SR_ERR_BUG; } devc->serial->fd = serial_open(devc->serial->port, O_RDWR | O_NONBLOCK); if (devc->serial->fd == -1) { - sr_err("fluke-dmm: Couldn't open serial port '%s'.", - devc->serial->port); + sr_err("Couldn't open serial port '%s'.", devc->serial->port); return SR_ERR; } if (serial_set_paramstr(devc->serial->fd, devc->serialcomm) != SR_OK) { - sr_err("fluke-dmm: unable to set serial parameters"); + sr_err("Unable to set serial parameters."); return SR_ERR; } sdi->status = SR_ST_ACTIVE; @@ -285,7 +284,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi) struct dev_context *devc; if (!(devc = sdi->priv)) { - sr_err("fluke-dmm: sdi->priv was NULL."); + sr_err("sdi->priv was NULL."); return SR_ERR_BUG; } @@ -341,7 +340,7 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, return SR_ERR; if (!(devc = sdi->priv)) { - sr_err("fluke-dmm: sdi->priv was NULL."); + sr_err("sdi->priv was NULL."); return SR_ERR_BUG; } @@ -349,20 +348,20 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, case SR_HWCAP_LIMIT_MSEC: /* TODO: not yet implemented */ if (*(const uint64_t *)value == 0) { - sr_err("fluke-dmm: LIMIT_MSEC can't be 0."); + sr_err("LIMIT_MSEC can't be 0."); return SR_ERR; } devc->limit_msec = *(const uint64_t *)value; - sr_dbg("fluke-dmm: Setting time limit to %" PRIu64 "ms.", + sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec); break; case SR_HWCAP_LIMIT_SAMPLES: devc->limit_samples = *(const uint64_t *)value; - sr_dbg("fluke-dmm: Setting sample limit to %" PRIu64 ".", + sr_dbg("Setting sample limit to %" PRIu64 ".", devc->limit_samples); break; default: - sr_err("fluke-dmm: Unknown capability: %d.", hwcap); + sr_err("Unknown capability: %d.", hwcap); return SR_ERR; break; } @@ -379,16 +378,16 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, struct dev_context *devc; if (!(devc = sdi->priv)) { - sr_err("fluke-dmm: sdi->priv was NULL."); + sr_err("sdi->priv was NULL."); return SR_ERR_BUG; } - sr_dbg("fluke-dmm: Starting acquisition."); + sr_dbg("Starting acquisition."); devc->cb_data = cb_data; /* Send header packet to the session bus. */ - sr_dbg("fluke-dmm: Sending SR_DF_HEADER."); + sr_dbg("Sending SR_DF_HEADER."); packet.type = SR_DF_HEADER; packet.payload = (uint8_t *)&header; header.feed_version = 1; @@ -396,7 +395,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, sr_session_send(devc->cb_data, &packet); /* Send metadata about the SR_DF_ANALOG packets to come. */ - sr_dbg("fluke-dmm: Sending SR_DF_META_ANALOG."); + sr_dbg("Sending SR_DF_META_ANALOG."); packet.type = SR_DF_META_ANALOG; packet.payload = &meta; meta.num_probes = 1; @@ -406,7 +405,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, sr_source_add(devc->serial->fd, G_IO_IN, 50, fluke_receive_data, (void *)sdi); if (serial_write(devc->serial->fd, "QM\r", 3) == -1) { - sr_err("fluke-dmm: unable to send QM: %s", strerror(errno)); + sr_err("Unable to send QM: %s.", strerror(errno)); return SR_ERR; } devc->cmd_sent_at = g_get_monotonic_time() / 1000; @@ -425,17 +424,17 @@ static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, return SR_ERR; if (!(devc = sdi->priv)) { - sr_err("fluke-dmm: sdi->priv was NULL."); + sr_err("sdi->priv was NULL."); return SR_ERR_BUG; } - sr_dbg("fluke-dmm: Stopping acquisition."); + sr_dbg("Stopping acquisition."); sr_source_remove(devc->serial->fd); hw_dev_close((struct sr_dev_inst *)sdi); /* Send end packet to the session bus. */ - sr_dbg("fluke-dmm: Sending SR_DF_END."); + sr_dbg("Sending SR_DF_END."); packet.type = SR_DF_END; sr_session_send(cb_data, &packet); diff --git a/hardware/fluke-dmm/fluke-dmm.h b/hardware/fluke-dmm/fluke-dmm.h index 495ff9f3..9994af5c 100644 --- a/hardware/fluke-dmm/fluke-dmm.h +++ b/hardware/fluke-dmm/fluke-dmm.h @@ -21,6 +21,15 @@ #ifndef LIBSIGROK_FLUKE_DMM_H #define LIBSIGROK_FLUKE_DMM_H +/* Message logging helpers with driver-specific prefix string. */ +#define DRIVER_LOG_DOMAIN "fluke-dmm: " +#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args) +#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args) +#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args) +#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args) +#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args) +#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args) + #define FLUKEDMM_BUFSIZE 256 /* Supported models */ diff --git a/hardware/fluke-dmm/fluke.c b/hardware/fluke-dmm/fluke.c index 6506fd23..6719b41c 100644 --- a/hardware/fluke-dmm/fluke.c +++ b/hardware/fluke-dmm/fluke.c @@ -47,7 +47,7 @@ static struct sr_datafeed_analog *handle_qm_v1(const struct sr_dev_inst *sdi, fvalue = strtof(tokens[1], &e); if (fvalue == 0.0 && e == tokens[1]) { /* Happens all the time, when switching modes. */ - sr_dbg("fluke-dmm: invalid float"); + sr_dbg("Invalid float."); return NULL; } } @@ -158,7 +158,7 @@ static struct sr_datafeed_analog *handle_qm_v2(const struct sr_dev_inst *sdi, (void)sdi; fvalue = strtof(tokens[0], &eptr); if (fvalue == 0.0 && eptr == tokens[0]) { - sr_err("fluke-dmm: invalid float"); + sr_err("Invalid float."); return NULL; } @@ -263,12 +263,12 @@ static void handle_line(const struct sr_dev_inst *sdi) char **tokens; devc = sdi->priv; - sr_spew("fluke-dmm: received line '%s' (%d)", devc->buf, devc->buflen); + sr_spew("Received line '%s' (%d).", devc->buf, devc->buflen); if (devc->buflen == 1) { if (devc->buf[0] != '0') { /* Not just a CMD_ACK from the query command. */ - sr_dbg("fluke-dmm: got CMD_ACK '%c'", devc->buf[0]); + sr_dbg("Got CMD_ACK '%c'.", devc->buf[0]); devc->expect_response = FALSE; } devc->buflen = 0; @@ -342,9 +342,9 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data) * or temporary disconnect issues. */ if ((devc->expect_response == FALSE && elapsed > devc->profile->poll_period) || elapsed > 1000) { - sr_spew("fluke-dmm: sending QM"); + sr_spew("Sending QM."); if (serial_write(devc->serial->fd, "QM\r", 3) == -1) - sr_err("fluke-dmm: unable to send QM: %s", strerror(errno)); + sr_err("Unable to send QM: %s.", strerror(errno)); devc->cmd_sent_at = now; devc->expect_response = TRUE; }