コード例 #1
0
        /// <summary>
        /// Gets the measurement value.
        /// </summary>
        /// <param name="energyEntry">The energy entry.</param>
        /// <returns></returns>
        private static MeasurementValue GetMeasurementValue(PeriodEntry energyEntry)
        {
            var counterValueUnscaled = Convert.ToInt64(energyEntry.Value);
            var scaler = energyEntry.Scaler;
            double? counterValueScaled = null;
            while (scaler++ < 0)
            {
                counterValueScaled = (double)counterValueUnscaled / 10;
            }

            var mv = new MeasurementValue
            {
                DataValue = counterValueScaled,
                ObisValue = (long)(ulong)energyEntry.Name,
                Unit = string.Format("{0}", energyEntry.Unit),
                ValueSignature = energyEntry.Signature,
                SignatureVerificationStatus = (int)SignatureVerificationResult.Unchecked
            };

            if (mv.ValueSignature != null)
            {
                // TODO: call verification service here
            }

            return mv;
        }
コード例 #2
0
        /// <summary>
        /// Gets the measurement value.
        /// </summary>
        /// <param name="energyEntry">The energy entry.</param>
        /// <param name="serverId">The server id required for ECC signature verification.</param>
        /// <param name="publicKey">The public key required for ECC signature verification.</param>
        /// <returns>
        /// The measurementValue structure based on a SmlListEntry.
        /// </returns>
        private static MeasurementValue GetMeasurementValue(ListEntry energyEntry, byte[] serverId = null, byte[] publicKey = null)
        {
            var counterValueUnscaled = Convert.ToInt64(energyEntry.Value);
            var scaler = energyEntry.Scaler;
            double? counterValueScaled = counterValueUnscaled;
            if (scaler < 0)
            {
                while (scaler++ < 0)
                {
                    counterValueScaled = counterValueScaled / 10;
                }
            }
            else
            {
                while (scaler-- > 0)
                {
                    counterValueScaled = counterValueScaled * 10;
                }
            }

            var mv = new MeasurementValue
               {
                   DataValue = counterValueScaled,
                   ObisValue = (long)(ulong)energyEntry.Name,
                   Unit = string.Format("{0}", energyEntry.Unit),
                   ValueTime = energyEntry.Time != null ? energyEntry.Time.UtcTime : DateTime.MinValue,
                   ValueSignature = energyEntry.Signature,
                   SignatureVerificationStatus = (int)SignatureVerificationResult.Unchecked
               };

            if (energyEntry.Status != null)
            {
                mv.StatusWord = (EdlStatusWord)energyEntry.Status;
            }

            // set an EDL 'invalid timestamp' to C# DateTime = null
            if (mv.ValueTime < new DateTime(1970, 1, 2) || mv.ValueTime > new DateTime(2100, 1, 1))
            {
                mv.ValueTime = null;
            }

            // Check the ECC signature
            if (mv.ValueSignature != null && mv.ValueTime != null && mv.ValueSignature.Length == 50 && publicKey != null && serverId != null)
            {
                //var verificationSvc = new EdlFormDataVerificationService();
                //var bdi = new EdlFormBillingDataItem();
                //bdi.BillingLocalDateTime = mv.ValueTime.Value;
                //bdi.CounterValue = counterValueUnscaled;
                //bdi.CounterValueScaler = scaler.Value;
                //bdi.EventLogCounter =
                //   BitConverter.ToUInt16(
                //      energyEntry.Signature.Skip(48).Take(2).Reverse().ToArray(), 0);
                //bdi.ObisCode = energyEntry.Name.ToArray();
                //bdi.PublicKey = publicKey;
                //bdi.ServerId = serverId;
                //bdi.Signature = mv.ValueSignature.Take(48).ToArray();

                // set result value

                /*mv.SignatureVerificationStatus = (int)(verificationSvc.VerifyFormBillingData(bdi) ?
                                                          SignatureVerificationResult.Valid :
                                                          SignatureVerificationResult.Invalid);*/
            }

            return mv;
        }