/** \file
 *
 *  Contains the BioacousticsDataBridge class declaration.
 *
 *  BioacousticsDataBridge.h should only be included by BioacousticsDataBridge.cpp
 *  Other classes should include BioacousticsDataBridgeIF.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 BIOACOUSTICSDATABRIDGE_H
#define BIOACOUSTICSDATABRIDGE_H

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

class UniversalDataWriter;


/**
 *  TODO
 *
 */
class BioacousticsDataBridge : public SyncSensorComponent
{
public:

    BioacousticsDataBridge( const Module* module );

    virtual ~BioacousticsDataBridge();

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

    DataReader* backseatAltitudeDataReader_;
    DataReader* lcmHeartbeatReader_;
    UniversalDataWriter* altitudeWriter_;

    // Placeholder DataValue for altitude reader
    static const StrValue NO_VALUE;

#ifdef __GAZEBO
    static constexpr float ALTITUDE_ACCURACY = 0.1;

    //static const float LCM_HEARTBEAT_TIMEOUT_SEC = 60 * 5;
    // Time after which to pause trying to read altitude
    static constexpr float LCM_HEARTBEAT_TIMEOUT_SEC = 10;

    // Time after which to invalidate old altitude
    static constexpr float ALTITUDE_TIMEOUT_SEC = 5;
#else
    static const float ALTITUDE_ACCURACY = 0.1;

    //static const float LCM_HEARTBEAT_TIMEOUT_SEC = 60 * 5;
    // Time after which to pause trying to read altitude
    static const float LCM_HEARTBEAT_TIMEOUT_SEC = 10;

    // Time after which to invalidate old altitude
    static const float ALTITUDE_TIMEOUT_SEC = 5;
#endif

    Timespan altitudeTimeout_;
    Timespan lcmHeartbeatTimeout_;

    // Timestamp of latest altitude from backseat
    Timestamp lastAltitudeTs_;

    // Latest altitude from backseat
    float altitude_;

    /// Debugging outputs
    bool debug_;

};
#endif /*BioacousticsDataBridge_H*/
