Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
base/net/web-net-script.js@132:5b2df69a4f17, 2020-03-11 (annotated)
- 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?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andrewboyson | 132:5b2df69a4f17 | 1 | //Net script |
| andrewboyson | 132:5b2df69a4f17 | 2 | 'use strict'; |
| andrewboyson | 132:5b2df69a4f17 | 3 | |
| andrewboyson | 132:5b2df69a4f17 | 4 | let mac = ''; |
| andrewboyson | 132:5b2df69a4f17 | 5 | let tcp = ''; |
| andrewboyson | 132:5b2df69a4f17 | 6 | |
| andrewboyson | 132:5b2df69a4f17 | 7 | function parseTcpLine(line) |
| andrewboyson | 132:5b2df69a4f17 | 8 | { |
| andrewboyson | 132:5b2df69a4f17 | 9 | if (line.length == 0) return; |
| andrewboyson | 132:5b2df69a4f17 | 10 | let fields = line.split('\t'); |
| andrewboyson | 132:5b2df69a4f17 | 11 | let minutes = parseInt(fields[0], 16) / 1000 / 60; |
| andrewboyson | 132:5b2df69a4f17 | 12 | let ipType = parseInt(fields[1], 16); |
| andrewboyson | 132:5b2df69a4f17 | 13 | let arIndex = parseInt(fields[2], 16); |
| andrewboyson | 132:5b2df69a4f17 | 14 | let locPort = parseInt(fields[3], 16); |
| andrewboyson | 132:5b2df69a4f17 | 15 | |
| andrewboyson | 132:5b2df69a4f17 | 16 | |
| andrewboyson | 132:5b2df69a4f17 | 17 | tcp += Math.floor(minutes).toString().padStart(4, ' '); |
| andrewboyson | 132:5b2df69a4f17 | 18 | tcp += ' '; |
| andrewboyson | 132:5b2df69a4f17 | 19 | |
| andrewboyson | 132:5b2df69a4f17 | 20 | if (ipType == 0x0800) tcp += "IPv4"; |
| andrewboyson | 132:5b2df69a4f17 | 21 | else if (ipType == 0x86DD) tcp += "IPv6"; |
| andrewboyson | 132:5b2df69a4f17 | 22 | else tcp += fields[1]; |
| andrewboyson | 132:5b2df69a4f17 | 23 | tcp += ' '; |
| andrewboyson | 132:5b2df69a4f17 | 24 | |
| andrewboyson | 132:5b2df69a4f17 | 25 | tcp += arIndex.toString(); |
| andrewboyson | 132:5b2df69a4f17 | 26 | tcp += ' '; |
| andrewboyson | 132:5b2df69a4f17 | 27 | |
| andrewboyson | 132:5b2df69a4f17 | 28 | tcp += locPort.toString(); |
| andrewboyson | 132:5b2df69a4f17 | 29 | tcp += '\r\n'; |
| andrewboyson | 132:5b2df69a4f17 | 30 | } |
| andrewboyson | 132:5b2df69a4f17 | 31 | function parseTcpLines(text) |
| andrewboyson | 132:5b2df69a4f17 | 32 | { |
| andrewboyson | 132:5b2df69a4f17 | 33 | tcp = ''; |
| andrewboyson | 132:5b2df69a4f17 | 34 | text.split('\n').forEach(parseTcpLine); |
| andrewboyson | 132:5b2df69a4f17 | 35 | } |
| andrewboyson | 132:5b2df69a4f17 | 36 | function parseGenLines(text) |
| andrewboyson | 132:5b2df69a4f17 | 37 | { |
| andrewboyson | 132:5b2df69a4f17 | 38 | let lines = text.split('\n'); |
| andrewboyson | 132:5b2df69a4f17 | 39 | mac = Net.makeMac(lines[ 0]); |
| andrewboyson | 132:5b2df69a4f17 | 40 | } |
| andrewboyson | 132:5b2df69a4f17 | 41 | function parse() |
| andrewboyson | 132:5b2df69a4f17 | 42 | { |
| andrewboyson | 132:5b2df69a4f17 | 43 | let topics = Ajax.response.split('\f'); |
| andrewboyson | 132:5b2df69a4f17 | 44 | parseGenLines(topics[0]); |
| andrewboyson | 132:5b2df69a4f17 | 45 | parseTcpLines(topics[1]); |
| andrewboyson | 132:5b2df69a4f17 | 46 | } |
| andrewboyson | 132:5b2df69a4f17 | 47 | function display() |
| andrewboyson | 132:5b2df69a4f17 | 48 | { |
| andrewboyson | 132:5b2df69a4f17 | 49 | let elem; |
| andrewboyson | 132:5b2df69a4f17 | 50 | |
| andrewboyson | 132:5b2df69a4f17 | 51 | elem = Ajax.getElementOrNull('ajax-tcp' ); if (elem) elem.textContent = tcp; |
| andrewboyson | 132:5b2df69a4f17 | 52 | elem = Ajax.getElementOrNull('ajax-mac' ); if (elem) elem.textContent = mac; |
| andrewboyson | 132:5b2df69a4f17 | 53 | } |
| andrewboyson | 132:5b2df69a4f17 | 54 | |
| andrewboyson | 132:5b2df69a4f17 | 55 | Ajax.server = '/net-ajax'; |
| andrewboyson | 132:5b2df69a4f17 | 56 | Ajax.onResponse = function() { parse(); display(); }; |
| andrewboyson | 132:5b2df69a4f17 | 57 | Ajax.init(); |