/******************************************************************************
 * FILE:			SerialSensor.h:	
 *
 * Description:	This file is the interface for which to to interface
 *		with serial port devices. The usage of this is as
 *		follows:
 *		1) 	inherit the interface to a specfic device 
 *		2) 	fill in the structure of SerialPort and
 *		   	pass it to initSerialPort().
 *		   	NOTE: SerialPort is defined in SerialPort.h
 *		3) 	implement the parse function, you can use
 *		   	the serialData pointer to hold your structure.
 *		   	*((*LogginStringIn)serialData) = loggingStringIn;
 *		4) 	implement the setSystem Data function.
 *		5)	register your serialSensor object by calling.
 *			ssObjPtr->registerSelf();
 *		Let SerialSensorMG handle the the rest.
 *
 *		NOTE: SerialSensorMG keeps a reference count on the number
 *			of SerialSensor objects around. SerialSensorMG::run()
 *			- run() will continually call parse()/setSystemData()
 *			on all the Serial Sensor objects.					
 *
 * DATE of Creation:			Oct. 13 / 2002				       	
 * DATE of last Modification:		NOV. 8 / 2002
 *****************************************************************************/

#ifndef __SERIAL_DEVICE_H
#define __SERIAL_DEVICE_H

/* c++ headers */
#include <iostream>		// c++ header file

/* c headers */
#include <string.h>		// string function def		
#include <termios.h>		// Posix terminal control def
#include <stdio.h>		// standard input/output def
#include <unistd.h>		// UNIX standard function def
#include <fcntl.h>		// file control def
#include <errno.h>		// errno number def
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>



class SerialDevice {
public:
	SerialDevice(char*, int, int);		// deviceName, period, type
	bool	initSerialPort(int, int, int, int, int);	// sets up the serial port
	const int handle();			// returns the handle
	const char* name();			// returns the device name
	const int frequency();			// returns the freq
	const int type_();
	virtual bool parse() = 0;		// parse the internal data
	virtual void setSystemData() = 0;	// set the system variables
	virtual int send() = 0;			// write data
		
	virtual ~SerialDevice();			// pure virtual destructor	

protected:
	int	fdHandle;			// handle to file descriptor
	char	deviceName[64];			// serial port device Name
	int	period;				// thread_period to write if it's
						// not a sensor.
						// period == 0 means it's a sensor  
	int 	type;	
        static 	char	parityError;
	

private:
	// copy of the current device is prohibited
	SerialDevice& operator=(const SerialDevice& rhs);
	SerialDevice(const SerialDevice& rhs);
	static int numSerialSensors;		// serial sensor object counter

};


#endif
