/****************************************************************************/
/* Copyright (c) 2012 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : CathxM12Log.cc                                                */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 09/17/2015                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#include "DataLogWriter.h"
#include "CathxM12Log.h"
#include "CathxM12Output.h"
#include "CathxM12.h"
#include "ShortData.h"
#include "TimeP.h"
#include "Syslog.h"

CathxM12Log::CathxM12Log(CathxM12 *c,
           DataLog::FileFormat fileFormat,
           const char* name)
   : _cathxM12(c),
     DataLogWriter(name, fileFormat, AutoTimeStamp)
{
  init();
}


void CathxM12Log::init(void)
{
  char dname[100];
  sprintf(dname, "%s.data", name());
  setMnemonic(dname);

  // Indicates that the CathxM12 board initialized and ready

  // CathxM12 state
  //
  sprintf(dname, "%s.saving", name());
  addField((_saving = new IntegerData(dname)));

  sprintf(dname, "%s.capture", name());
  addField((_capture = new IntegerData(dname)));

  sprintf(dname, "%s.profile", name());
  addField((_profile = new IntegerData(dname)));

  sprintf(dname, "%s.img_total", name());
  addField((_img_total = new IntegerData(dname)));

  sprintf(dname, "%s.img_session", name());
  addField((_img_session = new IntegerData(dname)));

  sprintf(dname, "%s.unresponsive", name());
  addField((_unresponsive = new IntegerData(dname)));

  sprintf(dname, "%s.storage", name());
  addField((_storage = new IntegerData(dname)));

}


CathxM12Log::~CathxM12Log()
{
}


void CathxM12Log::setFields()
{
   Boolean debug = False;


   if( _cathxM12 )
   {
      _saving->setValue(_cathxM12->_saving);
      dprintf("saving: %d", _cathxM12->_saving);
      _capture->setValue(_cathxM12->_capture_state);
      dprintf("capture: %d", _cathxM12->_capture_state);
      _profile->setValue(_cathxM12->_profile);
      dprintf("profile: %d", _cathxM12->_profile);
      _img_total->setValue(_cathxM12->_total);
      dprintf("total: %d", _cathxM12->_total);
      _img_session->setValue(_cathxM12->_session);
      dprintf("session: %d", _cathxM12->_session);
      _unresponsive->setValue(_cathxM12->_unresponsive);
      dprintf("unresposive: %d", _cathxM12->_session);
      _storage->setValue(_cathxM12->_available_space/1000); // in GB
      dprintf("storage: %d", _cathxM12->_available_space/1000);
   }
}
