]> sigrok.org Git - libsigrok.git/blobdiff - hardware/openbench-logic-sniffer/api.c
Add and use std_session_send_df_header().
[libsigrok.git] / hardware / openbench-logic-sniffer / api.c
index daf2311c78911ac8b64c982d792a6c7fa39e9695..56176cc7eda1e3b8496545934543801aea424282 100644 (file)
@@ -44,12 +44,12 @@ SR_PRIV const char *ols_probe_names[NUM_PROBES + 1] = {
        NULL,
 };
 
-/* default supported samplerates, can be overridden by device metadata */
+/* Default supported samplerates, can be overridden by device metadata. */
 static const struct sr_samplerates samplerates = {
-       SR_HZ(10),
-       SR_MHZ(200),
-       SR_HZ(1),
-       NULL,
+       .low  = SR_HZ(10),
+       .high = SR_MHZ(200),
+       .step = SR_HZ(1),
+       .list = NULL,
 };
 
 SR_PRIV struct sr_dev_driver ols_driver_info;
@@ -57,16 +57,7 @@ static struct sr_dev_driver *di = &ols_driver_info;
 
 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)
@@ -84,7 +75,9 @@ static GSList *hw_scan(GSList *options)
        char buf[8];
 
        (void)options;
+
        drvc = di->priv;
+
        devices = NULL;
 
        conn = serialcomm = NULL;
@@ -180,11 +173,7 @@ static GSList *hw_scan(GSList *options)
 
 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)
@@ -255,16 +244,7 @@ static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
 
        switch (id) {
-       case SR_DI_HWOPTS:
-               *data = hwopts;
-               break;
-       case SR_DI_HWCAPS:
-               *data = hwcaps;
-               break;
-       case SR_DI_TRIGGER_TYPES:
-               *data = (char *)TRIGGER_TYPES;
-               break;
-       case SR_DI_CUR_SAMPLERATE:
+       case SR_CONF_SAMPLERATE:
                if (sdi) {
                        devc = sdi->priv;
                        *data = &devc->cur_samplerate;
@@ -332,9 +312,18 @@ 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;
        case SR_CONF_SAMPLERATE:
                *data = &samplerates;
                break;
+       case SR_CONF_TRIGGER_TYPE:
+               *data = (char *)TRIGGER_TYPE;
+               break;
        default:
                return SR_ERR_ARG;
        }
@@ -345,8 +334,6 @@ static int config_list(int key, const void **data, const struct sr_dev_inst *sdi
 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;
        uint32_t trigger_config[4];
        uint32_t data;
@@ -468,30 +455,12 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        if (send_shortcommand(devc->serial, CMD_RUN) != SR_OK)
                return SR_ERR;
 
+       /* Send header packet to the session bus. */
+       std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
+
        sr_source_add(devc->serial->fd, G_IO_IN, -1, ols_receive_data,
                      cb_data);
 
-       if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
-               sr_err("Datafeed packet malloc failed.");
-               return SR_ERR_MALLOC;
-       }
-
-       if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
-               sr_err("Datafeed header malloc failed.");
-               g_free(packet);
-               return SR_ERR_MALLOC;
-       }
-
-       /* Send header packet to the session bus. */
-       packet->type = SR_DF_HEADER;
-       packet->payload = (unsigned char *)header;
-       header->feed_version = 1;
-       gettimeofday(&header->starttime, NULL);
-       sr_session_send(cb_data, packet);
-
-       g_free(header);
-       g_free(packet);
-
        return SR_OK;
 }