/** \file
 *
 *  Contains the VemcoVR2C class declaration.
 *
 *  VemcoVR2C.h should only be included by VemcoVR2C.cpp
 *  Other classes should include VemcoVR2CIF.h
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 */

#ifndef VemcoVR2C_H
#define VemcoVR2C_H

#include "VemcoVR2CIF.h"

#include "component/SyncComponent.h"
#include "io/LoadControl.h"
#include "io/UartStream.h"
#include "logger/Logger.h"

class UniversalDataWriter;

/**
 *  Provides software interface to the VemcoVR2C sensor.
 *
 *  \ingroup modules_science
 */

class VemcoVR2C : public SyncSensorComponent
{
public:

    VemcoVR2C( const Module* module );

    virtual ~VemcoVR2C();

    virtual void run();

    /// Do what needs to be done to run
    /// Similar to initialize, in old init/run/uninit sequence
    virtual RunState start();

    /// Might follow a STOP...START sequence
    virtual RunState starting();

    /// Pause for a short period (indicated by pauseTime)
    virtual RunState pause();

    /// Should eventually follow a PAUSE request: should set continueTime
    virtual RunState paused();

    /// Resume from PAUSE
    virtual RunState resume();

    /// Might follow a PAUSE...RESUME sequence
    virtual RunState resuming();

    /// Should eventually follow a START request or RESETTING
    virtual RunState runnable();

    /// Might occur in case of Error
    virtual RunState resetting()
    {
        return start();
    }

    /// Initial state -- can be later followed by START
    virtual RunState stop();

    virtual RunState stopping();

    /// Initial state -- can be later followed by START
    virtual RunState stopped();

    void uninitialize( void );

    /// Should return [myNamespace]::SIMULATE_HARDWARE, or [myNamespace]::POWER, etc
    virtual ConfigURI getConfigURI( ConfigOption configOption ) const;

private:
    // Note that the copy constructor below is private and not given a body.
    // Any attempt to call it will return a compiler error.
    VemcoVR2C( const VemcoVR2C& old ); // disallow copy constructor

    BlobWriter* responseStringWriter_;
    DataWriter* tagIDWriter_;
    DataWriter* adCountWriter_;

    // Really? It reads and parses responses from the Vemco.
    void readAndParseResponses( void );

    // returns true if data is requested from one of the readers
    bool isDataRequested();

    // Queries the LCBs for status
    bool logVoltageAndCurrent();

    // Stores the current response from the device
    char deviceResponse_[396];

    /// Holds the communications device
    UartStream uart_;

    /// Power and comms in this case
    LoadControl loadControl_;

    // Outputs to slate
    DataWriter* samplingActiveWriter_;

    /// Debugging outputs
    bool debug_;

    int tagID_, adCount_;

};
#endif /*VemcoVR2C_H*/
