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

#ifndef DYNAMXEL_H
#define DYNAMXEL_H

#include "dynamixel_defs.h"
#include "connection.h"

#define NO_ERROR 0
#define E_TX  -2
#define E_RX  -3
#define E_CRC -4

class Dynamixel
{
public:
  Dynamixel(const byte id, Connection *conn);
  virtual int readByte(const byte address, byte buff[], const byte nbytes) const;
  virtual int readByte(const byte address, byte *buff) const;
  virtual int readWord(const byte address, word buff[], const byte nwords) const;
  virtual int readWord(const byte address, word *buff) const; 
  
  virtual int writeByte(const byte address, const byte param[], const byte nbytes) const;
  virtual int writeByte(const byte address, const byte value) const; 
  virtual int writeWord(const byte address, const word param[], const byte nwords) const;
  virtual int writeWord(const byte address, const word value) const;   

  // pings a dynamixel module
  virtual bool ping() const;
  
  // get the id of this module
  virtual byte getId() const;
  
  virtual ~Dynamixel(){ }

protected:
  byte id;
  Connection *conn;
  Dynamixel(){}
  virtual int send(const Packet *txpkt, Packet *rxpkt) const;
};

#endif
