Project

General

Profile

Revision 392

moved colonet_wireless into the colonet server

View differences:

trunk/code/projects/colonet/lib/colonet_wireless/tests/colonet_wireless_test.cpp
1
/* Eugene Marinelli
2
 * 11/2/06
3
 *
4
 * colonet_wireless_test - tests the colonet_wireless library
5
 */
6

  
7
#include <iostream>
8
#include <signal.h>
9

  
10
#include "colonet_wireless.h"
11

  
12
int msg_handler(ColonetPacket* pkt)
13
{
14
  printf("Handler!\n");
15

  
16
  fprintf(stderr, 
17
          "token_src:%d\n"
18
          "token_dest:%d\n"
19
          "msg_dest:%d\n"
20
          "msg_type:%d\n"
21
          "msg_code:%d\n"
22
          "num_robots:%d\n",
23
          pkt->token_src, pkt->token_dest, pkt->msg_dest, pkt->msg_type,
24
          pkt->msg_code, pkt->num_robots);
25
  
26
  printf("data: ");
27

  
28
  for(int i = 0; i < PACKET_DATA_LEN; i++){
29
    printf("%d ", pkt->data[i]);
30
  }
31
  
32
  printf("\n\n");
33

  
34
  return 0;
35
}
36

  
37
int main()
38
{
39
  ColonetWireless* cw = new ColonetWireless(SERIAL_PORT, msg_handler, NULL, 
40
                                            true, false);
41

  
42
  /*
43
  unsigned char orbdata[3] = {0xFF, 0xFF, 0xFF};
44
  unsigned char motordata[4] = {0, 1, 0, 0xFF};
45
  unsigned char motordata2[4] = {0, 0, 0, 0xFF};
46
  unsigned char buzzerdata[5] = {0x01};
47
  */
48

  
49
  unsigned char data[10];
50
  unsigned char msgcode;
51

  
52
  //cw->send(GLOBAL_DEST, 0, 0, "eugene");
53

  
54
  //cw->send(GLOBAL_DEST, COLONET_COMMAND, ORB_SET, orbdata);
55
  //cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTOR1_SET, motordata);
56

  
57
  //cw->send(GLOBAL_DEST, COLONET_COMMAND, BUZZER_INIT, (unsigned char*)"");
58
  //cw->send(GLOBAL_DEST, COLONET_COMMAND, BUZZER_SET_VAL, buzzerdata);
59

  
60
  cw->run_listener_thread();
61

  
62
  printf("spawned thread\n");
63

  
64
  while(1){
65
    printf("Code: ");
66
    scanf("%x", (int*)&msgcode);
67

  
68
    for (int i = 0; i < 5; i++) {
69
      printf("Byte %d: ", i);
70
      scanf("%x", (int*)&(data[i]));
71
    }
72

  
73
    cw->send(GLOBAL_DEST, COLONET_COMMAND, msgcode, data);
74

  
75
    /*
76
    cw->send(GLOBAL_DEST, COLONET_COMMAND, ORB_SET, orbdata);
77
    cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTOR1_SET, motordata);
78
    cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTOR2_SET, motordata2);
79

  
80
    sleep(3);
81
    */
82
  }
83

  
84
  return 0;
85
}
trunk/code/projects/colonet/lib/colonet_wireless/tests/colonet_wireless_test2.cpp
1
/** @file colonet_wireless_test2.cpp
2
 * @brief colonet_wireless_test2 - tests the colonet_wireless library with
3
 * manual control.
4
 *
5
 * @author Eugene Marinelli
6
 * @date 2/5/06
7
 */
8

  
9
#include <iostream>
10
#include <signal.h>
11
#include <fcntl.h>
12
#include <signal.h>
13

  
14
#include "colonet_wireless.h"
15
#include "colonet_defs.h"
16

  
17
ColonetWireless* cw;
18

  
19
int msg_handler(ColonetPacket* pkt)
20
{
21
  printf("Handler!\n");
22
  return 0;
23
}
24

  
25
char get_mouse()
26
{
27
  int fd;
28
  char buf[10];
29

  
30
  fd = open("/dev/input/mouse0", O_RDONLY);
31

  
32
  read(fd, buf, 1);
33

  
34
  close(fd);
35

  
36
  return buf[0];
37
}
38

  
39
void exit_handler(int sig)
40
{
41
  unsigned char data[10];
42

  
43
  printf("Sending kill packet...\n");
44
  cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTORS_OFF, data);
45

  
46
  printf("Exiting...\n");
47

  
48
  sleep(2);
49
  exit(0);
50
}
51

  
52
int main()
53
{
54
  unsigned char data[10];
55
  char dir;
56
  int paused = 0;
57

  
58
  unsigned char motor_back_args[6] = {0, 0, 0, 0xFF, 0};
59
  unsigned char motor_forward_args[6] = {0, 1, 0, 0xFF, 0};
60

  
61
  cw = new ColonetWireless(SERIAL_PORT, msg_handler, NULL, true, true);
62

  
63
  signal(SIGINT, exit_handler);
64

  
65
  cw->run_listener_thread();
66

  
67
  while(1){
68
    dir = get_mouse();
69

  
70
    usleep(300000);
71

  
72
    printf("%d\n", dir);
73

  
74
    switch (dir) {
75
    case 40:
76
      /* Forward */
77
      cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTOR1_SET, motor_forward_args);
78
      cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTOR2_SET, motor_forward_args);
79
      break;
80
    case 8:
81
      /* Back */
82
      cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTOR1_SET, motor_back_args);
83
      cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTOR2_SET, motor_back_args);
84
      break;
85
    case 24:
86
      /* Left */
87
      //cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTORS_OFF, data);
88
      cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTOR1_SET, motor_forward_args);
89
      break;
90
    case 56:
91
      /* Right */
92
      //cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTORS_OFF, data);
93
      cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTOR2_SET, motor_forward_args);
94
      break;
95
    case 9:
96
      /* Left click */
97
      /* Stop */
98
      cw->clear_message_queue();
99
      cw->send(GLOBAL_DEST, COLONET_COMMAND, MOTORS_OFF, data);
100
      break;
101
    case 10:
102
      /* Right click */
103
      /* Execute first user-defined function */
104
      cw->send(GLOBAL_DEST, COLONET_COMMAND, 0xF0, data);
105
      break;
106
    }
107
  }
108

  
109
  return 0;
110
}
trunk/code/projects/colonet/lib/colonet_wireless/colonet_wireless_legacy.cpp
1
/** @file colonet_wireless.cpp 
2
 *
3
 * @brief Implementation of server-side colonet wireless library
4
 *
5
 * @author Eugene Marinelli
6
 *
7
 * @bug Only reads when gtkterm is open
8
 * @bug Fails to tokenize
9
 * @bug Deconstructor not implemented
10
 * @bug Nonsense initializations in constructor
11
 */
12

  
13
/********************************* Includes **********************************/
14
#include <string>
15
#include <pthread.h>
16
#include <iostream>
17
#include <fstream>
18
#include <unistd.h>
19
#include <fcntl.h>
20
#include "colonet_wireless.h"
21

  
22
/******************************* Definitions *********************************/
23
#define TIMEOUT_MAX 100
24
#define WL_SEND_DELAY 5 //microseconds
25

  
26
//for debug printouts
27
#define DEBUG 1
28

  
29
#ifdef DEBUG
30
#define dbg_printf(...) printf(__VA_ARGS__)
31
#define dbg_fprintf(...) fprintf(__VA_ARGS__)
32
#else
33
#define dbg_printf(...)
34
#define dbg_fprintf(...)
35
#endif
36

  
37
typedef struct {
38
  MsgHandlerFunction handler;
39
  ColonetWireless* cw;
40
} ListenerArgs;
41

  
42
/************************* Internal prototypes *******************************/
43
static void* listen(void* args);
44

  
45
/**************************** Public functions *******************************/
46
ColonetWireless::ColonetWireless(char* wl_port, 
47
                                 MsgHandlerFunction message_handler_, 
48
                                 char* log_filename_, bool join_token_ring_,
49
                                 bool ignore_token_)
50
{
51
  have_token = false;
52
  first_packet_sent = false;
53

  
54
  //FIX THESE INITIALIZATIONS
55
  token_src = 255;
56
  token_dest = 255;
57
  num_robots = 0;
58
  connected = false;
59
  ignore_token = ignore_token_;
60

  
61
  sprintf(wireless_port, wl_port);
62

  
63
  if (log_filename) {
64
    logging_enabled = true;
65
    sprintf(log_filename, log_filename_);
66
  }
67

  
68
  join_token_ring = join_token_ring_;
69

  
70
  message_handler = message_handler_;
71
}
72

  
73
ColonetWireless::~ColonetWireless()
74
{
75
  //kill listener thread
76
  
77

  
78
  //free packets in queues
79
  
80
}
81

  
82
int ColonetWireless::handle_packet(ColonetPacket* pkt)
83
{
84
  if (logging_enabled) {
85
    /* Log the packet */
86
    log_packet(pkt);
87
  }
88

  
89
  /* Update what we know about the network based on the packet */
90
  update_network_props(pkt);
91

  
92
  /* Received a message */
93
  if (message_handler(pkt) < 0) {
94
    fprintf(stderr, "%s: message_handler failed\n", __FUNCTION__);
95
    return -1;
96
  }
97
  
98
  if ((unsigned char) pkt->token_dest == WL_ERROR_DEST) {
99
    /* token_dest is an error - handle it */
100
    if (handle_error(pkt) < 0) {
101
      fprintf(stderr, "%s: handle_error failed\n", __FUNCTION__);
102
      return -1;
103
    }
104
  } else if(join_token_ring && !connected) {
105
    /* We want to join the token ring but we are not connected - join robot 
106
     * network */
107
    dbg_printf("%s: Trying to join robot network...\n", __FUNCTION__);
108

  
109
    if (join_network(pkt) < 0) {
110
      dbg_fprintf(stderr, "%s: join_network failed\n", __FUNCTION__);
111
      return -1;
112
    }
113
  } else {
114

  
115
    if (pkt->token_dest == token_src && join_token_ring && !ignore_token) {
116
      /* Received the token - send queued message(s) */
117
      dbg_printf("%s: token received\n", __FUNCTION__);
118

  
119
      have_token = true;
120
    
121
      if (transmit_queued_message() < 0) {
122
        fprintf(stderr, "%s: transmit_queued_message failed\n", __FUNCTION__);
123
        return -1;
124
      } else {
125
        if (!first_packet_sent) {
126
          dbg_printf("First packet sent.\n");
127
          first_packet_sent = true;
128
        }
129
      }
130
    }
131
  }
132

  
133
  return 0;
134
}
135

  
136
pthread_t* ColonetWireless::run_listener_thread()
137
{
138
  // pthread_t listener_thread;
139

  
140
  pthread_t* listener_thread = (pthread_t*)malloc(sizeof(pthread_t));
141

  
142
  dbg_printf("Spawning listener thread...\n");
143

  
144
  ListenerArgs* args = new ListenerArgs;
145
  args->cw = this;
146

  
147
  if (pthread_create(listener_thread, NULL, listen, args) != 0) {
148
    perror("pthread_create");
149
    return NULL;
150
  }
151

  
152
  return listener_thread;
153
}
154

  
155
int ColonetWireless::send(unsigned char msg_dest, unsigned char msg_type, 
156
                          unsigned char msg_code, unsigned char* data)
157
{
158
  /* Create a new packet it and queue it to be sent */
159
  ColonetPacket* newpkt = create_packet(token_src, token_dest, msg_dest, 
160
                                        msg_type, msg_code, data, num_robots);
161

  
162
  if(newpkt == NULL){
163
    fprintf(stderr, "Error: %s - create_packet failed\n", __FUNCTION__);
164
    return -1;
165
  }
166

  
167
  if (ignore_token) {
168
    send_packet(newpkt);
169
  } else {
170
    outbox.push(newpkt);                
171
  }
172

  
173
  return 0;
174
}
175

  
176
void ColonetWireless::clear_message_queue(void)
177
{
178
  while (!outbox.empty()) {
179
    outbox.pop();
180
  }
181
}
182

  
183
/**************************** Private functions ******************************/
184

  
185
/** @brief Analogous to the "SIGNAL" or "ISR" function on the robots.
186
 * Listens for bytes on the wireless port and constructs packets based on them.
187
 * Not part of the ColonetWireless class since a function pointer must be
188
 * passed in starting the thread that runs it (tricky or impossible if it's 
189
 * a class function).
190
 *
191
 * @param args Pointer to arguments.  Can be safely casted to ListenerArgs type
192
 * @return NULL
193
 */
194
static void* listen(void* args)
195
{
196
  int read_len;
197
  int portfd;
198
  unsigned char inbuf[128];
199
  int no_packet_timeout_count = 0;
200
  ColonetPacket* in_pkt;
201

  
202
  /* Extract arguments from args */
203

  
204
  ColonetWireless* cw = ((ListenerArgs*)args)->cw;
205

  
206
  /* Open connection to wireless port */
207
  if((portfd = open(cw->wireless_port, O_RDWR)) < 0){
208
    perror("open");
209
    pthread_exit(NULL);
210
  }
211

  
212
  /* loop waiting for messages */
213
  while(1){
214
    /* Read in some bytes (blocks until bytes are read) */
215
    read_len = read(portfd, inbuf, 3);
216

  
217
    if(read_len > 0){
218
      /* Read in some bytes - this will always be true if portfd is blocking */
219
      /* parse the packet or part of packet */
220
      in_pkt = cw->build_packet(inbuf, read_len);
221
      
222
      if(in_pkt == NULL){
223
        /* Packet is not ready yet - go back and read some more bytes */
224
        continue;
225
      }else{
226
        /* Packet is complete */
227
        /* close fd so that we can safely write to it in the handler */
228
        close(portfd);
229

  
230
        if (cw->handle_packet(in_pkt)) {
231
          fprintf(stderr, "%s: Error - handle_packet failed\n", __FUNCTION__);
232
        }
233

  
234
        /* reopen wireless port */
235
        if(!(portfd = open(cw->wireless_port, O_RDWR))){
236
          perror("open");
237
          pthread_exit(NULL);
238
        }
239
      }
240
    }else if(read_len == 0){
241
      // Note - this won't actually happen if read blocks
242
      if(no_packet_timeout_count++ > TIMEOUT_MAX){
243
        //Nothing received for a while - try to start a new token ring
244
        dbg_printf("Attempting to start a token ring...\n");
245

  
246
        cw->token_src = 0;
247
        cw->token_dest = 1;
248
        cw->num_robots = 0;
249
  
250
        ColonetPacket* tmp_pkt = cw->create_packet(cw->token_src, 
251
                                                   cw->token_dest, 0, 0, 0, 
252
                                                   (unsigned char*) "",
253
                                                   cw->num_robots);
254
        cw->send_packet(tmp_pkt);
255
        free(tmp_pkt);
256
      }
257
    }else{ //(read_len < 0)
258
      //Error
259
      perror("read");
260
    }
261
  }
262

  
263
  pthread_exit(NULL);
264

  
265
  return NULL;
266
}
267

  
268
/** @brief Takes some number of bytes and tries to build a packet with them
269
 * State of the function is saved between callings, so parts of packets 
270
 * can be provided as available
271
 *
272
 * @param buf Data buffer 
273
 * @param len Number of bytes to build with
274
 */
275
ColonetPacket* ColonetWireless::build_packet(unsigned char* buf, int len)
276
{
277
  static unsigned char packet_buf[PACKET_SIZE];
278
  static int buf_pos = 0;
279

  
280
  /* If this is pointer is returned - will either point to NULL or a complete
281
   * packet */
282
  ColonetPacket* complete_packet = NULL;
283

  
284
  if (buf_pos >= PACKET_SIZE) {
285
    buf_pos = 0;
286
  }
287

  
288
  for (int i = 0; i < len; i++) {
289
    dbg_printf("%d ", buf[i]);
290

  
291
    switch(buf_pos){
292
    case 0: //prefix0
293
      if(buf[i] == 'R'){
294
        memset(packet_buf, 0, PACKET_SIZE);
295
        packet_buf[0] = 'R';
296
        buf_pos = 1;
297
      }
298
      break;
299
    case 1: //prefix1
300
      if(buf[i] == 'C'){
301
        packet_buf[1] = 'C';
302
        buf_pos = 2;
303
      }else{
304
        buf_pos = 0;
305
      }
306
      break;
307
    default: 
308
      /* anything except prefix0, prefix1, or checksum */
309
      
310
      /* Check for R,C - in this case, very likely that we missed a byte */
311
      if (i > 0 && buf[i] == 'C' && buf[i-1] == 'R') {
312
        packet_buf[0] = 'R';
313
        packet_buf[1] = 'C';
314
        
315
        buf_pos = 2;
316
      } else {
317
        packet_buf[buf_pos] = buf[i];
318
        buf_pos++;
319
      }
320
      break;
321
    case (PACKET_SIZE-1):
322
      /* At checksum location */
323
      buf_pos = 0;
324
      packet_buf[15] = buf[i];
325

  
326
      /* Compute desired checksum */
327
      unsigned char sum = 0;
328
      for(int j = 2; j < PACKET_SIZE; j++){
329
        sum += packet_buf[j];
330
      }
331
      
332
      if(!sum){
333
        //Checksum passed
334
        dbg_printf("%s: checksum passed\n", __FUNCTION__);
335

  
336
        complete_packet = create_packet(packet_buf[2], packet_buf[3], 
337
                                        packet_buf[4], packet_buf[5], 
338
                                        packet_buf[6], (packet_buf+7), 
339
                                        packet_buf[PACKET_SIZE-2]);
340
      }else{
341
        dbg_printf("%s: checksum failed\n", __FUNCTION__);
342
      }
343

  
344
      break;
345
    }
346
  }
347

  
348
  return complete_packet;
349
}
350

  
351
void ColonetWireless::update_network_props(ColonetPacket* pkt)
352
{
353
  if(first_packet_sent && pkt->token_dest == token_dest){
354
    /* Another robot is sending to our dest - therefore the network
355
     * doesn't know about us yet.  Try to register again. */
356
    dbg_printf("Disconnected from network\n");
357
    dbg_printf("%s: failed to register in network; trying again...\n", 
358
               __FUNCTION__);
359
    connected = false;
360

  
361
  }
362

  
363
  if(num_robots < pkt->num_robots){    
364
    if(token_dest == 0){
365
      /* If we were the last robot, we now point to newly added robot */
366
      token_dest = num_robots;
367
      dbg_printf("%s: token_dest updated to %d\n", __FUNCTION__, token_dest);
368
    }
369

  
370
    num_robots = pkt->num_robots;
371

  
372
    dbg_printf("%s: num_robots updated to %d\n", __FUNCTION__, num_robots);
373
  }else if(num_robots > pkt->num_robots && first_packet_sent){
374
    /* A robot has left the network... hopefully not us */
375
    dbg_printf("%s: number of robots decreased to %d\n", __FUNCTION__, 
376
               pkt->num_robots);
377

  
378
    num_robots = pkt->num_robots;
379
  }
380
}
381

  
382
int ColonetWireless::join_network(ColonetPacket* pkt)
383
{
384
  dbg_printf("Attempting to join network...\n");
385

  
386
  token_src = pkt->num_robots;
387
  token_dest = 0;
388
  num_robots = pkt->num_robots+1;
389

  
390
  ColonetPacket* newpkt = create_packet(token_src, token_dest, 0, 0, 0, 
391
                                        (unsigned char*)"", num_robots);
392
  if(newpkt == NULL){
393
    fprintf(stderr, "Error: %s - create_packet failed\n", __FUNCTION__);
394
    return -1;
395
  }
396

  
397
  dbg_printf("JOIN PACKET:\n"
398
             "token_src:%d\n"
399
             "token_dest:%d\n"
400
             "msg_dest:%d\n"
401
             "msg_type:%d\n"
402
             "msg_code:%d\n"
403
             "num_robots:%d\n",
404
             newpkt->token_src, newpkt->token_dest, newpkt->msg_dest, 
405
             newpkt->msg_type, newpkt->msg_code, newpkt->num_robots);
406
  
407
  dbg_printf("data: ");
408

  
409
  for(int i = 0; i < PACKET_DATA_LEN; i++){
410
    dbg_printf("%d ", newpkt->data[i]);
411
  }
412
  dbg_printf("\n");
413

  
414
  send_packet(newpkt);
415

  
416
  connected = true;
417
  dbg_printf("Connected to network.\n");
418

  
419
  free(newpkt);
420

  
421
  return 0;
422
}
423

  
424
int ColonetWireless::transmit_queued_message()
425
{
426
  ColonetPacket* top_pkt;
427
  int ret;
428

  
429
  if(have_token){
430
    top_pkt = outbox.front();
431
    if(top_pkt == NULL){
432
      dbg_printf("%s: no messages to send -- Passing the token.\n", 
433
                 __FUNCTION__);
434
      /* If no packets need to be sent, just send a blank packet */
435
      top_pkt = create_packet(token_src, token_dest, 0, 0, 0, 
436
                              (unsigned char*)"", num_robots);
437
    }else{
438
      outbox.pop();
439
    }
440

  
441
    ret = send_packet(top_pkt);
442
    free(top_pkt);
443
    if(ret < 0){
444
      dbg_fprintf(stderr, "%s: send_packet failed\n", __FUNCTION__);
445
      return -1;
446
    }
447

  
448
    dbg_printf("%s: packet sent\n", __FUNCTION__);
449

  
450
    have_token = false;
451
  }
452

  
453
  return 0;
454
}
455

  
456
int ColonetWireless::send_packet(ColonetPacket* pkt)
457
{
458
  int portfd = open(wireless_port, O_RDWR);
459

  
460
  dbg_printf("\nsend packet: \n");
461

  
462
  if (portfd == 0) {
463
    return -1;
464
  }
465

  
466
  //write(portfd, (unsigned char*)pkt, 16);
467

  
468
  for (int i = 0; i < PACKET_SIZE; i++) {
469
    write(portfd, (unsigned char*)pkt+i, 1);
470
    usleep(50); //delay here - robot wireless can't handle full data rate...
471
    dbg_fprintf(stderr, "%x ", ((unsigned char*)pkt)[i]);
472
  }
473
  dbg_printf("\n");
474

  
475
  close(portfd);
476

  
477
  return 0;
478
}
479

  
480
unsigned char ColonetWireless::compute_checksum(ColonetPacket* pkt)
481
{
482
  char checksum = 0;
483

  
484
  checksum -= pkt->token_src;
485
  checksum -= pkt->token_dest;
486
  checksum -= pkt->msg_dest;
487
  checksum -= pkt->msg_type;
488
  checksum -= pkt->msg_code;
489

  
490
  for(int i = 0; i < PACKET_DATA_LEN; i++){
491
    checksum -= pkt->data[i];
492
  }
493

  
494
  checksum -= pkt->num_robots;
495

  
496
  return checksum;
497
}
498

  
499
ColonetPacket* ColonetWireless::create_packet(unsigned char token_src_, 
500
                                              unsigned char token_dest_,
501
                                              unsigned char msg_dest, 
502
                                              unsigned char msg_type, 
503
                                              unsigned char msg_code, 
504
                                              unsigned char* data,
505
                                              unsigned char num_robots_)
506
{
507
  ColonetPacket* dest_packet = new ColonetPacket;
508

  
509
  dest_packet->prefix[0] = 'R';
510
  dest_packet->prefix[1] = 'C';
511

  
512
  dest_packet->token_src = token_src_;
513
  dest_packet->token_dest = token_dest_;
514
    
515
  dest_packet->msg_dest = msg_dest;
516
  dest_packet->msg_type = msg_type;
517
  dest_packet->msg_code = msg_code;
518

  
519
  memset(dest_packet->data, 0, PACKET_DATA_LEN);
520
  memcpy(dest_packet->data, (char*)data, PACKET_DATA_LEN);
521

  
522
  dest_packet->num_robots = num_robots_;
523
  dest_packet->checksum = compute_checksum(dest_packet);
524

  
525
  //printf("Made this packet: \n");
526
  //print_packet(dest_packet);
527

  
528
  return dest_packet;
529
}
530

  
531
void ColonetWireless::print_packet(ColonetPacket* pkt)
532
{
533
  int i;
534

  
535
  printf("Prefix: %c%c\n", pkt->prefix[0], pkt->prefix[1]);
536
  printf("Token src: %d\n", pkt->token_src);
537
  printf("Token dest: %d\n", pkt->token_dest);
538
  printf("Msg dest: %d\n", pkt->msg_dest);
539
  printf("Msg type: %d\n", pkt->msg_type);
540
  printf("Msg code: %d\n", pkt->msg_code);
541

  
542
  printf("Data: ");
543
  for(i = 0; i < PACKET_DATA_LEN; i++){
544
    printf("%d ", pkt->data[i]);
545
  }
546
  printf("\n");
547
  
548
  printf("Num robots: %d\n", pkt->num_robots);
549
  printf("Checksum: %d\n", pkt->checksum);
550
}
551

  
552
int ColonetWireless::handle_error(ColonetPacket* pkt)
553
{
554
  int dead_robot;
555
  int errcode = ((char*)pkt)[WL_ERROR_LOC];
556

  
557
  dbg_printf("%s: Handling error %d\n", __FUNCTION__, pkt->token_dest);
558

  
559
  switch(errcode){ //token_dest 
560
  case WL_ERRCODE_ROBOTDEATH:
561
    dead_robot = ((char*)pkt)[WL_ERR_DEAD_LOC];
562

  
563
    fprintf(stderr, "Dead robot: %d\n", dead_robot);
564
    num_robots--;
565
    
566
    if(token_src > dead_robot){
567
      if(token_src == num_robots){
568
        token_src--;
569
        token_dest = 0;
570
      }else{
571
        token_src--;
572
        token_dest--;
573
      }
574
    }
575

  
576
    //ensure that the last robot talks to the 0th one
577
    //this won't be set if the LAST robot dies (all robots are < dead)
578
    if(token_src == num_robots - 1){
579
      token_dest = 0;
580
    }
581

  
582
    if(token_src == dead_robot){
583
      //you took the place of the dead robot
584
      //you start the token ring again
585
      ColonetPacket* tmp_pkt = create_packet(token_src, token_dest, 0, 0, 0,
586
                                             (unsigned char*)"", num_robots);
587
      send_packet(tmp_pkt);
588
      free(tmp_pkt);
589
    }
590
    break;
591
  case WL_ERRCODE_NEEDTOCHARGE:
592
    fprintf(stderr, "Need to charge error received\n");
593
    break;
594
  case WL_ERRCODE_CHARGESTATION:
595
    fprintf(stderr, "Charge station error received\n");
596
    break;
597
  }
598
    
599
  return 0;
600
}
601

  
602
/** @brief 
603
 *
604
 * @param pkt Packet to be logged
605
 *
606
 * @return 0 on success, -1 on failure
607
 */
608
int ColonetWireless::log_packet(ColonetPacket* pkt)
609
{
610
  FILE* logfile = fopen(log_filename, "a");
611

  
612
  if (logfile == NULL) {
613
    dbg_printf("%s: Error - fopen %s failed.\n", log_filename, __FUNCTION__);
614
    return -1;
615
  }
616

  
617
  for (int i = 0; i < PACKET_SIZE; i++) {
618
    fprintf(logfile, "%d ", *((unsigned char*)pkt+i));
619
  }
620

  
621
  fprintf(logfile, "\n");
622

  
623
  fclose(logfile);
624

  
625
  return 0;
626
}
trunk/code/projects/colonet/lib/colonet_wireless/colonet_wireless.h
1
/** @file colonet_wireless.h
2
 *
3
 * @brief Wireless library for communicating with colony robots
4
 *
5
 * @author Eugene Marinelli
6
 * @date 10/10/07
7
 */
8

  
9
#ifndef COLONET_WIRELESS_H_
10
#define COLONET_WIRELESS_H_
11

  
12
#include <colonet_defs.h>
13

  
14
typedef int(*MsgHandlerFunction)(unsigned char type, short source, int dest, unsigned char* data, int len);
15

  
16
/** @brief Initializes colonet wireless library
17
 *
18
 * @param wl_port Either SERIAL_PORT or USB_PORT (as defined in COLONET_DEFS)
19
 * @param log_filename Path to log file - outputs all raw data on the network
20
 * If set to NULL, logging is disabled.
21
 * @param msg_handler Function to be called when a packet is received.
22
 * Must take a ColonetPacket as an argument (see defn of MsgHandlerFunction)
23
 *
24
 * @return new ColonetWireless object
25
 */
26
void colonet_wl_init(char* wl_port, MsgHandlerFunction message_handler_, char* log_filename_);
27

  
28
/** @brief Spawns a thread which reads data from the hardware interface
29
 * with the colony (either a dongle or a robot programmed to relay data)
30
 * and runs msg_handler when a full packet is received
31
 *
32
 * @return pointer to the thread
33
 */
34
int colonet_wl_run_listener_thread(void);
35

  
36
void colonet_wl_kill_listener_thread(void);
37

  
38
/**
39
 * @brief ...
40
 *
41
 * @return void
42
 */
43
void colonet_wl_send(short client_source, short dest, ColonetMessageType msg_type, unsigned char msg_code,
44
                     unsigned char* args);
45

  
46
int colonet_get_num_robots(void);
47

  
48
int** colonet_get_sensor_matrix(int* numrobots, int** ids);
49
int* colonet_get_xbee_ids(int* numrobots);
50

  
51
#endif
trunk/code/projects/colonet/lib/colonet_wireless/Makefile
1
# colonet_wireless_test makefile
2

  
3
CC = gcc
4
CFLAGS = -Wall -Wshadow -Wextra -g
5
INCLUDES = -I../../../libwireless/lib -I../
6

  
7
default: colonet_wireless.o
8

  
9
tests: colonet_wireless_test colonet_wireless_test2
10

  
11
colonet_wireless_test: colonet_wireless_test.o colonet_wireless.o Makefile
12
	$(CC) $(CFLAGS) -I ../ -lpthread -o tests/colonet_wireless_test tests/colonet_wireless_test.o colonet_wireless.o
13

  
14
colonet_wireless_test2: colonet_wireless_test2.o colonet_wireless.o Makefile
15
	$(CC) $(CFLAGS) -I ../ -pthread -o tests/colonet_wireless_test2 tests/colonet_wireless_test2.o colonet_wireless.o
16

  
17
colonet_wireless.o: colonet_wireless.cpp colonet_wireless.h
18
	$(CC) $(CFLAGS) $(INCLUDES) -c colonet_wireless.cpp
19
	ar src ../libcolonet_wireless.a colonet_wireless.o
20
#	ranlib libcolonet_wireless.a
21

  
22
colonet_wireless_test.o: tests/colonet_wireless_test.cpp
23
	$(CC) $(CFLAGS) -I $(INCLUDES) -pthread -c tests/colonet_wireless_test.cpp
24

  
25
colonet_wireless_test2.o: colonet_wireless_test2.cpp
26
	$(CC) $(CFLAGS) -I $(INCLUDES) -pthread -c tests/colonet_wireless_test2.cpp
27

  
28
clean:
29
	rm -rf *.o tests/colonet_wireless_test tests/colonet_wireless_test2
trunk/code/projects/colonet/lib/colonet_wireless/colonet_wireless.cpp
1
/** @file colonet_wireless.c
2
 *
3
 * @brief Implementation of server-side colonet wireless library
4
 *
5
 * @author Eugene Marinelli
6
 */
7

  
8
/********************************* Includes **********************************/
9
#include <string>
10
#include <pthread.h>
11
#include <iostream>
12
#include <fstream>
13
#include <unistd.h>
14
#include <fcntl.h>
15
#include <signal.h>
16

  
17
#include <wireless.h> // Colonet wireless library.
18
#include <wl_token_ring.h>
19

  
20
#include "colonet_defs.h"
21
#include "colonet_wireless.h"
22

  
23
/******************************* Definitions *********************************/
24

  
25
//Enable debug printouts
26
#define DEBUG 1
27

  
28
#ifdef DEBUG
29
#define dbg_printf(...) printf(__VA_ARGS__)
30
#define dbg_fprintf(...) fprintf(__VA_ARGS__)
31
#else
32
#define dbg_printf(...)
33
#define dbg_fprintf(...)
34
#endif
35

  
36
static MsgHandlerFunction message_handler;
37
static bool logging_enabled;
38
static char log_filename[80];
39
static pthread_t listener_thread;
40
static char wl_port[40];
41

  
42
/************************* Internal prototypes *******************************/
43
static void* listen(void* args);
44
static void timeout_handler(void);
45
static void handle_response(int frame, int received);
46
static void handle_receive(char type, int source, unsigned char* packet, int len);
47
static void unregister(void);
48
static int log_packet(unsigned char* packet, int len);
49

  
50
/**************************** Public functions *******************************/
51
void colonet_wl_init(char* wl_port_, MsgHandlerFunction message_handler_, char* log_filename_) {
52
  if (log_filename_ != NULL) {
53
    logging_enabled = true;
54
    strcpy(log_filename, log_filename_);
55
  }
56

  
57
  strncpy(wl_port, wl_port_, 40);
58

  
59
  message_handler = message_handler_;
60

  
61
  printf("Calling wl_init...\n");
62
  wl_init();
63
  printf("wl_init succeeded.\n");
64

  
65
  wl_token_ring_register();
66

  
67
  printf("Joining token ring...\n");
68
  wl_token_ring_join();
69
  printf("Joined token ring.\n");
70
}
71

  
72
void colonet_wl_kill_listener_thread() {
73
  pthread_kill(listener_thread, 9);
74
}
75

  
76
int colonet_wl_run_listener_thread() {
77
  dbg_printf("Spawning listener thread...\n");
78

  
79
  if (pthread_create(&listener_thread, NULL, listen, NULL)) {
80
    perror("pthread_create");
81
    return -1;
82
  }
83

  
84
  return 0;
85
}
86

  
87
void colonet_wl_send(short client_source, short dest, ColonetMessageType msg_type, unsigned char msg_code,
88
                     unsigned char* args) {
89
  printf("colonet_wl_send: client_source:%d, dest:%d, msg_code:%d\n", client_source, dest, msg_code);
90

  
91
  ColonetRobotServerPacket pkt;
92
  pkt.client_id = client_source;
93
  pkt.msg_code = msg_code;
94

  
95
  for (int i = 0; i < PACKET_DATA_LEN; i++) {
96
    pkt.data[i] = args[i];
97
  }
98

  
99
  if (dest == GLOBAL_DEST) {
100
    printf("sending to global dest\n");
101

  
102
    wl_send_global_packet(COLONET_PACKET_GROUP_ID, (char)msg_type, (char*)(&pkt), sizeof(ColonetRobotServerPacket), 0);
103
  } else {
104
    printf("sending to specific robot.\n");
105
    wl_send_robot_to_robot_global_packet(COLONET_PACKET_GROUP_ID, (char)msg_type, (char*)(&pkt),
106
                                         sizeof(ColonetRobotServerPacket), dest, COLONET_RESPONSE_PACKET_FRAME_ID);
107
  }
108
}
109

  
110
int colonet_get_num_robots(void) {
111
  return wl_token_get_num_robots();
112
}
113

  
114
int* colonet_get_xbee_ids(int* numrobots) {
115
  int num_robots = wl_token_get_num_robots();
116
  int* ids = (int*)malloc(num_robots * sizeof(int));
117

  
118
  wl_token_iterator_begin();
119

  
120
  int* p = ids;
121
  while (wl_token_iterator_has_next()) {
122
    *p = wl_token_iterator_next();
123
    p++;
124
  }
125

  
126
  *numrobots = num_robots;
127
  return ids;
128
}
129

  
130
// Returns int**; should be freed
131
int** colonet_get_sensor_matrix(int* numrobots, int** ids_) {
132
  int num_robots;
133
  int* ids = colonet_get_xbee_ids(&num_robots);
134

  
135
  int** m = (int**)malloc(num_robots * sizeof(int*));
136
  for (int i = 0; i < num_robots; i++) {
137
    m[i] = (int*)malloc(num_robots * sizeof(int*));
138
  }
139

  
140
  for (int i = 0; i < num_robots; i++) {
141
    for (int j = 0; j < num_robots; j++) {
142
      m[i][j] = wl_token_get_sensor_reading(ids[i], ids[j]);
143
    }
144
  }
145

  
146
  *numrobots = num_robots;
147
  *ids_ = ids;
148
  return m;
149
}
150

  
151
/**************************** Private functions ******************************/
152

  
153
static void timeout_handler() {
154
  printf("colonet wireless - timeout!\n");
155
}
156

  
157
static void handle_response(int frame, int received) {
158
  printf("handle response\n");
159
}
160

  
161
static void handle_receive(char type, int source, unsigned char* packet,
162
                           int len) {
163
  ColonetRobotServerPacket pkt;
164
  pkt.client_id = packet[0] | (packet[1]<<8) | (packet[2]<<16) | (packet[3]<<24); //little endian
165

  
166
  memcpy(pkt.data, packet + 5, PACKET_DATA_LEN);
167

  
168
  if (logging_enabled) {
169
    log_packet(packet, len);
170
  }
171

  
172
  message_handler(type, source, pkt.client_id, packet, len);
173

  
174
  printf("handle receive\n");
175
}
176

  
177
static void unregister(void) {
178
  printf("unregister\n");
179
}
180

  
181
/** @brief Analogous to the "SIGNAL" or "ISR" function on the robots.
182
 * Listens for bytes on the wireless port and constructs packets based on them.
183
 * Not part of the ColonetWireless class since a function pointer must be
184
 * passed in starting the thread that runs it (tricky or impossible if it's
185
 * a class function).
186
 *
187
 * @param args Pointer to arguments.  Can be safely casted to ListenerArgs type
188
 * @return NULL
189
 */
190
static void* listen(void* args) {
191
  printf("Called listen.\n");
192

  
193
  PacketGroupHandler pgh = {COLONET_PACKET_GROUP_ID,
194
                            timeout_handler,
195
                            handle_response,
196
                            handle_receive,
197
                            unregister};
198
  wl_register_packet_group(&pgh);
199

  
200
  while (1) {
201
    wl_do();
202
  }
203

  
204
  wl_terminate();
205
  pthread_exit(NULL);
206
  return NULL;
207
}
208

  
209
/** @brief
210
 *
211
 * @param pkt Packet to be logged
212
 *
213
 * @return 0 on success, -1 on failure
214
 */
215
int log_packet(unsigned char* packet, int len) {
216
  FILE* logfile = fopen(log_filename, "a");
217

  
218
  if (logfile == NULL) {
219
    dbg_printf("%s: Error - fopen %s failed.\n", log_filename, __FUNCTION__);
220
    return -1;
221
  }
222

  
223
  for (int i = 0; i < len; i++) {
224
    fprintf(logfile, "%d ", *((unsigned char*)packet + i));
225
  }
226
  fprintf(logfile, "\n");
227

  
228
  fclose(logfile);
229
  return 0;
230
}
trunk/code/projects/colonet/ColonetServer/colonet_wireless.cpp
1
/** @file colonet_wireless.c
2
 *
3
 * @brief Implementation of server-side colonet wireless library
4
 *
5
 * @author Eugene Marinelli
6
 */
7

  
8
/********************************* Includes **********************************/
9
#include <string>
10
#include <pthread.h>
11
#include <iostream>
12
#include <fstream>
13
#include <unistd.h>
14
#include <fcntl.h>
15
#include <signal.h>
16

  
17
#include <wireless.h> // Colonet wireless library.
18
#include <wl_token_ring.h>
19

  
20
#include "colonet_defs.h"
21
#include "colonet_wireless.h"
22

  
23
/******************************* Definitions *********************************/
24

  
25
//Enable debug printouts
26
#define DEBUG 1
27

  
28
#ifdef DEBUG
29
#define dbg_printf(...) printf(__VA_ARGS__)
30
#define dbg_fprintf(...) fprintf(__VA_ARGS__)
31
#else
32
#define dbg_printf(...)
33
#define dbg_fprintf(...)
34
#endif
35

  
36
static MsgHandlerFunction message_handler;
37
static bool logging_enabled;
38
static char log_filename[80];
39
static pthread_t listener_thread;
40
static char wl_port[40];
41

  
42
/************************* Internal prototypes *******************************/
43
static void* listen(void* args);
44
static void timeout_handler(void);
45
static void handle_response(int frame, int received);
46
static void handle_receive(char type, int source, unsigned char* packet, int len);
47
static void unregister(void);
48
static int log_packet(unsigned char* packet, int len);
49

  
50
/**************************** Public functions *******************************/
51
void colonet_wl_init(char* wl_port_, MsgHandlerFunction message_handler_, char* log_filename_) {
52
  if (log_filename_ != NULL) {
53
    logging_enabled = true;
54
    strcpy(log_filename, log_filename_);
55
  }
56

  
57
  strncpy(wl_port, wl_port_, 40);
58

  
59
  message_handler = message_handler_;
60

  
61
  printf("Calling wl_init...\n");
62
  wl_init();
63
  printf("wl_init succeeded.\n");
64

  
65
  wl_token_ring_register();
66

  
67
  printf("Joining token ring...\n");
68
  wl_token_ring_join();
69
  printf("Joined token ring.\n");
70
}
71

  
72
void colonet_wl_kill_listener_thread() {
73
  pthread_kill(listener_thread, 9);
74
}
75

  
76
int colonet_wl_run_listener_thread() {
77
  dbg_printf("Spawning listener thread...\n");
78

  
79
  if (pthread_create(&listener_thread, NULL, listen, NULL)) {
80
    perror("pthread_create");
81
    return -1;
82
  }
83

  
84
  return 0;
85
}
86

  
87
void colonet_wl_send(short client_source, short dest, ColonetMessageType msg_type, unsigned char msg_code,
88
                     unsigned char* args) {
89
  printf("colonet_wl_send: client_source:%d, dest:%d, msg_code:%d\n", client_source, dest, msg_code);
90

  
91
  ColonetRobotServerPacket pkt;
92
  pkt.client_id = client_source;
93
  pkt.msg_code = msg_code;
94

  
95
  for (int i = 0; i < PACKET_DATA_LEN; i++) {
96
    pkt.data[i] = args[i];
97
  }
98

  
99
  if (dest == GLOBAL_DEST) {
100
    printf("sending to global dest\n");
101

  
102
    wl_send_global_packet(COLONET_PACKET_GROUP_ID, (char)msg_type, (char*)(&pkt), sizeof(ColonetRobotServerPacket), 0);
103
  } else {
104
    printf("sending to specific robot.\n");
105
    wl_send_robot_to_robot_global_packet(COLONET_PACKET_GROUP_ID, (char)msg_type, (char*)(&pkt),
106
                                         sizeof(ColonetRobotServerPacket), dest, COLONET_RESPONSE_PACKET_FRAME_ID);
107
  }
108
}
109

  
110
int colonet_get_num_robots(void) {
111
  return wl_token_get_num_robots();
112
}
113

  
114
int* colonet_get_xbee_ids(int* numrobots) {
115
  int num_robots = wl_token_get_num_robots();
116
  int* ids = (int*)malloc(num_robots * sizeof(int));
117

  
118
  wl_token_iterator_begin();
119

  
120
  int* p = ids;
121
  while (wl_token_iterator_has_next()) {
122
    *p = wl_token_iterator_next();
123
    p++;
124
  }
125

  
126
  *numrobots = num_robots;
127
  return ids;
128
}
129

  
130
// Returns int**; should be freed
131
int** colonet_get_sensor_matrix(int* numrobots, int** ids_) {
132
  int num_robots;
133
  int* ids = colonet_get_xbee_ids(&num_robots);
134

  
135
  int** m = (int**)malloc(num_robots * sizeof(int*));
136
  for (int i = 0; i < num_robots; i++) {
137
    m[i] = (int*)malloc(num_robots * sizeof(int*));
138
  }
139

  
140
  for (int i = 0; i < num_robots; i++) {
141
    for (int j = 0; j < num_robots; j++) {
142
      m[i][j] = wl_token_get_sensor_reading(ids[i], ids[j]);
143
    }
144
  }
145

  
146
  *numrobots = num_robots;
147
  *ids_ = ids;
148
  return m;
149
}
150

  
151
/**************************** Private functions ******************************/
152

  
153
static void timeout_handler() {
154
  printf("colonet wireless - timeout!\n");
155
}
156

  
157
static void handle_response(int frame, int received) {
158
  printf("handle response\n");
159
}
160

  
161
static void handle_receive(char type, int source, unsigned char* packet,
162
                           int len) {
163
  ColonetRobotServerPacket pkt;
164
  pkt.client_id = packet[0] | (packet[1]<<8) | (packet[2]<<16) | (packet[3]<<24); //little endian
165

  
166
  memcpy(pkt.data, packet + 5, PACKET_DATA_LEN);
167

  
168
  if (logging_enabled) {
169
    log_packet(packet, len);
170
  }
171

  
172
  message_handler(type, source, pkt.client_id, packet, len);
173

  
174
  printf("handle receive\n");
175
}
176

  
177
static void unregister(void) {
178
  printf("unregister\n");
179
}
180

  
181
/** @brief Analogous to the "SIGNAL" or "ISR" function on the robots.
182
 * Listens for bytes on the wireless port and constructs packets based on them.
183
 * Not part of the ColonetWireless class since a function pointer must be
184
 * passed in starting the thread that runs it (tricky or impossible if it's
185
 * a class function).
186
 *
187
 * @param args Pointer to arguments.  Can be safely casted to ListenerArgs type
188
 * @return NULL
189
 */
190
static void* listen(void* args) {
191
  printf("Called listen.\n");
192

  
193
  PacketGroupHandler pgh = {COLONET_PACKET_GROUP_ID,
194
                            timeout_handler,
195
                            handle_response,
196
                            handle_receive,
197
                            unregister};
198
  wl_register_packet_group(&pgh);
199

  
200
  while (1) {
201
    wl_do();
202
  }
203

  
204
  wl_terminate();
205
  pthread_exit(NULL);
206
  return NULL;
207
}
208

  
209
/** @brief
210
 *
211
 * @param pkt Packet to be logged
212
 *
213
 * @return 0 on success, -1 on failure
214
 */
215
int log_packet(unsigned char* packet, int len) {
216
  FILE* logfile = fopen(log_filename, "a");
217

  
218
  if (logfile == NULL) {
219
    dbg_printf("%s: Error - fopen %s failed.\n", log_filename, __FUNCTION__);
220
    return -1;
221
  }
222

  
223
  for (int i = 0; i < len; i++) {
224
    fprintf(logfile, "%d ", *((unsigned char*)packet + i));
225
  }
226
  fprintf(logfile, "\n");
227

  
228
  fclose(logfile);
229
  return 0;
230
}
trunk/code/projects/colonet/ColonetServer/includes/colonet_wireless.h
1
/** @file colonet_wireless.h
2
 *
3
 * @brief Wireless library for communicating with colony robots
4
 *
5
 * @author Eugene Marinelli
6
 * @date 10/10/07
7
 */
8

  
9
#ifndef COLONET_WIRELESS_H_
10
#define COLONET_WIRELESS_H_
11

  
12
#include <colonet_defs.h>
13

  
14
typedef int(*MsgHandlerFunction)(unsigned char type, short source, int dest, unsigned char* data, int len);
15

  
16
/** @brief Initializes colonet wireless library
17
 *
18
 * @param wl_port Either SERIAL_PORT or USB_PORT (as defined in COLONET_DEFS)
19
 * @param log_filename Path to log file - outputs all raw data on the network
20
 * If set to NULL, logging is disabled.
21
 * @param msg_handler Function to be called when a packet is received.
22
 * Must take a ColonetPacket as an argument (see defn of MsgHandlerFunction)
23
 *
24
 * @return new ColonetWireless object
25
 */
26
void colonet_wl_init(char* wl_port, MsgHandlerFunction message_handler_, char* log_filename_);
27

  
28
/** @brief Spawns a thread which reads data from the hardware interface
29
 * with the colony (either a dongle or a robot programmed to relay data)
30
 * and runs msg_handler when a full packet is received
31
 *
32
 * @return pointer to the thread
33
 */
34
int colonet_wl_run_listener_thread(void);
35

  
36
void colonet_wl_kill_listener_thread(void);
37

  
38
/**
39
 * @brief ...
40
 *
41
 * @return void
42
 */
43
void colonet_wl_send(short client_source, short dest, ColonetMessageType msg_type, unsigned char msg_code,
44
                     unsigned char* args);
45

  
46
int colonet_get_num_robots(void);
47

  
48
int** colonet_get_sensor_matrix(int* numrobots, int** ids);
49
int* colonet_get_xbee_ids(int* numrobots);
50

  
51
#endif
trunk/code/projects/colonet/ColonetServer/Makefile
3 3
CC = g++
4 4
CFLAGS = -Wall -Wshadow -Wextra -g
5 5

  
6
COLONETCPPFILES = Main.cpp ColonetServer.cpp wirelessMessageHandler.cpp ConnectionPool.cpp Command.cpp
6
COLONETCPPFILES = Main.cpp ColonetServer.cpp wirelessMessageHandler.cpp ConnectionPool.cpp Command.cpp colonet_wireless.cpp
7 7
COLONETCPPOBJECTS = $(COLONETCPPFILES:.cpp=.o)
8 8
COLONETFILES = options.c
9 9
COLONETOBJECTS = $(COLONETFILES:.c=.o)
......
29 29
	make; ./ColonetServer
30 30
	../vision/vision.sh
31 31

  
32
ColonetServer: $(COLONETCPPFILES) $(COLONETFILES) $(LOGGINGFILES) -lcolonet_wireless
32
ColonetServer: $(COLONETCPPFILES) $(COLONETFILES) $(LOGGINGFILES)
33 33
	@echo "---begin compilation---"
34 34
	@echo ""
35 35
	@echo "---create object files---"
......
39 39
	@echo "---finish creating object files---"
40 40
	@echo ""
41 41
	@echo "---link files---"
42
	$(CC) $(CFLAGS) $(COLONETOBJECTS) $(COLONETCPPOBJECTS) $(LOGGINGOBJECTS) $(LIBRARY_DIRS_FOR_GCC) -lpthread -lcolonet_wireless -lwireless_colonet  $(INCLUDE_DIRS_FOR_GCC) -o $@
42
	$(CC) $(CFLAGS) $(COLONETOBJECTS) $(COLONETCPPOBJECTS) $(LOGGINGOBJECTS) $(LIBRARY_DIRS_FOR_GCC) -lpthread -lwireless_colonet  $(INCLUDE_DIRS_FOR_GCC) -o $@
43 43
	@echo "---finish linking files---"
44 44
	@echo ""
45 45
	@echo "---finish compilation---"

Also available in: Unified diff