Index: trunk/code/projects/hunter_prey/testbench/main.c
===================================================================
--- trunk/code/projects/hunter_prey/testbench/main.c	(revision 1465)
+++ trunk/code/projects/hunter_prey/testbench/main.c	(revision 1466)
@@ -62,11 +62,22 @@
     delay8.tv_sec = 2;
     delay8.tv_nsec = 800000000;
 
-    wl_set_com_port("/dev/ttyUSB1");
+    wl_set_com_port("/dev/ttyUSB0");
     // set up wireless
-    wl_basic_init_default();
-    wl_set_channel(channel);
+    ret = wl_basic_init_default();
 
+    if(ret) {
+      printf("ERROR: wl_basic_init_default returned %d\n", ret);
+      return ret;
+    }
+
+    ret = wl_set_channel(channel);
+
+    if(ret) {
+      printf("ERROR: set channel failed! %d\n", ret);
+      return ret;
+    }
+
     printf("Testing communications\n\n");
 
     // Receive TAG, send ACK
Index: trunk/code/projects/hunter_prey/main.c
===================================================================
--- trunk/code/projects/hunter_prey/main.c	(revision 1465)
+++ trunk/code/projects/hunter_prey/main.c	(revision 1466)
@@ -4,7 +4,7 @@
 #include "smart_run_around_fsm.h"
 #include "hunter_prey.h"
 
-#define CHAN 0xF
+#define CHAN 0xC
 #define TAG_PAUSE 2000
 
 #define ROBOT_HUNTER 0
Index: trunk/code/projects/hunter_prey/ref/main.c
===================================================================
--- trunk/code/projects/hunter_prey/ref/main.c	(nonexistent)
+++ trunk/code/projects/hunter_prey/ref/main.c	(revision 1466)
@@ -0,0 +1,129 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+#include "../../libwireless/lib/wl_basic.h"
+#include "../../libwireless/lib/wireless.h"
+#include "../hunter_prey.h"
+
+#define TYPE 42	// packet type for wireless communication
+#define ROBOTID 255 // make up a robot id because the PC doesn't have one
+
+void packet_receive(char type, int source, unsigned char* packet, int length);
+
+volatile unsigned int preyTime[20];
+volatile int preyBot=-1;
+
+void waitKey(void) {
+  unsigned char buf[10];
+
+  //read from stdin
+   while(read(0, buf, 10)==10) {
+     printf("!");
+     fflush(stdout);
+   }
+
+  while(getchar()==-1);
+}
+
+void print_stats(void) {
+
+  int i=0;
+
+  for(i=0;i<20;i++) {
+    printf("%5d ", preyTime[i]);
+  }
+
+  printf("\n");
+
+}
+
+int main(int argc, char *argv[])
+{
+    char send_buffer[2];    // holds data to send
+    int data_length;	// length of data received
+    unsigned char *packet_data;	// data received
+    int ret;
+    int i;
+
+    unsigned int channel = 0xF;
+
+    struct timespec delay, rem;
+
+    delay.tv_sec = 0;
+    delay.tv_nsec = 100000000;
+
+
+    if(argc > 1) {
+      channel = atoi(argv[1]);
+    }
+
+    printf("using wireless channel %d\n", channel);
+
+    wl_set_com_port("/dev/ttyUSB0");
+    // set up wireless
+    ret = wl_basic_init(&packet_receive);
+
+    if(ret) {
+      printf("ERROR: wl_basic_init failed. %d\n", ret);
+      return ret;
+    }
+    //wl_set_channel(channel);
+
+    for(i=0;i<16;i++) {
+      preyTime[i]=0;
+    }
+
+    ret = 0;    
+    i=0;
+
+    printf("ready\n");
+
+    //TODO: use rtc to make this more accurate
+    while(1) {
+      wl_do();
+
+      if(ret==0) {
+	ret = nanosleep(&delay, &rem);
+      }
+      else {
+	ret = nanosleep(&rem, &rem);
+      }
+
+      //update counts when we have waited at least enough time
+      if(ret == 0 && preyBot >= 0) {
+	preyTime[preyBot]++;
+	i++;
+      }
+
+      if(i%10==0) {
+	print_stats();
+      }
+    }
+
+    return 0;
+}
+
+void packet_receive(char type, int source, unsigned char* packet, int length)
+{
+
+  if(type==42 && length>=2){
+    if(packet[0] == HUNTER_PREY_ACTION_TAG) {
+      //TODO: check tag
+
+    }
+    else if(packet[0] == HUNTER_PREY_ACTION_ACK) {
+
+      preyBot = packet[1];
+      printf("bot %d is prey!\n", preyBot);
+
+    }
+    else {
+      printf("got invalid packet! %c%d\n", packet[0], packet[1]);
+    }
+  }
+  else {
+    printf("got unknown packet! type=%d, length=%d\n", type, length);
+  }
+}
+
Index: trunk/code/projects/hunter_prey/ref/Makefile
===================================================================
--- trunk/code/projects/hunter_prey/ref/Makefile	(nonexistent)
+++ trunk/code/projects/hunter_prey/ref/Makefile	(revision 1466)
@@ -0,0 +1,11 @@
+CC = gcc
+CFLAGS = -Wall -g
+
+all: ref
+
+ref: *.c ../../libwireless/lib/*.c 
+	$(CC) $(CFLAGS) *.c -L../../libwireless/lib -o ref -DWL_DEBUG -lwireless -lpthread -ggdb
+
+clean:
+	rm -f *.o ref ../lib/*.o
+
