15 #include <condition_variable> 198 int run(uint64_t samples);
213 int start(uint64_t samples);
244 int flash_firmware(std::string file, std::vector<Device*> devices = {});
251 void attached(libusb_device* usb_dev);
253 void detached(libusb_device* usb_dev);
346 std::pair<uint8_t, uint8_t> m_usb_addr;
351 virtual int fwver_sem(std::array<unsigned, 3>& components) = 0;
359 virtual int set_serial(std::string serial =
"") = 0;
369 virtual int set_mode(
unsigned channel,
unsigned mode,
bool restore =
true) = 0;
372 void set_usb(libusb_device_handle* usb) {
m_usb = usb;}
378 virtual int get_mode(
unsigned channel) = 0;
390 virtual ssize_t
read(std::vector<std::array<float, 4>>& buf,
size_t samples,
int timeout = 0,
bool skipsamples =
false) = 0;
399 virtual int write(std::vector<float>& buf,
unsigned channel,
bool cyclic =
false) = 0;
404 virtual void flush(
int channel,
bool read =
false) = 0;
409 int ctrl_transfer(
unsigned bmRequestType,
unsigned bRequest,
unsigned wValue,
unsigned wIndex,
410 unsigned char *data,
unsigned wLength,
unsigned timeout);
424 virtual int sync() = 0;
448 virtual void calibration(std::vector<std::vector<float>>* cal) = 0;
457 virtual int set_led(
unsigned leds) = 0;
462 virtual void set_usb_device_addr(std::pair<uint8_t, uint8_t> usb_addr) = 0;
466 Device(
Session* s, libusb_device* usb_dev, libusb_device_handle* usb_handle,
467 const char* hw_version,
const char* fw_version,
const char* serial);
483 virtual int configure(uint32_t sampleRate) = 0;
488 virtual int on() = 0;
493 virtual int off() = 0;
500 virtual int run(uint64_t samples) = 0;
550 void constant(std::vector<float>& buf, uint64_t samples,
float val);
560 void square(std::vector<float>& buf, uint64_t samples,
float midpoint,
float peak,
double period,
double phase,
double duty);
569 void sawtooth(std::vector<float>& buf, uint64_t samples,
float midpoint,
float peak,
double period,
double phase);
578 void stairstep(std::vector<float>& buf, uint64_t samples,
float midpoint,
float peak,
double period,
double phase);
587 void sine(std::vector<float>& buf, uint64_t samples,
float midpoint,
float peak,
double period,
double phase);
596 void triangle(std::vector<float>& buf, uint64_t samples,
float midpoint,
float peak,
double period,
double phase);
double resolution
Signal resolution.
Definition: libsmu.hpp:61
void handle_error(int status, const char *tag)
internal: Called by devices on the USB thread when a device encounters an error.
virtual int read_calibration()=0
Read device calibration data from the EEPROM.
virtual ssize_t read(std::vector< std::array< float, 4 >> &buf, size_t samples, int timeout=0, bool skipsamples=false)=0
Get all signal samples from a device.
Mode
Supported channel modes.
Definition: libsmu.hpp:88
std::mutex m_lock_devlist
Lock for the available device list. All code that references m_available_devices needs to acquire thi...
Definition: libsmu.hpp:289
int cancel()
Cancel capture and block waiting for it to complete.
uint64_t m_in_sampleno
Current sample number being handled for input.
Definition: libsmu.hpp:518
void sine(std::vector< float > &buf, uint64_t samples, float midpoint, float peak, double period, double phase)
Generate a sinusoidal waveform.
Source voltage, measure current.
Definition: libsmu.hpp:90
virtual int off()=0
Stop any current sample writes and stop capturing samples.
size_t signal_count
Number of available signals.
Definition: libsmu.hpp:68
virtual int run(uint64_t samples)=0
Make the device start sampling.
int remove(Device *device, bool detached=false)
Remove a device from the session.
int run(uint64_t samples)
Run the currently configured capture and wait for it to complete.
virtual int sync()=0
Prepare multi-device synchronization. Get current microframe index, set m_sof_start to be time in the...
const char * label
Device label.
Definition: libsmu.hpp:73
SIMV with enabled switch for the input only pin added in Rev F.
Definition: libsmu.hpp:94
const std::vector< std::vector< uint16_t > > SAMBA_DEVICES
List of supported devices in SAM-BA bootloader mode. The list uses the vendor and project IDs from US...
Definition: libsmu.hpp:39
uint64_t m_requested_sampleno
Cumulative sample number being handled for input.
Definition: libsmu.hpp:516
std::vector< std::function< void(Device *device)> > m_hotplug_detach_callbacks
Callbacks called on the USB thread when a device is plugged into the system.
Definition: libsmu.hpp:304
virtual void unlock()
Unlock the device's mutex. Allows this device's transfers to be processed.
Definition: libsmu.hpp:433
Src
Supported signal sources.
Definition: libsmu.hpp:78
std::condition_variable m_completion
Blocks on m_lock until session completion is finished.
Definition: libsmu.hpp:291
uint32_t inputModes
Bitmask of modes for which this signal is enabled as input.
Definition: libsmu.hpp:49
Stairstep wave output.
Definition: libsmu.hpp:82
int scan_samba_devs(std::vector< libusb_device * > &samba_devs)
Scan system for devices in SAM-BA mode.
virtual int set_adc_mux(unsigned adc_mux)=0
set adc mux mode
std::recursive_mutex m_state
Lock for transfer state.
Definition: libsmu.hpp:527
virtual int cancel()=0
Cancel all pending libusb transactions.
virtual const sl_channel_info * channel_info(unsigned channel) const =0
Get the descriptor for the specified channel.
int add_all()
Shim to scan and add all available devices to a session. This method may not be called while the sess...
Source current, measure voltage.
Definition: libsmu.hpp:91
std::vector< Device * > m_available_devices
Devices that are present on the system. Note that these devices consist of all supported devices curr...
Definition: libsmu.hpp:123
Device(Session *s, libusb_device *usb_dev, libusb_device_handle *usb_handle, const char *hw_version, const char *fw_version, const char *serial)
Device constructor.
virtual const sl_device_info * info() const =0
Get the descriptor for the device.
struct sl_signal_info sl_signal_info
Signal information.
libusb_device *const m_usb_dev
Underlying libusb device.
Definition: libsmu.hpp:511
libusb_context * m_usb_ctx
libusb context related with a session. This allows for segregating libusb usage so external users can...
Definition: libsmu.hpp:296
Device info.
Definition: libsmu.hpp:72
virtual int get_default_rate()
Get the default sample rate.
Definition: libsmu.hpp:418
void stairstep(std::vector< float > &buf, uint64_t samples, float midpoint, float peak, double period, double phase)
Generate a stairstep waveform.
Signal(const sl_signal_info *info=NULL)
internal: Do not call the constructor directly; obtain a Signal from a Device.
Definition: libsmu.hpp:536
virtual int claim()
Device claiming and initialization when a session adds this device.
Definition: libsmu.hpp:472
void constant(std::vector< float > &buf, uint64_t samples, float val)
Generate a constant waveform.
const char * label
Signal label.
Definition: libsmu.hpp:46
int ctrl_transfer(unsigned bmRequestType, unsigned bRequest, unsigned wValue, unsigned wIndex, unsigned char *data, unsigned wLength, unsigned timeout)
Perform a raw USB control transfer on the underlying USB device.
Generic signal class.
Definition: libsmu.hpp:533
double max
Maximum possible value for the signal.
Definition: libsmu.hpp:58
double min
Minimum possible value for the signal.
Definition: libsmu.hpp:55
uint64_t m_sample_rate
Session sample rate.
Definition: libsmu.hpp:269
virtual int configure(uint32_t sampleRate)=0
Configurization and initialization for device sampling.
void square(std::vector< float > &buf, uint64_t samples, float midpoint, float peak, double period, double phase, double duty)
Generate a square waveform.
void triangle(std::vector< float > &buf, uint64_t samples, float midpoint, float peak, double period, double phase)
Generate a triangle waveform.
Square wave output.
Definition: libsmu.hpp:80
virtual int fwver_sem(std::array< unsigned, 3 > &components)=0
Get the array of firmware version components (major, minor, patch). Note that this method assumes sem...
virtual int get_mode(unsigned channel)=0
Get the mode of the specified channel.
virtual int write(std::vector< float > &buf, unsigned channel, bool cyclic=false)=0
Write data to a specified channel of the device.
Channel info.
Definition: libsmu.hpp:65
struct sl_channel_info sl_channel_info
Channel info.
int scan()
Scan system for all supported devices. Updates the list of available, supported devices for the sessi...
virtual Signal * signal(unsigned channel, unsigned signal)=0
Get the specified signal.
struct sl_device_info sl_device_info
Device info.
virtual void flush(int channel, bool read=false)=0
Flush the read and selected channel write queue for a device.
const std::string m_serial
serial number
Definition: libsmu.hpp:343
HI_Z with enabled switch for the input only pin added in Rev F.
Definition: libsmu.hpp:92
int start(uint64_t samples)
Start the currently configured capture, but do not wait for it to complete.
const sl_signal_info *const m_info
Signal information.
Definition: libsmu.hpp:544
bool m_continuous
Flag used to determine if a session is in continuous mode or not.
Definition: libsmu.hpp:272
virtual int release()
Device releasing when a session removes this device.
Definition: libsmu.hpp:477
Generic device class.
Definition: libsmu.hpp:321
virtual int set_mode(unsigned channel, unsigned mode, bool restore=true)=0
Set the mode of the specified channel.
std::vector< std::function< void(Device *device)> > m_hotplug_attach_callbacks
Callbacks called on the USB thread when a device is removed from the system.
Definition: libsmu.hpp:302
void completion()
internal: Called by devices on the USB thread when they are complete.
virtual void calibration(std::vector< std::vector< float >> *cal)=0
Get the device calibration data from the EEPROM.
int destroy(Device *device)
Remove a device from the list of available devices.
std::thread m_usb_thread
USB thread handling pending events in blocking mode.
Definition: libsmu.hpp:282
size_t mode_count
Number of available modes.
Definition: libsmu.hpp:67
double m_write_timeout
Amount of time in milliseconds to wait before timing out write operations, defaults to 100 ms and is ...
Definition: libsmu.hpp:524
virtual int write_calibration(const char *cal_file_name)
Write the device calibration data into the EEPROM.
Definition: libsmu.hpp:441
unsigned m_active_devices
Number of devices currently streaming samples.
Definition: libsmu.hpp:131
std::atomic< bool > m_usb_thread_loop
Flag for controlling USB event handling. USB event handling loop will be run while m_usb_thread_loop ...
Definition: libsmu.hpp:280
unsigned m_cancellation
Flag used to cancel all pending USB transactions for devices in a session.
Definition: libsmu.hpp:276
Constant value output.
Definition: libsmu.hpp:79
int m_overcurrent
Session this device is associated with.
Definition: libsmu.hpp:453
SVMI with enabled switch for the input only pin added in Rev F.
Definition: libsmu.hpp:93
Generic session class.
Definition: libsmu.hpp:110
virtual int set_led(unsigned leds)=0
Set the leds states for device.
void attached(libusb_device *usb_dev)
internal: Called by device attach events on the USB thread.
Sine wave output.
Definition: libsmu.hpp:83
void detached(libusb_device *usb_dev)
internal: Called by device detach events on the USB thread.
unsigned m_queue_size
Size of input/output sample queues for every device. Alter this if necessary to make continuous data ...
Definition: libsmu.hpp:141
const std::vector< std::vector< uint16_t > > SUPPORTED_DEVICES
List of supported devices. The list uses the vendor and project IDs from USB information formatted as...
Definition: libsmu.hpp:31
uint32_t outputModes
Bitmask of modes for which this signal is enabled as output.
Definition: libsmu.hpp:52
virtual void lock()
Lock the device's mutex. This prevents this device's transfers from being processed....
Definition: libsmu.hpp:429
int add(Device *device)
Add a device to the session. This method may not be called while the session is active.
std::map< libusb_device *, libusb_device_handle * > m_deviceHandles
Map for the workaround described in session.cpp -> probe_device().
Definition: libsmu.hpp:134
int end()
For noncontinuous sessions, block until all devices have completed, then turn off the devices....
std::mutex m_lock
Lock for session completion.
Definition: libsmu.hpp:285
virtual int samba_mode()=0
Force the device into SAM-BA bootloader mode.
void flush()
Flush the read and write queues for all devices in a session.
virtual int set_serial(std::string serial="")=0
Set a custom serial number for the device.
Channel is floating.
Definition: libsmu.hpp:89
libusb_hotplug_callback_handle m_usb_cb
libusb hotplug callback handle.
Definition: libsmu.hpp:299
Session *const m_session
Session this device is associated with.
Definition: libsmu.hpp:508
const char * label
Channel label.
Definition: libsmu.hpp:66
size_t channel_count
Number of available channels.
Definition: libsmu.hpp:74
Signal information.
Definition: libsmu.hpp:44
void sawtooth(std::vector< float > &buf, uint64_t samples, float midpoint, float peak, double period, double phase)
Generate a sawtooth waveform.
std::set< Device * > m_devices
Devices that are part of this session. These devices will be started when start() is called....
Definition: libsmu.hpp:128
libusb_device_handle * m_usb
Underlying libusb device handle.
Definition: libsmu.hpp:513
const sl_signal_info * info() const
Get the descriptor struct of the Signal. Pointed-to memory is valid for the lifetime of the Device.
Definition: libsmu.hpp:542
const std::string m_fwver
firmware version
Definition: libsmu.hpp:341
Triangle wave output.
Definition: libsmu.hpp:84
Library versioning support. Versioning for libsmu follows the guidelines of semantic versioning for s...
Sawtooth wave output.
Definition: libsmu.hpp:81
float get_sample()
Generate value for currently selected waveform.
int flash_firmware(std::string file, std::vector< Device * > devices={})
Update firmware for the target device(s).
bool cancelled()
Determine the cancellation status of a session.
Definition: libsmu.hpp:227
int configure(uint32_t sampleRate=0)
Configure the session's sample rate.
Device * probe_device(libusb_device *usb_dev)
Identify devices supported by libsmu.
Device * find_existing_device(libusb_device *usb_dev)
Find an existing, available device.
std::function< void(unsigned)> m_completion_callback
Callback run via the USB thread on session completion. Called with the current value of m_cancellatio...
Definition: libsmu.hpp:266
const std::string m_hwver
hardware version
Definition: libsmu.hpp:339
virtual int on()=0
Turn on power supplies and clear sampling state.
uint64_t m_out_sampleno
Current sample number being submitted for output.
Definition: libsmu.hpp:520