Project

General

Profile

Revision 1224

Added by Rich Hong about 15 years ago

Parallelized Master and Server

View differences:

master.c
5 5
//#include <unistd.h>
6 6

  
7 7
#define GROUP 1
8
#define TYPE 0
9
#define ACK 1
8
#define MOTOR 0
9
#define ENCODER 1
10 10

  
11
#define SENDER 1
12
#define RECEIVER 0
13

  
11 14
unsigned char data[4];
12 15

  
13 16
sentCount = 0;
14
char ack = 0;
17
char position = 0;
15 18

  
16 19
void packet_receive (char type, int source, unsigned char* packet, int length);
17 20

  
18 21
PacketGroupHandler packetHandler = {GROUP, 0, 0, &packet_receive, 0};
19 22

  
20 23
void packet_receive (char type, int source, unsigned char* packet, int length) {
21
	//orb_set_color(YELLOW);
22
		
23
	//send to server
24
	//lcd_clear_screen();
25
	//lcd_puts("Writing to server");
26
	usb_putc(packet[0]);
27
	//lcd_puti(1);
28
	usb_putc(packet[1]);
29
	//lcd_puti(2);
30
	usb_putc(packet[2]);
31
	//lcd_puti(3);
32
	usb_putc(packet[3]);
33
	//lcd_puti(4);
34
	//lcd_clear_screen();
35
	//lcd_puts("Reading from server");
36 24

  
37
	//Read in from server
38
	data[0] = usb_getc(); 
39
	//lcd_puti(1);
40
	data[1] = usb_getc();
41
	//lcd_puti(2);
42
	data[2] = usb_getc();
43
	//lcd_puti(3);
44
	data[3] = usb_getc();
45
	//lcd_puti(4);
46
	  
25
	if(type == ENCODER)
26
	{
27
		usb_putc(packet[0]);
28
		usb_putc(packet[1]);
29
		usb_putc(packet[2]);
30
		usb_putc(packet[3]);
31
	}
47 32
	
48
	wl_send_global_packet(GROUP, TYPE, data, 4, 0);
49
		
50
	//lcd_clear_screen();
51
	//lcd_puts("Sent ");
52
	//lcd_puti(sentCount);
53
	//sentCount++;
54
	//orb_set_color(GREEN);
55 33
}
56 34

  
57 35
int main (void) {
58
  	//dragonfly_init(SERIAL | USB | COMM | ORB | ANALOG | MOTORS | BUZZER);
36

  
59 37
	dragonfly_init(ALL_ON);
60 38
	wl_init();
61 39
	lcd_init();
62
	lcd_puts("S");
63 40

  
64
//	orb_set_color(RED);
41
	lcd_puts("STARTING");
42
	position = usb_getc();
43
	lcd_puts("position is ");
44
	lcd_puti(position);
65 45

  
66
//  	wl_register_packet_group(&packetHandler);
67
	
68
  //      orb_set_color(YELLOW);	
69
	//Read in from server
70
//	delay_ms(1000);
71
	lcd_puts("starting init");
72
	data[0] = usb_getc(); 
73
	//motor1_set(0,200);
74
	data[1] = usb_getc();
75
	//motor2_set(0,200);
76
	data[2] = usb_getc();
77
	//motor1_set(1,200);
78
	data[3] = usb_getc();
79
	
80
	lcd_puts("Done with init\n");
81
	wl_register_packet_group(&packetHandler);
82
	//motor2_set(1,200);
83
	
84
//	orb_set_color(PURPLE);
85
	//packet_receive(TYPE, 0, data, 4);
46
	if(position == SENDER)
47
	{
48
		//Read in from server
49
		lcd_puts("starting init");
50
		data[0] = usb_getc(); 
51
		data[1] = usb_getc();
52
		data[2] = usb_getc();
53
		data[3] = usb_getc();
54
		
55
		lcd_puts("Done with init\n");
86 56

  
87
	wl_send_global_packet(GROUP, TYPE, data, 4, 0);
88
	
89
	lcd_clear_screen();
90
	lcd_puts("Sent first wireless Packet");
91
	sentCount++;
92
//	orb_set_color(GREEN);
57
		wl_send_global_packet(GROUP, MOTOR, data, 4, 0);
58
	}
59
	else
60
	{
61
		wl_register_packet_group(&packetHandler);
62
	}
63

  
64
//	lcd_clear_screen();
93 65
  while (1) {
94
	 // char vel[4] = {170, 0, 170, 1};
95
	 // wl_send_global_packet(GROUP, TYPE, vel, 4, 0);	  
66
  if(position == SENDER)
67
  {
68
		data[0] = usb_getc(); 
69
		data[1] = usb_getc();
70
		data[2] = usb_getc();
71
		data[3] = usb_getc();
72
		wl_send_global_packet(GROUP, MOTOR, data, 4, 0);
73
}	
74

  
96 75
	  wl_do();
97 76
  }
98 77
  

Also available in: Unified diff