Publishing for Biomimetics.
Dependencies: CRC MODDMA MODSERIAL MPU6050IMU PID QEI mbed-rtos mbed-src
protocol.h@0:8cfa73bb68e4, 2016-05-31 (annotated)
- Committer:
- abuchan
- Date:
- Tue May 31 17:04:59 2016 +0000
- Revision:
- 0:8cfa73bb68e4
Publishing for Biomimetics.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
abuchan | 0:8cfa73bb68e4 | 1 | #ifndef PROTOCOL_H |
abuchan | 0:8cfa73bb68e4 | 2 | #define PROTOCOL_H |
abuchan | 0:8cfa73bb68e4 | 3 | |
abuchan | 0:8cfa73bb68e4 | 4 | #include <stdint.h> |
abuchan | 0:8cfa73bb68e4 | 5 | /** |
abuchan | 0:8cfa73bb68e4 | 6 | * Packet type characters. |
abuchan | 0:8cfa73bb68e4 | 7 | */ |
abuchan | 0:8cfa73bb68e4 | 8 | #define PKT_TYPE_COMMAND 'C' |
abuchan | 0:8cfa73bb68e4 | 9 | #define PKT_TYPE_SENSOR 'S' |
abuchan | 0:8cfa73bb68e4 | 10 | #define PKT_TYPE_READ 'G' |
abuchan | 0:8cfa73bb68e4 | 11 | #define PKT_TYPE_RESET 'R' |
abuchan | 0:8cfa73bb68e4 | 12 | #define PKT_TYPE_TIME 'T' |
abuchan | 0:8cfa73bb68e4 | 13 | #define PKT_TYPE_PID 'P' |
abuchan | 0:8cfa73bb68e4 | 14 | |
abuchan | 0:8cfa73bb68e4 | 15 | /** |
abuchan | 0:8cfa73bb68e4 | 16 | * Defines the total maximum size of a packet, including header |
abuchan | 0:8cfa73bb68e4 | 17 | */ |
abuchan | 0:8cfa73bb68e4 | 18 | #define MAX_PACKET_LENGTH 256 |
abuchan | 0:8cfa73bb68e4 | 19 | |
abuchan | 0:8cfa73bb68e4 | 20 | /** |
abuchan | 0:8cfa73bb68e4 | 21 | * Packet structure definitions |
abuchan | 0:8cfa73bb68e4 | 22 | */ |
abuchan | 0:8cfa73bb68e4 | 23 | typedef struct header_t { |
abuchan | 0:8cfa73bb68e4 | 24 | uint8_t start; |
abuchan | 0:8cfa73bb68e4 | 25 | uint8_t length; |
abuchan | 0:8cfa73bb68e4 | 26 | char type; |
abuchan | 0:8cfa73bb68e4 | 27 | uint8_t flags; |
abuchan | 0:8cfa73bb68e4 | 28 | uint32_t sequence; |
abuchan | 0:8cfa73bb68e4 | 29 | } header_t; |
abuchan | 0:8cfa73bb68e4 | 30 | |
abuchan | 0:8cfa73bb68e4 | 31 | typedef struct packet_t { |
abuchan | 0:8cfa73bb68e4 | 32 | header_t header; |
abuchan | 0:8cfa73bb68e4 | 33 | uint8_t data_crc[MAX_PACKET_LENGTH-sizeof(header_t)]; |
abuchan | 0:8cfa73bb68e4 | 34 | } packet_t; |
abuchan | 0:8cfa73bb68e4 | 35 | |
abuchan | 0:8cfa73bb68e4 | 36 | typedef union packet_union_t { |
abuchan | 0:8cfa73bb68e4 | 37 | packet_t packet; |
abuchan | 0:8cfa73bb68e4 | 38 | char raw[MAX_PACKET_LENGTH]; |
abuchan | 0:8cfa73bb68e4 | 39 | } packet_union_t; |
abuchan | 0:8cfa73bb68e4 | 40 | |
abuchan | 0:8cfa73bb68e4 | 41 | typedef struct command_data_t { |
abuchan | 0:8cfa73bb68e4 | 42 | float left; |
abuchan | 0:8cfa73bb68e4 | 43 | float right; |
abuchan | 0:8cfa73bb68e4 | 44 | } command_data_t; |
abuchan | 0:8cfa73bb68e4 | 45 | |
abuchan | 0:8cfa73bb68e4 | 46 | typedef struct sensor_data_t { |
abuchan | 0:8cfa73bb68e4 | 47 | uint32_t time; |
abuchan | 0:8cfa73bb68e4 | 48 | float accel[3]; |
abuchan | 0:8cfa73bb68e4 | 49 | float gyro[3]; |
abuchan | 0:8cfa73bb68e4 | 50 | int32_t encoder[2]; |
abuchan | 0:8cfa73bb68e4 | 51 | float velocity[2]; |
abuchan | 0:8cfa73bb68e4 | 52 | float voltage; |
abuchan | 0:8cfa73bb68e4 | 53 | } sensor_data_t; |
abuchan | 0:8cfa73bb68e4 | 54 | |
abuchan | 0:8cfa73bb68e4 | 55 | typedef struct read_data_t { |
abuchan | 0:8cfa73bb68e4 | 56 | int32_t period; |
abuchan | 0:8cfa73bb68e4 | 57 | } read_data_t; |
abuchan | 0:8cfa73bb68e4 | 58 | |
abuchan | 0:8cfa73bb68e4 | 59 | typedef struct time_data_t { |
abuchan | 0:8cfa73bb68e4 | 60 | uint32_t time; |
abuchan | 0:8cfa73bb68e4 | 61 | } time_data_t; |
abuchan | 0:8cfa73bb68e4 | 62 | |
abuchan | 0:8cfa73bb68e4 | 63 | typedef struct pid_data_t { |
abuchan | 0:8cfa73bb68e4 | 64 | float vel[2]; |
abuchan | 0:8cfa73bb68e4 | 65 | float pwm[2]; |
abuchan | 0:8cfa73bb68e4 | 66 | } pid_data_t; |
abuchan | 0:8cfa73bb68e4 | 67 | |
abuchan | 0:8cfa73bb68e4 | 68 | #endif |