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

#ifndef DYNAMIXEL_DEFS_H
#define DYNAMIXEL_DEFS_H

typedef unsigned char byte;
typedef unsigned short word;

// convert a word into 2 bytes
#define lowbyte(w)  ((byte) w)
#define highbyte(w) ((byte) (w >> 8))

// convert a word into 2 bytes with sign
#define highbyte_s(w) (w&0x80000000?(byte)(w >> 8)|(0x8000):(byte)(w >> 8))

// convert 2 bytes into a word
#define byte2word(high, low) ((high << 8) | low)

// convert 2 bytes into a signed word (int)
#define byte2word_s(high, low) high&0x80?((high<<8)|low|0xffff0000):((high << 8)|low)

#define WORD_MAX_SIZE  32767
#define WORD_MIN_SIZE -32767

#define BROADCAST_ID 0xFE

//---INSTRUCTIONS ---
#define INST_PING           0x01
#define INST_READ           0x02
#define INST_WRITE          0x03
#define INST_REG_WRITE      0x04
#define INST_ACTION         0x05
#define INST_RESET          0x06
#define INST_DIGITAL_RESET  0x07
#define INST_SYSTEM_READ    0x0C
#define INST_SYSTEM_WRITE   0x0D
#define INST_SYNC_WRITE     0x83
#define INST_SYNC_REG_WRITE 0x84

//---ERRORCODES---     
#define E_INPUT_VOLTAGE 0x01
#define E_ANGLE_LIMIT   0x02
#define E_OVERHEATING   0x04
#define E_RANGE         0x08
#define E_CHECKSUM      0x10
#define E_OVERLOAD      0x20
#define E_INSTRUCTION   0x40

/*
const char* DyError2Str(short errorcode)
{          
  switch(errorcode){
    case(E_INPUT_VOLTAGE): return "E_INPUT_VOLTAGE";
    case(E_ANGLE_LIMIT):   return "E_ANGLE_LIMIT";
    case(E_OVERHEATING):   return "E_OVERHEATING";
    case(E_RANGE):         return "E_RANGE";
    case(E_CHECKSUM):      return "E_CHECKSUM";
    case(E_OVERLOAD):      return "E_OVERLOAD";
    case(E_INSTRUCTION):   return "E_INSTRUCTION";
    default:               return "E_NO_SUCH_ERRORCODE"; 
  }
}*/
                      
#endif
