3using System.Text.RegularExpressions;
4using System.Threading.Tasks;
23 public static readonly Regex
RegEx =
new Regex(
@"^(?'Magnitude'[+-]?\d*([.]\d*)?([eE][+-]?\d+)?)\s+(?'Unit'[^\s]+)$", RegexOptions.Compiled | RegexOptions.Singleline);
27 private byte nrDecimals;
48 this.nrDecimals = NrDecimals;
61 Match M =
RegEx.Match(s);
62 if (M.Success &&
CommonTypes.
TryParse(M.Groups[
"Magnitude"].Value, out
this.value, out
this.nrDecimals))
64 this.unit = M.Groups[
"Unit"].Value;
65 this.Timestamp = DateTime.UtcNow;
93 this.value, this.nrDecimals, this.unit,
FieldType.Momentary,
FieldQoS.AutomaticReadout));
94 return Task.CompletedTask;
110 (n) => Task.FromResult<
double?>(
this.value),
114 this.Topic.MqttClient.PUBLISH(this.Topic.FullTopic, this.QoS, this.Retain, Encoding.UTF8.GetBytes(CommonTypes.Encode(v, this.nrDecimals) +
" " + this.unit));
115 return Task.CompletedTask;
125 this.
Information(Output, this.value.ToString(
"F" +
this.nrDecimals.ToString()) +
" " +
this.unit);
Helps with parsing of commong data types.
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Information about content received from the MQTT server.
string DataString
String representation of UTF-8 encoded binary data.
MqttHeader Header
MQTT Header
Contains information about a language.
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 ...
Abstract base class for control parameters.
Double control parameter.
Abstract base class for MQTT data encapsulations.
void Information(ICommunicationLayer Output, string Info)
Outputs information to sniffer.
MqttTopic Topic
Topic used
DateTime Timestamp
Timestamp of data reception.
string Append(string Prefix, string Name)
Appends a name to a topic name.
Represents an MQTT topic with Physical Quantity data.
override bool IsControllable
TODO
override Task< string > GetTypeName(Language Language)
Type name representing data.
QuantityData(MqttTopic Topic, double Value, byte NrDecimals, string Unit)
Represents an MQTT topic with Physical Quantity data.
override IMqttData CreateNew(MqttTopic Topic, MqttContent Content)
Creates a new instance of the data.
static readonly Regex RegEx
TODO
QuantityData()
Represents an MQTT topic with Physical Quantity data.
override void SnifferOutput(ICommunicationLayer Output)
Outputs the parsed data to the sniffer.
override ControlParameter[] GetControlParameters()
TODO
override Task StartReadout(ThingReference ThingReference, ISensorReadout Request, string Prefix, bool Last)
Starts a readout of the data.
override Task< DataProcessingResult > DataReported(MqttTopic Topic, MqttContent Content)
Called when new data has been published.
override Grade DefaultSupport
Default support.
A Metering node representing an MQTT topic
Represents a physical quantity value.
Contains a reference to a thing
Interface for observable classes implementing communication protocols.
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
Task< DataProcessingResult > DataReported(MqttTopic Topic, MqttContent Content)
Called when new data has been published.
DataProcessingResult
Results from processing an incoming message.
FieldQoS
Field Quality of Service flags
FieldType
Field Type flags