/** \file
 *
 *  Contains the Power24vConverter class declaration.
 *
 *  Power24vConverter.h should only be included by Power24vConverter.cpp
 *  Other classes should include Power24vConverterIF.h
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 *
 *  This class simply provides power and a data writer to
 *  allowing a mission to request it
 */

#ifndef POWER24VCONVERTER_H
#define POWER24VCONVERTER_H

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

class UniversalDataWriter;


/**
 *  Provides software interface to power on/off the 24v power converter.
 *
 */
class Power24vConverter : public SyncSensorComponent
{
public:

    Power24vConverter( const Module* module );

    virtual ~Power24vConverter();

    /// 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();

    /// 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.
    Power24vConverter( const Power24vConverter& old ); // disallow copy constructor

    //*------------------- vehicle parameters --------------------------*/

    /// Power interface
    LoadControl loadControl_;

    /// Returns true if data is requested from the 24v converter
    bool isDataRequested( void );

    /// Powers up the 24v converter
    bool powerUpLoadControl( void );

    /// Powers down the 24v converter
    bool powerDownLoadControl( void );

    /// 24v converter power writer (the request interface)
    DataWriter* power24vConverterDataWriter_;

    /// Power off timeout (time to wait before powering off)
    Timespan powerOffTimeout_;

    /// Marks the power off request time
    Timestamp powerOffTime_;

    /// Indicates the 24v converter is powered
    bool powered_;

    /// Debugging outputs
    bool debug_;

};
#endif /*POWER24VCONVERTER_H*/
