#include "sensor_driver.hpp"

#include <QSerialPortInfo>
#include <QtDebug>
#include <QtGlobal>

#include "log_tr.hpp"

std::vector<Sensor> enumerateSensors()
{
    qDebug(ltr("Enumerating sensors"));

    std::vector<Sensor> sensors;

    const auto portsInfo = QSerialPortInfo::availablePorts();

    qDebug(ltr("Found %1 serial ports").arg(portsInfo.count()));

    for(const auto& portInfo: portsInfo) {
        qDebug(ltr("Checking port %1").arg(portInfo.portName()));
        auto sensor = Sensor(portInfo.portName());
        if(sensor.isValidSensor()) {
            qInfo(ltr("Successfully enumerated sensor on port %1").arg(portInfo.portName()));
            sensors.push_back(sensor);
        }
    }

    return sensors;
}
