2using System.Collections.Generic;
20 private ushort errorCode;
59 if (!(this.data is
null))
61 ErrorCode = this.errorCode;
72 ErrorCode = this.
NextUInt16(nameof(ErrorCode));
77 List<Field> Fields =
new List<Field>();
87 string FieldName =
"Value";
90 if (!(ChannelTeds is
null))
92 FieldName = ChannelTeds.FieldName ?? FieldName;
94 if (!(PreferredUnit is
null) &&
96 Script.Units.Unit.TryConvert(NumericValue, ChannelTeds.
FieldUnit, NrDecimals, PreferredUnit, out
double ConvertedValue, out
byte NrDec2))
98 NumericValue = ConvertedValue;
112 Fields.Add(
new StringField(Thing, Timestamp,
"Value", Value,
125 if (!(ChannelTeds is
null))
128 this.errorCode = ErrorCode;
146 out
double TimeoutSeconds)
151 SamplingMode = this.NextUInt8<SamplingMode>(nameof(
SamplingMode));
179 using (MemoryStream ms =
new MemoryStream())
183 ms.Write(AppId, 0, 16);
186 ms.WriteByte((
byte)(ChannelId >> 8));
187 ms.WriteByte((
byte)ChannelId);
190 TimeoutSeconds *= 1e9 * 65536;
191 ulong l = (ulong)TimeoutSeconds;
192 byte[] Bin = BitConverter.GetBytes(l);
200 if (!(SnifferOutput is
null))
202 SnifferOutput.Append(
"App ID: ");
204 SnifferOutput.Append(
"NCAP ID: ");
206 SnifferOutput.Append(
"TIM ID: ");
208 SnifferOutput.Append(
"Channel ID: ");
209 SnifferOutput.AppendLine(ChannelId.ToString());
210 SnifferOutput.Append(
"Sampling Mode: ");
212 SnifferOutput.Append(
"Timeout (s): ");
213 SnifferOutput.AppendLine(TimeoutSeconds.ToString());
231 public static byte[]
SerializeResponse(ushort ErrorCode,
byte[] NcapId,
byte[] TimId, ushort ChannelId,
232 string Value, DateTime Timestamp, StringBuilder SnifferOutput)
235 NcapId =
new byte[16];
236 else if (NcapId.Length != 16)
237 throw new ArgumentException(
"Invalid NCAP UUID.", nameof(NcapId));
240 TimId =
new byte[16];
241 else if (TimId.Length != 16)
242 throw new ArgumentException(
"Invalid TIM UUID.", nameof(TimId));
244 using (MemoryStream ms =
new MemoryStream())
248 ms.WriteByte((
byte)(ErrorCode >> 8));
249 ms.WriteByte((
byte)ErrorCode);
250 ms.Write(AppId, 0, 16);
251 ms.Write(NcapId, 0, 16);
252 ms.Write(TimId, 0, 16);
253 ms.WriteByte((
byte)(ChannelId >> 8));
254 ms.WriteByte((
byte)ChannelId);
256 byte[] Bin = Encoding.UTF8.GetBytes(Value);
257 ms.Write(Bin, 0, Bin.Length);
277 if (!(SnifferOutput is
null))
279 SnifferOutput.Append(
"App ID: ");
281 SnifferOutput.Append(
"NCAP ID: ");
283 SnifferOutput.Append(
"TIM ID: ");
285 SnifferOutput.Append(
"Channel ID: ");
286 SnifferOutput.AppendLine(ChannelId.ToString());
287 SnifferOutput.Append(
"Value: ");
288 SnifferOutput.AppendLine(Value);
289 SnifferOutput.Append(
"Timestamp: ");
290 SnifferOutput.AppendLine(Timestamp.ToString());
Helps with parsing of commong data types.
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
override string ToString()
static readonly Unit Empty
Empty unit.
Contains methods for simple hash calculations.
static string BinaryToString(byte[] Data)
Converts an array of bytes to a string with their hexadecimal representations (in lower case).
string NextString(string Name)
Gets the next String.
ICommunicationLayer ComLayer
Sniffable interface on which the message was received.
Time NextTime(string Name)
Gets the next Time.
double NextTimeDurationSeconds(string Name)
Gets the next time duration, expressed in seconds.
ushort NextUInt16(string Name)
Gets the next ushort.
ChannelAddress NextChannelId(bool AppId)
Parses a Channel ID from the message.
static readonly byte[] EmptyUuid
Empty UUID (16 zero bytes)
byte[] Tail
Bytes that are received after the body.
string Unit
Field unit of value, if found, otherwise the empty string.
Unit FieldUnit
Field unit of value, if found, otherwise null.
IEEE 1451.0 Transducer Access Message
bool TryParseTransducerData(ThingReference Thing, Teds ChannelTeds, Unit PreferredUnit, out ushort ErrorCode, out TransducerData Data)
Tries to parse Transducer Data from the message.
TransducerAccessService TransducerAccessService
Transducer Access Service
TransducerAccessMessage(NetworkServiceType NetworkServiceType, TransducerAccessService TransducerAccessService, MessageType MessageType, byte[] Body, byte[] Tail, ICommunicationLayer ComLayer)
IEEE 1451.0 Transducer Access Message
static byte[] SerializeResponse(ushort ErrorCode, byte[] NcapId, byte[] TimId, ushort ChannelId, string Value, DateTime Timestamp, StringBuilder SnifferOutput)
Serializes a request for transducer data.
static byte[] SerializeRequest(byte[] NcapId, byte[] TimId, ushort ChannelId, SamplingMode SamplingMode, double TimeoutSeconds, StringBuilder SnifferOutput)
Serializes a request for transducer data.
bool TryParseRequest(out ChannelAddress Channel, out SamplingMode SamplingMode, out double TimeoutSeconds)
Tries to parse a Transfucer Access request from the message.
override string NetworkServiceIdName
Name of Message.NetworkServiceId
Static class for IEEE 1451-related parsing tasks.
static byte[] SerializeMessage(NetworkServiceType NetworkServiceType, byte NetworkServiceId, MessageType MessageType, byte[] Payload)
Creates a binary IEEE 1451.0 message.
Defines the Metering Topology data source. This data source contains a tree structure of persistent r...
static Root Root
Root node.
Represents a physical quantity value.
Represents a string value.
Contains a reference to a thing
Interface for observable classes implementing communication protocols.
SamplingMode
Sampling Mode
MessageType
Network Service Message Type
TransducerAccessService
Transducer access service
NetworkServiceType
IEEE 1451.0 Network Service Type
FieldQoS
Field Quality of Service flags
FieldType
Field Type flags
Time representation in IEEE 1451.0
DateTime ToDateTime()
Converts the Time structure to a DateTime.
uint NanoSeconds
Nano-seconds