mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
temper: move basic device lifecycle functions to usb code
This commit is contained in:
parent
dbf798f29b
commit
11849a59c0
2 changed files with 25 additions and 8 deletions
|
@ -24,6 +24,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <villas/exceptions.hpp>
|
||||
#include <villas/log.hpp>
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
|
@ -87,11 +88,33 @@ protected:
|
|||
|
||||
std::string getStringDescriptor(uint8_t desc_id) const;
|
||||
|
||||
Logger logger;
|
||||
|
||||
public:
|
||||
Device(struct libusb_device *dev) :
|
||||
device(dev),
|
||||
handle(nullptr)
|
||||
{ }
|
||||
{
|
||||
int ret = libusb_get_device_descriptor(dev, &desc);
|
||||
if (ret != LIBUSB_SUCCESS)
|
||||
throw Error((enum libusb_error) ret, "Failed to get device descriptor");
|
||||
|
||||
auto ln = fmt::format("usb:dev:{}:{}", libusb_get_bus_number(device), libusb_get_port_number(device));
|
||||
logger = logging.get(ln);
|
||||
|
||||
ret = libusb_open(device, &handle);
|
||||
if (ret < 0)
|
||||
throw Error((enum libusb_error) ret, "Failed to open device");
|
||||
|
||||
libusb_ref_device(device);
|
||||
}
|
||||
|
||||
virtual ~Device()
|
||||
{
|
||||
libusb_close(handle);
|
||||
|
||||
libusb_unref_device(device);
|
||||
}
|
||||
|
||||
const struct libusb_device_descriptor & getDescriptor() const
|
||||
{
|
||||
|
|
|
@ -54,11 +54,7 @@ TEMPerDevice::TEMPerDevice(struct libusb_device *dev) :
|
|||
scale(1.0),
|
||||
offset(0.0),
|
||||
timeout(5000)
|
||||
{
|
||||
int ret = libusb_get_device_descriptor(dev, &desc);
|
||||
if (ret != LIBUSB_SUCCESS)
|
||||
throw RuntimeError("Could not get USB device descriptor: {}", libusb_strerror((enum libusb_error) ret));
|
||||
}
|
||||
{ }
|
||||
|
||||
void TEMPerDevice::open(bool reset)
|
||||
{
|
||||
|
@ -87,8 +83,6 @@ void TEMPerDevice::close()
|
|||
{
|
||||
libusb_release_interface(handle, 0x00);
|
||||
libusb_release_interface(handle, 0x01);
|
||||
|
||||
libusb_close(handle);
|
||||
}
|
||||
|
||||
void TEMPerDevice::read(struct sample *smp)
|
||||
|
|
Loading…
Add table
Reference in a new issue