using System;
using Microsoft.SPOT;

//TODO move all these parameters into appropriate classes

namespace CPF
{
    public static class configFile
    {
        public static readonly TimeSpan missionTimeout = new TimeSpan(0, 8, 0, 0);

        public const double bellowsLowerLimit = 20.0;
        public const double bellowsUpperLimit = 190.0;
        public static double lowerDescendBellowsLimit = bellowsLowerLimit + 3.0;
        public static double upperDescendBellowsLimit = bellowsUpperLimit - 3.0;

        public static TimeSpan SMSleepPeriod = new TimeSpan(0, 0, 0, 0, SBE41SamplePeriod);        //msec

        public const double SOSetBellowsPosition = 185.0;
        public const int SOSetBellowsJV = 20000;

        public const double RMSetBellowsPosition = 185.0;

        public const double ABSetBellowsPosition = 165.0;
        public const int ABSetBellowsJV = 15000;
        public const int ABRetractJV = 5000;
        public const double ABVelocityThreshold = -0.02;
        public const double ABPressureThreshold = 0.2;
 
        //Buoyancy control stuff
        public const double surfacePressure = 0.35;

        //Anchor stuff
        public const double deanchorVelocityThreshold = 0.007;
        public const int deanchorJV = 4000;
        public const double deanchorVelocityLimit = 0.02;

        public const int anchorPressureCountThreshold = 4;
        public const double anchorPressureMinimum = 4.0;
        public const double anchorVelocityLimit = 0.03;
        public const double exitAnchorPressureThreshold = 5.0;

        //nudge control
        public const double approachVel = 0.01;

        //FLBB Stuff
        public static int flbbPkt = 2;
        public static int flbbAve = 3;

        //SBE41 stuff
        public const int cpPressureCutoff = 1;      //CP mode stops below this pressure in deciBars
        public const int cpRunPumpTime = 2;         //run the pump for this many seconds before starting CP mode
        public static bool CPMode = true;           //Puts SBE41 in CP mode during ascend state only
        public const int SBE41SamplePeriod = 3000;                 //msec
        public const int SBE41CPSamplePeriod = 1000;                 //msec
        public const double maxPressure = 150.0;                   //dBar
        static public readonly TimeSpan cpDelay = new TimeSpan(0, 0, 20);

        //EngrLogger stuff
        public static int verbosityLevel = 5;

        //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 = 10.0,                        // filter time constant
                            TtPlatVel = 100.0,                      // Anti-windup time constant
                            BPlatVel = 1.0,                         // Setpoint weight
                            uLowPlatVel = -2500.0 / 60.0,           // minimum possible output (RPS)
                            uHighPlatVel = 2500.0 / 60.0,           // maximum possible output (RPS)
                            hPlatVel = 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

        //ADC stuff
        public const int aducEnqueueDecimator = 15;
        //public const double minBatteryBusVolts = 26.0;
        //public const double minBatteryBusVolts = 30.5;
        public const int ADCSamplePeriod = 3000;
        public const int PTHSamplePeriod = 60000;
    }
}
