import stamp.core.*;
import stamp.rf.*;
/**
 * Put a one line description of your class here.
 * <p>
 * This comment should contain a description of the class. What it
 * is for, what it does and how to use it.
 *
 * You should rename the class and then save it in a file with
 * exactly the same name as the class.
 *
 * @version 1.0 Date
 * @author Your Name Here
 */

public class xBeeTestRX
  {
  static Uart tx;
  static StringBuffer buff = new StringBuffer(16);
  static char temp;
  public static void main()
    {
    System.out.println("Booting...");
    XBee base = new XBee(CPU.pin6,CPU.pin7,0,"BASE NODE");
    System.out.println("Ready...");
    base.send("Communication Established\r");

    while (true)
      {
      while (base.byteAvailable())
        {
        temp = (char)base.rxByte();
        if (temp == 0x0D)
          {
          System.out.print("<CR>");
          }
        else System.out.print(temp);
        }

      while (Terminal.byteAvailable())
        {
        temp = Terminal.getChar();
        if (temp == 'd')
          {
          base.discover();
          }
        if (temp == 's')
          {
          base.save();
          System.out.println("\nSETTINGS SAVED!");
          }
        if (temp == 'n')
          {
          base.send("TEST TO NODE 0",0);
          }
        if (temp == 'g')
          {
          base.setGuardTime(5);
          System.out.println("\nGUARDTIME SET!");
          }
        if (temp == 'r')
          {
          System.out.print("\nLEVEL : -");
          System.out.print(base.getRFLevel());
          System.out.println("dBm");
          }
        if (temp == 'o')
          {
          System.out.print("\nGUARDTIME : ");
          System.out.println(base.getGuardTime());
          }
        buff.clear();
        buff.append(temp);
        base.send(buff);
       //tx.sendString("x+++x");
        }
      }
      // Your code goes here.
    }
  }
