using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading;
using HWModules;
using SWModules;

using System.Text;
using Microsoft.SPOT;

namespace CPFUnitTests
{
    class PTHUnitTest
    {
        public BuoyancyEngine buoyancyEngine;
        
        [TestMethod]
        public void TestPth()
        {
            StringBuilder sbTemp = new StringBuilder(128);
            DateTime timeNow;

            MessageQueue messageQ = MessageQueue.Instance;
            RMG185_PTHSensor pthSensor = new RMG185_PTHSensor();

            HWModules.MotherBoard motherboard = HWModules.MotherBoard.Instance;
            motherboard.EnableChannelPower(MotherBoard.ChannelNames.PositionSensorChannel);
            
            buoyancyEngine = BuoyancyEngine.Instance;
            buoyancyEngine.init();

            double bellowsPosition = -10000.0;

            pthSensor.init();
            PTHData pthData;

            EnergyMonitorHotel emBatteryBus = EnergyMonitorHotel.Instance;
            EnergyMonitorLTC2946.EM_VandI emData;

            for (int i = 1; i < 10000; i++)
            {
                timeNow = DateTime.Now;

                pthData = pthSensor.getPTH();
                emData = emBatteryBus.getVoltsAndMilliAmps();   
                bellowsPosition = buoyancyEngine.getBellowsPositionStringPot();
 
                for (int j = 0; j < 10; j++)
                {
                    messageQ.processQ();
                     Thread.Sleep(100);
                }
                sbTemp.Clear();
                sbTemp.Append(timeNow.ToString());
                sbTemp.Append("   Pressure= ");
                sbTemp.Append(pthData.canPressure.ToString("D1"));
                sbTemp.Append("   PTemper.= ");
                sbTemp.Append(pthData.canP_Temperature.ToString("D1"));
                sbTemp.Append("   Humidity= ");
                sbTemp.Append(pthData.canHumidity.ToString("D1"));
                sbTemp.Append("   HTemper.= ");
                sbTemp.Append(pthData.canH_Temperature.ToString("D1"));
                sbTemp.Append("   Bus Volts= ");
                sbTemp.Append(emData.volts.ToString("D2"));
                sbTemp.Append("   Bus mAmps= ");
                sbTemp.Append(emData.amps.ToString("D2"));
                sbTemp.Append("   Bel. Pos.= ");
                sbTemp.Append(bellowsPosition.ToString("f3"));
                Debug.Print(sbTemp.ToString());

                Thread.Sleep(1000);
            }
        }
    }
}