/** \file tfd128.h 
\brief Header
*/

#ifndef __TFD128__
#define __TFD128__


#define STX 0x02
#define ETX 0x03
#define ENQ 0x05
#define ACK 0x06
#define NAK 0x15

// define the Baudrate
#define BAUDRATE B38400

typedef unsigned short U16;
typedef unsigned char U8;




//! \struct sDate TFD128 Date structure 
struct sDate
{
    U16 uYear;              /*!< Year, beginning is 0 */
    U8 uMonth;              /*!< Month */
    U8 uDay;                /*!< Day */
    U8 uHours;              /*!< Hour */
    U8 uMinutes;            /*!< Minutes */
    U8 uSeconds;            /*!< Seconds */
};


//! \struct startData Data to be sent by the 'S' command
struct startData
{
    struct sDate sCurDate;      /*!< Start Time */
    U8 mode;                    /*!< Mode 2, 3*/
    U8 interval;                /*!< Interval in sec 1-5*/
};


//! \struct AllData Data received by the 'Z' command
struct AllData
{
    struct sDate sStartDate;     /*!< Start Time */
    U8 mode;                    /*!< Mode 2, 3*/
    U8 interval;                /*!< Interval in sec 1-5*/
    struct sDate sStopDate;     /*!< Stop Time */
};



//! Set the FTDI chip to the right valus
/*!
    \return Succeeded
*/
int init(void);


//! Write a byte to the TFD128
/*!
    \param buf Byte to be written
*/
void writeTFD(U8 buf);


//! Read a byte from the TFD128
/*!
    \return Byte read from TFD128
 */
U8 readTFD(void);

//! Command the TFD128
/*!
    \param cmd Command
    \param *data Pointer for storage of received data
    \param datalen Number of bytes to be written
    \return Received Bytes for this command
 */
int commandTFD(char cmd, U8 *data, int datalen);

//! Get current time
/*!
    \return Current time
 */
struct sDate getTime(void);

//! Get the version number
/*!
    \return Version Number
 */
U16 getVersionNumb(void);

//! Get Number of stored datapoints
/*!
    \return Number of datapoints
 */
U16 getDataPointsCount(void);

//! Start logging
/*!
    \param mode 2 = temp; 3 = temp + hum
    \param interval Seconds
    \return Succeeded
 */
U16 startLogging(U8 mode, U8 interval);

//! Stop gogging
/*!
    \return Succeeded
 */
U16 stopLogging(void);

//! Shows log values
/*!
    
 */
void showLog(void);

//! Checks if FTD128 is busy
/*!
    \return 1: busy; 2: not busy
 */
U8 busy(void);

//! Get the parameter values
/*!
    \return Starttime, Stoptime, mode, interval
 */
struct AllData getAllData(void);

//! Show the time 
/*!
    \param Date Time to show
*/
void  showTime(struct sDate Date);



#endif 
