#define SERIALCOMM "9600/8e1"
static const int hwopts[] = {
- SR_HWOPT_CONN,
- SR_HWOPT_SERIALCOMM,
+ SR_CONF_CONN,
+ SR_CONF_SERIALCOMM,
0,
};
static const int hwcaps[] = {
- SR_HWCAP_SOUNDLEVELMETER,
- SR_HWCAP_LIMIT_SAMPLES,
- SR_HWCAP_CONTINUOUS,
+ SR_CONF_SOUNDLEVELMETER,
+ SR_CONF_LIMIT_SAMPLES,
+ SR_CONF_CONTINUOUS,
0,
};
static int hw_init(struct sr_context *sr_ctx)
{
- struct drv_context *drvc;
-
- if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
- sr_err("Driver context malloc failed.");
- return SR_ERR_MALLOC;
- }
-
- drvc->sr_ctx = sr_ctx;
- di->priv = drvc;
-
- return SR_OK;
+ return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
}
static GSList *hw_scan(GSList *options)
GSList *devices, *l;
const char *conn, *serialcomm;
- devices = NULL;
drvc = di->priv;
drvc->instances = NULL;
+ devices = NULL;
+
conn = serialcomm = NULL;
for (l = options; l; l = l->next) {
if (!(src = l->data)) {
continue;
}
switch (src->key) {
- case SR_HWOPT_CONN:
+ case SR_CONF_CONN:
conn = src->value;
break;
- case SR_HWOPT_SERIALCOMM:
+ case SR_CONF_SERIALCOMM:
serialcomm = src->value;
break;
default:
static GSList *hw_dev_list(void)
{
- struct drv_context *drvc;
-
- drvc = di->priv;
-
- return drvc->instances;
+ return ((struct drv_context *)(di->priv))->instances;
}
static int hw_dev_open(struct sr_dev_inst *sdi)
return SR_OK;
}
-static int hw_info_get(int info_id, const void **data,
- const struct sr_dev_inst *sdi)
-{
- (void)sdi;
-
- switch (info_id) {
- case SR_DI_HWOPTS:
- *data = hwopts;
- break;
- case SR_DI_HWCAPS:
- *data = hwcaps;
- break;
- default:
- return SR_ERR_ARG;
- }
-
- return SR_OK;
-}
-
-static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
- const void *value)
+static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
devc = sdi->priv;
- switch (hwcap) {
- case SR_HWCAP_LIMIT_SAMPLES:
+ switch (id) {
+ case SR_CONF_LIMIT_SAMPLES:
devc->limit_samples = *(const uint64_t *)value;
sr_dbg("Setting sample limit to %" PRIu64 ".",
devc->limit_samples);
break;
default:
- sr_err("Unknown hardware capability: %d.", hwcap);
+ sr_err("Unknown hardware capability: %d.", id);
+ return SR_ERR_ARG;
+ }
+
+ return SR_OK;
+}
+
+static int config_list(int key, const void **data, const struct sr_dev_inst *sdi)
+{
+
+ (void)sdi;
+
+ switch (key) {
+ case SR_CONF_SCAN_OPTIONS:
+ *data = hwopts;
+ break;
+ case SR_CONF_DEVICE_OPTIONS:
+ *data = hwcaps;
+ break;
+ default:
return SR_ERR_ARG;
}
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
void *cb_data)
{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_header header;
struct dev_context *devc;
devc = sdi->priv;
devc->cb_data = cb_data;
/* Send header packet to the session bus. */
- sr_dbg("Sending SR_DF_HEADER.");
- packet.type = SR_DF_HEADER;
- packet.payload = (uint8_t *)&header;
- header.feed_version = 1;
- gettimeofday(&header.starttime, NULL);
- sr_session_send(devc->cb_data, &packet);
+ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Poll every 500ms, or whenever some data comes in. */
sr_source_add(devc->serial->fd, G_IO_IN, 500,
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
{
- int ret, final_ret;
- struct sr_datafeed_packet packet;
- struct dev_context *devc;
-
- final_ret = SR_OK;
-
- if (sdi->status != SR_ST_ACTIVE) {
- sr_err("Device inactive, can't stop acquisition.");
- return SR_ERR;
- }
-
- devc = sdi->priv;
-
- if ((ret = sr_source_remove(devc->serial->fd)) < 0) {
- sr_err("Error removing source: %d.", ret);
- final_ret = SR_ERR;
- }
-
- if ((ret = hw_dev_close(sdi)) < 0) {
- sr_err("Error closing device: %d.", ret);
- final_ret = SR_ERR;
- }
-
- /* Send end packet to the session bus. */
- sr_dbg("Sending SR_DF_END.");
- packet.type = SR_DF_END;
- sr_session_send(cb_data, &packet);
-
- return final_ret;
+ return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close,
+ ((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN);
}
SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info = {
.scan = hw_scan,
.dev_list = hw_dev_list,
.dev_clear = clear_instances,
+ .config_get = NULL,
+ .config_set = config_set,
+ .config_list = config_list,
.dev_open = hw_dev_open,
.dev_close = hw_dev_close,
- .info_get = hw_info_get,
- .dev_config_set = hw_dev_config_set,
.dev_acquisition_start = hw_dev_acquisition_start,
.dev_acquisition_stop = hw_dev_acquisition_stop,
.priv = NULL,