Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
bc71d49d
Commit
bc71d49d
authored
May 12, 2015
by
Lorenz Meier
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1557 from DonLakeFlyer/FileManager
File Manager fixes and unit test
parents
886b40b5
f534aa7e
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
417 additions
and
481 deletions
+417
-481
QGCApplication.pro
QGCApplication.pro
+4
-3
MockLink.cc
src/comm/MockLink.cc
+29
-18
MockLink.h
src/comm/MockLink.h
+9
-1
MockLinkFileServer.cc
src/comm/MockLinkFileServer.cc
+88
-73
MockLinkFileServer.h
src/comm/MockLinkFileServer.h
+27
-26
FileManagerTest.cc
src/qgcunittest/FileManagerTest.cc
+201
-269
FileManagerTest.h
src/qgcunittest/FileManagerTest.h
+5
-12
MockMavlinkInterface.cc
src/qgcunittest/MockMavlinkInterface.cc
+0
-9
MockMavlinkInterface.h
src/qgcunittest/MockMavlinkInterface.h
+0
-44
FileManager.cc
src/uas/FileManager.cc
+51
-22
FileManager.h
src/uas/FileManager.h
+3
-4
No files found.
QGCApplication.pro
View file @
bc71d49d
...
...
@@ -236,6 +236,7 @@ HEADERS += \
src
/
comm
/
LinkManager
.
h
\
src
/
comm
/
MAVLinkProtocol
.
h
\
src
/
comm
/
MockLink
.
h
\
src
/
comm
/
MockLinkFileServer
.
h
\
src
/
comm
/
MockLinkMissionItemHandler
.
h
\
src
/
comm
/
ProtocolInterface
.
h
\
src
/
comm
/
QGCFlightGearLink
.
h
\
...
...
@@ -374,6 +375,7 @@ SOURCES += \
src
/
comm
/
LinkManager
.
cc
\
src
/
comm
/
MAVLinkProtocol
.
cc
\
src
/
comm
/
MockLink
.
cc
\
src
/
comm
/
MockLinkFileServer
.
cc
\
src
/
comm
/
MockLinkMissionItemHandler
.
cc
\
src
/
comm
/
QGCFlightGearLink
.
cc
\
src
/
comm
/
QGCJSBSimLink
.
cc
\
...
...
@@ -518,8 +520,6 @@ INCLUDEPATH += \
HEADERS
+=
\
src
/
qgcunittest
/
FlightGearTest
.
h
\
src
/
qgcunittest
/
MockMavlinkFileServer
.
h
\
src
/
qgcunittest
/
MockMavlinkInterface
.
h
\
src
/
qgcunittest
/
MultiSignalSpy
.
h
\
src
/
qgcunittest
/
TCPLinkTest
.
h
\
src
/
qgcunittest
/
TCPLoopBackServer
.
h
\
...
...
@@ -534,10 +534,10 @@ HEADERS += \
src
/
qgcunittest
/
PX4RCCalibrationTest
.
h
\
src
/
qgcunittest
/
UnitTest
.
h
\
src
/
VehicleSetup
/
SetupViewTest
.
h
\
src
/
qgcunittest
/
FileManagerTest
.
h
\
SOURCES
+=
\
src
/
qgcunittest
/
FlightGearTest
.
cc
\
src
/
qgcunittest
/
MockMavlinkFileServer
.
cc
\
src
/
qgcunittest
/
MultiSignalSpy
.
cc
\
src
/
qgcunittest
/
TCPLinkTest
.
cc
\
src
/
qgcunittest
/
TCPLoopBackServer
.
cc
\
...
...
@@ -552,6 +552,7 @@ SOURCES += \
src
/
qgcunittest
/
PX4RCCalibrationTest
.
cc
\
src
/
qgcunittest
/
UnitTest
.
cc
\
src
/
VehicleSetup
/
SetupViewTest
.
cc
\
src
/
qgcunittest
/
FileManagerTest
.
cc
\
}
#
DebugBuild
|
WindowsDebugAndRelease
}
#
AndroidBuild
...
...
src/comm/MockLink.cc
View file @
bc71d49d
...
...
@@ -75,7 +75,8 @@ MockLink::MockLink(MockConfiguration* config) :
_mavlinkStarted
(
false
),
_mavBaseMode
(
MAV_MODE_FLAG_MANUAL_INPUT_ENABLED
|
MAV_MODE_FLAG_CUSTOM_MODE_ENABLED
),
_mavState
(
MAV_STATE_STANDBY
),
_autopilotType
(
MAV_AUTOPILOT_PX4
)
_autopilotType
(
MAV_AUTOPILOT_PX4
),
_fileServer
(
NULL
)
{
_config
=
config
;
union
px4_custom_mode
px4_cm
;
...
...
@@ -84,6 +85,9 @@ MockLink::MockLink(MockConfiguration* config) :
px4_cm
.
main_mode
=
PX4_CUSTOM_MAIN_MODE_MANUAL
;
_mavCustomMode
=
px4_cm
.
data
;
_fileServer
=
new
MockLinkFileServer
(
_vehicleSystemId
,
_vehicleComponentId
,
this
);
Q_CHECK_PTR
(
_fileServer
);
_missionItemHandler
=
new
MockLinkMissionItemHandler
(
_vehicleSystemId
,
this
);
Q_CHECK_PTR
(
_missionItemHandler
);
...
...
@@ -218,7 +222,6 @@ void MockLink::_loadParams(void)
void
MockLink
::
_sendHeartBeat
(
void
)
{
mavlink_message_t
msg
;
uint8_t
buffer
[
MAVLINK_MAX_PACKET_LEN
];
mavlink_msg_heartbeat_pack
(
_vehicleSystemId
,
_vehicleComponentId
,
...
...
@@ -228,7 +231,14 @@ void MockLink::_sendHeartBeat(void)
_mavBaseMode
,
// MAV_MODE
_mavCustomMode
,
// custom mode
_mavState
);
// MAV_STATE
respondWithMavlinkMessage
(
msg
);
}
void
MockLink
::
respondWithMavlinkMessage
(
const
mavlink_message_t
&
msg
)
{
uint8_t
buffer
[
MAVLINK_MAX_PACKET_LEN
];
int
cBuffer
=
mavlink_msg_to_send_buffer
(
buffer
,
&
msg
);
QByteArray
bytes
((
char
*
)
buffer
,
cBuffer
);
emit
bytesReceived
(
this
,
bytes
);
...
...
@@ -332,6 +342,10 @@ void MockLink::_handleIncomingMavlinkBytes(const uint8_t* bytes, int cBytes)
_handleMissionCount(msg);
break;
#endif
case
MAVLINK_MSG_ID_FILE_TRANSFER_PROTOCOL
:
_handleFTP
(
msg
);
break
;
default:
qDebug
()
<<
"MockLink: Unhandled mavlink message, id:"
<<
msg
.
msgid
;
...
...
@@ -340,15 +354,6 @@ void MockLink::_handleIncomingMavlinkBytes(const uint8_t* bytes, int cBytes)
}
}
void
MockLink
::
_emitMavlinkMessage
(
const
mavlink_message_t
&
msg
)
{
uint8_t
outputBuffer
[
MAVLINK_MAX_PACKET_LEN
];
int
cBuffer
=
mavlink_msg_to_send_buffer
(
outputBuffer
,
&
msg
);
QByteArray
bytes
((
char
*
)
outputBuffer
,
cBuffer
);
emit
bytesReceived
(
this
,
bytes
);
}
void
MockLink
::
_handleHeartBeat
(
const
mavlink_message_t
&
msg
)
{
Q_UNUSED
(
msg
);
...
...
@@ -494,7 +499,7 @@ void MockLink::_handleParamRequestList(const mavlink_message_t& msg)
paramType
,
// MAV_PARAM_TYPE
cParameters
,
// Total number of parameters
paramIndex
++
);
// Index of this parameter
_emit
MavlinkMessage
(
responseMsg
);
respondWith
MavlinkMessage
(
responseMsg
);
// Only first parameter the first time through
break
;
...
...
@@ -533,7 +538,7 @@ void MockLink::_handleParamRequestList(const mavlink_message_t& msg)
paramType
,
// MAV_PARAM_TYPE
cParameters
,
// Total number of parameters
paramIndex
++
);
// Index of this parameter
_emit
MavlinkMessage
(
responseMsg
);
respondWith
MavlinkMessage
(
responseMsg
);
}
}
}
...
...
@@ -571,7 +576,7 @@ void MockLink::_handleParamSet(const mavlink_message_t& msg)
request
.
param_type
,
// Send same type back
_mapParamName2Value
[
componentId
].
count
(),
// Total number of parameters
_mapParamName2Value
[
componentId
].
keys
().
indexOf
(
paramId
));
// Index of this parameter
_emit
MavlinkMessage
(
responseMsg
);
respondWith
MavlinkMessage
(
responseMsg
);
}
void
MockLink
::
_handleParamRequestRead
(
const
mavlink_message_t
&
msg
)
...
...
@@ -613,7 +618,7 @@ void MockLink::_handleParamRequestRead(const mavlink_message_t& msg)
_mapParamName2MavParamType
[
paramId
],
// Parameter type
_mapParamName2Value
[
componentId
].
count
(),
// Total number of parameters
_mapParamName2Value
[
componentId
].
keys
().
indexOf
(
paramId
));
// Index of this parameter
_emit
MavlinkMessage
(
responseMsg
);
respondWith
MavlinkMessage
(
responseMsg
);
}
void
MockLink
::
_handleMissionRequestList
(
const
mavlink_message_t
&
msg
)
...
...
@@ -632,7 +637,7 @@ void MockLink::_handleMissionRequestList(const mavlink_message_t& msg)
msg
.
sysid
,
// Target is original sender
msg
.
compid
,
// Target is original sender
_missionItems
.
count
());
// Number of mission items
_emit
MavlinkMessage
(
responseMsg
);
respondWith
MavlinkMessage
(
responseMsg
);
}
void
MockLink
::
_handleMissionRequest
(
const
mavlink_message_t
&
msg
)
...
...
@@ -660,7 +665,7 @@ void MockLink::_handleMissionRequest(const mavlink_message_t& msg)
item
.
autocontinue
,
item
.
param1
,
item
.
param2
,
item
.
param3
,
item
.
param4
,
item
.
x
,
item
.
y
,
item
.
z
);
_emit
MavlinkMessage
(
responseMsg
);
respondWith
MavlinkMessage
(
responseMsg
);
}
void
MockLink
::
_handleMissionItem
(
const
mavlink_message_t
&
msg
)
...
...
@@ -711,5 +716,11 @@ void MockLink::emitRemoteControlChannelRawChanged(int channel, uint16_t raw)
chanRaw
[
16
],
// channel raw value
chanRaw
[
17
],
// channel raw value
0
);
// rss
_emitMavlinkMessage
(
responseMsg
);
respondWithMavlinkMessage
(
responseMsg
);
}
void
MockLink
::
_handleFTP
(
const
mavlink_message_t
&
msg
)
{
Q_ASSERT
(
_fileServer
);
_fileServer
->
handleFTPMessage
(
msg
);
}
src/comm/MockLink.h
View file @
bc71d49d
...
...
@@ -28,6 +28,7 @@
#include <QLoggingCategory>
#include "MockLinkMissionItemHandler.h"
#include "MockLinkFileServer.h"
#include "LinkManager.h"
#include "QGCMAVLink.h"
...
...
@@ -71,6 +72,11 @@ public:
MAV_AUTOPILOT
getAutopilotType
(
void
)
{
return
_autopilotType
;
}
void
setAutopilotType
(
MAV_AUTOPILOT
autopilot
)
{
_autopilotType
=
autopilot
;
}
void
emitRemoteControlChannelRawChanged
(
int
channel
,
uint16_t
raw
);
/// Sends the specified mavlink message to QGC
void
respondWithMavlinkMessage
(
const
mavlink_message_t
&
msg
);
MockLinkFileServer
*
getFileServer
(
void
)
{
return
_fileServer
;
}
// These are left unimplemented in order to cause linker errors which indicate incorrect usage of
// connect/disconnect on link directly. All connect/disconnect calls should be made through LinkManager.
...
...
@@ -109,7 +115,6 @@ private:
void
_handleIncomingNSHBytes
(
const
char
*
bytes
,
int
cBytes
);
void
_handleIncomingMavlinkBytes
(
const
uint8_t
*
bytes
,
int
cBytes
);
void
_loadParams
(
void
);
void
_emitMavlinkMessage
(
const
mavlink_message_t
&
msg
);
void
_handleHeartBeat
(
const
mavlink_message_t
&
msg
);
void
_handleSetMode
(
const
mavlink_message_t
&
msg
);
void
_handleParamRequestList
(
const
mavlink_message_t
&
msg
);
...
...
@@ -118,6 +123,7 @@ private:
void
_handleMissionRequestList
(
const
mavlink_message_t
&
msg
);
void
_handleMissionRequest
(
const
mavlink_message_t
&
msg
);
void
_handleMissionItem
(
const
mavlink_message_t
&
msg
);
void
_handleFTP
(
const
mavlink_message_t
&
msg
);
float
_floatUnionForParam
(
int
componentId
,
const
QString
&
paramName
);
void
_setParamFloatUnionIntoMap
(
int
componentId
,
const
QString
&
paramName
,
float
paramFloat
);
...
...
@@ -144,6 +150,8 @@ private:
MockConfiguration
*
_config
;
MAV_AUTOPILOT
_autopilotType
;
MockLinkFileServer
*
_fileServer
;
};
#endif
src/
qgcunittest/MockMavl
inkFileServer.cc
→
src/
comm/MockL
inkFileServer.cc
View file @
bc71d49d
This diff is collapsed.
Click to expand it.
src/
qgcunittest/MockMavl
inkFileServer.h
→
src/
comm/MockL
inkFileServer.h
View file @
bc71d49d
...
...
@@ -21,29 +21,25 @@
======================================================================*/
#ifndef MOCKMAVLINKFILESERVER_H
#define MOCKMAVLINKFILESERVER_H
#include "MockMavlinkInterface.h"
#include "FileManager.h"
/// @file
/// @brief Mock implementation of Mavlink FTP server. Used as mavlink plugin to MockUAS.
/// Only root directory access is supported.
///
/// @author Don Gagne <don@thegagnes.com>
#ifndef MockLinkFileServer_H
#define MockLinkFileServer_H
#include "FileManager.h"
#include <QStringList>
class
MockMavlinkFileServer
:
public
MockMavlinkInterface
class
MockLink
;
/// Mock implementation of Mavlink FTP server.
class
MockLinkFileServer
:
public
QObject
{
Q_OBJECT
public:
/// @brief Constructor for MockMavlinkFileServer
/// @param System ID for QGroundControl App
/// @pqram System ID for this Server
MockMavlinkFileServer
(
uint8_t
systemIdQGC
,
uint8_t
systemIdServer
);
MockLinkFileServer
(
uint8_t
systemIdServer
,
uint8_t
componentIdServer
,
MockLink
*
mockLink
);
/// @brief Sets the list of files returned by the List command. Prepend names with F or D
/// to indicate (F)ile or (D)irectory.
...
...
@@ -70,8 +66,8 @@ public:
/// @brief The number of ErrorModes in the rgFailureModes array.
static
const
size_t
cFailureModes
;
//
From MockMavlinkInterfac
e
v
irtual
void
sendMessage
(
mavlink_message_t
message
);
//
/ Called to handle an FTP messag
e
v
oid
handleFTPMessage
(
const
mavlink_message_t
&
message
);
/// @brief Used to represent a single test case for download testing.
struct
FileTestCase
{
...
...
@@ -88,18 +84,22 @@ public:
static
const
FileTestCase
rgFileTestCases
[
cFileTestCases
];
signals:
///
@brief
You can connect to this signal to be notified when the server receives a Terminate command.
/// You can connect to this signal to be notified when the server receives a Terminate command.
void
terminateCommandReceived
(
void
);
/// You can connect to this signal to be notified when the server receives a Reset command.
void
resetCommandReceived
(
void
);
private:
void
_sendAck
(
uint16_t
seqNumber
,
FileManager
::
Opcode
reqOpcode
);
void
_sendNak
(
FileManager
::
ErrorCode
error
,
uint16_t
seqNumber
,
FileManager
::
Opcode
reqOpcode
);
void
_emitResponse
(
FileManager
::
Request
*
request
,
uint16_t
seqNumber
);
void
_listCommand
(
FileManager
::
Request
*
request
,
uint16_t
seqNumber
);
void
_openCommand
(
FileManager
::
Request
*
request
,
uint16_t
seqNumber
);
void
_readCommand
(
FileManager
::
Request
*
request
,
uint16_t
seqNumber
);
void
_streamCommand
(
FileManager
::
Request
*
request
,
uint16_t
seqNumber
);
void
_terminateCommand
(
FileManager
::
Request
*
request
,
uint16_t
seqNumber
);
void
_sendAck
(
uint8_t
targetSystemId
,
uint8_t
targetComponentId
,
uint16_t
seqNumber
,
FileManager
::
Opcode
reqOpcode
);
void
_sendNak
(
uint8_t
targetSystemId
,
uint8_t
targetComponentId
,
FileManager
::
ErrorCode
error
,
uint16_t
seqNumber
,
FileManager
::
Opcode
reqOpcode
);
void
_sendResponse
(
uint8_t
targetSystemId
,
uint8_t
targetComponentId
,
FileManager
::
Request
*
request
,
uint16_t
seqNumber
);
void
_listCommand
(
uint8_t
senderSystemId
,
uint8_t
senderComponentId
,
FileManager
::
Request
*
request
,
uint16_t
seqNumber
);
void
_openCommand
(
uint8_t
senderSystemId
,
uint8_t
senderComponentId
,
FileManager
::
Request
*
request
,
uint16_t
seqNumber
);
void
_readCommand
(
uint8_t
senderSystemId
,
uint8_t
senderComponentId
,
FileManager
::
Request
*
request
,
uint16_t
seqNumber
);
void
_streamCommand
(
uint8_t
senderSystemId
,
uint8_t
senderComponentId
,
FileManager
::
Request
*
request
,
uint16_t
seqNumber
);
void
_terminateCommand
(
uint8_t
senderSystemId
,
uint8_t
senderComponentId
,
FileManager
::
Request
*
request
,
uint16_t
seqNumber
);
void
_resetCommand
(
uint8_t
senderSystemId
,
uint8_t
senderComponentId
,
uint16_t
seqNumber
);
uint16_t
_nextSeqNumber
(
uint16_t
seqNumber
);
QStringList
_fileList
;
///< List of files returned by List command
...
...
@@ -108,7 +108,8 @@ private:
uint8_t
_readFileLength
;
///< Length of active file being read
ErrorMode_t
_errMode
;
///< Currently set error mode, as specified by setErrorMode
const
uint8_t
_systemIdServer
;
///< System ID for server
const
uint8_t
_systemIdQGC
;
///< QGC System ID
const
uint8_t
_componentIdServer
;
///< Component ID for server
MockLink
*
_mockLink
;
///< MockLink to communicate through
};
#endif
src/qgcunittest/FileManagerTest.cc
View file @
bc71d49d
This diff is collapsed.
Click to expand it.
src/qgcunittest/FileManagerTest.h
View file @
bc71d49d
...
...
@@ -28,9 +28,8 @@
#include <QtTest/QtTest>
#include "UnitTest.h"
#include "MockUAS.h"
#include "MockMavlinkFileServer.h"
#include "FileManager.h"
#include "MockLink.h"
#include "MultiSignalSpy.h"
/// @file
...
...
@@ -47,18 +46,13 @@ public:
private
slots
:
// Test case initialization
void
initTestCase
(
void
);
void
cleanupTestCase
(
void
);
void
init
(
void
);
void
cleanup
(
void
);
// Test cases
void
_ackTest
(
void
);
void
_noAckTest
(
void
);
void
_resetTest
(
void
);
void
_listTest
(
void
);
void
_readDownloadTest
(
void
);
void
_streamDownloadTest
(
void
);
// Connected to FileManager listEntry signal
void
listEntry
(
const
QString
&
entry
);
...
...
@@ -76,16 +70,15 @@ private:
enum
{
listEntrySignalMask
=
1
<<
listEntrySignalIndex
,
commandCompleteSignalMask
=
1
<<
commandCompleteSignalIndex
,
commandErrorSignalMask
=
1
<<
errorMessage
SignalIndex
,
commandErrorSignalMask
=
1
<<
commandError
SignalIndex
,
};
static
const
uint8_t
_systemIdQGC
=
255
;
static
const
uint8_t
_systemIdServer
=
128
;
MockUAS
*
_mockUAS
;
MockMavlinkFileServer
_mockFileServer
;
FileManager
*
_fileManager
;
MockLink
*
_mockLink
;
MockLinkFileServer
*
_fileServer
;
FileManager
*
_fileManager
;
MultiSignalSpy
*
_multiSpy
;
static
const
size_t
_cSignals
=
maxSignalIndex
;
...
...
src/qgcunittest/MockMavlinkInterface.cc
deleted
100644 → 0
View file @
886b40b5
//
// MockMavlinkInterface.cc
// QGroundControl
//
// Created by Donald Gagne on 6/19/14.
// Copyright (c) 2014 Donald Gagne. All rights reserved.
//
#include "MockMavlinkInterface.h"
src/qgcunittest/MockMavlinkInterface.h
deleted
100644 → 0
View file @
886b40b5
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
#include <QObject>
#include "QGCMAVLink.h"
#include "LinkInterface.h"
#ifndef MOCKMAVLINKINTERFACE_H
#define MOCKMAVLINKINTERFACE_H
class
MockMavlinkInterface
:
public
QObject
{
Q_OBJECT
public:
virtual
void
sendMessage
(
mavlink_message_t
message
)
=
0
;
signals:
// link argument will always be NULL
void
messageReceived
(
LinkInterface
*
link
,
mavlink_message_t
message
);
};
#endif
src/uas/FileManager.cc
View file @
bc71d49d
...
...
@@ -32,13 +32,13 @@
QGC_LOGGING_CATEGORY
(
FileManagerLog
,
"FileManagerLog"
)
FileManager
::
FileManager
(
QObject
*
parent
,
UASInterface
*
uas
,
uint8_t
unitTestSystemIdQGC
)
:
FileManager
::
FileManager
(
QObject
*
parent
,
UASInterface
*
uas
)
:
QObject
(
parent
),
_currentOperation
(
kCOIdle
),
_mav
(
uas
),
_lastOutgoingSeqNumber
(
0
),
_activeSession
(
0
),
_systemIdQGC
(
unitTestSystemIdQGC
)
_systemIdQGC
(
0
)
{
connect
(
&
_ackTimer
,
&
QTimer
::
timeout
,
this
,
&
FileManager
::
_ackTimeout
);
...
...
@@ -104,8 +104,8 @@ void FileManager::_closeDownloadSession(bool success)
emit
commandComplete
();
}
// If !success error is emitted elsewhere
_readFileAccumulator
.
clear
();
// Close the open session
_sendResetCommand
();
}
...
...
@@ -153,24 +153,19 @@ void FileManager::_downloadAckResponse(Request* readAck, bool readFile)
emit
commandProgress
(
100
*
((
float
)
_readFileAccumulator
.
length
()
/
(
float
)
_downloadFileSize
));
}
if
(
readAck
->
hdr
.
size
==
sizeof
(
readAck
->
data
))
{
if
(
readFile
||
readAck
->
hdr
.
burstComplete
)
{
// Possibly still more data to read, send next read request
if
(
readFile
||
readAck
->
hdr
.
burstComplete
)
{
// Possibly still more data to read, send next read request
Request
request
;
request
.
hdr
.
session
=
_activeSession
;
request
.
hdr
.
opcode
=
readFile
?
kCmdReadFile
:
kCmdBurstReadFile
;
request
.
hdr
.
offset
=
_downloadOffset
;
request
.
hdr
.
size
=
0
;
Request
request
;
request
.
hdr
.
session
=
_activeSession
;
request
.
hdr
.
opcode
=
readFile
?
kCmdReadFile
:
kCmdBurstReadFile
;
request
.
hdr
.
offset
=
_downloadOffset
;
request
.
hdr
.
size
=
0
;
_sendRequest
(
&
request
);
}
else
{
// Streaming, so next ack should come automatically
_setupAckTimeout
();
}
}
else
if
(
readFile
)
{
// We only receieved a partial buffer back. These means we are at EOF
_closeDownloadSession
(
true
/* success */
);
_sendRequest
(
&
request
);
}
else
if
(
!
readFile
)
{
// Streaming, so next ack should come automatically
_setupAckTimeout
();
}
}
...
...
@@ -340,7 +335,30 @@ void FileManager::receiveMessage(LinkInterface* link, mavlink_message_t message)
// Make sure we have a good sequence number
uint16_t
expectedSeqNumber
=
_lastOutgoingSeqNumber
+
1
;
if
(
incomingSeqNumber
!=
expectedSeqNumber
)
{
_currentOperation
=
kCOIdle
;
switch
(
_currentOperation
)
{
case
kCOBurst
:
case
kCORead
:
_closeDownloadSession
(
false
/* failure */
);
break
;
case
kCOWrite
:
_closeUploadSession
(
false
/* failure */
);
break
;
case
kCOOpenRead
:
case
kCOOpenBurst
:
case
kCOCreate
:
// We could have an open session hanging around
_currentOperation
=
kCOIdle
;
_sendResetCommand
();
break
;
default:
// Don't need to do anything special
_currentOperation
=
kCOIdle
;
break
;
}
_emitErrorMessage
(
tr
(
"Bad sequence number on received message: expected(%1) received(%2)"
).
arg
(
expectedSeqNumber
).
arg
(
incomingSeqNumber
));
return
;
}
...
...
@@ -457,12 +475,22 @@ void FileManager::_sendListCommand(void)
void
FileManager
::
downloadPath
(
const
QString
&
from
,
const
QDir
&
downloadDir
)
{
if
(
_currentOperation
!=
kCOIdle
)
{
_emitErrorMessage
(
tr
(
"Command not sent. Waiting for previous command to complete."
));
return
;
}
qCDebug
(
FileManagerLog
)
<<
"downloadPath from:"
<<
from
<<
"to:"
<<
downloadDir
;
_downloadWorker
(
from
,
downloadDir
,
true
/* read file */
);
}
void
FileManager
::
streamPath
(
const
QString
&
from
,
const
QDir
&
downloadDir
)
{
if
(
_currentOperation
!=
kCOIdle
)
{
_emitErrorMessage
(
tr
(
"Command not sent. Waiting for previous command to complete."
));
return
;
}
qCDebug
(
FileManagerLog
)
<<
"streamPath from:"
<<
from
<<
"to:"
<<
downloadDir
;
_downloadWorker
(
from
,
downloadDir
,
false
/* stream file */
);
}
...
...
@@ -677,7 +705,6 @@ void FileManager::_emitListEntry(const QString& entry)
/// @brief Sends the specified Request out to the UAS.
void
FileManager
::
_sendRequest
(
Request
*
request
)
{
qCDebug
(
FileManagerLog
)
<<
"_sendRequest opcode:"
<<
request
->
hdr
.
opcode
;
mavlink_message_t
message
;
...
...
@@ -687,6 +714,8 @@ void FileManager::_sendRequest(Request* request)
request
->
hdr
.
seqNumber
=
_lastOutgoingSeqNumber
;
qCDebug
(
FileManagerLog
)
<<
"_sendRequest opcode:"
<<
request
->
hdr
.
opcode
<<
"seqNumber:"
<<
request
->
hdr
.
seqNumber
;
if
(
_systemIdQGC
==
0
)
{
_systemIdQGC
=
MAVLinkProtocol
::
instance
()
->
getSystemId
();
}
...
...
src/uas/FileManager.h
View file @
bc71d49d
...
...
@@ -37,12 +37,11 @@ class FileManager : public QObject
Q_OBJECT
public:
FileManager
(
QObject
*
parent
,
UASInterface
*
uas
,
uint8_t
unitTestSystemIdQGC
=
0
);
FileManager
(
QObject
*
parent
,
UASInterface
*
uas
);
/// These methods are only used for testing purposes.
bool
_sendCmdTestAck
(
void
)
{
return
_sendOpcodeOnlyCmd
(
kCmdNone
,
kCOAck
);
};
bool
_sendCmdTestNoAck
(
void
)
{
return
_sendOpcodeOnlyCmd
(
kCmdTestNoAck
,
kCOAck
);
};
bool
_sendCmdReset
(
void
)
{
return
_sendOpcodeOnlyCmd
(
kCmdResetSessions
,
kCOAck
);
};
/// Timeout in msecs to wait for an Ack time come back. This is public so we can write unit tests which wait long enough
/// for the FileManager to timeout.
...
...
@@ -226,9 +225,9 @@ private:
uint8_t
_systemIdQGC
;
///< System ID for QGC
uint8_t
_systemIdServer
;
///< System ID for server
// We give Mock
Mavl
inkFileServer friend access so that it can use the data structures and opcodes
// We give Mock
L
inkFileServer friend access so that it can use the data structures and opcodes
// to build a mock mavlink file server for testing.
friend
class
Mock
Mavl
inkFileServer
;
friend
class
Mock
L
inkFileServer
;
};
#endif // FileManager_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment