mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-31 10:21:37 +08:00
All unit tests compile, but crash. This is the most horrifying commit I've ever made.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <uavcan/build_config.hpp>
|
||||
#include <uavcan/util/templates.hpp>
|
||||
#include <uavcan/std.hpp>
|
||||
|
||||
namespace uavcan
|
||||
@@ -29,7 +30,13 @@ class UAVCAN_EXPORT TransferPriority
|
||||
|
||||
public:
|
||||
static const uint8_t BitLen = 5U;
|
||||
static const uint8_t NumericallyMax = (1U << BitLen) - 1;
|
||||
static const uint8_t NumericallyMin = 0;
|
||||
|
||||
/// This priority is used by default
|
||||
static const TransferPriority Default;
|
||||
static const TransferPriority OneHigherThanLowest;
|
||||
static const TransferPriority OneLowerThanHighest;
|
||||
|
||||
TransferPriority() : value_(0xFF) { }
|
||||
|
||||
@@ -39,6 +46,16 @@ public:
|
||||
UAVCAN_ASSERT(isValid());
|
||||
}
|
||||
|
||||
template <uint8_t Percent>
|
||||
static TransferPriority fromPercent()
|
||||
{
|
||||
StaticAssert<(Percent <= 100)>::check();
|
||||
enum { Result = ((100U - Percent) * NumericallyMax) / 100U };
|
||||
StaticAssert<(Result <= NumericallyMax)>::check();
|
||||
StaticAssert<(Result >= NumericallyMin)>::check();
|
||||
return TransferPriority(Result);
|
||||
}
|
||||
|
||||
uint8_t get() const { return value_; }
|
||||
|
||||
bool isValid() const { return value_ < (1U << BitLen); }
|
||||
|
||||
Reference in New Issue
Block a user