Revision 366
The lib things were just because of a few recompilations.
Data requests project works for IR, the problems with IR were almost definitely the problems with the others (encoder / BOM data).
I'll fix the code for those next time, and then begin work on encoders.
Hopefully I'll be able to abstract the robots out completely and just work with raw data in a month or two.
data_requests.c | ||
---|---|---|
10 | 10 |
|
11 | 11 |
void receive_handle(char type, int source, unsigned char* packet, int length); |
12 | 12 |
|
13 |
void (*bom_handle)(BomNode* head); |
|
14 |
void (*IR_handle)(unsigned char* data);
|
|
15 |
void (*encoder_handle)(unsigned char* data); |
|
13 |
void (*bom_handle)(BomNode** head);
|
|
14 |
void (*IR_handle)(short** data);
|
|
15 |
void (*encoder_handle)(unsigned char** data);
|
|
16 | 16 |
|
17 |
void data_requests_init(void(*bom_data_handler)(BomNode* head), |
|
18 |
void(*IR_data_handler)(unsigned char* data),
|
|
19 |
void(*encoder_data_handler)(unsigned char* data)){ |
|
17 |
void data_requests_init(void(*bom_data_handler)(BomNode** head),
|
|
18 |
void(*IR_data_handler)(short** data),
|
|
19 |
void(*encoder_data_handler)(unsigned char** data)){
|
|
20 | 20 |
bom_handle = bom_data_handler; |
21 | 21 |
IR_handle = IR_data_handler; |
22 | 22 |
encoder_handle = encoder_data_handler; |
... | ... | |
43 | 43 |
wl_send_robot_to_robot_global_packet(DATA_REQUEST_GROUP,ENCODER_TYPE,NULL,0,robot_id,0); |
44 | 44 |
} |
45 | 45 |
|
46 |
void* pthread_handle(void* arg){ |
|
46 |
/*void* pthread_handle(void* arg){
|
|
47 | 47 |
RawData* data = (RawData*)arg; |
48 | 48 |
unsigned char* packet = data->packet; |
49 | 49 |
int length = data->length; |
50 | 50 |
char type = data->type; |
51 |
|
|
52 | 51 |
int i=0; |
53 | 52 |
BomNode* head; |
54 | 53 |
switch(type){ |
... | ... | |
72 | 71 |
break; |
73 | 72 |
|
74 | 73 |
case IR_TYPE: |
75 |
/*An IR packet consists of just the 5 bytes representing the IR |
|
76 |
values, in order.*/ |
|
77 |
if(length != 5){ |
|
78 |
//The packet is incomplete... bail. |
|
79 |
break; |
|
74 |
An IR packet consists of just the 5 bytes representing the IR |
|
75 |
values, in order. |
|
76 |
if(length != 10) break; |
|
77 |
short data[10]; |
|
78 |
for(i=0;i<5;i++){ |
|
79 |
data[i] = ((short)packet[2*i]<<8)+((short)packet[2*i+1]); |
|
80 | 80 |
} |
81 |
else{ |
|
82 |
unsigned char data[5]; |
|
83 |
for(i=0;i<5;i++){ |
|
84 |
data[i] = packet[i]; |
|
81 |
IR_handle(data); |
|
82 |
break; |
|
83 |
|
|
84 |
case ENCODER_TYPE: |
|
85 |
/*I have no idea, unsupported. |
|
86 |
break; |
|
87 |
} |
|
88 |
free(data->packet); |
|
89 |
free(data); |
|
90 |
return NULL; |
|
91 |
|
|
92 |
}*/ |
|
93 |
|
|
94 |
|
|
95 |
void receive_handle(char type, int source, unsigned char* packet, int length){ |
|
96 |
int i=0; |
|
97 |
BomNode* head; |
|
98 |
printf("Packet contents: [ "); |
|
99 |
for(i=0;i<length;i++){ |
|
100 |
printf("%i ",packet[i]); |
|
101 |
} |
|
102 |
switch(type){ |
|
103 |
|
|
104 |
case BOM_TYPE: |
|
105 |
printf("I shouldn't be here during testing\n"); |
|
106 |
head = malloc(sizeof(BomNode)); |
|
107 |
BomNode* iter = head; |
|
108 |
|
|
109 |
while(i<length){ |
|
110 |
iter->robot_id = ((short)packet[i]<<8) + ((short)packet[i+1]); |
|
111 |
i+=2; |
|
112 |
iter->value = packet[i++]; |
|
113 |
if(i<length){ |
|
114 |
iter-> next = malloc(sizeof(BomNode)); |
|
115 |
iter = iter->next; |
|
85 | 116 |
} |
86 |
IR_handle(data); |
|
87 | 117 |
} |
118 |
bom_handle(head); |
|
88 | 119 |
break; |
89 | 120 |
|
121 |
case IR_TYPE: |
|
122 |
/*An IR packet consists of just the 10 bytes representing the IR |
|
123 |
values as shorts, in order.*/ |
|
124 |
if(length != 10) break; |
|
125 |
short* data = malloc(5*sizeof(short)); |
|
126 |
for(i=0;i<5;i++){ |
|
127 |
data[i]= ((((short)packet[2*i])<<8)&0xff00 ) | ( (short)(packet[2*i+1])&255); |
|
128 |
} |
|
129 |
|
|
130 |
IR_handle(&data); |
|
131 |
break; |
|
132 |
|
|
90 | 133 |
case ENCODER_TYPE: |
91 | 134 |
/*I have no idea, unsupported.*/ |
92 | 135 |
break; |
93 | 136 |
} |
94 |
free(data->packet); |
|
95 |
free(data); |
|
96 | 137 |
} |
97 | 138 |
|
98 |
void receive_handle(char type, int source, unsigned char* packet, int length){ |
|
139 |
|
|
140 |
/*void receive_handle(char type, int source, unsigned char* packet, int length){ |
|
99 | 141 |
|
100 | 142 |
RawData* data = malloc(sizeof(RawData)); |
101 | 143 |
if(!data){ |
102 | 144 |
return; |
103 | 145 |
} |
146 |
|
|
104 | 147 |
unsigned char* newPacket = malloc(length); |
105 | 148 |
memcpy(newPacket, packet,length); |
106 | 149 |
|
107 |
|
|
108 | 150 |
data->packet=newPacket; |
109 | 151 |
data->source=source; |
110 | 152 |
data->length=length; |
... | ... | |
112 | 154 |
|
113 | 155 |
dr_thread = malloc(sizeof(pthread_t)); |
114 | 156 |
pthread_create(dr_thread,NULL,pthread_handle,(void*)data); |
115 |
} |
|
157 |
}*/ |
Also available in: Unified diff