/*
 *  packet.h
 *
 * $Id: packet.h 2 2008-07-30 09:28:03Z mschneider $
 * $URL: svn://localhost/Bioloid/trunk/packet.h $
 
 * \version   $Rev: 2 $
 * \author    Markus Schneider
 * \date      17.07.08
 *
 */

#ifndef PACKET_H
#define PACKET_H

#include <stdio.h>
#include "dynamixel_defs.h"


/***********************************************************************
* PACKET
***********************************************************************/
class Packet
{
public:
  static const int MAX_PARAM = 255;
  
  byte id;
  byte len;
  union{byte cmd; byte error;};
  byte paramPtr;
  byte param[ MAX_PARAM ];
  byte crc; 
 
 /**
  * default constructor
  */
  Packet();  
  
 /**
  * default constructor
  * @param id The dynamixel id
  * @param cmd The command to use. See dynamixel_defs.h INST_*
  * @param param The parameter for the command
  * @param paramcnt The number of parameters
  */  
  Packet(byte id, byte cmd, byte param[], byte paramcnt); 
        
                    
 /**
  * copy constructor
  */ 
  Packet(const Packet &pkt);  
  
 /**
  * Tests two Packets for equality
  */
  virtual bool operator==(const Packet &pkt) const; 
  
 /**
  * Tests two Packets for non-equality
  */  
  virtual bool operator!=(const Packet &pkt) const;    
  
 /**
  * the assignment operator
  */
  virtual Packet &operator=(const Packet &pkt);  
  
 /**
  * Print Packet to a FILE
  */ 
  virtual void fprint(FILE *stream) const;  
  
 /**
  * return true if crc != 0xFF
  */ 
  virtual bool crcError() const;
  
 /**
  * sets all values to 0x00
  */
  virtual void reset();
  
  virtual byte calcChecksum() const;
  
  virtual ~Packet();
  
};

#endif
