#include "protocol.h"
-static const int32_t hwopts[] = {
+static const uint32_t scanopts[] = {
SR_CONF_CONN,
SR_CONF_SERIALCOMM,
};
-static const int32_t hwcaps[] = {
+static const uint32_t drvopts[] = {
SR_CONF_THERMOMETER,
- SR_CONF_LIMIT_SAMPLES,
- SR_CONF_LIMIT_MSEC,
- SR_CONF_CONTINUOUS,
+};
+
+static const uint32_t devopts[] = {
+ SR_CONF_CONTINUOUS | SR_CONF_SET,
+ SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
+ SR_CONF_LIMIT_MSEC | SR_CONF_SET,
};
static const char *channel_names[] = {
"T1", "T2", "T3", "T4",
- NULL,
};
SR_PRIV struct sr_dev_driver center_309_driver_info;
static int init(struct sr_context *sr_ctx, int idx)
{
- sr_dbg("Selected '%s' subdriver.", center_devs[idx].di->name);
-
return std_init(sr_ctx, center_devs[idx].di, LOG_PREFIX);
}
struct sr_dev_inst *sdi;
struct drv_context *drvc;
struct dev_context *devc;
- struct sr_channel *ch;
struct sr_serial_dev_inst *serial;
GSList *devices;
- if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
- return NULL;
+ serial = sr_serial_dev_inst_new(conn, serialcomm);
- if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
+ if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;
drvc = center_devs[idx].di->priv;
sr_info("Found device on port %s.", conn);
- if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, center_devs[idx].vendor,
- center_devs[idx].device, NULL)))
- goto scan_cleanup;
-
- if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
- sr_err("Device context malloc failed.");
- goto scan_cleanup;
- }
-
+ sdi = g_malloc0(sizeof(struct sr_dev_inst));
+ sdi->status = SR_ST_INACTIVE;
+ sdi->vendor = g_strdup(center_devs[idx].vendor);
+ sdi->model = g_strdup(center_devs[idx].device);
+ devc = g_malloc0(sizeof(struct dev_context));
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
-
sdi->priv = devc;
sdi->driver = center_devs[idx].di;
- for (i = 0; i < center_devs[idx].num_channels; i++) {
- if (!(ch = sr_channel_new(i, SR_CHANNEL_ANALOG,
- TRUE, channel_names[i])))
- goto scan_cleanup;
- sdi->channels = g_slist_append(sdi->channels, ch);
- }
+ for (i = 0; i < center_devs[idx].num_channels; i++)
+ sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);
drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
-scan_cleanup:
serial_close(serial);
return devices;
return dev_clear(idx);
}
-static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
+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;
devc = sdi->priv;
- switch (id) {
+ switch (key) {
case SR_CONF_LIMIT_SAMPLES:
if (g_variant_get_uint64(data) == 0)
return SR_ERR_ARG;
return SR_OK;
}
-static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
+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_INT32,
- hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+ scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
- hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
+ 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;
default:
return SR_ERR_NA;
/* Driver-specific API function wrappers */
#define HW_INIT(X) \
-static int init_##X(struct sr_context *sr_ctx) { return init(sr_ctx, X); }
+static int init_##X(struct sr_dev_driver *d, \
+ struct sr_context *sr_ctx) { (void)d; return init(sr_ctx, X); }
#define HW_CLEANUP(X) \
-static int cleanup_##X(void) { return cleanup(X); }
+static int cleanup_##X(const struct sr_dev_driver *d) { \
+ (void)d; return cleanup(X); }
#define HW_SCAN(X) \
-static GSList *scan_##X(GSList *options) { return scan(options, X); }
+static GSList *scan_##X(struct sr_dev_driver *d, GSList *options) { \
+ (void)d; return scan(options, X); }
#define HW_DEV_LIST(X) \
-static GSList *dev_list_##X(void) { return dev_list(X); }
+static GSList *dev_list_##X(const struct sr_dev_driver *d) { \
+ (void)d; return dev_list(X); }
#define HW_DEV_CLEAR(X) \
-static int dev_clear_##X(void) { return dev_clear(X); }
+static int dev_clear_##X(const struct sr_dev_driver *d) { \
+ (void)d; return dev_clear(X); }
#define HW_DEV_ACQUISITION_START(X) \
static int dev_acquisition_start_##X(const struct sr_dev_inst *sdi, \
void *cb_data) { return dev_acquisition_start(sdi, cb_data, X); }