4using System.Threading.Tasks;
19 private ushort errorCode;
67 if (!(this.data is
null))
69 ErrorCode = this.errorCode;
77 ErrorCode = this.
NextUInt16(nameof(ErrorCode));
82 uint TedsOffset = this.
NextUInt32(nameof(TedsOffset));
92 if (Len >
int.MaxValue)
102 CheckSum += this.
Body[Start++];
106 ushort CheckSum2 = this.
NextUInt16(nameof(CheckSum));
107 if (CheckChecksum && CheckSum != CheckSum2)
117 this.errorCode = ErrorCode;
144 out uint TedsOffset, out
double TimeoutSeconds)
149 TedsAccessCode = this.NextUInt8<TedsAccessCode>(nameof(
TedsAccessCode));
150 TedsOffset = this.
NextUInt32(nameof(TedsOffset));
180 using (MemoryStream ms =
new MemoryStream())
184 ms.Write(AppId, 0, 16);
187 ms.WriteByte((
byte)(ChannelId >> 8));
188 ms.WriteByte((
byte)ChannelId);
191 byte[] Bin = BitConverter.GetBytes(TedsOffset);
195 TimeoutSeconds *= 1e9 * 65536;
196 ulong l = (ulong)TimeoutSeconds;
197 Bin = BitConverter.GetBytes(l);
203 if (!(SnifferOutput is
null))
205 SnifferOutput.Append(
"App ID: ");
207 SnifferOutput.Append(
"NCAP ID: ");
209 SnifferOutput.Append(
"TIM ID: ");
211 SnifferOutput.Append(
"Channel ID: ");
212 SnifferOutput.AppendLine(ChannelId.ToString());
213 SnifferOutput.Append(
"TEDS Access Code: ");
215 SnifferOutput.Append(
"TEDS Offset: ");
216 SnifferOutput.AppendLine(TedsOffset.ToString());
217 SnifferOutput.Append(
"Timeout (s): ");
218 SnifferOutput.AppendLine(TimeoutSeconds.ToString());
237 ushort ChannelId, StringBuilder SnifferOutput,
TedsId TedsHeader, params
TedsRecord[] Records)
240 NcapId =
new byte[16];
241 else if (NcapId.Length != 16)
242 throw new ArgumentException(
"Invalid NCAP UUID.", nameof(NcapId));
245 TimId =
new byte[16];
246 else if (TimId.Length != 16)
247 throw new ArgumentException(
"Invalid TIM UUID.", nameof(TimId));
249 using (MemoryStream ms =
new MemoryStream())
253 ms.WriteByte((
byte)(ErrorCode >> 8));
254 ms.WriteByte((
byte)ErrorCode);
255 ms.Write(AppId, 0, 16);
256 ms.Write(NcapId, 0, 16);
257 ms.Write(TimId, 0, 16);
258 ms.WriteByte((
byte)(ChannelId >> 8));
259 ms.WriteByte((
byte)ChannelId);
265 using (MemoryStream ms2 =
new MemoryStream())
267 Append(ms2, TedsHeader);
272 byte[] Bin = ms2.ToArray();
273 int Len = Bin.Length;
280 for (i = 0; i < 4; i++)
289 for (i = 0; i < 4; i++)
291 ms.WriteByte((
byte)k);
297 ms.Write(Bin, 0, Len);
299 for (i = 0; i < Len; i++)
305 ms.WriteByte((
byte)(Checksum >> 8));
306 ms.WriteByte((
byte)Checksum);
310 if (!(SnifferOutput is
null))
312 SnifferOutput.Append(
"Error Code: ");
313 SnifferOutput.AppendLine(ErrorCode.ToString());
314 SnifferOutput.Append(
"App ID: ");
316 SnifferOutput.Append(
"NCAP ID: ");
318 SnifferOutput.Append(
"TIM ID: ");
320 SnifferOutput.Append(
"Channel ID: ");
321 SnifferOutput.AppendLine(ChannelId.ToString());
322 SnifferOutput.AppendLine(
"TEDS Offset: 0");
324 TedsHeader.
Append(SnifferOutput);
327 Record.
Append(SnifferOutput);
329 SnifferOutput.AppendLine(Checksum.ToString());
330 SnifferOutput.AppendLine(
"TEDS Offset: 0");
338 private static void Append(MemoryStream ms2,
TedsRecord Record)
341 int RecordLen = Bin?.Length ?? 0;
343 throw new Exception(
"Record length exceeds 255 bytes in length.");
345 ms2.WriteByte(Record.
Type);
346 ms2.WriteByte((
byte)RecordLen);
349 ms2.Write(Bin, 0, RecordLen);
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).
IEEE 1451.0 Binary object
void LogInformationToSniffer()
Logs accumulated sniffer output to associated sniffable interface.
bool HasSniffers
If sniffers are available.
int Position
Current position.
ICommunicationLayer ComLayer
Sniffable interface on which the message was received.
uint NextUInt32(string Name)
Gets the next uint.
TedsRecord[] ParseTedsRecords(ParsingState State)
Parses a set of TEDS records.
byte[] NextUInt8Array(string Name)
Gets the next Byte array
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.
IEEE 1451.0 TEDS Access Message
TedsAccessMessage(NetworkServiceType NetworkServiceType, TedsAccessService TedsAccessService, MessageType MessageType, byte[] Body, byte[] Tail, ICommunicationLayer ComLayer)
IEEE 1451.0 TEDS Access Message
override string NetworkServiceIdName
Name of Message.NetworkServiceId
bool TryParseTeds(bool CheckChecksum, out ushort ErrorCode, out Teds Teds)
Tries to parse a TEDS from the message.
static byte[] SerializeRequest(byte[] NcapId, byte[] TimId, ushort ChannelId, TedsAccessCode TedsAccessCode, uint TedsOffset, double TimeoutSeconds, StringBuilder SnifferOutput)
Serializes a request for TEDS.
static byte[] SerializeResponse(ushort ErrorCode, byte[] NcapId, byte[] TimId, ushort ChannelId, StringBuilder SnifferOutput, TedsId TedsHeader, params TedsRecord[] Records)
Serializes a response to a TEDS request.
bool TryParseRequest(out ChannelAddress Channel, out TedsAccessCode TedsAccessCode, out uint TedsOffset, out double TimeoutSeconds)
Tries to parse a TEDS request from the message.
bool TryParseTeds(out ushort ErrorCode, out Teds Teds)
Tries to parse a TEDS from the message.
TedsAccessService TedsAccessService
TEDS Access Service
Contains parsing information.
TEDS identification header (§6.3)
Represents one record in a TEDS
byte[] RawValue
TEDS Raw Record value
byte Type
TEDS Record Type
void Append(StringBuilder SnifferOutput)
Appends record to sniffer output.
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.
void Exception(string Exception)
Called to inform the viewer of an exception state.
Interface for observable classes implementing communication protocols.
TedsAccessCode
TEDS Access Code
MessageType
Network Service Message Type
NetworkServiceType
IEEE 1451.0 Network Service Type
TedsAccessService
TEDS Access Service