#ifndef RS232COM_H
#define RS232COM_H

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include <sys/ioctl.h>

#include <sys/time.h>
#include <sys/types.h>

#define VERBOSE_RS232COM false 

namespace iwear {
namespace sensor {
namespace ser_sensor{

  /**
   * The function of this class (RS232com = RS232 communication) is to 
   * communicate with the serial port of the computer. It offers methods for
   * setting levels at DTR and RTS and for the getting of the level at CTS.
   * There's also a method for making a small pause to retard the communication
   * with devices. With special open and close methods a connection can be
   * built to. 
   * @author Daniel Dahme, Uwe Krüger
   */  
  class RS232com {
    
  protected:
    
    /**
     * constructor to get an instance of the RS232com class
     */  
    RS232com();

    /**
     * destructor to destroy an instance of the RS232com class
     */
    ~RS232com();
    
    /**
     * Open the serial port for setting levels of pins
     * @param device The serial port to communicate with
     */
    void open_port(const char *device);

    /**
     * Close the serial port an stop communication
     */
    void close_port();
    
    /**
     * Set the level of the DTR pin
     * @param bit The level to be set (0=low, 1=high).
     * @return An error value (0=everything is ok)
     */
    int set_dtr(int bit);
    
    /**
     * Set the level of the RTS pin
     * @param bit The level to be set (0=low, 1=high).
     * @return An error value (0=everything is ok)
     */
    int set_rts(int bit);
    
    /**
     * Get the level of the CTS pin
     * @param bit The level to be gotten (0=low, 1=high).
     * @return An error value (0=everything is ok)
     */
    int get_cts(int* bit) const;
   
    /**
     * Make a brake with the length in seconds of the given time
     * @time The length of the break in seconds
     */
    void do_pause(double time) const;
    
  private:
    
    /**
     * The file discriptor for opening the port
     */
    static int fd;

    /**
     * Whole line data of the port for communication
     */
    static int lines;
    
  };

}
}
}
#endif /*RS232COM_H*/

