From a25ae69e9acb2fe566ca39d61d87910c6a1564eb Mon Sep 17 00:00:00 2001 From: Bernhard Trinnes Date: Sat, 12 Jan 2019 19:31:58 +0100 Subject: [PATCH] Serial port commander: removed deprecated files --- .../devicepluginserialportcommander.cpp | 20 +- serialportcommander/serialportcommander.cpp | 183 ------------------ serialportcommander/serialportcommander.h | 74 ------- 3 files changed, 17 insertions(+), 260 deletions(-) delete mode 100644 serialportcommander/serialportcommander.cpp delete mode 100644 serialportcommander/serialportcommander.h diff --git a/serialportcommander/devicepluginserialportcommander.cpp b/serialportcommander/devicepluginserialportcommander.cpp index fd5b9d90..02815518 100644 --- a/serialportcommander/devicepluginserialportcommander.cpp +++ b/serialportcommander/devicepluginserialportcommander.cpp @@ -20,6 +20,23 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/*! + \page serialportcommander.html + \title Serial Port Commander + \brief Plug-In to send and receive strings over a serial port. + + \ingroup plugins + \ingroup nymea-plugins + + \chapter Plugin properties + Following JSON file contains the definition and the description of all available \l{DeviceClass}{DeviceClasses} + and \l{Vendor}{Vendors} of this \l{DevicePlugin}. + + For more details how to read this JSON file please check out the documentation for \l{The plugin JSON File}. + + \quotefile plugins/deviceplugins/serialportcommander/devicepluginserialportcommander.json +*/ + #include "devicepluginserialportcommander.h" #include "plugininfo.h" @@ -33,7 +50,6 @@ void DevicePluginSerialPortCommander::init() DeviceManager::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(Device *device) { - if (device->deviceClassId() == serialPortCommanderDeviceClassId) { QString interface = device->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString(); @@ -68,7 +84,6 @@ DeviceManager::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(De serialPort->setFlowControl(QSerialPort::FlowControl::NoFlowControl); } - if (!serialPort->open(QIODevice::ReadWrite)) { qCWarning(dcSerialPortCommander()) << "Could not open serial port" << interface << serialPort->errorString(); return DeviceManager::DeviceSetupStatusFailure; @@ -96,7 +111,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; diff --git a/serialportcommander/serialportcommander.cpp b/serialportcommander/serialportcommander.cpp deleted file mode 100644 index cc4c6d14..00000000 --- a/serialportcommander/serialportcommander.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * - * Copyright (C) 2017 Bernhard Trinnes * - * * - * This file is part of guh. * - * * - * Guh is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, version 2 of the License. * - * * - * Guh is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with guh. If not, see . * - * * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#include "serialportcommander.h" - -SerialPortCommander::SerialPortCommander(QSerialPort *serialPort, QObject *parent) : - QObject(parent), - m_serialPort(serialPort) -{ - connect(m_serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(onSerialError(QSerialPort::SerialPortError))); - connect(m_serialPort, SIGNAL(readyRead()), this, SLOT(onReadyRead())); - connect(m_serialPort, SIGNAL(baudRateChanged(qint32, QSerialPort::Direction)), this, SLOT(onBaudRateChanged(qint32, QSerialPort::Direction))); - connect(m_serialPort, SIGNAL(parityChanged(QSerialPort::Parity)), this, SLOT(onParityChanged(QSerialPort::Parity))); - connect(m_serialPort, SIGNAL(dataBitsChanged(QSerialPort::DataBits)), this, SLOT(onDataBitsChanged(QSerialPort::DataBits))); - connect(m_serialPort, SIGNAL(stopBitsChanged(QSerialPort::StopBits)), this, SLOT(onStopBitsChanged(QSerialPort::StopBits))); - connect(m_serialPort, SIGNAL(flowControlChanged(QSerialPort::FlowControl)), this, SLOT(onFlowControlChanged(QSerialPort::FlowControl))); -} - - -SerialPortCommander::~SerialPortCommander() -{ - m_serialPort->close(); - m_serialPort->deleteLater(); -} - - -void SerialPortCommander::addOutputDevice(Device* device) -{ - m_outputDevice = device; -} - - -void SerialPortCommander::removeOutputDevice() -{ - m_outputDevice = nullptr; -} - - -void SerialPortCommander::addInputDevice(Device* device) -{ - m_inputDevices.append(device); -} - - -void SerialPortCommander::removeInputDevice(Device* device) -{ - m_inputDevices.removeAll(device); -} - - -bool SerialPortCommander::isEmpty() -{ - return(!hasOutputDevice() && m_inputDevices.empty()); -} - - -bool SerialPortCommander::hasOutputDevice() -{ - if (m_outputDevice == nullptr) { - return false; - } else { - return true; - } -} - - -QSerialPort * SerialPortCommander::serialPort() -{ - return m_serialPort; -} - - -Device * SerialPortCommander::outputDevice() -{ - return m_outputDevice; -} - - -void SerialPortCommander::onReadyRead() -{ - QByteArray data; - while (!m_serialPort->atEnd()) { - data = m_serialPort->read(100); - } - qDebug(dcSerialPortCommander()) << "Message received" << data; - - foreach (Device *device, m_inputDevices) { - if (device->paramValue(serialPortInputComparisonTypeParamTypeId).toString() == "Is exactly") { - if (data == device->paramValue(serialPortInputInputCommandParamTypeId)) { - emit commandReceived(device); - } - } else if (device->paramValue(serialPortInputComparisonTypeParamTypeId).toString() == "Contains") { - if (data.contains(device->paramValue(serialPortInputInputCommandParamTypeId).toByteArray())) { - emit commandReceived(device); - } - } else if (device->paramValue(serialPortInputComparisonTypeParamTypeId) == "Contains not") { - if (!data.contains(device->paramValue(serialPortInputInputCommandParamTypeId).toByteArray())) { - emit commandReceived(device); - } - } else if (device->paramValue(serialPortInputComparisonTypeParamTypeId) == "Starts with") { - if (data.startsWith(device->paramValue(serialPortInputInputCommandParamTypeId).toByteArray())) { - emit commandReceived(device); - } - } else if (device->paramValue(serialPortInputComparisonTypeParamTypeId) == "Ends with") { - if (data.endsWith(device->paramValue(serialPortInputInputCommandParamTypeId).toByteArray())) { - emit commandReceived(device); - } - } - } -} - -void SerialPortCommander::onSerialError(QSerialPort::SerialPortError error) -{ - Q_UNUSED(error); -} - -void SerialPortCommander::onBaudRateChanged(qint32 baudRate, QSerialPort::Direction direction) -{ - Q_UNUSED(direction); - foreach(Device *device, m_inputDevices) { - device->setParamValue(serialPortInputBaudRateParamTypeId, baudRate); - } - if(m_outputDevice != nullptr) - m_outputDevice->setParamValue(serialPortOutputBaudRateParamTypeId, baudRate); -} - -void SerialPortCommander::onParityChanged(QSerialPort::Parity parity) -{ - foreach(Device *device, m_inputDevices) { - device->setParamValue(serialPortInputParityParamTypeId, parity); //TODO Strings not int - } - if(m_outputDevice != nullptr) - m_outputDevice->setParamValue(serialPortOutputBaudRateParamTypeId, parity); -} - -void SerialPortCommander::onDataBitsChanged(QSerialPort::DataBits dataBits) -{ - foreach(Device *device, m_inputDevices) { - device->setParamValue(serialPortInputDataBitsParamTypeId, dataBits); - } - if(m_outputDevice != nullptr) - m_outputDevice->setParamValue(serialPortOutputDataBitsParamTypeId, dataBits); -} - -void SerialPortCommander::onStopBitsChanged(QSerialPort::StopBits stopBits) -{ - foreach(Device *device, m_inputDevices) { - device->setParamValue(serialPortInputStopBitsParamTypeId, stopBits); - } - if(m_outputDevice != nullptr) - m_outputDevice->setParamValue(serialPortOutputStopBitsParamTypeId, stopBits); -} - -void SerialPortCommander::onFlowControlChanged(QSerialPort::FlowControl flowControl) -{ - //foreach(Device *device, m_inputDevices) { //TODO enum to stringau - //device->setParamValue(serialPortInputFlowControlParamTypeId, QVariant::fromValue(QSerialPort::FlowControl).value()); - //} - if(m_outputDevice != nullptr) - m_outputDevice->setParamValue(serialPortOutputFlowControlParamTypeId, flowControl); -} - -void SerialPortCommander::sendCommand(QByteArray data) -{ - m_serialPort->write(data); -} diff --git a/serialportcommander/serialportcommander.h b/serialportcommander/serialportcommander.h deleted file mode 100644 index 3b877623..00000000 --- a/serialportcommander/serialportcommander.h +++ /dev/null @@ -1,74 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * - * Copyright (C) 2017 Bernhard Trinnes * - * * - * This file is part of guh. * - * * - * Guh is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, version 2 of the License. * - * * - * Guh is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with guh. If not, see . * - * * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#ifndef SERIALPORTCOMMANDER_H -#define SERIALPORTCOMMANDER_H - -#include -#include -#include "extern-plugininfo.h" -#include "devicemanager.h" - -class SerialPortCommander : public QObject -{ - Q_OBJECT -public: - explicit SerialPortCommander(QSerialPort *serialPort ,QObject *parent = 0); - ~SerialPortCommander(); - - enum ComparisonType { - IsExactly, - Contains, - ContainsNot, - StartsWith, - EndsWith - }; - - void addOutputDevice(Device *device); - void addInputDevice(Device *device); - void removeInputDevice(Device *device); - bool isEmpty(); - bool hasOutputDevice(); - void removeOutputDevice(); - void sendCommand(QByteArray data); - QSerialPort *serialPort(); - Device *outputDevice(); - -private: - QList m_inputDevices; - Device *m_outputDevice; - QSerialPort *m_serialPort; - -signals: - void commandReceived(Device *device); - -public slots: - - void onReadyRead(); - void onSerialError(QSerialPort::SerialPortError error); - void onBaudRateChanged(qint32 baudRate, QSerialPort::Direction direction); - void onParityChanged(QSerialPort::Parity parity); - void onDataBitsChanged(QSerialPort::DataBits dataBits); - void onStopBitsChanged(QSerialPort::StopBits stopBits); - void onFlowControlChanged(QSerialPort::FlowControl flowControl); - -}; - -#endif // SERIALPORTCOMMANDER_H