]> sigrok.org Git - libsigrok.git/commitdiff
scpi-pps: Use regex to match model names.
authorBert Vermeulen <redacted>
Fri, 5 Sep 2014 10:50:07 +0000 (12:50 +0200)
committerBert Vermeulen <redacted>
Mon, 8 Sep 2014 10:45:21 +0000 (12:45 +0200)
src/hardware/scpi-pps/api.c
src/hardware/scpi-pps/protocol.h

index cf161710af1da2a8002691f5786e90bd06c71b94..31e7ca6cf418388f0b6c7293c0ccbc808d2124c1 100644 (file)
@@ -45,6 +45,8 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        const struct scpi_pps *device;
        const struct channel_group_spec *cgs;
        struct pps_channel_group *pcg;
+       GRegex *model_re;
+       GMatchInfo *model_mi;
        uint64_t mask;
        unsigned int i, j;
        const char *vendor;
@@ -57,20 +59,23 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        device = NULL;
        for (i = 0; i < num_pps_profiles; i++) {
                vendor = get_vendor(hw_info->manufacturer);
-               if (strcasecmp(vendor, pps_profiles[i].idn_vendor))
+               if (strcasecmp(vendor, pps_profiles[i].vendor))
                        continue;
-               if (!strcmp(hw_info->model, pps_profiles[i].idn_model)) {
+               model_re = g_regex_new(pps_profiles[i].model, 0, 0, NULL);
+               if (g_regex_match(model_re, hw_info->model, 0, &model_mi))
                        device = &pps_profiles[i];
+               g_match_info_unref(model_mi);
+               g_regex_unref(model_re);
+               if (device)
                        break;
-               }
        }
        if (!device) {
                sr_scpi_hw_info_free(hw_info);
                return NULL;
        }
 
-       sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, vendor,
-                       device->idn_model, hw_info->firmware_version);
+       sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, vendor, hw_info->model,
+                       hw_info->firmware_version);
        sdi->conn = scpi;
        sdi->driver = di;
        sdi->inst_type = SR_INST_SCPI;
index 25b55cb1d372ea7c331d2cc47103ecbc95aee783..fc332ed7d89c905179e668693948e49e21c449d7 100644 (file)
@@ -70,8 +70,8 @@ enum pps_features {
 };
 
 struct scpi_pps {
-       char *idn_vendor;
-       char *idn_model;
+       char *vendor;
+       char *model;
        uint64_t features;
        const int32_t *devopts;
        unsigned int num_devopts;