root / trunk / code / projects / mapping / python / robots.c @ 1438
History | View | Annotate | Download (1.7 KB)
1 | 902 | tachim | #include <stdlib.h> |
---|---|---|---|
2 | #include <wireless.h> |
||
3 | 932 | tachim | #include <wl_token_ring.h> |
4 | 902 | tachim | #include <string.h> |
5 | #include <stdio.h> |
||
6 | 934 | tachim | #include <unistd.h> |
7 | 902 | tachim | #include "robots.h" |
8 | |||
9 | 918 | tachim | #define CHANNEL 0xE |
10 | 932 | tachim | #define GROUP 1 |
11 | 918 | tachim | |
12 | 932 | tachim | void do_nothing(void); |
13 | 934 | tachim | void packet_receive(char type, int source, unsigned char* packet, int length); |
14 | 902 | tachim | |
15 | void make_listener()
|
||
16 | { |
||
17 | PacketGroupHandler *receiver; |
||
18 | printf("wl_init() returned %d\n", wl_init());
|
||
19 | 918 | tachim | wl_set_channel(CHANNEL); |
20 | 902 | tachim | receiver = malloc(sizeof(PacketGroupHandler));
|
21 | receiver->groupCode = GROUP; |
||
22 | 932 | tachim | receiver->handle_response = do_nothing; |
23 | receiver->timeout_handler = do_nothing; |
||
24 | 934 | tachim | receiver->handle_receive = packet_receive; |
25 | 902 | tachim | wl_register_packet_group(receiver); |
26 | } |
||
27 | |||
28 | 934 | tachim | void packet_receive(char type, int source, unsigned char* packet, int length) |
29 | 902 | tachim | { |
30 | 934 | tachim | /* stolen from cmar */
|
31 | char buffer[22]; |
||
32 | short x,y,ir1,ir2,ir3,ir4,ir5, n;
|
||
33 | x = ((short)packet[1] << 8) | (short)packet[0]; |
||
34 | y = ((short)packet[3] << 8) | (short)packet[2]; |
||
35 | ir1 = ((short)packet[9] << 8) | (short)packet[8]; |
||
36 | ir2 = ((short)packet[11] << 8) | (short)packet[10]; |
||
37 | ir3 = ((short)packet[13] << 8) | (short)packet[12]; |
||
38 | ir4 = ((short)packet[15] << 8) | (short)packet[14]; |
||
39 | ir5 = ((short)packet[17] << 8) | (short)packet[16]; |
||
40 | 902 | tachim | |
41 | 934 | tachim | char tarr[] = {packet[4],packet[5],packet[6],packet[7]}; |
42 | float *theta_ptr = (float *)tarr; |
||
43 | float theta = *theta_ptr;
|
||
44 | |||
45 | printf( "%d %d %f %d %d %d %d %d\n", x, y, theta,
|
||
46 | ir1, ir2, ir3, ir4, ir5); |
||
47 | buffer[0] = (char) source; |
||
48 | buffer[1] = (char) length; |
||
49 | buffer[2] = type;
|
||
50 | buffer[3] = 0; |
||
51 | memcpy ( buffer+4, packet, length);
|
||
52 | |||
53 | n = write(newsockfd, buffer, 22);
|
||
54 | bzero(buffer, 22);
|
||
55 | |||
56 | 902 | tachim | } |
57 | |||
58 | 934 | tachim | void do_nothing()
|
59 | 902 | tachim | { |
60 | 932 | tachim | return;
|
61 | } |