]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/brymen-dmm/api.c
Backport recent changes from mainline.
[libsigrok.git] / src / hardware / brymen-dmm / api.c
index 00ff6cf110783be92707c3e42c8d53183b069a91..ce6f1f33e4f4c8e832fa34232a74f04698d89f13 100644 (file)
@@ -25,8 +25,11 @@ static const uint32_t scanopts[] = {
        SR_CONF_SERIALCOMM,
 };
 
-static const uint32_t devopts[] = {
+static const uint32_t drvopts[] = {
        SR_CONF_MULTIMETER,
+};
+
+static const uint32_t devopts[] = {
        SR_CONF_CONTINUOUS,
        SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
        SR_CONF_LIMIT_MSEC | SR_CONF_SET,
@@ -58,7 +61,7 @@ static GSList *brymen_scan(struct sr_dev_driver *di, const char *conn,
                goto scan_cleanup;
        }
 
-       len = 128;
+       len = sizeof(buf);
        ret = brymen_stream_detect(serial, buf, &len, brymen_packet_length,
                             brymen_packet_is_valid, 1000, 9600);
        if (ret != SR_OK)
@@ -107,52 +110,30 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        if (!conn)
                return NULL;
 
-       if (serialcomm) {
-               /* Use the provided comm specs. */
+       if (serialcomm)
                devices = brymen_scan(di, conn, serialcomm);
-       } else {
-               /* But 9600/8n1 should work all of the time. */
+       else
                devices = brymen_scan(di, conn, "9600/8n1/dtr=1/rts=1");
-       }
 
        return devices;
 }
 
-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;
 
        (void)cg;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
 
        return sr_sw_limits_config_set(&devc->sw_limits, key, data);
 }
 
-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:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
@@ -160,15 +141,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
 
        sr_sw_limits_acquisition_start(&devc->sw_limits);
        std_session_send_df_header(sdi);
 
-       /* Poll every 50ms, or whenever some data comes in. */
        serial = sdi->conn;
        serial_source_add(sdi->session, serial, G_IO_IN, 50,
                        brymen_dmm_receive_data, (void *)sdi);
@@ -184,7 +161,7 @@ static struct sr_dev_driver brymen_bm857_driver_info = {
        .cleanup = std_cleanup,
        .scan = scan,
        .dev_list = std_dev_list,
-       .dev_clear = NULL,
+       .dev_clear = std_dev_clear,
        .config_get = NULL,
        .config_set = config_set,
        .config_list = config_list,