-
Notifications
You must be signed in to change notification settings - Fork 5
/
Msg.c
285 lines (231 loc) · 6.5 KB
/
Msg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/**
* The MIT License (MIT)
*
* Copyright (c) 2018-2019 Erik Moqvist
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* This file was generated by cantools version 37.1.0 Thu Mar 30 21:54:28 2023.
*/
#include <string.h>
#include "Msg.h"
static inline uint8_t pack_left_shift_u8(
uint8_t value,
uint8_t shift,
uint8_t mask)
{
return (uint8_t)((uint8_t)(value << shift) & mask);
}
static inline uint8_t pack_left_shift_u16(
uint16_t value,
uint8_t shift,
uint8_t mask)
{
return (uint8_t)((uint8_t)(value << shift) & mask);
}
static inline uint8_t pack_right_shift_u16(
uint16_t value,
uint8_t shift,
uint8_t mask)
{
return (uint8_t)((uint8_t)(value >> shift) & mask);
}
static inline uint16_t unpack_left_shift_u16(
uint8_t value,
uint8_t shift,
uint8_t mask)
{
return (uint16_t)((uint16_t)(value & mask) << shift);
}
static inline uint8_t unpack_right_shift_u8(
uint8_t value,
uint8_t shift,
uint8_t mask)
{
return (uint8_t)((uint8_t)(value & mask) >> shift);
}
static inline uint16_t unpack_right_shift_u16(
uint8_t value,
uint8_t shift,
uint8_t mask)
{
return (uint16_t)((uint16_t)(value & mask) >> shift);
}
int Msg_steering_command_unpack(
struct Msg_steering_command_t *dst_p,
const uint8_t *src_p,
size_t size)
{
uint16_t steer_angle;
uint8_t steer_torque;
if (size < 5u) {
return (-EINVAL);
}
dst_p->checksum = unpack_right_shift_u8(src_p[0], 0u, 0xffu);
dst_p->counter = unpack_right_shift_u8(src_p[1], 0u, 0x0fu);
dst_p->steer_mode = unpack_right_shift_u8(src_p[1], 4u, 0x30u);
steer_angle = unpack_right_shift_u16(src_p[2], 0u, 0xffu);
steer_angle |= unpack_left_shift_u16(src_p[3], 8u, 0xffu);
dst_p->steer_angle = (int16_t)steer_angle;
steer_torque = unpack_right_shift_u8(src_p[4], 0u, 0xffu);
dst_p->steer_torque = (int8_t)steer_torque;
return (0);
}
float Msg_steering_command_checksum_decode(uint8_t value)
{
return ((float)value);
}
bool Msg_steering_command_checksum_is_in_range(uint8_t value)
{
(void)value;
return (true);
}
float Msg_steering_command_counter_decode(uint8_t value)
{
return ((float)value);
}
bool Msg_steering_command_counter_is_in_range(uint8_t value)
{
return (value <= 15u);
}
float Msg_steering_command_steer_mode_decode(uint8_t value)
{
return ((float)value);
}
bool Msg_steering_command_steer_mode_is_in_range(uint8_t value)
{
return (value <= 3u);
}
float Msg_steering_command_steer_angle_decode(int16_t value)
{
return ((float)value * 0.125f);
}
bool Msg_steering_command_steer_angle_is_in_range(int16_t value)
{
(void)value;
return (true);
}
float Msg_steering_command_steer_torque_decode(int8_t value)
{
return ((float)value * 0.125f);
}
bool Msg_steering_command_steer_torque_is_in_range(int8_t value)
{
(void)value;
return (true);
}
int Msg_steering_status_pack(
uint8_t *dst_p,
const struct Msg_steering_status_t *src_p,
size_t size)
{
uint16_t steering_angle;
uint8_t steering_speed;
uint8_t steering_torque;
if (size < 8u) {
return (-EINVAL);
}
memset(&dst_p[0], 0, 8);
dst_p[0] |= pack_left_shift_u8(src_p->checksum, 0u, 0xffu);
dst_p[1] |= pack_left_shift_u8(src_p->counter, 0u, 0x0fu);
dst_p[1] |= pack_left_shift_u8(src_p->control_status, 4u, 0xf0u);
steering_torque = (uint8_t)src_p->steering_torque;
dst_p[2] |= pack_left_shift_u8(steering_torque, 0u, 0xffu);
steering_speed = (uint8_t)src_p->steering_speed;
dst_p[3] |= pack_left_shift_u8(steering_speed, 0u, 0xffu);
dst_p[4] |= pack_left_shift_u8(src_p->temperature, 0u, 0xffu);
steering_angle = (uint16_t)src_p->steering_angle;
dst_p[5] |= pack_left_shift_u16(steering_angle, 0u, 0xffu);
dst_p[6] |= pack_right_shift_u16(steering_angle, 8u, 0xffu);
dst_p[7] |= pack_left_shift_u8(src_p->debug_states, 0u, 0xffu);
return (8);
}
uint8_t Msg_steering_status_checksum_encode(float value)
{
return (uint8_t)(value);
}
bool Msg_steering_status_checksum_is_in_range(uint8_t value)
{
(void)value;
return (true);
}
uint8_t Msg_steering_status_counter_encode(float value)
{
return (uint8_t)(value);
}
bool Msg_steering_status_counter_is_in_range(uint8_t value)
{
return (value <= 15u);
}
uint8_t Msg_steering_status_control_status_encode(float value)
{
return (uint8_t)(value);
}
bool Msg_steering_status_control_status_is_in_range(uint8_t value)
{
return (value <= 15u);
}
int8_t Msg_steering_status_steering_torque_encode(float value)
{
return (int8_t)(value / 0.125f);
}
bool Msg_steering_status_steering_torque_is_in_range(int8_t value)
{
(void)value;
return (true);
}
int8_t Msg_steering_status_steering_speed_encode(float value)
{
return (int8_t)(value / 0.015625f);
}
bool Msg_steering_status_steering_speed_is_in_range(int8_t value)
{
(void)value;
return (true);
}
uint8_t Msg_steering_status_temperature_encode(float value)
{
return (uint8_t)(value - -60.0f);
}
bool Msg_steering_status_temperature_is_in_range(uint8_t value)
{
(void)value;
return (true);
}
int16_t Msg_steering_status_steering_angle_encode(float value)
{
return (int16_t)(value / 0.125f);
}
bool Msg_steering_status_steering_angle_is_in_range(int16_t value)
{
(void)value;
return (true);
}
uint8_t Msg_steering_status_debug_states_encode(float value)
{
return (uint8_t)(value);
}
bool Msg_steering_status_debug_states_is_in_range(uint8_t value)
{
(void)value;
return (true);
}