Example #1
0
 private void WriteSettings()
 {
     try
     {
         _uiRoot.Notifier.Notify(() => { _logger.Log("Запись группы настроек..."); });
         var settingsPart = new AinSettingsPartWritable
         {
             // TODO: null handling like in group 100 or 101 (q8)
             UchMin = BytesPair.FromSignedShortLowFirst(ConvertDecimalToShort(Parameter01Vm.CurrentValue).Value),
             UchMax = BytesPair.FromSignedShortLowFirst(ConvertDecimalToShort(Parameter02Vm.CurrentValue).Value)
         };
         _readerWriter.WriteSettingsAsync(settingsPart, exception =>
         {
             _uiRoot.Notifier.Notify(() =>
             {
                 if (exception != null)
                 {
                     _logger.Log("Ошибка при записи настроек. " + exception.Message);
                 }
                 else
                 {
                     _logger.Log("Группа настроек была успешно записана");
                 }
             });
         }
                                          );
     }
     catch (Exception ex)
     {
         _logger.Log("Не удалось записать группу настроек. " + ex.Message);
     }
 }
Example #2
0
 public BytesPairNullableToStringThroughOneWireConverter(double multiplier, double addition, string format, BytesPair noLinkCode)
 {
     _multiplier = multiplier;
     _addition   = addition;
     _format     = format;
     _noLinkCode = noLinkCode;
 }
        public static decimal ConvertBytesPairToDecimalQ8(BytesPair value)
        {
            var ushortValue = value.LowFirstUnsignedValue;
            var iValue      = ushortValue << 16;

            return(iValue / 16777216.0m);
        }
        public static BytesPair ConvertToBytesPairQ8(decimal value)
        {
            var iValue      = (int)(value * 16777216.0m);
            var ushortValue = (ushort)(iValue >> 16);

            return(BytesPair.FromUnsignedShortLowFirst(ushortValue));
        }
 public TextFormatterSensor(double modifier, double addition, BytesPair noLinkCode, string format, string nullFormat, string noLinkFormat)
 {
     _modifier     = modifier;
     _addition     = addition;
     _noLinkCode   = noLinkCode;
     _format       = format;
     _nullFormat   = nullFormat;
     _noLinkFormat = noLinkFormat;
 }
Example #6
0
 public SensorIndicationDoubleBasedOnBytesPair(
     BytesPair valueFirstHi,
     double modifier,
     double afterModificationAddition,
     BytesPair noLinkCode) : base(valueFirstHi, noLinkCode)
 {
     _valueFirstHi = valueFirstHi;
     _modifier     = modifier;
     _afterModificationAddition = afterModificationAddition;
 }
        public IMukFanVaporizerDataReply03 Build()
        {
            var automaticModeStage = new BytesPair(_data[17], _data[18]).HighFirstUnsignedValue;

            return(new MukFanVaporizerDataReply03Simple
            {
                FanPwm = new BytesPair(_data[3], _data[4]).HighFirstUnsignedValue,

                TemperatureAddress1 =
                    new SensorIndicationDoubleBasedOnBytesPair(new BytesPair(_data[5], _data[6]), 0.01, 0.0, NoSensor),
                TemperatureAddress2 =
                    new SensorIndicationDoubleBasedOnBytesPair(new BytesPair(_data[7], _data[8]), 0.01, 0.0, NoSensor),

                IncomingSignals = _data[10],
                OutgoingSignals = _data[12],

                AnalogInput = new BytesPair(_data[13], _data[14]).HighFirstUnsignedValue,
                HeatingPwm = new BytesPair(_data[15], _data[16]).HighFirstUnsignedValue,

                AutomaticModeStage = automaticModeStage,
                AutomaticModeStageParsed = new MukFanEvaporatorWorkstageBuilder(automaticModeStage).Build(),


                TemperatureRegulatorWorkMode =
                    new TemperatureRegulatorWorkModeBuilderReplied(new BytesPair(_data[19], _data[20])).Build(),

                CalculatedTemperatureSetting = new BytesPair(_data[21], _data[22]).HighFirstUnsignedValue * 0.01,
                FanSpeed = new BytesPair(_data[23], _data[24]).HighFirstUnsignedValue,

                Diagnostic1 = new BytesPair(_data[25], _data[26]).HighFirstUnsignedValue,
                Diagnostic1Parsed = new MukFanVaporizerDataReply03Diagnostic1Builder(_data[26]).Build(),

                Diagnostic2 = new BytesPair(_data[27], _data[28]).HighFirstUnsignedValue,
                Diagnostic2Parsed = new MukFanVaporizerDataReply03Diagnostic2Builder(_data[28], _data[27]).Build(),

                Diagnostic3 = new BytesPair(_data[29], _data[30]).HighFirstUnsignedValue,
                Diagnostic3Parsed =
                    new MukEmersionSwitchOnDiagnosticBuilder(new BytesPair(_data[29], _data[30]).HighFirstUnsignedValue)
                    .Build(),

                Diagnostic4 = new BytesPair(_data[31], _data[32]).HighFirstUnsignedValue,
                Diagnostic4OneWire1 =
                    new MukFlapDiagnosticOneWireSensorBuilder(
                        new BytesPair(_data[31], _data[32]).HighFirstUnsignedValue).Build(),

                Diagnostic5 = new BytesPair(_data[33], _data[34]).HighFirstUnsignedValue,
                Diagnostic5OneWire2 =
                    new MukFlapDiagnosticOneWireSensorBuilder(
                        new BytesPair(_data[33], _data[34]).HighFirstUnsignedValue).Build(),

                FirmwareBuildNumber = new BytesPair(_data[35], _data[36]).HighFirstUnsignedValue,
                TemperatureAddress3 =
                    new SensorIndicationDoubleBasedOnBytesPair(new BytesPair(_data[37], _data[38]), 0.01, 0.0, NoSensor)
            });
        }
        public IMukFlapAirRequest16Data Build()
        {
            var bitsRegistry = new BytesPair(_bytes[15], _bytes[16]);                                           // word #4

            return(new Request16Data(new KsmCommandWorkmodeAndUnparsedValueSimple(_bytes[7] * 256 + _bytes[8]), // word #0 TODO: выводить только младший байт!?
                                     _bytes[9] * 256 + _bytes[10],                                              // word #1
                                     (_bytes[11] * 256 + _bytes[12]) * 0.01,                                    // word #2
                                     _bytes[13] * 256 + _bytes[14],                                             // word #3
                                     bitsRegistry.HighFirstUnsignedValue,
                                     bitsRegistry.HighFirstUnsignedValue.GetBit(0),
                                     _bytes[17] * 256 + _bytes[18] // word #5
                                     ));
        }
Example #9
0
 public CommonTelemetrySimple(ushort commonEngineState, ushort commonFaultState, bool ain1LinkFault,
                              bool ain2LinkFault, bool ain3LinkFault, ushort ain1Status, ushort ain2Status, ushort ain3Status,
                              BytesPair mcw, BytesPair msw, BytesPair asw, BytesPair fset, BytesPair mset, BytesPair reserve3,
                              BytesPair mMin, BytesPair max)
 {
     CommonEngineState = commonEngineState;
     CommonFaultState  = commonFaultState;
     Ain1LinkFault     = ain1LinkFault;
     Ain2LinkFault     = ain2LinkFault;
     Ain3LinkFault     = ain3LinkFault;
     Ain1Status        = ain1Status;
     Mcw      = mcw;
     Msw      = msw;
     Asw      = asw;
     Fset     = fset;
     Mset     = mset;
     Reserve3 = reserve3;
     MMin     = mMin;
     MMax     = max;
 }
        public AinSettingsSimple(
            BytesPair reserved00,
            decimal kpW,
            decimal kiW,
            decimal fiNom,
            short imax,
            short udcMax,
            short udcMin,
            decimal fnom,
            decimal fmax,
            decimal dflLim,
            decimal flMinMin,
            short ioutMax,
            decimal fiMin,
            ushort dacCh,
            ushort imcw,
            short ia0,
            short ib0,
            short ic0,
            short udc0,
            decimal tauR,
            decimal lm,
            decimal lsl,
            decimal lrl,
            BytesPair reserved24,
            decimal kpFi,
            decimal kiFi,
            BytesPair reserved28,
            decimal kpId,
            decimal kiId,
            BytesPair reserved32,
            decimal kpIq,
            decimal kiIq,
            decimal accDfDt,
            decimal decDfDt,
            decimal unom,
            decimal tauFlLim,
            decimal rs,
            decimal fmin,
            decimal tauM, decimal tauF, decimal tauFSet, decimal tauFi,
            short idSetMin, short idSetMax,
            BytesPair uchMin, BytesPair uchMax,
            BytesPair reserved50, BytesPair reserved51,
            int np, int nimpFloorCode, AinTelemetryFanWorkmode fanMode, bool directCurrentMagnetization,
            decimal umodThr,
            decimal emdecDfdt,
            short textMax,
            short toHl, bool ain1LinkFault, bool ain2LinkFault, bool ain3LinkFault)
        {
            Reserved00 = reserved00;
            KpW        = kpW;
            KiW        = kiW;

            FiNom = fiNom;
            Imax  = imax;

            UdcMax = udcMax;
            UdcMin = udcMin;

            Fnom = fnom;
            Fmax = fmax;

            DflLim   = dflLim;
            FlMinMin = flMinMin;

            IoutMax = ioutMax;
            FiMin   = fiMin;
            DacCh   = dacCh;
            Imcw    = imcw;
            Ia0     = ia0;
            Ib0     = ib0;
            Ic0     = ic0;
            Udc0    = udc0;
            TauR    = tauR;
            Lm      = lm;
            Lsl     = lsl;
            Lrl     = lrl;

            Reserved24 = reserved24;
            KpFi       = kpFi;
            KiFi       = kiFi;

            Reserved28 = reserved28;
            KpId       = kpId;
            KiId       = kiId;

            Reserved32 = reserved32;
            KpIq       = kpIq;
            KiIq       = kiIq;

            AccDfDt = accDfDt;
            DecDfDt = decDfDt;

            Unom = unom;

            TauFlLim = tauFlLim;

            Rs      = rs;
            Fmin    = fmin;
            TauM    = tauM;
            TauF    = tauF;
            TauFSet = tauFSet;
            TauFi   = tauFi;

            IdSetMin = idSetMin;
            IdSetMax = idSetMax;

            UchMin = uchMin;
            UchMax = uchMax;

            Reserved50 = reserved50;
            Reserved51 = reserved51;

            Np            = np;
            NimpFloorCode = nimpFloorCode;
            FanMode       = fanMode;
            DirectCurrentMagnetization = directCurrentMagnetization;

            UmodThr = umodThr;

            EmdecDfdt = emdecDfdt;
            TextMax   = textMax;
            ToHl      = toHl;

            Ain1LinkFault = ain1LinkFault;
            Ain2LinkFault = ain2LinkFault;
            Ain3LinkFault = ain3LinkFault;
        }
 public double ConvertToSomething(BytesPair value)
 {
     return(value.HighFirstUnsignedValue * _modifier + _offset);
 }
Example #12
0
        public byte[] Serialize()
        {
            var settingsSerialized = new byte[114];

            settingsSerialized[0] = _settings.Reserved00.First;
            settingsSerialized[1] = _settings.Reserved00.Second;
            Console.WriteLine("_settings.KpW = " + _settings.KpW.ToString("f10"));
            var bpKpW = BytesPairToDecimalQ8Converter.ConvertToBytesPairQ8(_settings.KpW);

            settingsSerialized[2] = bpKpW.First;
            settingsSerialized[3] = bpKpW.Second;
            Console.WriteLine("_settings.KpW SERIALIZED = " + bpKpW);


            var ushbp52 = (ushort)(_settings.Np | (_settings.NimpFloorCode << 5) |
                                   ((_settings.FanMode.ToIoBits() & 0x03) << 8));

            Console.WriteLine("NPRM without DCM = " + ushbp52.ToString("X4"));
            ushbp52 = _settings.DirectCurrentMagnetization ? ushbp52.SetBit(11) : ushbp52.ResetBit(11);
            var bp52 = BytesPair.FromUnsignedShortLowFirst(ushbp52);

            Console.WriteLine("NPRM = " + bp52);


            settingsSerialized.SerializeIntLowFirst(4, (int)(_settings.KiW * 16777216.0m));
            settingsSerialized.SerializeShortLowFirst(8, (short)(_settings.FiNom * 1000.0m));
            settingsSerialized.SerializeShortLowFirst(10, _settings.Imax);
            settingsSerialized.SerializeShortLowFirst(12, _settings.UdcMax);
            settingsSerialized.SerializeShortLowFirst(14, _settings.UdcMin);

            settingsSerialized.SerializeUshortLowFirst(16, (ushort)(_settings.Fnom * 10.0m));
            settingsSerialized.SerializeUshortLowFirst(18, (ushort)(_settings.Fmax * 10.0m));

            settingsSerialized.SerializeShortLowFirst(20, (short)(_settings.DflLim * 1000.0m));
            settingsSerialized.SerializeShortLowFirst(22, (short)(_settings.FlMinMin * 1000.0m));

            settingsSerialized.SerializeShortLowFirst(24, _settings.IoutMax);
            settingsSerialized.SerializeShortLowFirst(26, (short)(_settings.FiMin * 1000.0m));

            settingsSerialized.SerializeUshortLowFirst(28, _settings.DacCh);
            settingsSerialized.SerializeUshortLowFirst(30, _settings.Imcw);

            settingsSerialized.SerializeShortLowFirst(32, _settings.Ia0);
            settingsSerialized.SerializeShortLowFirst(34, _settings.Ib0);
            settingsSerialized.SerializeShortLowFirst(36, _settings.Ic0);
            settingsSerialized.SerializeShortLowFirst(38, _settings.Udc0);
            settingsSerialized.SerializeShortLowFirst(40, (short)(_settings.TauR * 10000.0m));
            settingsSerialized.SerializeShortLowFirst(42, (short)(_settings.Lm * 100000.0m));
            settingsSerialized.SerializeShortLowFirst(44, (short)(_settings.Lsl * 1000000.0m));
            settingsSerialized.SerializeShortLowFirst(46, (short)(_settings.Lrl * 1000000.0m));

            settingsSerialized[48] = _settings.Reserved24.First;
            settingsSerialized[49] = _settings.Reserved24.Second;

            var bpKpFi = BytesPairToDecimalQ8Converter.ConvertToBytesPairQ8(_settings.KpFi);

            settingsSerialized[50] = bpKpFi.First;
            settingsSerialized[51] = bpKpFi.Second;

            settingsSerialized.SerializeIntLowFirst(52, (int)(_settings.KiFi * 16777216.0m));

            settingsSerialized[56] = _settings.Reserved28.First;
            settingsSerialized[57] = _settings.Reserved28.Second;

            var bpKpId = BytesPairToDecimalQ8Converter.ConvertToBytesPairQ8(_settings.KpId);

            settingsSerialized[58] = bpKpId.First;
            settingsSerialized[59] = bpKpId.Second;

            settingsSerialized.SerializeIntLowFirst(60, (int)(_settings.KiId * 16777216.0m));


            settingsSerialized[64] = _settings.Reserved32.First;
            settingsSerialized[65] = _settings.Reserved32.Second;


            var bpKpIq = BytesPairToDecimalQ8Converter.ConvertToBytesPairQ8(_settings.KpIq);

            settingsSerialized[66] = bpKpIq.First;
            settingsSerialized[67] = bpKpIq.Second;

            settingsSerialized.SerializeIntLowFirst(68, (int)(_settings.KiIq * 16777216.0m));

            settingsSerialized.SerializeShortLowFirst(72, (short)(_settings.AccDfDt * 10.0m));
            settingsSerialized.SerializeShortLowFirst(74, (short)(_settings.DecDfDt * 10.0m));
            settingsSerialized.SerializeUshortLowFirst(76,
                                                       (ushort)Math.Round(_settings.Unom * (decimal)Math.Sqrt(2.0)));

            settingsSerialized.SerializeShortLowFirst(78, (short)(_settings.TauFlLim * 10000.0m));

            settingsSerialized.SerializeUshortLowFirst(80, (ushort)(_settings.Rs * 10000.0m));

            settingsSerialized.SerializeUshortLowFirst(82, (ushort)(_settings.Fmin * 10.0m));
            settingsSerialized.SerializeShortLowFirst(84, (short)(_settings.TauM * 10000.0m));
            settingsSerialized.SerializeShortLowFirst(86, (short)(_settings.TauF * 10000.0m));
            settingsSerialized.SerializeShortLowFirst(88, (short)(_settings.TauFSet * 10000.0m));
            settingsSerialized.SerializeShortLowFirst(90, (short)(_settings.TauFi * 10000.0m));
            settingsSerialized.SerializeShortLowFirst(92, _settings.IdSetMin);
            settingsSerialized.SerializeShortLowFirst(94, _settings.IdSetMax);


            settingsSerialized[96] = _settings.UchMin.First;
            settingsSerialized[97] = _settings.UchMin.Second;

            settingsSerialized[98] = _settings.UchMax.First;
            settingsSerialized[99] = _settings.UchMax.Second;


            settingsSerialized[100] = _settings.Reserved50.First;
            settingsSerialized[101] = _settings.Reserved50.Second;

            settingsSerialized[102] = _settings.Reserved51.First;
            settingsSerialized[103] = _settings.Reserved51.Second;


            settingsSerialized[104] = bp52.First;
            settingsSerialized[105] = bp52.Second;


            settingsSerialized.SerializeShortLowFirst(106, (short)(_settings.UmodThr * 1000.0m));
            settingsSerialized.SerializeShortLowFirst(108, (short)(_settings.EmdecDfdt * 10.0m));
            settingsSerialized.SerializeShortLowFirst(110, _settings.TextMax);
            settingsSerialized.SerializeShortLowFirst(112, _settings.ToHl);

            var result = new byte[115];

            result[0] = OneBasedAinNumber;
            settingsSerialized.CopyTo(result, 1);
            return(result);
        }
 public static double ConvertBytesPairToDoubleQ8(BytesPair value)
 {
     var ushortValue = value.LowFirstUnsignedValue;
     var iValue = ushortValue << 16;
     return iValue / 16777216.0;
 }
 public static BytesPair ConvertDoubleToBytesPairQ8(double value)
 {
     var iValue = (int) (value * 16777216.0);
     var ushortValue = (ushort) (iValue >> 16);
     return BytesPair.FromUnsignedShortLowFirst(ushortValue);
 }
 public TemperatureRegulatorWorkModeBuilderReplied(BytesPair dataBytes)
 {
     _dataBytes = dataBytes;
 }
        private void Load()
        {
            var winSystem = new WpfWindowSystem();
            var filename  = winSystem.ShowOpenFileDialog("Импорт настроек", "XML files|*.xml|All files|*.*");

            if (filename != null)
            {
                try
                {
                    var doc         = XDocument.Load(filename);
                    var rootElement = doc.Element("Settings");
                    try
                    {
                        var ainElements = rootElement.Elements("AinSettings");
                        foreach (var ainElement in ainElements)
                        {
                            var zbAinNumber = byte.Parse(ainElement.Attribute("Number").Value);
                            try
                            {
                                _ainSettingsReadNotifyRaisable.RaiseAinSettingsReadStarted(zbAinNumber);

                                var reserved00 = BytesPair.Parse(TryGetChildElement(ainElement, "Reserved00").Value);
                                var kpW        = decimal.Parse(TryGetChildElement(ainElement, "KpW").Value,
                                                               CultureInfo.InvariantCulture);
                                var kiW = decimal.Parse(TryGetChildElement(ainElement, "KiW").Value,
                                                        CultureInfo.InvariantCulture);

                                var fiNom = decimal.Parse(TryGetChildElement(ainElement, "FiNom").Value,
                                                          CultureInfo.InvariantCulture);
                                var imax = short.Parse(TryGetChildElement(ainElement, "Imax").Value,
                                                       CultureInfo.InvariantCulture);
                                var udcMax = short.Parse(TryGetChildElement(ainElement, "UdcMax").Value,
                                                         CultureInfo.InvariantCulture);
                                var udcMin = short.Parse(TryGetChildElement(ainElement, "UdcMin").Value,
                                                         CultureInfo.InvariantCulture);
                                var fnom = decimal.Parse(TryGetChildElement(ainElement, "Fnom").Value,
                                                         CultureInfo.InvariantCulture);
                                var fmax = decimal.Parse(TryGetChildElement(ainElement, "Fmax").Value,
                                                         CultureInfo.InvariantCulture);

                                var dflLim = decimal.Parse(TryGetChildElement(ainElement, "DflLim").Value,
                                                           CultureInfo.InvariantCulture);
                                var flMinMin = decimal.Parse(TryGetChildElement(ainElement, "FlMinMin").Value,
                                                             CultureInfo.InvariantCulture);

                                var ioutMax = short.Parse(TryGetChildElement(ainElement, "IoutMax").Value,
                                                          CultureInfo.InvariantCulture);
                                var fiMin = decimal.Parse(TryGetChildElement(ainElement, "FiMin").Value,
                                                          CultureInfo.InvariantCulture);
                                var dacCh = ushort.Parse(TryGetChildElement(ainElement, "DacCh").Value,
                                                         CultureInfo.InvariantCulture);
                                var imcw = ushort.Parse(TryGetChildElement(ainElement, "Imcw").Value,
                                                        CultureInfo.InvariantCulture);
                                var ia0 = short.Parse(TryGetChildElement(ainElement, "Ia0").Value,
                                                      CultureInfo.InvariantCulture);
                                var ib0 = short.Parse(TryGetChildElement(ainElement, "Ib0").Value,
                                                      CultureInfo.InvariantCulture);
                                var ic0 = short.Parse(TryGetChildElement(ainElement, "Ic0").Value,
                                                      CultureInfo.InvariantCulture);
                                var udc0 = short.Parse(TryGetChildElement(ainElement, "Udc0").Value,
                                                       CultureInfo.InvariantCulture);

                                var tauR = decimal.Parse(TryGetChildElement(ainElement, "TauR").Value,
                                                         CultureInfo.InvariantCulture);
                                var lm = decimal.Parse(TryGetChildElement(ainElement, "Lm").Value,
                                                       CultureInfo.InvariantCulture);
                                var lsl = decimal.Parse(TryGetChildElement(ainElement, "Lsl").Value,
                                                        CultureInfo.InvariantCulture);
                                var lrl = decimal.Parse(TryGetChildElement(ainElement, "Lrl").Value,
                                                        CultureInfo.InvariantCulture);
                                var reserved24 = BytesPair.Parse(TryGetChildElement(ainElement, "Reserved24").Value);

                                var kpFi = decimal.Parse(TryGetChildElement(ainElement, "KpFi").Value,
                                                         CultureInfo.InvariantCulture);
                                var kiFi = decimal.Parse(TryGetChildElement(ainElement, "KiFi").Value,
                                                         CultureInfo.InvariantCulture);

                                var reserved28 = BytesPair.Parse(TryGetChildElement(ainElement, "Reserved28").Value);

                                var kpId = decimal.Parse(TryGetChildElement(ainElement, "KpId").Value,
                                                         CultureInfo.InvariantCulture);
                                var kiId = decimal.Parse(TryGetChildElement(ainElement, "KiId").Value,
                                                         CultureInfo.InvariantCulture);

                                var reserved32 = BytesPair.Parse(TryGetChildElement(ainElement, "Reserved32").Value);

                                var kpIq = decimal.Parse(TryGetChildElement(ainElement, "KpIq").Value,
                                                         CultureInfo.InvariantCulture);
                                var kiIq = decimal.Parse(TryGetChildElement(ainElement, "KiIq").Value,
                                                         CultureInfo.InvariantCulture);

                                var accDfDt = decimal.Parse(TryGetChildElement(ainElement, "AccDfDt").Value,
                                                            CultureInfo.InvariantCulture);
                                var decDfDt = decimal.Parse(TryGetChildElement(ainElement, "DecDfDt").Value,
                                                            CultureInfo.InvariantCulture);
                                var unom = decimal.Parse(TryGetChildElement(ainElement, "Unom").Value,
                                                         CultureInfo.InvariantCulture);

                                var tauFlLim = decimal.Parse(TryGetChildElement(ainElement, "TauFlLim").Value,
                                                             CultureInfo.InvariantCulture);

                                var rs = decimal.Parse(TryGetChildElement(ainElement, "Rs").Value,
                                                       CultureInfo.InvariantCulture);
                                var fmin = decimal.Parse(TryGetChildElement(ainElement, "Fmin").Value,
                                                         CultureInfo.InvariantCulture);
                                var tauM = decimal.Parse(TryGetChildElement(ainElement, "TauM").Value,
                                                         CultureInfo.InvariantCulture);
                                var tauF = decimal.Parse(TryGetChildElement(ainElement, "TauF").Value,
                                                         CultureInfo.InvariantCulture);
                                var tauFSet = decimal.Parse(TryGetChildElement(ainElement, "TauFSet").Value,
                                                            CultureInfo.InvariantCulture);
                                var tauFi = decimal.Parse(TryGetChildElement(ainElement, "TauFi").Value,
                                                          CultureInfo.InvariantCulture);
                                var idSetMin = short.Parse(TryGetChildElement(ainElement, "IdSetMin").Value,
                                                           CultureInfo.InvariantCulture);
                                var idSetMax = short.Parse(TryGetChildElement(ainElement, "IdSetMax").Value,
                                                           CultureInfo.InvariantCulture);
                                var uchMin = BytesPair.Parse(TryGetChildElement(ainElement, "UchMin").Value);
                                var uchMax = BytesPair.Parse(TryGetChildElement(ainElement, "UchMax").Value);

                                var reserved50 = BytesPair.Parse(TryGetChildElement(ainElement, "Reserved50").Value);
                                var reserved51 = BytesPair.Parse(TryGetChildElement(ainElement, "Reserved51").Value);

                                var np = int.Parse(TryGetChildElement(ainElement, "Np").Value,
                                                   CultureInfo.InvariantCulture);
                                var nimpFloorCode = int.Parse(TryGetChildElement(ainElement, "NimpFloorCode").Value,
                                                              CultureInfo.InvariantCulture);
                                var fanMode = AinTelemetryFanWorkmodeExtensions.FromIoBits(
                                    int.Parse(TryGetChildElement(ainElement, "FanMode").Value,
                                              CultureInfo.InvariantCulture));
                                var directCurrentMagnetization =
                                    bool.Parse(TryGetChildElement(ainElement, "DirectCurrentMagnetization").Value);

                                var umodThr = decimal.Parse(TryGetChildElement(ainElement, "UmodThr").Value,
                                                            CultureInfo.InvariantCulture);

                                var emdecDfdt = decimal.Parse(TryGetChildElement(ainElement, "EmdecDfdt").Value,
                                                              CultureInfo.InvariantCulture);

                                var textMax = short.Parse(TryGetChildElement(ainElement, "TextMax").Value,
                                                          CultureInfo.InvariantCulture);
                                var toHl = short.Parse(TryGetChildElement(ainElement, "ToHl").Value,
                                                       CultureInfo.InvariantCulture);
                                var ain1LinkFault = bool.Parse(TryGetChildElement(ainElement, "Ain1LinkFault").Value);
                                var ain2LinkFault = bool.Parse(TryGetChildElement(ainElement, "Ain2LinkFault").Value);
                                var ain3LinkFault = bool.Parse(TryGetChildElement(ainElement, "Ain3LinkFault").Value);


                                var setting = new AinSettingsSimple(reserved00, kpW, kiW, fiNom, imax, udcMax, udcMin,
                                                                    fnom, fmax, dflLim, flMinMin, ioutMax, fiMin, dacCh, imcw, ia0, ib0, ic0, udc0,
                                                                    tauR, lm, lsl, lrl, reserved24, kpFi, kiFi, reserved28, kpId, kiId, reserved32,
                                                                    kpIq, kiIq, accDfDt, decDfDt, unom, tauFlLim, rs, fmin, tauM, tauF, tauFSet, tauFi,
                                                                    idSetMin, idSetMax, uchMin, uchMax, reserved50, reserved51, np, nimpFloorCode,
                                                                    fanMode, directCurrentMagnetization, umodThr, emdecDfdt, textMax, toHl,
                                                                    ain1LinkFault, ain2LinkFault, ain3LinkFault);
                                _ainSettingsStorageSettable.SetSettings(zbAinNumber, setting);
                                _ainSettingsReadNotifyRaisable.RaiseAinSettingsReadComplete(zbAinNumber, null,
                                                                                            setting); // TODO: try catch real exception
                                _debugLogger.GetLogger(5).Log("Настройки №" + zbAinNumber + " успешно импортированы",
                                                              new StackTrace(true));
                            }
                            catch (Exception e)
                            {
                                _debugLogger.GetLogger(1)
                                .Log(
                                    "Не удалось импортировать настройки АИН№" + zbAinNumber + Environment.NewLine +
                                    e, new StackTrace(e, true));
                            }
                        }
                    }
                    catch (Exception exx)
                    {
                        _debugLogger.GetLogger(1)
                        .Log("Не удалось импортировать настройки АИН" + Environment.NewLine + exx,
                             new StackTrace(exx, true));
                    }

                    var engineSettingsElement = rootElement.Element("EngineSettings");
                    if (engineSettingsElement != null)
                    {
                        try
                        {
                            var settings = new EngineSettingsSimple
                            {
                                Inom = ushort.Parse(TryGetChildElement(engineSettingsElement, "Inom").Value,
                                                    CultureInfo.InvariantCulture),
                                Nnom = ushort.Parse(TryGetChildElement(engineSettingsElement, "Nnom").Value,
                                                    CultureInfo.InvariantCulture),
                                Nmax = ushort.Parse(TryGetChildElement(engineSettingsElement, "Nmax").Value,
                                                    CultureInfo.InvariantCulture),
                                Pnom = decimal.Parse(TryGetChildElement(engineSettingsElement, "Pnom").Value,
                                                     CultureInfo.InvariantCulture),
                                CosFi = decimal.Parse(TryGetChildElement(engineSettingsElement, "CosFi").Value,
                                                      CultureInfo.InvariantCulture),
                                Eff = decimal.Parse(TryGetChildElement(engineSettingsElement, "Eff").Value,
                                                    CultureInfo.InvariantCulture),
                                Mass = ushort.Parse(TryGetChildElement(engineSettingsElement, "Mass").Value,
                                                    CultureInfo.InvariantCulture),
                                MmM = ushort.Parse(TryGetChildElement(engineSettingsElement, "MmM").Value,
                                                   CultureInfo.InvariantCulture),
                                Height = ushort.Parse(TryGetChildElement(engineSettingsElement, "Height").Value,
                                                      CultureInfo.InvariantCulture),
                                I2Tmax = uint.Parse(TryGetChildElement(engineSettingsElement, "I2Tmax").Value,
                                                    CultureInfo.InvariantCulture),
                                Icontinious =
                                    ushort.Parse(TryGetChildElement(engineSettingsElement, "Icontinious").Value,
                                                 CultureInfo.InvariantCulture),
                                ZeroF = ushort.Parse(TryGetChildElement(engineSettingsElement, "ZeroF").Value,
                                                     CultureInfo.InvariantCulture)
                            };
                            _engineSettingsStorageSettable.SetSettings(settings);
                            _engineSettingsReadNotifyRaisable.RaiseEngineSettingsReadComplete(null, settings);
                            _debugLogger.GetLogger(5).Log("Настройки двигателя успешно импортированы",
                                                          new StackTrace(true));
                        }
                        catch (Exception ex)
                        {
                            _debugLogger.GetLogger(1)
                            .Log("Не удалось импортировать настройки двигателя" + Environment.NewLine + ex,
                                 new StackTrace(ex, true));
                            throw;
                        }
                    }
                }
                catch (Exception ex)
                {
                    _debugLogger.GetLogger(1)
                    .Log("Не удалось импортировать настройки из " + filename + Environment.NewLine + ex,
                         new StackTrace(ex, true));
                    throw;
                }
            }
        }
        public IAinSettings GetResult(byte[] reply)
        {
            if (reply[0] != OneBasedAinNumber)
            {
                throw new Exception("неверный номер АИН в ответе, ожидался " + OneBasedAinNumber);
            }

            // TODO: check if reply[0] is equal oneBasedAinNumber
            var replyWithoutAinNumber = reply.Skip(1).ToList();


            var bp52 = new BytesPair(replyWithoutAinNumber[104], replyWithoutAinNumber[105]);
            //Console.WriteLine("<<READ>> NPRM = " + bp52.First.ToString("X2") + bp52.Second.ToString("X2"));
            var np            = bp52.First & 0x1F;
            var nimpFloorCode = (bp52.First & 0xE0) >> 5;
            var fanMode       = AinTelemetryFanWorkmodeExtensions.FromIoBits(bp52.Second & 0x03);
            var directCurrentMagnetization = bp52.Second.GetBit(3);

            return(new AinSettingsSimple(
                       new BytesPair(replyWithoutAinNumber[0], replyWithoutAinNumber[1]),
                       BytesPairToDecimalQ8Converter.ConvertBytesPairToDecimalQ8(new BytesPair(replyWithoutAinNumber[2],
                                                                                               replyWithoutAinNumber[3])),
                       // kiW
                       (replyWithoutAinNumber[4] + (replyWithoutAinNumber[5] << 8) + (replyWithoutAinNumber[6] << 16) +
                        (replyWithoutAinNumber[7] << 24)) / 16777216.0m,
                       new BytesPair(replyWithoutAinNumber[8], replyWithoutAinNumber[9]).LowFirstSignedValue / 1000.0m,
                       new BytesPair(replyWithoutAinNumber[10], replyWithoutAinNumber[11]).LowFirstSignedValue,
                       new BytesPair(replyWithoutAinNumber[12], replyWithoutAinNumber[13]).LowFirstSignedValue,
                       new BytesPair(replyWithoutAinNumber[14], replyWithoutAinNumber[15]).LowFirstSignedValue,

                       // Fnom:
                       new BytesPair(replyWithoutAinNumber[16], replyWithoutAinNumber[17]).LowFirstSignedValue / 10.0m,
                       // Fmax:
                       new BytesPair(replyWithoutAinNumber[18], replyWithoutAinNumber[19]).LowFirstSignedValue / 10.0m,
                       // DflLim:
                       new BytesPair(replyWithoutAinNumber[20], replyWithoutAinNumber[21]).LowFirstSignedValue / 1000.0m,
                       new BytesPair(replyWithoutAinNumber[22], replyWithoutAinNumber[23]).LowFirstSignedValue / 1000.0m,
                       new BytesPair(replyWithoutAinNumber[24], replyWithoutAinNumber[25]).LowFirstSignedValue,
                       new BytesPair(replyWithoutAinNumber[26], replyWithoutAinNumber[27]).LowFirstSignedValue / 1000.0m,
                       new BytesPair(replyWithoutAinNumber[28], replyWithoutAinNumber[29]).LowFirstUnsignedValue,
                       new BytesPair(replyWithoutAinNumber[30], replyWithoutAinNumber[31]).LowFirstUnsignedValue,
                       new BytesPair(replyWithoutAinNumber[32], replyWithoutAinNumber[33]).LowFirstSignedValue,
                       new BytesPair(replyWithoutAinNumber[34], replyWithoutAinNumber[35]).LowFirstSignedValue,
                       new BytesPair(replyWithoutAinNumber[36], replyWithoutAinNumber[37]).LowFirstSignedValue,
                       new BytesPair(replyWithoutAinNumber[38], replyWithoutAinNumber[39]).LowFirstSignedValue,

                       // TauR:
                       new BytesPair(replyWithoutAinNumber[40], replyWithoutAinNumber[41]).LowFirstSignedValue / 10000.0m,
                       // Lm:
                       new BytesPair(replyWithoutAinNumber[42], replyWithoutAinNumber[43]).LowFirstSignedValue / 100000.0m,
                       // Lsl:
                       new BytesPair(replyWithoutAinNumber[44], replyWithoutAinNumber[45]).LowFirstSignedValue / 1000000.0m,
                       // Lrl:
                       new BytesPair(replyWithoutAinNumber[46], replyWithoutAinNumber[47]).LowFirstSignedValue / 1000000.0m,

                       // reserved 24:
                       new BytesPair(replyWithoutAinNumber[48], replyWithoutAinNumber[49]),
                       BytesPairToDecimalQ8Converter.ConvertBytesPairToDecimalQ8(new BytesPair(replyWithoutAinNumber[50],
                                                                                               replyWithoutAinNumber[51])),
                       // kiFi:
                       (replyWithoutAinNumber[52] + (replyWithoutAinNumber[53] << 8) + (replyWithoutAinNumber[54] << 16) +
                        (replyWithoutAinNumber[55] << 24)) / 16777216.0m,

                       // reserved 28:
                       new BytesPair(replyWithoutAinNumber[56], replyWithoutAinNumber[57]),

                       // kpId:
                       BytesPairToDecimalQ8Converter.ConvertBytesPairToDecimalQ8(new BytesPair(replyWithoutAinNumber[58],
                                                                                               replyWithoutAinNumber[59])),
                       // kiId:
                       (replyWithoutAinNumber[60] + (replyWithoutAinNumber[61] << 8) + (replyWithoutAinNumber[62] << 16) +
                        (replyWithoutAinNumber[63] << 24)) / 16777216.0m,

                       // reserverd 32:
                       new BytesPair(replyWithoutAinNumber[64], replyWithoutAinNumber[65]),

                       // kpIq:
                       BytesPairToDecimalQ8Converter.ConvertBytesPairToDecimalQ8(new BytesPair(replyWithoutAinNumber[66],
                                                                                               replyWithoutAinNumber[67])),
                       // kiIq:
                       (replyWithoutAinNumber[68] + (replyWithoutAinNumber[69] << 8) + (replyWithoutAinNumber[70] << 16) +
                        (replyWithoutAinNumber[71] << 24)) / 16777216.0m,
                       new BytesPair(replyWithoutAinNumber[72], replyWithoutAinNumber[73]).LowFirstSignedValue * 0.1m,
                       new BytesPair(replyWithoutAinNumber[74], replyWithoutAinNumber[75]).LowFirstSignedValue * 0.1m,
                       // Unom:
                       new BytesPair(replyWithoutAinNumber[76], replyWithoutAinNumber[77]).LowFirstSignedValue /
                       (decimal)Math.Sqrt(2.0),
                       // TauFlLim:
                       new BytesPair(replyWithoutAinNumber[78], replyWithoutAinNumber[79]).LowFirstSignedValue / 10000.0m,
                       // Rs:
                       new BytesPair(replyWithoutAinNumber[80], replyWithoutAinNumber[81]).LowFirstSignedValue / 10000.0m,
                       // fmin:
                       new BytesPair(replyWithoutAinNumber[82], replyWithoutAinNumber[83]).LowFirstSignedValue / 10.0m,
                       new BytesPair(replyWithoutAinNumber[84], replyWithoutAinNumber[85]).LowFirstSignedValue / 10000.0m,
                       new BytesPair(replyWithoutAinNumber[86], replyWithoutAinNumber[87]).LowFirstSignedValue / 10000.0m,
                       new BytesPair(replyWithoutAinNumber[88], replyWithoutAinNumber[89]).LowFirstSignedValue / 10000.0m,
                       new BytesPair(replyWithoutAinNumber[90], replyWithoutAinNumber[91]).LowFirstSignedValue / 10000.0m,
                       new BytesPair(replyWithoutAinNumber[92], replyWithoutAinNumber[93]).LowFirstSignedValue,
                       new BytesPair(replyWithoutAinNumber[94], replyWithoutAinNumber[95]).LowFirstSignedValue,
                       new BytesPair(replyWithoutAinNumber[96], replyWithoutAinNumber[97]),
                       new BytesPair(replyWithoutAinNumber[98], replyWithoutAinNumber[99]),

                       // reserverd 50:
                       new BytesPair(replyWithoutAinNumber[100], replyWithoutAinNumber[101]),

                       // reserverd 51:
                       new BytesPair(replyWithoutAinNumber[102], replyWithoutAinNumber[103]),

                       // Param52 (np and others):
                       np,
                       nimpFloorCode,
                       fanMode,
                       directCurrentMagnetization,
                       new BytesPair(replyWithoutAinNumber[106], replyWithoutAinNumber[107]).LowFirstSignedValue / 1000.0m,
                       new BytesPair(replyWithoutAinNumber[108], replyWithoutAinNumber[109]).LowFirstSignedValue / 10.0m,
                       new BytesPair(replyWithoutAinNumber[110], replyWithoutAinNumber[111]).LowFirstSignedValue,
                       new BytesPair(replyWithoutAinNumber[112], replyWithoutAinNumber[113]).LowFirstSignedValue,

                       // Status byte:
                       (replyWithoutAinNumber[114] & 0x01) == 0x01,
                       (replyWithoutAinNumber[114] & 0x02) == 0x02,
                       (replyWithoutAinNumber[114] & 0x04) == 0x04
                       ));
        }
Example #18
0
 public double ConvertToSomething(BytesPair value)
 {
     return(value.HighFirstUnsignedValue);
 }
 protected SensorIndicationBytesPairCheck(BytesPair value, BytesPair noLinkCode)
 {
     _value      = value;
     _noLinkCode = noLinkCode;
 }