23 #include <sys/types.h>
28 #include "libsigrok-internal.h"
31 #define LOG_PREFIX "hwdriver"
70 "Serial communication", NULL},
72 "Modbus slave address", NULL},
78 "Pre-trigger capture ratio", NULL},
82 "Run length encoding", NULL},
84 "Trigger slope", NULL},
88 "Number of samples to average over", NULL},
90 "Trigger source", NULL},
92 "Horizontal trigger position", NULL},
104 "Trigger matches", NULL},
106 "Sample interval", NULL},
108 "Number of horizontal divisions", NULL},
110 "Number of vertical divisions", NULL},
112 "Sound pressure level frequency weighting", NULL},
114 "Sound pressure level time weighting", NULL},
116 "Sound pressure level measurement range", NULL},
122 "Voltage threshold", NULL },
124 "External clock mode", NULL},
126 "Swap channel order", NULL},
128 "Center frequency", NULL},
130 "Number of logic channels", NULL},
132 "Number of analog channels", NULL},
134 "Current voltage", NULL},
136 "Voltage target", NULL},
138 "Current current", NULL},
140 "Current limit", NULL},
142 "Channel enabled", NULL},
144 "Channel modes", NULL},
146 "Over-voltage protection enabled", NULL},
148 "Over-voltage protection active", NULL},
150 "Over-voltage protection threshold", NULL},
152 "Over-current protection enabled", NULL},
154 "Over-current protection active", NULL},
156 "Over-current protection threshold", NULL},
162 "Channel regulation", NULL},
164 "Over-temperature protection", NULL},
166 "Output frequency", NULL},
168 "Output frequency target", NULL},
170 "Measured quantity", NULL},
172 "Equivalent circuit model", NULL},
174 "Over-temperature protection active", NULL},
176 "Under-voltage condition", NULL},
178 "Under-voltage condition active", NULL},
180 "Trigger level", NULL},
184 "Session file", NULL},
186 "Capture file", NULL},
188 "Capture unitsize", NULL},
192 "Data source", NULL},
194 "Probe factor", NULL},
196 "Number of ADC powerline cycles", NULL},
202 "Sample limit", NULL},
204 "Frame limit", NULL},
206 "Continuous sampling", NULL},
210 "Device mode", NULL},
267 "Frequency weighted (A)", NULL},
269 "Frequency weighted (C)", NULL},
271 "Frequency weighted (Z)", NULL},
273 "Frequency weighted (flat)", NULL},
275 "Time weighted (S)", NULL},
277 "Time weighted (F)", NULL},
280 "Percentage over alarm", NULL},
295 return G_VARIANT_TYPE_INT32;
297 return G_VARIANT_TYPE_UINT64;
299 return G_VARIANT_TYPE_STRING;
301 return G_VARIANT_TYPE_BOOLEAN;
303 return G_VARIANT_TYPE_DOUBLE;
308 return G_VARIANT_TYPE_TUPLE;
310 return G_VARIANT_TYPE_DICTIONARY;
312 return G_VARIANT_TYPE_TUPLE;
319 SR_PRIV int sr_variant_type_check(uint32_t
key, GVariant *value)
322 const GVariantType *type, *expected;
323 char *expected_string, *type_string;
329 expected = sr_variant_type_get(info->
datatype);
330 type = g_variant_get_type(value);
331 if (!g_variant_type_equal(type, expected)
332 && !g_variant_type_is_subtype_of(type, expected)) {
333 expected_string = g_variant_type_dup_string(expected);
334 type_string = g_variant_type_dup_string(type);
335 sr_err(
"Wrong variant type for key '%s': expected '%s', got '%s'",
336 info->
name, expected_string, type_string);
337 g_free(expected_string);
361 return ctx->driver_list;
388 sr_err(
"Invalid libsigrok context, can't initialize.");
393 sr_err(
"Invalid driver, can't initialize.");
397 if ((ret = driver->
init(driver, ctx)) < 0)
398 sr_err(
"Failed to initialize the driver: %d.", ret);
422 const uint32_t *opts;
429 opts = g_variant_get_fixed_array(gvar, &num_opts,
sizeof(uint32_t));
431 result = g_array_sized_new(FALSE, FALSE,
sizeof(uint32_t), num_opts);
433 g_array_insert_vals(result, 0, opts, num_opts);
435 g_variant_unref(gvar);
440 static int check_options(
struct sr_dev_driver *driver, GSList *options,
441 uint32_t optlist_key,
struct sr_dev_inst *sdi,
448 const uint32_t *opts;
458 opts = g_variant_get_fixed_array(gvar_opts, &num_opts,
sizeof(uint32_t));
459 for (l = options; l; l = l->next) {
461 for (i = 0; i < num_opts; i++) {
462 if (opts[i] == src->
key)
468 sr_err(
"Invalid option %d.", src->
key);
470 sr_err(
"Invalid option '%s'.", srci->
id);
474 if (sr_variant_type_check(src->
key, src->
data) !=
SR_OK) {
479 g_variant_unref(gvar_opts);
514 sr_err(
"Invalid driver, can't scan for devices.");
519 sr_err(
"Driver not initialized, can't scan for devices.");
524 if (check_options(driver, options, SR_CONF_SCAN_OPTIONS, NULL, NULL) !=
SR_OK)
528 l = driver->
scan(driver, options);
530 sr_spew(
"Scan of '%s' found %d devices.", driver->
name,
552 for (i = 0; drivers[i]; i++) {
554 drivers[i]->
cleanup(drivers[i]);
570 src = g_malloc0(
sizeof(
struct sr_config));
572 src->
data = g_variant_ref_sink(data);
585 if (!src || !src->
data) {
586 sr_err(
"%s: invalid data!", __func__);
590 g_variant_unref(src->
data);
595 static void log_key(
const struct sr_dev_inst *sdi,
603 if (key == SR_CONF_DEVICE_OPTIONS)
609 tmp_str = g_variant_print(data, TRUE);
610 sr_spew(
"sr_config_%s(): key %d (%s) sdi %p cg %s -> %s", opstr, key,
611 srci ? srci->
id :
"NULL", sdi, cg ? cg->
name :
"NULL",
612 data ? tmp_str :
"NULL");
618 uint32_t key,
int op, GVariant *data)
623 const uint32_t *opts;
629 suffix =
" for this device and channel group";
631 suffix =
" for this device";
636 sr_err(
"Invalid key %d.", key);
648 if (g_variant_get_uint64(data) == 0) {
649 sr_err(
"Cannot set '%s' to 0.", srci->
id);
657 sr_err(
"No options available%s.", suffix);
660 opts = g_variant_get_fixed_array(gvar_opts, &num_opts,
sizeof(uint32_t));
662 for (i = 0; i < num_opts; i++) {
663 if ((opts[i] & SR_CONF_MASK) == key) {
668 g_variant_unref(gvar_opts);
670 sr_err(
"Option '%s' not available%s.", srci->
id, suffix);
674 if (!(pub_opt & op)) {
675 sr_err(
"Option '%s' not available to %s%s.", srci->
id, opstr, suffix);
708 const struct sr_dev_inst *sdi,
710 uint32_t key, GVariant **data)
714 if (!driver || !data)
723 if (sdi && !sdi->priv) {
724 sr_err(
"Can't get config (sdi != NULL, sdi->priv == NULL).");
732 g_variant_ref_sink(*data);
760 uint32_t key, GVariant *data)
764 g_variant_ref_sink(data);
766 if (!sdi || !sdi->driver || !sdi->priv || !data)
768 else if (!sdi->driver->config_set)
772 else if ((ret = sr_variant_type_check(key, data)) ==
SR_OK) {
774 ret = sdi->driver->config_set(key, data, sdi, cg);
777 g_variant_unref(data);
795 if (!sdi || !sdi->driver)
797 else if (!sdi->driver->config_commit)
800 ret = sdi->driver->config_commit(sdi);
831 const struct sr_dev_inst *sdi,
833 uint32_t key, GVariant **data)
837 if (!driver || !data)
841 else if (key != SR_CONF_SCAN_OPTIONS && key != SR_CONF_DEVICE_OPTIONS) {
845 if (sdi && !sdi->priv) {
846 sr_err(
"Can't list config (sdi != NULL, sdi->priv == NULL).");
851 g_variant_ref_sink(*data);
857 static struct sr_key_info *get_keytable(
int keytype)
863 table = sr_key_info_config;
866 table = sr_key_info_mq;
869 table = sr_key_info_mqflag;
872 sr_err(
"Invalid keytype %d", keytype);
895 if (!(table = get_keytable(keytype)))
898 for (i = 0; table[i].
key; i++) {
899 if (table[i].key == key)
922 if (!(table = get_keytable(keytype)))
925 for (i = 0; table[i].
key; i++) {
928 if (!strcmp(table[i].
id, keyid))
Generic/unspecified error.
Output frequency target in Hz.
Time is duration (as opposed to epoch, ...).
Sound pressure level is not weighted in the frequency domain, albeit without standards-defined low an...
GSList * sr_driver_scan(struct sr_dev_driver *driver, GSList *options)
Tell a hardware driver to scan for devices.
const char * name
Full capitalized name, e.g.
Sound pressure level is A-weighted in the frequency domain, according to IEC 61672:2003.
The device can measure temperature.
The device supports setting the number of logic channels.
The device supports setting the number of analog channels.
The device supports setting a sample number limit (how many samples should be acquired).
The device supports run-length encoding (RLE).
Measurement is four wire (e.g.
The device can act as an oscilloscope.
This is a true RMS measurement.
The device can act as an LCR meter.
Under-voltage condition active.
Series capacitance (LCR meter model).
Equivalent circuit model.
Channel regulation get: "CV", "CC" or "UR", denoting constant voltage, constant current or unregulate...
int sr_driver_init(struct sr_context *ctx, struct sr_dev_driver *driver)
Initialize a hardware driver.
Sound pressure level measurement is S-weighted (1s) in the time domain.
The device supports continuous sampling.
Number of vertical divisions, as related to SR_CONF_VDIV.
Sound pressure level measurement is F-weighted (125ms) in the time domain.
Over-current protection (OCP) feature.
The device can act as a scale.
The device supports setting a sample time limit (how long the sample acquisition should run...
int sr_config_commit(const struct sr_dev_inst *sdi)
Apply configuration settings to the device hardware.
GArray * sr_driver_scan_options_list(const struct sr_dev_driver *driver)
Enumerate scan options supported by this driver.
Data source for acquisition.
int(* cleanup)(const struct sr_dev_driver *driver)
Called before driver is unloaded.
The public libsigrok header file to be used by frontends.
Over-current protection (OCP) threshold.
Logic low-high threshold range.
Sound pressure level is time-averaged (LAT), also known as Equivalent Continuous A-weighted Sound Lev...
Device is in autoranging mode.
Sound pressure level is C-weighted in the frequency domain, according to IEC 61672:2003.
const char * name
Driver name.
struct sr_dev_driver ** sr_driver_list(const struct sr_context *ctx)
Return the list of supported hardware drivers.
The device is a demo device.
Device is in "min" mode, only updating upon a new min value.
Electrical power, usually in W, or dBm.
Sound pressure level represented as a percentage of measurements that were over a preset alarm level...
int datatype
Data type like SR_T_STRING, etc if applicable.
The device supports specifying a capturefile to inject.
Voltage measurement is alternating current (AC).
The device supports setting a pre/post-trigger capture ratio.
Used for setting or getting value of a config item.
Horizontal trigger position.
The device supports specifying the capturefile unit size.
Specification on how to connect to a device.
The device can measure energy consumption.
The device supports setting its sample interval, in ms.
Device is in "hold" mode (repeating the last measurement).
The device has internal storage, into which data is logged.
Enabling/disabling channel.
Over-voltage protection (OVP) threshold.
Parallel inductance (LCR meter model).
Possible values can be enumerated.
Number of powerline cycles for ADC integration time.
The device can act as a function generator.
const struct sr_key_info * sr_key_info_name_get(int keytype, const char *keyid)
Get information about a key, by name.
Parallel resistance (LCR meter model).
Series resistance (LCR meter model).
GVariant * data
Key-specific data.
The device can measure humidity.
int(* config_list)(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
List all possible values for a configuration key in a device instance.
The device can act as a multimeter.
The device supports using an external clock.
The device supports setting its samplerate, in Hz.
Structure for groups of channels that have common properties.
The device can act as logic analyzer.
The device can act as a signal demodulator.
int sr_config_list(const struct sr_dev_driver *driver, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg, uint32_t key, GVariant **data)
List all possible values for a configuration key.
Amplitude of a source without strictly-defined MQ.
Over-voltage protection (OVP) active.
The device supports averaging.
Modbus slave address specification.
The device supports swapping channels.
int sr_config_set(const struct sr_dev_inst *sdi, const struct sr_channel_group *cg, uint32_t key, GVariant *data)
Set value of a configuration key in a device instance.
char * name
Name of the channel group.
Device is in "avg" mode, averaging upon each new value.
Sound pressure level time weighting.
Device mode for multi-function devices.
Voltage measurement is direct current (DC).
The device can act as a sound level meter.
The device supports setting trigger slope.
Serial communication specification, in the form:
void * context
Device driver context, considered private.
GSList *(* scan)(struct sr_dev_driver *driver, GSList *options)
Scan for devices.
uint32_t key
Config key like SR_CONF_CONN, MQ value like SR_MQ_VOLTAGE, etc.
Series inductance (LCR meter model).
int sr_config_get(const struct sr_dev_driver *driver, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg, uint32_t key, GVariant **data)
Query value of a configuration key at the given driver or device instance.
The device supports setting a pattern (pattern generator mode).
Gain (a transistor's gain, or hFE, for example).
The device supports setting number of samples to be averaged over.
The device supports setting a probe factor.
The device can act as a programmable power supply.
Sound pressure level is Z-weighted (i.e.
int(* init)(struct sr_dev_driver *driver, struct sr_context *sr_ctx)
Called when driver is loaded, e.g.
uint32_t key
Config key like SR_CONF_CONN, etc.
Over-temperature protection (OTP)
Over-voltage protection (OVP) feature.
Difference from reference value.
Over-temperature protection (OTP) active.
Value is voltage drop across a diode, or NAN.
Parallel capacitance (LCR meter model).
int(* config_get)(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
Query value of a configuration key in driver or given device instance.
Sound pressure level measurement range.
const char * id
Short, lowercase ID string, e.g.
Device is in "max" mode, only updating upon a new max value.
Device is in relative mode.
The device supports setting a frame limit (how many frames should be acquired).
Logarithmic representation of sound pressure relative to a reference value.
const struct sr_key_info * sr_key_info_get(int keytype, uint32_t key)
Get information about a key, by key.
The device can act as an electronic load.
Sound pressure level frequency weighting.
Number of horizontal divisions, as related to SR_CONF_TIMEBASE.
Opaque structure representing a libsigrok context.
Over-current protection (OCP) active.
Choice of clock edge for external clock ("r" or "f").
Unstable value (hasn't settled yet).