Exemplo n.º 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();
        }
Exemplo n.º 2
0
        public override void CanPacketReceived(CanPacket canPacket)
        {
            int canOffset = (int)canPacket.CanIdBase10 - (int)BaseAddress;

            if (IdMatch("0", canOffset))
            {
                SerialNumber = canPacket.GetInt32(1);
                DeviceId     = canPacket.GetInt32(0);
            }
            else

            if (IdMatch("F4", canOffset))
            {
                SOCPercentage = canPacket.GetFloat(1);
                SOCAh         = canPacket.GetFloat(0);
            }

            if (IdMatch("F5", canOffset))
            {
                BalancePercentage = canPacket.GetFloat(1);
                BalanceAh         = canPacket.GetFloat(0);
            }

            if (IdMatch("F6", canOffset))
            {
                TotalPackCapacity         = canPacket.GetUint16(3);
                DischargeCellVoltageError = canPacket.GetInt16(2);
                CellTempMargin            = canPacket.GetInt16(1);
                ChargeCellVoltageError    = canPacket.GetInt16(0);
            }

            if (IdMatch("F7", canOffset))
            {
                PrechargeTimer  = canPacket.GetUint8(7);
                TimerFlag       = canPacket.GetUint8(6);
                PrechargeState  = canPacket.GetUint8(1);
                ContactorStatus = canPacket.GetUint8(0);
            }

            if (IdMatch("F8", canOffset))
            {
                CellNumberMaxCell = canPacket.GetInt8(7);
                CMUNumberMaxCell  = canPacket.GetInt8(6);
                CellNumberMinCell = canPacket.GetInt8(5);
                CMUNumberMinCell  = canPacket.GetInt8(4);
                MaxCellVoltage    = canPacket.GetUint16(1);
                MinCellVoltage    = canPacket.GetUint16(0);
            }

            if (IdMatch("F9", canOffset))
            {
                CMUNumberMaxTemp = canPacket.GetInt8(6);
                CMUNumberMinTemp = canPacket.GetInt8(4);
                MaxCellTemp      = canPacket.GetUint16(1);
                MinCellTemp      = canPacket.GetUint16(0);
            }

            if (IdMatch("FA", canOffset))
            {
                BatteryCurrent = canPacket.GetInt32(1);
                BatteryVoltage = canPacket.GetUint32(0);
            }


            if (IdMatch("FB", canOffset))
            {
                BMUFirmwareBuildNumber = canPacket.GetUint16(3);
                CMUCount    = canPacket.GetUint8(5);
                StatusFlags = canPacket.GetUint8(4);
                BalanceVoltageThresholdFalling = canPacket.GetUint16(1);
                BalanceVoltageThresholdRising  = canPacket.GetUint16(0);
            }


            if (IdMatch("FC", canOffset))
            {
                TwelveVoltCurrentCMUs           = canPacket.GetUint16(3);
                TwelveVoltCurrentFansContactors = canPacket.GetUint16(2);
                FanSpeed1RPM = canPacket.GetUint16(1);
                FanSpeed0RPM = canPacket.GetUint16(0);
            }

            if (IdMatch("FD", canOffset))
            {
                BMUModelId         = canPacket.GetInt8(5);
                BMUHardwareVersion = canPacket.GetInt16(3);
                ExtendedStausFlag  = canPacket.GetUint32(0);
            }
        }