using System.Threading; using HWModules; using Microsoft.SPOT.Hardware; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.SPOT; using System.Text; using SWModules; using System; using SensorModules; namespace CPFUnitTests { [TestClass] public class UnitTest_MotherBoard_EnergyMonitor { [TestMethod] public void TestIVWTCE() { HWModules.MotherBoard motherboard = MotherBoard.Instance; var lheBoard = HWModules.LheBoard.Instance; var buoyancyEngine = BuoyancyEngine.Instance; buoyancyEngine.init(); buoyancyEngine.stopMotor(); var hotelEM = EnergyMonitorHotel.Instance; EnergyMonitorHotel.emIVWTCE hotelIVWTCE; var pumpEM = EnergyMonitorPump.Instance; EnergyMonitorPump.emIVWTCE pumpIVWTCE; BTConsole btConsole = BTConsole.Instance; MSC1 msc1 = MSC1.Instance; CTD1 ctd1 = CTD1.Instance; Radiometer1 radiometer1 = Radiometer1.Instance; FLBB1 flbb1 = FLBB1.Instance; Optode1 optode1 = Optode1.Instance; IridiumModem1 iModem1 = IridiumModem1.Instance; GPS1 gps1 = GPS1.Instance; StringBuilder sbTemp = new StringBuilder(); double bellowsPos = double.NaN; int numCycles = 10; bool skip = false; Debug.Print("date\ttime\tcomment\tpumpMilliAmps\tpumpVolts\tpumpMilliWatts\tpumpMilliSeconds\tpumpUCoulombs\tpumpJoules" + "\thotelMilliAmps\thotelVolts\thotelMilliWatts\thotelMilliSeconds\thotelUCoulombs\thotelJoules\tbellowsPos"); for (int j = 0; j < 12; j++) { hotelEM.ResetAccumulators(); pumpEM.ResetAccumulators(); skip = false; switch (j) { case 0: Debug.Print("\t\tStarting case " + j.ToString() + " all loads off, 5V and 12V on"); lheBoard.EnablePumpPower(false); motherboard.DisableAllLoads(); Thread.Sleep(2000); break; case 3: Debug.Print("\t\tStarting case " + j.ToString() + " FLBB on"); flbb1.powerUp(); Thread.Sleep(2000); break; case 4: Debug.Print("\t\tStarting case " + j.ToString() + " CTD on"); ctd1.powerUp(); Thread.Sleep(2000); break; case 5: Debug.Print("\t\tStarting case " + j.ToString() + " Radiometer on"); radiometer1.powerUp(); Thread.Sleep(2000); break; case 6: Debug.Print("\t\tStarting case " + j.ToString() + " Bluetooth on"); btConsole.powerUp(); Thread.Sleep(2000); break; case 7: Debug.Print("\t\tStarting case " + j.ToString() + " GPS Modem on"); gps1.powerUp(); Thread.Sleep(2000); break; case 8: Debug.Print("\t\tStarting case " + j.ToString() + " Iridium Modem on"); iModem1.powerUp(); Thread.Sleep(2000); break; case 9: Debug.Print("\t\tStarting case " + j.ToString() + " MSC on"); msc1.powerUp(); Thread.Sleep(2000); break; case 10: Debug.Print("\t\tStarting case " + j.ToString() + " enable pumping"); lheBoard.EnablePumpPower(false); motherboard.DisableAllLoads(); lheBoard.EnablePumpPower(true); motherboard.EnableChannelPower(MotherBoard.ChannelNames.MotorizedValve); motherboard.EnableChannelPower(MotherBoard.ChannelNames.PositionSensorChannel); motherboard.EnableChannelPower(MotherBoard.ChannelNames.PumpMotorControllerElexChannel); motherboard.Enable12V(); motherboard.Enable5V(); for (int i = 0; i < 5; i++) { bellowsPos = buoyancyEngine.getBellowsPositionStringPot(); Debug.Print("\t\tBellows Pos = " + bellowsPos.ToString("f1")); Thread.Sleep(500); } break; case 11: Debug.Print("\t\tStarting case " + j.ToString() + " start pumping 20000 cps"); buoyancyEngine.increaseBuoyancy(20000); break; default: skip = true; Debug.Print("\t\tSkipping case " + j.ToString()); break; } if (!skip) { for (int i = 0; i < numCycles; i++) { hotelIVWTCE = hotelEM.getIVWTCE(); pumpIVWTCE = pumpEM.getIVWTCE(); bellowsPos = buoyancyEngine.getBellowsPositionStringPot(); //logToEngFile(ref hotelIVWTCE, ref pumpIVWTCE); sbTemp.Clear(); sbTemp.Append(DateTime.Now.ToString("yyyy-MMM-dd\tHH:mm:ss.0") + "\tgetIVWTCE()" + "\t" + pumpIVWTCE.milliAmps.ToString("f1") + "\t" + pumpIVWTCE.milliVolts.ToString("f1") + "\t" + pumpIVWTCE.microWatts.ToString("f1") + "\t" + pumpIVWTCE.milliSeconds.ToString("f1") + "\t" + pumpIVWTCE.uCoulombs.ToString("f1") + "\t" + pumpIVWTCE.milliJoules.ToString("f1") + "\t" + hotelIVWTCE.milliAmps.ToString("f1") + "\t" + hotelIVWTCE.milliVolts.ToString("f1") + "\t" + hotelIVWTCE.microWatts.ToString("f1") + "\t" + hotelIVWTCE.milliSeconds.ToString("f1") + "\t" + hotelIVWTCE.uCoulombs.ToString("f1") + "\t" + hotelIVWTCE.milliJoules.ToString("f1")); sbTemp.Append("\t" + bellowsPos.ToString("f3")); Debug.Print(sbTemp.ToString()); Thread.Sleep(500); } } } Debug.Print("Stopping motor and closing .eng file"); buoyancyEngine.stopMotor(); buoyancyEngine.closeMV(); EngrLogger.closeEngrLogFile(); } private static void logToEngFile(ref EnergyMonitorHotel.emIVWTCE hotelIVWTCE, ref EnergyMonitorPump.emIVWTCE pumpIVWTCE) { EngrLogger.writeToColumns(EngrLiterals.ColumnNums.dateTime, DateTime.Now, EngrLiterals.ColumnNums.state, "UT_MB_EnergyMonitor", EngrLiterals.ColumnNums.comment, "Test getIVWTCE()", EngrLiterals.ColumnNums.hotelMilliamps, hotelIVWTCE.milliAmps, EngrLiterals.ColumnNums.hotelMilliVolts, hotelIVWTCE.milliVolts, EngrLiterals.ColumnNums.hotelMicroWatts, hotelIVWTCE.microWatts, EngrLiterals.ColumnNums.hotelMilliSeconds, hotelIVWTCE.milliSeconds, EngrLiterals.ColumnNums.hotelUCoulombs, hotelIVWTCE.uCoulombs, EngrLiterals.ColumnNums.hotelMilliJoules, hotelIVWTCE.milliJoules, EngrLiterals.ColumnNums.pumpMilliamps, pumpIVWTCE.milliAmps, EngrLiterals.ColumnNums.pumpMilliVolts, pumpIVWTCE.milliVolts, EngrLiterals.ColumnNums.pumpMicroWatts, pumpIVWTCE.microWatts, EngrLiterals.ColumnNums.pumpMilliSeconds, pumpIVWTCE.milliSeconds, EngrLiterals.ColumnNums.pumpUCoulombs, pumpIVWTCE.uCoulombs, EngrLiterals.ColumnNums.pumpMilliJoules, pumpIVWTCE.milliJoules); } [TestMethod] public void TestEnergyMonitorVI() { HWModules.MotherBoard motherboard = MotherBoard.Instance; var em = EnergyMonitorHotel.Instance; motherboard.DisableChannelPower(MotherBoard.ChannelNames.IridiumChannel); for (int i = 0; i < 50; i++) { EngrLogger.writeToColumns("Iridium off BATTERY EM DATA V/I:" + em.getVoltsAndMilliAmps()); Thread.Sleep(100); } motherboard.EnableChannelPower(MotherBoard.ChannelNames.IridiumChannel); Thread.Sleep(2000); for (int i = 0; i < 50; i++) { EngrLogger.writeToColumns("Iridium on BATTERY EM DATA V/I:" + em.getVoltsAndMilliAmps()); Thread.Sleep(100); } motherboard.DisableChannelPower(MotherBoard.ChannelNames.IridiumChannel); Thread.Sleep(2000); for (int i = 0; i < 50; i++) { EngrLogger.writeToColumns("Iridium off BATTERY EM DATA V/I:" + em.getVoltsAndMilliAmps()); Thread.Sleep(100); } } /** No longer using this with LHE [TestMethod] public void TestEnergyMonitorPump() { EnergyMonitorLTC2946 em = new EnergyMonitorLTC2946(new I2CDevice.Configuration(0xDC>>1, 400), EnergyMonitorLTC2946.VoltageSource.Vdd, 0.025, 5.00); int i = 10; while (--i >0 ) { EnergyMonitorLTC2946.EM_VandI data = em.getVandI(); EngrLogger.writeToColumns("PUMP V/I:" + data.volts.ToString() + " / " + data.amps.ToString()); Thread.Sleep(100); } } */ } }