X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fnorma-dmm%2Fapi.c;h=59715ec421d0b4e9c9d35b81ae0d4b803255c70f;hb=1c47e0da8f2571bc34dbdc368c3c1f55318c3aa0;hp=83e11351060bff50bce99157b9a582e75f1359a2;hpb=91219afc75c9aa1d0c5e2da5c03343c1e43eb6df;p=libsigrok.git diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c index 83e11351..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,56 +44,47 @@ 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_norma_dmm(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { - return std_init(sr_ctx, &norma_dmm_driver_info, LOG_PREFIX); + return std_init(sr_ctx, di, LOG_PREFIX); } -static int init_siemens_b102x(struct sr_context *sr_ctx) -{ - return std_init(sr_ctx, &siemens_b102x_driver_info, LOG_PREFIX); -} - -static GSList *do_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; struct dev_context *devc; struct sr_config *src; - struct sr_channel *ch; 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; @@ -119,16 +111,14 @@ static GSList *do_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; } @@ -138,7 +128,7 @@ static GSList *do_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); @@ -155,8 +145,7 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options) sdi->conn = serial; sdi->priv = devc; sdi->driver = drv; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); break; @@ -183,24 +172,9 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options) return devices; } -static GSList *scan_norma_dmm(GSList *options) +static GSList *dev_list(const struct sr_dev_driver *di) { - return do_scan(&norma_dmm_driver_info, options); -} - -static GSList *scan_siemens_b102x(GSList *options) -{ - return do_scan(&siemens_b102x_driver_info, options); -} - -static GSList *dev_list_norma_dmm(void) -{ - return ((struct drv_context *)(norma_dmm_driver_info.priv))->instances; -} - -static GSList *dev_list_siemens_b102x(void) -{ - return ((struct drv_context *)(siemens_b102x_driver_info.priv))->instances; + return ((struct drv_context *)(di->context))->instances; } static int dev_close(struct sr_dev_inst *sdi) @@ -219,14 +193,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup_norma_dmm(void) +static int cleanup(const struct sr_dev_driver *di) { - return std_dev_clear(&norma_dmm_driver_info, NULL); -} - -static int cleanup_siemens_b102x(void) -{ - return std_dev_clear(&siemens_b102x_driver_info, NULL); + return std_dev_clear(di, NULL); } static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, @@ -246,18 +215,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd switch (key) { case SR_CONF_LIMIT_MSEC: - if (g_variant_get_uint64(data) == 0) { - sr_err("LIMIT_MSEC can't be 0."); - return SR_ERR; - } devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: return SR_ERR_NA; @@ -288,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; @@ -302,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. */ @@ -333,10 +292,10 @@ SR_PRIV struct sr_dev_driver norma_dmm_driver_info = { .name = "norma-dmm", .longname = "Norma DM9x0 DMMs", .api_version = 1, - .init = init_norma_dmm, - .cleanup = cleanup_norma_dmm, - .scan = scan_norma_dmm, - .dev_list = dev_list_norma_dmm, + .init = init, + .cleanup = cleanup, + .scan = scan, + .dev_list = dev_list, .dev_clear = NULL, .config_get = NULL, .config_set = config_set, @@ -345,18 +304,17 @@ 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 = { .name = "siemens-b102x", .longname = "Siemens B102x DMMs", .api_version = 1, - .init = init_siemens_b102x, - .cleanup = cleanup_siemens_b102x, - .scan = scan_siemens_b102x, - .dev_list = dev_list_siemens_b102x, + .init = init, + .cleanup = cleanup, + .scan = scan, + .dev_list = dev_list, .dev_clear = NULL, .config_get = NULL, .config_set = config_set, @@ -365,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, };