root / trunk / code / projects / colonet / robot / wl_network_colonet / wl_adhoc.h @ 481
History | View | Annotate | Download (3.17 KB)
1 |
#ifndef _WL_ADHOC_H_
|
---|---|
2 |
#define _WL_ADHOC_H_
|
3 |
|
4 |
#include "localization.h" |
5 |
|
6 |
#define WL_BAUD BAUD115200
|
7 |
|
8 |
/*
|
9 |
0 - R
|
10 |
1 - C
|
11 |
2 - SRC
|
12 |
3 - DEST
|
13 |
4 - DATA0 Behavior specific Data
|
14 |
5 - DATA1
|
15 |
6 - DATA2
|
16 |
7 - ROW[0]
|
17 |
8 - ROW[1]
|
18 |
9 - ROW[2]
|
19 |
10 - ROW[3] make sure that you can fit MAX_ROBOTS bytes
|
20 |
11 - ROW[4]
|
21 |
12 - ROW[5]
|
22 |
13 - ROW[6]
|
23 |
14 - NUM_BOTS
|
24 |
15 - CHK
|
25 |
*/
|
26 |
|
27 |
#define WL_PKT_LEN 16 //0...15 |
28 |
|
29 |
#define WL_SRC_LOC 2 //SRC |
30 |
#define WL_DEST_LOC 3 //DEST |
31 |
|
32 |
#define WL_DATA_DATA0 4 //Behavior Specific Data |
33 |
#define WL_DATA_DATA1 5 |
34 |
#define WL_DATA_DATA2 6 |
35 |
|
36 |
#define WL_DATA_ROW_START 7 //start of sensor row (ROW[0]) |
37 |
#define WL_DATA_ROW_END 13 //end (ROW[6] for now) |
38 |
|
39 |
//start of wireless data -- not necessarily anything in particular
|
40 |
#define WL_DATA_START 4 |
41 |
#define WL_DATA_END 13 |
42 |
|
43 |
#define NUM_BOTS_LOC 14 //location of number of robots - sent in every packet |
44 |
#define WL_CHK_LOC 15 //check sum, negative of the sum of the rest of the |
45 |
|
46 |
#define WL_TIMEOUT 4 |
47 |
#define WL_TO_INITIAL 4 |
48 |
#define WL_TO_LEADER 2 |
49 |
#define WL_TO_DEATH 5 |
50 |
//if a robot times out WL_TO_DEATH times, it will be considered dead
|
51 |
|
52 |
#define LAST_ROBOT_DELAY 10 |
53 |
#define WL_DELAY_BOM_PRE 100 |
54 |
//How much to delay between turning on BOM and sending a packet
|
55 |
|
56 |
#define WL_DELAY_BOM_POST 100 |
57 |
//How much to delay between completing a packet send and turning off BOM
|
58 |
|
59 |
#define WL_PKT_ERROR 255 |
60 |
#define WL_ERROR_LOC 4 |
61 |
|
62 |
//error codes
|
63 |
#define WL_ERRCODE_ROBOTDEATH 123 //For timeouts |
64 |
#define WL_ERRCODE_NEEDTOCHARGE 250 //For pinging charging station |
65 |
#define WL_ERRCODE_CHARGESTATION 251 //Charging station response to ping |
66 |
#define WL_ERR_DEAD_LOC 5 |
67 |
|
68 |
char wl_buf[WL_PKT_LEN];
|
69 |
int wl_csloc; //Stores where the last seen Charging Station was relative to you |
70 |
char wl_input;
|
71 |
unsigned int wl_index; |
72 |
unsigned char wl_chksum; |
73 |
|
74 |
unsigned char wl_to_flag; |
75 |
//Throws 1 if the time since last packet crosses a threshhold
|
76 |
|
77 |
unsigned int wl_to_count; |
78 |
//Counts up for every time unit that you do not recieve
|
79 |
|
80 |
unsigned int PREV; //Who's before you in the ring |
81 |
unsigned int SRC; //Your ID in the ring |
82 |
unsigned int DEST; //Who's after you in the ring |
83 |
unsigned int NUM_BOTS; //How many robots are in the ring |
84 |
|
85 |
unsigned int CHARGESTATION; //0 If robot, 1 if Charging Station |
86 |
|
87 |
unsigned int wl_to_max; //Timeout maximum (threshold) |
88 |
|
89 |
//Counts how many times the robot before you times out
|
90 |
unsigned int wl_to_death_count; |
91 |
unsigned char wl_to_death_flag; //If the one before you times out too much |
92 |
|
93 |
char first_time;
|
94 |
char wl_wait_for_turn;
|
95 |
|
96 |
/* Functions */
|
97 |
void bom_test(void); |
98 |
void wl_adhoc(void); |
99 |
|
100 |
void wl_init(void); |
101 |
|
102 |
void wl_send(void); |
103 |
void parse_buffer(void); |
104 |
void wl_timeout_handler(void); |
105 |
|
106 |
//Prints out debug information
|
107 |
void display_debug(void); |
108 |
|
109 |
//Removes Dead robot from network
|
110 |
void wl_death_handler( void ); |
111 |
//Chooses an error and deals with it
|
112 |
void wl_error_handler(unsigned char ecode); |
113 |
|
114 |
//Generic Packet
|
115 |
void wl_create_packet(void); |
116 |
//Data Packet
|
117 |
void wl_create_data_packet(unsigned char d0, unsigned char d1, |
118 |
unsigned char d2); |
119 |
|
120 |
//Generic Error Packet
|
121 |
void wl_create_error_packet(unsigned char errcode); |
122 |
//Compute the checksum and stores it for a packet
|
123 |
void wl_make_checksum( void); |
124 |
|
125 |
#endif
|