Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
HexNcap.cs
1using System;
2using System.Threading.Tasks;
9
11{
15 public class HexNcap : Ncap
16 {
17 private bool firstMessage = true;
18
22 public HexNcap()
23 : base()
24 {
25 }
26
32 public HexNcap(MqttTopic Topic, byte[] Value)
33 : base(Topic, Value)
34 {
35 }
36
43 public override async Task<DataProcessingResult> DataReported(MqttTopic Topic, MqttContent Content)
44 {
45 string s = Content.DataString;
46
47 if (!HexStringData.RegEx.IsMatch(s))
48 return this.firstMessage ? DataProcessingResult.Incompatible : DataProcessingResult.Processed;
49
50 try
51 {
52 this.firstMessage = false;
53 return await this.DataReported(Topic, Content, Hashes.StringToBinary(s));
54 }
55 catch (Exception)
56 {
57 return DataProcessingResult.Processed;
58 }
59 }
60
64 public override Task<string> GetTypeName(Language Language)
65 {
66 return Language.GetStringAsync(typeof(RootTopic), 13, "IEEE 1451.1.6 NCAP (HEX)");
67 }
68
72 public override void SnifferOutput(ICommunicationLayer Output)
73 {
74 }
75
82 public override IMqttData CreateNew(MqttTopic Topic, MqttContent Content)
83 {
84 IMqttData Result = new HexNcap(Topic, default);
85 Result.DataReported(Topic, Content);
86 return Result;
87 }
88 }
89}
Information about content received from the MQTT server.
Definition: MqttContent.cs:9
string DataString
String representation of UTF-8 encoded binary data.
Definition: MqttContent.cs:56
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
Contains methods for simple hash calculations.
Definition: Hashes.cs:59
static byte[] StringToBinary(string s)
Parses a hex string.
Definition: Hashes.cs:102
Hex-encoded IEEE 1451.1.6 NCAP.
Definition: HexNcap.cs:16
HexNcap(MqttTopic Topic, byte[] Value)
Hex-encoded IEEE 1451.1.6 NCAP.
Definition: HexNcap.cs:32
override void SnifferOutput(ICommunicationLayer Output)
Outputs the parsed data to the sniffer.
Definition: HexNcap.cs:72
HexNcap()
Hex-encoded IEEE 1451.1.6 NCAP.
Definition: HexNcap.cs:22
override IMqttData CreateNew(MqttTopic Topic, MqttContent Content)
Creates a new instance of the data.
Definition: HexNcap.cs:82
override async Task< DataProcessingResult > DataReported(MqttTopic Topic, MqttContent Content)
Called when new data has been published.
Definition: HexNcap.cs:43
override Task< string > GetTypeName(Language Language)
Type name representing data.
Definition: HexNcap.cs:64
Abstract base class for IEEE 1451.1.6 NCAPs.
Definition: Ncap.cs:22
IEEE 1451.1.6 root topic node
Definition: RootTopic.cs:13
Represents an MQTT topic with binary data encoded as decimal strings.
static readonly Regex RegEx
Parsed regular expression for hexadecimal string data.
MQTT Topic information.
Definition: MqttTopic.cs:19
Interface for observable classes implementing communication protocols.
Interface for MQTT Data encapsulations
Definition: IMqttData.cs:38
Task< DataProcessingResult > DataReported(MqttTopic Topic, MqttContent Content)
Called when new data has been published.
DataProcessingResult
Results from processing an incoming message.
Definition: IMqttData.cs:17