Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ProxyMqttTimTopicNode.cs
1using System.Collections.Generic;
2using System.Text;
3using System.Threading.Tasks;
14
16{
21 {
26 {
27 }
28
32 public override Task<string> GetTypeNameAsync(Language Language)
33 {
34 return Language.GetStringAsync(typeof(Ieee1451Parser), 1, "IEEE 1451.0 Proxy TIM");
35 }
36
40 public override Task<bool> AcceptsParentAsync(INode Parent)
41 {
42 return Task.FromResult(Parent is ProxyMqttNcapTopicNode);
43 }
44
48 public override Task<bool> AcceptsChildAsync(INode Child)
49 {
50 return Task.FromResult(Child is ProxyMqttChannelTopicNode);
51 }
52
58 public override Grade Supports(MqttTopicRepresentation Topic)
59 {
60 return Grade.NotAtAll;
61 }
62
68 {
69 if (!(await this.GetParent() is ProxyMqttNcapTopicNode Parent))
70 return;
71
72 if (!(await Parent.GetParent() is DiscoverableTopicNode GrandParent))
73 return;
74
75 MqttBrokerNode BrokerNode = await GrandParent.GetBroker();
76 if (BrokerNode is null)
77 return;
78
79 MqttBroker Broker = await BrokerNode.GetBroker();
80 if (Broker is null)
81 return;
82
83 string Topic = await GrandParent.GetFullTopic();
84 if (string.IsNullOrEmpty(Topic))
85 return;
86
88 {
89 case DiscoveryService.NCAPTIMTransducerDiscovery:
90 List<ushort> ChannelIds = new List<ushort>();
91 List<string> Names = new List<string>();
92
93 foreach (INode Child in await this.ChildNodes)
94 {
95 if (!(Child is ProxyMqttChannelTopicNode ChannelNode))
96 continue;
97
98 ChannelIds.Add((ushort)ChannelNode.ChannelId);
99 Names.Add(ChannelNode.EntityName);
100 }
101
102 if (ChannelIds.Count == 0)
103 break;
104
105 StringBuilder ToSniffer = BrokerNode.HasSniffers ? new StringBuilder() : null;
106 byte[] Response = DiscoveryMessage.SerializeResponse(0, this.NcapIdBinary, this.TimIdBinary, ChannelIds.ToArray(), Names.ToArray(), ToSniffer);
107
108 if (!(ToSniffer is null))
109 await BrokerNode.Information(ToSniffer.ToString());
110
111 await Broker.Publish(Topic, MqttQualityOfService.AtLeastOnce, false, Response);
112 break;
113 }
114 }
115
124 TedsAccessCode TedsAccessCode, uint TedsOffset, double TimeoutSeconds)
125 {
126 if (!(await this.GetParent() is ProxyMqttNcapTopicNode NcapNode))
127 return;
128
129 if (!(await NcapNode.GetParent() is DiscoverableTopicNode CommunicationNode))
130 return;
131
132 MqttBrokerNode BrokerNode = await CommunicationNode.GetBroker();
133 if (BrokerNode is null)
134 return;
135
136 MqttBroker Broker = await BrokerNode.GetBroker();
137 if (Broker is null)
138 return;
139
140 string Topic = await CommunicationNode.GetFullTopic();
141 if (string.IsNullOrEmpty(Topic))
142 return;
143
144 byte[] Response;
145 StringBuilder ToSniffer;
146
147 switch (TedsAccessCode)
148 {
149 case TedsAccessCode.MetaTEDS:
150 ToSniffer = BrokerNode.HasSniffers ? new StringBuilder() : null;
151 int NrTransducerChannels = 0;
152
153 foreach (INode Child in await this.ChildNodes)
154 {
155 if (Child is ProxyMqttChannelTopicNode)
157 }
158
160 this.TimIdBinary, 0, ToSniffer,
161 new TedsId(99, 255, (byte)TedsAccessCode.MetaTEDS, 2, 1),
162 new Uuid(this.TimIdBinary),
164 break;
165
166 case TedsAccessCode.XdcrName:
167 ToSniffer = BrokerNode.HasSniffers ? new StringBuilder() : null;
169 this.TimIdBinary, 0, ToSniffer,
170 new TedsId(99, 255, (byte)TedsAccessCode.XdcrName, 2, 1),
171 new Format(true),
172 new Ieee1451_0.TEDS.FieldTypes.TransducerNameTeds.Content(this.EntityName));
173 break;
174
175 default:
176 return;
177 }
178
179 if (!(ToSniffer is null))
180 await BrokerNode.Information(ToSniffer.ToString());
181
182 await Broker.Publish(Topic, MqttQualityOfService.AtLeastOnce, false, Response);
183 }
184 }
185}
Contains information about a language.
Definition: Language.cs:17
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Definition: Language.cs:209
static byte[] SerializeResponse(ushort ErrorCode, byte[] NcapId, string Name, StringBuilder SnifferOutput)
Serializes an NCAP discovery response.
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.
TEDS Universal unique identifier (§6.4.2.2)
Definition: Uuid.cs:15
TEDS identification header (§6.3)
Definition: TedsId.cs:14
MQTT Topic node that publishes discovery commands in accordance with IEEE 1451.0.
Topic node representing an IEEE 1451.0 TIM.
Topic node representing a proxy for an IEEE 1451.0 Channel.
Topic node representing an IEEE 1451.0 NCAP Proxy.
Topic node representing an IEEE 1451.0 TIM Proxy.
ProxyMqttTimTopicNode()
Topic node representing an IEEE 1451.0 TIM Proxy.
async Task DiscoveryRequest(DiscoveryMessage DiscoveryMessage)
A request for TEDS data has been received.
override Task< bool > AcceptsChildAsync(INode Child)
If the node accepts a given child.
override Task< string > GetTypeNameAsync(Language Language)
Diaplayable type name for node.
override Grade Supports(MqttTopicRepresentation Topic)
How well the topic node supports an MQTT topic
override Task< bool > AcceptsParentAsync(INode Parent)
If the node accepts a given parent.
async Task TedsRequest(TedsAccessMessage TedsAccessMessage, TedsAccessCode TedsAccessCode, uint TedsOffset, double TimeoutSeconds)
A request for TEDS data has been received.
Static class for IEEE 1451-related parsing tasks.
MQTT Broker connection object.
Definition: MqttBroker.cs:17
Task Publish(string Topic, MqttQualityOfService QoS, bool Retain, byte[] Data)
Publishes binary data to a topic.
Definition: MqttBroker.cs:147
Node representing a connection to an MQTT broker.
Task< MqttBroker > GetBroker()
Gets the corresponding broker node.
async Task Information(string Comment)
Called to inform the viewer of something.
Contains information about an MQTT topic
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
Definition: INode.cs:140
INode Parent
Parent Node, or null if a root node.
Definition: INode.cs:116
Interface for nodes that can be discovered on an IEEE 1451.0 network.
Interface for nodes that can return TEDS.
Definition: ITedsNode.cs:10
Task< INode > GetParent()
Gets the parent of the node.
MqttQualityOfService
MQTT Quality of Service level.
Grade
Grade enumeration
Definition: Grade.cs:7