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@133:98c6bf14bc37, 2020-03-11 (annotated)
- Committer:
- andrewboyson
- Date:
- Wed Mar 11 16:00:21 2020 +0000
- Revision:
- 133:98c6bf14bc37
- Parent:
- 132:5b2df69a4f17
- Child:
- 143:cc2e148cb96a
Addewd more fields to TCP connections
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 | 133:98c6bf14bc37 | 11 | let state = parseInt(fields[0], 16); |
| andrewboyson | 133:98c6bf14bc37 | 12 | let idleMs = parseInt(fields[1], 16); |
| andrewboyson | 133:98c6bf14bc37 | 13 | let ipType = parseInt(fields[2], 16); |
| andrewboyson | 133:98c6bf14bc37 | 14 | let arIndex = parseInt(fields[3], 16); |
| andrewboyson | 133:98c6bf14bc37 | 15 | let locPort = parseInt(fields[4], 16); |
| andrewboyson | 133:98c6bf14bc37 | 16 | let remPort = parseInt(fields[5], 16); |
| andrewboyson | 133:98c6bf14bc37 | 17 | let bytesRcvd = parseInt(fields[6], 16); |
| andrewboyson | 133:98c6bf14bc37 | 18 | let bytesSent = parseInt(fields[7], 16); |
| andrewboyson | 132:5b2df69a4f17 | 19 | |
| andrewboyson | 133:98c6bf14bc37 | 20 | switch (state) |
| andrewboyson | 133:98c6bf14bc37 | 21 | { |
| andrewboyson | 133:98c6bf14bc37 | 22 | case 1: tcp += " Syn"; break; |
| andrewboyson | 133:98c6bf14bc37 | 23 | case 2: tcp += " Est"; break; |
| andrewboyson | 133:98c6bf14bc37 | 24 | case 3: tcp += " Wait"; break; |
| andrewboyson | 133:98c6bf14bc37 | 25 | default: tcp += state.toString().padStart(5, ' '); break; |
| andrewboyson | 133:98c6bf14bc37 | 26 | } |
| andrewboyson | 132:5b2df69a4f17 | 27 | |
| andrewboyson | 133:98c6bf14bc37 | 28 | let idleMinutes = Math.floor(idleMs / 1000 / 60); |
| andrewboyson | 133:98c6bf14bc37 | 29 | tcp += idleMinutes.toString().padStart(4, ' '); |
| andrewboyson | 133:98c6bf14bc37 | 30 | tcp += " "; |
| andrewboyson | 132:5b2df69a4f17 | 31 | |
| andrewboyson | 133:98c6bf14bc37 | 32 | if (ipType == 0x0800) tcp += "IPv4"; |
| andrewboyson | 132:5b2df69a4f17 | 33 | else if (ipType == 0x86DD) tcp += "IPv6"; |
| andrewboyson | 132:5b2df69a4f17 | 34 | else tcp += fields[1]; |
| andrewboyson | 132:5b2df69a4f17 | 35 | |
| andrewboyson | 133:98c6bf14bc37 | 36 | tcp += arIndex.toString().padStart(4, ' '); |
| andrewboyson | 133:98c6bf14bc37 | 37 | tcp += locPort.toString().padStart(9, ' '); |
| andrewboyson | 133:98c6bf14bc37 | 38 | tcp += remPort.toString().padStart(9, ' '); |
| andrewboyson | 133:98c6bf14bc37 | 39 | tcp += bytesRcvd.toString().padStart(6, ' '); |
| andrewboyson | 133:98c6bf14bc37 | 40 | tcp += bytesSent.toString().padStart(6, ' '); |
| andrewboyson | 132:5b2df69a4f17 | 41 | tcp += '\r\n'; |
| andrewboyson | 132:5b2df69a4f17 | 42 | } |
| andrewboyson | 132:5b2df69a4f17 | 43 | function parseTcpLines(text) |
| andrewboyson | 132:5b2df69a4f17 | 44 | { |
| andrewboyson | 133:98c6bf14bc37 | 45 | tcp = "State Idle Protocol ARI Port-Loc Port-Rem Rcvd Sent\n"; |
| andrewboyson | 132:5b2df69a4f17 | 46 | text.split('\n').forEach(parseTcpLine); |
| andrewboyson | 132:5b2df69a4f17 | 47 | } |
| andrewboyson | 132:5b2df69a4f17 | 48 | function parseGenLines(text) |
| andrewboyson | 132:5b2df69a4f17 | 49 | { |
| andrewboyson | 132:5b2df69a4f17 | 50 | let lines = text.split('\n'); |
| andrewboyson | 132:5b2df69a4f17 | 51 | mac = Net.makeMac(lines[ 0]); |
| andrewboyson | 132:5b2df69a4f17 | 52 | } |
| andrewboyson | 132:5b2df69a4f17 | 53 | function parse() |
| andrewboyson | 132:5b2df69a4f17 | 54 | { |
| andrewboyson | 132:5b2df69a4f17 | 55 | let topics = Ajax.response.split('\f'); |
| andrewboyson | 132:5b2df69a4f17 | 56 | parseGenLines(topics[0]); |
| andrewboyson | 132:5b2df69a4f17 | 57 | parseTcpLines(topics[1]); |
| andrewboyson | 132:5b2df69a4f17 | 58 | } |
| andrewboyson | 132:5b2df69a4f17 | 59 | function display() |
| andrewboyson | 132:5b2df69a4f17 | 60 | { |
| andrewboyson | 132:5b2df69a4f17 | 61 | let elem; |
| andrewboyson | 132:5b2df69a4f17 | 62 | |
| andrewboyson | 132:5b2df69a4f17 | 63 | elem = Ajax.getElementOrNull('ajax-tcp' ); if (elem) elem.textContent = tcp; |
| andrewboyson | 132:5b2df69a4f17 | 64 | elem = Ajax.getElementOrNull('ajax-mac' ); if (elem) elem.textContent = mac; |
| andrewboyson | 132:5b2df69a4f17 | 65 | } |
| andrewboyson | 132:5b2df69a4f17 | 66 | |
| andrewboyson | 132:5b2df69a4f17 | 67 | Ajax.server = '/net-ajax'; |
| andrewboyson | 132:5b2df69a4f17 | 68 | Ajax.onResponse = function() { parse(); display(); }; |
| andrewboyson | 132:5b2df69a4f17 | 69 | Ajax.init(); |