Revision 118
updated server for new wl library changes
trunk/code/projects/colonet/ColonetServer/client.cpp | ||
---|---|---|
24 | 24 |
|
25 | 25 |
|
26 | 26 |
/* Public functions */ |
27 |
int wirelessMessageHandler(ColonetPacket* pkt) |
|
28 |
{ |
|
29 |
printf("Received wireless message!!!\n"); |
|
30 |
if (!pkt) { |
|
31 |
printf("The packet pointer was null.\n"); |
|
32 |
return -1; |
|
33 |
} |
|
27 |
int wirelessMessageHandler(unsigned char type, short source, int dest, |
|
28 |
unsigned char* data, int len) { |
|
29 |
printf("Server received wireless message!!!\n"); |
|
34 | 30 |
|
35 |
if ((int)pkt->msg_type == COLONET_RESPONSE) {
|
|
31 |
if (type == COLONET_RESPONSE) { |
|
36 | 32 |
printf("response\n"); |
37 | 33 |
|
38 |
int dest = (int)(pkt->msg_dest); |
|
39 | 34 |
char buffer[WRITE_BUFFER_SIZE]; |
40 | 35 |
|
41 |
int value = (int)(pkt->data[0]);
|
|
36 |
int value = (int)(data[0]); |
|
42 | 37 |
snprintf(buffer, WRITE_BUFFER_SIZE, "%d\n", value); |
43 | 38 |
|
44 |
int len = strlen(buffer); |
|
45 |
if (connection_pool->write_to_client(dest, buffer, len) == ERROR_INVALID_CLIENT_ID) { |
|
46 |
printf("The robot wanted to pass the data to a client not in the pool.\n"); |
|
39 |
int buflen = strlen(buffer); |
|
40 |
if (connection_pool->write_to_client(dest, buffer, buflen) |
|
41 |
== ERROR_INVALID_CLIENT_ID) { |
|
42 |
printf("The robot wanted to pass the data to a client not in the " |
|
43 |
"pool.\n"); |
|
47 | 44 |
return -1; |
48 | 45 |
} |
49 | 46 |
|
... | ... | |
52 | 49 |
printf("not a response\n"); |
53 | 50 |
} |
54 | 51 |
|
55 |
pkt = 0; |
|
56 | 52 |
return 0; |
57 | 53 |
} |
trunk/code/projects/colonet/ColonetServer/includes/ConnectionPool.h | ||
---|---|---|
37 | 37 |
|
38 | 38 |
int add_client(int client_file_descriptor); |
39 | 39 |
int remove_client(int pool_index); |
40 |
int check_clients(ColonetWireless * wireless);
|
|
40 |
int check_clients(); |
|
41 | 41 |
int write_to_client(int pool_index, char * message, int length); |
42 | 42 |
void set_listen_socket_in_ready_set(int listen_socket); |
43 | 43 |
int perform_select(int listen_socket); |
... | ... | |
74 | 74 |
char * write_buffer[MAX_CONNECTIONS]; |
75 | 75 |
int write_buffer_size[MAX_CONNECTIONS]; |
76 | 76 |
|
77 |
int parse_command(char* command, int pool_index, ColonetWireless * wireless);
|
|
77 |
int parse_command(char* command, int pool_index); |
|
78 | 78 |
int tokenize_command(char* command, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE]); |
79 | 79 |
int check_tokens(unsigned char* tokens, int number_tokens); |
80 | 80 |
}; |
trunk/code/projects/colonet/ColonetServer/includes/ColonetServer.h | ||
---|---|---|
6 | 6 |
#ifndef COLONETSERVER_H |
7 | 7 |
#define COLONETSERVER_H |
8 | 8 |
|
9 |
#include <colonet_wireless.h> |
|
10 | 9 |
#include "ConnectionPool.h" |
11 | 10 |
#include "Log.h" |
12 | 11 |
|
... | ... | |
28 | 27 |
private: |
29 | 28 |
ConnectionPool connection_pool; |
30 | 29 |
Log logger; |
31 |
ColonetWireless* wireless; |
|
32 | 30 |
int listen_socket; |
33 | 31 |
|
34 | 32 |
int initialize_wireless(); |
trunk/code/projects/colonet/ColonetServer/includes/client.h | ||
---|---|---|
9 | 9 |
|
10 | 10 |
#include <colonet_wireless.h> |
11 | 11 |
|
12 |
int wirelessMessageHandler(ColonetPacket* pkt);
|
|
12 |
int wirelessMessageHandler(unsigned char* pkt, int len);
|
|
13 | 13 |
int initWireless(void); |
14 |
void send_wireless_message(unsigned char msg_dest, unsigned char msg_type,
|
|
15 |
unsigned char msg_code, unsigned char* data);
|
|
14 |
int wirelessMessageHandler(unsigned char type, short source, int dest,
|
|
15 |
unsigned char* data, int len);
|
|
16 | 16 |
|
17 | 17 |
#endif |
trunk/code/projects/colonet/ColonetServer/ConnectionPool.cpp | ||
---|---|---|
16 | 16 |
#include "includes/ConnectionPool.h" |
17 | 17 |
#include "includes/client.h" |
18 | 18 |
#include "../lib/colonet_defs.h" |
19 |
#include <colonet_wireless.h> |
|
19 | 20 |
|
20 | 21 |
/** |
21 | 22 |
* @brief The default constructor for ConnectionPool |
... | ... | |
139 | 140 |
* Sees is any clients are ready to read from their file descriptor or are |
140 | 141 |
* ready to write to their file descriptor. |
141 | 142 |
* |
142 |
* @param wireless A pointer to the wireless object |
|
143 |
* |
|
144 | 143 |
* @return 0 on success, negative error code on error |
145 | 144 |
*/ |
146 | 145 |
//TODO: test that it drops commands properly if it gets sent too much data |
147 | 146 |
// do we want it to drop the data or drop the connection? |
148 |
int ConnectionPool::check_clients(ColonetWireless * wireless) {
|
|
147 |
int ConnectionPool::check_clients() { |
|
149 | 148 |
char temporary_buffer[READ_BUFFER_SIZE]; |
150 | 149 |
char temporary_command_buffer[READ_BUFFER_SIZE+1]; |
151 | 150 |
int i; |
... | ... | |
228 | 227 |
break; |
229 | 228 |
} |
230 | 229 |
|
231 |
if (parse_command(temporary_command_buffer, i, wireless) < 0) {
|
|
230 |
if (parse_command(temporary_command_buffer, i) < 0) { |
|
232 | 231 |
printf("There was an error parsing command\n"); |
233 | 232 |
break; |
234 | 233 |
} |
... | ... | |
376 | 375 |
} |
377 | 376 |
|
378 | 377 |
//TODO: write a function to write data into the write buffers (jason: what was this referring to?) |
379 |
int ConnectionPool::parse_command(char* command, int pool_index, ColonetWireless * wireless) {
|
|
378 |
int ConnectionPool::parse_command(char* command, int pool_index) { |
|
380 | 379 |
char tokens[MAX_TOKENS][MAX_TOKEN_SIZE]; |
381 | 380 |
unsigned char int_tokens[MAX_TOKENS]; |
382 | 381 |
int number_tokens = 0; |
... | ... | |
435 | 434 |
*/ |
436 | 435 |
|
437 | 436 |
// Fill arguments buffer with arguments |
438 |
for (i = ROBOT_COMMAND_LEN; i < number_int_tokens-ROBOT_COMMAND_OFFSET; i++) { |
|
437 |
for (i = ROBOT_COMMAND_LEN; i < number_int_tokens-ROBOT_COMMAND_OFFSET; |
|
438 |
i++) { |
|
439 | 439 |
arguments[i-ROBOT_COMMAND_LEN] = int_tokens[i]; |
440 | 440 |
} |
441 | 441 |
|
... | ... | |
446 | 446 |
} |
447 | 447 |
|
448 | 448 |
// Send packet to robot |
449 |
fprintf(stderr, "Calling wireless->send(%d, %d, %d, arguments)\n",
|
|
449 |
fprintf(stderr, "Calling colonet_wl_send(%d, %d, %d, arguments)\n",
|
|
450 | 450 |
int_tokens[0], int_tokens[1], int_tokens[2]); |
451 |
wireless->send(int_tokens[0], int_tokens[1], int_tokens[2], arguments); |
|
451 |
colonet_wl_send(pool_index, int_tokens[0], |
|
452 |
(ColonetMessageType)int_tokens[1], int_tokens[2], |
|
453 |
arguments); |
|
452 | 454 |
} else if (command_id == REQUEST_FROM_SERVER) { |
453 | 455 |
if (number_tokens < 2) |
454 | 456 |
return -1; |
trunk/code/projects/colonet/ColonetServer/ColonetServer.cpp | ||
---|---|---|
8 | 8 |
* @date 10/31/06 |
9 | 9 |
*/ |
10 | 10 |
|
11 |
#include <colonet_wireless.h> |
|
11 |
#include <arpa/inet.h> |
|
12 |
#include <fcntl.h> |
|
13 |
#include <errno.h> |
|
14 |
#include <netinet/in.h> |
|
15 |
#include <string.h> |
|
12 | 16 |
#include <sys/select.h> |
13 | 17 |
#include <sys/socket.h> |
14 |
#include <netinet/in.h> |
|
15 |
#include <errno.h> |
|
16 |
#include <arpa/inet.h> |
|
17 | 18 |
|
18 |
#include <fcntl.h> |
|
19 |
|
|
20 | 19 |
#include <colonet_wireless.h> |
21 | 20 |
|
22 | 21 |
#include "includes/ColonetServer.h" |
... | ... | |
149 | 148 |
logger.logMessage(LOG_TYPE_CONNECT, log_buffer); |
150 | 149 |
} |
151 | 150 |
|
152 |
if (connection_pool.check_clients(wireless) < 0) {
|
|
151 |
if (connection_pool.check_clients() < 0) { |
|
153 | 152 |
printf("\tThere was an error trying to update the clients."); |
154 | 153 |
continue; |
155 | 154 |
} |
... | ... | |
181 | 180 |
log_filename = optionsG.log_filename; |
182 | 181 |
} |
183 | 182 |
|
184 |
wireless = new ColonetWireless(optionsG.wireless_port, |
|
185 |
wirelessMessageHandler, log_filename, |
|
186 |
/*!optionsG.listener_mode*/false, true); |
|
187 |
//Note: last arg set to true ignores token ring; in general, this should |
|
188 |
//probably be false (changed for demo purposes) |
|
183 |
colonet_wl_init(optionsG.wireless_port, wirelessMessageHandler, |
|
184 |
log_filename); |
|
189 | 185 |
|
190 |
if (!wireless->run_listener_thread()) { |
|
186 |
if (!colonet_wl_run_listener_thread()) { |
|
187 |
fprintf(stderr, "%s: colonet_wl_run_listener_thread failed.\n", |
|
188 |
__FUNCTION__); |
|
191 | 189 |
return -1; |
192 | 190 |
} |
193 | 191 |
|
trunk/code/projects/colonet/ColonetServer/Makefile | ||
---|---|---|
12 | 12 |
|
13 | 13 |
VPATH = ../lib:../lib/colonet_wireless |
14 | 14 |
INCLUDE_DIRS = ../lib/colonet_wireless ../lib |
15 |
LIBRARY_DIRS = ../lib |
|
15 |
LIBRARY_DIRS = ../lib ../../libwireless/lib
|
|
16 | 16 |
|
17 | 17 |
|
18 | 18 |
#this takes the include directory and puts a -I in front of each directory name before being used in a gcc statement |
... | ... | |
30 | 30 |
$(CC) $(CFLAGS) -c $(COLONETFILES) $(INCLUDE_DIRS_FOR_GCC) |
31 | 31 |
$(CC) $(CFLAGS) -c $(COLONETCPPFILES) $(INCLUDE_DIRS_FOR_GCC) |
32 | 32 |
$(CC) $(CFLAGS) -c $(LOGGINGFILES) $(INCLUDE_DIRS_FOR_GCC) |
33 |
$(CC) $(CFLAGS) $(COLONETOBJECTS) $(COLONETCPPOBJECTS) $(LOGGINGOBJECTS) $(LIBRARY_DIRS_FOR_GCC) -lpthread -lcolonet_wireless $(INCLUDE_DIRS_FOR_GCC) -o $@
|
|
33 |
$(CC) $(CFLAGS) $(COLONETOBJECTS) $(COLONETCPPOBJECTS) $(LOGGINGOBJECTS) $(LIBRARY_DIRS_FOR_GCC) -lpthread -lcolonet_wireless $(INCLUDE_DIRS_FOR_GCC) -lwireless -o $@
|
|
34 | 34 |
|
35 | 35 |
clean: |
36 | 36 |
rm -rf *.o ColonetServer |
Also available in: Unified diff