Revision 1434 trunk/code/projects/hunter_prey/testbench/main.c
| main.c (revision 1434) | ||
|---|---|---|
| 1 |
// testbench for Lab 2 first checkpoint |
|
| 2 |
// determine whether robot under test complies with communication standard |
|
| 3 |
// to be conducted using XBee USB dongle |
|
| 1 |
/* 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 |
*/ |
|
| 4 | 5 |
|
| 6 |
/* 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 |
|
|
| 5 | 21 |
#include <stdlib.h> |
| 6 | 22 |
#include <stdio.h> |
| 7 | 23 |
#include <wl_basic.h> |
| 8 | 24 |
#include "hunter_prey.h" |
| 9 | 25 |
|
| 26 |
#define CHANNEL 0xF // channel for wireless communication |
|
| 27 |
#define TYPE 42 // packet type for wireless communication |
|
| 28 |
|
|
| 10 | 29 |
void main() |
| 11 | 30 |
{
|
| 31 |
char send_buffer[2]; // holds data to send |
|
| 32 |
int data_length; // length of data received |
|
| 33 |
unsigned char *packet_data; // data received |
|
| 12 | 34 |
|
| 35 |
// 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");
|
|
| 13 | 61 |
} |
| 14 | 62 |
|
Also available in: Unified diff