示例#1
0
        static void ParseMessagePayload(DateTime dt, string topic, byte[] payload, IMQTTDecoderRegistry decoders)
        {
            string[] topicPath = topic.Split('/');
            var      node      = topicPath[0];
            var      path      = String.Join("/", topicPath, 1, topicPath.Length - 1);

            var hex       = MQTTDecoder.PayloadToHex(payload);
            var timestamp = dt.ToString("yyyy-MM-ddTHH:mm:ssZ");

            var logstring = $"{timestamp}\t{node}\t{path}\t{hex}";

            Console.WriteLine(logstring);

            if (node == "application" && path.Contains("/device/"))
            {
                if (path.EndsWith("/event/up") || path.EndsWith("/event/error") || path.EndsWith("/event/status"))
                {
                    var parts = path.Split("/", 10);
                    node = parts[parts.Length - 3];
                    path = $"/event/{parts[parts.Length-1]}";
                }
            }
            else if (node.StartsWith("node_"))
            {
                node = node.Substring(5);
            }

            IMQTTDecoder decoder = decoders.GetDecoderForNode(node, path);

            decoder.Decode(timestamp, node, path, payload);
        }
示例#2
0
 static void TestParseData(IMQTTDecoderRegistry decoders)
 {
     string[] lines = System.IO.File.ReadAllLines(@" <enter path here> ");
     foreach (var line in lines)
     {
         string[] parts = line.Split('\t');
         if (parts.Length == 4)
         {
             string   timestamp = parts[0];
             string   topic     = parts[1] + "/" + parts[2];
             DateTime dt        = DateTime.Parse(timestamp);
             ParseMessagePayload(dt, topic, ParseHex(parts[3]), decoders);
         }
     }
 }