root / trunk / code / projects / hunter_prey / testbench / main.c @ 1434
History | View | Annotate | Download (1.85 KB)
1 | 1434 | alevkoy | /* testbench for Lab 2 first checkpoint
|
---|---|---|---|
2 | * determine whether robot under test complies with communication standard
|
||
3 | * to be conducted using XBee USB dongle
|
||
4 | */
|
||
5 | 1433 | alevkoy | |
6 | 1434 | alevkoy | /* The tests shall be as follows
|
7 | * Receive a TAG, send an ACK
|
||
8 | * - Robot passes if it sends a tag and changes to prey state
|
||
9 | * Send a TAG, receive an ACK
|
||
10 | * - Pass if sends ACK, changes to wait state, then hunter state
|
||
11 | * Receive TAG, send slightly delayed (< 1s) ACK
|
||
12 | * - Pass if sends one and only one TAG packet (and changes state appropriately)
|
||
13 | * Receive TAG, do not send ACK
|
||
14 | * - Pass if sends one and only one TAG packet (and does not change state)
|
||
15 | * Receive TAG, send ACK to incorrect robot
|
||
16 | * - Pass if goes to wait state, then back to hunter state
|
||
17 | * Simulate TAG from robot A to B, ACK from B to A
|
||
18 | * - Pass if ignores TAG, goes to wait then hunter in response to ACK
|
||
19 | */
|
||
20 | |||
21 | 1433 | alevkoy | #include <stdlib.h> |
22 | #include <stdio.h> |
||
23 | #include <wl_basic.h> |
||
24 | #include "hunter_prey.h" |
||
25 | |||
26 | 1434 | alevkoy | #define CHANNEL 0xF // channel for wireless communication |
27 | #define TYPE 42 // packet type for wireless communication |
||
28 | |||
29 | 1433 | alevkoy | void main()
|
30 | { |
||
31 | 1434 | alevkoy | char send_buffer[2]; // holds data to send |
32 | int data_length; // length of data received |
||
33 | unsigned char *packet_data; // data received |
||
34 | 1433 | alevkoy | |
35 | 1434 | alevkoy | // set up wireless
|
36 | wl_basic_init_default(); |
||
37 | wl_set_channel(CHANNEL); |
||
38 | wl_set_com("/dev/ttyUSB0");
|
||
39 | |||
40 | printf("Testing communications\n\n");
|
||
41 | |||
42 | // Receive TAG, send ACK
|
||
43 | printf("Receive TAG, send ACK... ");
|
||
44 | // Wait until we receive a packet
|
||
45 | while (!(packet_data = wl_basic_do_default(&data_length)));
|
||
46 | |||
47 | if (data_length > 2) |
||
48 | printf("Excessive TAG packet length... ");
|
||
49 | |||
50 | if (data_length >= 2 && packet_data[0] == HUNTER_PREY_ACTION_TAG) |
||
51 | { |
||
52 | // send back an ACK
|
||
53 | send_buffer[0] = HUNTER_PREY_ACTION_TAG;
|
||
54 | send_buffer[1] = packet_data[1]; |
||
55 | wl_basic_send_global_packet(TYPE, send_buffer, 2);
|
||
56 | |||
57 | printf("PASSED");
|
||
58 | } |
||
59 | else
|
||
60 | printf("FAILED");
|
||
61 | 1433 | alevkoy | } |