using System;
using Microsoft.SPOT;

namespace miniCPF
{
    class configFile
    {
        //State timeout values
        static public readonly TimeSpan RunEngrTestTimeout = new TimeSpan(0, 20, 0);
        static public readonly TimeSpan preMissionDelayTimeout = new TimeSpan(0, 0, 20);
        static public readonly TimeSpan SOSetBellowsTimeout = new TimeSpan(0, 20, 0);
        static public readonly TimeSpan surfaceOpsTimeout = new TimeSpan(0, 4, 0);
        static public readonly TimeSpan ABSetBellowsTimeout = new TimeSpan(0, 20, 0);
        static public readonly TimeSpan ABRetractTimeout = new TimeSpan(0, 10, 0);
        static public readonly TimeSpan descendTimeout = new TimeSpan(0, 20, 0);
        // static public readonly TimeSpan descendParkTimeout = 300000;
        static public readonly TimeSpan anchorTimeout = new TimeSpan(6, 0, 0);
        static public readonly TimeSpan deAnchorTimeout = new TimeSpan(1, 0, 0);
        static public readonly TimeSpan ascendTimeout = descendTimeout;
        //static public readonly TimeSpan ascendParkTimeout = descendParkTimeout;
        //static public readonly TimeSpan surfaceTimeout = 300000;
        static public readonly TimeSpan timeoutDefaultPeriod = new TimeSpan(0, 0, 10);

        public const int SMSleepPeriod = 100;                     //msec

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

        //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.5,                        //Constant for P term of PID
                            TiDepth = 50000.0,                    // Time constant for I term of PID (in denominator, bigger values less I term in output
                            TdDepth = 500.0,                        // Time constant for D term of PID
                            TfDepth = 2.0,                        // Derivative filter time constant
                            TtDepth = 100.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;

        //ADUC 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
        public const double cn0254CH0Scale = 22.81250;
        public const double cn0254CH0Offset = -2.28125;
        public const double cn0254CH1Scale = 9.304;
        public const double cn0254CH1Offset = -1.734;
        public const double cn0254CH2Scale = 1.6956;
        public const double cn0254CH2Offset = -0.0794;
        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;
    }
}
