Пример #1
0
        /// <summary>
        /// 从报文提取 ECU设定参数
        /// </summary>
        /// <param name="packet">报文</param>
        /// <param name="extraPacket">额外的报文</param>
        /// <returns>ECU设定参数</returns>
        public static Models.Settings.ECUSetting TOECUSetting(byte[] packet, byte[] extraPacket, byte[] O2Packet, byte[] OBDPacket = null, byte[] AnticipateInjPacket = null)//LDC提取接收到的设置参数
        {
            System.Diagnostics.Debug.WriteLine("Begin Packet To Model ECUSetting");
            packet      = packet.PacketData(1).ToArray();
            extraPacket = extraPacket.PacketData(1).ToArray();
            O2Packet    = O2Packet.PacketData(1).ToArray();
            if (OBDPacket != null)
            {
                OBDPacket = OBDPacket.PacketData(1).ToArray();
            }
            if (AnticipateInjPacket != null)
            {
                AnticipateInjPacket = AnticipateInjPacket.PacketData(1).ToArray();
            }
            var model = new Models.Settings.ECUSetting();

            //  model.GasLevel[0] = 2;
            //model.BaseData[0] = packet[0];
            //model.BaseData[1] = packet[1];
            //model.BaseData[2] = packet[2];
            //model.BaseData[3] = packet[3];
            model.BaseData  = new int[] { packet[0], packet[1], packet[2], packet[3] };
            model.FuelType  = ValueConvert.FuelTypeFrom(packet[0]);  //LDCYG  1 字节 bit1:燃料类型, 0-LPG, 1-CNG;
            model.O2Numbers = ValueConvert.O2NumbersFrom(packet[0]); //O2Numbers //1 字节 bit2:氧传感器 Number of bank, 0-2 个, 1-1 个;
            //1 字节 bit4:MAP 传感器类型, 1-IGT013;
            //1 字节 bit5:转换时没有油气混和过度, 0-禁止, 1-允许;
            model.InjectionMode = ValueConvert.InjectionModeFrom(packet[0], packet[3]);//LDCYG  1 字节 bit6:喷射方式, 0-Sequential, 1-Full group;
            // 1 字节 bit7:燃气电磁阀提前打开, 0-取消, 1-选中;
            //是否为单燃料2 字节 bit0  //需修改2 字节 bit0:转换方式, 0-other, 1-Monofuel(单燃料);
            model.ExtraInjectionSensitivityEnable = (packet[1] & 2) != 2; //2 字节 bit1:额外喷射灵敏度, 0-选中, 1-取消;
            // 2 字节 bit3:Switch from PC, 0-disable, 1-enable;
            //2 字节 bit4:Switch, 0-off, 1-on;
            // 2 字节 bit5:MAP 传感器类型, 1-IGT025;
            model.AutoDiagnosis = (packet[2] & 0x08) == 0x08;                                                       //3 字节 bit3:启用诊断, 0-取消, 1-选中;
            // 3 字节 bit6:加速密集喷射处理, 0-禁止, 1-允许;
            model.RunningGasStrategy = ValueConvert.GasStrategiesFrom(packet[2], extraPacket[15], extraPacket[16]); //处理异常 //3 字节 bit7:高速运行, 0-燃气/燃油, 1-燃油增加; 0燃气(转速8500)  1-燃油增加   0燃油
            model.MinOilEn           = (packet[3] & 1) == 1;                                                        //4 字节 bit0:最小运行, 0-转回燃油, 1-燃油 ; 0燃气 0转回燃油(有转速)   1燃油(有转速)
            //4 字节 bit4:燃料顺序转换, 0-选中, 1-取消;
            //4 字节 bit6:喷射方式, 0-Sequential, 1-MJ-Sequential;
            //4 字节 bit7:OBD 适应性, 0-取消, 1-选中;
            model.AutoAdaptive = (packet[3] & 0x80) == 0x80;                                      //4 字节 bit7:OBD 适应性, 0-取消, 1-选中;
            model.Cylinders    = ValueConvert.CylindersFrom(packet[4]);                           //LDC  5 字节:发动机参数-缸数;三缸:0x07,四缸:0x0F;
            //model.Coils = ValueConvert.CoilNumsFrom(packet[5]);//LDC转速信号类型 增加 & 0x40
            model.RevolutionSignalType = ValueConvert.RevolutionSignalTypeFrom(packet[5]);        //LDC转速信号类型 增加 & 0x40
            model.RPMInjectionSelect   = ValueConvert.RPMInjectionSelectFrom(packet[5]);          //LDC RPMInjectionSelect增加
            model.RPMSource            = ValueConvert.RPMSourceFrom(packet[5]);                   // 6 字节:Bit6:0-Standard,1-Weak;Bit7:0-传感器,1-喷油嘴
            model.SwitchRPM            = ValueConvert.SwitchRPMFrom(packet[6], packet[7]);        //7、8 字节:切换转速;单位 rpm;已改
            model.SwitchMode           = ValueConvert.SwitchModeFrom(packet[6], packet[7]);       //切换方式 转速的最后一位
            model.SwitchTemp           = ValueConvert.SingleTempFrom(packet[8]);                  //9 字节:切换温度;范围:0~80,单位℃
            model.OverlapTimes         = ValueConvert.OverlapTimesFrom(packet[9]);                //10 字节:切换延时时间;单位 s;//LDC已改
            //11 字节:重叠时间;单位 20ms;
            model.OrderDelay         = ValueConvert.OrderDelayFrom(packet[11]);                   //12 字节:顺序切换延时;真接数字不用转换
            model.ReducerTempSens    = ValueConvert.TempSensFrom(packet[12]);                     // 13 字节:减压器温度传感器类型;10Kohm:0x04,4K7ohm:0x00,2Kohm:0x02;
            model.GasTempSens        = ValueConvert.TempSensFrom(packet[13]);                     //14 字节:燃气温度传感器类型;10Kohm:0x05,4K7ohm:0x00,2Kohm:0x02;
            model.OperationalPress   = ValueConvert.OperationalPressFrom(packet[14], packet[15]); //15、16 字节:燃气工作压力;单位 0.001bar//需修改
            model.MinimumPress       = ValueConvert.MinimumPressFrom(packet[16], packet[17]);     //17、18 字节:最小燃气压力;单位 0.001bar//需修改
            model.PressErrorTime     = ValueConvert.PressErrorTimeFrom(packet[18]);               // 19 字节:压力故障时间;单位 20ms;//同A8
            model.MiniGasTemp        = ValueConvert.SingleTempFrom(packet[19]);                   //20 字节:燃气最低温度;范围:-20~15,单位℃;//同A8
            model.InjectorType       = ValueConvert.InjectorTypeFrom(packet[20]);                 //LDCYG 21 字节:燃气喷轨类型;0x00:Matrix,0x12:3ohm,0x52:1ohm; 0x16:IGT
            model.LevelIndicatorSens = ValueConvert.LevelIndicatorSensFrom(packet[21]);           // 22 字节:液位传感器类型;//还需修改
            model.GasLevel           = ValueConvert.GasLevelSetFrom(packet[22], packet[23]        //液位传感器电压档   LDCYG
                                                                    , packet[24], packet[25]);
            if (packet.Count() >= 27)
            {
                model.BackTransitionTm = packet[26];
            }
            else
            {
                model.BackTransitionTm = 0xf000;
            }
            //model.MinGasRPM = ValueConvert.MinGasRPMFrom(packet[20]);
            //  model.RPMVoltage = ValueConvert.RPMVoltageFrom(packet[9]);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            model.ExtraData = new int[] { extraPacket[0], extraPacket[1], extraPacket[2], extraPacket[3], extraPacket[4] };
            if (AnticipateInjPacket != null)
            {
                model.AnticipateInjSetting = new int[] { AnticipateInjPacket[0], AnticipateInjPacket[1], AnticipateInjPacket[2], AnticipateInjPacket[3] }
            }
            ;
            else
            {
                model.AnticipateInjSetting = new int[] { 0xf0, 0xf0, 0xf0, 0xf0 }
            };
            //model.MinGasRPM = ValueConvert.MinGasRPMFrom(packet[20]);
            //model.ExtraInjectionCutting = (packet[4] & 1) == 1;
            model.HotStart    = ValueConvert.HotStartFrom(extraPacket[0]);
            model.Valvetronik = ValueConvert.ValvetronikFrom(extraPacket[0]);

            model.CompleteResetOfErrors  = (extraPacket[0] & 0x10) == 0x10; //OBD
            model.SelectiveResetOfErrors = (extraPacket[0] & 0x80) == 0x80; //OBD

            model.StartAndStop           = ValueConvert.StartAndStopForm(extraPacket[1]);
            model.InjetPositiveDrive     = ((extraPacket[4] & 0x01) == 0x01);
            model.ExtraInjectionCutting  = (extraPacket[0] & 1) == 1; //  1 字节 bit0:额外喷射断开, 0-取消, 1-选中;
            model.InjectorPositiveDriver = extraPacket[0] == 0x01;
            //   model.EngineType = ValueConvert.EngineTypeFrom(extraPacket[1]);
            model.Weak         = extraPacket[7];
            model.SpeedThicken = extraPacket[8];
            //////////model.RunningTijiTime = extraPacket[7] * 0.1f;
            //////////model.RunningOilCompensation = extraPacket[8] * 0.1f;
            //////////model.Lambda1Type = ValueConvert.LambdaTypeFrom(extraPacket[9]);//O2Packet
            model.ExtrainjSensitivity     = ValueConvert.ExtrainjSensitivityFrom(extraPacket[9], extraPacket[10]);      //额外喷射灵敏度
            model.ExtraInjectionIdentTime = ValueConvert.ExtraInjectionIdentTimeFrom(extraPacket[11], extraPacket[12]); //额外喷射起始时间
            model.MinGasRPM              = ValueConvert.MinGasRPMFrom(extraPacket[13], extraPacket[14]);                //最低转速  气的时候为00
            model.RunningMinRPM          = ValueConvert.RunningRPMFrom(extraPacket[15], extraPacket[16]);               //最高转速(低)
            model.RunningMaxRPM          = ValueConvert.RunningRPMFrom(extraPacket[17], extraPacket[18]);               //最高转速(高)
            model.RunningTijiTime        = ValueConvert.RunningTimeFrom(extraPacket[19], extraPacket[20]);
            model.RunningOilCompensation = ValueConvert.RunningTimeFrom(extraPacket[21], extraPacket[22]);

            //if (extraPacket.Length > 25)
            //{
            //    model.HighGasTempLowRPM = (sbyte)extraPacket[25];
            //    model.HighGasTempHighRPM = (sbyte)extraPacket[26];
            //}
            if (extraPacket.Length > 27)
            {
                model.GasFillTime = extraPacket[27];
            }
            //model.Lambda1HV = ValueConvert.SingleVoltageFrom(extraPacket[11]);
            //model.Lambda1LV = ValueConvert.SingleVoltageFrom(extraPacket[12]);
            //model.Lambda2HV = ValueConvert.SingleVoltageFrom(extraPacket[13]);
            //model.Lambda2LV = ValueConvert.SingleVoltageFrom(extraPacket[14]);
            //model.LambdaDelay = extraPacket[15];
            //model.LambdaInjectNum = extraPacket[16];

            //model.AutoAdaptive = extraPacket[18] == 0x01;
            //model.AdaptiveRange = extraPacket[19];
            //model.AutoStopAdaptive = extraPacket[20] == 0x01;
            //model.AdaptiveAssist = extraPacket[21] == 0x01;
            //model.ODBReverseAssist = extraPacket[22] == 0x01;
            //model.ODBAdaptRange = extraPacket[23];
            //model.ODBBank1Correct =ValueConvert.ConvetToSbyteSafe(extraPacket[24]);
            //model.ODBBank2Correct = ValueConvert.ConvetToSbyteSafe(extraPacket[25]);
            //model.ODBErrorAutoClear = ValueConvert.ODBErrorAutoClearFrom(extraPacket[26]);
            model.O2Type      = ValueConvert.O2TypeFrom(O2Packet[0]);
            model.Lambda1Type = ValueConvert.LambdaTypeFrom(O2Packet[1]);//O2Packet
            model.Lambda2Type = ValueConvert.LambdaTypeFrom(O2Packet[2]);

            if (OBDPacket != null)
            {
                model.OBDStandard = ValueConvert.OBDStandardFrom(OBDPacket[0]);
                model.Reserve     = OBDPacket[1];
                model.OBDType     = ValueConvert.OBDTypeFrom(OBDPacket[2]);
                if (OBDPacket.Length > 3)
                {
                    model.OBDAdaptiveRange = OBDPacket[3];
                }
            }


            System.Diagnostics.Debug.WriteLine("End Packet To Model ECUSetting");
            return(model);
        }