Mario Bambagini / Mbed 2 deprecated car_chassis

Dependencies:   Servo mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers net.hpp Source File

net.hpp

00001 #ifndef __NET_H__
00002 #define __NET_H__
00003 
00004 #include "common_types.h"
00005 
00006 #define CAN_FLAG_EMPTY          0x00
00007 #define CAN_FLAG_RECEIVED       0x01
00008 #define CAN_FLAG_SEND           0x02
00009 
00010 #define CMD_ECHO                0x0A0A
00011 
00012 /**************************************************
00013  * MESSAGE IDs
00014  **************************************************/
00015 
00016 #define CAN_CMD_BODY_ID         0xAA
00017 #define CAN_STS_BODY_ID         0xAB
00018 #define CAN_CMD_ENGINE_ID       0x0A
00019 #define CAN_CMD_TIME_ID         0xBB
00020 #define CAN_CMD_DIAG_ID         0x11
00021 #define CAN_STS_DIAG_ID         0x10
00022 #define CAN_CMD_CAMERA_ID       0x22
00023 
00024 /**************************************************
00025  * PERIODs
00026  **************************************************/
00027 
00028 #define PERIOD_60s              (60000/CAN_THREAD_PERIOD)
00029 #define PERIOD_3s               (3000/CAN_THREAD_PERIOD)
00030 #define PERIOD_1s               (1000/CAN_THREAD_PERIOD)
00031 #define PERIOD_500ms            (500/CAN_THREAD_PERIOD)
00032 #define PERIOD_400ms            (400/CAN_THREAD_PERIOD)
00033 #define PERIOD_300ms            (300/CAN_THREAD_PERIOD)
00034 #define PERIOD_200ms            (200/CAN_THREAD_PERIOD)
00035 #define PERIOD_100ms            (100/CAN_THREAD_PERIOD)
00036 
00037 #define CAN_CMD_BODY_PERIOD     PERIOD_1s
00038 #define CAN_STS_BODY_PERIOD     PERIOD_1s
00039 #define CAN_CMD_ENGINE_PERIOD   PERIOD_500ms
00040 #define CAN_CMD_CAMERA_PERIOD   PERIOD_1s
00041 
00042 #define CAN_MISSING_DETECTION   PERIOD_3s
00043 
00044 #define CAN_MISSING_CMD_BODY_ID     0
00045 #define CAN_MISSING_CMD_ENGINE_ID   1
00046 #define CAN_MISSING_CMD_CAMERA_ID   2
00047 #define CAN_MISSING_STS_BODY_ID     3
00048 
00049 #define CAN_RX_PERIODIC_MSG         4
00050 
00051 /**************************************************
00052  * MESSAGE SIZEs
00053  **************************************************/
00054 
00055 #define CAN_CMD_PAYLOAD_BODY    4
00056 #define CAN_STS_PAYLOAD_BODY    8
00057 #define CAN_CMD_PAYLOAD_ENGINE  4
00058 #define CAN_CMD_PAYLOAD_TIME    4
00059 #define CAN_CMD_PAYLOAD_DIAG    8
00060 #define CAN_STS_PAYLOAD_DIAG    4
00061 #define CAN_CMD_PAYLOAD_CAMERA  2
00062 
00063 /**************************************************
00064  * MESSAGE TYPEs
00065  **************************************************/
00066 typedef union can_cmd_body_payload_s {
00067     uint8 buf[CAN_CMD_PAYLOAD_BODY];
00068     struct {
00069         uint32 light_r:1;
00070         uint32 light_c:1;
00071         uint32 light_l:1;
00072         uint32 unused:29;
00073     } msg;
00074 } can_cmd_body_payload_t;
00075 typedef struct can_cmd_body_s {
00076     can_cmd_body_payload_t payload;
00077     uint8 flag;
00078 } can_cmd_body_t;
00079 
00080 typedef union can_sts_body_payload_s {
00081     uint8 buf[CAN_STS_PAYLOAD_BODY];
00082     struct {
00083         uint32 hit_front:1;
00084         uint32 hit_rear:1;
00085         uint32 hit_left:1;
00086         uint32 hit_right:1;
00087         uint32 light_sens:1;
00088         uint32 unused:3;
00089         uint32 eye_back_l:8;
00090         uint32 eye_back_r:8;
00091         uint32 eye_front:16;
00092     } msg;
00093 } can_sts_body_payload_t;
00094 typedef struct can_sts_body_s {
00095     can_sts_body_payload_t payload;
00096     uint8 flag;
00097 } can_sts_body_t;
00098 
00099 typedef union can_cmd_engine_payload_s {
00100     uint8 buf[CAN_CMD_PAYLOAD_BODY];
00101     struct {
00102         uint32 steering:8;
00103         uint32 power:8;
00104         uint32 direction:1;
00105         uint32 breaking:1;
00106         uint32 unused:14;
00107     } msg;
00108 } can_cmd_engine_payload_t;
00109 typedef struct can_cmd_engine_s {
00110     can_cmd_engine_payload_t payload;
00111     uint8 flag;
00112 } can_cmd_engine_t;
00113 
00114 typedef union can_cmd_time_payload_s {
00115     uint8 buf[CAN_CMD_PAYLOAD_TIME];
00116     struct {
00117         uint32 time;
00118     } msg;
00119 } can_cmd_time_payload_t;
00120 typedef struct can_cmd_time_s {
00121     can_cmd_time_payload_t payload;
00122     uint8 flag;
00123 } can_cmd_time_t;
00124 
00125 typedef union can_cmd_diag_payload_s {
00126     uint8 buf[CAN_CMD_PAYLOAD_DIAG];
00127     struct {
00128         uint32 cmd:16;
00129         uint32 opt:16;
00130         uint32 data;
00131     } msg;
00132 } can_cmd_diag_payload_t;
00133 typedef struct can_cmd_diag_s {
00134     can_cmd_diag_payload_t payload;
00135     uint8 flag;
00136 } can_cmd_diag_t;
00137 
00138 typedef union can_sts_diag_payload_s {
00139     uint8 buf[CAN_STS_PAYLOAD_DIAG];
00140     struct {
00141         uint32 data;
00142     } msg;
00143 } can_sts_diag_payload_t;
00144 typedef struct can_sts_diag_time_s {
00145     can_sts_diag_payload_t payload;
00146     uint8 flag;
00147 } can_sts_diag_t;
00148 
00149 typedef union can_cmd_camera_payload_s {
00150     uint8 buf[CAN_CMD_PAYLOAD_CAMERA];
00151     struct {
00152         uint16 x:7;
00153         uint16 y:7;
00154         uint16 mode:2;
00155     } msg;
00156 } can_cmd_camera_payload_t;
00157 typedef struct can_cmd_camera_s {
00158     can_cmd_camera_payload_t payload;
00159     uint8 flag;
00160 } can_cmd_camera_t;
00161 
00162 /**************************************************
00163  * MESSAGE BUFFERs
00164  **************************************************/
00165 
00166 extern can_cmd_body_t can_cmd_body;
00167 extern can_sts_body_t can_sts_body;
00168 extern can_cmd_engine_t can_cmd_engine;
00169 extern can_cmd_time_t can_cmd_time;
00170 extern can_cmd_diag_t can_cmd_diag;
00171 extern can_sts_diag_t can_sts_diag;
00172 extern can_cmd_camera_t can_cmd_camera;
00173 
00174 #endif //__NET_H__