From d3f00a9f5ee619511b10f3ab0539487c2fe0951e Mon Sep 17 00:00:00 2001 From: nymea Date: Mon, 20 May 2019 10:51:04 +0200 Subject: [PATCH] refurbished the serialport commander --- .../devicepluginserialportcommander.cpp | 57 ++++++++++--------- .../devicepluginserialportcommander.h | 5 +- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/serialportcommander/devicepluginserialportcommander.cpp b/serialportcommander/devicepluginserialportcommander.cpp index bff5e691..6f203946 100644 --- a/serialportcommander/devicepluginserialportcommander.cpp +++ b/serialportcommander/devicepluginserialportcommander.cpp @@ -44,6 +44,34 @@ DevicePluginSerialPortCommander::DevicePluginSerialPortCommander() { } + +DeviceManager::DeviceError DevicePluginSerialPortCommander::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) +{ + Q_UNUSED(params) + // Create the list of available serial interfaces + QList deviceDescriptors; + + foreach(QSerialPortInfo port, QSerialPortInfo::availablePorts()) { + + qCDebug(dcSerialPortCommander()) << "Found serial port:" << port.portName(); + QString description = port.manufacturer() + " " + port.description(); + DeviceDescriptor deviceDescriptor(deviceClassId, port.portName(), description); + ParamList parameters; + foreach (Device *existingDevice, myDevices()) { + if (existingDevice->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString() == port.portName()) { + deviceDescriptor.setDeviceId(existingDevice->id()); + break; + } + } + parameters.append(Param(serialPortCommanderDeviceSerialPortParamTypeId, port.portName())); + deviceDescriptor.setParams(parameters); + deviceDescriptors.append(deviceDescriptor); + } + emit devicesDiscovered(deviceClassId, deviceDescriptors); + return DeviceManager::DeviceErrorAsync; +} + + DeviceManager::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(Device *device) { if(!m_reconnectTimer) { @@ -105,33 +133,6 @@ DeviceManager::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(De } -DeviceManager::DeviceError DevicePluginSerialPortCommander::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) -{ - Q_UNUSED(params) - // Create the list of available serial interfaces - QList deviceDescriptors; - - foreach(QSerialPortInfo port, QSerialPortInfo::availablePorts()) { - - qCDebug(dcSerialPortCommander()) << "Found serial port:" << port.portName(); - QString description = port.manufacturer() + " " + port.description(); - DeviceDescriptor deviceDescriptor(deviceClassId, port.portName(), description); - ParamList parameters; - foreach (Device *existingDevice, myDevices()) { - if (existingDevice->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString() == port.portName()) { - deviceDescriptor.setDeviceId(existingDevice->id()); - break; - } - } - parameters.append(Param(serialPortCommanderDeviceSerialPortParamTypeId, port.portName())); - deviceDescriptor.setParams(parameters); - deviceDescriptors.append(deviceDescriptor); - } - emit devicesDiscovered(deviceClassId, deviceDescriptors); - return DeviceManager::DeviceErrorAsync; -} - - DeviceManager::DeviceError DevicePluginSerialPortCommander::executeAction(Device *device, const Action &action) { if (device->deviceClassId() == serialPortCommanderDeviceClassId ) { @@ -189,7 +190,7 @@ void DevicePluginSerialPortCommander::onReadyRead() emitEvent(event); } -void DevicePluginSerialPortCommander::onSerialError(const QSerialPort::SerialPortError &error) +void DevicePluginSerialPortCommander::onSerialError(QSerialPort::SerialPortError error) { QSerialPort *serialPort = static_cast(sender()); Device *device = m_serialPorts.key(serialPort); diff --git a/serialportcommander/devicepluginserialportcommander.h b/serialportcommander/devicepluginserialportcommander.h index 302ab647..44d69ecf 100644 --- a/serialportcommander/devicepluginserialportcommander.h +++ b/serialportcommander/devicepluginserialportcommander.h @@ -25,8 +25,8 @@ #include "plugin/deviceplugin.h" #include "devicemanager.h" -#include +#include #include #include @@ -51,14 +51,13 @@ private: private slots: void onReadyRead(); - void onSerialError(const QSerialPort::SerialPortError &error); + void onSerialError(QSerialPort::SerialPortError error); void onBaudRateChanged(qint32 baudRate, QSerialPort::Directions direction); void onParityChanged(QSerialPort::Parity parity); void onDataBitsChanged(QSerialPort::DataBits dataBits); void onStopBitsChanged(QSerialPort::StopBits stopBits); void onFlowControlChanged(QSerialPort::FlowControl flowControl); void onReconnectTimer(); - }; #endif // DEVICEPLUGINSERIALPORTCOMMANDER_H