/***************************************************************
 * PrAccelSensorJr3.h
 *
 * Abstract class encapsulating JR3 accel sensor functionality that is common
 * across both the PCI and ISA versions. 
 *
 ****************************************************************/

/*
 * modification history
 *----------------------
 *
 * 02/25/03: Weyn Ong : Created; based on code by Jaeheung Park.
 */

#ifndef _PrAccelSensorJr3_h
#define _PrAccelSensorJr3_h

#include "PrAccelSensorIntf.h"
#include "PrJr3Defn.h"

class PrAccelSensorJr3 : public PrAccelSensorIntf {
  public:
    struct AccelArray {
        Float axis[6];    // from 0 to 5; fx, fy, fz, mx, my, mz.  Scaled.
        int v1;
        int v2;
    };

    struct WarningBits {
        unsigned fx_near_sat : 1;
        unsigned fy_near_sat : 1;
        unsigned fz_near_sat : 1;
        unsigned mx_near_sat : 1;
        unsigned my_near_sat : 1;
        unsigned mz_near_sat : 1;
        unsigned reserved   : 10;
    };

    struct ErrorBits {
        unsigned fx_sat : 1;
        unsigned fy_sat : 1;
        unsigned fz_sat : 1;
        unsigned mx_sat : 1;
        unsigned my_sat : 1;
        unsigned mz_sat : 1;
        unsigned reserved : 4;
        unsigned memory_error : 1;
        unsigned sensor_change : 1;
        unsigned system_busy : 1;
        unsigned cal_crc_bad : 1;
        unsigned watch_dog2  : 1;
        unsigned watch_dog  : 1;
    };

    // read accel sensor values
    virtual int values( Float *data ) = 0;
    virtual int value( int channel, Float &data ) = 0;

    // read accel sensor values using different filters, from 0 (unfiltered)
    // to 6 (0.49Hz).
    virtual AccelArray getAccel( int filterNum = 0) = 0;
    virtual AccelArray getDerivativeAccel( int filterNum = 0 ) = 0;

    // if the rate divisor is x, rate is calculated every x samples.
    virtual unsigned int getRateDivisor() = 0;
    virtual void setRateDivisor( unsigned int divisor ) = 0;  // default is 1

    /* From the manual : What is ErrorCount? 
    Error_count is a running count of data reception errors. If this counter
    is changing rapidly, it probably indicates a bad sensor cable connection
    or other hardware problem. In most installations error_count should not 
    change at all. But it is possible in an extremely noisy environment
    to experience occasional errors even without a hardware problem.
    */
    virtual unsigned int getErrorCount() = 0;

    // These should be zero when the sensor is operating well.
    virtual unsigned int getSaturationWarning() = 0;
    virtual unsigned int getErrorMessages() = 0;

    // set current sensor value offsets to zero
    virtual int zero() = 0;

  protected:
    // constructor sets flag
    // flag() should be called before using
    // Client cannot instantiate this class directly.  Instantiate
    // either the PCI or ISA derived classes.
    PrAccelSensorJr3() 
        : PrAccelSensorIntf( PR_JR3_CHANNEL_COUNT, PR_JR3_BIT_COUNT ) {} 
};

#endif // _PrAccelSensorJr3_h
