Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Wed Mar 11 08:28:53 2020 +0000
Revision:
132:5b2df69a4f17
Child:
133:98c6bf14bc37
Include TCP monitor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 132:5b2df69a4f17 1 "//Net script\n"
andrewboyson 132:5b2df69a4f17 2 "'use strict';\n"
andrewboyson 132:5b2df69a4f17 3 "\n"
andrewboyson 132:5b2df69a4f17 4 "let mac = '';\n"
andrewboyson 132:5b2df69a4f17 5 "let tcp = '';\n"
andrewboyson 132:5b2df69a4f17 6 "\n"
andrewboyson 132:5b2df69a4f17 7 "function parseTcpLine(line)\n"
andrewboyson 132:5b2df69a4f17 8 "{\n"
andrewboyson 132:5b2df69a4f17 9 " if (line.length == 0) return;\n"
andrewboyson 132:5b2df69a4f17 10 " let fields = line.split('\\t');\n"
andrewboyson 132:5b2df69a4f17 11 " let minutes = parseInt(fields[0], 16) / 1000 / 60;\n"
andrewboyson 132:5b2df69a4f17 12 " let ipType = parseInt(fields[1], 16);\n"
andrewboyson 132:5b2df69a4f17 13 " let arIndex = parseInt(fields[2], 16);\n"
andrewboyson 132:5b2df69a4f17 14 " let locPort = parseInt(fields[3], 16);\n"
andrewboyson 132:5b2df69a4f17 15 " \n"
andrewboyson 132:5b2df69a4f17 16 " \n"
andrewboyson 132:5b2df69a4f17 17 " tcp += Math.floor(minutes).toString().padStart(4, ' ');\n"
andrewboyson 132:5b2df69a4f17 18 " tcp += ' ';\n"
andrewboyson 132:5b2df69a4f17 19 " \n"
andrewboyson 132:5b2df69a4f17 20 " if (ipType == 0x0800) tcp += \"IPv4\"; \n"
andrewboyson 132:5b2df69a4f17 21 " else if (ipType == 0x86DD) tcp += \"IPv6\";\n"
andrewboyson 132:5b2df69a4f17 22 " else tcp += fields[1];\n"
andrewboyson 132:5b2df69a4f17 23 " tcp += ' ';\n"
andrewboyson 132:5b2df69a4f17 24 " \n"
andrewboyson 132:5b2df69a4f17 25 " tcp += arIndex.toString(); \n"
andrewboyson 132:5b2df69a4f17 26 " tcp += ' ';\n"
andrewboyson 132:5b2df69a4f17 27 " \n"
andrewboyson 132:5b2df69a4f17 28 " tcp += locPort.toString(); \n"
andrewboyson 132:5b2df69a4f17 29 " tcp += '\\r\\n';\n"
andrewboyson 132:5b2df69a4f17 30 "}\n"
andrewboyson 132:5b2df69a4f17 31 "function parseTcpLines(text)\n"
andrewboyson 132:5b2df69a4f17 32 "{\n"
andrewboyson 132:5b2df69a4f17 33 " tcp = '';\n"
andrewboyson 132:5b2df69a4f17 34 " text.split('\\n').forEach(parseTcpLine);\n"
andrewboyson 132:5b2df69a4f17 35 "}\n"
andrewboyson 132:5b2df69a4f17 36 "function parseGenLines(text)\n"
andrewboyson 132:5b2df69a4f17 37 "{\n"
andrewboyson 132:5b2df69a4f17 38 " let lines = text.split('\\n');\n"
andrewboyson 132:5b2df69a4f17 39 " mac = Net.makeMac(lines[ 0]);\n"
andrewboyson 132:5b2df69a4f17 40 "}\n"
andrewboyson 132:5b2df69a4f17 41 "function parse()\n"
andrewboyson 132:5b2df69a4f17 42 "{\n"
andrewboyson 132:5b2df69a4f17 43 " let topics = Ajax.response.split('\\f');\n"
andrewboyson 132:5b2df69a4f17 44 " parseGenLines(topics[0]);\n"
andrewboyson 132:5b2df69a4f17 45 " parseTcpLines(topics[1]);\n"
andrewboyson 132:5b2df69a4f17 46 "}\n"
andrewboyson 132:5b2df69a4f17 47 "function display()\n"
andrewboyson 132:5b2df69a4f17 48 "{\n"
andrewboyson 132:5b2df69a4f17 49 " let elem;\n"
andrewboyson 132:5b2df69a4f17 50 "\n"
andrewboyson 132:5b2df69a4f17 51 " elem = Ajax.getElementOrNull('ajax-tcp' ); if (elem) elem.textContent = tcp;\n"
andrewboyson 132:5b2df69a4f17 52 " elem = Ajax.getElementOrNull('ajax-mac' ); if (elem) elem.textContent = mac;\n"
andrewboyson 132:5b2df69a4f17 53 "}\n"
andrewboyson 132:5b2df69a4f17 54 "\n"
andrewboyson 132:5b2df69a4f17 55 "Ajax.server = '/net-ajax';\n"
andrewboyson 132:5b2df69a4f17 56 "Ajax.onResponse = function() { parse(); display(); };\n"
andrewboyson 132:5b2df69a4f17 57 "Ajax.init();\n"
andrewboyson 132:5b2df69a4f17 58 ""