-
Notifications
You must be signed in to change notification settings - Fork 44
Improve sensor detector usability #897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c54b661
46eba0b
196ae93
1efe3da
9c1bceb
5c0eeaa
8a2d9e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,8 +29,8 @@ DeviceManager::DeviceManager() | |
| void DeviceManager::append(const LinkConfiguration& linkConf, const QString& deviceName, const QString& detectorName) | ||
| { | ||
| for (int i {0}; i < _sensors[Connection].size(); i++) { | ||
| auto vectorLinkConf = _sensors[Connection][i].value<QSharedPointer<LinkConfiguration>>().get(); | ||
| if (*vectorLinkConf == linkConf) { | ||
| const auto vectorLinkConf = _sensors[Connection][i].value<QSharedPointer<LinkConfiguration>>(); | ||
| if (!vectorLinkConf.isNull() && *vectorLinkConf == linkConf) { | ||
| qCDebug(DEVICEMANAGER) << "Connection configuration already exist for:" << _sensors[Name][i] << linkConf | ||
| << linkConf.argsAsConst(); | ||
| _sensors[Available][i] = true; | ||
|
|
@@ -50,6 +50,7 @@ void DeviceManager::append(const LinkConfiguration& linkConf, const QString& dev | |
| _sensors[Connected].append(false); | ||
| _sensors[DetectorName].append(detectorName); | ||
| _sensors[Name].append(deviceName); | ||
| _sensors[UnavailableCounter].append(0); | ||
|
|
||
| const auto& indexRow = index(line); | ||
| endInsertRows(); | ||
|
|
@@ -151,19 +152,57 @@ void DeviceManager::updateAvailableConnections( | |
| const QVector<LinkConfiguration>& availableLinkConfigurations, const QString& detector) | ||
| { | ||
| qCDebug(DEVICEMANAGER) << "Available devices:" << availableLinkConfigurations; | ||
| // Make all connections unavailable by default | ||
|
|
||
| for (int i {0}; i < _sensors[Available].size(); i++) { | ||
| auto linkConf = _sensors[Connection][i].value<QSharedPointer<LinkConfiguration>>(); | ||
| const auto linkConf = _sensors[Connection][i].value<QSharedPointer<LinkConfiguration>>(); | ||
| if (linkConf->isSimulation() || _sensors[DetectorName][i] != detector) { | ||
| continue; | ||
| } | ||
|
|
||
| // Make all connections unavailable by default | ||
| _sensors[Available][i] = false; | ||
| const auto indexRow = index(i); | ||
| emit dataChanged(indexRow, indexRow, _roles); | ||
| } | ||
|
|
||
| // Check if the configuration already exists for a sensor | ||
| // Serial ports does not support multiple devices connected | ||
| // Some sensors, like Ping1D, can fail to answer a ABR procedure | ||
| for (const auto& link : availableLinkConfigurations) { | ||
| append(link, PingHelper::nameFromDeviceType(link.deviceType()), detector); | ||
| const bool sameSerialDevice = std::any_of( | ||
| _sensors[Connection].cbegin(), _sensors[Connection].cend(), [&link](const QVariant& variantLink) { | ||
tcanabrava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const auto sensorLink = variantLink.value<QSharedPointer<LinkConfiguration>>(); | ||
| qCDebug(DEVICEMANAGER) << "Device" << *sensorLink | ||
| << "already already provided by a different connection:" << link; | ||
| return link.serialPort() == sensorLink->serialPort() && link != *sensorLink; | ||
| }); | ||
|
|
||
| if (!sameSerialDevice) { | ||
| append(link, PingHelper::nameFromDeviceType(link.deviceType()), detector); | ||
| } | ||
| } | ||
|
|
||
| // We'll let the link to fail the communication attempt "a max number of fails" before making it unavailable | ||
| // This is necessary to avoid any problem related to automatic baud rates problem from the sensor side. | ||
| static const int maxNumberOfFails = 3; | ||
| for (int i {0}; i < _sensors[Available].size(); i++) { | ||
| const auto linkConf = _sensors[Connection][i].value<QSharedPointer<LinkConfiguration>>(); | ||
| if (linkConf->isSimulation()) { | ||
| continue; | ||
| } | ||
|
|
||
| const auto indexRow = index(i); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. explicit types when it's ipossible to guess the type by reading the code?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // The sensor was detected, we can remove unavailable counter | ||
| if (_sensors[Available][i].toBool()) { | ||
tcanabrava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _sensors[UnavailableCounter][i] = 0; | ||
tcanabrava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| emit dataChanged(indexRow, indexRow, _roles); | ||
| continue; | ||
| } | ||
| _sensors[Available][i] = _sensors[UnavailableCounter][i].toInt() < maxNumberOfFails; | ||
| _sensors[UnavailableCounter][i] = _sensors[UnavailableCounter][i].toInt() + 1; | ||
|
|
||
| emit dataChanged(indexRow, indexRow, _roles); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.