Serialport commander: incorporating changes from review
This commit is contained in:
parent
83c55edf6d
commit
252b63888d
@ -44,10 +44,6 @@ DevicePluginSerialPortCommander::DevicePluginSerialPortCommander()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginSerialPortCommander::init()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceManager::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(Device *device)
|
DeviceManager::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(Device *device)
|
||||||
{
|
{
|
||||||
if (device->deviceClassId() == serialPortCommanderDeviceClassId) {
|
if (device->deviceClassId() == serialPortCommanderDeviceClassId) {
|
||||||
@ -97,8 +93,8 @@ DeviceManager::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(De
|
|||||||
connect(serialPort, SIGNAL(stopBitsChanged(QSerialPort::StopBits)), this, SLOT(onStopBitsChanged(QSerialPort::StopBits)));
|
connect(serialPort, SIGNAL(stopBitsChanged(QSerialPort::StopBits)), this, SLOT(onStopBitsChanged(QSerialPort::StopBits)));
|
||||||
connect(serialPort, SIGNAL(flowControlChanged(QSerialPort::FlowControl)), this, SLOT(onFlowControlChanged(QSerialPort::FlowControl)));
|
connect(serialPort, SIGNAL(flowControlChanged(QSerialPort::FlowControl)), this, SLOT(onFlowControlChanged(QSerialPort::FlowControl)));
|
||||||
qCDebug(dcSerialPortCommander()) << "Setup successfully serial port" << interface;
|
qCDebug(dcSerialPortCommander()) << "Setup successfully serial port" << interface;
|
||||||
|
m_usedInterfaces.append(interface);
|
||||||
m_serialPorts.insert(device, serialPort);
|
m_serialPorts.insert(device, serialPort);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return DeviceManager::DeviceSetupStatusFailure;
|
return DeviceManager::DeviceSetupStatusFailure;
|
||||||
}
|
}
|
||||||
@ -124,16 +120,11 @@ DeviceManager::DeviceError DevicePluginSerialPortCommander::discoverDevices(cons
|
|||||||
QString description = port.manufacturer() + " " + port.description();
|
QString description = port.manufacturer() + " " + port.description();
|
||||||
DeviceDescriptor descriptor(deviceClassId, port.portName(), description);
|
DeviceDescriptor descriptor(deviceClassId, port.portName(), description);
|
||||||
ParamList parameters;
|
ParamList parameters;
|
||||||
|
parameters.append(Param(serialPortCommanderDeviceSerialPortParamTypeId, port.portName()));
|
||||||
if (deviceClassId == serialPortCommanderDeviceClassId) {
|
|
||||||
parameters.append(Param(serialPortCommanderDeviceSerialPortParamTypeId, port.portName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
descriptor.setParams(parameters);
|
descriptor.setParams(parameters);
|
||||||
deviceDescriptors.append(descriptor);
|
deviceDescriptors.append(descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit devicesDiscovered(deviceClassId, deviceDescriptors);
|
emit devicesDiscovered(deviceClassId, deviceDescriptors);
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
}
|
}
|
||||||
@ -158,15 +149,11 @@ DeviceManager::DeviceError DevicePluginSerialPortCommander::executeAction(Device
|
|||||||
|
|
||||||
void DevicePluginSerialPortCommander::deviceRemoved(Device *device)
|
void DevicePluginSerialPortCommander::deviceRemoved(Device *device)
|
||||||
{
|
{
|
||||||
QString interface;
|
|
||||||
QSerialPort *serialPort;
|
|
||||||
|
|
||||||
if (device->deviceClassId() == serialPortCommanderDeviceClassId) {
|
if (device->deviceClassId() == serialPortCommanderDeviceClassId) {
|
||||||
|
|
||||||
m_usedInterfaces.removeAll(device->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString());
|
m_usedInterfaces.removeAll(device->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString());
|
||||||
serialPort = m_serialPorts.value(device);
|
QSerialPort *serialPort = m_serialPorts.take(device);
|
||||||
serialPort->close();
|
serialPort->close();
|
||||||
m_serialPorts.remove(device);
|
|
||||||
serialPort->deleteLater();
|
serialPort->deleteLater();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,7 +175,7 @@ void DevicePluginSerialPortCommander::onReadyRead()
|
|||||||
|
|
||||||
void DevicePluginSerialPortCommander::onSerialError(QSerialPort::SerialPortError error)
|
void DevicePluginSerialPortCommander::onSerialError(QSerialPort::SerialPortError error)
|
||||||
{
|
{
|
||||||
Q_UNUSED(error)
|
qCWarning(dcSerialPortCommander) << "Serial Port error happened:" << error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginSerialPortCommander::onBaudRateChanged(qint32 baudRate, QSerialPort::Direction direction)
|
void DevicePluginSerialPortCommander::onBaudRateChanged(qint32 baudRate, QSerialPort::Direction direction)
|
||||||
|
|||||||
@ -41,9 +41,7 @@ public:
|
|||||||
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
||||||
void deviceRemoved(Device *device) override;
|
void deviceRemoved(Device *device) override;
|
||||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms);
|
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms);
|
||||||
|
|
||||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||||
void init() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<Device *, QSerialPort *> m_serialPorts;
|
QHash<Device *, QSerialPort *> m_serialPorts;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user