Esempio n. 1
0
 public void ExecuteReadConfig()
 {
     try
     {
         _cvConfiguration.LoadConfiguration(ConfigurationFile);
         StartVoltage     = _cvConfiguration.StartVoltage;
         FinalVoltage     = _cvConfiguration.FinalVoltage;
         IncrementVoltage = _cvConfiguration.IncrementVoltage;
         CurrentLimit     = _cvConfiguration.CurrentLimit;
         Amplitude        = _cvConfiguration.Amplitude;
         FrequencyList.Clear();
         foreach (var frequency in _cvConfiguration.TestWaveFrequency)
         {
             FrequencyList.Add(frequency);
         }
         StatusMessage = $"Configuration File {ConfigurationFile} loaded";
     }
     catch (Exception ex)
     {
         StatusMessage = $"Error {ex.Message} reading Configuration File: {ConfigurationFile}";
     }
 }
Esempio n. 2
0
            /// <summary>
            /// Adapted from https://github.com/google/brotli/blob/master/c/enc/compress_fragment.c (ShouldMergeBlock).
            /// </summary>
            private bool ShouldMergeBlock(int ip, int blockSize)
            {
                const int            sampleRate = 43;
                FrequencyList <byte> bytes      = new FrequencyList <byte>();

                for (int offset = 0; offset < blockSize; offset += sampleRate)
                {
                    bytes.Add(input[ip + offset]);
                }

                int    total = (blockSize + sampleRate - 1) / sampleRate;
                double r     = ((total == 0 ? 0 : Math.Log(total, 2.0) + 0.5) * total) + 200;

                foreach (var symbol in bytes)
                {
                    var samples = bytes[symbol];
                    var literal = new Literal(symbol);

                    r -= samples * (literalTree !.FindPath(literal).Length + Math.Log(samples, 2.0));
                }

                return(r >= 0.0);
            }
        protected override (MetaBlock, BrotliGlobalState) Transform(MetaBlock.Compressed original, BrotliGlobalState state, BrotliCompressionParameters parameters)
        {
            var builder = new CompressedMetaBlockBuilder(original, state);

            var literals      = new List <Literal>(builder.GetTotalBlockLength(Category.Literal));
            var lengthCodes   = new List <InsertCopyLengthCode>(builder.GetTotalBlockLength(Category.InsertCopy));
            var distanceCodes = new List <DistanceCode>(builder.GetTotalBlockLength(Category.Distance));

            var distanceFreq       = new FrequencyList <DistanceCode>();
            var validDistanceCodes = new List <DistanceCode>(5);

            foreach (var command in original.Data.InsertCopyCommands)
            {
                literals.AddRange(command.Literals);
                state.OutputLiterals(command.Literals);

                if (command.CopyDistance == DistanceInfo.EndsAfterLiterals)
                {
                    lengthCodes.Add(command.Lengths.MakeCode(ImplicitDistanceCodeZero.PreferEnabled));
                    break;
                }

                if (!command.CopyDistance.FindCodes(original.Header.DistanceParameters, state, validDistanceCodes))
                {
                    lengthCodes.Add(command.Lengths.MakeCode(ImplicitDistanceCodeZero.ForceEnabled));
                }
                else
                {
                    DistanceCode distanceCode;

                    if (command.CopyDistance == DistanceInfo.ExplicitCodeZero)
                    {
                        distanceCode = DistanceCode.Zero;
                    }
                    else
                    {
                        distanceCode = validDistanceCodes.Count > 1 ? parameters.DistanceCodePicker(validDistanceCodes, distanceFreq) : validDistanceCodes[0];
                    }

                    distanceFreq.Add(distanceCode);
                    distanceCodes.Add(distanceCode);
                    lengthCodes.Add(command.Lengths.MakeCode(ImplicitDistanceCodeZero.Disable));
                }
            }

            var origLitCtxMap = builder.LiteralCtxMap;

            if (origLitCtxMap.TreeCount == 1)
            {
                Split(builder, Category.Literal, literals, 512, 400.0);

                builder.UseSameLiteralContextMode(LiteralContextMode.UTF8);
                builder.LiteralCtxMap = new ContextMapBuilder.Literals(builder).RepeatFirstBlockType(true).Build();
            }
            else
            {
                var literalContextMap  = Enumerable.Range(0, origLitCtxMap.ContextsPerBlockType).Select(index => origLitCtxMap.DetermineTreeID(0, index)).ToArray();
                var literalContextMode = builder.LiteralContextModes[0];

                var literalBuffer = RingBufferFast <byte> .From(0, 0);

                Split(builder, Category.Literal, literals, 512, 400.0, new BlockSplitter <Literal> .ContextInfo(literalContextMap, literal => {
                    literalBuffer.Push(literal.Value);
                    return(literalContextMode.DetermineContextID(literalBuffer.Front, literalBuffer.Back));
                }));

                builder.UseSameLiteralContextMode(literalContextMode);
                builder.LiteralCtxMap = new ContextMapBuilder.Literals(builder).Set(0, literalContextMap).RepeatFirstBlockType(true).Build();
            }

            Split(builder, Category.InsertCopy, lengthCodes, 1024, 500.0);
            Split(builder, Category.Distance, distanceCodes, 512, 100.0);

            builder.DistanceCtxMap = new ContextMapBuilder.Distances(builder).RepeatFirstBlockType(true).Build();

            return(builder.Build(parameters));
        }
Esempio n. 4
0
 public void ExecuteAddFrequency()
 {
     FrequencyList.Add(NewFrequency);
     FrequencyList.Sort();
 }