mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-16 04:20:36 +08:00
CRC64 removed, file messages refactored
This commit is contained in:
@@ -11,7 +11,6 @@ Path path
|
||||
|
||||
---
|
||||
|
||||
uint64 crc64 # Undefined for directories
|
||||
uint32 size # Undefined for directories
|
||||
uint40 size # Undefined for directories
|
||||
Error error
|
||||
EntryType entry_type
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# will be returned, and data array will be empty.
|
||||
#
|
||||
|
||||
uint32 offset
|
||||
uint40 offset
|
||||
Path path
|
||||
|
||||
---
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
# example by means of creating a staging area for uncompleted writes (like FTP servers do).
|
||||
#
|
||||
|
||||
uint32 offset
|
||||
uint40 offset
|
||||
Path path
|
||||
uint8[<=200] data
|
||||
uint8[<=192] data
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -30,11 +30,6 @@ public:
|
||||
typedef protocol::file::EntryType EntryType;
|
||||
typedef protocol::file::Error Error;
|
||||
|
||||
/**
|
||||
* Use this class to compute CRC64 for uavcan.protocol.file.GetInfo.
|
||||
*/
|
||||
typedef DataTypeSignatureCRC FileCRC;
|
||||
|
||||
/**
|
||||
* All read operations must return this number of bytes, unless end of file is reached.
|
||||
*/
|
||||
@@ -51,7 +46,7 @@ public:
|
||||
* Implementation of this method is required.
|
||||
* On success the method must return zero.
|
||||
*/
|
||||
virtual int16_t getInfo(const Path& path, uint64_t& out_crc64, uint32_t& out_size, EntryType& out_type) = 0;
|
||||
virtual int16_t getInfo(const Path& path, uint64_t& out_size, EntryType& out_type) = 0;
|
||||
|
||||
/**
|
||||
* Backend for uavcan.protocol.file.Read.
|
||||
@@ -60,7 +55,7 @@ public:
|
||||
* if the end of file is reached.
|
||||
* On success the method must return zero.
|
||||
*/
|
||||
virtual int16_t read(const Path& path, const uint32_t offset, uint8_t* out_buffer, uint16_t& inout_size) = 0;
|
||||
virtual int16_t read(const Path& path, const uint64_t offset, uint8_t* out_buffer, uint16_t& inout_size) = 0;
|
||||
|
||||
// Methods below are optional.
|
||||
|
||||
@@ -69,7 +64,7 @@ public:
|
||||
* Implementation of this method is NOT required; by default it returns uavcan.protocol.file.Error.NOT_IMPLEMENTED.
|
||||
* On success the method must return zero.
|
||||
*/
|
||||
virtual int16_t write(const Path& path, const uint32_t offset, const uint8_t* buffer, const uint16_t size)
|
||||
virtual int16_t write(const Path& path, const uint64_t offset, const uint8_t* buffer, const uint16_t size)
|
||||
{
|
||||
(void)path;
|
||||
(void)offset;
|
||||
@@ -129,7 +124,7 @@ class BasicFileServer
|
||||
|
||||
void handleGetInfo(const protocol::file::GetInfo::Request& req, protocol::file::GetInfo::Response& resp)
|
||||
{
|
||||
resp.error.value = backend_.getInfo(req.path.path, resp.crc64, resp.size, resp.entry_type);
|
||||
resp.error.value = backend_.getInfo(req.path.path, resp.size, resp.entry_type);
|
||||
}
|
||||
|
||||
void handleRead(const protocol::file::Read::Request& req, protocol::file::Read::Response& resp)
|
||||
|
||||
@@ -13,15 +13,10 @@ public:
|
||||
static const std::string file_name;
|
||||
static const std::string file_data;
|
||||
|
||||
virtual int16_t getInfo(const Path& path, uint64_t& out_crc64, uint32_t& out_size, EntryType& out_type)
|
||||
virtual int16_t getInfo(const Path& path, uint64_t& out_size, EntryType& out_type)
|
||||
{
|
||||
if (path == file_name)
|
||||
{
|
||||
{
|
||||
FileCRC crc;
|
||||
crc.add(reinterpret_cast<const uavcan::uint8_t*>(file_data.c_str()), unsigned(file_data.length()));
|
||||
out_crc64 = crc.get();
|
||||
}
|
||||
out_size = uint16_t(file_data.length());
|
||||
out_type.flags |= EntryType::FLAG_FILE;
|
||||
out_type.flags |= EntryType::FLAG_READABLE;
|
||||
@@ -33,7 +28,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual int16_t read(const Path& path, const uint32_t offset, uint8_t* out_buffer, uint16_t& inout_size)
|
||||
virtual int16_t read(const Path& path, const uint64_t offset, uint8_t* out_buffer, uint16_t& inout_size)
|
||||
{
|
||||
if (path == file_name)
|
||||
{
|
||||
@@ -90,7 +85,6 @@ TEST(BasicFileServer, Basic)
|
||||
ASSERT_TRUE(get_info.collector.result.get());
|
||||
ASSERT_TRUE(get_info.collector.result->isSuccessful());
|
||||
|
||||
ASSERT_EQ(0x62EC59E3F1A4F00A, get_info.collector.result->getResponse().crc64);
|
||||
ASSERT_EQ(0, get_info.collector.result->getResponse().error.value);
|
||||
ASSERT_EQ(9, get_info.collector.result->getResponse().size);
|
||||
ASSERT_EQ(EntryType::FLAG_FILE | EntryType::FLAG_READABLE,
|
||||
|
||||
Reference in New Issue
Block a user