X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fgmc-mh-1x-2x%2Fapi.c;h=048a0afc6e3d2909853e4b49ca7c91accd92c249;hb=7dcaddd3f0df3a87dae252eb1f64f7b0e3997b8f;hp=3d18ebdab81858057d0ec04311b46638a35631a8;hpb=15a5bfe4815f9991a9bb532c05d6244a1818a0e4;p=libsigrok.git diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 3d18ebda..048a0afc 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -144,7 +144,6 @@ static enum model scan_model_sm(struct sr_serial_dev_inst *serial) static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; - struct drv_context *drvc; struct dev_context *devc; struct sr_config *src; struct sr_serial_dev_inst *serial; @@ -154,7 +153,6 @@ static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options) gboolean serialcomm_given; devices = NULL; - drvc = di->context; conn = serialcomm = NULL; serialcomm_given = FALSE; @@ -209,11 +207,8 @@ static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options) sdi->vendor = g_strdup(VENDOR_GMC); sdi->model = g_strdup(gmc_model_str(model)); devc = g_malloc0(sizeof(struct dev_context)); + sr_sw_limits_init(&devc->limits); devc->model = model; - devc->limit_samples = 0; - devc->limit_msec = 0; - devc->num_samples = 0; - devc->elapsed_msec = g_timer_new(); devc->settings_ok = FALSE; sdi->conn = serial; sdi->priv = devc; @@ -231,7 +226,6 @@ static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options) static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; - struct drv_context *drvc; struct dev_context *devc; struct sr_config *src; struct sr_serial_dev_inst *serial; @@ -245,8 +239,6 @@ static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options) conn = serialcomm = NULL; devices = NULL; - drvc = di->context; - sr_spew("scan_2x_bd232() called!"); for (l = options; l; l = l->next) { @@ -303,7 +295,7 @@ static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options) if (devc->model != METRAHIT_NONE) { sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(devc->model)); - devc->elapsed_msec = g_timer_new(); + sr_sw_limits_init(&devc->limits); sdi->model = g_strdup(gmc_model_str(devc->model)); sdi->version = g_strdup_printf("Firmware %d.%d", devc->fw_ver_maj, devc->fw_ver_min); sdi->conn = serial; @@ -344,13 +336,8 @@ static int dev_close(struct sr_dev_inst *sdi) std_serial_dev_close(sdi); sdi->status = SR_ST_INACTIVE; - - /* Free dynamically allocated resources. */ - if ((devc = sdi->priv) && devc->elapsed_msec) { - g_timer_destroy(devc->elapsed_msec); - devc->elapsed_msec = NULL; + if ((devc = sdi->priv)) devc->model = METRAHIT_NONE; - } return SR_OK; } @@ -371,11 +358,8 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s ret = SR_OK; switch (key) { case SR_CONF_LIMIT_SAMPLES: - *data = g_variant_new_uint64(devc->limit_samples); - break; case SR_CONF_LIMIT_MSEC: - *data = g_variant_new_uint64(devc->limit_msec); - break; + return sr_sw_limits_config_get(&devc->limits, key, data); case SR_CONF_POWER_OFF: *data = g_variant_new_boolean(FALSE); break; @@ -449,11 +433,8 @@ static int dev_acquisition_start_1x_2x_rs232(const struct sr_dev_inst *sdi) devc->settings_ok = FALSE; devc->buflen = 0; - std_session_send_df_header(sdi, LOG_PREFIX); - - /* Start timer, if required. */ - if (devc->limit_msec) - g_timer_start(devc->elapsed_msec); + sr_sw_limits_acquisition_start(&devc->limits); + std_session_send_df_header(sdi); /* Poll every 40ms, or whenever some data comes in. */ serial = sdi->conn; @@ -475,11 +456,8 @@ static int dev_acquisition_start_2x_bd232(const struct sr_dev_inst *sdi) devc->settings_ok = FALSE; devc->buflen = 0; - std_session_send_df_header(sdi, LOG_PREFIX); - - /* Start timer, if required. */ - if (devc->limit_msec) - g_timer_start(devc->elapsed_msec); + sr_sw_limits_acquisition_start(&devc->limits); + std_session_send_df_header(sdi); /* Poll every 40ms, or whenever some data comes in. */ serial = sdi->conn; @@ -490,18 +468,6 @@ static int dev_acquisition_start_2x_bd232(const struct sr_dev_inst *sdi) return req_meas14(sdi); } -static int dev_acquisition_stop(struct sr_dev_inst *sdi) -{ - struct dev_context *devc; - - /* Stop timer, if required. */ - if (sdi && (devc = sdi->priv) && devc->limit_msec) - g_timer_stop(devc->elapsed_msec); - - return std_serial_dev_acquisition_stop(sdi, dev_close, - sdi->conn, LOG_PREFIX); -} - static struct sr_dev_driver gmc_mh_1x_2x_rs232_driver_info = { .name = "gmc-mh-1x-2x-rs232", .longname = "Gossen Metrawatt Metrahit 1x/2x, RS232 interface", @@ -517,7 +483,7 @@ static struct sr_dev_driver gmc_mh_1x_2x_rs232_driver_info = { .dev_open = std_serial_dev_open, .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start_1x_2x_rs232, - .dev_acquisition_stop = dev_acquisition_stop, + .dev_acquisition_stop = std_serial_dev_acquisition_stop, .context = NULL, }; SR_REGISTER_DEV_DRIVER(gmc_mh_1x_2x_rs232_driver_info); @@ -537,7 +503,7 @@ static struct sr_dev_driver gmc_mh_2x_bd232_driver_info = { .dev_open = std_serial_dev_open, .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start_2x_bd232, - .dev_acquisition_stop = dev_acquisition_stop, + .dev_acquisition_stop = std_serial_dev_acquisition_stop, .context = NULL, }; SR_REGISTER_DEV_DRIVER(gmc_mh_2x_bd232_driver_info);