var txG = new BigInt64Array(10); var txB = new BigInt64Array(10); var rxG = new BigInt64Array(10); var rxB = new BigInt64Array(10); const linkS = [function(){return t('speed_disabled')}, function(){return t('speed_down')}, "10M", "100M", "1000M", "500M", "10G", "2.5G", "5G"]; var pState = new Int8Array(10); var pIsSFP = new Int8Array(10); var pAdvertised = new Int8Array(10); var numPorts = 0; function linkText(idx) { var v = linkS[idx]; return typeof v === 'function' ? v() : v; } var logToPhysPort = new Int8Array(10); var physToLogPort = new Int8Array(10); var portNames = new Array(10); var currentRequests = []; var currentCallback; function drawPorts() { var f = document.getElementById('ports'); console.log("DRAWING PORTS: ", numPorts); for (let i = 0; i < numPorts; i++) { console.log("DRAWING isSFP: ", pIsSFP[i]); const d = document.createElement("div"); d.classList.add('tooltip'); const s = document.createElement("span"); s.classList.add("tooltiptext"); s.innerHTML = t('common_port'); s.id="tt_" + (i+1); const l = document.createElement("object"); d.appendChild(l); d.appendChild(s); l.type = "image/svg+xml"; if (!pIsSFP[i]) { l.data = "port.svg"; l.width ="40"; l.height ="40"; } else { l.data = "sfp.svg"; l.width = "60"; l.height = "60"; } l.id="port" + (i+1); f.appendChild(d); } } function parseUint16(val) { return parseInt(val, 16) & 0xffff; } function parseInt16(val) { let valInt = parseInt(val, 16); let num = valInt & 0x7fff; if (valInt & 0x8000) { return num - 0x8000; } return num; } function applyCalibrationSlopeOffset(val, cal) { if (typeof cal !== 'string') { return val; } if (cal.startsWith("0x")) { cal = cal.substring(2); } if (cal.length != 8) { return val; } let slope = parseUint16(cal.substring(0, 4)) / 256; let offset = parseInt16(cal.substring(4, 8)); return slope * val + offset; } function applyRxPowerCalibration(val, cal) { if (typeof cal !== 'string') { return val; } if (cal.startsWith("0x")) { cal = cal.substring(2); } if (cal.length != 40) { return val; } let bytes = cal.match(/.{1,2}/g).map(function (x) { return parseInt(x, 16); }); let view = new DataView(new Uint8Array(bytes).buffer); return view.getFloat32(0) * Math.pow(val, 4) + view.getFloat32(4) * Math.pow(val, 3) + view.getFloat32(8) * Math.pow(val, 2) + view.getFloat32(12) * val + view.getFloat32(16); } function decodeSfpTemp(val, cal) { let temp = parseInt16(val); return applyCalibrationSlopeOffset(temp, cal) / 256; } function decodeSfpVcc(val, cal) { let vcc = parseUint16(val); return applyCalibrationSlopeOffset(vcc, cal) / 10000; } function decodeSfpTxBias(val, cal) { let bias = parseUint16(val); return applyCalibrationSlopeOffset(bias, cal) / 500; } function decodeSfpTxPower(val, cal) { let txPower = parseUint16(val); return applyCalibrationSlopeOffset(txPower, cal) / 10000; } function decodeSfpRxPower(val, cal) { let rxPower = parseUint16(val); return applyRxPowerCalibration(rxPower, cal) / 10000; } function convertPowerTodBm(val) { return 10 * Math.log10(val); } function update(callback) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { console.log("IN UPDATE "); if (this.readyState == 4 && this.status == 401) document.location = "/login.html" if (this.readyState == 4 && this.status == 200) { const s = JSON.parse(xhttp.responseText); if (!numPorts) { numPorts = s.length; for (let i = 0; i < s.length; i++) pIsSFP[s[i].portNum-1] = s[i].isSFP; drawPorts(); } console.log("RES:", JSON.stringify(s)); for (let i = 0; i < s.length; i++) { p = s[i]; let n = p.portNum; logToPhysPort[p.logPort] = n; physToLogPort[n-1] = p.logPort; portNames[p.logPort] = p.name; let pid = "port" + n; let ttid = "tt_" + n; n--; txG[n] = BigInt(p.txG); txB[n] = BigInt(p.txB); rxG[n] = BigInt(p.rxG); rxB[n] = BigInt(p.rxB); var psvg = document.getElementById(pid); var tt = document.getElementById(ttid); if (psvg == null || !psvg.contentDocument) continue; var bgs = psvg.contentDocument.getElementsByClassName("bg"); var leds = psvg.contentDocument.getElementsByClassName("led"); if (leds[0] == null || leds[0].style == null) continue; const portName = p.name || portNames[p.logPort] || ''; var iHTML = "
| " + t('port_name') + " | : | " + portName + " |
| " + t('port_status') + " | : | " + t('port_not_enabled') + " |