Implement checking sensor version
This commit is contained in:
parent
6c50eb6f84
commit
7c54a080d1
@ -1,5 +1,7 @@
|
||||
#include "sensor_driver.hpp"
|
||||
|
||||
#include <regex>
|
||||
|
||||
#include <QSerialPort>
|
||||
#include <QSerialPortInfo>
|
||||
#include <QtDebug>
|
||||
@ -146,5 +148,20 @@ bool SensorDriver::isValidSensor(const QString& serialPortName) const
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
const auto version = parseVersionResponse(response);
|
||||
return version == "AdaptiveBrightness v1.2";
|
||||
}
|
||||
|
||||
std::string SensorDriver::parseVersionResponse(const QByteArray& response) const
|
||||
{
|
||||
const auto versionRegex = std::regex("[a-zA-Z]+ v[0-9]\\.[0-9]");
|
||||
const auto strResponse = response.toStdString();
|
||||
std::smatch versionMatch;
|
||||
|
||||
if(std::regex_search(strResponse, versionMatch, versionRegex)) {
|
||||
qDebug(ltr("Found version match: '%1'").arg(QString().fromStdString(versionMatch[0].str())));
|
||||
return versionMatch[0];
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -29,4 +29,5 @@ class SensorDriver {
|
||||
private:
|
||||
bool getSensorCommandResponse(const QString& serialPortName, QByteArray command, QByteArray& response) const;
|
||||
bool isValidSensor(const QString& serialPortName) const;
|
||||
std::string parseVersionResponse(const QByteArray& response) const;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user