示例#1
0
        protected static DataPointValue ParseDataPoint(Stream inputStream, MetaFrame meta, ushort index)
        {
            if (index > meta.FieldMetaDataList.Count - 1)
            {
                throw new Exception("Decode DeltaFrame: Could not parse field as corresponding meta data is not present");
            }

            // Value
            FieldMetaData metaData = meta.FieldMetaDataList[index];

            if (metaData.Index != index)
            {
                Logger.Error($"Index does not match: FieldMetaData.Index {metaData.Index} != {index} read from Stream.");
            }
            if (Logger.IsDebugEnabled)
            {
                Logger.Debug($"Decoding item at position {index} in Meta Frame. Using FieldMetaData:");
                Logger.Debug(metaData);
            }
            DataPointValue item = null;

            if (metaData.DataType == File.PreDefinedNodeID)
            {
                item = new File();
                item.Decode(inputStream);
            }
            else
            {
                item            = ProcessValueFactory.CreateValue(metaData.DataType);
                item.Properties = metaData.Properties;
                if (meta.StructureDataTypes.TryGetValue(metaData.DataType, out StructureDescription desc))
                {
                    if (meta.EnumDataTypes != null &&
                        desc.Name.Name.ToString()
                        .Contains("EnumValue", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string enumName = desc.Name.Name.Value
                                          .Substring(10);
                        item.EnumDescription = meta.EnumDataTypes.First(s => s.Value.Name.Name.Value == enumName)
                                               .Value;
                    }
                    item.Decode(inputStream);
                }
            }

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (item == null)
            {
                Logger.Error($"Unable to decode value {metaData.DataType} at position {index} in message.");
                return(null);
            }
            item.Name       = metaData.Name.Value;
            item.Properties = metaData.Properties;
            item.Index      = index;
            return(item);
        }
示例#2
0
        internal static DataPointValue GetDataPointValue(DeltaEntry keyEntry, DataSetType dataSetType)
        {
            ProcessDataPointValue dpv = ProcessValueFactory.CreateValue(keyEntry.DataType);

            if (dpv == null)
            {
                Logger.Error($"Unable to create DataPoint for entry: {keyEntry}");
                return(null);
            }
            dpv.Orcat     = keyEntry.Orcat;
            dpv.Quality   = keyEntry.Quality;
            dpv.Timestamp = keyEntry.TimeStamp;
            dpv.Value     = keyEntry.Value;
            if (keyEntry is KeyEntry key)
            {
                dpv.Prefix  = key.Prefix;
                dpv.Unit    = key.Unit;
                dpv.FieldID = key.FieldID;
            }
            if (dpv is CounterValue)
            {
                dpv.SetAttributeValue(CounterValue.QuantityAttributeName, keyEntry.Value2);
            }
            if (dpv is StepPosValue || dpv is StepPosEvent)
            {
                dpv.SetAttributeValue(StepPosValue.TransientAttributeName, keyEntry.Value2);
            }
            if (dpv is ComplexMeasuredValue)
            {
                dpv.SetAttributeValue(ComplexMeasuredValue.AngleAttributeName, keyEntry.Value2);
            }
            if (dpv.Timestamp == 0)
            {
                dpv.Timestamp = DateTime.Now.ToFileTimeUtc();
            }
            return(dpv);
        }