コード例 #1
0
 /// <summary>
 /// Gets the topic (Except STATE messages).
 /// </summary>
 /// <param name="nameSpace">The namespace.</param>
 /// <param name="groupIdentifier">The group identifier.</param>
 /// <param name="messageType">The message type.</param>
 /// <param name="edgeNodeIdentifier">The edge node identifier.</param>
 /// <param name="deviceIdentifier">The device identifier. (Optional)</param>
 /// <returns>The topic as <see cref="string"/>.</returns>
 public static string GetTopic(
     SparkplugNamespace nameSpace,
     string groupIdentifier,
     SparkplugMessageType messageType,
     string edgeNodeIdentifier,
     string?deviceIdentifier)
 {
     return(string.IsNullOrWhiteSpace(deviceIdentifier)
                ? $"{nameSpace.GetDescription()}/{groupIdentifier}/{messageType.GetDescription()}/{edgeNodeIdentifier}"
                : $"{nameSpace.GetDescription()}/{groupIdentifier}/{messageType.GetDescription()}/{edgeNodeIdentifier}/{deviceIdentifier}");
 }
コード例 #2
0
        /// <summary>
        /// Gets a STATE message.
        /// </summary>
        /// <param name="nameSpace">The namespace.</param>
        /// <param name="scadaHostIdentifier">The SCADA host identifier.</param>
        /// <param name="online">A value indicating whether the message sender is online or not.</param>
        /// <returns>A new STATE <see cref="MqttApplicationMessage"/>.</returns>
        public MqttApplicationMessage GetSparkplugStateMessage(SparkplugNamespace nameSpace, string scadaHostIdentifier, bool online)
        {
            if (!scadaHostIdentifier.IsIdentifierValid())
            {
                throw new ArgumentException(nameof(scadaHostIdentifier));
            }

            return(nameSpace switch
            {
                SparkplugNamespace.VersionA => this.GetSparkplugStateMessageA(scadaHostIdentifier, online),
                SparkplugNamespace.VersionB => this.GetSparkplugStateMessageB(scadaHostIdentifier, online),
                _ => throw new ArgumentOutOfRangeException(nameof(nameSpace))
            });
コード例 #3
0
 /// <inheritdoc cref="SparkplugBase"/>
 /// <summary>
 /// Initializes a new instance of the <see cref="SparkplugNode"/> class.
 /// </summary>
 /// <param name="nameSpace">The namespace.</param>
 /// <seealso cref="SparkplugBase"/>
 public SparkplugNode(SparkplugNamespace nameSpace) : base(nameSpace)
 {
 }
コード例 #4
0
 /// <summary>
 /// Gets the device command subscription topic.
 /// </summary>
 /// <param name="nameSpace">The namespace.</param>
 /// <param name="groupIdentifier">The group identifier.</param>
 /// <param name="edgeNodeIdentifier">The edge node identifier.</param>
 /// <param name="deviceIdentifier">The device identifier.</param>
 /// <returns>The wildcard device command subscription topic <see cref="string"/>.</returns>
 public static string GetDeviceCommandSubscribeTopic(SparkplugNamespace nameSpace, string groupIdentifier, string edgeNodeIdentifier, string deviceIdentifier)
 {
     return($"{nameSpace.GetDescription()}/{groupIdentifier}/{SparkplugMessageType.DeviceCommand.GetDescription()}/{edgeNodeIdentifier}/{deviceIdentifier}");
 }
コード例 #5
0
 /// <summary>
 /// Gets the wildcard namespace subscription topic.
 /// </summary>
 /// <param name="nameSpace">The namespace.</param>
 /// <returns>The wildcard namespace subscription topic <see cref="string"/></returns>
 public static string GetWildcardNamespaceSubscribeTopic(SparkplugNamespace nameSpace)
 {
     return($"{nameSpace.GetDescription()}/#");
 }
コード例 #6
0
 /// <inheritdoc cref="SparkplugBase"/>
 /// <summary>
 /// Initializes a new instance of the <see cref="SparkplugApplication"/> class.
 /// </summary>
 /// <param name="nameSpace">The namespace.</param>
 /// <seealso cref="SparkplugBase"/>
 public SparkplugApplication(SparkplugNamespace nameSpace) : base(nameSpace)
 {
 }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SparkplugBase"/> class.
 /// </summary>
 /// <param name="nameSpace">The namespace.</param>
 public SparkplugBase(SparkplugNamespace nameSpace)
 {
     this.NameSpace = nameSpace;
     this.Client    = new MqttFactory().CreateMqttClient();
 }
コード例 #8
0
 /// <inheritdoc cref="SparkplugBase"/>
 /// <summary>
 /// Initializes a new instance of the <see cref="SparkplugDevice"/> class.
 /// </summary>
 /// <param name="nameSpace">The namespace.</param>
 /// <seealso cref="SparkplugBase"/>
 public SparkplugDevice(SparkplugNamespace nameSpace) : base(nameSpace)
 {
 }