Index: main.c
===================================================================
--- main.c	(revision 1437)
+++ main.c	(revision 1438)
@@ -4,29 +4,33 @@
  */
 
 /* The tests shall be as follows
- * Receive a TAG, send an ACK
+ * 1. Receive a TAG, send an ACK
  * - Robot passes if it sends a tag and changes to prey state
- * Send a TAG, receive an ACK
+ * 2. Send a TAG, receive an ACK
  * - Pass if sends ACK, changes to wait state, then hunter state
- * Receive TAG, send slightly delayed (< 1s) ACK
+ * 3. Receive TAG, send slightly delayed (< 1s) ACK
  * - Pass if sends one and only one TAG packet (and changes state appropriately)
- * Receive TAG, do not send ACK
+ * 4. Receive TAG, do not send ACK
  * - Pass if sends one and only one TAG packet (and does not change state)
- * Receive TAG, send ACK to incorrect robot
+ * 5. Receive TAG, send ACK to incorrect robot
  * - Pass if goes to wait state, then back to hunter state
- * Simulate TAG from robot A to B, ACK from B to A
+ * 6. Simulate TAG from robot A to B, ACK from B to A
  * - Pass if ignores TAG, goes to wait then hunter in response to ACK
  */
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <time.h>
 #include <wl_basic.h>
+#include <wireless.h>
+#include "../../libwireless/lib/wireless.h"
 #include "hunter_prey.h"
 
 #define CHANNEL 0xF // channel for wireless communication
 #define TYPE 42	// packet type for wireless communication
+#define ROBOTID 255 // make up a robot id because the PC doesn't have one
 
-void main()
+int main(int argc, char *argv[])
 {
     char send_buffer[2];    // holds data to send
     int data_length;	// length of data received
@@ -35,7 +39,7 @@
     // set up wireless
     wl_basic_init_default();
     wl_set_channel(CHANNEL);
-    wl_set_com("/dev/ttyUSB0");
+    wl_set_com_port("/dev/ttyUSB0");
 
     printf("Testing communications\n\n");
 
@@ -50,13 +54,115 @@
     if (data_length >= 2 && packet_data[0] == HUNTER_PREY_ACTION_TAG)
     {
 	// send back an ACK
-	send_buffer[0] = HUNTER_PREY_ACTION_TAG;
+	send_buffer[0] = HUNTER_PREY_ACTION_ACK;
 	send_buffer[1] = packet_data[1];
 	wl_basic_send_global_packet(TYPE, send_buffer, 2);
 
-	printf("PASSED");
+	printf("PASSED\n");
     }
     else
-	printf("FAILED");
+	printf("FAILED\n");
+
+    // Send a TAG, receive an ACK
+    printf("Send TAG, wait for ACK... ");
+
+    send_buffer[0] = HUNTER_PREY_ACTION_TAG;
+    send_buffer[1] = ROBOTID;
+    // robot number stays the same
+    wl_basic_send_global_packet(TYPE, send_buffer, 2);
+
+    // Wait for an ACK
+    delay_ms(800);  // wait for 800 ms before sending ACK
+    packet_data = wl_basic_do_default(&data_length);
+
+    // Check ACK for presence and correctness
+    if (!packet_data || data_length < 2 ||
+	    packet_data[0] != HUNTER_PREY_ACTION_ACK ||
+	    packet_data[1] != ROBOTID)
+	printf("FAILED\n");
+    else
+	printf("PASSED\n");
+
+    // Receive a TAG, send a delayed ACK
+    printf("Receive a TAG, send a delayed ACK... ");
+
+    while (!(packet_data = wl_basic_do_default(&data_length)));
+
+    if (data_length >= 2 && packet_data[0] == HUNTER_PREY_ACTION_TAG)
+    {
+	// wait before sending ACK back
+	delay_ms(900);
+
+	if (wl_basic_do_default(&data_length))
+	    printf("FAILED\n");
+	else
+	{
+	    // send packet
+	    send_buffer[0] = HUNTER_PREY_ACTION_ACK;
+	    send_buffer[1] = packet_data[1];
+	    wl_basic_send_global_packet(TYPE, send_buffer, 2);
+
+	    printf("PASSED\n");
+	}
+    }
+
+    else
+	printf("FAILED\n");
+
+    // Receive a TAG, never send an ACK
+    printf("Receive TAG, never send ACK... ");
+
+    while (!(packet_data = wl_basic_do_default(&data_length)));
+
+    if (data_length >= 2 && packet_data[0] == HUNTER_PREY_ACTION_TAG)
+    {
+	delay_ms(5000);	// wait 5 seconds to see if they TAG again
+
+	if (wl_basic_do_default(&data_length))
+	    printf("FAILED\n");
+	else
+	    printf("PASSED\n");
+    }
+
+    else
+	printf("FAILED\n");
+
+    // Receive TAG, send ACK to incorrect robot
+    printf("Receive TAG, send ACK to incorrect robot... ");
+
+    // Wait until we receive a packet
+    while (!(packet_data = wl_basic_do_default(&data_length)));
+
+    if (data_length >= 2 && packet_data[0] == HUNTER_PREY_ACTION_TAG)
+    {
+	// send back an ACK
+	send_buffer[0] = HUNTER_PREY_ACTION_ACK;
+	send_buffer[1] = packet_data[1] + 1;
+	wl_basic_send_global_packet(TYPE, send_buffer, 2);
+
+	printf("PASSED\n");
+    }
+    else
+	printf("FAILED\n");
+
+    // Simulate TAG from robot A to B, ACK from robot B to A
+    printf("Send TAG from robot A to B, ACK from B to A... ");
+
+    // TAG
+    send_buffer[0] = HUNTER_PREY_ACTION_TAG;
+    send_buffer[1] = packet_data[1] - 1;    // robot other than testee
+    wl_basic_send_global_packet(TYPE, send_buffer, 2);
+
+    // ACK
+    send_buffer[0] = HUNTER_PREY_ACTION_ACK;
+    // send_buffer[1] stays the same
+    wl_basic_send_global_packet(TYPE, send_buffer, 2);
+
+    if (wl_basic_do_default(&data_length))
+	printf("FAILED\n");
+    else
+	printf("PASSED\n");
+
+    return 0;
 }
 
