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))
const struct sr_key_info * sr_key_info_get(int keytype, uint32_t key)
Get information about a key, by key.
Generic/unspecified error.
Choice of clock edge for external clock ("r" or "f").
Time is duration (as opposed to epoch, ...).
Sound pressure level is not weighted in the frequency domain, albeit without standards-defined low an...
The device can measure temperature.
The device supports setting the number of logic channels.
Sound pressure level is A-weighted in the frequency domain, according to IEC 61672:2003.
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 can act as an LCR meter.
The device can act as an oscilloscope.
Series capacitance (LCR meter model).
The device supports run-length encoding (RLE).
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.
This is a true RMS measurement.
Sound pressure level measurement is S-weighted (1s) in the time domain.
Number of vertical divisions, as related to SR_CONF_VDIV.
Equivalent circuit model.
Channel regulation get: "CV", "CC" or "UR", denoting constant voltage, constant current or unregulate...
Sound pressure level measurement is F-weighted (125ms) in the time domain.
The device supports continuous sampling.
Opaque structure representing a libsigrok context.
uint32_t key
Config key like SR_CONF_CONN, etc.
Over-current protection (OCP) feature.
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 scale.
const char * id
Short, lowercase ID string, e.g.
The device supports setting a sample time limit (how long the sample acquisition should run...
Over-current protection (OCP) threshold.
Sound pressure level is time-averaged (LAT), also known as Equivalent Continuous A-weighted Sound Lev...
Logic low-high threshold range.
Data source for acquisition.
Sound pressure level is C-weighted in the frequency domain, according to IEC 61672:2003.
Device is in autoranging mode.
The device is a demo device.
Electrical power, usually in W, or dBm.
Device is in "min" mode, only updating upon a new min value.
The device supports setting a pre/post-trigger capture ratio.
Voltage measurement is alternating current (AC).
Horizontal trigger position.
Sound pressure level represented as a percentage of measurements that were over a preset alarm level...
The device supports specifying a capturefile to inject.
The device supports specifying the capturefile unit size.
Specification on how to connect to a device.
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.
SR_PRIV int sr_variant_type_check(uint32_t key, GVariant *value)
The device can measure energy consumption.
The device supports setting its sample interval, in ms.
GSList * sr_driver_scan(struct sr_dev_driver *driver, GSList *options)
Tell a hardware driver to scan for devices.
Device is in "hold" mode (repeating the last measurement).
The device has internal storage, into which data is logged.
Enabling/disabling channel.
int(* cleanup)(const struct sr_dev_driver *driver)
Called before driver is unloaded.
Parallel inductance (LCR meter model).
Over-voltage protection (OVP) threshold.
Possible values can be enumerated.
int datatype
Data type like SR_T_STRING, etc if applicable.
Series resistance (LCR meter model).
The device can act as a multimeter.
Parallel resistance (LCR meter model).
The device can measure humidity.
const char * name
Full capitalized name, e.g.
The device can act as logic analyzer.
The device supports using an external clock.
Structure for groups of channels that have common properties.
The device can act as a signal demodulator.
const struct sr_key_info * sr_key_info_name_get(int keytype, const char *keyid)
Get information about a key, by name.
Amplitude of a source without strictly-defined MQ.
The device supports setting its samplerate, in Hz.
Over-voltage protection (OVP) active.
The device supports swapping channels.
The device supports averaging.
Device is in "avg" mode, averaging upon each new value.
Modbus slave address specification.
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.
Voltage measurement is direct current (DC).
struct sr_dev_driver ** sr_driver_list(const struct sr_context *ctx)
Return the list of supported hardware drivers.
Serial communication specification, in the form:
The device can act as a sound level meter.
Sound pressure level time weighting.
Device mode for multi-function devices.
The device supports setting trigger slope.
int sr_config_commit(const struct sr_dev_inst *sdi)
Apply configuration settings to the device hardware.
Series inductance (LCR meter model).
int(* init)(struct sr_dev_driver *driver, struct sr_context *sr_ctx)
Called when driver is loaded, e.g.
int sr_driver_init(struct sr_context *ctx, struct sr_dev_driver *driver)
Initialize a hardware driver.
Gain (a transistor's gain, or hFE, for example).
The device supports setting a pattern (pattern generator mode).
The device supports setting number of samples to be averaged over.
GSList *(* scan)(struct sr_dev_driver *driver, GSList *options)
Scan for devices.
Sound pressure level is Z-weighted (i.e.
The device supports setting a probe factor.
void * context
Device driver context, considered private.
The device can act as a programmable power supply.
const char * name
Driver name.
uint32_t key
Config key like SR_CONF_CONN, MQ value like SR_MQ_VOLTAGE, etc.
GVariant * data
Key-specific data.
Over-temperature protection (OTP)
SR_PRIV const GVariantType * sr_variant_type_get(int datatype)
Difference from reference value.
GArray * sr_driver_scan_options_list(const struct sr_dev_driver *driver)
Enumerate scan options supported by this driver.
Over-voltage protection (OVP) feature.
The public libsigrok header file to be used by frontends.
Over-temperature protection (OTP) active.
Value is voltage drop across a diode, or NAN.
Device is in relative mode.
char * name
Name of the channel group.
Parallel capacitance (LCR meter model).
Sound pressure level measurement range.
Device is in "max" mode, only updating upon a new max value.
Logarithmic representation of sound pressure relative to a reference value.
The device supports setting a frame limit (how many frames should be acquired).
The device can act as an electronic load.
Used for setting or getting value of a config item.
Sound pressure level frequency weighting.
Number of horizontal divisions, as related to SR_CONF_TIMEBASE.
Unstable value (hasn't settled yet).
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.
Output frequency target in Hz.
Over-current protection (OCP) active.