|
10 | 10 | #include <stdint.h> |
11 | 11 |
|
12 | 12 | // The current version number for the message format |
13 | | -#define MSG_VERSION 2 |
| 13 | +#define MSG_VERSION 2 |
14 | 14 |
|
15 | 15 | // TODO: Implement more message types |
16 | | -#define MSG_TYPE_DATA 0 // Message contains float values |
17 | | -#define MSG_TYPE_START 1 // Message marks the beginning of a new simulation case |
18 | | -#define MSG_TYPE_STOP 2 // Message marks the end of a simulation case |
| 16 | +#define MSG_TYPE_DATA 0 // Message contains float values |
| 17 | +#define MSG_TYPE_START 1 // Message marks the beginning of a new simulation case |
| 18 | +#define MSG_TYPE_STOP 2 // Message marks the end of a simulation case |
19 | 19 |
|
20 | 20 | // The total size in bytes of a message |
21 | | -#define MSG_LEN(values) (sizeof(struct msg) + MSG_DATA_LEN(values)) |
| 21 | +#define MSG_LEN(values) (sizeof(struct msg) + MSG_DATA_LEN(values)) |
22 | 22 |
|
23 | 23 | // The length of \p values values in bytes |
24 | | -#define MSG_DATA_LEN(values) (sizeof(float) * (values)) |
| 24 | +#define MSG_DATA_LEN(values) (sizeof(float) * (values)) |
25 | 25 |
|
26 | 26 | // The offset to the first data value in a message |
27 | | -#define MSG_DATA_OFFSET(msg) ((char *) (msg) + offsetof(struct msg, data)) |
| 27 | +#define MSG_DATA_OFFSET(msg) ((char *)(msg) + offsetof(struct msg, data)) |
28 | 28 |
|
29 | 29 | // Initialize a message with default values |
30 | | -#define MSG_INIT(len, seq) (struct msg) {\ |
31 | | - .version = MSG_VERSION, \ |
32 | | - .type = MSG_TYPE_DATA, \ |
33 | | - .length = len, \ |
34 | | - .sequence = seq, \ |
35 | | - .id = 0 \ |
36 | | -} |
| 30 | +#define MSG_INIT(len, seq) \ |
| 31 | + (struct msg) { \ |
| 32 | + .version = MSG_VERSION, .type = MSG_TYPE_DATA, .length = len, \ |
| 33 | + .sequence = seq, .id = 0 \ |
| 34 | + } |
37 | 35 |
|
38 | 36 | // The timestamp of a message in struct timespec format |
39 | | -#define MSG_TS(msg) (struct timespec) { \ |
40 | | - .tv_sec = (msg)->ts.sec, \ |
41 | | - .tv_nsec = (msg)->ts.nsec \ |
42 | | -} |
| 37 | +#define MSG_TS(msg) \ |
| 38 | + (struct timespec) { .tv_sec = (msg)->ts.sec, .tv_nsec = (msg)->ts.nsec } |
43 | 39 |
|
44 | 40 | // This message format is used by all clients |
45 | | -struct msg |
46 | | -{ |
| 41 | +struct msg { |
47 | 42 | #if BYTE_ORDER == BIG_ENDIAN |
48 | | - unsigned version: 4; // Specifies the format of the remaining message (see MGS_VERSION) |
49 | | - unsigned type : 2; // Data or control message (see MSG_TYPE_*) |
50 | | - unsigned reserved1 : 2; // Reserved bits |
| 43 | + unsigned |
| 44 | + version : 4; // Specifies the format of the remaining message (see MGS_VERSION) |
| 45 | + unsigned type : 2; // Data or control message (see MSG_TYPE_*) |
| 46 | + unsigned reserved1 : 2; // Reserved bits |
51 | 47 | #elif BYTE_ORDER == LITTLE_ENDIAN |
52 | | - unsigned reserved1 : 2; // Reserved bits |
53 | | - unsigned type : 2; // Data or control message (see MSG_TYPE_*) |
54 | | - unsigned version: 4; // Specifies the format of the remaining message (see MGS_VERSION) |
| 48 | + unsigned reserved1 : 2; // Reserved bits |
| 49 | + unsigned type : 2; // Data or control message (see MSG_TYPE_*) |
| 50 | + unsigned |
| 51 | + version : 4; // Specifies the format of the remaining message (see MGS_VERSION) |
55 | 52 | #else |
56 | | - #error Invalid byte-order |
| 53 | +#error Invalid byte-order |
57 | 54 | #endif // BYTEORDER |
58 | 55 |
|
59 | | - uint8_t id; // An id which identifies the source of this sample |
60 | | - uint16_t length; // The number of values in msg::data[] |
61 | | - uint32_t sequence; // The sequence number is incremented by one for consecutive messages |
| 56 | + uint8_t id; // An id which identifies the source of this sample |
| 57 | + uint16_t length; // The number of values in msg::data[] |
| 58 | + uint32_t |
| 59 | + sequence; // The sequence number is incremented by one for consecutive messages |
62 | 60 |
|
63 | | - // A timestamp per message |
64 | | - struct { |
65 | | - uint32_t sec; // Seconds since 1970-01-01 00:00:00 |
66 | | - uint32_t nsec; // Nanoseconds of the current second |
67 | | - } ts; |
| 61 | + // A timestamp per message |
| 62 | + struct { |
| 63 | + uint32_t sec; // Seconds since 1970-01-01 00:00:00 |
| 64 | + uint32_t nsec; // Nanoseconds of the current second |
| 65 | + } ts; |
68 | 66 |
|
69 | | - // The message payload |
70 | | - union { |
71 | | - float f; // Floating point values |
72 | | - uint32_t i; // Integer values |
73 | | - } data[]; |
| 67 | + // The message payload |
| 68 | + union { |
| 69 | + float f; // Floating point values |
| 70 | + uint32_t i; // Integer values |
| 71 | + } data[]; |
74 | 72 | } __attribute__((packed)); |
0 commit comments