Revision 1861
Added function to reply to pings, and come calls to ping robots in the queue. Won't yet do anything to check if a bot disappeared, but it will compile.
main.c | ||
---|---|---|
55 | 55 |
#define WHIGHWAYEXIT 22 //[type, bot, highway] |
56 | 56 |
#define WPINGGLOBAL 30 //[type, bot] |
57 | 57 |
#define WPINGBOT 31 //[type, fromBot, toBot] |
58 |
#define WPINGQUEUE 32 //[type, bot, queue]
|
|
58 |
#define WPINGQUEUE 32 //[type, fromBot, queue, toBot]
|
|
59 | 59 |
#define WPINGREPLY 33 //[type, fromBot, toBot] |
60 | 60 |
|
61 |
void pingReply(char ping[PACKET_LENGTH], char sendBuffer[PACKET_LENGTH], char nextBot){ |
|
62 |
sendBuffer[0] = WPINGREPLY; |
|
63 |
switch(ping[0]){ |
|
64 |
case WPINGBOT: |
|
65 |
sendBuffer[2] = ping[1]; |
|
66 |
wl_basic_send_global_packet(42, sendBuffer, PACKET_LENGTH); |
|
67 |
break; |
|
68 |
case WPINGQUEUE: |
|
69 |
sendBuffer[2] = ping[1]; |
|
70 |
if(ping[3] == get_robotid()){ |
|
71 |
wl_basic_send_global_packet(42, sendBuffer, PACKET_LENGTH); |
|
72 |
} |
|
73 |
if(ping[3] == nextBot){ |
|
74 |
//If next bot is missing from queue, take its place |
|
75 |
} |
|
76 |
break; |
|
77 |
default: |
|
78 |
break; |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
61 | 82 |
int main (void) { |
62 | 83 |
|
63 | 84 |
int state, sign, dataLength; |
... | ... | |
146 | 167 |
orb2_set_color(BLUE); |
147 | 168 |
} |
148 | 169 |
} |
170 |
if(dataLength==PACKET_LENGTH && (packet[0]==WPINGBOT || packet[0]==WPINGQUEUE)){ |
|
171 |
pingReply(packet, sendBuffer, nextBot); |
|
172 |
} |
|
173 |
if(rtc_get()<<12 == 0){ |
|
174 |
sendBuffer[0] = WPINGQUEUE; |
|
175 |
sendBuffer[2] = intersectionNum; |
|
176 |
wl_basic_send_global_packet(42, sendBuffer, PACKET_LENGTH); |
|
177 |
} |
|
149 | 178 |
} |
150 | 179 |
orb1_set_color(RED); |
151 | 180 |
//Drives through intersection |
Also available in: Unified diff