transfer.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
3  */
4 
5 #ifndef UAVCAN_TRANSPORT_TRANSFER_HPP_INCLUDED
6 #define UAVCAN_TRANSPORT_TRANSFER_HPP_INCLUDED
7 
8 #include <cassert>
11 #include <uavcan/std.hpp>
12 
13 namespace uavcan
14 {
15 
16 static const unsigned GuaranteedPayloadLenPerFrame = 7;
17 
19 {
23 };
24 
25 static const uint8_t NumTransferTypes = 3;
26 
27 
29 {
31 
32 public:
33  static const uint8_t BitLen = 5U;
34  static const uint8_t NumericallyMax = (1U << BitLen) - 1;
35  static const uint8_t NumericallyMin = 0;
36 
38  static const TransferPriority Default;
42  static const TransferPriority Lowest;
43 
44  TransferPriority() : value_(0xFF) { }
45 
46  TransferPriority(uint8_t value) // Implicit
47  : value_(value)
48  {
49  UAVCAN_ASSERT(isValid());
50  }
51 
52  template <uint8_t Percent>
54  {
55  StaticAssert<(Percent <= 100)>::check();
56  enum { Result = ((100U - Percent) * NumericallyMax) / 100U };
57  StaticAssert<(Result <= NumericallyMax)>::check();
58  StaticAssert<(Result >= NumericallyMin)>::check();
59  return TransferPriority(Result);
60  }
61 
62  uint8_t get() const { return value_; }
63 
64  bool isValid() const { return value_ < (1U << BitLen); }
65 
66  bool operator!=(TransferPriority rhs) const { return value_ != rhs.value_; }
67  bool operator==(TransferPriority rhs) const { return value_ == rhs.value_; }
68 };
69 
70 
72 {
74 
75 public:
76  static const uint8_t BitLen = 5U;
77  static const uint8_t Max = (1U << BitLen) - 1U;
78  static const uint8_t Half = (1U << BitLen) / 2U;
79 
81  : value_(0)
82  { }
83 
84  TransferID(uint8_t value) // implicit
85  : value_(value)
86  {
87  value_ &= Max;
88  UAVCAN_ASSERT(value == value_);
89  }
90 
91  bool operator!=(TransferID rhs) const { return !operator==(rhs); }
92  bool operator==(TransferID rhs) const { return get() == rhs.get(); }
93 
94  void increment()
95  {
96  value_ = (value_ + 1) & Max;
97  }
98 
99  uint8_t get() const
100  {
101  UAVCAN_ASSERT(value_ <= Max);
102  return value_;
103  }
104 
108  int computeForwardDistance(TransferID rhs) const;
109 };
110 
111 
113 {
114  static const uint8_t ValueBroadcast = 0;
115  static const uint8_t ValueInvalid = 0xFF;
117 
118 public:
119  static const uint8_t BitLen = 7U;
120  static const uint8_t Max = (1U << BitLen) - 1U;
121  static const uint8_t MaxRecommendedForRegularNodes = Max - 2;
122  static const NodeID Broadcast;
123 
124  NodeID() : value_(ValueInvalid) { }
125 
126  NodeID(uint8_t value) // Implicit
127  : value_(value)
128  {
129  UAVCAN_ASSERT(isValid());
130  }
131 
132  uint8_t get() const { return value_; }
133 
134  bool isValid() const { return value_ <= Max; }
135  bool isBroadcast() const { return value_ == ValueBroadcast; }
136  bool isUnicast() const { return (value_ <= Max) && (value_ != ValueBroadcast); }
137 
138  bool operator!=(NodeID rhs) const { return !operator==(rhs); }
139  bool operator==(NodeID rhs) const { return value_ == rhs.value_; }
140 
141  bool operator<(NodeID rhs) const { return value_ < rhs.value_; }
142  bool operator>(NodeID rhs) const { return value_ > rhs.value_; }
143  bool operator<=(NodeID rhs) const { return value_ <= rhs.value_; }
144  bool operator>=(NodeID rhs) const { return value_ >= rhs.value_; }
145 };
146 
147 }
148 
149 #endif // UAVCAN_TRANSPORT_TRANSFER_HPP_INCLUDED
TransferID(uint8_t value)
Definition: transfer.hpp:84
std::uint8_t uint8_t
Definition: std.hpp:24
ROSCPP_DECL bool check()
bool operator==(NodeID rhs) const
Definition: transfer.hpp:139
static const NodeID Broadcast
Definition: transfer.hpp:122
bool isUnicast() const
Definition: transfer.hpp:136
bool operator>=(NodeID rhs) const
Definition: transfer.hpp:144
bool operator>(NodeID rhs) const
Definition: transfer.hpp:142
bool isBroadcast() const
Definition: transfer.hpp:135
bool operator==(TransferID rhs) const
Definition: transfer.hpp:92
UAVCAN_EXPORT EnableIf<!IsSameType< R, Array< T, ArrayMode, MaxSize > >::Result, bool >::Type operator==(const R &rhs, const Array< T, ArrayMode, MaxSize > &lhs)
Definition: array.hpp:1101
static const unsigned GuaranteedPayloadLenPerFrame
Guaranteed for all transfers, all CAN standards.
Definition: transfer.hpp:16
bool operator<(NodeID rhs) const
Definition: transfer.hpp:141
bool isValid() const
Definition: transfer.hpp:134
uint8_t get() const
Definition: transfer.hpp:99
TransferType
Definition: transfer.hpp:18
bool operator!=(NodeID rhs) const
Definition: transfer.hpp:138
static const TransferPriority Default
This priority is used by default.
Definition: transfer.hpp:38
bool operator!=(TransferPriority rhs) const
Definition: transfer.hpp:66
bool operator!=(TransferID rhs) const
Definition: transfer.hpp:91
bool operator==(TransferPriority rhs) const
Definition: transfer.hpp:67
NodeID(uint8_t value)
Definition: transfer.hpp:126
static const uint8_t NumTransferTypes
Definition: transfer.hpp:25
TransferPriority(uint8_t value)
Definition: transfer.hpp:46
uint8_t value_
Definition: transfer.hpp:116
static TransferPriority fromPercent()
Definition: transfer.hpp:53
bool isValid() const
Definition: transfer.hpp:64
static const TransferPriority Lowest
Definition: transfer.hpp:42
static const TransferPriority OneHigherThanLowest
Definition: transfer.hpp:40
static const TransferPriority MiddleLower
Definition: transfer.hpp:39
static const TransferPriority OneLowerThanHighest
Definition: transfer.hpp:41
bool operator<=(NodeID rhs) const
Definition: transfer.hpp:143


uavcan_communicator
Author(s):
autogenerated on Wed Jan 11 2023 03:59:40