Project

General

Profile

Revision 433

defined robot position interface

View differences:

trunk/code/projects/colonet/lib/colonet_dragonfly/colonet_dragonfly.c
24 24
/* Globals (internal) */
25 25
static UserHandler user_handlers[USER_DEFINED_MSG_TOTAL];
26 26

  
27
static int robot_x, robot_y;
28
static int server_xbee_id; // ID of server xbee; set when a colonet packet is received.
29

  
27 30
/* Internal function prototypes */
28 31
static void packet_string_to_struct(ColonetRobotServerPacket* dest_pkt, unsigned char* pkt_buf);
29 32
static unsigned int two_bytes_to_int(char high, char low);
30 33
static void colonet_handle_receive(char type, int source, unsigned char* packet, int length);
34
static void request_abs_position(void);
35
static void move_to_position_routine(int x, int y);
31 36

  
32 37
static PacketGroupHandler colonet_pgh;
33 38

  
......
42 47
  // TODO this should return an error if wl_init has not been called yet.
43 48
  wl_register_packet_group(&colonet_pgh);
44 49

  
50
  robot_x = 0;
51
  robot_y = 0;
52
  server_xbee_id = -1;
53

  
45 54
  return 0;
46 55
}
47 56

  
......
60 69
  return 0;
61 70
}
62 71

  
72
static void request_abs_position() {
73
  if (server_xbee_id != -1) { // if -1, then we don't know the server's xbee id yet.
74
    ColonetRobotServerPacket pkt;
75
    pkt.client_id = -1;
76
    pkt.msg_code = ROBOT_REQUEST_POSITION_FROM_SERVER;
77
    wl_send_robot_to_robot_global_packet(colonet_pgh.groupCode, 0, (char*)&pkt, sizeof(pkt), server_xbee_id, 0);
78
  }
79
}
80

  
81
static void move_to_position_routine(int x, int y) {
82
  /* TODO emarinel control algorithm */
83
  
84
}
85

  
63 86
/* Private functions */
64 87

  
65 88
/** @brief Handles colonet packets.  Should be called by parse_buffer
......
75 98
  unsigned char* args; //up to 7 char args
76 99
  unsigned int int_args[3]; //up to 3 int (2-byte) args
77 100

  
101
  /* Globally store this id. */
102
  server_xbee_id = wl_source;
103

  
78 104
  usb_puts("Packet received.\n");
79 105
  char buf[40];
80 106
  sprintf(buf, "length=%d\n", length);
......
163 189
/*              pkt.msg_code); */
164 190
/*       break; */
165 191

  
192
    case SERVER_REPORT_POSITION_TO_ROBOT:
193
      robot_x = int_args[0];
194
      robot_y = int_args[1];
195
      break;
196

  
197
    case MOVE_TO_ABSOLUTE_POSITION:
198
      move_to_position_routine(int_args[0], int_args[1]);
199
      break;
200

  
166 201
      //Buzzer
167 202
    case BUZZER_INIT:
168 203
      buzzer_init();
trunk/code/projects/colonet/lib/colonet_defs.h
142 142
#define PRINTF 0x51
143 143
#define KILL_ROBOT 0x52
144 144

  
145
#define MOVE_TO_ABSOLUTE_POSITION 0x53
146
#define ROBOT_REQUEST_POSITION_FROM_SERVER 0x54
147
#define SERVER_REPORT_POSITION_TO_ROBOT 0x54
148

  
145 149
/* End low-level robot commands */
146 150

  
147 151

  
trunk/code/projects/colonet/ColonetServer/ColonetServer.cpp
85 85
    }
86 86
    return -1;
87 87
  }
88

  
88 89
  return 0;
89 90
}
90 91

  
......
126 127
      }
127 128

  
128 129
      if (optionsG.logging_enabled) {
129
	char log_buffer[LOG_BUFFER_LENGTH];
130
	snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s attempting to connect.",
131
                 inet_ntoa(client_addr.sin_addr));
132
	logger->log_string(LOG_TYPE_CONNECT, log_buffer);
130
        char log_buffer[LOG_BUFFER_LENGTH];
131
        snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s attempting to connect.",
132
          inet_ntoa(client_addr.sin_addr));
133
        logger->log_string(LOG_TYPE_CONNECT, log_buffer);
133 134
      }
134 135

  
135 136
      if (connection_pool.add_client(accept_socket) < 0) {
......
138 139
      }
139 140

  
140 141
      if (optionsG.logging_enabled) {
141
	char log_buffer[LOG_BUFFER_LENGTH];
142
        char log_buffer[LOG_BUFFER_LENGTH];
142 143
        snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s successfully added to connection pool.",
143 144
                 inet_ntoa(client_addr.sin_addr));
144 145
        logger->log_string(LOG_TYPE_CONNECT, log_buffer);
......
166 167
    return -1;
167 168
  }
168 169

  
169
  //("Put data in write buffer for client.\n");
170

  
171 170
  return 0;
172 171
}
173 172

  
trunk/code/projects/colonet/ColonetServer/Makefile
9 9
COLONETOBJECTS = $(COLONETFILES:.c=.o)
10 10
LOGGINGFILES = Log.cpp
11 11
LOGGINGOBJECTS = $(LOGGINGFILES:.cpp=.o)
12

  
12
9
13 13
VPATH = ../lib:../lib/colonet_wireless
14 14
INCLUDE_DIRS = ../lib/colonet_wireless ../lib ../../libwireless/lib ../lib/colonet_wireless includes
15 15
LIBRARY_DIRS = ../lib ../../libwireless/lib ../lib/colonet_wireless

Also available in: Unified diff