Пример #1
0
        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();
        }
Пример #2
0
        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;
        }