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

#ifndef ONBOARD_H_
#define ONBOARD_H_

#include "component/AsyncComponent.h"
#include "io/AnalogToDigital.h"
#include "io/I2C.h"

/**
 *  Provides software interface to internal system sensors
 *  on the Tethys motherboard.
 *
 *  Onboard.h should only be included by Onboard.cpp
 *  Other classes should include OnboardIF.h
 *
 *  \ingroup modules_sensor
 */
class Onboard: public AsyncComponent
{
public:
    Onboard( const Module* module );
    virtual ~Onboard();

    void initialize();
    void run();
    void uninitialize();

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

    DataWriter* pressureWriter_;
    DataWriter* temperatureWriter_;
    DataWriter* humidityWriter_;
    DataWriter* mainBatteryVoltageWriter_;
    DataWriter* backupBatteryVoltageWriter_;
    DataWriter* batteryCurrentWriter_;
    UniversalDataWriter* batteryVoltageWriter_;
    UniversalDataWriter* averageCurrentWriter_;
    UniversalDataWriter* vehiclePowerWriter_;
    UniversalDataWriter* averagePowerWriter_;

    ConfigReader* pressureA0CfgReader_;
    ConfigReader* pressureB1CfgReader_;
    ConfigReader* pressureB2CfgReader_;
    ConfigReader* pressureC12CfgReader_;

    ConfigReader* humidityAddrCfgReader_;

    // Debugging output?
    bool debug_;

    // Pressure coefficients
    float coeffA0_, coeffB1_, coeffB2_, coeffC12_;

    bool humidityDataRequested_;

    I2C i2cHumidity_, i2cPressure_;

    Timestamp sampleTime_;

    int avgVoltageCycles_, fgAvgTimeoutCycles_;

    FILE *mainVoltageSysNode_, *mainCurrentSysNode_;
    FILE *mainChargeSysNode_, *mainChargeResetSysNode_;
    FILE *backupVoltageSysNode_, *backupCurrentSysNode_;
    FILE *backupChargeSysNode_, *backupChargeResetSysNode_;

    FILE* openSysNode( Str, Str );
    void getHumidity();
    void getPressure();
    void getBatteryStatus();
    bool readConfig();
};

#endif /* ONBOARD_H_ */
