mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-14 23:23:33 +08:00
TransferReceiver made 32 bit less in size
This commit is contained in:
@@ -112,16 +112,16 @@ class DynamicTransferBuffer : public TransferBufferManagerEntry, public LinkedLi
|
||||
unsigned int& total_offset, unsigned int& left_to_write);
|
||||
};
|
||||
|
||||
unsigned int max_write_pos_;
|
||||
IAllocator* allocator_;
|
||||
LinkedListRoot<Block> blocks_; // Blocks are ordered from lower to higher buffer offset
|
||||
unsigned int max_write_pos_;
|
||||
|
||||
void resetImpl();
|
||||
|
||||
public:
|
||||
DynamicTransferBuffer(IAllocator* allocator)
|
||||
: max_write_pos_(0)
|
||||
, allocator_(allocator)
|
||||
: allocator_(allocator)
|
||||
, max_write_pos_(0)
|
||||
{
|
||||
StaticAssert<(Block::SIZE > 8)>::check();
|
||||
IsDynamicallyAllocatable<Block>::check();
|
||||
|
||||
@@ -4,20 +4,22 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
#include <uavcan/internal/transport/transfer.hpp>
|
||||
#include <uavcan/internal/transport/transfer_buffer.hpp>
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
#pragma pack(push, 1)
|
||||
class TransferReceiver
|
||||
{
|
||||
public:
|
||||
enum ResultCode { RESULT_NOT_COMPLETE, RESULT_COMPLETE, RESULT_SINGLE_FRAME };
|
||||
|
||||
static const uint64_t DEFAULT_TRANSFER_INTERVAL = 500 * 1000;
|
||||
static const uint64_t MIN_TRANSFER_INTERVAL = 1 * 1000;
|
||||
static const uint64_t MAX_TRANSFER_INTERVAL = 10 * 1000 * 1000;
|
||||
static const uint32_t DEFAULT_TRANSFER_INTERVAL = 500 * 1000UL;
|
||||
static const uint32_t MIN_TRANSFER_INTERVAL = 1 * 1000UL;
|
||||
static const uint32_t MAX_TRANSFER_INTERVAL = 10 * 1000 * 1000UL;
|
||||
|
||||
private:
|
||||
enum TidRelation { TID_SAME, TID_REPEAT, TID_FUTURE };
|
||||
@@ -26,7 +28,7 @@ private:
|
||||
uint64_t prev_transfer_ts_monotonic_;
|
||||
uint64_t this_transfer_ts_monotonic_;
|
||||
uint64_t first_frame_ts_utc_;
|
||||
uint64_t transfer_interval_; // TODO: make 32 bit
|
||||
uint32_t transfer_interval_;
|
||||
ITransferBufferManager* bufmgr_;
|
||||
TransferBufferManagerKey bufmgr_key_;
|
||||
TransferID tid_;
|
||||
@@ -96,7 +98,8 @@ public:
|
||||
uint64_t getLastTransferTimestampMonotonic() const { return prev_transfer_ts_monotonic_; }
|
||||
uint64_t getLastTransferTimestampUtc() const { return first_frame_ts_utc_; }
|
||||
|
||||
uint64_t getInterval() const { return transfer_interval_; }
|
||||
uint32_t getInterval() const { return transfer_interval_; }
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
const uint64_t TransferReceiver::DEFAULT_TRANSFER_INTERVAL;
|
||||
const uint64_t TransferReceiver::MIN_TRANSFER_INTERVAL;
|
||||
const uint64_t TransferReceiver::MAX_TRANSFER_INTERVAL;
|
||||
const uint32_t TransferReceiver::DEFAULT_TRANSFER_INTERVAL;
|
||||
const uint32_t TransferReceiver::MIN_TRANSFER_INTERVAL;
|
||||
const uint32_t TransferReceiver::MAX_TRANSFER_INTERVAL;
|
||||
|
||||
void TransferReceiver::cleanup()
|
||||
{
|
||||
@@ -44,8 +44,8 @@ void TransferReceiver::updateTransferTimings()
|
||||
(prev_transfer_ts_monotonic_ >= prev_prev_ts))
|
||||
{
|
||||
uint64_t interval = prev_transfer_ts_monotonic_ - prev_prev_ts;
|
||||
interval = std::max(std::min(interval, MAX_TRANSFER_INTERVAL), MIN_TRANSFER_INTERVAL);
|
||||
transfer_interval_ = (transfer_interval_ * 7 + interval) / 8;
|
||||
interval = std::max(std::min(interval, uint64_t(MAX_TRANSFER_INTERVAL)), uint64_t(MIN_TRANSFER_INTERVAL));
|
||||
transfer_interval_ = static_cast<uint32_t>((uint64_t(transfer_interval_) * 7 + interval) / 8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,11 +139,11 @@ TransferReceiver::ResultCode TransferReceiver::receive(const RxFrame& frame)
|
||||
|
||||
bool TransferReceiver::isTimedOut(uint64_t timestamp) const
|
||||
{
|
||||
static const int INTERVAL_MULT = (1 << TransferID::BITLEN) / 2 - 1;
|
||||
static const uint64_t INTERVAL_MULT = (1 << TransferID::BITLEN) / 2 - 1;
|
||||
const uint64_t ts = this_transfer_ts_monotonic_;
|
||||
if (timestamp <= ts)
|
||||
return false;
|
||||
return (timestamp - ts) > (transfer_interval_ * INTERVAL_MULT);
|
||||
return (timestamp - ts) > (uint64_t(transfer_interval_) * INTERVAL_MULT);
|
||||
}
|
||||
|
||||
TransferReceiver::ResultCode TransferReceiver::addFrame(const RxFrame& frame)
|
||||
@@ -160,7 +160,7 @@ TransferReceiver::ResultCode TransferReceiver::addFrame(const RxFrame& frame)
|
||||
}
|
||||
|
||||
const bool not_initialized = !isInitialized();
|
||||
const bool iface_timed_out = (frame.ts_monotonic - this_transfer_ts_monotonic_) > (transfer_interval_ * 2);
|
||||
const bool iface_timed_out = (frame.ts_monotonic - this_transfer_ts_monotonic_) > (uint64_t(transfer_interval_) * 2);
|
||||
const bool receiver_timed_out = isTimedOut(frame.ts_monotonic);
|
||||
const bool same_iface = frame.iface_index == iface_index_;
|
||||
const bool first_fame = frame.frame_index == 0;
|
||||
|
||||
Reference in New Issue
Block a user