GX3.cpp
Go to the documentation of this file.
00001 /*
00002  * GX3.cpp
00003  *
00004  *  Created on: May 20, 2011
00005  *      Author: dnad
00006  */
00007 #include <microstrain/GX3.hpp>
00008 #include <microstrain/MicrostrainException.hpp>
00009 #include <microstrain/MicrostrainLib.hpp>
00010 #include <iostream>
00011 #include <boost/asio.hpp>
00012 
00013 using namespace LABUST::MICROSTRAIN;
00014 
00015 const size_t GX3::supportedFirmware(0);
00016 
00017 GX3::GX3(const std::string& portName, int baud):
00018     io(),
00019     port(io)
00020 {
00021   connect(portName, baud);
00022   checkFirmware();
00023   //readSetup();
00024 }
00025 
00026 void GX3::connect(const std::string& portName, int baud)
00027 {
00028   try
00029   {
00030     port.open(portName);
00031 
00032     if (port.is_open())
00033     {
00034       std::cout<<"Port "<<portName<<" is open."<<std::endl;
00035       port.set_option(boost::asio::serial_port::baud_rate(baud));
00036       port.set_option(boost::asio::serial_port::flow_control(boost::asio::serial_port::flow_control::none));
00037       port.set_option(boost::asio::serial_port::parity(boost::asio::serial_port::parity::none));
00038       port.set_option(boost::asio::serial_port::stop_bits(boost::asio::serial_port::stop_bits::one));
00039       port.set_option(boost::asio::serial_port::character_size(8));
00040     }
00041     else
00042     {
00043       throw MicrostrainException("Unable to open port.");
00044     }
00045   }
00046   catch (std::exception& e)
00047   {
00048     std::cout<<"Failed during port setup : "<<e.what()<<std::endl;
00049     throw e;
00050   }
00051 }
00052 
00053 void GX3::checkFirmware()
00054 {
00055   using namespace GX3COMMS;
00056   //Get firmware message
00057  /* ReadFirmwareVersion firmware;
00058   boost::asio::write(port,boost::asio::buffer(&firmware.command,1));
00059   boost::asio::read(port,boost::asio::buffer(firmware.response));
00060 
00061   std::cout<<firmware.response<<std::endl;*/
00062 }
00063 
00064 double GX3::heading()
00065 {
00066   unsigned char req = 0xCE;
00067   boost::asio::write(port, boost::asio::buffer(&req,1));
00068   boost::asio::read(port, boost::asio::buffer(&req,1));
00069   float data[4];
00070   boost::asio::read(port, boost::asio::buffer(data,sizeof(data)));
00071   short int chks = 0;
00072   boost::asio::read(port,boost::asio::buffer(&chks,sizeof(chks)));
00073 
00074   return GX3COMMS::byte_swap(data[2]);
00075 }


acoustic_vr
Author(s):
autogenerated on Fri Feb 7 2014 11:37:09