#ifndef SERSENSOR_H
#define SERSENSOR_H

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#include <iwear-ser_sensor/devcom.h>

#define VERBOSE_SERSENSOR false

#ifndef STD_DEVICE
#define STD_DEVICE "/dev/ttyS0"
#endif
	  
#define IDENTIFICATION_CHANNEL_STD_PRIORITY 5

#define SENSOR_LIGHT 0
#define SENSOR_TEMPERATURE 1

// S_CONNECT[sensor][channel][values]
// --- not ready yet ---
const int S_CONNECT[2][3][7] = {
    {{481, 561, 529, -1, -1, -1, -1}, {292, 376, 509, -1, -1, -1, -1}, {172, 453, 354, -1, -1, -1, -1}},
    {{380, 509, 453, -1, -1, -1, -1}, {251, 561, 354, -1, -1, -1, -1}, {157, 376, 529, -1, -1, -1, -1}}
};
#define NUM_OF_VALUES 7

#define TOLERANCE 2

namespace iwear {
	namespace sensor {
namespace ser_sensor{
 
  /**
   * This class is the base class for every sensor class of the serial sensor
   * device. Every class should derivate from this class, because it offers
   * methods both for connecting and disconnecting and for testing if the the
   * equipment and sensors are connected.
   * @author Daniel Dahme, Uwe Krüger, Falko Buttler
   */
  class SerSensor: public Devcom {
    
  public:
   
  protected:
    
    /**
     * Constructor to get an instance of the SerSensor class
     */
    SerSensor();

    /**
     * Destructor to destroy an instance of the SerSensor class
     */
    ~SerSensor();
    
    /**
     * Connect to the serial sensor device for getting data.
     * @param device The port the equipment is connected at
     * @return true, if the connect has been successful. Sometimes it may take
     * some time until the connection is developed. In this case the method 
     * returns false. The connection test then can be done by the
     * device_connected method.
     */
    bool connect(char *device);

    /**
     * Break the connection to the serial sensor device.
     */
    void disconnect();
    
    /**
     * Check if given sensor is connected at the serial sensor device.
     * @param sensor_type the sensor type which should be checked for 
     * connection (e.g. SENSOR_LIGHT, SENSOR_TEMPERATURE)
     * @return The channel (0-7) the given sensor is connected at,
     * -1 if it's not connected
     */
    int sensor_connected(int sensor_type) const;
    
  };
}
}
}
#endif /*SERSENSOR_H*/
