OGE.MeasurementStream.PointMetaData.AdaptCommands2 C# (CSharp) Method

AdaptCommands2() private method

private AdaptCommands2 ( ) : void
return void
        private void AdaptCommands2()
        {
            byte code1 = 0;
            int count1 = 0;

            byte code2 = 1;
            int count2 = 0;

            byte code3 = 2;
            int count3 = 0;

            int total = 0;

            for (int x = 0; x < m_commandStats.Length; x++)
            {
                int cnt = m_commandStats[x];
                m_commandStats[x] = 0;

                total += cnt;

                if (cnt > count3)
                {
                    if (cnt > count1)
                    {
                        code3 = code2;
                        count3 = count2;

                        code2 = code1;
                        count2 = count1;

                        code1 = (byte)x;
                        count1 = cnt;
                    }
                    else if (cnt > count2)
                    {
                        code3 = code2;
                        count3 = count2;

                        code2 = (byte)x;
                        count2 = cnt;
                    }
                    else
                    {
                        code3 = (byte)x;
                        count3 = cnt;
                    }
                }
            }

            int mode1Size = total * 6;
            int mode2Size = count1 * 1 + (total - count1) * 7;
            int mode3Size = count1 * 1 + count2 * 2 + (total - count1 - count2) * 8;
            int mode4Size = count1 * 1 + count2 * 2 + count3 * 3 + (total - count1 - count2 - count3) * 9;

            int minSize = int.MaxValue;
            minSize = Math.Min(minSize, mode1Size);
            minSize = Math.Min(minSize, mode2Size);
            minSize = Math.Min(minSize, mode3Size);
            minSize = Math.Min(minSize, mode4Size);

            if (minSize == mode1Size)
            {
                Mode = 1;
            }
            else if (minSize == mode2Size)
            {
                Mode = 2;
                Mode2_1 = code1;
            }
            else if (minSize == mode3Size)
            {
                Mode = 3;
                Mode3_1 = code1;
                Mode3_01 = code2;
            }
            else if (minSize == mode4Size)
            {
                Mode = 4;
                Mode4_1 = code1;
                Mode4_01 = code2;
                Mode4_001 = code3;
            }
            else
            {
                throw new Exception("Coding Error");
            }

            m_commandsSentSinceLastChange = 0;
        }