23 #include <sys/types.h> 28 #include "libsigrok-internal.h" 31 #define LOG_PREFIX "hwdriver" 69 "Serial communication", NULL},
71 "Modbus slave address", NULL},
77 "Pre-trigger capture ratio", NULL},
81 "Run length encoding", NULL},
83 "Trigger slope", NULL},
87 "Number of samples to average over", NULL},
89 "Trigger source", NULL},
91 "Horizontal trigger position", NULL},
103 "Trigger matches", NULL},
105 "Sample interval", NULL},
107 "Number of horizontal divisions", NULL},
109 "Number of vertical divisions", NULL},
111 "Sound pressure level frequency weighting", NULL},
113 "Sound pressure level time weighting", NULL},
115 "Sound pressure level measurement range", NULL},
121 "Voltage threshold", NULL },
123 "External clock mode", NULL},
125 "Swap channel order", NULL},
127 "Center frequency", NULL},
129 "Number of logic channels", NULL},
131 "Number of analog channels", NULL},
133 "Current voltage", NULL},
135 "Voltage target", NULL},
137 "Current current", NULL},
139 "Current limit", NULL},
141 "Channel enabled", NULL},
143 "Channel modes", NULL},
145 "Over-voltage protection enabled", NULL},
147 "Over-voltage protection active", NULL},
149 "Over-voltage protection threshold", NULL},
151 "Over-current protection enabled", NULL},
153 "Over-current protection active", NULL},
155 "Over-current protection threshold", NULL},
161 "Channel regulation", NULL},
163 "Over-temperature protection", NULL},
165 "Output frequency", NULL},
167 "Output frequency target", NULL},
169 "Measured quantity", NULL},
171 "Equivalent circuit model", NULL},
173 "Over-temperature protection active", NULL},
177 "Session file", NULL},
179 "Capture file", NULL},
181 "Capture unitsize", NULL},
185 "Data source", NULL},
187 "Probe factor", NULL},
193 "Sample limit", NULL},
195 "Frame limit", NULL},
197 "Continuous sampling", NULL},
201 "Device mode", NULL},
257 "Frequency weighted (A)", NULL},
259 "Frequency weighted (C)", NULL},
261 "Frequency weighted (Z)", NULL},
263 "Frequency weighted (flat)", NULL},
265 "Time weighted (S)", NULL},
267 "Time weighted (F)", NULL},
270 "Percentage over alarm", NULL},
283 return G_VARIANT_TYPE_INT32;
285 return G_VARIANT_TYPE_UINT64;
287 return G_VARIANT_TYPE_STRING;
289 return G_VARIANT_TYPE_BOOLEAN;
291 return G_VARIANT_TYPE_DOUBLE;
296 return G_VARIANT_TYPE_TUPLE;
298 return G_VARIANT_TYPE_DICTIONARY;
300 return G_VARIANT_TYPE_TUPLE;
309 const GVariantType *type, *expected;
310 char *expected_string, *type_string;
317 type = g_variant_get_type(value);
318 if (!g_variant_type_equal(type, expected)
319 && !g_variant_type_is_subtype_of(type, expected)) {
320 expected_string = g_variant_type_dup_string(expected);
321 type_string = g_variant_type_dup_string(type);
322 sr_err(
"Wrong variant type for key '%s': expected '%s', got '%s'",
323 info->
name, expected_string, type_string);
324 g_free(expected_string);
348 return ctx->driver_list;
375 sr_err(
"Invalid libsigrok context, can't initialize.");
380 sr_err(
"Invalid driver, can't initialize.");
384 sr_spew(
"Initializing driver '%s'.", driver->
name);
385 if ((ret = driver->
init(driver, ctx)) < 0)
386 sr_err(
"Failed to initialize the driver: %d.", ret);
410 const uint32_t *opts;
417 opts = g_variant_get_fixed_array(gvar, &num_opts,
sizeof(uint32_t));
419 result = g_array_sized_new(FALSE, FALSE,
sizeof(uint32_t), num_opts);
421 g_array_insert_vals(result, 0, opts, num_opts);
423 g_variant_unref(gvar);
428 static int check_options(
struct sr_dev_driver *driver, GSList *options,
429 uint32_t optlist_key,
struct sr_dev_inst *sdi,
436 const uint32_t *opts;
446 opts = g_variant_get_fixed_array(gvar_opts, &num_opts,
sizeof(uint32_t));
447 for (l = options; l; l = l->next) {
449 for (i = 0; i < num_opts; i++) {
450 if (opts[i] == src->
key)
456 sr_err(
"Invalid option %d.", src->
key);
458 sr_err(
"Invalid option '%s'.", srci->
id);
467 g_variant_unref(gvar_opts);
502 sr_err(
"Invalid driver, can't scan for devices.");
507 sr_err(
"Driver not initialized, can't scan for devices.");
512 if (check_options(driver, options, SR_CONF_SCAN_OPTIONS, NULL, NULL) !=
SR_OK)
516 l = driver->
scan(driver, options);
518 sr_spew(
"Scan of '%s' found %d devices.", driver->
name,
540 for (i = 0; drivers[i]; i++) {
542 drivers[i]->
cleanup(drivers[i]);
555 src = g_malloc0(
sizeof(
struct sr_config));
557 src->
data = g_variant_ref_sink(data);
568 if (!src || !src->
data) {
569 sr_err(
"%s: invalid data!", __func__);
573 g_variant_unref(src->
data);
578 static void log_key(
const struct sr_dev_inst *sdi,
585 if (
key == SR_CONF_DEVICE_OPTIONS)
591 sr_spew(
"sr_config_%s(): key %d (%s) sdi %p cg %s -> %s", opstr,
key,
592 srci ? srci->
id :
"NULL", sdi, cg ? cg->
name :
"NULL",
593 data ? g_variant_print(data, TRUE) :
"NULL");
598 uint32_t
key,
int op, GVariant *data)
603 const uint32_t *opts;
609 suffix =
" for this device and channel group";
611 suffix =
" for this device";
616 sr_err(
"Invalid key %d.",
key);
628 if (g_variant_get_uint64(data) == 0) {
629 sr_err(
"Cannot set '%s' to 0.", srci->
id);
637 sr_err(
"No options available%s.", suffix);
640 opts = g_variant_get_fixed_array(gvar_opts, &num_opts,
sizeof(uint32_t));
642 for (i = 0; i < num_opts; i++) {
643 if ((opts[i] & SR_CONF_MASK) ==
key) {
648 g_variant_unref(gvar_opts);
650 sr_err(
"Option '%s' not available%s.", srci->
id, suffix);
654 if (!(pub_opt & op)) {
655 sr_err(
"Option '%s' not available to %s%s.", srci->
id, opstr, suffix);
687 const struct sr_dev_inst *sdi,
689 uint32_t
key, GVariant **data)
693 if (!driver || !data)
706 g_variant_ref_sink(*data);
733 uint32_t
key, GVariant *data)
737 g_variant_ref_sink(data);
739 if (!sdi || !sdi->driver || !data)
741 else if (!sdi->driver->config_set)
747 ret = sdi->driver->config_set(key, data, sdi, cg);
750 g_variant_unref(data);
768 if (!sdi || !sdi->driver)
770 else if (!sdi->driver->config_commit)
773 ret = sdi->driver->config_commit(sdi);
802 const struct sr_dev_inst *sdi,
804 uint32_t
key, GVariant **data)
808 if (!driver || !data)
812 else if (key != SR_CONF_SCAN_OPTIONS && key != SR_CONF_DEVICE_OPTIONS) {
818 g_variant_ref_sink(*data);
824 static struct sr_key_info *get_keytable(
int keytype)
830 table = sr_key_info_config;
833 table = sr_key_info_mq;
836 table = sr_key_info_mqflag;
839 sr_err(
"Invalid keytype %d", keytype);
862 if (!(table = get_keytable(keytype)))
865 for (i = 0; table[i].
key; i++) {
866 if (table[i].key == key)
889 if (!(table = get_keytable(keytype)))
892 for (i = 0; table[i].
key; i++) {
895 if (!strcmp(table[i].
id, keyid))
Series capacitance (LCR meter model).
Logarithmic representation of sound pressure relative to a reference value.
Sound pressure level measurement is S-weighted (1s) in the time domain.
int datatype
Data type like SR_T_STRING, etc if applicable.
int sr_driver_init(struct sr_context *ctx, struct sr_dev_driver *driver)
Initialize a hardware driver.
The device supports specifying a capturefile to inject.
Sound pressure level frequency weighting.
Voltage measurement is alternating current (AC).
Gain (a transistor's gain, or hFE, for example).
Opaque structure representing a libsigrok context.
Horizontal trigger position.
Over-current protection (OCP) active.
Unstable value (hasn't settled yet).
Sound pressure level is Z-weighted (i.e.
Generic/unspecified error.
Output frequency target in Hz.
Time is duration (as opposed to epoch, ...).
The device has internal storage, into which data is logged.
GSList * sr_driver_scan(struct sr_dev_driver *driver, GSList *options)
Tell a hardware driver to scan for devices.
Sound pressure level is A-weighted in the frequency domain, according to IEC 61672:2003.
Over-voltage protection (OVP) feature.
Parallel inductance (LCR meter model).
The device supports setting the number of logic channels.
The device supports setting a sample number limit (how many samples should be acquired).
The device supports run-length encoding (RLE).
Over-temperature protection (OTP) active.
Value is voltage drop across a diode, or NAN.
This is a true RMS measurement.
Sound pressure level measurement range.
The device can act as an LCR meter.
Electrical power, usually in W, or dBm.
Equivalent circuit model.
Channel regulation get: "CV", "CC" or "UR", denoting constant voltage, constant current or unregulate...
char * name
Name of the channel group.
Number of vertical divisions, as related to SR_CONF_VDIV.
The device can act as a multimeter.
The device supports setting a pre/post-trigger capture ratio.
int(* cleanup)(const struct sr_dev_driver *driver)
Called before driver is unloaded.
Sound pressure level measurement is F-weighted (125ms) in the time domain.
int(* init)(struct sr_dev_driver *driver, struct sr_context *sr_ctx)
Called when driver is loaded, e.g.
The device supports using an external clock.
The device supports specifying the capturefile unit size.
Number of horizontal divisions, as related to SR_CONF_TIMEBASE.
The device can act as logic analyzer.
The device can measure energy consumption.
Choice of clock edge for external clock ("r" or "f").
Amplitude of a source without strictly-defined MQ.
The device can act as a scale.
The device supports setting its sample interval, in ms.
Device is in "hold" mode (repeating the last measurement).
Data source for acquisition.
void * context
Device driver context, considered private.
Modbus slave address specification.
The device supports swapping channels.
The device supports setting the number of analog channels.
Sound pressure level is C-weighted in the frequency domain, according to IEC 61672:2003.
Sound pressure level time weighting.
struct sr_dev_driver ** sr_driver_list(const struct sr_context *ctx)
Return the list of supported hardware drivers.
Voltage measurement is direct current (DC).
The device supports setting trigger slope.
The device is a demo device.
Device is in "min" mode, only updating upon a new min value.
SR_PRIV const GVariantType * sr_variant_type_get(int datatype)
The device supports continuous sampling.
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.
Used for setting or getting value of a config item.
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.
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.
const char * id
Short, lowercase ID string, e.g.
The device can act as a signal demodulator.
The device supports setting a probe factor.
The device supports setting a sample time limit (how long the sample acquisition should run...
const char * name
Full capitalized name, e.g.
Over-voltage protection (OVP) active.
The device supports averaging.
uint32_t key
Config key like SR_CONF_CONN, MQ value like SR_MQ_VOLTAGE, etc.
Over-current protection (OCP) threshold.
The public libsigrok header file to be used by frontends.
Sound pressure level is time-averaged (LAT), also known as Equivalent Continuous A-weighted Sound Lev...
Over-voltage protection (OVP) threshold.
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.
The device can act as a sound level meter.
const struct sr_key_info * sr_key_info_get(int keytype, uint32_t key)
Get information about a key, by key.
Parallel resistance (LCR meter model).
Series resistance (LCR meter model).
Sound pressure level represented as a percentage of measurements that were over a preset alarm level...
The device can measure humidity.
Device is in "max" mode, only updating upon a new max value.
GVariant * data
Key-specific data.
Specification on how to connect to a device.
The device supports setting a pattern (pattern generator mode).
SR_PRIV int sr_variant_type_check(uint32_t key, GVariant *value)
uint32_t key
Config key like SR_CONF_CONN, etc.
The device can act as a programmable power supply.
Enabling/disabling channel.
Possible values can be enumerated.
Device is in "avg" mode, averaging upon each new value.
The device can measure temperature.
Structure for groups of channels that have common properties.
Parallel capacitance (LCR meter model).
Device is in relative mode.
The device supports setting a frame limit (how many frames should be acquired).
The device can act as an electronic load.
const struct sr_key_info * sr_key_info_name_get(int keytype, const char *keyid)
Get information about a key, by name.
The device supports setting its samplerate, in Hz.
The device supports setting number of samples to be averaged over.
Over-current protection (OCP) feature.
const char * name
Driver name.
Sound pressure level is not weighted in the frequency domain, albeit without standards-defined low an...
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.
Over-temperature protection (OTP)
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.
Logic low-high threshold range.
Device mode for multi-function devices.
Difference from reference value.
Device is in autoranging mode.
GSList *(* scan)(struct sr_dev_driver *driver, GSList *options)
Scan for devices.
Serial communication specification, in the form:
The device can act as an oscilloscope.
Series inductance (LCR meter model).