X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fappa-55ii%2Fapi.c;h=ddf3fe4a11885468a041838e1ab8d01a0300c2ea;hb=bde6a99b33fd520152c05183f5b80cff63d75675;hp=6598757b67d8a6b23ec24f6c5f5f9d34a958255d;hpb=aac29cc192ccf82b64e77b5e6b11b411da32deed;p=libsigrok.git
diff --git a/src/hardware/appa-55ii/api.c b/src/hardware/appa-55ii/api.c
index 6598757b..ddf3fe4a 100644
--- a/src/hardware/appa-55ii/api.c
+++ b/src/hardware/appa-55ii/api.c
@@ -17,6 +17,7 @@
* along with this program. If not, see .
*/
+#include
#include
#include "protocol.h"
@@ -30,7 +31,7 @@ static const uint32_t drvopts[] = {
};
static const uint32_t devopts[] = {
- SR_CONF_CONTINUOUS | SR_CONF_SET,
+ SR_CONF_CONTINUOUS,
SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
SR_CONF_DATA_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
@@ -41,21 +42,11 @@ static const char *data_sources[] = {
"Memory",
};
-SR_PRIV struct sr_dev_driver appa_55ii_driver_info;
-static struct sr_dev_driver *di = &appa_55ii_driver_info;
-
-static int init(struct sr_context *sr_ctx)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- return std_init(sr_ctx, di, LOG_PREFIX);
-}
-
-static GSList *scan(GSList *options)
-{
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
struct sr_dev_inst *sdi;
- struct sr_channel *ch;
struct sr_config *src;
GSList *devices, *l;
const char *conn, *serialcomm;
@@ -81,15 +72,13 @@ static GSList *scan(GSList *options)
if (!serialcomm)
serialcomm = "9600/8n1";
- if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
- return NULL;
+ serial = sr_serial_dev_inst_new(conn, serialcomm);
+
if (serial_open(serial, SERIAL_RDONLY) != SR_OK)
return NULL;
sr_info("Probing serial port %s.", conn);
- drvc = di->priv;
- drvc->instances = NULL;
serial_flush(serial);
/* Let's get a bit of data and see if we can find a packet. */
@@ -103,47 +92,25 @@ static GSList *scan(GSList *options)
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("APPA");
sdi->model = g_strdup("55II");
-
- if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
- sr_err("Device context malloc failed.");
- goto scan_cleanup;
- }
-
+ devc = g_malloc0(sizeof(struct dev_context));
devc->data_source = DEFAULT_DATA_SOURCE;
-
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
- sdi->driver = di;
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "T1")))
- goto scan_cleanup;
- sdi->channels = g_slist_append(sdi->channels, ch);
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "T2")))
- goto scan_cleanup;
- sdi->channels = g_slist_append(sdi->channels, ch);
+ sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "T1");
+ sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "T2");
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
scan_cleanup:
serial_close(serial);
- return devices;
-}
-
-static GSList *dev_list(void)
-{
- return ((struct drv_context *)(di->priv))->instances;
-}
-
-static int cleanup(void)
-{
- return std_dev_clear(di, NULL);
+ return std_scan_complete(di, devices);
}
-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 = sdi->priv;
@@ -151,11 +118,8 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
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_DATA_SOURCE:
*data = g_variant_new_string(data_sources[devc->data_source]);
break;
@@ -166,43 +130,25 @@ 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;
- const char *tmp_str;
- unsigned int i;
+ int idx;
(void)cg;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
- if (!(devc = sdi->priv)) {
- sr_err("sdi->priv was NULL.");
- return SR_ERR_BUG;
- }
+ devc = sdi->priv;
switch (key) {
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_LIMIT_MSEC:
- devc->limit_msec = g_variant_get_uint64(data);
- sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec);
- break;
- case SR_CONF_DATA_SOURCE: {
- tmp_str = g_variant_get_string(data, NULL);
- for (i = 0; i < ARRAY_SIZE(data_sources); i++)
- if (!strcmp(tmp_str, data_sources[i])) {
- devc->data_source = i;
- break;
- }
- if (i == ARRAY_SIZE(data_sources))
- return SR_ERR;
+ return sr_sw_limits_config_set(&devc->limits, key, data);
+ case SR_CONF_DATA_SOURCE:
+ if ((idx = std_str_idx(data, ARRAY_AND_SIZE(data_sources))) < 0)
+ return SR_ERR_ARG;
+ devc->data_source = idx;
break;
- }
default:
return SR_ERR_NA;
}
@@ -210,27 +156,15 @@ 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)
{
- (void)sdi;
- (void)cg;
-
switch (key) {
case SR_CONF_SCAN_OPTIONS:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
- break;
case SR_CONF_DEVICE_OPTIONS:
- if (!sdi)
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
- else
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
- break;
+ return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_DATA_SOURCE:
- *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
+ *data = g_variant_new_strv(ARRAY_AND_SIZE(data_sources));
break;
default:
return SR_ERR_NA;
@@ -239,62 +173,40 @@ 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 sr_serial_dev_inst *serial;
struct dev_context *devc;
serial = sdi->conn;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
- if (!(devc = sdi->priv)) {
- sr_err("sdi->priv was NULL.");
- return SR_ERR_BUG;
- }
+ devc = sdi->priv;
- devc->session_cb_data = cb_data;
+ sr_sw_limits_acquisition_start(&devc->limits);
- /*
- * Reset the number of samples to take. If we've already collected our
- * quota, but we start a new session, and don't reset this, we'll just
- * quit without acquiring any new samples.
- */
- devc->num_samples = 0;
- devc->start_time = g_get_monotonic_time();
+ std_session_send_df_header(sdi);
- /* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
-
- /* Poll every 50ms, or whenever some data comes in. */
serial_source_add(sdi->session, serial, G_IO_IN, 50,
appa_55ii_receive_data, (void *)sdi);
return SR_OK;
}
-static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
-{
- return std_serial_dev_acquisition_stop(sdi, cb_data,
- std_serial_dev_close, sdi->conn, LOG_PREFIX);
-}
-
-SR_PRIV struct sr_dev_driver appa_55ii_driver_info = {
+static struct sr_dev_driver appa_55ii_driver_info = {
.name = "appa-55ii",
.longname = "APPA 55II",
.api_version = 1,
- .init = init,
- .cleanup = cleanup,
+ .init = std_init,
+ .cleanup = std_cleanup,
.scan = scan,
- .dev_list = dev_list,
- .dev_clear = NULL,
+ .dev_list = std_dev_list,
+ .dev_clear = std_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(appa_55ii_driver_info);