Subversion Repositories HomeAutomation

Rev

Rev 73 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  * File created by Jimmy
  3.  * at 2003-sep-03 13:39:58
  4.  */
  5. package Macbeth.Modules.modARNE;
  6.  
  7. import Macbeth.Utilities.UByte;
  8.  
  9. /**
  10.  * Represents an ARNE packet that can be transmitted
  11.  * or received to/from an ARNE network.
  12.  * @author Jimmy
  13.  */
  14. public class ARNEPacket {
  15.  
  16.     /**
  17.      * Maximum number of data bytes inside an ARNE packet.
  18.      */
  19.     public static final int MAX_ARNE_DATALEN = 15;
  20.  
  21.     /**
  22.      * The ARNE header bytes. There are always two of them.
  23.      */
  24.     public UByte[] header;
  25.  
  26.     /**
  27.      * The ARNE data bytes.
  28.      */
  29.     public UByte[] data;
  30.  
  31.     /**
  32.      * Creates a new instance of ARNEPacket.
  33.      */
  34.     public ARNEPacket() {
  35.         //always two header bytes
  36.         header = new UByte[2];
  37.         data = null;
  38.     }
  39.  
  40.     /**
  41.      * Sets the lenght of the data field in this packet.
  42.      * @param size The number of data bytes.
  43.      */
  44.     public void setDataLen(int size) {
  45.         data = new UByte[size];
  46.         //first header byte contains startbits and data size
  47.         header[0] = UByte.fromShort((short)(0xA0 | (0x0F & size)));
  48.     }
  49.  
  50.     /**
  51.      * Gets the length of the data field in this packet.
  52.      * @return The number of data bytes.
  53.      */
  54.     public int getDataLen() {
  55.         if (data!=null) {
  56.             return data.length;
  57.         } else {
  58.             return 0;
  59.         }
  60.     }
  61.  
  62.     /**
  63.      * Sets the node address to which this packet is to
  64.      * be delivered. This address will be saved in the
  65.      * ARNE header.
  66.      * @param address The destination node address.
  67.      */
  68.     public void setNodeAddress(short address) {
  69.         header[1] = UByte.fromShort(address);
  70.     }
  71.  
  72. }