using System;
using Microsoft.SPOT;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using CPF;

using System.Text;
using System.Threading;
using HWModules;

namespace CPFUnitTests
{
    class PumpEffTests
    {
        [TestMethod]
        public void TestPumpEff()
        {
            HWModules.MotherBoard motherboard = HWModules.MotherBoard.Instance;
            motherboard.EnableChannelPower(1);  //Slot 1 channel A
            motherboard.EnableChannelPower(15);
            motherboard.EnableChannelPower(14); //Brent's version 0 digital IO board J4: position sensor
// TODO P1 THIS CODE DOES NOT REFLECT CHANGES FROM THE ISB OR LHE UPGRADES
            var lheBoard = HWModules.LheBoard.Instance;
            lheBoard.EnablePumpPower(true);
            
            BuoyancyEngine buoyancyEngine = BuoyancyEngine.Instance;
            double innerBellowsPosition = double.NaN;

            EnergyMonitorPump emPump = EnergyMonitorPump.Instance;
            EnergyMonitorLTC2946.EM_VandI emData;

            lheBoard.EnablePumpPower(true);
            motherboard.EnableChannelPower((int)MotherBoard.ChannelNames.PumpMotorControllerElexChannel);

            StringBuilder sbTemp = new StringBuilder(128);
            StringBuilder tab = new StringBuilder("\t");

            sbTemp.Clear();
            sbTemp.Append("Time of Day\tInner Bellows Position\tBattery Voltage\tBattery Current (mA)");
            Debug.Print(sbTemp.ToString());

            for (int i = 0; i < 5; i++ )
            {
                innerBellowsPosition = buoyancyEngine.getBellowsPositionStringPot();
                emData = emPump.getVoltsAndMilliAmps();

                sbTemp.Clear();
                sbTemp.Append(DateTime.Now.TimeOfDay);
                sbTemp.Append(tab);
                sbTemp.Append(innerBellowsPosition.ToString("F2"));
                sbTemp.Append(tab);
                sbTemp.Append(emData.volts.ToString("F3"));
                sbTemp.Append(tab);
                sbTemp.Append(emData.amps.ToString("F3"));
                Debug.Print(sbTemp.ToString());

                Thread.Sleep(1000);
            }

            lheBoard.EnablePumpPower(false);
            motherboard.DisableChannelPower((int)MotherBoard.ChannelNames.PumpMotorControllerElexChannel);

            for (int i = 0; i < 5; i++)
            {
                innerBellowsPosition = buoyancyEngine.getBellowsPositionStringPot();
                emData = emPump.getVoltsAndMilliAmps();

                sbTemp.Clear();
                sbTemp.Append(DateTime.Now.TimeOfDay);
                sbTemp.Append(tab);
                sbTemp.Append(innerBellowsPosition.ToString("F2"));
                sbTemp.Append(tab);
                sbTemp.Append(emData.volts.ToString("F3"));
                sbTemp.Append(tab);
                sbTemp.Append(emData.amps.ToString("F3"));
                Debug.Print(sbTemp.ToString());

                Thread.Sleep(1000);
            }

        }
    }
}
