]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/appa-55ii/api.c
serial: extend stream detect for variable length packet checkers
[libsigrok.git] / src / hardware / appa-55ii / api.c
index c55a5fd0e87d0d940585ffe888c8935972ed8cc0..14211c6a92df90eb4f546d561d9517a60a93d5bd 100644 (file)
@@ -79,11 +79,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
        sr_info("Probing serial port %s.", conn);
 
-       serial_flush(serial);
-
        /* Let's get a bit of data and see if we can find a packet. */
        if (serial_stream_detect(serial, buf, &len, 25,
-                       appa_55ii_packet_valid, 500, 9600) != SR_OK)
+                       appa_55ii_packet_valid, NULL, NULL, 500) != SR_OK)
                goto scan_cleanup;
 
        sr_info("Found device on port %s.", conn);
@@ -134,8 +132,7 @@ 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;
-       const char *tmp_str;
-       unsigned int i;
+       int idx;
 
        (void)cg;
 
@@ -145,17 +142,11 @@ static int config_set(uint32_t key, GVariant *data,
        case SR_CONF_LIMIT_SAMPLES:
        case SR_CONF_LIMIT_MSEC:
                return sr_sw_limits_config_set(&devc->limits, key, data);
-       case SR_CONF_DATA_SOURCE: {
-               tmp_str = g_variant_get_string(data, NULL);
-               for (i = 0; i < ARRAY_SIZE(data_sources); i++)
-                       if (!strcmp(tmp_str, data_sources[i])) {
-                               devc->data_source = i;
-                               break;
-                       }
-               if (i == ARRAY_SIZE(data_sources))
-                       return SR_ERR;
+       case SR_CONF_DATA_SOURCE:
+               if ((idx = std_str_idx(data, ARRAY_AND_SIZE(data_sources))) < 0)
+                       return SR_ERR_ARG;
+               devc->data_source = idx;
                break;
-       }
        default:
                return SR_ERR_NA;
        }