fixed device discovery

This commit is contained in:
Bernhard Trinnes 2018-06-13 23:07:37 +02:00 committed by Michael Zanetti
parent 4403be8d76
commit ac6318a10d

View File

@ -112,28 +112,10 @@ DeviceManager::DeviceError DevicePluginSerialPortCommander::discoverDevices(cons
QList<DeviceDescriptor> deviceDescriptors; QList<DeviceDescriptor> deviceDescriptors;
Q_FOREACH(QSerialPortInfo port, QSerialPortInfo::availablePorts()) { Q_FOREACH(QSerialPortInfo port, QSerialPortInfo::availablePorts()) {
qCDebug(dcSerialPortCommander()) << "Found Serial interface:" << port.systemLocation() << port.portName(); if (m_serialPortCommanders.contains(port.portName())){
QString description = port.manufacturer() + " | " + port.description(); SerialPortCommander *serialPortCommander = m_serialPortCommanders.value(port.portName());
DeviceDescriptor descriptor(deviceClassId, port.systemLocation(), description);
ParamList parameters;
if (deviceClassId == serialPortInputDeviceClassId) {
//TODO add all currenly used devices
parameters.append(Param(serialPortInputSerialPortParamTypeId, port.systemLocation()));
}
if (deviceClassId == serialPortOutputDeviceClassId) {
//TODO add currently only as input used devices
parameters.append(Param(serialPortOutputSerialPortParamTypeId, port.systemLocation()));
}
descriptor.setParams(parameters);
deviceDescriptors.append(descriptor);
}
Q_FOREACH(SerialPortCommander *serialPortCommander, m_serialPortCommanders.values()) {
QSerialPort *serialPort = serialPortCommander->serialPort(); QSerialPort *serialPort = serialPortCommander->serialPort();
QString description = "also used by another device"; QString description = "Note, this serial port is also used by another device";
DeviceDescriptor descriptor(deviceClassId, serialPort->portName(), description); DeviceDescriptor descriptor(deviceClassId, serialPort->portName(), description);
ParamList parameters; ParamList parameters;
@ -145,19 +127,33 @@ DeviceManager::DeviceError DevicePluginSerialPortCommander::discoverDevices(cons
if (serialPortCommander->hasOutputDevice()){ if (serialPortCommander->hasOutputDevice()){
continue; continue;
} }
}
parameters.append(Param(serialPortOutputSerialPortParamTypeId, serialPort->portName())); parameters.append(Param(serialPortOutputSerialPortParamTypeId, serialPort->portName()));
parameters.append(Param(serialPortOutputBaudRateParamTypeId, serialPort->baudRate())); parameters.append(Param(serialPortOutputBaudRateParamTypeId, serialPort->baudRate()));
parameters.append(Param(serialPortOutputDataBitsParamTypeId, serialPort->dataBits())); parameters.append(Param(serialPortOutputDataBitsParamTypeId, serialPort->dataBits()));
parameters.append(Param(serialPortOutputFlowControlParamTypeId, serialPort->flowControl())); parameters.append(Param(serialPortOutputFlowControlParamTypeId, serialPort->flowControl()));
parameters.append(Param(serialPortOutputStopBitsParamTypeId, serialPort->stopBits())); parameters.append(Param(serialPortOutputStopBitsParamTypeId, serialPort->stopBits()));
parameters.append(Param(serialPortOutputParityParamTypeId, serialPort->parity())); parameters.append(Param(serialPortOutputParityParamTypeId, serialPort->parity()));
descriptor.setParams(parameters);
deviceDescriptors.append(descriptor);
} else {
qCDebug(dcSerialPortCommander()) << "Found Serial interface:" << port.portName();
QString description = port.manufacturer() + " | " + port.description();
DeviceDescriptor descriptor(deviceClassId, port.portName(), description);
ParamList parameters;
if (deviceClassId == serialPortInputDeviceClassId) {
parameters.append(Param(serialPortInputSerialPortParamTypeId, port.portName()));
}
if (deviceClassId == serialPortOutputDeviceClassId) {
parameters.append(Param(serialPortOutputSerialPortParamTypeId, 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;
@ -192,16 +188,21 @@ void DevicePluginSerialPortCommander::deviceRemoved(Device *device)
interface = device->paramValue(serialPortInputSerialPortParamTypeId).toString(); interface = device->paramValue(serialPortInputSerialPortParamTypeId).toString();
serialPortCommander = m_serialPortCommanders.value(interface); serialPortCommander = m_serialPortCommanders.value(interface);
serialPortCommander->removeInputDevice(device); serialPortCommander->removeInputDevice(device);
if (serialPortCommander->isEmpty()) {
m_serialPortCommanders.remove(interface);
serialPortCommander->deleteLater();
}
} }
if (device->deviceClassId() == serialPortOutputDeviceClassId) { if (device->deviceClassId() == serialPortOutputDeviceClassId) {
interface = device->paramValue(serialPortOutputSerialPortParamTypeId).toString(); interface = device->paramValue(serialPortOutputSerialPortParamTypeId).toString();
serialPortCommander = m_serialPortCommanders.value(interface); serialPortCommander = m_serialPortCommanders.value(interface);
serialPortCommander->removeOutputDevice(); serialPortCommander->removeOutputDevice();
} if (serialPortCommander->isEmpty()) {
if (serialPortCommander->isEmpty())
m_serialPortCommanders.remove(interface); m_serialPortCommanders.remove(interface);
serialPortCommander->deleteLater();
}
}
} }