Index: branches/wireless/code/lib/include/libwireless/wireless.h
===================================================================
--- branches/wireless/code/lib/include/libwireless/wireless.h	(revision 1616)
+++ branches/wireless/code/lib/include/libwireless/wireless.h	(revision 1617)
@@ -1,6 +1,6 @@
 /**
- * Copyright (c) 2007 Colony Project
- *
+ * Copyright (c) 2009 Colony Project
+ * 
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
  * files (the "Software"), to deal in the Software without
@@ -9,10 +9,10 @@
  * copies of the Software, and to permit persons to whom the
  * Software is furnished to do so, subject to the following
  * conditions:
- *
+ * 
  * The above copyright notice and this permission notice shall be
  * included in all copies or substantial portions of the Software.
- *
+ * 
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -25,140 +25,176 @@
 
 /**
  * @file wireless.h
- * @brief Contains definitions for the wireless library.
+ * @brief Contains definitions for using the wireless library
  *
- * Contains functions for the wireless library.
+ * Contains definitions for interfacing with the 
+ * wireless library.
  *
- * @author Brian Coltin, Colony Project, CMU Robotics Club
+ * @author Colony Project, CMU Robotics Club
  **/
 
 #ifndef WIRELESS_H
 #define WIRELESS_H
 
-//Note: If this is raised above 16, we will need to do
-//something about frame numbers for TX Status packets.
-/**
- * The maximum number of packet groups.
- **/
-//TODO: a PacketGroupHandler is at least 10 bytes (I don't know if function pointers are 2 bytes
-// or 4 bytes).  That means that in the c file, your array of packet groups is at least 160 bytes.
-// Normally that might be fine (the robot's avr chips have 4k SRAM), but austin's chip only has
-// 1k SRAM, so if this number can be reduced or if the size of the struct could be reduced, that would be a plus.
-#define WL_MAX_PACKET_GROUPS 16
+// need this for C99 int types
+#ifndef STDINT_H
+#define STDINT_H
+#include <stdint.h>
+#endif
 
+
 /**
  * @defgroup wireless Wireless
- * @brief Wireless definitions.
+ * @brief Interface with the wireless library
  *
- * Contains functions and definitions for dealing with wireless functionality.<br><br>
+ * Interface with the wireless library.
  *
- * The wireless library provides a modular method for dealing with
- * wireless packets, by allowing packet groups to be registered.
- * A packet group is a collection of packets which share a packet
- * group code. Each packet in the group also has a type. A packet
- * group code and type are sent with each packet. When a packet
- * with a group code registered in the wireless library is
- * received, the corresponding event handler is called. The
- * event handler uses the packet type and other information
- * stored in the packet to respond.<br><br>
- *
- * This architecture allows different wireless functionality to be
- * defined and handled separately, making it simpler and more
- * efficient to take advantage of the XBee's wireless functionality.
- *
  * @{
  **/
+ 
+/**@defgroup wl_defines Public Constants
+ * @{ **/
+ 
+/**@brief basic group code **/
+#define BASIC UINT8_C(0)
 
+/**@brief global scope **/
+#define GLOBAL UINT8_C(0)
+
+/**@brief local pan scope **/
+#define PAN UINT8_C(1)
+
+/**@brief broadcast address **/
+#define BROADCAST UINT16_C(0xFFFF)
+
+/**@brief reliable (TCP) mode **/
+#define RELIABLE UINT8_C(0)
+
+/**@brief fast (UDP) mode **/
+#define FAST UINT8_C(1)
+
+/**@brief standard priority **/
+#define NORMAL_PRIORITY UINT8_C(0)
+
+/**@brief high priority, handle immediately **/
+#define HIGH_PRIORITY UINT8_C(1)
+
+/**@brief packet still in sending phase **/
+#define SENDING UINT8_C(0)
+
+/**@brief packet was send successfully **/
+#define ACK_OK UINT8_C(1)
+
+/**@brief packet failure - no acknowledgment **/
+#define ACK_FAILURE UINT8_C(2)
+
+/**@brief packet failure - network too busy **/
+#define CCA_FAILURE UINT8_C(3)
+
+/**@brief packet handler function pointer type **/
+#define FUNC func
+
+/**@brief packet handler function pointer type **/
+#define FNPTR void (*FUNC)(uint8_t* data,uint8_t length,uint8_t source)
+
+// TODO: this max may be too big b/c the packet handler array stores 3*MAX_PACKET_GROUPS bytes 
+/**@brief maximum number of packet groups, size of handler array **/
+#define MAX_PACKET_GROUPS UINT8_C(16)
+
+/**@brief init_flag when library has not been initialized **/
+#define INIT_NO UINT8_C(0)
+
+/**@brief init_flag when library has been initialized **/
+#define INIT_YES UINT8_C(1)
+
+/**@brief numer of reliable sending retries **/
+#define NUM_RETRIES UINT8_C(3)
+
+/**@} **/ // end defines group
+
 /**
  * @struct PacketGroupHandler
  * A PacketGroupHandler represents a packet group, and is used to
  * register a packet group with the wireless library. It contains
- * handlers for various events which can occur related to a packet
- * group.
+ * a function pointer to the packet handler function and the priority
+ * of the packet group.
  **/
-//TODO: the order of member variables in this struct should be changed in case the compile packs the struct
-// In order to achieve the best packing, the variables should be listed in order of decreasing memory size.
-// Thus, pointers should be first, followed by int, followed by char.
-typedef struct
-{
-	/**
-	 * The group code for this packet group. This number
-	 * must be unique. The maximum number of packet groups
-	 * is defined by WL_MAX_PACKET_GROUPS.
-	 **/
-  //TODO: if this number must be less than or equal to WL_MAX_PACKET_GROUPS, don't you only need
-  // one byte for it and it can be made an unsigned char?
-	unsigned int groupCode;
+typedef struct {
+    
+    // function pointer of handler for this packet group
+    FNPTR;
 
-	/**
-	 * Called every half second (not in interrupt,
-	 * but in wl_do).
-	 **/
-	void (*timeout_handler) (void);
+    // priority for this packet group
+    uint8_t priority;
+    
+} PacketGroupHandler;
 
-	/**
-	 * Called when a transmit status packet is received
-	 * from the XBee where the first four bits of the frame
-	 * are  the group code.
-	 *
-	 * @param frame the last four bits of the frame
-	 * @param received is true if we received an ack, 0 if
-	 * we did not.
-	 **/
-	void (*handle_response) (int frame, int received);
+static PacketGroupHandler wl_packet_handlers[MAX_PACKET_GROUPS];
 
-	/**
-	 * Called when we receive a packet from this group.
-	 *
-	 * @param type the packet type
-	 * @param source the 16-bit address of the XBee this
-	 * packet was sent from
-	 * @param packet the packet received
-	 * @param length the length of the packet
-	 **/
-	void (*handle_receive) (char type, int source, unsigned char* packet, int length);
+/**@defgroup wl_functions Public API Functions 
+ * @{ **/
+ 
+// the init function
 
-	/**
-	 * Called for any cleanup when the network is turned off.
-	 **/
-	void (*unregister) (void);
+/**@brief Initialize wireless. **/
+int8_t wl_init(void);
 
-} PacketGroupHandler;
+/**@brief Terminate wireless. **/
+int8_t wl_terminate(void);
 
-/**@brief Initialize the wireless library **/
-int wl_init(void);
-/**@brief Uninitialize the wireless library **/
-void wl_terminate(void);
-/**@brief Perform wireless library functionality **/
-void wl_do(void);
-/**@brief Register a packet group with the wireless library **/
-void wl_register_packet_group(PacketGroupHandler* h);
-/**@brief Unregister a packet group with the wireless library **/
-void wl_unregister_packet_group(PacketGroupHandler* h);
 
-/**@brief Send a packet to a specific robot in any PAN **/
-int wl_send_robot_to_robot_global_packet(char group, char type, char* data, int len, int dest, char frame);
-/**@brief Send a packet to a specific robot in our PAN **/
-int wl_send_robot_to_robot_packet(char group, char type, char* data, int len, int dest, char frame);
-/**@brief Send a packet to all robots **/
-int wl_send_global_packet(char group, char type, char* data, int len, char frame);
-/**@brief Send a packet to all robots in our PAN **/
-void wl_send_pan_packet(char group, char type, char* data, int len, char frame);
+// the send functions
 
-/**@brief Set the PAN we are using **/
-int wl_set_pan(int pan);
-/**@brief Get the PAN we are using **/
-int wl_get_pan(void);
-/**@brief Set the channel we are using **/
-int wl_set_channel(int channel);
-/**@brief Get the channel we are using **/
-int wl_get_channel(void);
-/**@brief Get the 16-bit address of the XBee module **/
-int wl_get_xbee_id(void);
-/**@brief Set the com port on a computer, undefined on the robot.**/
-void wl_set_com_port(char* port);
+/**@brief The core send function. This will take all possible arguments and send all types of packets. **/
+int16_t wl_send(uint8_t *data, uint8_t length, uint8_t group, uint8_t scope, uint16_t dest, uint8_t mode);
 
-/** @} **/ // end defgroup
+/**@brief Wrapper for core send function that will send a global packet across the current channel. **/
+int16_t wl_send_global(uint8_t *data, uint8_t length, uint8_t group);
 
+/**@brief Wrapper for core send function that will send a packet across the current channel on the current pan. **/
+int16_t wl_send_pan(uint8_t *data, uint8_t length, uint8_t group);
+
+/**@brief Wrapper for core send function that will send a packet across the current channel to a specific robot. **/
+int16_t wl_send_robot(uint8_t *data, uint8_t length, uint8_t group, uint16_t dest, uint8_t mode);
+
+/**@brief Default (i.e. basic) send wrapper. **/
+int16_t wl_send_basic(uint8_t *data, uint8_t length);
+
+
+// the ack function
+
+/**@brief Returns the number of acknowledgment errors. **/
+uint8_t wl_ack_error(void);
+
+/**@brief Checks a specific packet for the acknowledgement status. **/
+int8_t wl_ack_check(uint8_t packet);
+
+/**@brief Resets acknowledgement statistics back to zero. **/
+void wl_ack_reset(void);
+
+
+// the receive functions
+
+/**@brief The main receive function.  Dispatches packets for registered handlers and returns next basic packet if available. **/
+int8_t wl_get(char *data, uint8_t length);
+
+/**@brief Returns the next basic packet if available. **/
+int8_t wl_get_basic(char *data, uint8_t length);
+
+/**@brief Dispatches packets for registered handlers. **/
+int8_t wl_dispatch(void);
+
+
+// the group register function
+
+/**@brief Function to register new packet handlers (for non-default groups only). **/
+int8_t wl_register_handler(uint8_t group, FNPTR, uint8_t priority);
+
+/**@brief Function to unregister existing packet handlers (for non-default groups only). **/
+int8_t wl_unregister_handler(uint8_t group);
+
+/**@} **/ //end functions group
+
+/**@} **/ //end wireless group
+
 #endif
-
Index: branches/wireless/code/lib/include/libwireless/wl_defs.h
===================================================================
--- branches/wireless/code/lib/include/libwireless/wl_defs.h	(revision 1616)
+++ branches/wireless/code/lib/include/libwireless/wl_defs.h	(revision 1617)
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2007 Colony Project
+ * Copyright (c) 2009 Colony Project
  * 
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
@@ -27,15 +27,32 @@
  * @file wl_defs.h
  * @brief Definitions for Wireless
  *
- * Contains definitions for wireless packet groups, packet types,
- * debugging information, etc.
+ * Contains definitions for wireless, debugging information, etc.
  *
- * @author Brian Coltin, Colony Project, CMU Robotics Club
+ * @author Colony Project, CMU Robotics Club
  **/
 
 #ifndef WL_DEFS_H
 #define WL_DEFS_H
 
+// create main wireless page documentation
+
+/** @mainpage The Wireless Library
+ * 
+ * This is the documentation for the Colony wireless library.\n\n
+ * Xbee documentation can be found under @ref xbee \n
+ * Higher level wireless documentation can be found under @ref wireless \n
+ **/
+
+
+// need this for C99 int types
+#ifndef STDINT_H
+#define STDINT_H
+#include <stdint.h>
+#endif
+
+// ***** TODO: these next two defines should be moved to makefile options
+
 //comment out this line if using a computer hooked up to an xbee
 //#define ROBOT
 
@@ -42,55 +59,84 @@
 //uncomment this line for debug information
 //#define WL_DEBUG
 
-//return value definitions
+/**@addtogroup wireless 
+ * @{ **/
+ 
+/**@defgroup wl_error Error Codes
+ * @{ **/
+ 
+/** @brief Success **/
+#define WL_SUCCESS INT8_C(0)
+
 /** @brief Error code for init failure **/
-#define WL_ERROR_INIT_FAILED 1
+#define WL_ERROR_INIT_FAILED INT8_C(-1) 
+
 /** @brief Error code for duplicate init calls **/
-#define WL_ERROR_INIT_ALREADY_INITD 2
+#define WL_ERROR_INIT_ALREADY_INITD INT8_C(-2) 
+
 /** @brief Error code for not calling init **/
-#define WL_ERROR_LIBRARY_NOT_INITD 3
+#define WL_ERROR_LIBRARY_NOT_INITD INT8_C(-3) 
 
-// Packet Groups and Types
+/** @brief Error code for failed termination **/
+#define WL_ERROR_TERMINATION_FAILED INT8_C(-4)
 
-// Error group
-#define WL_ERROR_GROUP 1
+/** @brief Error code for failed packet group registration **/
+#define WL_ERROR_FAILED_REGISTRATION INT8_C(-5)
 
-#define WL_ERROR_STRING_TYPE 1
+/** @brief Error code for failed packet group registration **/
+#define WL_ERROR_FAILED_UNREGISTRATION INT8_C(-6)
 
-// Token Ring group
-#define WL_TOKEN_RING_GROUP 2
+/** @brief Error in arguments **/
+#define WL_ERROR_ARGUMENT INT8_C(-7)
 
-#define WL_TOKEN_PASS 1
-#define WL_TOKEN_SENSOR_MATRIX 2
-#define WL_TOKEN_BOM_ON 3
-#define WL_TOKEN_JOIN 4
-#define WL_TOKEN_JOIN_ACCEPT 5
+/** @brief Error code for send failure **/
+#define WL_ERROR_SEND INT8_C(-10)
 
-// timing constants
-#ifndef FIREFLY
-#define BOM_DELAY 100
-#else
-#define BOM_DELAY 200
-#endif
+/** @brief Error code for a bad group number **/
+#define WL_ERROR_BAD_GROUP INT8_C(-11)
 
-#define DEATH_DELAY 4
-#define JOIN_DELAY 8
+/** @brief Error code for a bad scope **/
+#define WL_ERROR_SCOPE INT8_C(-12)
 
+/** @brief Error code for a bad robot address **/
+#define WL_ERROR_ADDRESS INT8_C(-13)
+
+/** @brief Error code for a bad mode **/
+#define WL_ERROR_MODE INT8_C(-14)
+
+/** @brief Error code for received paacket destination too small for received packet **/
+#define WL_ERROR_TOO_SMALL INT8_C(-15)
+
+/** @brief Error code for sending buffer full (the packet was sent, but no retries will be made). **/
+#define WL_ERROR_SENDING_BUFFER_FULL INT8_C(-16)
+
+/** @brief Error code for failed xbee command **/
+#define WL_ERROR_XBEE_COMMAND INT8_C(-17)
+
+/** @brief Error code for failed 16bit xbee command **/
+#define WL_ERROR_XBEE_COMMAND_16BIT 0xFEFE
+
+/** @brief Error code for bad baud rate **/
+#define WL_ERROR_BAUD INT8_C(-18)
+
+/**@} */ // end error group
+
+// TODO: is this a good size?
+/*Buffer sizes*/
+#define PACKET_BUFFER_SIZE	128
+
+/**@} */ // end wireless group
+
 #ifdef WL_DEBUG
 
 #ifdef ROBOT
 #include <serial.h>
-#endif
-
-#ifdef ROBOT
 #define WL_DEBUG_PRINT( s ) usb_puts( s )
+#define WL_DEBUG_PRINT_CHAR( c ) usb_putc( c )
+#define WL_DEBUG_PRINT_INT( i ) usb_puti(i)
 #else
 #define WL_DEBUG_PRINT( s ) printf( s )
-#endif
-
-#ifdef ROBOT
-#define WL_DEBUG_PRINT_INT( i ) usb_puti(i)
-#else
+#define WL_DEBUG_PRINT_CHAR( c ) printf("%c", c)
 #define WL_DEBUG_PRINT_INT( i ) printf("%i", i)
 #endif
 
@@ -97,9 +143,9 @@
 #else
 
 #define WL_DEBUG_PRINT( s )
+#define WL_DEBUG_PRINT_CHAR( c )
 #define WL_DEBUG_PRINT_INT( i )
 
 #endif
 
 #endif
-
Index: branches/wireless/code/lib/include/libwireless/xbee.h
===================================================================
--- branches/wireless/code/lib/include/libwireless/xbee.h	(revision 1616)
+++ branches/wireless/code/lib/include/libwireless/xbee.h	(revision 1617)
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2007 Colony Project
+ * Copyright (c) 2009 Colony Project
  * 
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
@@ -32,20 +32,19 @@
  * To use a robot, define ROBOT in wl_defs.h, and
  * to use a computer, don't define ROBOT.
  *
- * @author Brian Coltin, Colony Project, CMU Robotics Club
+ * @author Colony Project, CMU Robotics Club
  **/
 
 #ifndef XBEE_H
 #define XBEE_H
 
-/**
- * The port to use the XBee from on the computer.
- * Also, a backup port if the other is used.
- **/
-#ifndef ROBOT
-#define XBEE_PORT_DEFAULT "/dev/ttyUSB1"
+// need this for C99 int types
+#ifndef STDINT_H
+#define STDINT_H
+#include <stdint.h>
 #endif
 
+
 /**
  * @defgroup xbee XBee
  * @brief Interface with the XBee module
@@ -54,8 +53,19 @@
  *
  * @{
  **/
-
-/*Definitions*/
+ 
+ /**@defgroup xbee_const xbee constants 
+  * @brief These are constants used for the xbee module.
+  * @{ **/
+  
+#ifndef XBEE_BAUD
+/** @brief The XBee baud rate **/
+#define XBEE_BAUD 115200
+#endif
+ 
+/**@name xbee options
+ * @{ **/
+ 
 /**@brief Unset PAN, uses XBee default **/
 #define XBEE_PAN_DEFAULT 0xFFFF
 /**@brief Unset channel, uses XBee default **/
@@ -73,29 +83,66 @@
 /**@brief A packet received from another XBee **/
 #define XBEE_RX 0x81
 
+/**@}
+ * @name xbee frame types
+ * @{ **/
+
+// TODO: add comments for all of these definitions
+
+/*Frame Types*/
+#define XBEE_FRAME_START 0x7E
+#define XBEE_FRAME_STATUS 0x8A
+#define XBEE_FRAME_AT_COMMAND 0x08
+#define XBEE_FRAME_AT_COMMAND_RESPONSE 0x88
+#define XBEE_FRAME_TX_REQUEST_64 0x00
+#define XBEE_FRAME_TX_REQUEST_16 0x01
+#define XBEE_FRAME_TX_STATUS XBEE_TX_STATUS
+#define XBEE_FRAME_RX_64 0x80
+#define XBEE_FRAME_RX_16 XBEE_RX
+
+/** @} **/
+
+/**@} **/ // end const group
+ 
+/**
+ * @defgroup xbee_funcs Xbee Functions
+ * @brief These are the public xbee functions.
+ * @{
+ **/
+  
 /**@brief Initialize the XBee library **/
-int xbee_lib_init(void);
+int8_t xbee_init(void);
 /**@brief Uninitialize the XBee library **/
-void xbee_terminate(void);
-/**@brief Get a packet from the XBee **/
-int xbee_get_packet(unsigned char* packet);
+int8_t xbee_terminate(void);
+/**@brief Send a byte to the xbee **/
+int8_t xbee_putc(uint8_t c);
+/**@brief Read a byte form the xbee **/
+int16_t xbee_getc(void);
+/**@brief Read a byte from the xbee (nonblocking) **/
+int8_t xbee_getc_nb(uint8_t *c);
+/**@brief Send an array of bytes to the xbee **/
+int8_t xbee_send(uint8_t* buf, uint16_t size);
+/**@brief Add a buffer to the checksum value **/
+int8_t xbee_checksum_add(uint8_t *buf, uint8_t len, uint8_t* sum);
+/**@brief Send a frame header to the xbee **/
+int8_t xbee_send_header(uint8_t type, uint16_t len);
 /**@brief Send a packet to the XBee **/
-int xbee_send_packet(char* packet, int len, int dest, char options, char frame);
+int8_t xbee_send_packet(uint8_t* packet, uint8_t len, uint16_t dest, uint8_t options, uint8_t frame);
 /**@brief Set the PAN ID for the XBee **/
-int xbee_set_pan_id(int id);
+int8_t xbee_set_pan_id(uint16_t id);
 /**@brief Get the XBee's PAN ID **/
-unsigned int xbee_get_pan_id(void);
+uint16_t xbee_get_pan_id(void);
 /**@brief Set the channel the XBee is currently using **/
-int xbee_set_channel(int channel);
+int8_t xbee_set_channel(uint8_t channel);
 /**@brief Get the channel the XBee is currently using **/
-int xbee_get_channel(void);
+int8_t xbee_get_channel(void);
 /**@brief Get the XBee's 16-bit address **/
-unsigned int xbee_get_address(void);
-/**@brief Set the com port on a computer, undefined on the robot**/
-void xbee_set_com_port(char* port);
+uint16_t xbee_get_address(void);
 /**@brief Reset XBee **/
-int xbee_reset(void);
+int8_t xbee_reset(void); // TODO: implement this function
 
-/**@}**/ //end defgroup
+/**@} **/ //end xbee_funcs group
 
+/**@} **/ //end defgroup
+
 #endif
Index: branches/wireless/code/lib/bin/libwireless.a
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: branches/wireless/code/lib/bin/libdragonfly.a
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: branches/wireless/code/projects/unit_tests/test_tokenring.c
===================================================================
--- branches/wireless/code/projects/unit_tests/test_tokenring.c	(revision 1616)
+++ branches/wireless/code/projects/unit_tests/test_tokenring.c	(nonexistent)
@@ -1,98 +0,0 @@
-#include <dragonfly_lib.h>
-#include <wireless.h>
-#include <wl_token_ring.h>
-
-
-/**
- * Tests the token ring and BOM
- * - prints table of bom values for every robot in token ring
- * - takes several seconds to initialize token ring
- */
- 
-#define MAX_ROBOTS 16
-
-// set a list of integers to 0
-void clearRobots(int* list) {
-  for(int i=0;i<MAX_ROBOTS;i++)
-    list[i] = 0;
-}
-
-int testtokenring(void) {
-  usb_init();
-	usb_puts("usb turned on\r\n");
-  wl_init();
-  usb_puts("wireless turned on\r\n");
-  wl_token_ring_register();
-  wl_token_ring_join(); // join token ring
-  usb_puts("token ring joined\r\n");
-  int robotList[sizeof(int)*MAX_ROBOTS];
-  int numRobots = 0;
-  delay_ms(1000);
-  
-  // start testing wireless/token ring/BOM
-  int i=0;
-  while(1) {
-    wl_do();
-    // only print table every 200 loops
-    if (i%200==0) {
-      // get token ring size values
-      usb_puts("\r\nnumber of robots in token ring:");
-      usb_puti(wl_token_get_robots_in_ring());
-      usb_puts("\r\nnumber of robots in matrix:"); 
-      usb_puti(wl_token_get_num_robots());
-      
-      // get list of robots
-      numRobots = 0;
-      clearRobots(robotList);
-      wl_token_iterator_begin();
-      while(wl_token_iterator_has_next()) {
-        int tmp = wl_token_iterator_next();
-        if (tmp < 0)
-          break;
-        robotList[tmp] = 1;
-        numRobots++;
-      }
-      if (numRobots < 1) {
-        usb_puts("\r\nNo BOM table available.");
-        continue; // skip table printing
-      } else {
-        usb_puts("\r\nBOM table: (* indicates this robot)");
-      }
-      
-      // print table of bom readings between robots
-      usb_puts("\r\ns \\ d");
-      // print header
-      for(int j=0;j<MAX_ROBOTS;j++)
-        if (robotList[j]) {
-          usb_puts("\t|");
-          if (j == wl_get_xbee_id())
-            usb_puts("*"); // indicate that this is the current bot
-          usb_puti(j);
-        }
-      usb_puts("\r\n");
-      // print body
-      for(int l=0;l<MAX_ROBOTS;l++) 
-        if (robotList[l]) {        
-          if (l == wl_get_xbee_id())
-            usb_puts("*"); // indicate that this is the current bot
-          usb_puti(l); // print label col
-          for(int k=0;k<MAX_ROBOTS;k++) 
-            if (robotList[k]) {
-              usb_puts("\t|");
-              if (k != l) {
-                int bom = wl_token_get_sensor_reading(l,k);
-                if (bom >= 0 && bom <= 15)
-                  usb_puti(bom); // print bom value
-              }
-            }
-          usb_puts("\r\n");
-        }
-      usb_puts("\r\n");
-    }
-  }
-  
-  // end testing token ring and bom
-	return 0;
-}
-
-

Property changes on: branches/wireless/code/projects/unit_tests/test_tokenring.c
___________________________________________________________________
Deleted: svn:mergeinfo
## -0,0 +0,0 ##
Index: branches/wireless/code/projects/unit_tests/xbee.c
===================================================================
--- branches/wireless/code/projects/unit_tests/xbee.c	(revision 1616)
+++ branches/wireless/code/projects/unit_tests/xbee.c	(nonexistent)
@@ -1,1038 +0,0 @@
-/**
- * Copyright (c) 2007 Colony Project
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- **/
-
-/**
- * @file xbee.c
- * @brief XBee Interface
- *
- * Implementation of low level communication with the XBee in API mode.
- *
- * @author Brian Coltin, Colony Project, CMU Robotics Club
- **/
-
-#include <xbee.h>
-#include <wl_defs.h>
-
-#define ROBOT
-#define WL_DEBUG
-#define WL_DEBUG_PRINT( s ) usb_puts( s )
-#define WL_DEBUG_PRINT_INT( i ) usb_puti(i)
-
-#ifndef ROBOT
-
-#include <fcntl.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <errno.h>
-#include <termios.h>
-
-#else
-
-#include <serial.h>
-#include <avr/interrupt.h>
-
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define XBEE_FRAME_START 0x7E
-#define XBEE_GET_PACKET_TIMEOUT 1000
-
-/*Frame Types*/
-#define XBEE_FRAME_STATUS 0x8A
-#define XBEE_FRAME_AT_COMMAND 0x08
-#define XBEE_FRAME_AT_COMMAND_RESPONSE 0x88
-#define XBEE_FRAME_TX_REQUEST_64 0x00
-#define XBEE_FRAME_TX_REQUEST_16 0x01
-#define XBEE_FRAME_TX_STATUS XBEE_TX_STATUS
-#define XBEE_FRAME_RX_64 0x80
-#define XBEE_FRAME_RX_16 XBEE_RX
-
-/*Internal Function Prototypes*/
-
-/*I/O Functions*/
-static int xbee_send(char* buf, int size);
-static int xbee_send_string(char* c);
-
-#ifndef ROBOT
-static int xbee_read(char* buf, int size);
-#endif
-
-/*Command Mode Functions
- * Called during initialization.
- */
-static int xbee_enter_command_mode(void);
-static int xbee_exit_command_mode(void);
-static int xbee_enter_api_mode(void);
-static int xbee_exit_api_mode(void);
-static int xbee_wait_for_string(char* s, int len);
-static int xbee_wait_for_ok(void);
-
-/*API Mode Functions*/
-
-static int xbee_handle_packet(char* packet, int len);
-static void xbee_handle_at_command_response(char* command, char result, char* extra, int extraLen);
-static void xbee_handle_status(char status);
-static int xbee_verify_checksum(char* packet, int len);
-static char xbee_compute_checksum(char* packet, int len);
-static int xbee_send_frame(char* buf, int len);
-int xbee_send_read_at_command(char* command);
-static int xbee_send_modify_at_command(char* command, char* value);
-
-/*Global Variables*/
-
-#ifndef ROBOT
-static char* xbee_com_port = XBEE_PORT_DEFAULT;
-static int xbee_stream;
-static pthread_t* xbee_listen_thread;
-#endif
-
-// TODO: is this a good size?
-#define XBEE_BUFFER_SIZE	128
-#define PACKET_BUFFER_SIZE	108
-// a buffer for data received from the XBee
-char arrival_buf[XBEE_BUFFER_SIZE];
-// location of last unread byte in buffer
-volatile int buffer_last = 0;
-// first unread byte in buffer
-volatile int buffer_first = 0;
-
-
-//used to store packets as they are read
-static char xbee_buf[PACKET_BUFFER_SIZE];
-static int currentBufPos = 0;
-
-//XBee status
-static unsigned int xbee_panID = XBEE_PAN_DEFAULT;
-static unsigned int xbee_pending_panID = XBEE_PAN_DEFAULT;
-static int xbee_channel = XBEE_CHANNEL_DEFAULT;
-static int xbee_pending_channel = XBEE_CHANNEL_DEFAULT;
-static volatile unsigned int xbee_address = 0;
-
-/*Function Implementations*/
-
-#ifdef ROBOT
-
-/**
- * Interrupt for the robot. Adds bytes received from the xbee
- * to the buffer.
- **/
-#ifndef FIREFLY
-ISR(USART1_RX_vect)
-{
-	char c = UDR1;
-	arrival_buf[buffer_last] = c;
-	int t = buffer_last + 1;
-	if (t == XBEE_BUFFER_SIZE)
-		t = 0;
-	if (t == buffer_first)
-	{
-		WL_DEBUG_PRINT("\nOut of space in buffer.\n");
-	}
-	buffer_last = t;
-}
-#else
-SIGNAL(SIG_USART0_RECV)
-{
-	char c = UDR0;
-	arrival_buf[buffer_last] = c;
-	int t = buffer_last + 1;
-	if (t == XBEE_BUFFER_SIZE)
-		t = 0;
-	if (t == buffer_first)
-	{
-		WL_DEBUG_PRINT("Out of space in buffer.\n");
-	}
-	buffer_last = t;
-}
-#endif
-
-#else
-
-// Computer code
-
-/**
- * Thread that listens to the xbee.
- **/
-static void* listen_to_xbee(void* x)
-{
-	char c;
-	while (1)
-	{
-		if (xbee_read(&c, 1) != 0) {
-			WL_DEBUG_PRINT("xbee_read failed.\n");
-			return NULL;
-		}
-
-		arrival_buf[buffer_last] = c;
-		int t = buffer_last + 1;
-		if (t == XBEE_BUFFER_SIZE)
-			t = 0;
-		if (t == buffer_first)
-		{
-			WL_DEBUG_PRINT("Out of space in buffer.\n");
-		}
-		buffer_last = t;
-
-		usleep(1000);
-	}
-
-	return NULL;
-}
-
-#endif
-
-/**
- * Initializes the XBee library so that other functions may be used.
- **/
-int xbee_lib_init()
-{
-	WL_DEBUG_PRINT("in xbee_init\n");
-#ifdef ROBOT
-
-	//enable the receiving interrupt
-#ifdef FIREFLY
-	UCSR0B |= _BV(RXCIE) | _BV(RXEN);
-#else
-#ifdef BAYBOARD
-	UCSR1B |= _BV(RXCIE1);
-#else
-	UCSR1B |= _BV(RXCIE);
-#endif
-#endif
-	sei();
-#else
-	xbee_stream = open(xbee_com_port, O_RDWR);
-	if (xbee_stream == -1/* || lockf(xbee_stream, F_TEST, 0) != 0*/)
-	{
-		WL_DEBUG_PRINT("Failed to open connection to XBee on port ");
-		WL_DEBUG_PRINT_INT(xbee_com_port);
-		WL_DEBUG_PRINT(".\n");
-		return -1;
-	} else {
-	  WL_DEBUG_PRINT("Successfully opened connection to XBee on port ");
-		WL_DEBUG_PRINT_INT(xbee_com_port);
-		WL_DEBUG_PRINT(".\n");
-	}
-
-	// set baud rate, etc. correctly
-	struct termios options;
-
-	tcgetattr(xbee_stream, &options);
-	cfsetispeed(&options, B9600);
-	cfsetospeed(&options, B9600);
-	options.c_iflag &= ~ICRNL;
-	options.c_oflag &= ~OCRNL;
-	options.c_cflag |= (CLOCAL | CREAD);
-	options.c_cflag &= ~PARENB;
-	options.c_cflag &= ~CSTOPB;
-	options.c_cflag &= ~CSIZE;
-	options.c_cflag |= CS8;
-	options.c_lflag &= ~ICANON;
-	options.c_cc[VMIN] = 1;
-	options.c_cc[VTIME] = 50;
-
-	if (tcsetattr(xbee_stream, TCSANOW, &options))
-	{
-		WL_DEBUG_PRINT("Error setting attributes.\n");
-		return -1;
-	}
-
-	xbee_listen_thread = (pthread_t*)malloc(sizeof(pthread_t));
-	if (xbee_listen_thread == NULL)
-	{
-		WL_DEBUG_PRINT("Malloc failed.\n");
-		return -1;
-	}
-
-	int ret = pthread_create(xbee_listen_thread, NULL, listen_to_xbee, NULL);
-	if (ret)
-	{
-		WL_DEBUG_PRINT("Failed to create listener thread.\n");
-		return -1;
-	}
-#endif
-
-	WL_DEBUG_PRINT("Entering command mode.\n");
-
-	if (xbee_enter_command_mode() != 0) {
-		return -1;
-	}
-
-	WL_DEBUG_PRINT("Entered command mode.\n");
-
-	if (xbee_enter_api_mode() != 0) {
-		return -1;
-	}
-
-	WL_DEBUG_PRINT("Entered api mode.\n");
-
-	if (xbee_exit_command_mode() != 0) {
-	     return -1;
-	}
-	
-	WL_DEBUG_PRINT("Left command mode.\n");
-
-	if (xbee_send_read_at_command("MY")) {
-		return -1;
-	}
-	WL_DEBUG_PRINT("Getting ATMY address.\n");
-
-#ifndef ROBOT
-	int i;
-	for (i = 0; xbee_address == 0 && i < XBEE_GET_PACKET_TIMEOUT; i++) {
-	  ret = xbee_get_packet(NULL);
-
-	  usleep(1000);
-	  
-/* 	  if (ret == -1) { */
-/* 	    WL_DEBUG_PRINT("xbee_get_packet(NULL) failed.\n"); */
-/* 	    return -1; */
-/* 	  } */
-	}
-#else
-	//wait to return until the address is set
-  //TODO: this shouldn't wait indefinitely.  There should be some sort of reasonable timeout
-  // so if the address is never set right, an error can be returned instead of having the
-  // robot hang forever
-	while (xbee_address == 0) {
-	  xbee_get_packet(NULL);
-	}
-#endif
-	WL_DEBUG_PRINT("Got ATMY address.\n");
-
-#ifndef ROBOT
-	if (i == XBEE_GET_PACKET_TIMEOUT) { // We timed-out.
-
-	  WL_DEBUG_PRINT("xbee_get_packet timed out.\n");
-	  return -1;
-	} else {
-	  return 0;
-	}
-#else
-	return 0;
-#endif
-}
-
-/**
- * Call when finished using the XBee library. This releases
- * all sued resources.
- **/
-void xbee_terminate()
-{
-	#ifndef ROBOT
-	pthread_cancel(*xbee_listen_thread);
-    pthread_join(*xbee_listen_thread, NULL);
-	free(xbee_listen_thread);
-	lockf(xbee_stream, F_ULOCK, 0);
-	close(xbee_stream);
-  #else
-  xbee_exit_api_mode();
-	#endif
-}
-
-/**
- * Send a buffer buf of size bytes to the XBee.
- *
- * @param buf the buffer of data to send
- * @param size the number of bytes to send
- **/
-static int xbee_send(char* buf, int size)
-{
-#ifdef ROBOT
-	int i;
-	for (i = 0; i < size; i++) {
-		xbee_putc(buf[i]);
-	}
-
-	return 0;
-
-#else
-
-	int ret = write(xbee_stream, buf, size);
-	//success
-	if (ret == size)
-		return 0;
-	if (ret == -1)
-	{
-		//interrupted by system signal, probably timer interrupt.
-		//just try again
-		if (errno == 4)
-		{
-			return xbee_send(buf, size);
-		}
-		WL_DEBUG_PRINT("Failed to write to xbee\r\n");
-		return -1;
-	}
-
-	//write was interrupted after writing ret bytes
-	return xbee_send(buf + ret, size - ret);
-#endif
-}
-
-/**
- * Sends a string to the XBee.
- *
- * @param c the string to send to the XBEE
- **/
-static int xbee_send_string(char* c)
-{
-	return xbee_send(c, strlen(c));
-}
-
-#ifndef ROBOT
-static int xbee_read(char* buf, int size)
-{
-	if (read(xbee_stream, buf, size) == -1) {
-		WL_DEBUG_PRINT("Failed to read from xbee.\r\n");
-		return -1;
-	}
-
-	return 0;
-}
-#endif
-
-/**
- * Enter into command mode.
- **/
-static int xbee_enter_command_mode()
-{
-	if (xbee_send_string("+++") != 0) {
-		return -1;
-	}
-
-	if (xbee_wait_for_ok() != 0) {
-	  return -1;
-	}
-	  return 0;
-}
-
-/**
- * Exit from command mode.
- **/
-static int xbee_exit_command_mode()
-{
-	if (xbee_send_string("ATCN\r") != 0) {
-		return -1;
-	}
-
-	xbee_wait_for_ok();
-
-	return 0;
-}
-
-/**
- * Enter API mode.
- **/
-static int xbee_enter_api_mode()
-{
-	if (xbee_send_string("ATAP 1\r") != 0) {
-		return -1;
-	}
-	xbee_wait_for_ok();
-
-	return 0;
-}
-
-/**
- * Exit API mode.
- **/
-static int xbee_exit_api_mode()
-{
-	if (xbee_send_modify_at_command("AP","0") != 0) {
-		return -1;
-	}
-
-	return 0;
-}
-
-/**
- * Wait until the string "OK\r" is received from the XBee.
- **/
-static int xbee_wait_for_ok()
-{
-	return xbee_wait_for_string("OK\r", 3);
-}
-
-/**
- * Delay until the specified string is received from
- * the XBee. Discards all other XBee data.
- *
- * ********* Robot often hangs here ****************
- *
- * @param s the string to receive
- * @param len the length of the string
- **/
-static int xbee_wait_for_string(char* s, int len)
-{
-	char* curr = s;
-	while (curr - s < len) {
-    WL_DEBUG_PRINT("waiting for string\r\n");
-		// check if buffer is empty
-		if (buffer_last != buffer_first) {
-			char c = arrival_buf[buffer_first++];
-			if (buffer_first == XBEE_BUFFER_SIZE) {
-				buffer_first = 0;
-			}
-
-			if (c == *curr) {
-				curr++;
-			} else {
-#ifndef ROBOT
-			  //return -1; // Computer is less forgiving.
-			  curr = s;
-#else
-			  curr = s;
-#endif
-			}
-		} // else buffer is empty.
-
-#ifndef ROBOT
-		usleep(100);
-#endif
-	}
-
-	return 0;
-}
-
-/**
- * Verifies that the packets checksum is correct.
- * (If the checksum is correct, the sum of the bytes
- * is 0xFF.)
- *
- * @param packet the packet received. This includes the first
- * three bytes, which are header information from the XBee.
- *
- * @param len The length of the packet received from the XBee
- *
- * @return 0 if the checksum is incorrect, nonzero
- * otherwise
- **/
-int xbee_verify_checksum(char* packet, int len)
-{
-	unsigned char sum = 0;
-	int i;
-	for (i = 3; i < len; i++)
-		sum += (unsigned char)packet[i];
-	return sum == 0xFF;
-}
-
-/**
- * Returns the checksum of the given packet.
- *
- * @param buf the data for the packet to send
- * @param len the length of the packet in bytes
- *
- * @return the checksum of the packet, which will
- * become the last byte sent in the packet
- **/
-char xbee_compute_checksum(char* buf, int len)
-{
-	int i;
-	unsigned char sum = 0;
-	for (i = 0; i < len; i++)
-		sum += (unsigned char)buf[i];
-	return 0xFF - sum;
-}
-
-/**
- * Adds header information and checksum to the given
- * packet and sends it. Header information includes
- * XBEE_FRAME_START and the packet length, as two bytes.
- *
- * @param buf the packet data
- * @param len the size in bytes of the packet data
- *
- **/
-static int xbee_send_frame(char* buf, int len)
-{
-	char prefix[3];
-	prefix[0] = XBEE_FRAME_START;
-	prefix[1] = (len & 0xFF00) >> 8;
-	prefix[2] = len & 0xFF;
-	char checksum = xbee_compute_checksum(buf, len);
-
-	if (xbee_send(prefix, 3) != 0) {
-		return -1;
-	}
-
-	if (xbee_send(buf, len) != 0) {
-		return -1;
-	}
-
-	if (xbee_send(&checksum, 1) != 0) {
-		return -1;
-	}
-
-	return 0;
-}
-
-/**
- * Sends an AT command to read a parameter.
- *
- * @param command the AT command to send. For exmaple,
- * use ID to read the PAN ID and MY to return the XBee ID.
- * See the XBee reference guide for a complete listing.
- **/
-int xbee_send_read_at_command(char* command)
-{
-	return xbee_send_modify_at_command(command, NULL);
-}
-
-/**
- * Sends the given AT command.
- *
- * @param command the AT command to send (e.g., MY, ID)
- * @param value the value to pass as a parameter
- * (or NULL if there is no parameter)
- **/
-static int xbee_send_modify_at_command(char* command, char* value)
-{
-	char buf[16];
-	int i;
-
-	buf[0] = XBEE_FRAME_AT_COMMAND;
-	buf[1] = 1;
-	buf[2] = command[0];
-	buf[3] = command[1];
-	int valueLen = 0;
-	if (value != NULL)
-	{
-		valueLen = strlen(value);
-		if (valueLen > 8)
-		{
-			WL_DEBUG_PRINT("AT Command too large.\r\n");
-			return -1;
-		}
-
-		for (i = 0; i < valueLen; i++) {
-			buf[4 + i] = value[i];
-		}
-	}
-
-	return xbee_send_frame(buf, 4 + valueLen);
-}
-
-/**
- * Send the specified packet.
- *
- * @param packet the packet data to send
- * @param len the number of bytes in the packet
- *
- * @param dest the ID of the XBee to send the packet to,
- * or XBEE_BROADCAST to send the message to all robots
- * in the PAN.
- *
- * @param options a combination of the flags
- * XBEE_OPTIONS_NONE, XBEE_OPTIONS_DISABLE_RESPONSE and
- * XBEE_OPTIONS_BROADCAST_ALL_PANS
- *
- * @param frame the frame number to associate this packet
- * with. This will be used to identify the response when
- * the XBee alerts us as to whether or not our message
- * was received.
- **/
-int xbee_send_packet(char* packet, int len, int dest, char options, char frame)
-{
-	char buf[5];
-	char prefix[3];
-	int i;
-	unsigned char checksum = 0;
-
-	if (len > 100)
-	{
-		WL_DEBUG_PRINT("Packet is too large.\r\n");
-		return -1;
-	}
-
-	//data for sending request
-	buf[0] = XBEE_FRAME_TX_REQUEST_16;
-	buf[1] = frame;
-	buf[2] = (dest >> 8) & 0xFF;
-	buf[3] = dest & 0xFF;
-	buf[4] = options;
-
-	//packet prefix, do this here so we don't need an extra buffer
-	prefix[0] = XBEE_FRAME_START;
-	prefix[1] = ((5 + len) & 0xFF00) >> 8;
-	prefix[2] = (5 + len) & 0xFF;
-
-	for (i = 0; i < 5; i++)
-		checksum += (unsigned char)buf[i];
-	for (i = 0; i < len; i++)
-		checksum += (unsigned char)packet[i];
-	checksum = 0xFF - checksum;
-
-	if (xbee_send(prefix, 3) != 0) {
-		return -1;
-	}
-
-	if (xbee_send(buf, 5) != 0) {
-		return -1;
-	}
-
-	if (xbee_send(packet, len) != 0) {
-		return -1;
-	}
-
-	if (xbee_send((char*)&checksum, 1) != 0) {
-		return -1;
-	}
-
-	return 0;
-}
-
-/**
- * Reads a packet received from the XBee. This function
- * is non-blocking. The resulting packet is stored in dest.
- * Only returns transmission response packets and
- * received packets. The returned packet does not include
- * header information or the checksum. This method also
- * handles special packets dealt with by the XBee library,
- * and so should be called frequently while the XBee is in
- * use.<br><br>
- *
- * The first byte of the packet will be either
- * XBEE_TX_STATUS or XBEE_RX to indicated
- * a response to a sent message or a received message,
- * respectively.<br><br>
- *
- * For a status response packet:<br>
- * The first byte will be XBEE_TX_STATUS.<br>
- * The second byte will be the frame number.<br>
- * The third byte will be the result. 0 indicates success,
- * and nonzero indicates that an error ocurred in
- * transmitting the packet.<br><br>
- *
- * For a received packet:<br>
- * The first byte will be XBEE_RX.<br>
- * The second and third bytes will be the 16-bit
- * address of the packet's sender.<br>
- * The fourth byte is the signal strength.<br>
- * The fifth byte is 1 if the packet were sent to
- * a specific address, and 2 if it is a broadcast packet.<br><br>
- *
- * @param dest set to the packet data
- * @return the length of the packet, or -1 if no packet
- * is available
- **/
-int xbee_get_packet(unsigned char* dest)
-{
-     int ret;
-	//start reading a packet with XBEE_FRAME_START
-	if (currentBufPos == 0)
-	{
-		do
-		{
-			if (buffer_first == XBEE_BUFFER_SIZE)
-				buffer_first = 0;
-			// check if buffer is empty
-			if (buffer_first == buffer_last) {
-				return -1;
-			}
-		} while (arrival_buf[buffer_first++] != XBEE_FRAME_START);
-
-		if (buffer_first == XBEE_BUFFER_SIZE) {
-			buffer_first = 0;
-		}
-		xbee_buf[0] = XBEE_FRAME_START;
-		currentBufPos++;
-	}
-
-	int len = -1;
-	if (currentBufPos >= 3) {
-		len = (int)xbee_buf[2] + ((int)xbee_buf[1] << 8);
-	}
-
-	while (len == -1 //packet length has not been read yet
-		|| currentBufPos < len + 4)
-	{
-		if (currentBufPos == 3)
-		{
-			len = (int)xbee_buf[2] + ((int)xbee_buf[1] << 8);
-			if (len > 120)
-			{
-				WL_DEBUG_PRINT("Packet too large. Probably error in XBee transmission.\n");
-				currentBufPos = 0;
-				return -1;
-			}
-		}
-
-		// check if buffer is empty
-		if (buffer_first == buffer_last) {
-			return -1;
-		}
-		xbee_buf[currentBufPos++] = arrival_buf[buffer_first++];
-		if (buffer_first == XBEE_BUFFER_SIZE) {
-			buffer_first = 0;
-		}
-	}
-
-	currentBufPos = 0;
-
-	if (!xbee_verify_checksum(xbee_buf, len + 4))
-	{
-		WL_DEBUG_PRINT("XBee checksum failed.\r\n");
-		return -1;
-	}
-
-	//we will take care of the packet
-	
-	ret = xbee_handle_packet(xbee_buf+3, len);
-	if (ret == 1) {
-		return 3;
-	}
-	
-	if (dest == NULL) {
-		return -1;
-	}
-
-	int i;
-	for (i = 3; i < len + 3; i++) {
-		dest[i - 3] = xbee_buf[i];
-	}
-	return len;
-}
-
-/**
- * Handles modem status packets.
- *
- * @param status the type of status packet received.
- **/
-void xbee_handle_status(char status)
-{
-	switch (status)
-	{
-		case 0:
-			WL_DEBUG_PRINT("XBee hardware reset.\r\n");
-			break;
-		case 1:
-			WL_DEBUG_PRINT("Watchdog timer reset.\r\n");
-			break;
-		case 2:
-			WL_DEBUG_PRINT("Associated.\r\n");
-			break;
-		case 3:
-			WL_DEBUG_PRINT("Disassociated.\r\n");
-			break;
-		case 4:
-			WL_DEBUG_PRINT("Synchronization lost.\r\n");
-			break;
-		case 5:
-			WL_DEBUG_PRINT("Coordinator realignment.\r\n");
-			break;
-		case 6:
-			WL_DEBUG_PRINT("Coordinator started.\r\n");
-			break;
-	}
-}
-
-/**
- * Handles AT command response packets.
- * @param command the two character AT command, e.g. MY or ID
- * @param result 0 for success, 1 for an error
- * @param extra the hex value of the requested register
- * @param extraLen the length in bytes of extra
- **/
-static void xbee_handle_at_command_response(char* command, char result, char* extra, int extraLen)
-{
-	if (result == 1)
-	{
-		WL_DEBUG_PRINT("Error with AT");
-		WL_DEBUG_PRINT(command);
-		WL_DEBUG_PRINT(" packet.\r\n");
-	}
-	WL_DEBUG_PRINT("AT");
-	WL_DEBUG_PRINT(command);
-	WL_DEBUG_PRINT(" command was successful.\r\n");
-
-	if (command[0] == 'I' && command[1] == 'D')
-	{
-		xbee_panID = xbee_pending_panID;
-		WL_DEBUG_PRINT("PAN ID set to ");
-		WL_DEBUG_PRINT_INT(xbee_panID);
-		WL_DEBUG_PRINT(".\r\n");
-		return;
-	}
-
-	if (command[0] == 'C' && command[1] == 'H')
-	{
-		xbee_channel = xbee_pending_channel;
-		WL_DEBUG_PRINT("Channel set to ");
-		WL_DEBUG_PRINT_INT(xbee_channel);
-		WL_DEBUG_PRINT(".\r\n");
-		return;
-	}
-  
-  if (command[0] == 'N' && command[1] == 'D')
-	{
-		xbee_channel = xbee_pending_channel;
-		WL_DEBUG_PRINT("extra=");
-    WL_DEBUG_PRINT(extra);
-		WL_DEBUG_PRINT("\r\n");
-		return;
-	}
-
-	if (command[0] == 'M' && command[1] == 'Y' && extraLen != 0)
-	{
-		xbee_address = 0;
-		int i;
-		for (i = 0; i < extraLen; i++) {
-			xbee_address = (xbee_address << 8) + extra[i];
-		}
-
-		WL_DEBUG_PRINT("XBee address is ");
-		WL_DEBUG_PRINT_INT(xbee_address);
-		WL_DEBUG_PRINT(".\r\n");
-
-		if (xbee_address == 0)
-		{
-			WL_DEBUG_PRINT("XBee 16-bit address must be set using ATMY.\r\n");
-			#ifndef ROBOT
-			exit(0);
-			#endif
-		}
-	}
-}
-
-/**
- * Attempts to handle the packet if it is dealt with
- * by the library.
- * We will handle the following packet types:
- *    Modem Status
- *    AT Command Response
- *
- * @param packet the packet to handle
- * @param len the length of the packet
- *
- * @return 1 if we have handled the packet, 0 otherwise
- */
-static int xbee_handle_packet(char* packet, int len)
-{
-
-	char command[3] = {1, 2, 3};
-	if (len <= 0) //this should not happend
-	{
-		WL_DEBUG_PRINT("Non-positive packet length.\r\n");
-		return 0;
-	}
-
-	switch ((unsigned char)packet[0]) //packet type
-	{
-		case XBEE_FRAME_STATUS:
-			xbee_handle_status(packet[1]);
-			return 1;
-		case XBEE_FRAME_AT_COMMAND_RESPONSE:
-			command[0] = packet[2];
-			command[1] = packet[3];
-			command[2] = 0;
-			xbee_handle_at_command_response(command, packet[4], packet + 5, len - 5);
-			return 1;
-	}
-	return 0;
-}
-
-/**
- * Sets the personal area network id.
- *
- * @param id the new personal area network (PAN) id
- **/
-int xbee_set_pan_id(int id)
-{
-	char s[3];
-	s[0] = (id >> 8) & 0xFF;
-	s[1] = id & 0xFF;
-	s[2] = 0;
-	xbee_pending_panID = id;
-	return xbee_send_modify_at_command("ID", s);
-}
-
-/**
- * Get the PAN ID for the XBee.
- *
- * @return the personal area network id, or
- * XBEE_PAN_DEFAULT if it has not yet been set.
- **/
-unsigned int xbee_get_pan_id()
-{
-	return xbee_panID;
-}
-
-/**
- * Set the channel the XBee is using.
- *
- * @param channel the channel the XBee will not use,
- * between 0x0B and 0x1A
- *
- * @see xbee_get_channel
- **/
-int xbee_set_channel(int channel)
-{
-	if (channel < 0x0B || channel > 0x1A)
-	{
-		WL_DEBUG_PRINT("Channel out of range.\r\n");
-		return -1;
-	}
-
-	char s[3];
-	s[0] = channel & 0xFF;
-	s[1] = 0;
-	xbee_pending_channel = channel;
-
-	return xbee_send_modify_at_command("CH", s);
-}
-
-/**
- * Returns the channel which the XBee is currently using.
- *
- * @return the channel the XBee is using
- *
- * @see xbee_set_channel
- **/
-int xbee_get_channel(void)
-{
-	return xbee_channel;
-}
-
-/**
- * Get the 16-bit address of the XBee.
- * This is used to specify who to send messages to
- * and who messages are from.
- *
- * @return the 16-bit address of the XBee.
- **/
-unsigned int xbee_get_address()
-{
-	return xbee_address;
-}
-
-#ifndef ROBOT
-void xbee_set_com_port(char* port)
-{
-	xbee_com_port = port;
-}
-#endif
Index: branches/wireless/code/projects/unit_tests/test_wireless.c
===================================================================
--- branches/wireless/code/projects/unit_tests/test_wireless.c	(revision 1616)
+++ branches/wireless/code/projects/unit_tests/test_wireless.c	(nonexistent)
@@ -1,114 +0,0 @@
-/**
- * Instructions:
- *  - wait for both robots to show ORB 1 RED and ORB 2 GREEN
- *  - press BUTTON 1 on robot to send first (ROBOT 1) - orbs should turn PURPLE
- *  - press BUTTON 2 on robot to receive first (ROBOT 2) - orbs should turn ORANGE
- *  - wait at least a second, then press BUTTON 1 on both robots SIMULTANEOUSLY
- *  - ROBOT 2 orbs should cycle ORANGE to RED to BLUE
- *  - then ROBOT 1 orbs should cycle PURPLE to RED to BLUE
- *  - then orbs on both robots should turn GREEN
- *  - test will reset to ORB 1 RED and ORB 2 CYAN
- *  - test should take ~7 seconds
- *
- * Depends on:
- *  - Orbs (Lights)
- *  - Serial (for debugging)
- **/
-
-#include <dragonfly_lib.h>
-#include <wl_basic.h>
-
-unsigned char* packet;
-int length;
-
-int testwireless(void) {
-    int count = 0;
-    int is_sender = 0;
-
-    wl_basic_init_default();
-    wl_set_channel(0x0E);
-
-    orb1_set_color(RED);
-    orb2_set_color(GREEN);
-    delay_ms(500);
-    while (count < 1) {
-        if (button1_click()) {
-            is_sender = 1;
-            orb_set_color(PURPLE);
-            count++;
-        }
-        if (button2_click()) {
-            is_sender = 0;
-            orb_set_color(ORANGE);
-            count++;
-        }
-    }
-    count = 0;
-
-    delay_ms(1000);
-
-    button1_wait();
-
-    delay_ms(500);
-
-    if (is_sender == 1) {
-        delay_ms(1000);
-        wl_basic_send_global_packet(1, "r", 2);
-        usb_puts("sent RED packet\r\n");
-        delay_ms(1000);
-        wl_basic_send_global_packet(1, "b", 2);
-        usb_puts("sent BLUE packet\r\n");
-        while(count < 2) {
-            packet = wl_basic_do_default(&length);
-            if (packet != 0) {
-                if (length > 0) {
-                    if (packet[0] == 'r') {
-                        orb_set_color(RED);
-                        usb_puts("received RED packet\r\n");
-                        count++;
-                    }
-                    else if (packet[0] == 'b') {
-                        orb_set_color(BLUE);
-                        usb_puts("received BLUE packet\r\n");
-                        count++;
-                    }
-                }
-            }
-        }
-    }
-    else {
-        while(count < 2) {
-            packet = wl_basic_do_default(&length);
-            if (packet != 0) {
-                if (length > 0) {
-                    if (packet[0] == 'r') {
-                        orb_set_color(RED);
-                        usb_puts("received RED packet\r\n");
-                        count++;
-                    }
-                    else if (packet[0] == 'b') {
-                        orb_set_color(BLUE);
-                        usb_puts("received BLUE packet\r\n");
-                        count++;
-                    }
-                }
-            }
-        }
-        delay_ms(1000);
-        wl_basic_send_global_packet(1, "r", 2);
-        usb_puts("sent RED packet\r\n");
-        delay_ms(1000);
-        wl_basic_send_global_packet(1, "b", 2);
-        usb_puts("sent BLUE packet\r\n");
-    }
-    delay_ms(1000);
-
-	wl_terminate();
-
-    orb_set_color(GREEN);
-
-    delay_ms(2000);
-
-    return 0;
-}
-
Index: branches/wireless/code/projects/unit_tests/test_xbee.c
===================================================================
--- branches/wireless/code/projects/unit_tests/test_xbee.c	(revision 1616)
+++ branches/wireless/code/projects/unit_tests/test_xbee.c	(revision 1617)
@@ -3,12 +3,7 @@
 
 #define ROBOT
 #define WL_DEBUG
-#define WL_DEBUG_PRINT( s ) usb_puts( S )
 
-extern int xbee_send_read_at_command(char* command);
-extern int xbee_get_packet(unsigned char* dest);
-extern void xbee_terminate(void);
-
 /*
  * This function tests the xbee, returning the results to teraterm
  *
@@ -23,11 +18,11 @@
 	usb_init();
 	usb_puts("usb turned on, test starting:\r\n");
   
-  if (xbee_lib_init() != 0) {
-    usb_puts("xbee_lib_init() failed\r\n");
+  if (xbee_init() != 0) {
+    usb_puts("xbee_init() failed\r\n");
     return -1;
   } else {
-    usb_puts("xbee_lib__init successful\r\n");
+    usb_puts("xbee_init successful\r\n");
   }
  
 	usb_puts("\r\n\n");
@@ -37,7 +32,7 @@
   
 	
 	// try getting xbee address
-  xbee_send_read_at_command("MY");
+  /*xbee_send_read_at_command("MY");
   while(i++ < 10000) {
     if(xbee_get_packet(buf) == 3) {
       usb_puts("got response from xbee\r\n");
@@ -46,7 +41,7 @@
       //usb_puts("|end\r\n");
       break; // got a response
     }
-  }
+  }*/
   
   // try setting channel
   /*xbee_set_channel(0x0F);
@@ -86,7 +81,7 @@
   usb_puts("\r\nwireless set channel works\r\n");*/
   
   // scan all xbees in network
-  xbee_send_read_at_command("ND");
+  /*xbee_send_read_at_command("ND");
   i=0;
   while(i < 1000) {
     if(xbee_get_packet(buf) == 3) {
@@ -93,11 +88,15 @@
       usb_puts("got response from xbee\r\n");
       i++;
     }
-  }
+  }*/
   
   // end of tests
-  xbee_terminate();
+  if (xbee_terminate() != 0) {
+    usb_puts("xbee_terminate error\r\n");
+  } else {
+    usb_puts("xbee_terminate success\r\n");
+  }
   usb_puts("testxbee done\r\n\r\n");
     
 	return 0;
-}
\ No newline at end of file
+}
Index: branches/wireless/code/projects/unit_tests/main.c
===================================================================
--- branches/wireless/code/projects/unit_tests/main.c	(revision 1616)
+++ branches/wireless/code/projects/unit_tests/main.c	(revision 1617)
@@ -18,7 +18,7 @@
     //RUN_TEST(testrangefinder);
     // RUN_TEST(testtokenring);
     // RUN_TEST(testwireless);
-    //RUN_TEST(testxbee);
+    RUN_TEST(testxbee);
     delay_ms(1000);
   }
 
Index: branches/wireless/code/projects/unit_tests/test_wireless.c.bak
===================================================================
--- branches/wireless/code/projects/unit_tests/test_wireless.c.bak	(nonexistent)
+++ branches/wireless/code/projects/unit_tests/test_wireless.c.bak	(revision 1617)
@@ -0,0 +1,114 @@
+/**
+ * Instructions:
+ *  - wait for both robots to show ORB 1 RED and ORB 2 GREEN
+ *  - press BUTTON 1 on robot to send first (ROBOT 1) - orbs should turn PURPLE
+ *  - press BUTTON 2 on robot to receive first (ROBOT 2) - orbs should turn ORANGE
+ *  - wait at least a second, then press BUTTON 1 on both robots SIMULTANEOUSLY
+ *  - ROBOT 2 orbs should cycle ORANGE to RED to BLUE
+ *  - then ROBOT 1 orbs should cycle PURPLE to RED to BLUE
+ *  - then orbs on both robots should turn GREEN
+ *  - test will reset to ORB 1 RED and ORB 2 CYAN
+ *  - test should take ~7 seconds
+ *
+ * Depends on:
+ *  - Orbs (Lights)
+ *  - Serial (for debugging)
+ **/
+
+#include <dragonfly_lib.h>
+#include <wl_basic.h>
+
+unsigned char* packet;
+int length;
+
+int testwireless(void) {
+    int count = 0;
+    int is_sender = 0;
+
+    wl_basic_init_default();
+    wl_set_channel(0x0E);
+
+    orb1_set_color(RED);
+    orb2_set_color(GREEN);
+    delay_ms(500);
+    while (count < 1) {
+        if (button1_click()) {
+            is_sender = 1;
+            orb_set_color(PURPLE);
+            count++;
+        }
+        if (button2_click()) {
+            is_sender = 0;
+            orb_set_color(ORANGE);
+            count++;
+        }
+    }
+    count = 0;
+
+    delay_ms(1000);
+
+    button1_wait();
+
+    delay_ms(500);
+
+    if (is_sender == 1) {
+        delay_ms(1000);
+        wl_basic_send_global_packet(1, "r", 2);
+        usb_puts("sent RED packet\r\n");
+        delay_ms(1000);
+        wl_basic_send_global_packet(1, "b", 2);
+        usb_puts("sent BLUE packet\r\n");
+        while(count < 2) {
+            packet = wl_basic_do_default(&length);
+            if (packet != 0) {
+                if (length > 0) {
+                    if (packet[0] == 'r') {
+                        orb_set_color(RED);
+                        usb_puts("received RED packet\r\n");
+                        count++;
+                    }
+                    else if (packet[0] == 'b') {
+                        orb_set_color(BLUE);
+                        usb_puts("received BLUE packet\r\n");
+                        count++;
+                    }
+                }
+            }
+        }
+    }
+    else {
+        while(count < 2) {
+            packet = wl_basic_do_default(&length);
+            if (packet != 0) {
+                if (length > 0) {
+                    if (packet[0] == 'r') {
+                        orb_set_color(RED);
+                        usb_puts("received RED packet\r\n");
+                        count++;
+                    }
+                    else if (packet[0] == 'b') {
+                        orb_set_color(BLUE);
+                        usb_puts("received BLUE packet\r\n");
+                        count++;
+                    }
+                }
+            }
+        }
+        delay_ms(1000);
+        wl_basic_send_global_packet(1, "r", 2);
+        usb_puts("sent RED packet\r\n");
+        delay_ms(1000);
+        wl_basic_send_global_packet(1, "b", 2);
+        usb_puts("sent BLUE packet\r\n");
+    }
+    delay_ms(1000);
+
+	wl_terminate();
+
+    orb_set_color(GREEN);
+
+    delay_ms(2000);
+
+    return 0;
+}
+
Index: branches/wireless/code/projects/unit_tests/test_tokenring.c.bak
===================================================================
--- branches/wireless/code/projects/unit_tests/test_tokenring.c.bak	(nonexistent)
+++ branches/wireless/code/projects/unit_tests/test_tokenring.c.bak	(revision 1617)
@@ -0,0 +1,98 @@
+#include <dragonfly_lib.h>
+#include <wireless.h>
+#include <wl_token_ring.h>
+
+
+/**
+ * Tests the token ring and BOM
+ * - prints table of bom values for every robot in token ring
+ * - takes several seconds to initialize token ring
+ */
+ 
+#define MAX_ROBOTS 16
+
+// set a list of integers to 0
+void clearRobots(int* list) {
+  for(int i=0;i<MAX_ROBOTS;i++)
+    list[i] = 0;
+}
+
+int testtokenring(void) {
+  usb_init();
+	usb_puts("usb turned on\r\n");
+  wl_init();
+  usb_puts("wireless turned on\r\n");
+  wl_token_ring_register();
+  wl_token_ring_join(); // join token ring
+  usb_puts("token ring joined\r\n");
+  int robotList[sizeof(int)*MAX_ROBOTS];
+  int numRobots = 0;
+  delay_ms(1000);
+  
+  // start testing wireless/token ring/BOM
+  int i=0;
+  while(1) {
+    wl_do();
+    // only print table every 200 loops
+    if (i%200==0) {
+      // get token ring size values
+      usb_puts("\r\nnumber of robots in token ring:");
+      usb_puti(wl_token_get_robots_in_ring());
+      usb_puts("\r\nnumber of robots in matrix:"); 
+      usb_puti(wl_token_get_num_robots());
+      
+      // get list of robots
+      numRobots = 0;
+      clearRobots(robotList);
+      wl_token_iterator_begin();
+      while(wl_token_iterator_has_next()) {
+        int tmp = wl_token_iterator_next();
+        if (tmp < 0)
+          break;
+        robotList[tmp] = 1;
+        numRobots++;
+      }
+      if (numRobots < 1) {
+        usb_puts("\r\nNo BOM table available.");
+        continue; // skip table printing
+      } else {
+        usb_puts("\r\nBOM table: (* indicates this robot)");
+      }
+      
+      // print table of bom readings between robots
+      usb_puts("\r\ns \\ d");
+      // print header
+      for(int j=0;j<MAX_ROBOTS;j++)
+        if (robotList[j]) {
+          usb_puts("\t|");
+          if (j == wl_get_xbee_id())
+            usb_puts("*"); // indicate that this is the current bot
+          usb_puti(j);
+        }
+      usb_puts("\r\n");
+      // print body
+      for(int l=0;l<MAX_ROBOTS;l++) 
+        if (robotList[l]) {        
+          if (l == wl_get_xbee_id())
+            usb_puts("*"); // indicate that this is the current bot
+          usb_puti(l); // print label col
+          for(int k=0;k<MAX_ROBOTS;k++) 
+            if (robotList[k]) {
+              usb_puts("\t|");
+              if (k != l) {
+                int bom = wl_token_get_sensor_reading(l,k);
+                if (bom >= 0 && bom <= 15)
+                  usb_puti(bom); // print bom value
+              }
+            }
+          usb_puts("\r\n");
+        }
+      usb_puts("\r\n");
+    }
+  }
+  
+  // end testing token ring and bom
+	return 0;
+}
+
+

Property changes on: branches/wireless/code/projects/unit_tests/test_tokenring.c.bak
___________________________________________________________________
Added: svn:mergeinfo
## -0,0 +0,0 ##
Index: branches/wireless/code/projects/libwireless/xbee.h
===================================================================
--- branches/wireless/code/projects/libwireless/xbee.h	(revision 1616)
+++ branches/wireless/code/projects/libwireless/xbee.h	(revision 1617)
@@ -110,8 +110,6 @@
  * @{
  **/
   
-// TODO: convert all int references to int16_t syntax (see stdint.h)
-
 /**@brief Initialize the XBee library **/
 int8_t xbee_init(void);
 /**@brief Uninitialize the XBee library **/
Index: branches/wireless/code/projects/libwireless/Makefile
===================================================================
--- branches/wireless/code/projects/libwireless/Makefile	(revision 1616)
+++ branches/wireless/code/projects/libwireless/Makefile	(revision 1617)
@@ -83,7 +83,8 @@
 #  -Wa,...:      tell GCC to pass this to the assembler.
 #    -adhlns...: create assembler listing
 CFLAGS =
-#CFLAGS += -g$(DEBUG)
+# debug is enabled.  comment out next line to disable
+CFLAGS += -g$(DEBUG)
 CFLAGS += $(CDEFS) $(CINCS)
 CFLAGS += -O$(OPT)
 CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
Index: branches/wireless/code/Makefile
===================================================================
--- branches/wireless/code/Makefile	(revision 1616)
+++ branches/wireless/code/Makefile	(revision 1617)
@@ -390,8 +390,8 @@
 	make clean -C $(COLONYROOT)/code/projects/libdragonfly
 	make dist -C $(COLONYROOT)/code/projects/libdragonfly
 ifdef USE_WIRELESS
-	make clean -C $(COLONYROOT)/code/projects/libwireless/lib
-	make dist -C $(COLONYROOT)/code/projects/libwireless/lib
+	make clean -C $(COLONYROOT)/code/projects/libwireless
+	make dist -C $(COLONYROOT)/code/projects/libwireless
 endif
 
 # Check if library needs to be built
@@ -399,7 +399,7 @@
 	@echo $(MSG_LIBRARY_CHECK)
 	make dist -C $(COLONYROOT)/code/projects/libdragonfly
 #ifdef USE_WIRELESS
-	make dist -C $(COLONYROOT)/code/projects/libwireless/lib
+	make dist -C $(COLONYROOT)/code/projects/libwireless
 #endif
 
 
