@@ -26,90 +26,95 @@ namespace modm::can
26
26
/// @ingroup modm_architecture_can
27
27
struct Message
28
28
{
29
- inline Message(uint32_t inIdentifier = 0, uint8_t inLength = 0) :
29
+ constexpr Message(uint32_t inIdentifier = 0, uint8_t inLength = 0) :
30
30
identifier(inIdentifier), flags()
31
31
{
32
32
setLength(inLength);
33
33
}
34
34
35
- inline Message(uint32_t inIdentifier, uint8_t inLength, const uint64_t &inData, bool extended = false) :
35
+ constexpr Message(uint32_t inIdentifier, uint8_t inLength, const uint64_t &inData, bool extended = false) :
36
36
Message(inIdentifier, std::min(inLength, uint8_t(8)))
37
37
{
38
38
flags.extended = extended;
39
- const uint8_t *inDataB = reinterpret_cast<const uint8_t *>(&inData);
40
39
for (uint8_t ii = 0; ii < length; ++ii)
41
- data[ii] = inDataB[length - ii - 1] ;
40
+ data[ii] = inData >> ((7 - ii - (8 - length)) * 8) ;
42
41
}
43
42
44
- inline Message(uint32_t inIdentifier, uint8_t inLength, const uint8_t *inData, bool extended = false) :
43
+ constexpr Message(uint32_t inIdentifier, uint8_t inLength, const uint8_t *inData, bool extended = false) :
45
44
Message(inIdentifier, inLength)
46
45
{
47
46
flags.extended = extended;
48
47
for (uint8_t ii = 0; ii < length; ++ii)
49
48
data[ii] = inData[ii];
50
49
}
51
50
52
- inline uint32_t
51
+ constexpr Message(const modm::can::Message& rhs)
52
+ : identifier{rhs.identifier}, flags{rhs.flags}, dlc{rhs.dlc}, length{rhs.length}
53
+ {
54
+ std::copy(std::begin(rhs.data), std::end(rhs.data), std::begin(data));
55
+ }
56
+
57
+ constexpr uint32_t
53
58
getIdentifier() const
54
59
{
55
60
return identifier;
56
61
}
57
62
58
- inline void
63
+ constexpr void
59
64
setIdentifier(uint32_t id)
60
65
{
61
66
identifier = id;
62
67
}
63
68
64
- inline constexpr uint8_t
69
+ constexpr uint8_t
65
70
getCapacity() const
66
71
{
67
72
return capacity;
68
73
}
69
74
70
- inline void
75
+ constexpr void
71
76
setFlexibleData(bool fd = true)
72
77
{
73
78
flags.fd = fd;
74
79
}
75
80
76
- inline bool
81
+ constexpr bool
77
82
isFlexibleData() const
78
83
{
79
84
return (flags.fd != 0);
80
85
}
81
86
82
- inline bool
87
+ constexpr bool
83
88
isBitRateSwitching() const
84
89
{
85
90
return (flags.brs != 0);
86
91
}
87
92
88
- inline void
93
+ constexpr void
89
94
setExtended(bool extended = true)
90
95
{
91
96
flags.extended = (extended) ? 1 : 0;
92
97
}
93
98
94
- inline bool
99
+ constexpr bool
95
100
isExtended() const
96
101
{
97
102
return (flags.extended != 0);
98
103
}
99
104
100
- inline void
105
+ constexpr void
101
106
setRemoteTransmitRequest(bool rtr = true)
102
107
{
103
108
flags.rtr = (rtr) ? 1 : 0;
104
109
}
105
110
106
- inline bool
111
+ constexpr bool
107
112
isRemoteTransmitRequest() const
108
113
{
109
114
return (flags.rtr != 0);
110
115
}
111
116
112
- inline void
117
+ constexpr void
113
118
setDataLengthCode(uint8_t inDlc)
114
119
{
115
120
while (dlcConversionTable[inDlc] > capacity) inDlc--;
@@ -119,7 +124,7 @@ struct Message
119
124
if (dlc > 8) setFlexibleData();
120
125
}
121
126
122
- inline void
127
+ constexpr void
123
128
setLength(uint8_t inLength)
124
129
{
125
130
if constexpr (capacity <= 8)
@@ -134,13 +139,13 @@ struct Message
134
139
}
135
140
}
136
141
137
- inline uint8_t
142
+ constexpr uint8_t
138
143
getLength() const
139
144
{
140
145
return length;
141
146
}
142
147
143
- inline uint8_t
148
+ constexpr uint8_t
144
149
getDataLengthCode() const
145
150
{
146
151
return dlc;
@@ -153,7 +158,7 @@ public:
153
158
uint32_t identifier;
154
159
struct Flags
155
160
{
156
- Flags() :
161
+ constexpr Flags() :
157
162
fd(0), brs(0), rtr(0), extended(1)
158
163
{
159
164
}
@@ -165,10 +170,10 @@ public:
165
170
} flags;
166
171
uint8_t dlc;
167
172
uint8_t length;
168
- uint8_t modm_aligned(4) data[capacity];
173
+ uint8_t modm_aligned(4) data[capacity]{} ;
169
174
170
175
public:
171
- inline bool
176
+ constexpr bool
172
177
operator == (const modm::can::Message& rhs) const
173
178
{
174
179
return ((this->identifier == rhs.identifier) and
@@ -181,7 +186,7 @@ public:
181
186
std::equal(data, data + getLength(), rhs.data));
182
187
}
183
188
184
- inline void
189
+ constexpr modm::can::Message&
185
190
operator = (const modm::can::Message& rhs)
186
191
{
187
192
this->identifier = rhs.identifier;
@@ -192,9 +197,10 @@ public:
192
197
this->flags.rtr = rhs.flags.rtr;
193
198
this->flags.extended = rhs.flags.extended;
194
199
std::copy(std::begin(rhs.data), std::end(rhs.data), std::begin(this->data));
200
+ return *this;
195
201
}
196
202
197
- inline bool
203
+ constexpr bool
198
204
operator < (const modm::can::Message& rhs) const
199
205
{
200
206
return (this->identifier << (this->flags.extended ? 0 : 18))
0 commit comments