Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MqttData.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
11
13{
17 public abstract class MqttData : IMqttData
18 {
22 public MqttData()
23 {
24 this.Topic = new MqttTopic(null, string.Empty, string.Empty, null, null);
25 }
26
32 {
33 this.Topic = Topic;
34 }
35
39 public DateTime Timestamp { get; protected set; } = DateTime.UtcNow;
40
44 public MqttQualityOfService QoS { get; protected set; } = MqttQualityOfService.AtLeastOnce;
45
49 public MqttTopic Topic { get; }
50
54 public bool Retain { get; protected set; }
55
59 public virtual bool IsControllable => false;
60
67 public abstract Task<DataProcessingResult> DataReported(MqttTopic Topic, MqttContent Content);
68
72 public abstract Task<string> GetTypeName(Language Language);
73
81 public abstract Task StartReadout(ThingReference ThingReference, ISensorReadout Request, string Prefix, bool Last);
82
86 public abstract void SnifferOutput(ICommunicationLayer Output);
87
91 public void Information(ICommunicationLayer Output, string Info)
92 {
93 foreach (ISniffer Sniffer in Output.Sniffers)
94 Sniffer.Information(this.Topic.FullTopic + ": " + Info);
95 }
96
100 protected string Append(string Prefix, string Name)
101 {
102 if (string.IsNullOrEmpty(Prefix))
103 return Name;
104
105 if (Name == "Value")
106 return Prefix;
107 else
108 return Prefix + ", " + Name;
109 }
110
114 public void Add(List<Field> Fields, Field Field, ISensorReadout Request)
115 {
116 if (Fields.Count > 50)
117 {
118 Request.ReportFields(false, Fields.ToArray());
119 Fields.Clear();
120 }
121
122 Fields.Add(Field);
123 }
124
129 {
130 return new ControlParameter[0];
131 }
132
138 public Grade Supports(MqttContent Content)
139 {
140 return this.DataReported(null, Content).Result != DataProcessingResult.Incompatible ? this.DefaultSupport : Grade.NotAtAll;
141 }
142
146 public abstract Grade DefaultSupport { get; }
147
154 public abstract IMqttData CreateNew(MqttTopic Topic, MqttContent Content);
155 }
156}
Information about content received from the MQTT server.
Definition: MqttContent.cs:9
Contains information about a language.
Definition: Language.cs:17
Abstract base class for control parameters.
Abstract base class for MQTT data encapsulations.
Definition: MqttData.cs:18
void Information(ICommunicationLayer Output, string Info)
Outputs information to sniffer.
Definition: MqttData.cs:91
MqttData(MqttTopic Topic)
Abstract base class for MQTT data encapsulations.
Definition: MqttData.cs:31
bool Retain
If retain flag was set.
Definition: MqttData.cs:54
abstract Task< string > GetTypeName(Language Language)
Type name representing data.
void Add(List< Field > Fields, Field Field, ISensorReadout Request)
Reports fields during an active readout.
Definition: MqttData.cs:114
virtual ControlParameter[] GetControlParameters()
Gets an array of control parameters
Definition: MqttData.cs:128
abstract Task StartReadout(ThingReference ThingReference, ISensorReadout Request, string Prefix, bool Last)
Starts a readout of the data.
Grade Supports(MqttContent Content)
How well content of a specific type is supported.
Definition: MqttData.cs:138
abstract Grade DefaultSupport
Default support.
Definition: MqttData.cs:146
MqttQualityOfService QoS
Quality of Service used
Definition: MqttData.cs:44
abstract void SnifferOutput(ICommunicationLayer Output)
Outputs the parsed data to the sniffer.
abstract Task< DataProcessingResult > DataReported(MqttTopic Topic, MqttContent Content)
Called when new data has been published.
DateTime Timestamp
Timestamp of data reception.
Definition: MqttData.cs:39
abstract IMqttData CreateNew(MqttTopic Topic, MqttContent Content)
Creates a new instance of the data.
string Append(string Prefix, string Name)
Appends a name to a topic name.
Definition: MqttData.cs:100
MqttData()
Abstract base class for MQTT data encapsulations.
Definition: MqttData.cs:22
virtual bool IsControllable
If data can be controlled (written)
Definition: MqttData.cs:59
MQTT Topic information.
Definition: MqttTopic.cs:19
string FullTopic
Full topic name
Definition: MqttTopic.cs:66
Base class for all sensor data fields.
Definition: Field.cs:20
Contains a reference to a thing
Interface for observable classes implementing communication protocols.
Interface for sniffers. Sniffers can be added to ICommunicationLayer classes to eavesdrop on communic...
Definition: ISniffer.cs:11
Task Information(string Comment)
Called to inform the viewer of something.
Interface for classes managing sensor data readouts.
Task ReportFields(bool Done, params Field[] Fields)
Report read fields to the client.
Interface for MQTT Data encapsulations
Definition: IMqttData.cs:38
MqttQualityOfService
MQTT Quality of Service level.
Grade
Grade enumeration
Definition: Grade.cs:7