Skip to content
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

QGCCameraControl: allow to read camera information xml via ftp #10094

Merged
merged 3 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Camera/QGCCameraControl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "VideoManager.h"
#include "QGCMapEngine.h"
#include "QGCCameraManager.h"
#include "FTPManager.h"

#include <QDir>
#include <QStandardPaths>
Expand Down Expand Up @@ -1950,6 +1951,21 @@ QGCCameraControl::_handleDefinitionFile(const QString &url)
{
//-- First check and see if we have it cached
QFile xmlFile(_cacheFile);

QString ftpPrefix(QStringLiteral("%1://").arg(FTPManager::mavlinkFTPScheme));
if (url.startsWith(ftpPrefix, Qt::CaseInsensitive)) {
int ver = static_cast<int>(_info.cam_definition_version);
QString fileName = QString::asprintf("%s_%s_%03d.xml",
mrpollo marked this conversation as resolved.
Show resolved Hide resolved
_vendor.toStdString().c_str(),
_modelName.toStdString().c_str(),
ver);
connect(_vehicle->ftpManager(), &FTPManager::downloadComplete, this, &QGCCameraControl::_ftpDownloadComplete);
_vehicle->ftpManager()->download(url,
qgcApp()->toolbox()->settingsManager()->appSettings()->parameterSavePath().toStdString().c_str(),
fileName);
return;
}

if (!xmlFile.exists()) {
qCDebug(CameraControlLog) << "No camera definition file cached";
_httpRequest(url);
Expand Down Expand Up @@ -2020,6 +2036,26 @@ QGCCameraControl::_downloadFinished()
//reply->deleteLater();
}

void QGCCameraControl::_ftpDownloadComplete(const QString& fileName, const QString& errorMsg)
{
qCDebug(CameraControlLog) << "QGCCameraControl::_ftpDownloadComplete fileName:errorMsg" << fileName << errorMsg;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to set class and function name, that can be configured via environment variable:
https://doc.qt.io/qt-5/debug.html


disconnect(_vehicle->ftpManager(), &FTPManager::downloadComplete, this, &QGCCameraControl::_ftpDownloadComplete);
QFile xmlFile(fileName);

if (!xmlFile.exists()) {
qCDebug(CameraControlLog) << "No camera definition file present after ftp download completed";
return;
}
if (!xmlFile.open(QIODevice::ReadOnly)) {
qWarning() << "Could not read downloaded camera definition file: " << fileName;
return;
}

QByteArray bytes = xmlFile.readAll();
emit dataReady(bytes);
}

//-----------------------------------------------------------------------------
void
QGCCameraControl::_dataReady(QByteArray data)
Expand Down
1 change: 1 addition & 0 deletions src/Camera/QGCCameraControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ protected slots:
void _updateRanges (Fact* pFact);
void _httpRequest (const QString& url);
void _handleDefinitionFile (const QString& url);
void _ftpDownloadComplete (const QString& fileName, const QString& errorMsg);

QStringList _loadExclusions (QDomNode option);
QStringList _loadUpdates (QDomNode option);
Expand Down
1 change: 1 addition & 0 deletions src/Camera/QGCCameraManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ QGCCameraManager::_handleHeartbeat(const mavlink_message_t &message)
mavlink_heartbeat_t heartbeat;
mavlink_msg_heartbeat_decode(&message, &heartbeat);
//-- First time hearing from this one?
qCDebug(CameraManagerLog) << "Another Hearbeat from " << message.compid;
QString sCompID = QString::number(message.compid);
if(!_cameraInfoRequest.contains(sCompID)) {
qCDebug(CameraManagerLog) << "Hearbeat from " << message.compid;
Expand Down
10 changes: 8 additions & 2 deletions src/Vehicle/FTPManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ FTPManager::FTPManager(Vehicle* vehicle)
Q_ASSERT(sizeof(MavlinkFTP::RequestHeader) == 12);
}

bool FTPManager::download(const QString& fromURI, const QString& toDir)
bool FTPManager::download(const QString& fromURI, const QString& toDir, const QString& fileName)
{
qCDebug(FTPManagerLog) << "download fromURI:" << fromURI << "to:" << toDir;

Expand Down Expand Up @@ -72,7 +72,11 @@ bool FTPManager::download(const QString& fromURI, const QString& toDir)
}
lastDirSlashIndex++; // move past slash

_downloadState.fileName = _downloadState.fullPathOnVehicle.right(_downloadState.fullPathOnVehicle.size() - lastDirSlashIndex);
if (fileName.size() == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileName.isEmpty()

_downloadState.fileName = _downloadState.fullPathOnVehicle.right(_downloadState.fullPathOnVehicle.size() - lastDirSlashIndex);
} else {
_downloadState.fileName = fileName;
}

qCDebug(FTPManagerLog) << "_downloadState.fullPathOnVehicle:_downloadState.fileName" << _downloadState.fullPathOnVehicle << _downloadState.fileName;

Expand Down Expand Up @@ -641,6 +645,8 @@ bool FTPManager::_parseURI(const QString& uri, QString& parsedURI, uint8_t& comp
if (!ok) {
qCWarning(FTPManagerLog) << "Incorrect format for component id" << uri;
return false;
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont need else after return.

qCDebug(FTPManagerLog) << "Found compId:" << (int)compId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to cast it to int.

}
parsedURI.replace(QRegularExpression("\\[\\;comp\\=\\d+\\]"), "");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Vehicle/FTPManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FTPManager : public QObject
/// @param toDir Local directory to download file to
/// @return true: download has started, false: error, no download
/// Signals downloadComplete, commandError, commandProgress
bool download(const QString& fromURI, const QString& toDir);
bool download(const QString& fromURI, const QString& toDir, const QString& fileName="");

/// Cancel the current operation
/// This will emit downloadComplete() when done, and if there's currently a download in progress
Expand Down