#include "protocol.h"
+static const uint32_t drvopts[] = {
+ /* Device class */
+ SR_CONF_POWER_SUPPLY,
+};
+
static const uint32_t scanopts[] = {
SR_CONF_CONN,
SR_CONF_SERIALCOMM,
};
SR_PRIV struct sr_dev_driver manson_hcs_3xxx_driver_info;
-static struct sr_dev_driver *di = &manson_hcs_3xxx_driver_info;
-static int dev_clear(void)
+static int dev_clear(const struct sr_dev_driver *di)
{
return std_dev_clear(di, NULL);
}
-static int init(struct sr_context *sr_ctx)
+static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
{
return std_init(sr_ctx, di, LOG_PREFIX);
}
-static GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
int i, model_id;
struct drv_context *drvc;
struct dev_context *devc;
struct sr_dev_inst *sdi;
struct sr_config *src;
- struct sr_channel *ch;
GSList *devices, *l;
const char *conn, *serialcomm;
struct sr_serial_dev_inst *serial;
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_RDWR) != SR_OK)
return NULL;
}
/* Init device instance, etc. */
- sdi = sr_dev_inst_new();
+ sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Manson");
sdi->model = g_strdup(models[model_id].name);
sdi->conn = serial;
sdi->driver = di;
- if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1"))) {
- sr_err("Failed to create channel.");
- goto exit_err;
- }
- sdi->channels = g_slist_append(sdi->channels, ch);
+ sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
devc = g_malloc0(sizeof(struct dev_context));
devc->model = &models[model_id];
return NULL;
}
-static GSList *dev_list(void)
+static GSList *dev_list(const struct sr_dev_driver *di)
{
return ((struct drv_context *)(di->priv))->instances;
}
-static int cleanup(void)
+static int cleanup(const struct sr_dev_driver *di)
{
- return dev_clear();
+ return dev_clear(di);
}
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
(void)cg;
+ /* Always available (with or without sdi). */
+ if (key == SR_CONF_SCAN_OPTIONS) {
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+ scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
+ return SR_OK;
+ }
+
+ /* Return drvopts without sdi (and devopts with sdi, see below). */
+ if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+ drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
+ return SR_OK;
+ }
+
+ /* Every other key needs an sdi. */
if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv;
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:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));