/*
-----------------------------------------------------------------------------
This source file is part of OpenSpace3D
For the latest info, see http://www.openspace3d.com

Copyright (c) 2010 I-maginer

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt

You may alternatively use this source under the terms of a specific version of
the OpenSpace3D Unrestricted License provided you have obtained such a license from
I-maginer.
-----------------------------------------------------------------------------
*/

/*! \class SerialIO
  *  \brief Manage Serial device
  *  \
  *  \version 1.0
  *  \date jully 2011
  */
#ifndef __SERIAL_DEVICE_H__
#define __SERIAL_DEVICE_H__

#include "LSerie.h"
#include "thread.h"


/*!
*/
class SerialIO : public openutils::Thread
{
public:
	
protected:
private:
  LSerie* m_serial;
  int m_port;
  int m_baudrate;
  int m_parity;
  int m_byteSize;
  float m_stopBits;
  bool m_bRunning;
  bool m_bConnected;
  bool m_bLastConState;
  std::string* m_buffer;
  openutils::Mutex m_mutex;

public:
  /*!
  Constructor.
  */
  SerialIO(int port, int baudRate, int parity, int byteSize, int stopBits);

  /*!
  Destructor.
  */
  ~SerialIO();

  /*!
  Tell if the device is connected
  */
  bool IsConnected();

  /*!
  write on device
  */
  void Write(std::string data);

protected:
private:
  /*!
  Forbiden Constructor.
  */
  SerialIO();
  void run();
};

#endif
