Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / colonet / utilities / robot_slave / wl_adhoc.h @ 13

History | View | Annotate | Download (4.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 2
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_COLONET_PACKET 254
60
#define WL_PKT_ERROR 255
61
#define WL_ERROR_LOC 4
62

    
63
//parse buffer flag
64
#define NOT_REQUEST_CS 0
65
#define REQUEST_CS 1
66
#define DEPART_CS 2
67
#define ARRIVE_CS 3
68

    
69

    
70
//error codes
71
#define WL_ERRCODE_ROBOTDEATH 123     //For timeouts
72
#define WL_ERRCODE_NEEDTOCHARGE 250   //For pinging charging station
73
#define WL_ERRCODE_CHARGE_ACCEPT 251  //Charging station response to ping
74
#define WL_ERRCODE_CHARGE_DENY 252                //For if charging station is already in use
75
#define WL_ERRCODE_CHARGE_DOCK 253                //Robot announces docking (battery charging) status to charging station
76
#define WL_ERRCODE_CHARGE_DEPART 254        //Robot announces departing (battery full) status to charging station
77
#define WL_ERR_DEAD_LOC 5
78

    
79
char wl_buf[WL_PKT_LEN];
80
int wl_csloc; //Stores where the last seen Charging Station was relative to you
81
volatile char wl_input;
82
unsigned int wl_index;
83
unsigned char wl_chksum;
84

    
85
unsigned char wl_to_flag;
86
//Throws 1 if the time since last packet crosses a threshhold
87

    
88
int wl_sent_cs;
89
int wl_sent_depart;
90
int wl_sent_dock;
91

    
92
int wl_cs_flag;
93

    
94
//direction from charging station in bom reading
95
char direction_from_station;
96
//desired bay in charging station in bom reading
97
char desired_bay;
98

    
99
unsigned int wl_to_count;
100
//Counts up for every time unit that you do not recieve 
101

    
102
unsigned int PREV;            //Who's before you in the ring
103
unsigned int SRC;             //Your ID in the ring
104
unsigned int DEST;            //Who's after you in the ring
105
unsigned int NUM_BOTS;        //How many robots are in the ring
106

    
107
unsigned int CHARGESTATION;     //0 If robot, 1 if Charging Station
108

    
109
unsigned int wl_to_max;         //Timeout maximum (threshold)
110

    
111
//Counts how many times the robot before you times out
112
unsigned int wl_to_death_count;
113
unsigned char wl_to_death_flag;   //If the one before you times out too much
114

    
115
char first_time;
116
char wl_wait_for_turn;
117

    
118

    
119
#define CHARGE_REQUEST_NO_REPLY 0
120
#define CHARGE_REQUEST_ACCEPTED 1
121
#define CHARGE_REQUEST_NOT_ACCEPTED 2
122
char charge_request_register;        //@bit 0: charge_accepted, @bit 1 charge_not_accepted.
123

    
124

    
125
/* Functions */
126
void bom_test(void);
127
void wl_adhoc(void);
128

    
129
void wl_init(void);
130

    
131
void wl_send(void);
132
void parse_buffer(void);
133
void wl_timeout_handler(void);
134

    
135
//Prints out debug information
136
void display_debug(void);
137
void display_debug_usb(void);
138

    
139
//Removes Dead robot from network
140
void wl_death_handler( void );
141
//Chooses an error and deals with it
142
void wl_error_handler(unsigned char ecode);
143

    
144
//Generic Packet
145
void wl_create_packet(void);
146
//Data Packet
147
void wl_create_data_packet(unsigned char d0, unsigned char d1, 
148
                           unsigned char d2);
149
                           
150
void wl_create_charging_error_packet(void);
151
void wl_create_leaving_packet(void);
152
void wl_create_docking_packet(void);
153

    
154
//Generic Error Packet
155
void wl_create_error_packet(unsigned char errcode);
156
//Compute the checksum and stores it for a packet
157
void wl_make_checksum( void );
158

    
159
#endif