public void StartStopChargeTest() { CanService.Instance.ConnectViaLoopBack(); Assert.IsTrue(CanService.Instance.IsConnected()); ElconService elconService = ElconService.Instance; elconService.SupplyVoltageLimit = 230; elconService.SupplyCurrentLimit = 10; elconService.StartCharge(); CanPacket statusPacket = new CanPacket(ElconService.ELCON_CAN_STATUS) { IsLittleEndian = false }; statusPacket.SetUint16(0, (uint)1600); statusPacket.SetUint16(1, (uint)100); CanService.Instance.SendMessage(statusPacket); Assert.IsTrue(elconService.IsCharging); elconService.StopCharge(); Assert.IsFalse(elconService.IsCharging); CanPacket canPacket = CanService.Instance.LastestCanPacketById(ElconService.ELCON_CAN_COMMAND); // Update voltage requested to 0 Assert.AreEqual(canPacket.Int16Pos3, 0); Assert.AreEqual(canPacket.Int16Pos2, 0); CanService.Instance.Disconnect(); Assert.IsFalse(CanService.Instance.IsConnected()); }
public override void CanPacketReceived(CanPacket cp) { // Elcon uses big endian cp.IsLittleEndian = false; Boolean gotStatusMessage = false; try { switch (cp.CanIdBase10) { case ELCON_CAN_STATUS: // 0x18FF50E5 ActualVoltage = (float)cp.GetUint16(0) / 10.0f; ActualCurrent = (float)cp.GetUint16(1) / 10.0f; // Calculate and send updated dynamic current limit based on pack voltage if (ActualVoltage > 0.0f) { ChargerCurrentLimit = ChargerPowerLimit / ActualVoltage; if (ChargerCurrentLimit > ELCON_CURRENT_LIMIT) { ChargerCurrentLimit = ELCON_CURRENT_LIMIT; } } // Get status flags ChargerStatus = cp.GetUint8(4); gotStatusMessage = true; break; } } catch { //Let it go, let it go. Can't hold it back anymore... } if (chargeOutputOn && gotStatusMessage) { // We use the receipt of the status message to send the charger the latest power details CanPacket elconCommand = new CanPacket(ELCON_CAN_COMMAND) { IsLittleEndian = false }; // Update voltage requested by the ChargeService elconCommand.SetUint16(0, (UInt16)(RequestedVoltage * 10)); // Update current requested by the ChargeService elconCommand.SetUint16(1, (UInt16)(RequestedCurrent * 10)); ComponentCanService.SendMessage(elconCommand); } UpdateStatus(); }
public void SimulateSOCCan() { CanService.Instance.ConnectViaLoopBack(); CMU cmu = new CMU(0x203, true); Assert.IsNull(cmu.CellTemp); Assert.AreEqual(cmu.State, CanReceivingNode.STATE_NA); CanPacket PCBcanPacket = new CanPacket(0x203); PCBcanPacket.SetInt16(2, 520); // PCB Temp PCBcanPacket.SetInt16(3, 320); // PCB Temp cmu.TestCanPacketReceived(PCBcanPacket); Assert.AreEqual(cmu.PCBTemp, 52); Assert.AreEqual(cmu.CellTemp, 32); Assert.AreEqual(cmu.State, CanReceivingNode.STATE_ON); CanPacket Battery1canPacket = new CanPacket(0x204); Battery1canPacket.SetUint16(0, 1); Battery1canPacket.SetUint16(1, 11); Battery1canPacket.SetUint16(2, 21); Battery1canPacket.SetUint16(3, 31); cmu.TestCanPacketReceived(Battery1canPacket); CanPacket Battery2canPacket = new CanPacket(0x205); Battery2canPacket.SetUint16(0, 41); Battery2canPacket.SetUint16(1, 51); Battery2canPacket.SetUint16(2, 61); Battery2canPacket.SetUint16(3, 71); cmu.TestCanPacketReceived(Battery2canPacket); Assert.AreEqual(cmu.Cell0mV, (uint)1); Assert.AreEqual(cmu.Cell1mV, (uint)11); Assert.AreEqual(cmu.Cell2mV, (uint)21); Assert.AreEqual(cmu.Cell3mV, (uint)31); Assert.AreEqual(cmu.Cell4mV, (uint)41); Assert.AreEqual(cmu.Cell5mV, (uint)51); Assert.AreEqual(cmu.Cell6mV, (uint)61); Assert.AreEqual(cmu.Cell7mV, (uint)71); Assert.AreEqual(cmu.State, CanReceivingNode.STATE_ON); CanService.Instance.Disconnect(); }
public override void StopCharge() { StopReceivingCan(); // We use the receipt of the status message to send the charger the latest power details CanPacket elconCommand = new CanPacket(ELCON_CAN_COMMAND) { IsLittleEndian = false }; // Update voltage requested to 0 elconCommand.SetUint16(3, (UInt16)(0)); // Update current requested to 0 elconCommand.SetUint16(2, (UInt16)(0)); ComponentCanService.SendMessage(elconCommand); chargeOutputOn = false; }
private void SetCellVoltages(Battery battery, uint voltages) { uint baseCanId = 0x601; CanPacket PCBcanPacket = new CanPacket(baseCanId); PCBcanPacket.SetInt16(2, 520); // PCB Temp PCBcanPacket.SetInt16(3, 320); // PCB Temp CanPacket Battery1canPacket1 = new CanPacket(baseCanId + 1); Battery1canPacket1.SetUint16(0, voltages); Battery1canPacket1.SetUint16(1, voltages); Battery1canPacket1.SetUint16(2, voltages); Battery1canPacket1.SetUint16(3, voltages); CanPacket Battery1canPacket2 = new CanPacket(baseCanId + 2); Battery1canPacket2.SetUint16(0, voltages); Battery1canPacket2.SetUint16(1, voltages); Battery1canPacket2.SetUint16(2, voltages); Battery1canPacket2.SetUint16(3, voltages); if (battery.GetBMU(0) != null) { battery.GetBMU(0).GetCMU(0).TestCanPacketReceived(PCBcanPacket); } if (battery.GetBMU(0) != null) { battery.GetBMU(0).GetCMU(0).TestCanPacketReceived(Battery1canPacket1); } if (battery.GetBMU(0) != null) { battery.GetBMU(0).GetCMU(0).TestCanPacketReceived(Battery1canPacket2); } baseCanId = 0x201; CanPacket PCBcanPacket2 = new CanPacket(baseCanId); PCBcanPacket.SetInt16(2, 520); // PCB Temp PCBcanPacket.SetInt16(3, 320); // PCB Temp CanPacket Battery2canPacket1 = new CanPacket(baseCanId + 1); Battery2canPacket1.SetUint16(0, voltages); Battery2canPacket1.SetUint16(1, voltages); Battery2canPacket1.SetUint16(2, voltages); Battery2canPacket1.SetUint16(3, voltages); CanPacket Battery2canPacket2 = new CanPacket(baseCanId + 2); Battery2canPacket2.SetUint16(0, voltages); Battery2canPacket2.SetUint16(1, voltages); Battery2canPacket2.SetUint16(2, voltages); Battery2canPacket2.SetUint16(3, voltages); if (battery.GetBMU(1) != null) { battery.GetBMU(1).GetCMU(0).TestCanPacketReceived(PCBcanPacket2); } if (battery.GetBMU(1) != null) { battery.GetBMU(1).GetCMU(0).TestCanPacketReceived(Battery2canPacket1); } if (battery.GetBMU(1) != null) { battery.GetBMU(1).GetCMU(0).TestCanPacketReceived(Battery2canPacket2); } }