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

#ifndef SCPI_H
#define SCPI_H

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

class UniversalDataWriter;

/**
 *  Provides software interface to the Self Contained Plankton Imager camera.
 *
 *  \ingroup modules_science
 */

class SCPI : public SyncSensorComponent
{
public:

    SCPI( const Module* module );

    virtual ~SCPI();

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

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

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

    Timespan sampleTime_;

    ///////////////////////////////////

    // initialize vehicle config variables
    bool loadParams( void );
    bool readConfig( void );

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

    // indicates whether things are ok to run
    bool ok_;

    // Power for the Freewave
    LoadControl loadControl_;

    /// Time data request started
    Timestamp startTime_;

    /// Timeout for powering down/up
    Timespan powerOnTimeout_;

    /// Debugging outputs
    bool debug_;

    /// A sample is in process
    bool sampling_;

    // Holds the communications device
    UartStream uart_;

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

    DataWriter* samplingSCPIDataWriter_;

    ConfigReader* sampleTimeCfgReader_;

};
#endif /*SCPI_H*/
