Skip to content

Commit

Permalink
Improve logparser compatibility (#1469)
Browse files Browse the repository at this point in the history
Co-authored-by: Jens Jensen <[email protected]>
  • Loading branch information
zerog2k and Jens Jensen authored Mar 20, 2021
1 parent 05fe075 commit dc562a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Logparser/logparser.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<link rel="stylesheet" href="logparser.css" />
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.12/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.12.0/underscore-min.js"></script>
<div id="parser">
<h4>Paste log from gateway or node here:</h4>
<textarea class="form-control" @change="parse" rows="10" v-model="source"></textarea>
Expand All @@ -25,8 +25,8 @@ <h4>Human readable output:</h4>
<th>Payload</th>
<th>Description</th>
</tr>
<tr v-for="r in parsed">
<td v-for="c in r" v-html="c"></td>
<tr style="font-family: monospace;" v-for="row in parsed">
<td v-for="col in row" v-html="col"></td>
</tr>
</table>
</div>
Expand Down
27 changes: 18 additions & 9 deletions Logparser/logparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ var types = {

//mysgw: Client 0: 0;0;3;0;18;PING
var rprefix = "(?:\\d+ )?(?:mysgw: )?(?:Client 0: )?";
var prefilter = /(?=[!?]?(MCO|TSM|TSF|THA|SGN))(?<result>.*)/;
var match = [

// MySensors core
Expand Down Expand Up @@ -460,8 +461,9 @@ var match = [

// Init regexes
for (var i=0, len=match.length;i<len; i++) {
match[i].re = new RegExp("^" + rprefix + match[i].re);
match[i].re = new RegExp("^" + match[i].re);
}

var stripPrefix = new RegExp("^" + rprefix + "(.*)");

function getQueryVariable(variable)
Expand Down Expand Up @@ -538,18 +540,25 @@ new Vue({
var t = types[this.selector(cmd)]
return t !== undefined ? t[type] || "Undefined" : "Undefined";
},
match: function(msg) {
decodeLog: function(msg) {
var self = this;
var found = false;

filtered = msg.match(prefilter);
if (filtered) {
msg = filtered.groups.result;
} else {
return;
}
for (var i=0, len=match.length;!found && i<len; i++) {
var r = match[i];
if (r.re.test(msg)) {
msg = msg.replace(r.re, r.d);
// lookup and replace numerical constants with their symbols
msg = msg.replace(/{command:(\d+)}/g, function(match, m1) { return types.command[m1] });
msg = msg.replace(/{pt:(\d+)}/g, function(match, m1) { return types.payloadtype[m1] });
return msg.replace(/{type:(\d+):(\d+)}/g, function(match, cmd, type) {
return self.type(cmd, type);
});
msg = msg.replace(/{type:(\d+):(\d+)}/g, function(match, cmd, type) { return self.type(cmd, type) });
return msg;
}
}
},
Expand All @@ -558,17 +567,17 @@ new Vue({
var self = this;
var rows = this.source.split("\n");
this.parsed = _.map(rows, function(r) {
//var p = r.split(";");
// attempt decode of serial protocol (e.g. `12;6;0;0;3;My Light\n`)
var p = splitWithTail(r, ";", 6);
if (p.length !== 6) {
var desc = self.match(r);

// probably not serial protocol, maybe debug log?
var desc = self.decodeLog(r);
return ["","","","",desc?"":"Unknown", r, desc];
}
var sel = self.selector(p[2]);
var desc = "";
if (p[2] == "3" && p[4] == "9") {
desc = self.match(p[5]);
desc = self.decodeLog(p[5]);

}
var node = stripPrefix.exec(p[0]);
Expand Down

0 comments on commit dc562a2

Please sign in to comment.