gmc-mh-1x-2x: Use software limits helpers
Use the new software limit helper functions rather than open-coding their functionality. This also fixes the issue that driver the does not reset all the limit statistics in acquisition_start(). Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
6aacf011de
commit
3c41387928
|
@ -207,11 +207,8 @@ static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options)
|
||||||
sdi->vendor = g_strdup(VENDOR_GMC);
|
sdi->vendor = g_strdup(VENDOR_GMC);
|
||||||
sdi->model = g_strdup(gmc_model_str(model));
|
sdi->model = g_strdup(gmc_model_str(model));
|
||||||
devc = g_malloc0(sizeof(struct dev_context));
|
devc = g_malloc0(sizeof(struct dev_context));
|
||||||
|
sr_sw_limits_init(&devc->limits);
|
||||||
devc->model = model;
|
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;
|
devc->settings_ok = FALSE;
|
||||||
sdi->conn = serial;
|
sdi->conn = serial;
|
||||||
sdi->priv = devc;
|
sdi->priv = devc;
|
||||||
|
@ -298,7 +295,7 @@ static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options)
|
||||||
|
|
||||||
if (devc->model != METRAHIT_NONE) {
|
if (devc->model != METRAHIT_NONE) {
|
||||||
sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(devc->model));
|
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->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->version = g_strdup_printf("Firmware %d.%d", devc->fw_ver_maj, devc->fw_ver_min);
|
||||||
sdi->conn = serial;
|
sdi->conn = serial;
|
||||||
|
@ -339,13 +336,8 @@ static int dev_close(struct sr_dev_inst *sdi)
|
||||||
std_serial_dev_close(sdi);
|
std_serial_dev_close(sdi);
|
||||||
|
|
||||||
sdi->status = SR_ST_INACTIVE;
|
sdi->status = SR_ST_INACTIVE;
|
||||||
|
if ((devc = sdi->priv))
|
||||||
/* Free dynamically allocated resources. */
|
|
||||||
if ((devc = sdi->priv) && devc->elapsed_msec) {
|
|
||||||
g_timer_destroy(devc->elapsed_msec);
|
|
||||||
devc->elapsed_msec = NULL;
|
|
||||||
devc->model = METRAHIT_NONE;
|
devc->model = METRAHIT_NONE;
|
||||||
}
|
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
@ -366,11 +358,8 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
||||||
ret = SR_OK;
|
ret = SR_OK;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case SR_CONF_LIMIT_SAMPLES:
|
case SR_CONF_LIMIT_SAMPLES:
|
||||||
*data = g_variant_new_uint64(devc->limit_samples);
|
|
||||||
break;
|
|
||||||
case SR_CONF_LIMIT_MSEC:
|
case SR_CONF_LIMIT_MSEC:
|
||||||
*data = g_variant_new_uint64(devc->limit_msec);
|
return sr_sw_limits_config_get(&devc->limits, key, data);
|
||||||
break;
|
|
||||||
case SR_CONF_POWER_OFF:
|
case SR_CONF_POWER_OFF:
|
||||||
*data = g_variant_new_boolean(FALSE);
|
*data = g_variant_new_boolean(FALSE);
|
||||||
break;
|
break;
|
||||||
|
@ -444,12 +433,9 @@ static int dev_acquisition_start_1x_2x_rs232(const struct sr_dev_inst *sdi)
|
||||||
devc->settings_ok = FALSE;
|
devc->settings_ok = FALSE;
|
||||||
devc->buflen = 0;
|
devc->buflen = 0;
|
||||||
|
|
||||||
|
sr_sw_limits_acquisition_start(&devc->limits);
|
||||||
std_session_send_df_header(sdi, LOG_PREFIX);
|
std_session_send_df_header(sdi, LOG_PREFIX);
|
||||||
|
|
||||||
/* Start timer, if required. */
|
|
||||||
if (devc->limit_msec)
|
|
||||||
g_timer_start(devc->elapsed_msec);
|
|
||||||
|
|
||||||
/* Poll every 40ms, or whenever some data comes in. */
|
/* Poll every 40ms, or whenever some data comes in. */
|
||||||
serial = sdi->conn;
|
serial = sdi->conn;
|
||||||
serial_source_add(sdi->session, serial, G_IO_IN, 40,
|
serial_source_add(sdi->session, serial, G_IO_IN, 40,
|
||||||
|
@ -470,12 +456,9 @@ static int dev_acquisition_start_2x_bd232(const struct sr_dev_inst *sdi)
|
||||||
devc->settings_ok = FALSE;
|
devc->settings_ok = FALSE;
|
||||||
devc->buflen = 0;
|
devc->buflen = 0;
|
||||||
|
|
||||||
|
sr_sw_limits_acquisition_start(&devc->limits);
|
||||||
std_session_send_df_header(sdi, LOG_PREFIX);
|
std_session_send_df_header(sdi, LOG_PREFIX);
|
||||||
|
|
||||||
/* Start timer, if required. */
|
|
||||||
if (devc->limit_msec)
|
|
||||||
g_timer_start(devc->elapsed_msec);
|
|
||||||
|
|
||||||
/* Poll every 40ms, or whenever some data comes in. */
|
/* Poll every 40ms, or whenever some data comes in. */
|
||||||
serial = sdi->conn;
|
serial = sdi->conn;
|
||||||
serial_source_add(sdi->session, serial, G_IO_IN, 40,
|
serial_source_add(sdi->session, serial, G_IO_IN, 40,
|
||||||
|
@ -487,12 +470,6 @@ static int dev_acquisition_start_2x_bd232(const struct sr_dev_inst *sdi)
|
||||||
|
|
||||||
static int dev_acquisition_stop(struct sr_dev_inst *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,
|
return std_serial_dev_acquisition_stop(sdi, dev_close,
|
||||||
sdi->conn, LOG_PREFIX);
|
sdi->conn, LOG_PREFIX);
|
||||||
}
|
}
|
||||||
|
|
|
@ -670,7 +670,7 @@ static void send_value(struct sr_dev_inst *sdi)
|
||||||
packet.payload = &analog;
|
packet.payload = &analog;
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
|
|
||||||
devc->num_samples++;
|
sr_sw_limits_update_samples_read(&devc->limits, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Process 6-byte data message, Metrahit 1x/2x send mode. */
|
/** Process 6-byte data message, Metrahit 1x/2x send mode. */
|
||||||
|
@ -1097,7 +1097,6 @@ SR_PRIV int gmc_mh_1x_2x_receive_data(int fd, int revents, void *cb_data)
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
uint8_t buf, msgt;
|
uint8_t buf, msgt;
|
||||||
int len;
|
int len;
|
||||||
gdouble elapsed_s;
|
|
||||||
|
|
||||||
(void)fd;
|
(void)fd;
|
||||||
|
|
||||||
|
@ -1171,16 +1170,9 @@ SR_PRIV int gmc_mh_1x_2x_receive_data(int fd, int revents, void *cb_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If number of samples or time limit reached, stop acquisition. */
|
if (sr_sw_limits_check(&devc->limits))
|
||||||
if (devc->limit_samples && (devc->num_samples >= devc->limit_samples))
|
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
sdi->driver->dev_acquisition_stop(sdi);
|
||||||
|
|
||||||
if (devc->limit_msec) {
|
|
||||||
elapsed_s = g_timer_elapsed(devc->elapsed_msec, NULL);
|
|
||||||
if ((elapsed_s * 1000) >= devc->limit_msec)
|
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1191,7 +1183,6 @@ SR_PRIV int gmc_mh_2x_receive_data(int fd, int revents, void *cb_data)
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
uint8_t buf;
|
uint8_t buf;
|
||||||
int len;
|
int len;
|
||||||
gdouble elapsed_s;
|
|
||||||
|
|
||||||
(void)fd;
|
(void)fd;
|
||||||
|
|
||||||
|
@ -1222,16 +1213,9 @@ SR_PRIV int gmc_mh_2x_receive_data(int fd, int revents, void *cb_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If number of samples or time limit reached, stop acquisition. */
|
if (sr_sw_limits_check(&devc->limits))
|
||||||
if (devc->limit_samples && (devc->num_samples >= devc->limit_samples))
|
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
sdi->driver->dev_acquisition_stop(sdi);
|
||||||
|
|
||||||
if (devc->limit_msec) {
|
|
||||||
elapsed_s = g_timer_elapsed(devc->elapsed_msec, NULL);
|
|
||||||
if ((elapsed_s * 1000) >= devc->limit_msec)
|
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Request next data set, if required */
|
/* Request next data set, if required */
|
||||||
if (sdi->status == SR_ST_ACTIVE) {
|
if (sdi->status == SR_ST_ACTIVE) {
|
||||||
if (devc->response_pending) {
|
if (devc->response_pending) {
|
||||||
|
@ -1539,12 +1523,9 @@ SR_PRIV int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *s
|
||||||
else
|
else
|
||||||
g_usleep(2 * 1000 * 1000); /* Wait to ensure transfer before interface switched off. */
|
g_usleep(2 * 1000 * 1000); /* Wait to ensure transfer before interface switched off. */
|
||||||
break;
|
break;
|
||||||
case SR_CONF_LIMIT_MSEC:
|
|
||||||
devc->limit_msec = g_variant_get_uint64(data);
|
|
||||||
break;
|
|
||||||
case SR_CONF_LIMIT_SAMPLES:
|
case SR_CONF_LIMIT_SAMPLES:
|
||||||
devc->limit_samples = g_variant_get_uint64(data);
|
case SR_CONF_LIMIT_MSEC:
|
||||||
break;
|
return sr_sw_limits_config_set(&devc->limits, key, data);
|
||||||
default:
|
default:
|
||||||
return SR_ERR_NA;
|
return SR_ERR_NA;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,8 +87,7 @@ struct dev_context {
|
||||||
enum model model; /**< Model code. */
|
enum model model; /**< Model code. */
|
||||||
|
|
||||||
/* Acquisition settings */
|
/* Acquisition settings */
|
||||||
uint64_t limit_samples; /**< Target number of samples */
|
struct sr_sw_limits limits;
|
||||||
uint64_t limit_msec; /**< Target sampling time */
|
|
||||||
|
|
||||||
/* Operational state */
|
/* Operational state */
|
||||||
gboolean settings_ok; /**< Settings msg received yet. */
|
gboolean settings_ok; /**< Settings msg received yet. */
|
||||||
|
@ -111,8 +110,6 @@ struct dev_context {
|
||||||
gboolean response_pending; /**< Request sent, response is pending. */
|
gboolean response_pending; /**< Request sent, response is pending. */
|
||||||
|
|
||||||
/* Temporary state across callbacks */
|
/* Temporary state across callbacks */
|
||||||
uint64_t num_samples; /**< Current #samples for limit_samples */
|
|
||||||
GTimer *elapsed_msec; /**< Used for sampling with limit_msec */
|
|
||||||
uint8_t buf[GMC_BUFSIZE]; /**< Buffer for read callback */
|
uint8_t buf[GMC_BUFSIZE]; /**< Buffer for read callback */
|
||||||
int buflen; /**< Data len in buf */
|
int buflen; /**< Data len in buf */
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue