Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / colonet / server / VirtualWall.cpp @ 661

History | View | Annotate | Download (1.47 KB)

1
/**
2
 * Eugene Marinelli
3
 */
4

    
5
#include <VirtualWall.h>
6
#include <colonet_wireless.h>
7

    
8
VirtualWall::VirtualWall(void) {
9
  wall_available = false;
10
}
11

    
12
VirtualWall::~VirtualWall(void) {
13
}
14

    
15
int VirtualWall::set_coordinates(int upper_x, int upper_y, int lower_x, int lower_y) {
16
  if (upper_x < 0 || upper_y < 0 || lower_x < 0 || lower_y < 0) {
17
    return -1;
18
  }
19

    
20
  upper_left_x = upper_x;
21
  upper_left_y = upper_y;
22
  lower_right_x = lower_x;
23
  lower_right_y = lower_y;
24

    
25
  wall_available = true;
26

    
27
  /* Let the robots know. */
28
  send_to_robots();
29

    
30
  return 0;
31
}
32

    
33
void VirtualWall::send_to_robots() {
34
  if (wall_available) {
35
    unsigned char args[PACKET_DATA_LEN];
36

    
37
    args[0] = (upper_left_x >> 8) & 0xFF;
38
    args[1] = upper_left_x & 0xFF;
39
    args[2] = (upper_left_y >> 8) & 0xFF;
40
    args[3] = upper_left_y & 0xFF;
41
    colonet_wl_send(0, GLOBAL_DEST, COLONET_COMMAND, SERVER_REPORT_VIRTUAL_WALL_UPPER, args);
42

    
43
    args[0] = (lower_right_x >> 8) & 0xFF;
44
    args[1] = lower_right_x & 0xFF;
45
    args[2] = (lower_right_y >> 8) & 0xFF;
46
    args[3] = lower_right_y & 0xFF;
47
    colonet_wl_send(0, GLOBAL_DEST, COLONET_COMMAND, SERVER_REPORT_VIRTUAL_WALL_LOWER, args);
48
  }
49
}
50

    
51
void VirtualWall::clear() {
52
  wall_available = false;
53
}
54

    
55
int VirtualWall::get_coordinates(int* upper_x, int* upper_y, int* lower_x, int* lower_y) {
56
  if (wall_available) {
57
    *upper_x = upper_left_x;
58
    *upper_y = upper_left_y;
59
    *lower_x = lower_right_x;
60
    *lower_y = lower_right_y;
61

    
62
    return 0;
63
  } else {
64
    return -1;
65
  }
66
}