Project

General

Profile

Revision 161

formatting stuff

View differences:

trunk/code/projects/colonet/ColonetServer/Command.cpp
10 10
 *       and sends it to the appropriate client
11 11
 */
12 12

  
13
#include <colonet_wireless.h>
14 13
#include <ctype.h>
15 14
#include <stdio.h>
16 15
#include <stdlib.h>
17 16
#include <string.h>
18 17

  
18
#include <colonet_wireless.h>
19

  
19 20
#include "includes/Command.h"
20 21
#include "includes/ConnectionPool.h"
21 22

  
......
117 118
}
118 119

  
119 120

  
120
/** 
121
/**
121 122
 * @brief checks a list of tokens to see if it's valid
122 123
 *
123 124
 * @param tokens The tokens to check
......
135 136
    /* Not enough tokens */
136 137
    return -1;
137 138
  }
138
  
139

  
139 140
  if (tokens[1] != COLONET_REQUEST && tokens[1] != COLONET_COMMAND) {
140 141
    /* Invalid message type */
141 142
    return -1;
......
152 153

  
153 154
  memset(arguments, 1, PACKET_DATA_LEN);
154 155

  
155
  // Convert tokens to ints 
156
  // Convert tokens to ints
156 157
  for (i = ROBOT_COMMAND_OFFSET; i < number_int_tokens; i++) {
157 158
    int_tokens[i-ROBOT_COMMAND_OFFSET] = atoi(tokens[i]);
158 159
  }
159 160

  
160
  // Fill arguments buffer with arguments 
161
  // Fill arguments buffer with arguments
161 162
  for (i = ROBOT_COMMAND_LEN; i < number_int_tokens-ROBOT_COMMAND_OFFSET; i++) {
162 163
    arguments[i-ROBOT_COMMAND_LEN] = int_tokens[i];
163 164
  }
164 165

  
165
  // Check the tokens 
166
  // Check the tokens
166 167
  if (check_tokens(int_tokens, number_int_tokens) < 0) {
167 168
    fprintf(stderr, "%s: Error - Invalid robot command/request.\n", __FUNCTION__);
168 169
    return -1;
169 170
  }
170 171

  
171
  // Send packet to robot 
172
  // Send packet to robot
172 173
  fprintf(stderr, "Calling colonet_wl_send(%d, %d, %d, arguments)\n", int_tokens[0], int_tokens[1], int_tokens[2]);
173 174
  colonet_wl_send(pool_index, int_tokens[0], (ColonetMessageType)int_tokens[1], int_tokens[2], arguments);
174 175

  
......
193 194
    printf("There was an error converting second token into a number.\n");
194 195
    return -1;
195 196
  }
196
    
197

  
197 198
  if (second_token == REQUEST_BOM_MATRIX) {
198 199
    if (parse_request_bom_matrix(pool_index)) {
199 200
      return -1;
......
214 215
int Command::parse_request_bom_matrix(int pool_index) {
215 216
  char response_bom_matrix_buffer[MAX_RESPONSE_LEN];
216 217
  char temp_bom_matrix_buffer[MAX_RESPONSE_LEN];
217
 
218

  
218 219
  if (!connection_pool) {
219 220
    return -1;
220 221
  }
......
238 239
      bom_matrix[ii][j] = ((ii*3+j)%17)-1;
239 240
    }
240 241
  }
241
  
242 242

  
243

  
243 244
  printf("number of robots is %d\n", number_robots);
244 245

  
245 246
  //TODO: make this better
......
270 271

  
271 272
  char xbee_id_buffer[MAX_RESPONSE_LEN];
272 273
  char temp_xbee_id_buffer[MAX_RESPONSE_LEN];
273
      
274

  
274 275
  if (!connection_pool) {
275 276
    return -1;
276 277
  }
277 278

  
278 279
  snprintf(xbee_id_buffer, MAX_RESPONSE_LEN, "%d %d %d", RESPONSE_TO_CLIENT_REQUEST, REQUEST_XBEE_IDS, number_robots);
279
      
280

  
280 281
  printf("number of robots is %d\n", number_robots);
281 282

  
282 283
  for (int ii = 0; ii < number_robots; ii++) {
trunk/code/projects/colonet/ColonetServer/Log.cpp
2 2
 * @file Log.cpp
3 3
 *
4 4
 * @brief This file contains the code to do logging for Colonet
5
 * 
5
 *
6 6
 * @author Jason Knichel
7 7
 *
8 8
 */
......
52 52
struct tm Log::get_current_time() {
53 53
  struct tm current_time;
54 54
  memset(&current_time, 0, sizeof(struct tm));
55
  
55

  
56 56
  time_t t = time(NULL);
57 57
  localtime_r(&t, &current_time);
58
  
59
  return current_time;  
58

  
59
  return current_time;
60 60
}
61 61

  
62 62
/**
......
77 77
    fprintf(stderr, "Tried to log a null message.\n");
78 78
    return -1;
79 79
  }
80
  
80

  
81 81
  static char * start_log = "Starting Log";
82 82
  static char * connect = "Client Connecting";
83 83
  static char * disconnect = "Client Disconnecting";
......
108 108
  }
109 109

  
110 110
  struct tm current_time = get_current_time();
111
  
111

  
112 112
  char buffer[LOG_MAX_TIME_LENGTH];
113 113
  asctime_r(&current_time, buffer);
114 114
  int len = strlen(buffer);
......
134 134
 * @brief An easier way to log a normal message
135 135
 *
136 136
 * @param message The message to log as a normal message
137
 * 
137
 *
138 138
 * @return 0 on success, negative error code on error
139 139
 */
140 140
int Log::log_message(char *  message) {
trunk/code/projects/colonet/ColonetServer/ConnectionPool.cpp
17 17
#include "includes/ConnectionPool.h"
18 18
#include "includes/Command.h"
19 19
#include "../lib/colonet_defs.h"
20

  
20 21
#include <colonet_wireless.h>
21 22

  
22 23
/**
......
291 292

  
292 293
    while ((newline_position = strstr(read_buffer[pool_index], "\n"))) {
293 294

  
294
      //if no newline if found in the entire readbuffer (when its full), 
295
      //if no newline if found in the entire readbuffer (when its full),
295 296
      //toss out the command
296 297
      // because either the command being given is too long or someone is trying
297 298
      // to do something bad to the server
......
350 351

  
351 352
  int sent = write(client_file_descriptor, write_buffer[pool_index], write_buffer_size[pool_index]);
352 353
  memmove(write_buffer[pool_index], write_buffer[pool_index]+sent, WRITE_BUFFER_SIZE - sent);
353
  write_buffer_size[pool_index] -= sent;  
354
  write_buffer_size[pool_index] -= sent;
354 355

  
355 356
  return 0;
356 357
}
trunk/code/projects/colonet/ColonetServer/ColonetServer.cpp
1
/** 
1
/**
2 2
 * @file ColonetServer.cpp
3 3
 *
4 4
 * @brief colonet_server - primary server application for Colonet
......
117 117
      }
118 118

  
119 119
      char log_buffer[LOG_BUFFER_LENGTH];
120
      snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s attempting to connect.", 
120
      snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s attempting to connect.",
121 121
	       inet_ntoa(client_addr.sin_addr));
122 122
      logger.log_string(LOG_TYPE_CONNECT, log_buffer);
123 123

  
......
126 126
	continue;
127 127
      }
128 128

  
129
      snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s successfully added to connection pool.", 
129
      snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s successfully added to connection pool.",
130 130
	       inet_ntoa(client_addr.sin_addr));
131 131
      logger.log_string(LOG_TYPE_CONNECT, log_buffer);
132 132
    }
......
146 146
    printf("response\n");
147 147

  
148 148
    char buffer[WRITE_BUFFER_SIZE];
149
          
149

  
150 150
    int value = (int)(data[0]);
151 151
    snprintf(buffer, WRITE_BUFFER_SIZE, "%d\n", value);
152
          
152

  
153 153
    int buflen = strlen(buffer);
154 154
    if (connection_pool.write_to_client(dest, buffer, buflen)
155 155
        == ERROR_INVALID_CLIENT_ID) {
......
180 180
    log_filename = optionsG.log_filename;
181 181
  }
182 182

  
183
  /*
184
    colonet_wl_init(optionsG.wireless_port, wirelessMessageHandler,
185
    log_filename);
183
  colonet_wl_init(optionsG.wireless_port, wirelessMessageHandler,
184
                  log_filename);
186 185

  
187
    if (!colonet_wl_run_listener_thread()) {
186
  if (!colonet_wl_run_listener_thread()) {
188 187
    fprintf(stderr, "%s: colonet_wl_run_listener_thread failed.\n",
189
    __FUNCTION__);
188
            __FUNCTION__);
190 189
    return -1;
191
    }
192
  */
190
  }
193 191

  
194 192
  return 0;
195 193
}
......
202 200
 * @return 0 on success, negative error code on error
203 201
 */
204 202
int ColonetServer::initialize_connection(int port) {
205
  printf("Initializing connection that will be used to listen for " 
203
  printf("Initializing connection that will be used to listen for "
206 204
         "clients...\n");
207 205
  int options = 1;
208 206
  struct sockaddr_in my_address;
......
218 216
  my_address.sin_family = AF_INET;
219 217
  my_address.sin_addr.s_addr = htonl(INADDR_ANY);
220 218
  my_address.sin_port = htons(port);
221
  
219

  
222 220
  setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, &options, sizeof(options));
223 221

  
224 222
  //get the current socket options
......
233 231
    printf("\tThere was an error setting the socket to be non blocking.\n");
234 232
    return -1;
235 233
  }
236
  
234

  
237 235
  //bind the socket to listen on the specified port
238 236
  if (bind(listen_socket, (struct sockaddr *) &my_address, sizeof(my_address)) < 0) {
239 237
    printf("\tThere was an error binding the socket\n");
240 238
    return -1;
241 239
  }
242
  
240

  
243 241
  return 0;
244 242
}
245 243

  
......
263 261
  if (colonet_server.start_listening() < 0) {
264 262
    return -1;
265 263
  }
266
  
264

  
267 265
  colonet_server.run_server();
268 266

  
269 267
  return 0;
trunk/code/projects/colonet/ColonetServer/Makefile
43 43
	@echo "---finish compilation---"
44 44

  
45 45
clean: 
46
	rm -rf *.o ColonetServer
46
	rm -rf *.o ColonetServer *~

Also available in: Unified diff