public void AdjustVoltageTest()
        {
            TDKService tdkService = NewTDKService();

            tdkService.SupplyVoltageLimit = 230;
            tdkService.SupplyCurrentLimit = 10;
            tdkService.RequestedVoltage   = 160;

            Assert.AreEqual(tdkService.RequestedVoltage, 160);

            tdkService.RequestedVoltage = 150;
            Assert.AreEqual(tdkService.RequestedVoltage, 150);

            tdkService.RequestedVoltage = 170;
            Assert.AreEqual(tdkService.RequestedVoltage, 170);

            tdkService.RequestedVoltage = 0;
            Assert.AreEqual(tdkService.RequestedVoltage, 0);

            tdkService.RequestedVoltage = 120;
            Assert.AreEqual(tdkService.RequestedVoltage, 120);

            // Over the max of the charger, so should bring us back down
            tdkService.RequestedVoltage = 240;
            Assert.AreEqual(tdkService.RequestedVoltage, tdkService.ChargerVoltageLimit);

            tdkService.RequestedVoltage = 0;
            Assert.AreEqual(tdkService.RequestedVoltage, 0);
        }
        public void AdjustCurrentTest()
        {
            TDKService tdkService = NewTDKService();

            tdkService.SupplyVoltageLimit = 230;
            tdkService.SupplyCurrentLimit = 5;

            // Max available is 5
            tdkService.RequestedCurrent = 8;
            Assert.AreEqual(tdkService.RequestedCurrent, 5);

            tdkService.RequestedCurrent = 7;
            Assert.AreEqual(tdkService.RequestedCurrent, 5);

            tdkService.RequestedCurrent = 4;
            Assert.AreEqual(tdkService.RequestedCurrent, 4);

            tdkService.RequestedCurrent = 0;
            Assert.AreEqual(tdkService.RequestedCurrent, 0);

            tdkService.RequestedCurrent = 3;
            Assert.AreEqual(tdkService.RequestedCurrent, 3);

            // Over the max of the supply, so should bring us back down
            tdkService.RequestedCurrent = 11;
            Assert.AreEqual(tdkService.RequestedCurrent, 5);

            tdkService.RequestedCurrent = 0;
            Assert.AreEqual(tdkService.RequestedCurrent, 0);
        }
        public void CheckBasicComms()
        {
            TDKService tdkService = NewTDKService();

            tdkService.SendMessageGetResponse("ADR 05");
            Assert.AreEqual("OK", tdkService.SendMessageGetResponse("RMT LOC"));
            Assert.AreEqual("LOC", tdkService.SendMessageGetResponse("RMT?"));
        }
        public void StartStopChargeTest()
        {
            TDKService tdkService = NewTDKService();

            tdkService.StartCharge();
            Assert.IsTrue(tdkService.IsCharging, "Charger is not charging and should be");

            tdkService.StopCharge();
            Assert.IsFalse(tdkService.IsCharging, "Charger is charging and should be stopped");
        }
        private TDKService NewTDKService()
        {
            TDKService tdkService = TDKService.NewInstance;

            tdkService.SupplyVoltageLimit = 230;
            tdkService.SupplyCurrentLimit = 10;

            tdkService.Connect(ChargerIpAddress, ChargerIpPort);

            return(tdkService);
        }
Beispiel #6
0
        public async Task BasicChargeStartStopTest()
        {
            BatteryChargeService batteryChargeService = BatteryChargeService.NewInstance;

            batteryChargeService.UseTimerUpdateLoop = false;

            CanService canService = CanService.NewInstance;

            canService.ConnectViaLoopBack();

            TDKService tdkService = NewTDKService();

            tdkSimulator.BatteryConnected = true;

            batteryChargeService.SetCharger(NewTDKService());
            batteryChargeService.BatteryService.BatteryData.ComponentCanService = canService;

            if (batteryChargeService.BatteryService.BatteryData.GetBMU(0) != null)
            {
                batteryChargeService.BatteryService.BatteryData.GetBMU(0).ComponentCanService = canService;
            }

            if (batteryChargeService.BatteryService.BatteryData.GetBMU(1) != null)
            {
                batteryChargeService.BatteryService.BatteryData.GetBMU(1).ComponentCanService = canService;
            }

            uint state = batteryChargeService.ChargerState;

            Assert.IsTrue(state != CanReceivingNode.STATE_NA, "Charger does not seem to be there");

            Assert.IsFalse(batteryChargeService.IsCharging, "Battery is charging when it should not be as it has not yet been started");

            // Bit out of order but we simulate the contactors engaging now as we can't insert it during the call to StartCharge
            EngageContactors(batteryChargeService.BatteryService.BatteryData);

            // Battery is now setup in normal state, run the charge loop
            batteryChargeService.RequestedCurrent = 5;
            batteryChargeService.RequestedVoltage = 32;
            batteryChargeService.BatteryService.BatteryData.ParallelStrings = 1;
            SetCellVoltages(batteryChargeService.BatteryService.BatteryData, 4100);
            SendBatteryHeartBeat(canService, batteryChargeService.BatteryService.BatteryData);

            Assert.IsTrue(await batteryChargeService.StartCharge(), "Charger start failed");
            Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be");

            // Bit out of order but we simulate the contactors disengaging now as we can't insert it during the call to StartCharge
            DisengageContactors(batteryChargeService.BatteryService.BatteryData);

            await batteryChargeService.StopCharge();

            Assert.IsFalse(batteryChargeService.IsCharging, "Battery is charging when it should not be");
        }
        public void CheckTDKNotAvailable()
        {
            // Shutdown the simulator
            RunAfterAnyTests();

            TDKService tdkService = NewTDKService();

            tdkService.SendMessageGetResponse("ADR 05");
            Assert.AreEqual("ERROR", tdkService.SendMessageGetResponse("RMT LOC"));

            // Startup the simulator
            RunBeforeAnyTests();
        }
        public void OverCurrentTest()
        {
            // Request more current that the charger provides, make sure it steps us down
            TDKService tdkService = NewTDKService();

            tdkService.SupplyVoltageLimit = 230;
            tdkService.SupplyCurrentLimit = 10;
            tdkService.RequestedCurrent   = 80;
            Assert.AreEqual(tdkService.RequestedCurrent, tdkService.ChargerCurrentLimit);

            // Request more current that the mains provides, make sure it steps us down
            tdkService.SupplyVoltageLimit = 230;
            tdkService.SupplyCurrentLimit = 5;
            tdkService.RequestedCurrent   = 20;
            Assert.AreEqual(tdkService.RequestedCurrent, 5);
        }
        public void OverVoltageTest()
        {
            TDKService tdkService = NewTDKService();

            // 300V is the max for the charger
            tdkService.SupplyVoltageLimit = 230;
            tdkService.SupplyCurrentLimit = 10;
            tdkService.RequestedVoltage   = 500;
            Assert.AreEqual(tdkService.RequestedVoltage, tdkService.ChargerVoltageLimit, "Voltage has not been dropped to the Supply Voltage limit");

            tdkService.SupplyVoltageLimit = 120;
            tdkService.SupplyCurrentLimit = 10;

            // Power supply voltage is now lower than the max for the charger
            // so the charger can only supply at that voltage
            tdkService.RequestedVoltage = tdkService.ChargerVoltageLimit;
            Assert.AreEqual(tdkService.RequestedVoltage, 120);
        }
        public void SetChargePower()
        {
            TDKService tdkService = NewTDKService();

            tdkService.StartCharge();
            Assert.IsTrue(tdkService.IsCharging, "Charger is not charging and should be");

            tdkService.RequestedCurrent = 3.2f;
            tdkService.RequestedVoltage = 32.1f;

            // We call it twice as it gets set on the first time and read on the second
            tdkService.ChargerUpdateInner();
            tdkService.ChargerUpdateInner();

            Assert.AreEqual(tdkService.ActualCurrent, 0);
            Assert.AreEqual(tdkService.ActualVoltage, tdkService.RequestedVoltage, 0.5);

            tdkService.StopCharge();
            Assert.IsFalse(tdkService.IsCharging, "Charger is still charging and should be stopped");
        }
        public void CheckNetworkError()
        {
            TDKService tdkService = NewTDKService();

            // First test
            tdkService.Connect(null, 0);
            if (!tdkService.SendMessageGetResponse("RMT LOC").Equals("ERROR"))
            {
                Assert.Fail("Network should have thrown an exception as there is no IP set");
            }

            // Reset for the second test
            tdkService.Connect(ChargerIpAddress, ChargerIpPort);
            if (tdkService.SendMessageGetResponse("RMT LOC").Equals("ERROR"))
            {
                Assert.Fail("Network should not have thown an exception, looks like IP is not set");
            }

            tdkService.Disconnect();
        }
        public void CheckNetworkError()
        {
            TDKService tdkService = NewTDKService();

            try
            {
                tdkService.Connect(null, 0);
                tdkService.SendMessageGetResponse("RMT LOC");
            } catch
            {
                Assert.IsTrue(true, "Network should have thrown an exception");
            }

            tdkService.Connect(ChargerIpAddress, ChargerIpPort);

            try
            {
                tdkService.SendMessageGetResponse("RMT LOC");
            }
            catch
            {
                Assert.Fail("Network should not have thown an exception, look like IP is not set");
            }
        }
Beispiel #13
0
        public async Task BalancingChargeTest()
        {
            BatteryChargeService batteryChargeService = BatteryChargeService.NewInstance;

            batteryChargeService.UseTimerUpdateLoop = false;

            CanService canService = CanService.NewInstance;

            canService.ConnectViaLoopBack();

            TDKService tdkService = NewTDKService();

            tdkSimulator.BatteryConnected = true;

            batteryChargeService.SetCharger(NewTDKService());
            batteryChargeService.BatteryService.BatteryData.ComponentCanService = canService;

            if (batteryChargeService.BatteryService.BatteryData.GetBMU(0) != null)
            {
                batteryChargeService.BatteryService.BatteryData.GetBMU(0).ComponentCanService = canService;
            }

            if (batteryChargeService.BatteryService.BatteryData.GetBMU(1) != null)
            {
                batteryChargeService.BatteryService.BatteryData.GetBMU(1).ComponentCanService = canService;
            }

            Assert.IsFalse(batteryChargeService.IsCharging, "Battery is charging when it should not be - Point 1");

            // Bit out of order but we simulate the contactors engaging now as we can't insert it during the call to StartCharge
            EngageContactors(batteryChargeService.BatteryService.BatteryData);

            // Battery is now setup in normal state, run the charge loop
            batteryChargeService.RequestedCurrent = 5;
            batteryChargeService.RequestedVoltage = 32;
            batteryChargeService.BatteryService.BatteryData.ParallelStrings = 1;
            SetCellVoltages(batteryChargeService.BatteryService.BatteryData, 4100);
            SendBatteryHeartBeat(canService, batteryChargeService.BatteryService.BatteryData);

            Assert.IsTrue(await batteryChargeService.StartCharge(), "Charger start failed");
            Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be");

            SetChargeVoltageError(batteryChargeService.BatteryService.BatteryData, 100, -50);

            SendBatteryHeartBeat(canService, batteryChargeService.BatteryService.BatteryData);
            batteryChargeService.ChargerUpdateInner();

            tdkService.ChargerUpdateInner();
            tdkService.ChargerUpdateInner();

            Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be - Mark 2");

            // Keep sending heartbeats so we don't time out
            SendBatteryHeartBeat(canService, batteryChargeService.BatteryService.BatteryData);

            Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be - Mark 3");

            Assert.AreEqual(batteryChargeService.RequestedVoltage, batteryChargeService.ChargerActualVoltage, "Requested Voltage has not flowed through");
            Assert.IsTrue(batteryChargeService.ChargerService.RequestedCurrent > 0, "Battery does not appear to be charging");

            Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be - Mark 4");

            for (int i = 0; i < 10; i++)
            {
                batteryChargeService.ChargerUpdateInner();
                tdkService.ChargerUpdateInner();
                SendBatteryHeartBeat(canService, batteryChargeService.BatteryService.BatteryData);
            }

            Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be - Mark 3");

            float batteryChargerCurrent = batteryChargeService.ChargerService.RequestedCurrent;

            // Battery over charged
            SetChargeVoltageError(batteryChargeService.BatteryService.BatteryData, -35, -50);

            for (int i = 0; i < 10; i++)
            {
                batteryChargeService.ChargerUpdateInner();
                tdkService.ChargerUpdateInner();
                SendBatteryHeartBeat(canService, batteryChargeService.BatteryService.BatteryData);
            }

            Assert.IsTrue(batteryChargeService.IsCharging, "Battery is not charging when it should be - Mark 4");
            Assert.IsTrue(batteryChargeService.ChargerService.RequestedCurrent < batteryChargerCurrent, "Current should be going down as we are balancing, but it is not");

            // Bit out of order but we simulate the contactors disengaging now as we can't insert it during the call to StartCharge
            DisengageContactors(batteryChargeService.BatteryService.BatteryData);

            Assert.IsTrue(await batteryChargeService.StopCharge(), "Battery did not stop as expected");
            Assert.IsFalse(batteryChargeService.IsCharging, "Battery is charging when it should not be as it has been shutdown");
        }