24 #include "libsigrok-internal.h"
27 #define LOG_PREFIX "device: "
28 #define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args)
29 #define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args)
30 #define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args)
31 #define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args)
32 #define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args)
33 #define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args)
55 if (!(probe = g_try_malloc0(
sizeof(
struct sr_probe)))) {
56 sr_err(
"Probe malloc failed.");
64 probe->
name = g_strdup(name);
86 int probenum,
const char *
name)
93 sr_err(
"%s: sdi was NULL", __func__);
98 for (l = sdi->
probes; l; l = l->next) {
100 if (probe->
index == probenum) {
102 probe->
name = g_strdup(name);
133 for (l = sdi->
probes; l; l = l->next) {
135 if (probe->
index == probenum) {
170 for (l = sdi->
probes; l; l = l->next) {
172 if (probe->
index == probenum) {
175 probe->
trigger = g_strdup(trigger);
215 devopts = g_variant_get_fixed_array(gvar, &num_opts,
sizeof(int32_t));
216 for (i = 0; i < num_opts; i++) {
217 if (devopts[i] == key) {
222 g_variant_unref(gvar);
233 if (!(sdi = g_try_malloc(
sizeof(
struct sr_dev_inst)))) {
234 sr_err(
"Device instance malloc failed.");
242 sdi->
vendor = vendor ? g_strdup(vendor) : NULL;
243 sdi->
model = model ? g_strdup(model) : NULL;
244 sdi->
version = version ? g_strdup(version) : NULL;
258 for (l = sdi->
probes; l; l = l->next) {
264 g_slist_free(sdi->
probes);
272 #ifdef HAVE_LIBUSB_1_0
275 SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
276 uint8_t address,
struct libusb_device_handle *hdl)
278 struct sr_usb_dev_inst *udi;
280 if (!(udi = g_try_malloc(
sizeof(
struct sr_usb_dev_inst)))) {
281 sr_err(
"USB device instance malloc failed.");
286 udi->address = address;
293 SR_PRIV void sr_usb_dev_inst_free(
struct sr_usb_dev_inst *usb)
316 SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(
const char *port,
317 const char *serialcomm)
319 struct sr_serial_dev_inst *serial;
322 sr_err(
"Serial port required.");
326 if (!(serial = g_try_malloc0(
sizeof(
struct sr_serial_dev_inst)))) {
327 sr_err(
"Serial device instance malloc failed.");
331 serial->port = g_strdup(port);
333 serial->serialcomm = g_strdup(serialcomm);
340 SR_PRIV void sr_serial_dev_inst_free(
struct sr_serial_dev_inst *serial)
342 g_free(serial->port);
343 g_free(serial->serialcomm);
int sr_dev_probe_name_set(const struct sr_dev_inst *sdi, int probenum, const char *name)
Set the name of the specified probe in the specified device.
Device options for a particular device.
int(* config_list)(int info_id, GVariant **data, const struct sr_dev_inst *sdi)
int(* dev_open)(struct sr_dev_inst *sdi)
GSList * sr_dev_list(const struct sr_dev_driver *driver)
Get the list of devices/instances of the specified driver.
The public libsigrok header file to be used by frontends.
Generic/unspecified error.
int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum, gboolean state)
Enable or disable a probe on the specified device.
gboolean sr_dev_has_option(const struct sr_dev_inst *sdi, int key)
Determine whether the specified device instance has the specified capability.
struct sr_dev_driver * driver
int sr_dev_open(struct sr_dev_inst *sdi)
Open the specified device.
int sr_dev_close(struct sr_dev_inst *sdi)
Close the specified device.
int(* dev_close)(struct sr_dev_inst *sdi)
GSList *(* dev_list)(void)
int sr_dev_clear(const struct sr_dev_driver *driver)
Clear all devices/instances of the specified driver.
int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum, const char *trigger)
Add a trigger to the specified device (and the specified probe).
#define sr_err(s, args...)