diff --git a/serialportcommander/devicepluginserialportcommander.cpp b/serialportcommander/devicepluginserialportcommander.cpp index 44e346b7..42af3046 100644 --- a/serialportcommander/devicepluginserialportcommander.cpp +++ b/serialportcommander/devicepluginserialportcommander.cpp @@ -28,17 +28,15 @@ DevicePluginSerialPortCommander::DevicePluginSerialPortCommander() } -Device::DeviceError DevicePluginSerialPortCommander::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) +void DevicePluginSerialPortCommander::discoverDevices(DeviceDiscoveryInfo *info) { - 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); + DeviceDescriptor deviceDescriptor(info->deviceClassId(), port.portName(), description); ParamList parameters; foreach (Device *existingDevice, myDevices()) { if (existingDevice->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString() == port.portName()) { @@ -48,15 +46,17 @@ Device::DeviceError DevicePluginSerialPortCommander::discoverDevices(const Devic } parameters.append(Param(serialPortCommanderDeviceSerialPortParamTypeId, port.portName())); deviceDescriptor.setParams(parameters); - deviceDescriptors.append(deviceDescriptor); + info->addDeviceDescriptor(deviceDescriptor); } - emit devicesDiscovered(deviceClassId, deviceDescriptors); - return Device::DeviceErrorAsync; + + info->finish(Device::DeviceErrorNoError); } -Device::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(Device *device) +void DevicePluginSerialPortCommander::setupDevice(DeviceSetupInfo *info) { + Device *device = info->device(); + if(!m_reconnectTimer) { m_reconnectTimer = new QTimer(this); m_reconnectTimer->setSingleShot(true); @@ -68,8 +68,6 @@ Device::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(Device *d if (device->deviceClassId() == serialPortCommanderDeviceClassId) { QString interface = device->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString(); QSerialPort *serialPort = new QSerialPort(interface, this); - if(!serialPort) - return Device::DeviceSetupStatusFailure; serialPort->setBaudRate(device->paramValue(serialPortCommanderDeviceBaudRateParamTypeId).toInt()); serialPort->setDataBits(QSerialPort::DataBits(device->paramValue(serialPortCommanderDeviceDataBitsParamTypeId).toInt())); @@ -99,7 +97,8 @@ Device::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(Device *d if (!serialPort->open(QIODevice::ReadWrite)) { qCWarning(dcSerialPortCommander()) << "Could not open serial port" << interface << serialPort->errorString(); serialPort->deleteLater(); - return Device::DeviceSetupStatusFailure; + //: Error setting up device + return info->finish(Device::DeviceErrorHardwareFailure, QT_TR_NOOP("Could not open serial port.")); } connect(serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(onSerialError(QSerialPort::SerialPortError))); @@ -112,26 +111,26 @@ Device::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(Device *d m_serialPorts.insert(device, serialPort); device->setStateValue(serialPortCommanderConnectedStateTypeId, true); } - return Device::DeviceSetupStatusSuccess; + return info->finish(Device::DeviceErrorNoError); } -Device::DeviceError DevicePluginSerialPortCommander::executeAction(Device *device, const Action &action) +void DevicePluginSerialPortCommander::executeAction(DeviceActionInfo *info) { - if (device->deviceClassId() == serialPortCommanderDeviceClassId ) { + Device *device = info->device(); + Action action = info->action(); - if (action.actionTypeId() == serialPortCommanderTriggerActionTypeId) { - QSerialPort *serialPort = m_serialPorts.value(device); - qint64 size = serialPort->write(action.param(serialPortCommanderTriggerActionOutputDataParamTypeId).value().toByteArray()); - if(size != action.param(serialPortCommanderTriggerActionOutputDataParamTypeId).value().toByteArray().length()) { - return Device::DeviceErrorHardwareFailure; - } - return Device::DeviceErrorNoError; + if (action.actionTypeId() == serialPortCommanderTriggerActionTypeId) { + + QSerialPort *serialPort = m_serialPorts.value(device); + qint64 size = serialPort->write(action.param(serialPortCommanderTriggerActionOutputDataParamTypeId).value().toByteArray()); + if(size != action.param(serialPortCommanderTriggerActionOutputDataParamTypeId).value().toByteArray().length()) { + return info->finish(Device::DeviceErrorHardwareFailure, QT_TR_NOOP("Error writing to serial port.")); } - return Device::DeviceErrorActionTypeNotFound; + return info->finish(Device::DeviceErrorNoError); } - return Device::DeviceErrorDeviceClassNotFound; + info->finish(Device::DeviceErrorActionTypeNotFound); } diff --git a/serialportcommander/devicepluginserialportcommander.h b/serialportcommander/devicepluginserialportcommander.h index 1126df16..845baa45 100644 --- a/serialportcommander/devicepluginserialportcommander.h +++ b/serialportcommander/devicepluginserialportcommander.h @@ -39,10 +39,10 @@ class DevicePluginSerialPortCommander : public DevicePlugin public: explicit DevicePluginSerialPortCommander(); - Device::DeviceSetupStatus setupDevice(Device *device) override; + void setupDevice(DeviceSetupInfo *info) override; void deviceRemoved(Device *device) override; - Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override; - Device::DeviceError executeAction(Device *device, const Action &action) override; + void discoverDevices(DeviceDiscoveryInfo *info) override; + void executeAction(DeviceActionInfo *info) override; private: QTimer *m_reconnectTimer = nullptr; diff --git a/serialportcommander/translations/fe93a12e-36f4-4015-8019-26b659817773-en_US.ts b/serialportcommander/translations/fe93a12e-36f4-4015-8019-26b659817773-en_US.ts new file mode 100644 index 00000000..7b81e614 --- /dev/null +++ b/serialportcommander/translations/fe93a12e-36f4-4015-8019-26b659817773-en_US.ts @@ -0,0 +1,110 @@ + + + + + DevicePluginSerialPortCommander + + + Could not open serial port. + + + + + Error writing to serial port. + + + + + SerialPortCommander + + + Baud rate + The name of the ParamType (DeviceClass: serialPortCommander, Type: device, ID: {45dfc828-f238-4263-89a3-9b35cf5dea39}) + + + + + Data + The name of the ParamType (DeviceClass: serialPortCommander, ActionType: trigger, ID: {a27ecedc-424e-49ce-8956-9dbca2feac02}) + + + + + Data bits + The name of the ParamType (DeviceClass: serialPortCommander, Type: device, ID: {add4f7fb-1be9-4944-a420-3355b20174f9}) + + + + + Data received + The name of the EventType ({32087633-616c-45a7-85af-4f1695c22359}) of DeviceClass serialPortCommander + + + + + Flow control + The name of the ParamType (DeviceClass: serialPortCommander, Type: device, ID: {7e5d197f-0224-4c6f-8e86-0e7c867da5f1}) + + + + + Parity + The name of the ParamType (DeviceClass: serialPortCommander, Type: device, ID: {72de1b08-2a27-49c5-90e0-8788c3ea1da3}) + + + + + Received Data + The name of the ParamType (DeviceClass: serialPortCommander, EventType: triggered, ID: {b98fdacc-59d7-41c4-b790-1fdca50dfb22}) + + + + + Serial port + The name of the ParamType (DeviceClass: serialPortCommander, Type: device, ID: {ed49f7d8-ab18-4c37-9b80-1004b75dcb91}) + + + + + + Serial port commander + The name of the DeviceClass ({540566d8-a2a6-4ce2-9a1e-a66a989e6199}) +---------- +The name of the plugin SerialPortCommander ({fe93a12e-36f4-4015-8019-26b659817773}) + + + + + Stop bits + The name of the ParamType (DeviceClass: serialPortCommander, Type: device, ID: {4ea8bcdf-d4c5-45a4-a54f-f10ac3f08a78}) + + + + + Trigger + The name of the ActionType ({0b22c4d1-f5f6-4a93-aa93-660d27bf8f71}) of DeviceClass serialPortCommander + + + + + + connected + The name of the ParamType (DeviceClass: serialPortCommander, EventType: connected, ID: {e308259d-9180-4880-a0bf-1734b52de9ac}) +---------- +The name of the StateType ({e308259d-9180-4880-a0bf-1734b52de9ac}) of DeviceClass serialPortCommander + + + + + connected changed + The name of the EventType ({e308259d-9180-4880-a0bf-1734b52de9ac}) of DeviceClass serialPortCommander + + + + + nymea + The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) + + + +