X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fnorma-dmm%2Fapi.c;h=59715ec421d0b4e9c9d35b81ae0d4b803255c70f;hb=1c47e0da8f2571bc34dbdc368c3c1f55318c3aa0;hp=bf44df2756da534b9e00349e49c31c9d105936f9;hpb=dcd438ee3523098201c7937e75e55775da3b506f;p=libsigrok.git diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c index bf44df27..59715ec4 100644 --- a/src/hardware/norma-dmm/api.c +++ b/src/hardware/norma-dmm/api.c @@ -22,6 +22,7 @@ * @internal */ +#include #include "protocol.h" static const uint32_t scanopts[] = { @@ -43,27 +44,25 @@ static const uint32_t devopts[] = { SR_PRIV struct sr_dev_driver norma_dmm_driver_info; SR_PRIV struct sr_dev_driver siemens_b102x_driver_info; -static const char* get_brandstr(struct sr_dev_driver* drv) +static const char *get_brandstr(struct sr_dev_driver *drv) { - if (drv == &norma_dmm_driver_info) - return "Norma"; - else - return "Siemens"; + return (drv == &norma_dmm_driver_info) ? "Norma" : "Siemens"; } -static const char* get_typestr(int type, struct sr_dev_driver* drv) +static const char *get_typestr(int type, struct sr_dev_driver *drv) { - static const char* nameref[5][2] = { + static const char *nameref[5][2] = { {"DM910", "B1024"}, {"DM920", "B1025"}, {"DM930", "B1026"}, {"DM940", "B1027"}, - {"DM950", "B1028"}}; + {"DM950", "B1028"}, + }; if ((type < 1) || (type > 5)) return "Unknown type!"; - return nameref[type-1][(drv == &siemens_b102x_driver_info)]; + return nameref[type - 1][(drv == &siemens_b102x_driver_info)]; } static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) @@ -71,7 +70,7 @@ static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(struct sr_dev_driver* drv, GSList *options) +static GSList *scan(struct sr_dev_driver *drv, GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; @@ -79,14 +78,13 @@ static GSList *scan(struct sr_dev_driver* drv, GSList *options) struct sr_config *src; struct sr_serial_dev_inst *serial; GSList *l, *devices; - int len, cnt; + int len, cnt, auxtype; const char *conn, *serialcomm; char *buf; char req[10]; - int auxtype; devices = NULL; - drvc = drv->priv; + drvc = drv->context; drvc->instances = NULL; conn = serialcomm = NULL; @@ -113,16 +111,14 @@ static GSList *scan(struct sr_dev_driver* drv, GSList *options) serial_flush(serial); - if (!(buf = g_try_malloc(BUF_MAX))) { - sr_err("Serial buffer malloc failed."); - return NULL; - } + buf = g_malloc(BUF_MAX); snprintf(req, sizeof(req), "%s\r\n", nmadmm_requests[NMADMM_REQ_IDN].req_str); g_usleep(150 * 1000); /* Wait a little to allow serial port to settle. */ for (cnt = 0; cnt < 7; cnt++) { - if (serial_write_blocking(serial, req, strlen(req), 0) < 0) { + if (serial_write_blocking(serial, req, strlen(req), + serial_timeout(serial, strlen(req))) < 0) { sr_err("Unable to send identification request."); return NULL; } @@ -132,7 +128,7 @@ static GSList *scan(struct sr_dev_driver* drv, GSList *options) continue; buf[BUF_MAX - 1] = '\0'; - /* Match ID string, e.g. "1834 065 V1.06,IF V1.02" (DM950) */ + /* Match ID string, e.g. "1834 065 V1.06,IF V1.02" (DM950). */ if (g_regex_match_simple("^1834 [^,]*,IF V*", (char *)buf, 0, 0)) { auxtype = xgittoint(buf[7]); sr_spew("%s %s DMM %s detected!", get_brandstr(drv), get_typestr(auxtype, drv), buf + 9); @@ -178,7 +174,7 @@ static GSList *scan(struct sr_dev_driver* drv, GSList *options) static GSList *dev_list(const struct sr_dev_driver *di) { - return ((struct drv_context *)(di->priv))->instances; + return ((struct drv_context *)(di->context))->instances; } static int dev_close(struct sr_dev_inst *sdi) @@ -253,8 +249,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * return SR_OK; } -static int dev_acquisition_start(const struct sr_dev_inst *sdi, - void *cb_data) +static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; struct sr_serial_dev_inst *serial; @@ -267,7 +262,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, devc->cb_data = cb_data; - /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX); /* Start timer, if required. */ @@ -310,7 +304,7 @@ SR_PRIV struct sr_dev_driver norma_dmm_driver_info = { .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, }; SR_PRIV struct sr_dev_driver siemens_b102x_driver_info = { @@ -329,5 +323,5 @@ SR_PRIV struct sr_dev_driver siemens_b102x_driver_info = { .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, };