Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (1.24 KB)

1 11 emarinel
/** @file client.c
2
 *
3
 *  @author Jason Knichel
4
 *  @author Eugene Marinelli
5
 *
6
 * @bug Weird segfault when processing tokens
7
 */
8
9
#include <string.h>
10
#include <stdio.h>
11
#include <unistd.h>
12
#include <ctype.h>
13
#include <errno.h>
14
15
#include <colonet_wireless.h>
16
17
#include "includes/client.h"
18
#include "includes/options.h"
19
#include "includes/ConnectionPool.h"
20
21
/* Globals */
22 22 jknichel
extern ColonetWireless* wireless;
23 20 jknichel
extern ConnectionPool * connection_pool;
24 11 emarinel
25
26
/* Public functions */
27
int wirelessMessageHandler(ColonetPacket* pkt)
28
{
29
  printf("Received wireless message!!!\n");
30
  if (!pkt)
31
  {
32
    printf("The packet pointer was null.\n");
33
    return -1;
34
  }
35
36
  if ((int)pkt->msg_type == COLONET_RESPONSE)
37
  {
38
    printf("response\n");
39
40
    int dest = (int)(pkt->msg_dest);
41 22 jknichel
42
    char buffer[WRITE_BUFFER_SIZE];
43 11 emarinel
44 22 jknichel
    int value = (int)(pkt->data[0]);
45
    snprintf(buffer, WRITE_BUFFER_SIZE, "%d\n", value);
46 11 emarinel
47 22 jknichel
    int len = strlen(buffer);
48
    if (connection_pool->write_to_client(dest, buffer, len) == ERROR_INVALID_CLIENT_ID) {
49
      printf("The robot wanted to pass the data to a client not in the pool.\n");
50 11 emarinel
      return -1;
51
    }
52 22 jknichel
53
    printf("Put data in write buffer for client.\n");
54 11 emarinel
  }
55
  else
56
  {
57
    printf("not a response\n");
58
  }
59
60
  pkt = 0;
61
  return 0;
62
}