// Filename: external/TSerial.h
// Author: Jorge Bernadas (JB)
// Date of Creation: 11/02/2007
// Version: 1.0
//
// TODO(jbernadas): Put general comment here!
#ifndef EXTERNAL_TSERIAL_H__
#define EXTERNAL_TSERIAL_H__

/*
#include "tchar.h"
#include "windows.h"
#include "base/General.h"
#include "base/Types.h"
*/

#include "../global.h"
#include "../Includes/Basic.h"

//BEGIN_ENGINE_NAMESPACE();
//BEGIN_ENGINE_SUB_NAMESPACE(ext);
BEGIN_TEG_NAMESPACE();

namespace ext {

class TSerial {
public:
  // enumerate to indicate the port's parity
  enum SerialParity {NO_PARITY = NOPARITY, ODD_PARITY = ODDPARITY, EVEN_PARITY = EVENPARITY};

  // standard constructor and destructor
  TSerial();
  ~TSerial();

  // methods to connect and disconnect the serial port
  bool Connect(const _TCHAR* port, int baudrate, SerialParity parity);
  void Disconnect();

  // methods to send and get an array of bytes from the port
  int SendArray(const char* buffer, int count);
  int GetArray(char* buffer, int count);

  // method to get the number of bytes available to read
  int GetAvailableBytes();

protected:
  // string to store port's name ("COM1" or "COM2")
  static const int kMaxPortNameLength = 32;
  _TCHAR port_[kMaxPortNameLength];

  // port's configuration
  int baudrate_;         // baudrate used
  SerialParity parity_;  // parity used
  
  // Win32 handle to the file
  HANDLE handle_;        
};

}; // Namespace ext
//END_ENGINE_SUB_NAMESPACE(ext);
//END_ENGINE_NAMESPACE();
END_TEG_NAMESPACE();

#endif  // EXTERNAL_TSERIAL_H__
