/* +---------------------------------------------------------------------------+
   |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
   |                                                                           |
   |                   http://mrpt.sourceforge.net/                            |
   |                                                                           |
   |   Copyright (C) 2005-2008  University of Malaga                           |
   |                                                                           |
   |    This software was written by the Perception and Robotics               |
   |      research group, University of Malaga (Spain).                        |
   |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
   |                                                                           |
   |  This file is part of the MRPT project.                                   |
   |                                                                           |
   |     MRPT is free software: you can redistribute it and/or modify          |
   |     it under the terms of the GNU General Public License as published by  |
   |     the Free Software Foundation, either version 3 of the License, or     |
   |     (at your option) any later version.                                   |
   |                                                                           |
   |   MRPT is distributed in the hope that it will be useful,                 |
   |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
   |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
   |     GNU General Public License for more details.                          |
   |                                                                           |
   |     You should have received a copy of the GNU General Public License     |
   |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
   |                                                                           |
   +---------------------------------------------------------------------------+ */

#ifndef CBoardENoses_H
#define CBoardENoses_H

#include <lib_hwdrivers/CInterfaceFTDIMessages.h>

#include <MRPT/MRML/CObservationGasSensors.h>
#include <MRPT/UTILS/CConfigFileBase.h>


namespace HWDRIVERS
{
	/** A class for interfacing an e-Noses via a FTDI USB link.
	  *  Implemented for the board v1.0 designed by 2007 @ ISA (University of Malaga).
	  *
	  *  \code
	  *  PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
	  * -------------------------------------------------------
	  *   [supplied_section_name]
	  *    USB_serialname=ENOSE001
	  *
	  *    ; 3D position (in meters) of the master +slave eNoses
	  *    enose_poses_x=<MASTER X> <SLAVE#1 X> <SLAVE#2 X> <SLAVE#3 X>...
	  *    enose_poses_y=<MASTER Y> <SLAVE#1 Y> <SLAVE#2 Y> <SLAVE#3 Y>...
	  *    enose_poses_z=<MASTER Z> <SLAVE#1 Z> <SLAVE#2 Z> <SLAVE#3 Z>...
	  *
	  *    ; 3D pose angles (in degrees) of the master +slave eNoses
	  *    enose_poses_yaw=<MASTER YAW> <SLAVE#1 YAW> <SLAVE#2 YAW> <SLAVE#3 YAW>...
	  *    enose_poses_pitch=<MASTER PITCH> <SLAVE#1 PITCH> <SLAVE#2 PITCH> <SLAVE#3 PITCH>...
	  *    enose_poses_roll=<MASTER ROLL> <SLAVE#1 ROLL> <SLAVE#2 ROLL> <SLAVE#3 ROLL>...
	  *
	  *  \endcode
	  *
 	  */
	class CBoardENoses : public HWDRIVERS::CInterfaceFTDIMessages
	{
	protected:
		/** A copy of the device serial number (to open the USB FTDI chip)
		  */
		std::string		m_usbSerialNumber;

		/** The 3D pose of the master + N slave eNoses on the robot (meters & radians)
		  */
		std::vector<float>	enose_poses_x,enose_poses_y,enose_poses_z,enose_poses_yaw,enose_poses_pitch,enose_poses_roll;

		/** Tries to connect to the USB device (if disconnected).
		  * \return True on connection OK, false on error.
		  */
		bool	checkConnectionAndConnect();

	public:
		/** Constructor
		  * \param serialNumberUSBdevice The serial number (text) of the device to open.
		  *  The constructor will try to open the device. You can check if it failed calling "isOpen()".
		  */
		CBoardENoses( );

		/** Destructor
		  */
		virtual ~CBoardENoses();

		/** Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, loading from the section "[iniSection]" (see UTILS::CConfigFileBase and derived classes)
		  *  See HWDRIVERS::CBoardENoses for the possible parameters
		  */
		void  loadConfig(
			const UTILS::CConfigFileBase *configSource,
			const std::string	  &iniSection );

		/** Query the firmware version on the device (can be used to test communications).
		  * \return true on success, false on communications errors or device not found.
		  */
		bool	queryFirmwareVersion( std::string &out_firmwareVersion );

		/** Request the master eNose the latest readings from all the eNoses.
		  *  The output observation contains a valid timestamp and 3D positions if "loadConfig" has been called previously.
		  * \return true if OK, false if there were any error.
		  */
		bool getObservation( MRML::CObservationGasSensors &outObservation );



	}; // end of class

} // end of namespace


#endif


