Implement reading sensor values
This commit is contained in:
parent
6244f6f8ae
commit
728cb50a1e
@ -33,7 +33,14 @@ std::pair<int, int> SensorDriver::Sensor::readRange() const
|
||||
|
||||
std::vector<int> SensorDriver::Sensor::readValues() const
|
||||
{
|
||||
return {520, 1233, 4233};
|
||||
qDebug(ltr("Reading values of sensor on port %1").arg(m_serialPortName));
|
||||
|
||||
const auto readCmd = QByteArray(READ_CMD.data(), static_cast<int>(READ_CMD.size()));
|
||||
QByteArray response;
|
||||
if(!getSensorCommandResponse(m_serialPortName, readCmd, response))
|
||||
return {};
|
||||
|
||||
return parseReadResponse(response);
|
||||
}
|
||||
|
||||
std::pair<int, int> SensorDriver::Sensor::parseRangeResponse(const QByteArray& response) const
|
||||
@ -50,6 +57,20 @@ std::pair<int, int> SensorDriver::Sensor::parseRangeResponse(const QByteArray& r
|
||||
return {-1, -1};
|
||||
}
|
||||
|
||||
std::vector<int> SensorDriver::Sensor::parseReadResponse(const QByteArray& response) const
|
||||
{
|
||||
const auto readRegex = std::regex("([0-9]+),([0-9]+),([0-9]+)");
|
||||
const auto strResponse = response.toStdString();
|
||||
std::smatch readMatch;
|
||||
|
||||
if(std::regex_search(strResponse, readMatch, readRegex)) {
|
||||
qDebug(ltr("Found read response: '%1'").arg(QString().fromStdString(readMatch[0].str())));
|
||||
return {std::stoi(readMatch[1]), std::stoi(readMatch[2]), std::stoi(readMatch[3])};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
SensorDriver::SensorDriver()
|
||||
{
|
||||
qDebug("Initializing sensor driver");
|
||||
|
@ -20,6 +20,7 @@ class SensorDriver {
|
||||
QString m_serialPortName;
|
||||
|
||||
std::pair<int, int> parseRangeResponse(const QByteArray& response) const;
|
||||
std::vector<int> parseReadResponse(const QByteArray& response) const;
|
||||
};
|
||||
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user