X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fmotech-lps-30x%2Fapi.c;h=0c5817897499d3de0121d5260ac69e06d6e0cf4f;hb=713f3f84806855ae20d723ef33d7dfda97db9e8e;hp=c23f84a1ca49da8e1f7e8e06cd0079f4f8dbb754;hpb=1beccaed464a4d92a070988a0331fe399f9f7a7a;p=libsigrok.git
diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c
index c23f84a1..0c581789 100644
--- a/src/hardware/motech-lps-30x/api.c
+++ b/src/hardware/motech-lps-30x/api.c
@@ -18,68 +18,49 @@
* along with this program. If not, see .
*/
-/** @file
- * Motech LPS-30x series power supply driver
- * @internal
- */
-
+#include
#include
-#include
#include
#include
-
#include "protocol.h"
-/* Forward declarations */
-SR_PRIV struct sr_dev_driver motech_lps_301_driver_info;
SR_PRIV int lps_read_reply(struct sr_serial_dev_inst *serial, char **buf, int *buflen);
-SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char* fmt, va_list args);
-SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char* fmt, ...);
-SR_PRIV int lps_cmd_reply(char* reply, struct sr_serial_dev_inst *serial, const char* fmt, ...);
-SR_PRIV int lps_query_status(struct sr_dev_inst* sdi);
+SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char *fmt, va_list args);
+SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char *fmt, ...);
+SR_PRIV int lps_cmd_reply(char *reply, struct sr_serial_dev_inst *serial, const char *fmt, ...);
+SR_PRIV int lps_query_status(struct sr_dev_inst *sdi);
-/* Serial communication parameters */
#define SERIALCOMM "2400/8n1/dtr=1/rts=1/flow=0"
-#define VENDOR_MOTECH "Motech"
-
-/** Driver capabilities generic. */
-static const uint32_t drvopts[] = {
- /* Device class */
- SR_CONF_POWER_SUPPLY,
-};
-
-/** Driver scanning options. */
static const uint32_t scanopts[] = {
SR_CONF_CONN,
SR_CONF_SERIALCOMM,
};
-/** Hardware capabilities generic. */
-static const uint32_t devopts[] = {
- /* Device class */
+static const uint32_t drvopts[] = {
SR_CONF_POWER_SUPPLY,
- /* Aquisition modes. */
+};
+
+static const uint32_t devopts[] = {
SR_CONF_CONTINUOUS,
SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
- /* Device configuration */
- SR_CONF_OUTPUT_CHANNEL_CONFIG | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+ SR_CONF_CHANNEL_CONFIG | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
};
/** Hardware capabilities channel 1, 2. */
-static const uint32_t devopts_ch12[] = {
- SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET,
- SR_CONF_OUTPUT_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
- SR_CONF_OUTPUT_CURRENT | SR_CONF_GET,
- SR_CONF_OUTPUT_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
- SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET,
+static const uint32_t devopts_cg_ch12[] = {
+ SR_CONF_VOLTAGE | SR_CONF_GET,
+ SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+ SR_CONF_CURRENT | SR_CONF_GET,
+ SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+ SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
};
-/** Hardware capabilities channel 3. (LPS-304/305 only). */
-static const uint32_t devopts_ch3[] = {
- SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET,
- SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET,
+/** Hardware capabilities channel 3 (LPS-304/305 only). */
+static const uint32_t devopts_cg_ch3[] = {
+ SR_CONF_VOLTAGE | SR_CONF_GET,
+ SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
};
static const char *channel_modes[] = {
@@ -88,7 +69,7 @@ static const char *channel_modes[] = {
"Track2",
};
-static struct lps_modelspec models[] = {
+static const struct lps_modelspec models[] = {
{ LPS_UNKNOWN, "Dummy", 0,
{
@@ -134,14 +115,8 @@ static struct lps_modelspec models[] = {
},
};
-static int init_lps301(struct sr_dev_driver *di, struct sr_context *sr_ctx)
-{
- return std_init(sr_ctx, di, LOG_PREFIX);
-}
-
-/** Send command to device with va_list.
- */
-SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char* fmt, va_list args)
+/** Send command to device with va_list. */
+SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char *fmt, va_list args)
{
int retc;
char auxfmt[LINELEN_MAX];
@@ -152,7 +127,8 @@ SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char* fmt, va_l
sr_spew("lps_send_va: \"%s\"", buf);
- retc = serial_write_blocking(serial, buf, strlen(buf), 0);
+ retc = serial_write_blocking(serial, buf, strlen(buf),
+ serial_timeout(serial, strlen(buf)));
if (retc < 0)
return SR_ERR;
@@ -160,9 +136,8 @@ SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char* fmt, va_l
return SR_OK;
}
-/** Send command to device.
- */
-SR_PRIV int lps_send_req(struct sr_serial_dev_inst *serial, const char* fmt, ...)
+/** Send command to device. */
+SR_PRIV int lps_send_req(struct sr_serial_dev_inst *serial, const char *fmt, ...)
{
int retc;
va_list args;
@@ -175,13 +150,13 @@ SR_PRIV int lps_send_req(struct sr_serial_dev_inst *serial, const char* fmt, ...
}
/** Send command and consume simple OK reply. */
-SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char* fmt, ...)
+SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char *fmt, ...)
{
int retc;
va_list args;
char buf[LINELEN_MAX];
- char* bufptr;
- int buflen;
+ char *bufptr;
+ int buflen;
/* Send command */
va_start(args, fmt);
@@ -202,16 +177,17 @@ SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char* fmt, ...)
return SR_ERR;
}
-/** Send command and read reply string.
- * \param reply Pointer to buffer of size LINELEN_MAX. Will be NUL-terminated.
+/**
+ * Send command and read reply string.
+ * @param reply Pointer to buffer of size LINELEN_MAX. Will be NUL-terminated.
*/
-SR_PRIV int lps_cmd_reply(char* reply, struct sr_serial_dev_inst *serial, const char* fmt, ...)
+SR_PRIV int lps_cmd_reply(char *reply, struct sr_serial_dev_inst *serial, const char *fmt, ...)
{
int retc;
va_list args;
char buf[LINELEN_MAX];
- char* bufptr;
- int buflen;
+ char *bufptr;
+ int buflen;
reply[0] = '\0';
@@ -237,12 +213,12 @@ SR_PRIV int lps_cmd_reply(char* reply, struct sr_serial_dev_inst *serial, const
}
/** Process integer value returned by STATUS command. */
-SR_PRIV int lps_process_status(struct sr_dev_inst* sdi, int stat)
+SR_PRIV int lps_process_status(struct sr_dev_inst *sdi, int stat)
{
- struct dev_context* devc;
+ struct dev_context *devc;
int tracking_mode;
- devc = (struct dev_context*)sdi->priv;
+ devc = sdi->priv;
sr_spew("Status: %d", stat);
devc->channel_status[0].cc_mode = (stat & 0x01) != 0;
@@ -283,18 +259,19 @@ SR_PRIV int lps_process_status(struct sr_dev_inst* sdi, int stat)
}
/** Send STATUS commend and process status string. */
-SR_PRIV int lps_query_status(struct sr_dev_inst* sdi)
+SR_PRIV int lps_query_status(struct sr_dev_inst *sdi)
{
char buf[LINELEN_MAX];
- int stat;
- struct dev_context* devc;
+ int stat, ret;
+ struct dev_context *devc;
- devc = (struct dev_context*)sdi->priv;
+ devc = sdi->priv;
devc->req_sent_at = g_get_real_time();
- if (lps_cmd_reply(buf, sdi->conn, "STATUS") < 0) {
- sr_err("%s: Failed to read status: %d %s", __func__, errno, strerror(errno));
+ if ((ret = lps_cmd_reply(buf, sdi->conn, "STATUS")) < 0) {
+ sr_err("%s: Failed to read status: %s.", __func__,
+ sr_strerror(ret));
return SR_ERR;
}
@@ -314,9 +291,11 @@ static gint64 calc_timeout_ms(gint64 start_us)
return result;
}
-/** Read message into buf until "OK" received.
- * \retval SR_OK Msg received; buf and buflen contain result, if any except OK.
- * \retval SR_ERR Error, including timeout.
+/**
+ * Read message into buf until "OK" received.
+ *
+ * @retval SR_OK Msg received; buf and buflen contain result, if any except OK.
+ * @retval SR_ERR Error, including timeout.
*/
SR_PRIV int lps_read_reply(struct sr_serial_dev_inst *serial, char **buf, int *buflen)
{
@@ -368,19 +347,16 @@ SR_PRIV int lps_read_reply(struct sr_serial_dev_inst *serial, char **buf, int *b
return SR_ERR; /* Timeout! */
}
-/** Scan for LPS-300 series device.
- */
+/** Scan for LPS-300 series device. */
static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *options)
{
struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
struct sr_channel *ch;
struct sr_channel_group *cg;
- GSList *devices;
const char *conn, *serialcomm;
- int cnt;
+ int cnt, ret;
gchar buf[LINELEN_MAX];
gchar channel[10];
char *verstr;
@@ -388,12 +364,6 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
sdi = NULL;
devc = NULL;
conn = serialcomm = NULL;
- devices = NULL;
-
- drvc = drv->priv;
- drvc->instances = NULL;
-
- sr_spew("scan() called!");
/* Process and check options. */
if (sr_serial_extract_options(options, &conn, &serialcomm) != SR_OK)
@@ -435,7 +405,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
/* Query version */
verstr = NULL;
- if (lps_cmd_reply(buf, serial, "VERSION") == SR_OK) {
+ if ((ret = lps_cmd_reply(buf, serial, "VERSION")) == SR_OK) {
if (strncmp(buf, "Ver-", 4)) {
sr_spew("Version string %s not recognized.", buf);
goto exit_err;
@@ -444,25 +414,22 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
g_strstrip(buf);
verstr = buf + 4;
}
- else /* Bug in device FW 1.17: Quering version string fails while output is active.
+ else /* Bug in device FW 1.17: Querying version string fails while output is active.
Therefore just print an error message, but do not exit with error. */
- sr_err("Failed to query for hardware version: %d %s", errno, strerror(errno));
+ sr_err("Failed to query for hardware version: %s.",
+ sr_strerror(ret));
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
- sdi->vendor = g_strdup(VENDOR_MOTECH);
+ sdi->vendor = g_strdup("Motech");
sdi->model = g_strdup(models[modelid].modelstr);
sdi->version = g_strdup(verstr);
- sdi->driver = drv;
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
devc = g_malloc0(sizeof(struct dev_context));
+ sr_sw_limits_init(&devc->limits);
devc->model = &models[modelid];
- devc->limit_samples = 0;
- devc->limit_msec = 0;
- devc->num_samples = 0;
- devc->elapsed_msec = g_timer_new();
sdi->priv = devc;
@@ -482,30 +449,22 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
- drvc->instances = g_slist_append(drvc->instances, sdi);
- devices = g_slist_append(devices, sdi);
-
/* Query status */
if (lps_query_status(sdi) != SR_OK)
goto exit_err;
serial_close(serial);
- if (!devices)
- sr_serial_dev_inst_free(serial);
- return devices;
+ return std_scan_complete(drv, g_slist_append(NULL, sdi));
exit_err:
sr_info("%s: Error!", __func__);
- if (serial) {
+ if (serial)
serial_close(serial);
- sr_serial_dev_inst_free(serial);
- }
- if (devc)
- g_free(devc);
- if (sdi)
- sr_dev_inst_free(sdi);
+ sr_serial_dev_inst_free(serial);
+ g_free(devc);
+ sr_dev_inst_free(sdi);
return NULL;
}
@@ -516,34 +475,22 @@ static GSList *scan_lps301(struct sr_dev_driver *di, GSList *options)
return do_scan(LPS_301, di, options);
}
-static GSList *dev_list_lps301(const struct sr_dev_driver *di)
-{
- return ((struct drv_context *)(di->priv))->instances;
-}
-
-static void dev_clear_private(struct dev_context* devc)
+static void clear_helper(struct dev_context *devc)
{
int ch_idx;
/* Free channel_status.info (list only, data owned by sdi). */
for (ch_idx = 0; ch_idx < devc->model->num_channels; ch_idx++)
g_slist_free(devc->channel_status[ch_idx].info);
-
- g_timer_destroy(devc->elapsed_msec);
-}
-
-static int dev_clear_lps301(const struct sr_dev_driver *di)
-{
- return std_dev_clear(di, (std_dev_clear_callback)dev_clear_private);
}
-static int cleanup(const struct sr_dev_driver *di)
+static int dev_clear(const struct sr_dev_driver *di)
{
- return dev_clear_lps301(di);
+ return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper);
}
-static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
- const struct sr_channel_group *cg)
+static int config_get(uint32_t key, GVariant **data,
+ const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc;
struct sr_channel *ch;
@@ -555,15 +502,11 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
devc = sdi->priv;
if (!cg) {
- /* No channel group: global options. */
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;
- case SR_CONF_OUTPUT_CHANNEL_CONFIG:
+ return sr_sw_limits_config_get(&devc->limits, key, data);
+ case SR_CONF_CHANNEL_CONFIG:
*data = g_variant_new_string(channel_modes[devc->tracking_mode]);
break;
default:
@@ -573,20 +516,21 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
/* We only ever have one channel per channel group in this driver. */
ch = cg->channels->data;
ch_idx = ch->index;
+
switch (key) {
- case SR_CONF_OUTPUT_VOLTAGE:
+ case SR_CONF_VOLTAGE:
*data = g_variant_new_double(devc->channel_status[ch_idx].output_voltage_last);
break;
- case SR_CONF_OUTPUT_VOLTAGE_TARGET:
+ case SR_CONF_VOLTAGE_TARGET:
*data = g_variant_new_double(devc->channel_status[ch_idx].output_voltage_max);
break;
- case SR_CONF_OUTPUT_CURRENT:
+ case SR_CONF_CURRENT:
*data = g_variant_new_double(devc->channel_status[ch_idx].output_current_last);
break;
- case SR_CONF_OUTPUT_CURRENT_LIMIT:
+ case SR_CONF_CURRENT_LIMIT:
*data = g_variant_new_double(devc->channel_status[ch_idx].output_current_max);
break;
- case SR_CONF_OUTPUT_ENABLED:
+ case SR_CONF_ENABLED:
*data = g_variant_new_boolean(devc->channel_status[ch_idx].output_enabled);
break;
default:
@@ -597,20 +541,15 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
return SR_OK;
}
-static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
- const struct sr_channel_group *cg)
+static int config_set(uint32_t key, GVariant *data,
+ const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc;
struct sr_channel *ch;
gdouble dval;
int ch_idx;
- const char *sval;
gboolean bval;
int idx;
- gboolean found;
-
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
@@ -620,53 +559,31 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
return SR_ERR_NA;
if (!cg) {
- /* No channel group: global options. */
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;
- case SR_CONF_OUTPUT_CHANNEL_CONFIG:
- sval = g_variant_get_string(data, NULL);
- found = FALSE;
- for (idx = 0; idx < (int)ARRAY_SIZE(channel_modes); idx++)
- {
- if (!strcmp(sval, channel_modes[idx])) {
- found = TRUE;
- if (devc->tracking_mode == idx)
- break; /* Nothing to do! */
- devc->tracking_mode = idx;
- if (devc->model->modelid >= LPS_304) /* No use to set anything in the smaller models. */
- return lps_cmd_ok(sdi->conn, "TRACK%1d", devc->tracking_mode);
- }
- if (devc->model->modelid <= LPS_303) /* Only first setting possible for smaller models. */
- break;
- }
- if (!found) {
+ return sr_sw_limits_config_set(&devc->limits, key, data);
+ case SR_CONF_CHANNEL_CONFIG:
+ if ((idx = std_str_idx(data, ARRAY_AND_SIZE(channel_modes))) < 0)
return SR_ERR_ARG;
- }
+ if (devc->model->modelid <= LPS_303 && idx != 0)
+ break; /* Only first setting possible for smaller models. */
+ if (devc->tracking_mode == idx)
+ break; /* Nothing to do! */
+ devc->tracking_mode = idx;
+ if (devc->model->modelid >= LPS_304) /* No use to set anything in the smaller models. */
+ return lps_cmd_ok(sdi->conn, "TRACK%1d", devc->tracking_mode);
break;
default:
return SR_ERR_NA;
}
} else {
- /* Channel group specified: per-channel options. */
/* We only ever have one channel per channel group in this driver. */
ch = cg->channels->data;
ch_idx = ch->index;
switch (key) {
- case SR_CONF_OUTPUT_VOLTAGE_TARGET:
+ case SR_CONF_VOLTAGE_TARGET:
dval = g_variant_get_double(data);
if (dval < 0 || dval > devc->model->channels[ch_idx].voltage[1])
return SR_ERR_ARG;
@@ -687,7 +604,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
else
return lps_cmd_ok(sdi->conn, "VSET%d %05.3f", ch_idx+1, dval);
break;
- case SR_CONF_OUTPUT_CURRENT_LIMIT:
+ case SR_CONF_CURRENT_LIMIT:
dval = g_variant_get_double(data);
if (dval < 0 || dval > devc->model->channels[ch_idx].current[1])
return SR_ERR_ARG;
@@ -695,8 +612,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
return SR_ERR_NA;
devc->channel_status[ch_idx].output_current_max = dval;
return lps_cmd_ok(sdi->conn, "ISET%d %05.4f", ch_idx+1, dval);
- break;
- case SR_CONF_OUTPUT_ENABLED:
+ case SR_CONF_ENABLED:
bval = g_variant_get_boolean(data);
if (bval == devc->channel_status[ch_idx].output_enabled) /* Nothing to do. */
break;
@@ -719,87 +635,50 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
return SR_OK;
}
-static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
- const struct sr_channel_group *cg)
+static int config_list(uint32_t key, GVariant **data,
+ const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc;
struct sr_channel *ch;
- int ch_idx, i;
- GVariant *gvar;
- GVariantBuilder gvb;
-
- (void)data;
-
- /* Driver options, no device instance necessary. */
- switch (key) {
- case SR_CONF_SCAN_OPTIONS:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
- return SR_OK;
- case SR_CONF_DEVICE_OPTIONS:
- if (sdi != NULL)
- break;
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
- return SR_OK;
- default:
- if (sdi == NULL)
- return SR_ERR_ARG;
+ int ch_idx;
- devc = sdi->priv;
- }
+ devc = (sdi) ? sdi->priv : NULL;
- /* Device options, independent from channel groups. */
- if (cg == NULL) {
+ if (!cg) {
switch (key) {
+ case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
- return SR_OK;
- case SR_CONF_OUTPUT_CHANNEL_CONFIG:
+ return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
+ case SR_CONF_CHANNEL_CONFIG:
if (devc->model->modelid <= LPS_303) {
/* The 1-channel models. */
*data = g_variant_new_strv(channel_modes, 1);
} else {
/* The other models support all modes. */
- *data = g_variant_new_strv(channel_modes, ARRAY_SIZE(channel_modes));
+ *data = g_variant_new_strv(ARRAY_AND_SIZE(channel_modes));
}
return SR_OK;
- break;
default:
return SR_ERR_NA;
}
}
- /* Device options, depending on channel groups. */
+ /* We only ever have one channel per channel group in this driver. */
ch = cg->channels->data;
ch_idx = ch->index;
+
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
if ((ch_idx == 0) || (ch_idx == 1)) /* CH1, CH2 */
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- devopts_ch12, ARRAY_SIZE(devopts_ch12), sizeof(uint32_t));
+ *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_ch12));
else /* Must be CH3 */
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- devopts_ch3, ARRAY_SIZE(devopts_ch3), sizeof(uint32_t));
+ *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_ch3));
break;
- case SR_CONF_OUTPUT_VOLTAGE_TARGET:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- for (i = 0; i < 3; i++) {
- gvar = g_variant_new_double(devc->model->channels[ch_idx].voltage[i]);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ case SR_CONF_VOLTAGE_TARGET:
+ *data = std_gvar_min_max_step_array(devc->model->channels[ch_idx].voltage);
break;
- case SR_CONF_OUTPUT_CURRENT_LIMIT:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- for (i = 0; i < 3; i++) {
- gvar = g_variant_new_double(devc->model->channels[ch_idx].current[i]);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ case SR_CONF_CURRENT_LIMIT:
+ *data = std_gvar_min_max_step_array(devc->model->channels[ch_idx].current);
break;
default:
return SR_ERR_NA;
@@ -808,15 +687,11 @@ 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)
{
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
devc = sdi->priv;
devc->acq_running = TRUE;
@@ -824,11 +699,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
serial = sdi->conn;
serial_source_add(sdi->session, serial, G_IO_IN, 50,
motech_lps_30x_receive_data, (void *)sdi);
- std_session_send_df_header(cb_data, LOG_PREFIX);
+ std_session_send_df_header(sdi);
- /* Start timer, if required. */
- if (devc->limit_msec)
- g_timer_start(devc->elapsed_msec);
+ sr_sw_limits_acquisition_start(&devc->limits);
devc->acq_req = AQ_NONE;
/* Do not start polling device here, the read function will do it in 50 ms. */
@@ -836,33 +709,22 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
return SR_OK;
}
-static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
-{
- 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, cb_data, std_serial_dev_close,
- sdi->conn, LOG_PREFIX);
-}
-
-SR_PRIV struct sr_dev_driver motech_lps_301_driver_info = {
+static struct sr_dev_driver motech_lps_301_driver_info = {
.name = "motech-lps-301",
.longname = "Motech LPS-301",
.api_version = 1,
- .init = init_lps301,
- .cleanup = cleanup,
+ .init = std_init,
+ .cleanup = std_cleanup,
.scan = scan_lps301,
- .dev_list = dev_list_lps301,
- .dev_clear = dev_clear_lps301,
+ .dev_list = std_dev_list,
+ .dev_clear = dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,
.dev_open = std_serial_dev_open,
.dev_close = std_serial_dev_close,
.dev_acquisition_start = dev_acquisition_start,
- .dev_acquisition_stop = dev_acquisition_stop,
- .priv = NULL,
+ .dev_acquisition_stop = std_serial_dev_acquisition_stop,
+ .context = NULL,
};
+SR_REGISTER_DEV_DRIVER(motech_lps_301_driver_info);