using System;
using Microsoft.SPOT;

namespace CPF
{
    class configFile
    {
        //State timeout values
        static public readonly TimeSpan RunEngrTestTimeout = new TimeSpan(0, 2, 0, 0);
        static public readonly TimeSpan preMissionDelayTimeout = new TimeSpan(0, 2, 0);
        static public readonly TimeSpan SOSetBellowsTimeout = new TimeSpan(0, 20, 0);
        static public readonly TimeSpan surfaceOpsTimeout = new TimeSpan(0, 1, 30);
        static public readonly TimeSpan ABSetBellowsTimeout = new TimeSpan(0, 20, 0);
        static public readonly TimeSpan ABRetractTimeout = new TimeSpan(0, 20, 0);
        static public readonly TimeSpan descendTimeout = new TimeSpan(1, 20, 0);
        static public readonly TimeSpan anchorTimeout = new TimeSpan(0, 10, 0);
        static public readonly TimeSpan deAnchorTimeout = new TimeSpan(0, 5, 0);
        static public readonly TimeSpan ascendTimeout = descendTimeout;
         //static public readonly TimeSpan surfaceTimeout = 300000;
        static public readonly TimeSpan timeoutDefaultPeriod = new TimeSpan(0, 0, 10);

        //SBE41 stuff
        public const int SBE41SamplePeriod = 3000;                 //msec
        public const double maxPressure = 500.0;                   //dBar

        public const int SMSleepPeriod = SBE41SamplePeriod;        //msec
        
        //Buoyancy control holdVelocity constants
        public const double KPlatVel = 80.0,                        //Constant for P term of PID
                            TiPlatVel = 50000.0,                    // Time constant for I term of PID (in denominator, bigger values less I term in output
                            TdPlatVel = 10.0,                        // Time constant for D term of PID
                            TfPlatVel = 2.0,                        // Derivative filter time constant
                            TtPlatVel = 100.0,                      // Anti-windup time constant
                            BPlatVel = 1.0,                         // Setpoint weight
                            uLowPlatVel = -3000.0 / 60.0,           // minimum possible output (RPS)
                            uHighPlatVel = 3000.0 / 60.0,           // maximum possible output (RPS)
                            hPlatVel = SBE41SamplePeriod / 1000.0;  // Sample period (seconds)

        //Buoyancy control holdDepth constants
        public const double KDepth = 0.6,                        //Constant for P term of PID
                            TiDepth = 1000000.0,                    // Time constant for I term of PID (in denominator, bigger values less I term in output
                            TdDepth = 0.2,                        // Time constant for D term of PID
                            TfDepth = 2.0,                        // Derivative filter time constant
                            TtDepth = 1000000.0,                      // Anti-windup time constant
                            BDepth = 1.0,                         // Setpoint weight
                            uLowDepth = -3000.0 / 60.0,           // minimum possible output (RPS)
                            uHighDepth = 3000.0 / 60.0,           // maximum possible output (RPS)
                            hDepth = SBE41SamplePeriod / 1000.0;  // Sample period (seconds)

        //Pump motor encoder counts per revolution
        public const double COUNTSperREV = 500.0 * 4.0;      //500 Counts per Revolution *4 for quadrature interpolation

        //autoballast (AB) stuff
        public const double ABSetBellowsPosition = 50.0;
        public const int ABSetBellowsJV = 20000;
        public const int ABRetractJV = 5000;
        public const double ABVelocityThreshold = -0.02;
        public const double ABDepthThreshold = 0.3;
        public static bool autoDive = false;

        //ADC stuff
        public const int aducEnqueueDecimator = 15;

        public const double aducCH1Scale = 55.646;
        public const double aducCH1Offset = -11.525;
        public const double minBatteryBusVolts = 28.0;

        //CN0254 stuff

        //calculated from MTS C-Series position sensor data sheet
        public const double cn0254CH0Scale = 22.81250;
        public const double cn0254CH0Offset = -2.28125;

        //CH1 scale and offset calculated from SPICE model of resistor divider and ADC analog front end
        public const double cn0254CH1Scale = 8.87;
        public const double cn0254CH1Offset = 0;

        //Calculated from current monitor and DC/DC converter data sheets
        public const double cn0254CH2Scale = 1.667;
        public const double cn0254CH2Offset = 0.0;
        public const double cn0254CH3Scale = 2.5;
        public const double cn0254CH3Offset = 0.0;
        public const double cn0254CH4Scale = 2.5;
        public const double cn0254CH4Offset = 0.0;
        
        //Emergency Ascend (EA) stuff
        public const int EAJV = 40000;
        public const double bellowsEAPosition = 69.0;
        public static TimeSpan EASendPeriod = new TimeSpan(0, 0, 15, 0);

        //Buoyancy control stuff
        public const double surfacePressure = 0.35;
        public const double minBellowsPosition = 26.0;
        public const double maxBellowsPosition = 71.0;
        //public const double SOSetBellowsPosition = 68.5;
        public const double SOSetBellowsPosition = 51.5;            //use this for quicker tests
        public const int SOSetBellowsJV = 40000;

        //Anchor stuff
        public const double anchorPressureMinimum = 10.0;
        public const double deanchorVelocityThreshold = 0.02;
        public const int deanchorJV = 10000;

        //nudge control bands
        public const double OB = 2;    //"outer band" in meters
        public const double IB = 0.75;  //"inner band" in meters
        public const double approachVel = 0.01;
    }
}
