示例#1
0
        private void CollectPortInformation(MqttMessage msg)
        {
            if (msg == null || string.IsNullOrEmpty(msg.Topic))
            {
                return;
            }

            if (msg.Topic.StartsWith("/info"))
            {
                if (_info == null)
                {
                    _info = BcInfo.CreateFromMessage(msg);
                }
            }
            else
            {
                _nodes.SyncFromMessage(msg);
            }
        }
示例#2
0
        internal static BcInfo CreateFromMessage(MqttMessage msg)
        {
            // ["/info", {"id": "836d19830d33", "firmware": "bcf-gateway-usb-dongle", "version": "vdev"}]

            if (msg == null && string.IsNullOrEmpty(msg.Payload))
            {
                throw new ArgumentNullException(nameof(msg), "Response message missing or empty message payload");
            }

            JObject data = JsonConvert.DeserializeObject(msg.Payload) as JObject;

            if (!data.ContainsKey("id"))
            {
                throw new BcException("Info response message does not contain ID");
            }

            BcInfo info = BcInfo.CreateFromID(data["id"].ToString());

            info.SyncFromParsedMessage(data);

            return(info);
        }
示例#3
0
 internal static BcNode CreateFormID(string id)
 {
     return(new BcNode {
         Info = BcInfo.CreateFromID(id)
     });
 }