-
Notifications
You must be signed in to change notification settings - Fork 1
/
ring.h
118 lines (87 loc) · 1.89 KB
/
ring.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#define MAX_NUM_NEIGHBORS 10
#define SHARING_TIME 10
#define TOKEN_TIME 103
//PAYLOAD
#define MSG 0
#define ID 1
#define RIGHT_ID 2
#define LEFT_ID 3
#define STATE 4
#define RECEIVER 5
#define SENDER 6
#define COLOR 7
#define MINID 8
#define ACTIVE 0
#define QUEUE 2
#ifndef M_PI
#define M_PI 3.141592653589793238462643383279502884197169399375105820974944
#endif
typedef enum { NULL_MSG,
SHARE,
JOIN,
LEAVE,
MOVE,
ELECTION,
ELECTED
} message_type; // MESSAGES
typedef enum {
AUTONOMOUS,
COOPERATIVE
} robot_state; // STATE
// declare motion variable type
typedef enum {
STOP,
FORWARD,
LEFT,
RIGHT
} motion_t;
typedef struct{
uint8_t id;
uint8_t right_id;
uint8_t left_id;
robot_state state;
uint8_t distance;
uint8_t num;
uint8_t num_cooperative;
//uint8_t is_master;
uint8_t message_recv_delay;
} nearest_neighbor_t;
typedef struct {
uint8_t motion;
uint8_t time;
} motion_time_t;
typedef int bool;
enum { false, true };
typedef struct
{
uint8_t my_id;
uint8_t my_right;
uint8_t my_left;
message_t message[QUEUE];
message_t nullmessage;
robot_state state;
uint8_t num_neighbors;
uint8_t message_sent;
uint16_t now;
uint16_t nextShareSending;
uint8_t cur_motion;
uint8_t min_id;
uint8_t motion_state;
uint8_t time_active;
uint8_t move_state;
nearest_neighbor_t nearest_neighbors[MAX_NUM_NEIGHBORS];
motion_time_t move_motion[3];
char send_token;
uint8_t green;
uint8_t red;
uint8_t blue;
int8_t token;
int8_t head, tail;
int8_t copies;
//uint8_t master;
uint8_t loneliness;
bool send_election;
bool send_elected;
bool has_participated;
//status
} USERDATA;