Exemplo n.º 1
0
        protected void OnParse(byte[] table, int startOffset)
        {
            int initial = startOffset;

            for (int index = 0; index < DataSelectionTable.ActualRegisterTable.NumberOfSummations; index++)
            {
                byte[] summationArray = new byte[6];
                int    offset         = initial + index * 6;//Cada dato tiene 6 bytes
                Array.Copy(table, offset, summationArray, 0, 6);
                Array.Reverse(summationArray);
                JIBitArray jb        = new JIBitArray(summationArray);
                long       summation = 0;
                if (jb.Get(0) == true) //Es negativo hay que hacer complemento a 2
                {
                    jb        = jb.Not();
                    summation = jb.GetLong()[0];
                    summation = summation + 1;
                    summation = -1 * summation;
                }
                else
                {
                    summation = jb.GetLong()[0];
                }

                Source          registerSource    = DataSelectionTable.SummationSelect[index];
                BillingRegister summationRegister = new BillingRegister()
                {
                    Value     = summation * (decimal)Math.Pow(10, registerSource.ScaleFactor),
                    UOM       = Helper.ConvertUOMCodeToString(registerSource.UOMCode) + "h",
                    Direction = registerSource.Flow.ToString()
                };
                TotalDataBlock.Summations.Add(summationRegister);
            }

            initial = initial + (DataSelectionTable.ActualRegisterTable.NumberOfSummations * 6);
            for (int index = 0; index < DataSelectionTable.ActualRegisterTable.NumberOfDemmands; index++)
            {
                int    offset          = initial + index * (5 + 6 + 5); //Cada dato tiene 5+6+5 bytes
                byte[] dateArray       = new byte[5];
                byte[] cumulativeArray = new byte[6];
                byte[] maxArray        = new byte[5];
                Array.Copy(table, offset, dateArray, 0, 5);
                Array.Copy(table, offset + 5, cumulativeArray, 0, 6);
                Array.Reverse(cumulativeArray);
                JIBitArray jb         = new JIBitArray(cumulativeArray);
                long       cumulative = 0;
                if (jb.Get(0) == true) //Es negativo hay que hacer complemento a 2
                {
                    jb         = jb.Not();
                    cumulative = jb.GetLong()[0];
                    cumulative = cumulative + 1;
                    cumulative = -1 * cumulative;
                }
                else
                {
                    cumulative = jb.GetLong()[0];
                }
                Array.Copy(table, offset + 5 + 6, maxArray, 0, 5);
                Array.Reverse(maxArray);
                jb = new JIBitArray(maxArray);
                long maximum = 0;
                if (jb.Get(0) == true) //Es negativo hay que hacer complemento a 2
                {
                    jb      = jb.Not();
                    maximum = jb.GetLong()[0];
                    maximum = maximum + 1;
                    maximum = -1 * maximum;
                }
                else
                {
                    maximum = jb.GetLong()[0];
                }

                var    demandSource = DataSelectionTable.DemandSelect[index];
                string uom          = Helper.ConvertUOMCodeToString(demandSource.UOMCode);
                Demand demand       = new Demand()
                {
                    Max = new BillingRegister()
                    {
                        Value     = maximum * (decimal)Math.Pow(10, demandSource.ScaleFactor),
                        UOM       = uom,
                        Direction = demandSource.Flow.ToString()
                    },
                    Cumulative = new BillingRegister()
                    {
                        Value     = cumulative * (decimal)Math.Pow(10, demandSource.ScaleFactor),
                        UOM       = uom,
                        Direction = demandSource.Flow.ToString()
                    },
                    Date = Helper.ConvertToDateTime(dateArray)
                };

                TotalDataBlock.Demands.Add(demand);
            }

            initial = initial + DataSelectionTable.ActualRegisterTable.NumberOfDemmands * (5 + 6 + 5);
            for (int index = 0; index < DataSelectionTable.ActualRegisterTable.NumberOfCoincidentValues; index++)
            {
                byte[] coincidentArray = new byte[5];
                int    offset          = initial + index * 5;//Cada dato tiene 5 bytes
                Array.Copy(table, offset, coincidentArray, 0, 5);
                Array.Reverse(coincidentArray);
                JIBitArray jb         = new JIBitArray(coincidentArray);
                long       coincident = 0;
                if (jb.Get(0) == true) //Es negativo hay que hacer complemento a 2
                {
                    jb         = jb.Not();
                    coincident = jb.GetLong()[0];
                    coincident = coincident + 1;
                    coincident = -1 * coincident;
                }
                else
                {
                    coincident = jb.GetLong()[0];
                }
                Source          registerSource     = DataSelectionTable.CoincidentSelect[index];
                BillingRegister coincidentRegister = new BillingRegister()
                {
                    Value     = coincident * (decimal)Math.Pow(10, registerSource.ScaleFactor),
                    UOM       = Helper.ConvertUOMCodeToString(registerSource.UOMCode),
                    Direction = registerSource.Flow.ToString()
                };
                TotalDataBlock.Coincidents.Add(coincidentRegister);
            }

            initial = initial + DataSelectionTable.ActualRegisterTable.NumberOfCoincidentValues * 5;

            //Empiezo con las capas o fases
            for (int k = 0; k < DataSelectionTable.ActualRegisterTable.NumberOfTiers; k++)
            {
                Tier tier = new Tier(k);
                for (int index = 0; index < DataSelectionTable.ActualRegisterTable.NumberOfSummations; index++)
                {
                    byte[] summationArray = new byte[6];
                    int    offset         = initial + index * 6;//Cada dato tiene 6 bytes
                    Array.Copy(table, offset, summationArray, 0, 6);
                    Array.Reverse(summationArray);
                    JIBitArray jb        = new JIBitArray(summationArray);
                    long       summation = 0;
                    if (jb.Get(0) == true) //Es negativo hay que hacer complemento a 2
                    {
                        jb        = jb.Not();
                        summation = jb.GetLong()[0];
                        summation = summation + 1;
                        summation = -1 * summation;
                    }
                    else
                    {
                        summation = jb.GetLong()[0];
                    }

                    Source          registerSource    = DataSelectionTable.SummationSelect[index];
                    BillingRegister summationRegister = new BillingRegister()
                    {
                        Value     = summation * (decimal)Math.Pow(10, registerSource.ScaleFactor),
                        UOM       = Helper.ConvertUOMCodeToString(registerSource.UOMCode) + "h",
                        Direction = registerSource.Flow.ToString()
                    };


                    tier.Summations.Add(summationRegister);
                }

                initial = initial + DataSelectionTable.ActualRegisterTable.NumberOfSummations * 6;
                for (int index = 0; index < DataSelectionTable.ActualRegisterTable.NumberOfDemmands; index++)
                {
                    int    offset          = initial + index * (5 + 6 + 5);//Cada dato tiene 5+6+5 bytes
                    byte[] dateArray       = new byte[5];
                    byte[] cumulativeArray = new byte[6];
                    byte[] maxArray        = new byte[5];
                    Array.Copy(table, offset, dateArray, 0, 5);
                    Array.Copy(table, offset + 5, cumulativeArray, 0, 6);
                    Array.Reverse(cumulativeArray);
                    JIBitArray jb         = new JIBitArray(cumulativeArray);
                    long       cumulative = 0;
                    if (jb.Get(0) == true) //Es negativo hay que hacer complemento a 2
                    {
                        jb         = jb.Not();
                        cumulative = jb.GetLong()[0];
                        cumulative = cumulative + 1;
                        cumulative = -1 * cumulative;
                    }
                    else
                    {
                        cumulative = jb.GetLong()[0];
                    }
                    Array.Copy(table, offset + 5 + 6, maxArray, 0, 5);
                    Array.Reverse(maxArray);
                    jb = new JIBitArray(maxArray);
                    long maximum = 0;
                    if (jb.Get(0) == true) //Es negativo hay que hacer complemento a 2
                    {
                        jb      = jb.Not();
                        maximum = jb.GetLong()[0];
                        maximum = maximum + 1;
                        maximum = -1 * maximum;
                    }
                    else
                    {
                        maximum = jb.GetLong()[0];
                    }

                    var    demandSource = DataSelectionTable.DemandSelect[index];
                    string uom          = Helper.ConvertUOMCodeToString(demandSource.UOMCode);
                    Demand demand       = new Demand()
                    {
                        Max = new BillingRegister()
                        {
                            Value     = maximum * (decimal)Math.Pow(10, demandSource.ScaleFactor),
                            UOM       = uom,
                            Direction = demandSource.Flow.ToString()
                        },
                        Cumulative = new BillingRegister()
                        {
                            Value     = cumulative * (decimal)Math.Pow(10, demandSource.ScaleFactor),
                            UOM       = uom,
                            Direction = demandSource.Flow.ToString()
                        },
                        Date = Helper.ConvertToDateTime(dateArray)
                    };

                    tier.Demands.Add(demand);
                }

                initial = initial + DataSelectionTable.ActualRegisterTable.NumberOfDemmands * (5 + 6 + 5);
                for (int index = 0; index < DataSelectionTable.ActualRegisterTable.NumberOfCoincidentValues; index++)
                {
                    byte[] coincidentArray = new byte[5];
                    int    offset          = initial + index * 5;//Cada dato tiene 5 bytes
                    Array.Copy(table, offset, coincidentArray, 0, 5);
                    Array.Reverse(coincidentArray);
                    JIBitArray jb         = new JIBitArray(coincidentArray);
                    long       coincident = 0;
                    if (jb.Get(0) == true) //Es negativo hay que hacer complemento a 2
                    {
                        jb         = jb.Not();
                        coincident = jb.GetLong()[0];
                        coincident = coincident + 1;
                        coincident = -1 * coincident;
                    }
                    else
                    {
                        coincident = jb.GetLong()[0];
                    }
                    Source          registerSource     = DataSelectionTable.CoincidentSelect[index];
                    BillingRegister coincidentRegister = new BillingRegister()
                    {
                        Value     = coincident * (decimal)Math.Pow(10, registerSource.ScaleFactor),
                        UOM       = Helper.ConvertUOMCodeToString(registerSource.UOMCode),
                        Direction = registerSource.Flow.ToString()
                    };
                    tier.Coincidents.Add(coincidentRegister);
                }
                initial = initial + DataSelectionTable.ActualRegisterTable.NumberOfCoincidentValues * 5;
                Tiers.Add(tier);
            }
        }
Exemplo n.º 2
0
        protected override void OnParse(byte[] table)
        {
            int initial = 0;
            int offset  = 0;

            for (int i = 0; i < (table.Length / EntryLen); i++)
            {
                Source source = new Source();
                offset = initial;
                // Get UOM Code
                source.UOMCode = (UOMCode)table[offset];
                // Get Flow
                offset++;
                byte flow = table[offset];
                if (Helper.IsBitSet(flow, 0))
                {
                    source.Flow |= SourceFlow.Q1;
                }
                if (Helper.IsBitSet(flow, 1))
                {
                    source.Flow |= SourceFlow.Q2;
                }
                if (Helper.IsBitSet(flow, 2))
                {
                    source.Flow |= SourceFlow.Q3;
                }
                if (Helper.IsBitSet(flow, 3))
                {
                    source.Flow |= SourceFlow.Q4;
                }
                if (Helper.IsBitSet(flow, 4))
                {
                    source.Flow |= SourceFlow.Delivered;
                }

                //Get Segmentation
                JIBitArray segmentationJibArray = new JIBitArray(new byte[] { flow }).SubJIBitArray(0, 3);
                source.Segmentation = (SourceSegmentation)segmentationJibArray.GetShorts()[0];
                // Get Usage
                offset++;
                byte usage = table[offset];
                if (Helper.IsBitSet(usage, 0))
                {
                    source.Usage |= SourceUsage.BillingSummation;
                }
                if (Helper.IsBitSet(usage, 1))
                {
                    source.Usage |= SourceUsage.BillingDemand;
                }
                if (Helper.IsBitSet(usage, 2))
                {
                    source.Usage |= SourceUsage.Profile;
                }
                if (Helper.IsBitSet(usage, 3))
                {
                    source.Usage |= SourceUsage.PowerQuality;
                }
                if (Helper.IsBitSet(usage, 4))
                {
                    source.Usage |= SourceUsage.WaveForm;
                }
                // Get Harmonic
                offset++;
                JIBitArray harmonicJibArray = new JIBitArray(new byte[] { table[offset] }).SubJIBitArray(2, 6);
                source.Harmonic = (SourceHarmonic)harmonicJibArray.GetShorts()[0];
                // Get Scale Factor
                offset++;
                JIBitArray scaleFactorJibArray = new JIBitArray(new byte[] { table[offset] }).SubJIBitArray(3, 5);
                short      scaleFactor         = 0;
                if (scaleFactorJibArray.Get(0) == true)
                {
                    scaleFactorJibArray = scaleFactorJibArray.Not();
                    scaleFactor         = scaleFactorJibArray.GetShorts()[0];
                    scaleFactor         = (short)(scaleFactor + 1);
                    scaleFactor         = (short)(-1 * scaleFactor);
                }
                source.ScaleFactor      = scaleFactor;
                offset                 += 2;
                source.MultiplierSelect = (int)table[offset];
                Sources.Add(source);
                initial = offset + 1;
            }
        }