/*
 *  simple_packet.cpp
 *  Bioloid
 *
 *  Created by Markus Schneider on 4/10/08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "serialport_d2xx.h"
#include "serialport_ftdi.h"
#include "connection.h"
#include "packet.h"

int main (int argc, char * const argv[]) 
{
  int status;
  
  // create serial port
  SerialPort *port = new SerialPort_FTDI();
  
  // init connection
  Connection conn(port);  
  
  // create a new packet: 
  // dynamixel id 9
  // ping command
  // no parameters
  Packet *pkt = new Packet(9, INST_PING, NULL, 0);
  
  // print instruction packet to stdout: [0xff 0xff 0x9 0x2 0x1 0xf3]
  pkt->fprint(stdout);
  
  // transmit packet
  status = conn.write(pkt);
  
  // read packet
  status = conn.read(pkt);
  
  // print statuspacket to stdout: [0xff 0xff 0x9 0x2 0x0 0xf4]
  pkt->fprint(stdout);
  
  delete port;
  delete pkt;
  
  return 0;
}


