Mario Bambagini
/
can
program which tests the CAR project (concerning the CAN bus)
Diff: net.hpp
- Revision:
- 0:8097eeede645
- Child:
- 1:8446a0d14877
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/net.hpp Sun Aug 02 12:55:55 2015 +0000 @@ -0,0 +1,124 @@ +#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 + + +/************************************************** + * 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_1s 10 +#define PERIOD_500ms 5 + +#define CAN_STS_BODY_PERIOD PERIOD_500ms + +/************************************************** + * 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_driver_time_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 + **************************************************/ +void init_can(CAN *device); + +#endif //__NET_H__