Project

General

Profile

Revision 157

Sweet stuff. Eugene use this. It's good.
(But not tested yet, should work, modular, works for all server side applications,
even those that aren't explicitly colonet related.)

View differences:

branches/slam/code/projects/colonet/DataRequests/robot/data_response.c
1 1
#include "data_response.h"
2
#include <dragonfly_lib.h>
2
#include "dragonfly_lib.h"
3 3
#include "wl_token_ring.h"
4 4
#include "wireless.h"
5 5

  
6 6

  
7 7
PacketGroupHandler pgh;
8 8

  
9
void handle_receive(char type, int source, unsigned char * packet, int length);
9
void handle_receive(char type, int source, unsigned char* packet, int length);
10 10

  
11 11
int generate_bom_packet(char** buf);
12 12
int generate_IR_packet(char** buf);
......
15 15
  range_init();
16 16
  pgh.timeout_handler = NULL;
17 17
  pgh.handle_response = NULL;
18
  pgh.handle_response = handle_receive;
18
  pgh.handle_receive = handle_receive;
19 19
  pgh.unregister = NULL;
20
  wl_register_packet_group(&pgh);
20 21
}
21 22

  
22 23
void handle_receive(char type, int source, unsigned char* packet, int length){
......
25 26
  switch(type){
26 27
  case BOM_TYPE:
27 28
    size = generate_bom_packet(&buf); 
28
    wl_send_robot_to_robot_packet(DATA_REQUEST_GROUP,BOM_TYPE,data,size,source,0);
29
    wl_send_robot_to_robot_packet(DATA_REQUEST_GROUP,BOM_TYPE,buf,size,source,0);
29 30
  case IR_TYPE:
30 31
    size = generate_IR_packet(&buf); 
31
    wl_send_robot_to_robot_packet(DATA_REQUEST_GROUP,IR_TYPE,data,size,source,0);
32
    wl_send_robot_to_robot_packet(DATA_REQUEST_GROUP,IR_TYPE,buf,size,source,0);
32 33
  case ENCODER_TYPE:
34
    break; 
33 35
    //Not yet supported.
34

  
35 36
  }
36 37
}
37 38

  
......
41 42
  wl_token_iterator_begin();
42 43
  while(wl_token_iterator_has_next() && i<=99){
43 44
    robot_id = wl_token_iterator_next();
44
    *buf[i++] = (char)((robot_id>>8) & 255);
45
    *buf[i++] = (char)(robot_id & 255);
46
    *buf[i++] = (char)(wl_token_get_my_sensor_reading(robot_id));
45
    (*buf)[i++] = (char)((robot_id>>8) & 0xFF);
46
    (*buf)[i++] = (char)(robot_id & 0xFF);
47
    (*buf)[i++] = (char)(wl_token_get_my_sensor_reading(robot_id));
47 48
  }
48 49
  //i is one greater than the index of the last byte... the size.
49 50
  return i;
branches/slam/code/projects/colonet/DataRequests/robot/Makefile
14 14
USE_WIRELESS = 1
15 15

  
16 16
# com1 = serial port. Use lpt1 to connect to parallel port.
17
AVRDUDE_PORT = com4
17
AVRDUDE_PORT = /dev/cu.usbserial-A4001hAU
18 18
#
19 19
#
20 20
###################################
branches/slam/code/projects/colonet/DataRequests/server/test_main.c
1 1
#include <stdlib.h>
2 2
#include <stdio.h>
3
#include <unistd.h>
3 4
#include "data_requests.h"
5
#include "wireless.h"
6
#include "wl_token_ring.h"
4 7

  
8
void IR_handler(unsigned char* data);
9
void bom_handler(BomNode* head);
10
void encoder_handler(unsigned char* data);
11

  
12
char bom_responded_flag;
13
char ir_responded_flag;
14
char encoder_responded_flag;
15

  
5 16
int main(void){
6
  printf("Hello\n");
7
  data_requests_init(NULL,NULL,NULL);
8
  return -1;
17
  wl_init();
18
  wl_token_ring_register(); 
19
  data_requests_init(bom_handler,IR_handler,encoder_handler);
20
  int robot_id;
21
  bom_responded_flag = 0;
22
  ir_responded_flag = 0;
23
  encoder_responded_flag = 0;
24
  while(1){
25
      wl_token_iterator_begin();
26
      printf("This far.\n");
27
      while(wl_token_iterator_has_next()){
28
        robot_id = wl_token_iterator_next();
29

  
30
        bom_responded_flag = 0;
31
        ir_responded_flag = 0;
32
        encoder_responded_flag = 0;
33
/*
34
        request_bom_data(robot_id);
35
        while(!bom_responded_flag){
36
          delay_ms(50);
37
        }
38
*/        
39
        request_IR_data(robot_id);
40
        while(!ir_responded_flag){
41
          usleep(50000);
42
        }
43
/*       
44
        request_encoder_data(robot_id);
45
        while(!encoder_responded_flag){
46
          delay_ms(50);
47
        }
48
*/
49
      }
50
  }
9 51
}
52

  
53
void IR_handler(unsigned char* data){
54
  char i;
55
  for(i=0;i<5;i++){
56
    printf("IR %i is %u\n\n",i,data[i]);
57
  }
58
  ir_responded_flag=1;
59
}
60

  
61
void bom_handler(BomNode* head){
62
  bom_responded_flag=1;
63
}
64

  
65
void encoder_handler(unsigned char* data){
66
  encoder_responded_flag=1;
67
}
68

  
branches/slam/code/projects/colonet/DataRequests/server/data_requests.c
27 27
  wl_register_packet_group(&pgh);
28 28
}
29 29

  
30

  
30 31
void request_bom_data(int robot_id){
31 32
  wl_send_robot_to_robot_packet(DATA_REQUEST_GROUP,BOM_TYPE,NULL,0,robot_id,0);
32 33
}
branches/slam/code/projects/colonet/DataRequests/server/data_requests.h
1

  
2
#ifndef _DATA_REQUESTS_H
3
#define _DATA_REQUESTS_H 
4

  
5 1
#define DATA_REQUEST_GROUP 23
6 2
#define BOM_TYPE 0
7 3
#define IR_TYPE 1
......
22 18
void request_IR_data(int robot_id);
23 19
void request_encoder_data(int robot_id);
24 20

  
25
#endif
branches/slam/code/projects/colonet/DataRequests/server/Makefile
8 8
COLONYROOT = ../../..
9 9
endif
10 10

  
11
CINCS = -I$(COLONYROOT)/code/lib/include/libdragonfly
12
CINCS += -L$(COLONYROOT)/code/lib/bin
13

  
14
all: $(TARGET)
15

  
11 16
$(TARGET): *.c  *.h
12
	$(CC) $(CFLAGS) $(TARGET).c -L$(COLONYROOT)/code/lib/bin -o $(TARGET) -lwireless
17
	$(CC) $(CFLAGS) *.c -I$(COLONYROOT)/code/lib/include/libdragonfly -I$(COLONYROOT)/code/lib/include/libwireless -L$(COLONYROOT)/code/lib/bin -o $(TARGET) -lwireless
13 18

  
14 19
clean:
15 20
	rm $(TARGET)

Also available in: Unified diff