]> sigrok.org Git - libsigrok.git/blobdiff - src/hwdriver.c
More robust searching for config keys.
[libsigrok.git] / src / hwdriver.c
index e36990a258404842dd4a9ea25624dc23f86794a4..f9649f0c489666a5a4c9f7f039019bf93cdb4fce 100644 (file)
@@ -48,10 +48,36 @@ extern SR_PRIV struct sr_dev_driver *drivers_list[];
  */
 
 static struct sr_config_info sr_config_info_data[] = {
+       /* Device types */
+       {SR_CONF_LOGIC_ANALYZER, SR_T_STRING, NULL, "Logic Analyzer", NULL},
+       {SR_CONF_OSCILLOSCOPE, SR_T_STRING, NULL, "Oscilloscope", NULL},
+       {SR_CONF_MULTIMETER, SR_T_STRING, NULL, "Multimeter", NULL},
+       {SR_CONF_DEMO_DEV, SR_T_STRING, NULL, "Demo device", NULL},
+       {SR_CONF_SOUNDLEVELMETER, SR_T_STRING, NULL, "Sound level meter", NULL},
+       {SR_CONF_THERMOMETER, SR_T_STRING, NULL, "Thermometer", NULL},
+       {SR_CONF_HYGROMETER, SR_T_STRING, NULL, "Hygrometer", NULL},
+       {SR_CONF_ENERGYMETER, SR_T_STRING, NULL, "Energy meter", NULL},
+       {SR_CONF_DEMODULATOR, SR_T_STRING, NULL, "Demodulator", NULL},
+       {SR_CONF_POWER_SUPPLY, SR_T_STRING, NULL, "Power supply", NULL},
+       {SR_CONF_LCRMETER, SR_T_STRING, NULL, "LCR meter", NULL},
+
+       /* Sample limiting */
+       {SR_CONF_LIMIT_SAMPLES, SR_T_UINT64, "limit_samples",
+               "Sample limit", NULL},
+       {SR_CONF_LIMIT_MSEC, SR_T_UINT64, "limit_time",
+               "Time limit", NULL},
+       {SR_CONF_LIMIT_FRAMES, SR_T_UINT64, "limit_frames",
+               "Frame limit", NULL},
+       {SR_CONF_CONTINUOUS, SR_T_UINT64, "continuous",
+               "Continuous sampling", NULL},
+
+       /* Scan options */
        {SR_CONF_CONN, SR_T_STRING, "conn",
                "Connection", NULL},
        {SR_CONF_SERIALCOMM, SR_T_STRING, "serialcomm",
                "Serial communication", NULL},
+
+       /* Device/channel group options */
        {SR_CONF_SAMPLERATE, SR_T_UINT64, "samplerate",
                "Sample rate", NULL},
        {SR_CONF_CAPTURE_RATIO, SR_T_UINT64, "captureratio",
@@ -106,12 +132,12 @@ static struct sr_config_info sr_config_info_data[] = {
                "Number of analog channels", NULL},
        {SR_CONF_OUTPUT_VOLTAGE, SR_T_FLOAT, "output_voltage",
                "Current output voltage", NULL},
-       {SR_CONF_OUTPUT_VOLTAGE_MAX, SR_T_FLOAT, "output_voltage_max",
-               "Maximum output voltage", NULL},
+       {SR_CONF_OUTPUT_VOLTAGE_TARGET, SR_T_FLOAT, "output_voltage_target",
+               "Output voltage target", NULL},
        {SR_CONF_OUTPUT_CURRENT, SR_T_FLOAT, "output_current",
                "Current output current", NULL},
-       {SR_CONF_OUTPUT_CURRENT_MAX, SR_T_FLOAT, "output_current_max",
-               "Maximum output current", NULL},
+       {SR_CONF_OUTPUT_CURRENT_LIMIT, SR_T_FLOAT, "output_current_limit",
+               "Output current limit", NULL},
        {SR_CONF_OUTPUT_ENABLED, SR_T_BOOL, "output_enabled",
                "Output enabled", NULL},
        {SR_CONF_OUTPUT_CHANNEL_CONFIG, SR_T_STRING, "output_channel_config",
@@ -128,8 +154,6 @@ static struct sr_config_info sr_config_info_data[] = {
                "Over-current protection active", NULL},
        {SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD, SR_T_FLOAT, "ocp_threshold",
                "Over-current protection threshold", NULL},
-       {SR_CONF_LIMIT_SAMPLES, SR_T_UINT64, "limit_samples",
-               "Sample limit", NULL},
        {SR_CONF_CLOCK_EDGE, SR_T_STRING, "clock_edge",
                "Clock edge", NULL},
        {SR_CONF_AMPLITUDE, SR_T_FLOAT, "amplitude",
@@ -138,6 +162,14 @@ static struct sr_config_info sr_config_info_data[] = {
                "Over-temperature protection", NULL},
        {SR_CONF_OUTPUT_REGULATION, SR_T_STRING, "output_regulation",
                "Output channel regulation", NULL},
+       {SR_CONF_OUTPUT_FREQUENCY, SR_T_UINT64, "output_frequency",
+               "Output frequency", NULL},
+       {SR_CONF_MEASURED_QUANTITY, SR_T_STRING, "measured_quantity",
+               "Measured quantity", NULL},
+       {SR_CONF_MEASURED_2ND_QUANTITY, SR_T_STRING, "measured_2nd_quantity",
+               "Measured secondary quantity", NULL},
+       {SR_CONF_EQUIV_CIRCUIT_MODEL, SR_T_STRING, "equiv_circuit_model",
+               "Equivalent circuit model", NULL},
        {0, 0, NULL, NULL, NULL},
 };
 
@@ -170,20 +202,25 @@ SR_PRIV int sr_variant_type_check(uint32_t key, GVariant *value)
 {
        const struct sr_config_info *info;
        const GVariantType *type, *expected;
+       char *expected_string, *type_string;
+
        info = sr_config_info_get(key);
        if (!info)
                return SR_OK;
+
        expected = sr_variant_type_get(info->datatype);
        type = g_variant_get_type(value);
-       if (!g_variant_type_equal(type, expected)) {
-               gchar *expected_string = g_variant_type_dup_string(expected);
-               gchar *type_string = g_variant_type_dup_string(type);
+       if (!g_variant_type_equal(type, expected)
+                       && !g_variant_type_is_subtype_of(type, expected)) {
+               expected_string = g_variant_type_dup_string(expected);
+               type_string = g_variant_type_dup_string(type);
                sr_err("Wrong variant type for key '%s': expected '%s', got '%s'",
                        info->name, expected_string, type_string);
                g_free(expected_string);
                g_free(type_string);
                return SR_ERR_ARG;
        }
+
        return SR_OK;
 }
 
@@ -525,6 +562,8 @@ SR_API const struct sr_config_info *sr_config_info_name_get(const char *optname)
        int i;
 
        for (i = 0; sr_config_info_data[i].key; i++) {
+               if (!sr_config_info_data[i].id)
+                       continue;
                if (!strcmp(sr_config_info_data[i].id, optname))
                        return &sr_config_info_data[i];
        }