/*
 *  ax12syncpositionspeed.cpp
 *
 * $Id: ax12syncpositionspeed.cpp 1 2008-07-30 09:24:06Z mschneider $
 * $URL: svn://localhost/Bioloid/trunk/ax12syncpositionspeed.cpp $
 
 * \version   $Rev: 1 $
 * \author    Markus Schneider
 * \date      17.07.08
 *
 */


#include "ax12syncpositionspeed.h"

AX12SyncPositionSpeed::AX12SyncPositionSpeed(Connection *_conn)
: conn(_conn), swp(NULL)
{
  this->clear();
}

int AX12SyncPositionSpeed::add(AX12 *m, word position, word speed)
{
  return add(m->getId(), position, speed);
}

int AX12SyncPositionSpeed::add(byte id, word position, word speed)
{
  word buff[2];
  buff[0] = position;
  buff[1] = speed;
  return swp->add(id, buff);
}

int AX12SyncPositionSpeed::clear()
{
  if( swp != NULL )
    delete swp;
  swp = new SyncWritePacket(AX12_GOAL_POSITION_L, 4);
  return 0;
}

int AX12SyncPositionSpeed::execute()
{
  int status = conn->write(swp);
  this->clear();
  return status;
}
