48 using (MemoryStream ms =
new MemoryStream())
51 ms.Write(AppId, 0, 16);
55 if (!(SnifferOutput is
null))
57 SnifferOutput.Append(
"App ID: ");
73 if (NcapId is
null || NcapId.Length != 16)
74 throw new ArgumentException(
"Invalid NCAP UUID.", nameof(NcapId));
76 using (MemoryStream ms =
new MemoryStream())
80 ms.Write(AppId, 0, 16);
81 ms.Write(NcapId, 0, 16);
85 if (!(SnifferOutput is
null))
87 SnifferOutput.Append(
"App ID: ");
89 SnifferOutput.Append(
"NCAP ID: ");
104 public static byte[]
SerializeRequest(
byte[] NcapId,
byte[] TimId, StringBuilder SnifferOutput)
106 if (NcapId is
null || NcapId.Length != 16)
107 throw new ArgumentException(
"Invalid NCAP UUID.", nameof(NcapId));
109 if (TimId is
null || TimId.Length != 16)
110 throw new ArgumentException(
"Invalid TIM UUID.", nameof(TimId));
112 using (MemoryStream ms =
new MemoryStream())
116 ms.Write(AppId, 0, 16);
117 ms.Write(NcapId, 0, 16);
118 ms.Write(TimId, 0, 16);
122 if (!(SnifferOutput is
null))
124 SnifferOutput.Append(
"App ID: ");
126 SnifferOutput.Append(
"NCAP ID: ");
128 SnifferOutput.Append(
"TIM ID: ");
145 string Name, StringBuilder SnifferOutput)
147 if (NcapId is
null || NcapId.Length != 16)
148 throw new ArgumentException(
"Invalid NCAP UUID.", nameof(NcapId));
150 using (MemoryStream ms =
new MemoryStream())
154 ms.WriteByte((
byte)(ErrorCode >> 8));
155 ms.WriteByte((
byte)ErrorCode);
156 ms.Write(AppId, 0, 16);
157 ms.Write(NcapId, 0, 16);
159 byte[] Bin = Encoding.UTF8.GetBytes(Name);
160 ms.Write(Bin, 0, Bin.Length);
170 if (!(SnifferOutput is
null))
172 SnifferOutput.Append(
"Error Code: ");
173 SnifferOutput.AppendLine(ErrorCode.ToString());
174 SnifferOutput.Append(
"App ID: ");
176 SnifferOutput.Append(
"NCAP ID: ");
178 SnifferOutput.Append(
"Name: ");
179 SnifferOutput.AppendLine(Name);
180 SnifferOutput.AppendLine(
"IPv4: 127.0.0.1");
197 byte[][] TimIds,
string[] TimNames, StringBuilder SnifferOutput)
199 if (NcapId is
null || NcapId.Length != 16)
200 throw new ArgumentException(
"Invalid NCAP UUID.", nameof(NcapId));
202 if (TimIds is
null || TimIds.Length == 0)
203 throw new ArgumentException(
"No TIM IDs.", nameof(TimIds));
205 int i, c = TimIds.Length;
206 if (TimNames.Length != c)
207 throw new ArgumentException(
"Invalid number of TIM names.", nameof(TimNames));
209 for (i = 0; i < c; i++)
211 if (TimIds[i] is
null || TimIds[i].Length != 16)
212 throw new ArgumentException(
"Invalid TIM UUID.", nameof(TimIds));
215 using (MemoryStream ms =
new MemoryStream())
219 ms.WriteByte((
byte)(ErrorCode >> 8));
220 ms.WriteByte((
byte)ErrorCode);
221 ms.Write(AppId, 0, 16);
222 ms.Write(NcapId, 0, 16);
224 ms.WriteByte((
byte)(c >> 8));
225 ms.WriteByte((
byte)c);
227 for (i = 0; i < c; i++)
228 ms.Write(TimIds[i], 0, 16);
230 for (i = 0; i < c; i++)
232 byte[] Bin = Encoding.UTF8.GetBytes(TimNames[i]);
233 ms.Write(Bin, 0, Bin.Length);
239 if (!(SnifferOutput is
null))
241 SnifferOutput.Append(
"Error Code: ");
242 SnifferOutput.AppendLine(ErrorCode.ToString());
243 SnifferOutput.Append(
"App ID: ");
245 SnifferOutput.Append(
"NCAP ID: ");
248 for (i = 0; i < c; i++)
250 SnifferOutput.Append(
"TIM ID ");
251 SnifferOutput.Append((i + 1).ToString());
252 SnifferOutput.Append(
": ");
256 for (i = 0; i < c; i++)
258 SnifferOutput.Append(
"TIM Name ");
259 SnifferOutput.Append((i + 1).ToString());
260 SnifferOutput.Append(
": ");
261 SnifferOutput.AppendLine(TimNames[i]);
280 byte[] TimId, ushort[] ChannelIds,
string[] ChannelNames, StringBuilder SnifferOutput)
282 if (NcapId is
null || NcapId.Length != 16)
283 throw new ArgumentException(
"Invalid NCAP UUID.", nameof(NcapId));
285 if (TimId is
null || TimId.Length != 16)
286 throw new ArgumentException(
"Invalid TIM UUID.", nameof(TimId));
288 if (ChannelIds is
null || ChannelIds.Length == 0)
289 throw new ArgumentException(
"No Transducer channel IDs.", nameof(ChannelIds));
291 int i, c = ChannelIds.Length;
292 if (ChannelNames.Length != c)
293 throw new ArgumentException(
"Invalid number of Transducer channel names.", nameof(ChannelNames));
295 using (MemoryStream ms =
new MemoryStream())
299 ms.WriteByte((
byte)(ErrorCode >> 8));
300 ms.WriteByte((
byte)ErrorCode);
301 ms.Write(AppId, 0, 16);
302 ms.Write(NcapId, 0, 16);
303 ms.Write(TimId, 0, 16);
305 ms.WriteByte((
byte)(c >> 8));
306 ms.WriteByte((
byte)c);
308 for (i = 0; i < c; i++)
310 ushort ChannelId = ChannelIds[i];
312 ms.WriteByte((
byte)(ChannelId >> 8));
313 ms.WriteByte((
byte)ChannelId);
316 for (i = 0; i < c; i++)
318 byte[] Bin = Encoding.UTF8.GetBytes(ChannelNames[i]);
319 ms.Write(Bin, 0, Bin.Length);
325 if (!(SnifferOutput is
null))
327 SnifferOutput.Append(
"Error Code: ");
328 SnifferOutput.AppendLine(ErrorCode.ToString());
329 SnifferOutput.Append(
"App ID: ");
331 SnifferOutput.Append(
"NCAP ID: ");
333 SnifferOutput.Append(
"TIM ID: ");
336 for (i = 0; i < c; i++)
338 SnifferOutput.Append(
"Channel ID ");
339 SnifferOutput.Append((i + 1).ToString());
340 SnifferOutput.Append(
": ");
341 SnifferOutput.AppendLine(ChannelIds[i].ToString());
344 for (i = 0; i < c; i++)
346 SnifferOutput.Append(
"Channel Name ");
347 SnifferOutput.Append((i + 1).ToString());
348 SnifferOutput.Append(
": ");
349 SnifferOutput.AppendLine(ChannelNames[i]);
398 ErrorCode = this.
NextUInt16(nameof(ErrorCode));
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).
ushort[] NextUInt16Array(string Name)
Gets the next UInt16 array
string[] NextStringArray(string Name, int NrItems)
Gets the next string array
string NextString(string Name)
Gets the next String.
ICommunicationLayer ComLayer
Sniffable interface on which the message was received.
byte[] NextUInt8Array(string Name)
Gets the next Byte array
byte[][] NextUuidArray(string Name)
Gets the next UUID array
ushort NextUInt16(string Name)
Gets the next ushort.
Discovery data about a collection of channels.
Discovery data about a collection of entities.
Discovery data about a single entity.
Discovery data about a single NCAP.
IEEE 1451.0 Discovery Message
static byte[] SerializeRequest(StringBuilder SnifferOutput)
Serializes an NCAP Discovery request.
static byte[] SerializeRequest(byte[] NcapId, byte[] TimId, StringBuilder SnifferOutput)
Serializes an NCAP TIM Transducer Discovery request.
DiscoveryService DiscoveryService
Discovery Service
static byte[] SerializeResponse(ushort ErrorCode, byte[] NcapId, string Name, StringBuilder SnifferOutput)
Serializes an NCAP discovery response.
static byte[] SerializeRequest(byte[] NcapId, StringBuilder SnifferOutput)
Serializes an NCAP TIM Discovery request.
static byte[] SerializeResponse(ushort ErrorCode, byte[] NcapId, byte[][] TimIds, string[] TimNames, StringBuilder SnifferOutput)
Serializes a TIM discovery response.
override string NetworkServiceIdName
Name of Message.NetworkServiceId
DiscoveryMessage(NetworkServiceType NetworkServiceType, DiscoveryService DiscoveryService, MessageType MessageType, byte[] Body, byte[] Tail, ICommunicationLayer ComLayer)
IEEE 1451.0 Discovery Message
static byte[] SerializeResponse(ushort ErrorCode, byte[] NcapId, byte[] TimId, ushort[] ChannelIds, string[] ChannelNames, StringBuilder SnifferOutput)
Serializes a Transducer channel discovery response.
bool TryParseMessage(out ushort ErrorCode, out DiscoveryData Data)
Tries to parse a Discovery message.
ChannelAddress NextTimId(bool AppId)
Parses an TIM ID from the message.
ChannelAddress NextAppId()
Parses an Application ID from the message.
ChannelAddress NextChannelId(bool AppId)
Parses a Channel ID from the message.
byte[] Tail
Bytes that are received after the body.
ChannelAddress NextNcapId(bool AppId)
Parses an NCAP ID from the message.
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.
Interface for observable classes implementing communication protocols.
AddressType
NCAP address type.
DiscoveryService
Discovery Service
MessageType
Network Service Message Type
NetworkServiceType
IEEE 1451.0 Network Service Type