#include <unistd.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <errno.h>
#include "MetraByteOutput.h"
#include "SharedData.h"
#include "PeriodicTask.h"
#include "SerialDevice.h"
#include "time.h"
#include "Syslog.h"
#include "MetraByteLog.h"
#include "StreamSerialDriver.h"

//#define BAUD 4800
//#define PARITY "NONE"
//#define STOP_BITS 1
//#define DATA_BITS 8
//#define READ_TIMEOUT 100

//#define VOLTAGE_MSG "$4RD\n"
//#define CURRENT_MSG "$2RD\n"

/*
CLASS 
MetraByte

DESCRIPTION
Keithley Metrabyte (Battery Subsystem) Driver

AUTHOR
John Rieffel

*/

class MetraByte : public PeriodicTask {
  
  friend class MetraByteLog;
  
 public:
  
  MetraByte();
  MetraByte(SerialDevice *interface);
  ~MetraByte();
  
 protected:
  
  enum DataType {
    CurrentData,
    VoltageData
  };

  // Initialize 
  DeviceIF::Status init();

  // Periodic callback
  void sample(void);

  // Read specified data type
  int getData(DataType dataType);

  MetraByteLog *_log;
  MetraByteOutput *_output;
  SerialDevice *_device;
};
