Mario Bambagini
/
can
program which tests the CAR project (concerning the CAN bus)
net.hpp
- Committer:
- mariob
- Date:
- 2015-08-31
- Revision:
- 1:8446a0d14877
- Parent:
- 0:8097eeede645
File content as of revision 1:8446a0d14877:
#ifndef __NET_H__ #define __NET_H__ #include "common_types.h" #define CAN_FLAG_EMPTY 0x00 #define CAN_FLAG_RECEIVED 0x01 #define CAN_FLAG_SEND 0x02 #define CAN_THREAD_PERIOD 100 //ms #define CMD_ECHO 0x0A0A /************************************************** * GLOBAL DEFINES **************************************************/ #define CAN_CMD_BODY_ID 0xAA #define CAN_STS_BODY_ID 0xAB #define CAN_CMD_ENGINE_ID 0x0A #define CAN_CMD_TIME_ID 0xBB #define CAN_CMD_DRIVER_ID 0x11 #define CAN_STS_DRIVER_ID 0x10 #define PERIOD_3s (3000/CAN_THREAD_PERIOD) #define PERIOD_1s (1000/CAN_THREAD_PERIOD) #define PERIOD_500ms (500/CAN_THREAD_PERIOD) #define PERIOD_400ms (400/CAN_THREAD_PERIOD) #define PERIOD_300ms (300/CAN_THREAD_PERIOD) #define PERIOD_200ms (200/CAN_THREAD_PERIOD) #define PERIOD_100ms (100/CAN_THREAD_PERIOD) #define CAN_STS_BODY_PERIOD PERIOD_1s #define CAN_MISSING_DETECTION PERIOD_3s #define CAN_MISSING_BODY_ID 0 #define CAN_MISSING_ENGINE_ID 1 #define CAN_MISSING_TIME_ID 2 #define CAN_RX_PERIODIC_MSG 3 /************************************************** * GLOBAL TYPES **************************************************/ #define CAN_CMD_PAYLOAD_BODY 4 #define CAN_STS_PAYLOAD_BODY 8 #define CAN_CMD_PAYLOAD_ENGINE 4 #define CAN_CMD_PAYLOAD_TIME 4 #define CAN_CMD_PAYLOAD_DRIVER 8 #define CAN_STS_PAYLOAD_DRIVER 4 typedef union can_cmd_body_payload_s { uint8 buf[CAN_CMD_PAYLOAD_BODY]; struct { uint32 light_r:1; uint32 light_c:1; uint32 light_l:1; uint32 unused:29; } msg; } can_cmd_body_payload_t; typedef struct can_cmd_body_s { can_cmd_body_payload_t payload; uint8 flag; } can_cmd_body_t; typedef union can_sts_body_payload_s { uint8 buf[CAN_STS_PAYLOAD_BODY]; struct { uint32 hit_front:1; uint32 hit_rear:1; uint32 hit_left:1; uint32 hit_right:1; uint32 light_sens:1; uint32 unused:3; uint32 eye_back_l:8; uint32 eye_back_r:8; uint32 eye_front:16; } msg; } can_sts_body_payload_t; typedef struct can_sts_body_s { can_sts_body_payload_t payload; uint8 flag; } can_sts_body_t; typedef union can_cmd_engine_payload_s { uint8 buf[CAN_CMD_PAYLOAD_BODY]; struct { uint32 steering:8; uint32 power:8; uint32 direction:1; uint32 breaking:1; uint32 unused:14; } msg; } can_cmd_engine_payload_t; typedef struct can_cmd_engine_s { can_cmd_engine_payload_t payload; uint8 flag; } can_cmd_engine_t; typedef union can_cmd_time_payload_s { uint8 buf[CAN_CMD_PAYLOAD_TIME]; struct { uint32 time; } msg; } can_cmd_time_payload_t; typedef struct can_cmd_time_s { can_cmd_time_payload_t payload; uint8 flag; } can_cmd_time_t; typedef union can_cmd_driver_payload_s { uint8 buf[CAN_CMD_PAYLOAD_DRIVER]; struct { uint32 cmd:16; uint32 opt:16; uint32 data; } msg; } can_cmd_driver_payload_t; typedef struct can_cmd_driver_s { can_cmd_driver_payload_t payload; uint8 flag; } can_cmd_driver_t; typedef union can_sts_driver_payload_s { uint8 buf[CAN_STS_PAYLOAD_DRIVER]; struct { uint32 data; } msg; } can_sts_driver_payload_t; typedef struct can_sts_driver_time_s { can_sts_driver_payload_t payload; uint8 flag; } can_sts_driver_t; /************************************************** * DATA STRUCTURES **************************************************/ #endif //__NET_H__