Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / colonet / ColonetServer / client.cpp @ 118

History | View | Annotate | Download (1.21 KB)

1
/** @file client.c
2
 *
3
 *  @author Jason Knichel
4
 *  @author Eugene Marinelli
5
 *
6
 * @TODO remove dependency on connection_pool
7
 * @bug Weird segfault when processing tokens
8
 */
9

    
10
#include <string.h>
11
#include <stdio.h>
12
#include <unistd.h>
13
#include <ctype.h>
14
#include <errno.h>
15

    
16
#include <colonet_wireless.h>
17

    
18
#include "includes/client.h"
19
#include "includes/options.h"
20
#include "includes/ConnectionPool.h"
21

    
22
/* Globals */
23
extern ConnectionPool * connection_pool;
24

    
25

    
26
/* Public functions */
27
int wirelessMessageHandler(unsigned char type, short source, int dest,
28
                           unsigned char* data, int len) {
29
  printf("Server received wireless message!!!\n");
30

    
31
  if (type == COLONET_RESPONSE) {
32
    printf("response\n");
33

    
34
    char buffer[WRITE_BUFFER_SIZE];
35
          
36
    int value = (int)(data[0]);
37
    snprintf(buffer, WRITE_BUFFER_SIZE, "%d\n", value);
38
          
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");
44
      return -1;
45
    }
46

    
47
    printf("Put data in write buffer for client.\n");
48
  } else {
49
    printf("not a response\n");
50
  }
51

    
52
  return 0;
53
}