Update serialportcommander plugin
This commit is contained in:
parent
6ce95f7bda
commit
c20e7661e0
@ -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
|
// Create the list of available serial interfaces
|
||||||
QList<DeviceDescriptor> deviceDescriptors;
|
|
||||||
|
|
||||||
foreach(QSerialPortInfo port, QSerialPortInfo::availablePorts()) {
|
foreach(QSerialPortInfo port, QSerialPortInfo::availablePorts()) {
|
||||||
|
|
||||||
qCDebug(dcSerialPortCommander()) << "Found serial port:" << port.portName();
|
qCDebug(dcSerialPortCommander()) << "Found serial port:" << port.portName();
|
||||||
QString description = port.manufacturer() + " " + port.description();
|
QString description = port.manufacturer() + " " + port.description();
|
||||||
DeviceDescriptor deviceDescriptor(deviceClassId, port.portName(), description);
|
DeviceDescriptor deviceDescriptor(info->deviceClassId(), port.portName(), description);
|
||||||
ParamList parameters;
|
ParamList parameters;
|
||||||
foreach (Device *existingDevice, myDevices()) {
|
foreach (Device *existingDevice, myDevices()) {
|
||||||
if (existingDevice->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString() == port.portName()) {
|
if (existingDevice->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString() == port.portName()) {
|
||||||
@ -48,15 +46,17 @@ Device::DeviceError DevicePluginSerialPortCommander::discoverDevices(const Devic
|
|||||||
}
|
}
|
||||||
parameters.append(Param(serialPortCommanderDeviceSerialPortParamTypeId, port.portName()));
|
parameters.append(Param(serialPortCommanderDeviceSerialPortParamTypeId, port.portName()));
|
||||||
deviceDescriptor.setParams(parameters);
|
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) {
|
if(!m_reconnectTimer) {
|
||||||
m_reconnectTimer = new QTimer(this);
|
m_reconnectTimer = new QTimer(this);
|
||||||
m_reconnectTimer->setSingleShot(true);
|
m_reconnectTimer->setSingleShot(true);
|
||||||
@ -68,8 +68,6 @@ Device::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(Device *d
|
|||||||
if (device->deviceClassId() == serialPortCommanderDeviceClassId) {
|
if (device->deviceClassId() == serialPortCommanderDeviceClassId) {
|
||||||
QString interface = device->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString();
|
QString interface = device->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString();
|
||||||
QSerialPort *serialPort = new QSerialPort(interface, this);
|
QSerialPort *serialPort = new QSerialPort(interface, this);
|
||||||
if(!serialPort)
|
|
||||||
return Device::DeviceSetupStatusFailure;
|
|
||||||
|
|
||||||
serialPort->setBaudRate(device->paramValue(serialPortCommanderDeviceBaudRateParamTypeId).toInt());
|
serialPort->setBaudRate(device->paramValue(serialPortCommanderDeviceBaudRateParamTypeId).toInt());
|
||||||
serialPort->setDataBits(QSerialPort::DataBits(device->paramValue(serialPortCommanderDeviceDataBitsParamTypeId).toInt()));
|
serialPort->setDataBits(QSerialPort::DataBits(device->paramValue(serialPortCommanderDeviceDataBitsParamTypeId).toInt()));
|
||||||
@ -99,7 +97,8 @@ Device::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(Device *d
|
|||||||
if (!serialPort->open(QIODevice::ReadWrite)) {
|
if (!serialPort->open(QIODevice::ReadWrite)) {
|
||||||
qCWarning(dcSerialPortCommander()) << "Could not open serial port" << interface << serialPort->errorString();
|
qCWarning(dcSerialPortCommander()) << "Could not open serial port" << interface << serialPort->errorString();
|
||||||
serialPort->deleteLater();
|
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)));
|
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);
|
m_serialPorts.insert(device, serialPort);
|
||||||
device->setStateValue(serialPortCommanderConnectedStateTypeId, true);
|
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);
|
if (action.actionTypeId() == serialPortCommanderTriggerActionTypeId) {
|
||||||
qint64 size = serialPort->write(action.param(serialPortCommanderTriggerActionOutputDataParamTypeId).value().toByteArray());
|
|
||||||
if(size != action.param(serialPortCommanderTriggerActionOutputDataParamTypeId).value().toByteArray().length()) {
|
QSerialPort *serialPort = m_serialPorts.value(device);
|
||||||
return Device::DeviceErrorHardwareFailure;
|
qint64 size = serialPort->write(action.param(serialPortCommanderTriggerActionOutputDataParamTypeId).value().toByteArray());
|
||||||
}
|
if(size != action.param(serialPortCommanderTriggerActionOutputDataParamTypeId).value().toByteArray().length()) {
|
||||||
return Device::DeviceErrorNoError;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -39,10 +39,10 @@ class DevicePluginSerialPortCommander : public DevicePlugin
|
|||||||
public:
|
public:
|
||||||
explicit DevicePluginSerialPortCommander();
|
explicit DevicePluginSerialPortCommander();
|
||||||
|
|
||||||
Device::DeviceSetupStatus setupDevice(Device *device) override;
|
void setupDevice(DeviceSetupInfo *info) override;
|
||||||
void deviceRemoved(Device *device) override;
|
void deviceRemoved(Device *device) override;
|
||||||
Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
void discoverDevices(DeviceDiscoveryInfo *info) override;
|
||||||
Device::DeviceError executeAction(Device *device, const Action &action) override;
|
void executeAction(DeviceActionInfo *info) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTimer *m_reconnectTimer = nullptr;
|
QTimer *m_reconnectTimer = nullptr;
|
||||||
|
|||||||
@ -0,0 +1,110 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!DOCTYPE TS>
|
||||||
|
<TS version="2.1">
|
||||||
|
<context>
|
||||||
|
<name>DevicePluginSerialPortCommander</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../devicepluginserialportcommander.cpp" line="100"/>
|
||||||
|
<source>Could not open serial port.</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../devicepluginserialportcommander.cpp" line="128"/>
|
||||||
|
<source>Error writing to serial port.</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>SerialPortCommander</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="36"/>
|
||||||
|
<source>Baud rate</source>
|
||||||
|
<extracomment>The name of the ParamType (DeviceClass: serialPortCommander, Type: device, ID: {45dfc828-f238-4263-89a3-9b35cf5dea39})</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="39"/>
|
||||||
|
<source>Data</source>
|
||||||
|
<extracomment>The name of the ParamType (DeviceClass: serialPortCommander, ActionType: trigger, ID: {a27ecedc-424e-49ce-8956-9dbca2feac02})</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="42"/>
|
||||||
|
<source>Data bits</source>
|
||||||
|
<extracomment>The name of the ParamType (DeviceClass: serialPortCommander, Type: device, ID: {add4f7fb-1be9-4944-a420-3355b20174f9})</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="45"/>
|
||||||
|
<source>Data received</source>
|
||||||
|
<extracomment>The name of the EventType ({32087633-616c-45a7-85af-4f1695c22359}) of DeviceClass serialPortCommander</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="48"/>
|
||||||
|
<source>Flow control</source>
|
||||||
|
<extracomment>The name of the ParamType (DeviceClass: serialPortCommander, Type: device, ID: {7e5d197f-0224-4c6f-8e86-0e7c867da5f1})</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="51"/>
|
||||||
|
<source>Parity</source>
|
||||||
|
<extracomment>The name of the ParamType (DeviceClass: serialPortCommander, Type: device, ID: {72de1b08-2a27-49c5-90e0-8788c3ea1da3})</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="54"/>
|
||||||
|
<source>Received Data</source>
|
||||||
|
<extracomment>The name of the ParamType (DeviceClass: serialPortCommander, EventType: triggered, ID: {b98fdacc-59d7-41c4-b790-1fdca50dfb22})</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="57"/>
|
||||||
|
<source>Serial port</source>
|
||||||
|
<extracomment>The name of the ParamType (DeviceClass: serialPortCommander, Type: device, ID: {ed49f7d8-ab18-4c37-9b80-1004b75dcb91})</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="60"/>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="63"/>
|
||||||
|
<source>Serial port commander</source>
|
||||||
|
<extracomment>The name of the DeviceClass ({540566d8-a2a6-4ce2-9a1e-a66a989e6199})
|
||||||
|
----------
|
||||||
|
The name of the plugin SerialPortCommander ({fe93a12e-36f4-4015-8019-26b659817773})</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="66"/>
|
||||||
|
<source>Stop bits</source>
|
||||||
|
<extracomment>The name of the ParamType (DeviceClass: serialPortCommander, Type: device, ID: {4ea8bcdf-d4c5-45a4-a54f-f10ac3f08a78})</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="69"/>
|
||||||
|
<source>Trigger</source>
|
||||||
|
<extracomment>The name of the ActionType ({0b22c4d1-f5f6-4a93-aa93-660d27bf8f71}) of DeviceClass serialPortCommander</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="72"/>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="75"/>
|
||||||
|
<source>connected</source>
|
||||||
|
<extracomment>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</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="78"/>
|
||||||
|
<source>connected changed</source>
|
||||||
|
<extracomment>The name of the EventType ({e308259d-9180-4880-a0bf-1734b52de9ac}) of DeviceClass serialPortCommander</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/serialportcommander/plugininfo.h" line="81"/>
|
||||||
|
<source>nymea</source>
|
||||||
|
<extracomment>The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6})</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
</TS>
|
||||||
Loading…
x
Reference in New Issue
Block a user