#ifndef _NARADA_DEVICE_H_
#define _NARADA_DEVICE_H_

#include <klog.h>

#include "shinwa_proto.h"

class NaradaBattery
{
	enum eAntitheft
	{
		ANTI_THEFT_UNKNOWN,
		ANTI_THEFT_NOT_SUPPORTED,
		ANTI_THEFT_SUPPORTED,
	};

   cKlog logger;
   int mSerialPortFD;
   char mLabel[64];
   char mSerialPort[64];
   int mSerial;
   int mAddress;
   ShinwaTelemetry mTelemetry;

   int mAnitTheftTimeout;
   time_t mAntiTheftServiced;
   eAntitheft mAntiThefSupported;

   void txWakeUpCommands();

   int transaction(uint8_t *buffer, int buffer_len, int tx_len);

   bool readTelemetry();
   bool isAntitheftSupported(uint8_t *anti);
   bool readLockedTime(uint16_t *timeout);
   bool writeLockedTime(uint16_t timeout);
   //bool readVoltageLockedTime();
   bool releaseLock();
   bool serviceAntiTheft();

public:
   NaradaBattery(
         const char *label,
         const char *serial_port,
         int serial,
         int address,
		 int anti_theft
      );
   virtual ~NaradaBattery();

   void setSerialPortFD(int fd){ mSerialPortFD = fd; }

   const char* getSerialPort(){ return mSerialPort; }
   int getAddress(){ return mAddress; }
   const char* getLabel(){ return mLabel; }
   int getSerial(){ return mSerial; }

   bool sample();
   ShinwaTelemetry *getTelemetry(){ return &mTelemetry; }
   void debugDetails();

};

#endif /* _NARADA_DEVICE_H_ */
