/** \file
 *
 *  Contains the AMEcho class declaration.
 *
 *  AMEcho.h should only be included by AMEcho.cpp
 *  Other classes should include AMEchoIF.h
 *
 *  Copyright (c) 2020 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 */

#ifndef AMECHO_H
#define AMECHO_H

#include "AMEchoIF.h"

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

#include "data/Point3D.h"
#include "data/Point6D.h"
#include "data/Matrix3x3.h"

class UniversalDataReader;
class UniversalDataWriter;

#define ECHO_UART_BUFSIZE 256L

class AMEcho : public SyncSensorComponent
{
public:

    AMEcho( const Module* module );

    virtual ~AMEcho();

    virtual void run();
    virtual RunState start();
    virtual RunState starting();
    virtual RunState pause();
    virtual RunState paused();
    virtual RunState resume();
    virtual RunState resuming();
    virtual RunState runnable();

    virtual RunState resetting()
    {
        return stop();
    }

    virtual RunState stop();
    virtual RunState stopping();
    virtual RunState stopped();
    void uninitialize();
    void logVoltageAndCurrent();
    /// Should return [myNamespace]::SIMULATE_HARDWARE, or [myNamespace]::POWER, etc
    virtual ConfigURI getConfigURI( ConfigOption configOption ) const;

private:
    AMEcho( const AMEcho& old );

    // scan configuration settings
    void readConfig();

    bool belowDepthThreshold( void );
    bool isDataRequested( void );
    bool checkTimeouts( void );
    bool getSimAltitude( void );
    bool verifyChecksum( char *msg, char sum );
    bool readAltitude( void );

    Timespan commsTimeout_;
    Timespan powerOnTimeout_;
    Timestamp startTime_;
    float altitude_;

    UniversalDataWriter* altitudeWriter_;

    UniversalDataReader* depthReader_;
    DataReader* power24vConverterDataReader_;

    ConfigReader* enabledCfgReader_;
    ConfigReader* depthThresholdCfgReader_;

    bool enabled_;
    bool debug_;
    float depthThreshold_;
    char deviceResponse_[ECHO_UART_BUFSIZE];
    UartStream uart_;
    LoadControl loadControl_;
};
#endif /*AMECHO_H*/
