Exemple #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);
            }
        }
        protected override void OnParse(byte[] table)
        {
            int inicial = 1;

            byte[] numberOfValidEntriesArray = new byte[2];
            Array.Copy(table, inicial, numberOfValidEntriesArray, 0, 2);
            Array.Reverse(numberOfValidEntriesArray);
            JIBitArray jb = new JIBitArray(numberOfValidEntriesArray);

            NumberOfValidEntries = jb.GetInt()[0];

            inicial = inicial + 2 + 2 + 4 + 2;

            int offset = inicial;

            for (int i = 0; i < NumberOfValidEntries; i++)
            {
                int year = (int)table[offset];
                offset++;
                int month = (int)table[offset];
                offset++;
                int day = (int)table[offset];
                offset++;
                int hour = (int)table[offset];
                offset++;
                int minutes = (int)table[offset];
                offset++;
                int seconds = (int)table[offset];
                offset++;

                Event ev = new Event
                {
                    DateTime = new DateTime(year, month, day, hour, minutes, seconds)
                };

                byte[] sequenceArray = new byte[2];
                Array.Copy(table, offset, numberOfValidEntriesArray, 0, 2);
                Array.Reverse(sequenceArray);
                JIBitArray jb1 = new JIBitArray(sequenceArray);
                ev.SequenceNumber = jb1.GetInt()[0];
                offset            = offset + 2;

                byte[] userIdArray = new byte[2];
                Array.Copy(table, offset, userIdArray, 0, 2);
                Array.Reverse(userIdArray);
                JIBitArray jb2 = new JIBitArray(userIdArray);
                ev.UserId = jb2.GetInt()[0];
                offset    = offset + 2;

                byte[] eventIdArray = new byte[2];
                Array.Copy(table, offset, eventIdArray, 0, 2);
                Array.Reverse(eventIdArray);
                JIBitArray jb3 = new JIBitArray(eventIdArray);
                ev.EventId = jb3.SubJIBitArray(5, 11).GetInt()[0];
                offset     = offset + 2;

                switch (ev.EventId)
                {
                case 1:
                    ev.Descripcion = "Power down";
                    break;

                case 2:
                    ev.Descripcion = "Power up";
                    break;

                case 3:
                    ev.Descripcion = "Time changed (time stamp = old time)";
                    break;

                case 4:
                    ev.Descripcion = "Time changed (time stamp = new time)";
                    break;

                case 18:
                    ev.Descripcion = "Event log cleared";
                    break;

                case 20:
                    ev.Descripcion = "Demand reset";
                    break;

                case 32:
                    ev.Descripcion = "Test mode start";
                    break;

                case 33:
                    ev.Descripcion = "Test mode exit";
                    break;
                }
                Events.Add(ev);
            }
        }
Exemple #3
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;
            }
        }