From: Uwe Hermann Date: Tue, 30 Oct 2012 17:50:15 +0000 (+0100) Subject: agilent-dmm: Use message logging helpers. X-Git-Tag: dsupstream~612 X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=38d326e879c6e1bb7d4a11682c262ca838a7dde5;p=libsigrok.git agilent-dmm: Use message logging helpers. --- diff --git a/hardware/agilent-dmm/agilent-dmm.h b/hardware/agilent-dmm/agilent-dmm.h index 4c8ecac4..b2b6ba3b 100644 --- a/hardware/agilent-dmm/agilent-dmm.h +++ b/hardware/agilent-dmm/agilent-dmm.h @@ -21,6 +21,15 @@ #ifndef LIBSIGROK_AGILENT_DMM_H #define LIBSIGROK_AGILENT_DMM_H +/* Message logging helpers with driver-specific prefix string. */ +#define DRIVER_LOG_DOMAIN "agilent-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 AGDMM_BUFSIZE 256 /* Supported models */ diff --git a/hardware/agilent-dmm/api.c b/hardware/agilent-dmm/api.c index 7987086e..b6af3bbd 100644 --- a/hardware/agilent-dmm/api.c +++ b/hardware/agilent-dmm/api.c @@ -95,7 +95,7 @@ static int hw_init(void) struct drv_context *drvc; if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { - sr_err("agilent-dmm: driver context malloc failed."); + sr_err("Driver context malloc failed."); return SR_ERR; } @@ -140,7 +140,7 @@ static int serial_readline(int fd, char **buf, int *buflen, uint64_t timeout_ms) break; } if (*buflen) - sr_dbg("agilent-dmm: received '%s'", *buf); + sr_dbg("Received '%s'.", *buf); return SR_OK; } @@ -177,20 +177,20 @@ static GSList *hw_scan(GSList *options) return NULL; if ((fd = serial_open(conn, O_RDWR|O_NONBLOCK)) == -1) { - sr_err("agilent-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("agilent-dmm: unable to set serial parameters: %s", - strerror(errno)); + sr_err("Unable to set serial parameters: %s.", + strerror(errno)); return NULL; } serial_flush(fd); if (serial_write(fd, "*IDN?\r\n", 7) == -1) { - sr_err("agilent-dmm: unable to send identification string: %s", - strerror(errno)); + sr_err("Unable to send identification string: %s.", + strerror(errno)); return NULL; } @@ -210,7 +210,7 @@ static GSList *hw_scan(GSList *options) tokens[1], tokens[3]))) return NULL; if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { - sr_dbg("agilent-dmm: failed to malloc devc"); + sr_dbg("failed to malloc devc"); return NULL; } devc->profile = &supported_agdmm[i]; @@ -248,13 +248,13 @@ static int hw_dev_open(struct sr_dev_inst *sdi) struct dev_context *devc; if (!(devc = sdi->priv)) { - sr_err("agilent-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("agilent-dmm: Couldn't open serial port '%s'.", + sr_err("Couldn't open serial port '%s'.", devc->serial->port); return SR_ERR; } @@ -270,7 +270,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi) struct dev_context *devc; if (!(devc = sdi->priv)) { - sr_err("agilent-dmm: sdi->priv was NULL."); + sr_err("sdi->priv was NULL."); return SR_ERR_BUG; } @@ -326,7 +326,7 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, return SR_ERR; if (!(devc = sdi->priv)) { - sr_err("agilent-dmm: sdi->priv was NULL."); + sr_err("sdi->priv was NULL."); return SR_ERR_BUG; } @@ -334,20 +334,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("agilent-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("agilent-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("agilent-dmm: Setting sample limit to %" PRIu64 ".", + sr_dbg("Setting sample limit to %" PRIu64 ".", devc->limit_samples); break; default: - sr_err("agilent-dmm: Unknown capability: %d.", hwcap); + sr_err("Unknown capability: %d.", hwcap); return SR_ERR; break; } @@ -364,16 +364,16 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, struct dev_context *devc; if (!(devc = sdi->priv)) { - sr_err("agilent-dmm: sdi->priv was NULL."); + sr_err("sdi->priv was NULL."); return SR_ERR_BUG; } - sr_dbg("agilent-dmm: Starting acquisition."); + sr_dbg("Starting acquisition."); devc->cb_data = cb_data; /* Send header packet to the session bus. */ - sr_dbg("agilent-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; @@ -381,7 +381,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("agilent-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; @@ -403,17 +403,17 @@ static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, return SR_ERR; if (!(devc = sdi->priv)) { - sr_err("agilent-dmm: sdi->priv was NULL."); + sr_err("sdi->priv was NULL."); return SR_ERR_BUG; } - sr_dbg("agilent-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("agilent-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/agilent-dmm/sched.c b/hardware/agilent-dmm/sched.c index 6687953a..140c5340 100644 --- a/hardware/agilent-dmm/sched.c +++ b/hardware/agilent-dmm/sched.c @@ -26,7 +26,6 @@ #include #include - static void dispatch(const struct sr_dev_inst *sdi) { struct dev_context *devc; @@ -39,12 +38,11 @@ static void dispatch(const struct sr_dev_inst *sdi) now = g_get_monotonic_time() / 1000; for (i = 0; (&jobs[i])->interval; i++) { if (now - devc->jobqueue[i] > (&jobs[i])->interval) { - sr_spew("agilent-dmm: running job %d", i); + sr_spew("Running job %d.", i); (&jobs[i])->send(sdi); devc->jobqueue[i] = now; } } - } static void receive_line(const struct sr_dev_inst *sdi) @@ -65,7 +63,7 @@ static void receive_line(const struct sr_dev_inst *sdi) else break; } - sr_spew("agilent-dmm: received '%s'", devc->buf); + sr_spew("Received '%s'.", devc->buf); recv = NULL; recvs = devc->profile->recvs; @@ -83,11 +81,10 @@ static void receive_line(const struct sr_dev_inst *sdi) g_match_info_unref(match); g_regex_unref(reg); } else - sr_dbg("agilent-dmm: unknown line '%s'", devc->buf); + sr_dbg("Unknown line '%s'.", devc->buf); /* Done with this. */ devc->buflen = 0; - } SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data) @@ -132,14 +129,14 @@ static int agdmm_send(const struct sr_dev_inst *sdi, const char *cmd) char buf[32]; devc = sdi->priv; - sr_spew("agilent-dmm: sending '%s'", cmd); + sr_spew("Sending '%s'.", cmd); strncpy(buf, cmd, 28); if (!strncmp(buf, "*IDN?", 5)) strncat(buf, "\r\n", 32); else strncat(buf, "\n\r\n", 32); if (serial_write(devc->serial->fd, buf, strlen(buf)) == -1) { - sr_err("agilent-dmm: failed to send: %s", strerror(errno)); + sr_err("Failed to send: %s.", strerror(errno)); return SR_ERR; } @@ -148,7 +145,6 @@ static int agdmm_send(const struct sr_dev_inst *sdi, const char *cmd) static int send_stat(const struct sr_dev_inst *sdi) { - return agdmm_send(sdi, "STAT?"); } @@ -159,7 +155,7 @@ static int recv_stat_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match) devc = sdi->priv; s = g_match_info_fetch(match, 1); - sr_spew("agilent-dmm: STAT response '%s'", s); + sr_spew("STAT response '%s'.", s); /* Max, Min or Avg mode -- no way to tell which, so we'll * set both flags to denote it's not a normal measurement. */ @@ -185,7 +181,7 @@ static int recv_stat_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match) else devc->mode_tempaux = FALSE; - /* Continuity mode. */ + /* Continuity mode. */ if (s[16] == '1') devc->mode_continuity = TRUE; else @@ -203,7 +199,7 @@ static int recv_stat_u125x(const struct sr_dev_inst *sdi, GMatchInfo *match) devc = sdi->priv; s = g_match_info_fetch(match, 1); - sr_spew("agilent-dmm: STAT response '%s'", s); + sr_spew("STAT response '%s'.", s); /* Peak hold mode. */ if (s[4] == '1') @@ -224,7 +220,6 @@ static int recv_stat_u125x(const struct sr_dev_inst *sdi, GMatchInfo *match) static int send_fetc(const struct sr_dev_inst *sdi) { - return agdmm_send(sdi, "FETC?"); } @@ -236,7 +231,7 @@ static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match) float fvalue; char *mstr, *eptr; - sr_spew("agilent-dmm: FETC reply '%s'", g_match_info_get_string(match)); + sr_spew("FETC reply '%s'.", g_match_info_get_string(match)); devc = sdi->priv; if (devc->cur_mq == -1) @@ -255,7 +250,7 @@ static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match) fvalue = strtof(mstr, &eptr); g_free(mstr); if (fvalue == 0.0 && eptr == mstr) { - sr_err("agilent-dmm: invalid float"); + sr_err("Invalid float."); return SR_ERR; } if (devc->cur_divider > 0) @@ -279,7 +274,6 @@ static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match) static int send_conf(const struct sr_dev_inst *sdi) { - return agdmm_send(sdi, "CONF?"); } @@ -288,7 +282,7 @@ static int recv_conf_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match) struct dev_context *devc; char *mstr; - sr_spew("agilent-dmm: CONF? response '%s'", g_match_info_get_string(match)); + sr_spew("CONF? response '%s'.", g_match_info_get_string(match)); devc = sdi->priv; mstr = g_match_info_fetch(match, 1); if (!strcmp(mstr, "V")) { @@ -341,7 +335,7 @@ static int recv_conf_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match) devc->cur_mqflags = 0; devc->cur_divider = 0; } else - sr_dbg("agilent-dmm: unknown first argument"); + sr_dbg("Unknown first argument."); g_free(mstr); if (g_match_info_get_match_count(match) == 4) { @@ -352,7 +346,7 @@ static int recv_conf_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match) else if (!strcmp(mstr, "DC")) devc->cur_mqflags |= SR_MQFLAG_DC; else - sr_dbg("agilent-dmm: unknown third argument"); + sr_dbg("Unknown third argument."); g_free(mstr); } else devc->cur_mqflags &= ~(SR_MQFLAG_AC | SR_MQFLAG_DC); @@ -365,7 +359,7 @@ static int recv_conf_u125x(const struct sr_dev_inst *sdi, GMatchInfo *match) struct dev_context *devc; char *mstr; - sr_spew("agilent-dmm: CONF? response '%s'", g_match_info_get_string(match)); + sr_spew("CONF? response '%s'.", g_match_info_get_string(match)); devc = sdi->priv; mstr = g_match_info_fetch(match, 1); if (!strncmp(mstr, "VOLT", 4)) { @@ -398,11 +392,10 @@ static int recv_conf_u125x(const struct sr_dev_inst *sdi, GMatchInfo *match) } devc->cur_mqflags = 0; devc->cur_divider = 0; -} else - sr_dbg("agilent-dmm: unknown first argument"); + } else + sr_dbg("Unknown first argument."); g_free(mstr); - return SR_OK; } @@ -412,7 +405,7 @@ static int recv_conf(const struct sr_dev_inst *sdi, GMatchInfo *match) struct dev_context *devc; char *mstr; - sr_spew("agilent-dmm: CONF? response '%s'", g_match_info_get_string(match)); + sr_spew("CONF? response '%s'.", g_match_info_get_string(match)); devc = sdi->priv; mstr = g_match_info_fetch(match, 1); if(!strcmp(mstr, "DIOD")) { @@ -421,7 +414,7 @@ static int recv_conf(const struct sr_dev_inst *sdi, GMatchInfo *match) devc->cur_mqflags = SR_MQFLAG_DIODE; devc->cur_divider = 0; } else - sr_dbg("agilent-dmm: unknown single argument"); + sr_dbg("Unknown single argument."); g_free(mstr); return SR_OK; @@ -433,15 +426,13 @@ static int recv_conf(const struct sr_dev_inst *sdi, GMatchInfo *match) * we do need to catch this here, or it'll show up in some other output. */ static int recv_switch(const struct sr_dev_inst *sdi, GMatchInfo *match) { - (void)sdi; - sr_spew("agilent-dmm: switch '%s'", g_match_info_get_string(match)); + sr_spew("Switch '%s'.", g_match_info_get_string(match)); return SR_OK; } - SR_PRIV const struct agdmm_job agdmm_jobs_u123x[] = { { 143, send_stat }, { 1000, send_conf }, @@ -475,5 +466,3 @@ SR_PRIV const struct agdmm_recv agdmm_recvs_u125x[] = { { "^\"(DIOD)\"$", recv_conf }, { NULL, NULL } }; - -