LibreCAL API udpate
This commit is contained in:
parent
60c280b454
commit
a29c323556
@ -23,6 +23,7 @@ CalDevice::CalDevice(QString serial) :
|
|||||||
if(!okay) {
|
if(!okay) {
|
||||||
numPorts = 0;
|
numPorts = 0;
|
||||||
}
|
}
|
||||||
|
connect(usb, &USBDevice::communicationFailure, this, &CalDevice::disconnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
CalDevice::~CalDevice()
|
CalDevice::~CalDevice()
|
||||||
@ -32,24 +33,24 @@ CalDevice::~CalDevice()
|
|||||||
|
|
||||||
QString CalDevice::StandardToString(CalDevice::Standard s)
|
QString CalDevice::StandardToString(CalDevice::Standard s)
|
||||||
{
|
{
|
||||||
switch(s) {
|
switch(s.type) {
|
||||||
case Standard::Open: return "OPEN";
|
case Standard::Type::Open: return "OPEN";
|
||||||
case Standard::Short: return "SHORT";
|
case Standard::Type::Short: return "SHORT";
|
||||||
case Standard::Load: return "LOAD";
|
case Standard::Type::Load: return "LOAD";
|
||||||
case Standard::Through: return "THROUGH";
|
case Standard::Type::Through: return "THROUGH "+QString::number(s.throughDest);
|
||||||
case Standard::None: return "NONE";
|
case Standard::Type::None: return "NONE";
|
||||||
}
|
}
|
||||||
return "Invalid";
|
return "Invalid";
|
||||||
}
|
}
|
||||||
|
|
||||||
CalDevice::Standard CalDevice::StandardFromString(QString s)
|
CalDevice::Standard CalDevice::StandardFromString(QString s)
|
||||||
{
|
{
|
||||||
for(int i=0;i<=(int) Standard::None;i++) {
|
for(auto standard : availableStandards()) {
|
||||||
if(s == StandardToString((Standard) i)) {
|
if(s == StandardToString(standard)) {
|
||||||
return (Standard) i;
|
return standard;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Standard::None;
|
return Standard(Standard::Type::None);
|
||||||
}
|
}
|
||||||
|
|
||||||
CalDevice::Standard CalDevice::getStandard(int port)
|
CalDevice::Standard CalDevice::getStandard(int port)
|
||||||
@ -67,7 +68,7 @@ bool CalDevice::setStandard(int port, CalDevice::Standard s)
|
|||||||
|
|
||||||
std::vector<CalDevice::Standard> CalDevice::availableStandards()
|
std::vector<CalDevice::Standard> CalDevice::availableStandards()
|
||||||
{
|
{
|
||||||
return {Standard::None, Standard::Open, Standard::Short, Standard::Load, Standard::Through};
|
return {Standard(Standard::Type::None), Standard(Standard::Type::Open), Standard(Standard::Type::Short), Standard(Standard::Type::Load), Standard(1), Standard(2), Standard(3), Standard(4)};
|
||||||
}
|
}
|
||||||
|
|
||||||
double CalDevice::getTemperature()
|
double CalDevice::getTemperature()
|
||||||
@ -113,6 +114,11 @@ unsigned int CalDevice::getNumPorts() const
|
|||||||
return numPorts;
|
return numPorts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CalDevice::enterBootloader()
|
||||||
|
{
|
||||||
|
return usb->Cmd(":BOOTloader");
|
||||||
|
}
|
||||||
|
|
||||||
void CalDevice::loadCoefficientSets(QStringList names)
|
void CalDevice::loadCoefficientSets(QStringList names)
|
||||||
{
|
{
|
||||||
coeffSets.clear();
|
coeffSets.clear();
|
||||||
@ -306,6 +312,18 @@ std::vector<CalDevice::CoefficientSet> CalDevice::getCoefficientSets() const
|
|||||||
return coeffSets;
|
return coeffSets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CalDevice::addCoefficientSet(QString name)
|
||||||
|
{
|
||||||
|
CoefficientSet set;
|
||||||
|
set.name = name;
|
||||||
|
set.ports = numPorts;
|
||||||
|
set.loads.resize(numPorts, new CoefficientSet::Coefficient());
|
||||||
|
set.shorts.resize(numPorts, new CoefficientSet::Coefficient());
|
||||||
|
set.opens.resize(numPorts, new CoefficientSet::Coefficient());
|
||||||
|
set.throughs.resize(numPorts*(numPorts-1)/2, new CoefficientSet::Coefficient());
|
||||||
|
coeffSets.push_back(set);
|
||||||
|
}
|
||||||
|
|
||||||
QStringList CalDevice::getCoefficientSetNames()
|
QStringList CalDevice::getCoefficientSetNames()
|
||||||
{
|
{
|
||||||
QString resp = usb->Query(":COEFF:LIST?");
|
QString resp = usb->Query(":COEFF:LIST?");
|
||||||
|
@ -14,13 +14,20 @@ public:
|
|||||||
CalDevice(QString serial);
|
CalDevice(QString serial);
|
||||||
~CalDevice();
|
~CalDevice();
|
||||||
|
|
||||||
enum class Standard {
|
class Standard {
|
||||||
|
public:
|
||||||
|
enum class Type {
|
||||||
Open,
|
Open,
|
||||||
Short,
|
Short,
|
||||||
Load,
|
Load,
|
||||||
Through,
|
Through,
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
Standard(Type type) : type(type), throughDest(0){}
|
||||||
|
Standard(int throughDest) : type(Type::Through), throughDest(throughDest){}
|
||||||
|
Type type;
|
||||||
|
int throughDest;
|
||||||
|
};
|
||||||
|
|
||||||
static QString StandardToString(Standard s);
|
static QString StandardToString(Standard s);
|
||||||
static Standard StandardFromString(QString s);
|
static Standard StandardFromString(QString s);
|
||||||
@ -37,6 +44,8 @@ public:
|
|||||||
QString getFirmware() const;
|
QString getFirmware() const;
|
||||||
unsigned int getNumPorts() const;
|
unsigned int getNumPorts() const;
|
||||||
|
|
||||||
|
bool enterBootloader();
|
||||||
|
|
||||||
class CoefficientSet {
|
class CoefficientSet {
|
||||||
public:
|
public:
|
||||||
QString name;
|
QString name;
|
||||||
@ -67,6 +76,8 @@ public:
|
|||||||
void saveCoefficientSets();
|
void saveCoefficientSets();
|
||||||
std::vector<CoefficientSet> getCoefficientSets() const;
|
std::vector<CoefficientSet> getCoefficientSets() const;
|
||||||
|
|
||||||
|
void addCoefficientSet(QString name);
|
||||||
|
|
||||||
QStringList getCoefficientSetNames();
|
QStringList getCoefficientSetNames();
|
||||||
|
|
||||||
bool hasModifiedCoefficients();
|
bool hasModifiedCoefficients();
|
||||||
@ -76,6 +87,8 @@ signals:
|
|||||||
// emitted when all coefficients have been received and it is safe to call all functions again
|
// emitted when all coefficients have been received and it is safe to call all functions again
|
||||||
void updateCoefficientsDone(bool success);
|
void updateCoefficientsDone(bool success);
|
||||||
|
|
||||||
|
void disconnected();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadCoefficientSetsThread(QStringList names = QStringList());
|
void loadCoefficientSetsThread(QStringList names = QStringList());
|
||||||
void saveCoefficientSetsThread();
|
void saveCoefficientSetsThread();
|
||||||
|
@ -348,15 +348,15 @@ void LibreCALDialog::startCalibration()
|
|||||||
ui->progressCal->setValue(measurementsTaken * 100 / totalMeasurements);
|
ui->progressCal->setValue(measurementsTaken * 100 / totalMeasurements);
|
||||||
switch(measurementsTaken) {
|
switch(measurementsTaken) {
|
||||||
case 0:
|
case 0:
|
||||||
setTerminationOnAllUsedPorts(CalDevice::Standard::Open);
|
setTerminationOnAllUsedPorts(CalDevice::Standard(CalDevice::Standard::Type::Open));
|
||||||
emit cal->startMeasurements(openMeasurements);
|
emit cal->startMeasurements(openMeasurements);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
setTerminationOnAllUsedPorts(CalDevice::Standard::Short);
|
setTerminationOnAllUsedPorts(CalDevice::Standard(CalDevice::Standard::Type::Short));
|
||||||
emit cal->startMeasurements(shortMeasurements);
|
emit cal->startMeasurements(shortMeasurements);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
setTerminationOnAllUsedPorts(CalDevice::Standard::Load);
|
setTerminationOnAllUsedPorts(CalDevice::Standard(CalDevice::Standard::Type::Load));
|
||||||
emit cal->startMeasurements(loadMeasurements);
|
emit cal->startMeasurements(loadMeasurements);
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
@ -384,14 +384,13 @@ void LibreCALDialog::startCalibration()
|
|||||||
}
|
}
|
||||||
// sever connection to this function
|
// sever connection to this function
|
||||||
disconnect(cal, &Calibration::measurementsUpdated, this, nullptr);
|
disconnect(cal, &Calibration::measurementsUpdated, this, nullptr);
|
||||||
setTerminationOnAllUsedPorts(CalDevice::Standard::None);
|
setTerminationOnAllUsedPorts(CalDevice::Standard(CalDevice::Standard::Type::None));
|
||||||
enableUI();
|
enableUI();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
setTerminationOnAllUsedPorts(CalDevice::Standard::None);
|
setTerminationOnAllUsedPorts(CalDevice::Standard(CalDevice::Standard::Type::None));
|
||||||
auto m = throughMeasurements[throughIndex];
|
auto m = throughMeasurements[throughIndex];
|
||||||
device->setStandard(m->getPort1(), CalDevice::Standard::Through);
|
device->setStandard(m->getPort1(), CalDevice::Standard(m->getPort2()));
|
||||||
device->setStandard(m->getPort2(), CalDevice::Standard::Through);
|
|
||||||
emit cal->startMeasurements({m});
|
emit cal->startMeasurements({m});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -78,11 +78,12 @@ bool USBDevice::Cmd(QString cmd)
|
|||||||
{
|
{
|
||||||
QString rcv;
|
QString rcv;
|
||||||
bool success = send(cmd) && receive(&rcv);
|
bool success = send(cmd) && receive(&rcv);
|
||||||
if(success) {
|
if(success && rcv == "") {
|
||||||
// empty response expected by commad
|
// empty response expected by commad
|
||||||
return rcv == "";
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// failed to send/receive
|
// failed to send/receive
|
||||||
|
emit communicationFailure();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,7 +94,11 @@ QString USBDevice::Query(QString query)
|
|||||||
QString rcv;
|
QString rcv;
|
||||||
if(receive(&rcv)) {
|
if(receive(&rcv)) {
|
||||||
return rcv;
|
return rcv;
|
||||||
|
} else {
|
||||||
|
emit communicationFailure();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
emit communicationFailure();
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
@ -194,7 +199,7 @@ void USBDevice::SearchDevices(std::function<bool (libusb_device_handle *, QStrin
|
|||||||
|
|
||||||
bool USBDevice::send(const QString &s)
|
bool USBDevice::send(const QString &s)
|
||||||
{
|
{
|
||||||
qDebug() << "Send:"<<s;
|
// qDebug() << "Send:"<<s;
|
||||||
unsigned char data[s.size()+2];
|
unsigned char data[s.size()+2];
|
||||||
memcpy(data, s.toLatin1().data(), s.size());
|
memcpy(data, s.toLatin1().data(), s.size());
|
||||||
memcpy(&data[s.size()], "\r\n", 2);
|
memcpy(&data[s.size()], "\r\n", 2);
|
||||||
@ -232,7 +237,7 @@ bool USBDevice::receive(QString *s)
|
|||||||
if(res == 0) {
|
if(res == 0) {
|
||||||
if(s) {
|
if(s) {
|
||||||
*s = QString(data);
|
*s = QString(data);
|
||||||
qDebug() << "Receive:"<<*s;
|
// qDebug() << "Receive:"<<*s;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -240,6 +245,13 @@ bool USBDevice::receive(QString *s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool USBDevice::flushRX()
|
||||||
|
{
|
||||||
|
char data[512];
|
||||||
|
// libusb_bulk_transfer(m_handle, LIBUSB_ENDPOINT_IN | 0x03, (unsigned char*) data, sizeof(data), &actual, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString USBDevice::serial() const
|
QString USBDevice::serial() const
|
||||||
{
|
{
|
||||||
return m_serial;
|
return m_serial;
|
||||||
|
@ -6,8 +6,11 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
class USBDevice
|
#include <QObject>
|
||||||
|
|
||||||
|
class USBDevice : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
// connect to a CAL device. If serial is specified only connecting to this device, otherwise to the first one found
|
// connect to a CAL device. If serial is specified only connecting to this device, otherwise to the first one found
|
||||||
USBDevice(QString serial = QString());
|
USBDevice(QString serial = QString());
|
||||||
@ -20,10 +23,14 @@ public:
|
|||||||
// Returns serial numbers of all connected devices
|
// Returns serial numbers of all connected devices
|
||||||
static std::set<QString> GetDevices();
|
static std::set<QString> GetDevices();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void communicationFailure();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void SearchDevices(std::function<bool (libusb_device_handle *, QString)> foundCallback, libusb_context *context, bool ignoreOpenError);
|
static void SearchDevices(std::function<bool (libusb_device_handle *, QString)> foundCallback, libusb_context *context, bool ignoreOpenError);
|
||||||
bool send(const QString &s);
|
bool send(const QString &s);
|
||||||
bool receive(QString *s);
|
bool receive(QString *s);
|
||||||
|
bool flushRX();
|
||||||
libusb_device_handle *m_handle;
|
libusb_device_handle *m_handle;
|
||||||
libusb_context *m_context;
|
libusb_context *m_context;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user