|
| 1 | +/****************************************************************************** |
| 2 | + * @file OD_control |
| 3 | + * @brief object dictionnary managing flux control commands |
| 4 | + * @author Luos |
| 5 | + * @version 0.0.0 |
| 6 | + ******************************************************************************/ |
| 7 | +#ifndef OD_OD_CONTROL_H_ |
| 8 | +#define OD_OD_CONTROL_H_ |
| 9 | + |
| 10 | +#include "luos.h" |
| 11 | + |
| 12 | +/******************************************************************************* |
| 13 | + * Definitions |
| 14 | + ******************************************************************************/ |
| 15 | +/* |
| 16 | + * Control modes |
| 17 | + */ |
| 18 | +typedef enum |
| 19 | +{ |
| 20 | + PLAY, |
| 21 | + PAUSE, |
| 22 | + STOP |
| 23 | +} control_type_t; |
| 24 | +/* |
| 25 | + * controle |
| 26 | + */ |
| 27 | +typedef struct __attribute__((__packed__)) |
| 28 | +{ |
| 29 | + union |
| 30 | + { |
| 31 | + struct __attribute__((__packed__)) |
| 32 | + { |
| 33 | + // control modes |
| 34 | + uint8_t flux : 2; |
| 35 | + uint8_t rec : 1; |
| 36 | + }; |
| 37 | + uint8_t unmap; |
| 38 | + }; |
| 39 | +} control_t; |
| 40 | + |
| 41 | +/******************************************************************************* |
| 42 | + * Variables |
| 43 | + ******************************************************************************/ |
| 44 | + |
| 45 | +/******************************************************************************* |
| 46 | + * Function |
| 47 | + ******************************************************************************/ |
| 48 | +// There is no conversion possible for PID |
| 49 | +//******** Conversions *********** |
| 50 | + |
| 51 | +//******** Messages management *********** |
| 52 | +static inline void ControlOD_ControlToMsg(const control_t *const self, msg_t *const msg) |
| 53 | +{ |
| 54 | + msg->header.cmd = CONTROL; |
| 55 | + memcpy(msg->data, self, sizeof(control_t)); |
| 56 | + msg->header.size = sizeof(control_t); |
| 57 | +} |
| 58 | + |
| 59 | +static inline void ControlOD_ControlFromMsg(control_t *const self, const msg_t *const msg) |
| 60 | +{ |
| 61 | + LUOS_ASSERT(msg->header.size == sizeof(control_t)); |
| 62 | + memcpy(self, msg->data, sizeof(control_t)); |
| 63 | + // check data validity |
| 64 | + if (self->flux == 3) |
| 65 | + { |
| 66 | + // impossible value, go back to default values |
| 67 | + self->unmap = 0; |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +#endif /* OD_OD_CONTROL_H_ */ |
0 commit comments