/****************************************************************************/
/* Copyright (c) 2015 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  : Power Buoy Data Logger log file writer class                  */
/* Filename : fileSource.hpp                                                */
/* Author   : Henthorn                                                      */
/* Project  : Power Buoy                                                    */
/* Version  : 1.0                                                           */
/* Created  : 04/21/2015                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
/*                                                                          */
/* This class is meant to be used with data source objects to write source  */
/* to a log file.                                                           */
/*                                                                          */
/****************************************************************************/

#include "Crossbow.hpp"
#include "CanBus.hpp"

#ifndef _LOGWRITER_
#define _LOGWRITER_

class LogWriter {

public:

   // LogWriter constructor opens a log file for writing.
   //
   LogWriter(const char *filename);

   virtual ~LogWriter();

   virtual FILE* get_file() { return _file; }

   virtual int update_xbow_record(Crossbow::XB_Record *xb_rec);
   virtual int update_boost_record(CanBus::BC_Record *bc_rec);
   virtual int update_spring_record(void *sc_rec);

protected:

   int write_header();
   int write_record();     // Write complete record to log file
   int write_xb();         // Write the Crossbow record
   int write_bc();         // Write the Boost Controller record
   int write_sc();         // Write the Spring Controller record

   char *_name;
   FILE* _file;

   Crossbow::XB_Record _xb;
   CanBus::BC_Record   _bc;
};

#endif
