using System;
using Microsoft.SPOT;

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

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

using Microsoft.SPOT.Hardware;


namespace CPFUnitTests
{
    [TestClass]
    public class StartCPModeUT
    {
        [TestMethod]
        public void StartCPModeTest()
        {
            MessageQueue messageQ = MessageQueue.Instance;

            MotherBoard motherboard = MotherBoard.Instance;
            motherboard.EnableChannelPower(MotherBoard.ChannelNames.CTDChannel);
            Thread.Sleep(1000);

            BuoyancyEngine buoyancyEngine = BuoyancyEngine.Instance;
            buoyancyEngine.init();

            CTD1 ctd1 = CTD1.Instance;
            ctd1.init();
            Thread.Sleep(2000);
            messageQ.processQ(50);
            
            StartCPMode state = new StartCPMode("StartCPMode UT");

            TimeSpan SMCycleStartTime;

            SV.CurrentState = CPFStates.startCP;
            SV.NextState = CPFStates.startCP;

            EngrLogger.Comment("Sending fast pressure");
            ctd1.sendFastPressure();
            Thread.Sleep(2000);
            messageQ.processQ();

            state.doStateEntryActions();

            do
            {
                SMCycleStartTime = Utility.GetMachineTime();

                state.doStateActions();

                messageQ.processQ();

                SV.NextState = state.checkEvents();

                StateBase.StateMachinePacer(SMCycleStartTime);

            } while (SV.NextState == SV.CurrentState);

            for (int i = 0; i < 20; i++)
            {
                messageQ.processQ();
                Thread.Sleep(1000);
            }

            ctd1.sendStopProfile();

            state.doExitActions(false);

            for (int i = 0; i < 10; i++)
            {
                messageQ.processQ();
                Thread.Sleep(1000);
            }

        }

    }
}
