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

#ifndef ROWE_600_H
#define ROWE_600_H

#include "Rowe_600IF.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 UART_BUFSIZE 10240L

class Rowe_600 : public SyncSensorComponent
{
public:

    Rowe_600( const Module* module );

    virtual ~Rowe_600();

    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:
    Rowe_600( const Rowe_600& old );

    // scan configuraiton settings
    void readConfig();

    bool checkTimeouts( void );
    bool simPD13( void );
    bool readPD13( void );
    bool parsePD13( void );
    void processPD13( void );
    void writeData( void );
    void setAcousticWritersInvalid( bool invalid );

    bool hasPD13_;

    Timespan dvlTimeout_;
    Timespan dvlFailTimeout_; // How long we can go without valid data
    Timespan powerOnTimeout_; // How long it takes for the DVL to begin sending data
    Timestamp startTime_, dvlFailTime_;

    DataReader* power24vConverterDataReader_;

    UniversalDataWriter* altitudeWriter_;
    UniversalBlobWriter* velocityWrtGroundWriter_;
    UniversalDataWriter* xVelWrtGroundWriter_;
    UniversalDataWriter* yVelWrtGroundWriter_;
    UniversalDataWriter* zVelWrtGroundWriter_;

    DataWriter* veloInstFlagWriter_;
    DataWriter* beam1RangeWriter_;
    DataWriter* beam2RangeWriter_;
    DataWriter* beam3RangeWriter_;
    DataWriter* beam4RangeWriter_;

    bool isDataRequested();

    bool debug_;
    bool dvlTimeoutArmed_;
    char deviceResponse_[UART_BUFSIZE];
    UartStream uart_;
    LoadControl loadControl_;

    int status_;

    Point3D veloInst_;
    double veloInstX_;
    double veloInstY_;
    double veloInstZ_;
    double veloError_;
    int veloInstFlag_;

    double altEstimate_;
    double beam1Range_, beam2Range_, beam3Range_, beam4Range_;

    int bitError_;
};
#endif /*Rowe_600_H*/
