From d5fd7e34c7929b374e698409309abe4256c665b0 Mon Sep 17 00:00:00 2001 From: Simone <26844016+simonebortolin@users.noreply.github.com> Date: Sat, 24 Dec 2022 22:19:13 +0000 Subject: [PATCH 01/20] add class on custom.js --- _includes/js/custom.js | 223 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 _includes/js/custom.js diff --git a/_includes/js/custom.js b/_includes/js/custom.js new file mode 100644 index 00000000..b501b4c8 --- /dev/null +++ b/_includes/js/custom.js @@ -0,0 +1,223 @@ +class uuencoding { + /** + * uuencode a value + * + * @param {(String|Buffer)} The value to be encoded. + * @returns {String} The encoded value. + */ + static encode(inString) { + var stop = false; + var inIndex = 0; + var outIndex = 0; + var bytesRead = 0; + + var inBytes = new Buffer(inString); + var buffLen = inBytes.length; + var outBytes = new Buffer(buffLen + buffLen / 3 + 1 + buffLen / 45 * 2 + 2 + 4); + + do { + var n; + var bytesLeft = buffLen - bytesRead; + + if (bytesLeft === 0) { + break; + } + + if (bytesLeft <= 45) { + n = bytesLeft; + } else { + n = 45; + } + + outBytes[outIndex++] = (n & 0x3F) + 32; + + for (var i = 0; i < n; i += 3) { + if (buffLen - inIndex < 3) { + var padding = new Array(3); + var z = 0; + + while (inIndex + z < buffLen) { + padding[z] = inBytes[inIndex + z]; + ++z; + } + + this.#encodeBytes(padding, 0, outBytes, outIndex); + } else { + this.#encodeBytes(inBytes, inIndex, outBytes, outIndex); + } + + inIndex += 3; + outIndex += 4; + } + + outBytes[outIndex++] = 10; + bytesRead += n; + + if (n >= 45) { + continue; + } + + stop = true; + } while (!stop); + + return outBytes.toString().substring(0, outIndex); + } + + /** + * uudecode a value + * + * @param {(String|Buffer)} The value to be decoded. + * @returns {Buffer} The decoded value. + */ + static decode(inString) { + var stop = false; + var inIndex = 0; + var outIndex = 0; + var totalLen = 0; + + var inBytes = new Buffer(inString); + var buffLen = inBytes.length; + var outBytes = new Buffer(buffLen); + + do { + if (inIndex < buffLen) { + var n = inBytes[inIndex] - 32 & 0x3F; + + ++inIndex; + + if (n > 45) { + throw 'Invalid Data'; + } + + if (n < 45) { + stop = true; + } + + totalLen += n; + + while (n > 0) { + this.#decodeChars(inBytes, inIndex, outBytes, outIndex); + outIndex += 3; + inIndex += 4; + n -= 3; + } + + ++inIndex; + } else { + stop = true; + } + } while (!stop); + + return outBytes.slice(0, totalLen); + } + + // private helper functions + static #encodeBytes(inBytes, inIndex, outBytes, outIndex) { + var c1 = inBytes[inIndex] >>> 2; + var c2 = inBytes[inIndex] << 4 & 0x30 | inBytes[inIndex + 1] >>> 4 & 0xF; + var c3 = inBytes[inIndex + 1] << 2 & 0x3C | inBytes[inIndex + 2] >>> 6 & 0x3; + var c4 = inBytes[inIndex + 2] & 0x3F; + + outBytes[outIndex] = (c1 & 0x3F) + 32; + outBytes[outIndex + 1] = (c2 & 0x3F) + 32; + outBytes[outIndex + 2] = (c3 & 0x3F) + 32; + outBytes[outIndex + 3] = (c4 & 0x3F) + 32; + } + + static #decodeChars(inBytes, inIndex, outBytes, outIndex) { + var c1 = inBytes[inIndex]; + var c2 = inBytes[inIndex + 1]; + var c3 = inBytes[inIndex + 2]; + var c4 = inBytes[inIndex + 3]; + + var b1 = (c1 - 32 & 0x3F) << 2 | (c2 - 32 & 0x3F) >> 4; + var b2 = (c2 - 32 & 0x3F) << 4 | (c3 - 32 & 0x3F) >> 2; + var b3 = (c3 - 32 & 0x3F) << 6 | c4 - 32 & 0x3F; + + outBytes[outIndex] = b1 & 0xFF; + outBytes[outIndex + 1] = b2 & 0xFF; + outBytes[outIndex + 2] = b3 & 0xFF; + } +} + +class asciiHex { + static asciiToHex(str, prefix = "0x", glue = " ") { + var prefixi = glue !== "" ? prefix : ""; + var prefixs = glue === "" ? prefix : ""; + var hex = prefixs + ([...str].map((elem, n) => prefixi+Number(str.charCodeAt(n)).toString(16)).join(glue)); + return hex; + } + static hexToAscii(str, prefix = "0x", separator = " ") { + if(prefix != "" && str.startsWith(prefix)) + str = str.substring(prefix.length); + var ascii = separator === "" ? getChunks(str.substring(2),2).map(el => String.fromCharCode(parseInt(el, 16))).join('') : str.split(separator).map(el => String.fromCharCode(Number(el))).join(''); + return ascii; + } +} + +class gponSerial { + #vendor; + #progressive; + constructor(vendor, progressive) { + if(vendor.length == 4) { + this.#vendor = vendor.toUpperCase(); + } else if(vendor.length == 8) { + this.#vendor = asciiHex.hexToAscii(vendor,'','').toUpperCase(); + } else { + throw "vendor length unvalid"; + } + if(progressive.length == 8) { + this.#progressive = progressive.toLowerCase(); + } else { + throw "progressive length unvalid"; + } + } + constructor(serial) { + if(serial.length == 12) { + this.#vendor = serial.substring(0, 4).toUpperCase(); + this.#progressive = serial.substring(4).toLowerCase(); + } else if(serial.length == 16) { + this.#vendor = asciiHex.hexToAscii(serial.substring(0, 8)).toUpperCase(); + this.#progressive = serial.substring(8).toLowerCase(); + } else { + throw "serial length unvalid"; + } + } + get [vendorHex]() { + return ([...this.#vendor].map((elem, n) => Number(this.#vendor.charCodeAt(n)).toString(16)).join('')); + } + get [vendor]() { + return this.#vendor; + } + get [progressive]() { + return this.#progressive; + } + get [serial]() { + return `${this.#vendor}${this.#progressive}`; + } +} + +class gponPloam { + #ploam; + constructor(ploam) { + if(ploam.length <= 10) { + this.#ploam = ([...gpon_password].map((elem, n) => Number(gpon_password.charCodeAt(n)).toString(16)).join('')); + this.#ploam += '0'.repeat(20-gpon_password.length); + } + else if(ploam.length === 20) { + this.#ploam = ploam; + } + else if(ploam.length === 22 && ploam.startsWith("0x")) { + this.#ploam = ploam.substring(2); + } + } + get [ploam]() { + return asciiHex.hexToAscii(this.#ploam, '',''); + } + get [ploamEncoding]() { + return JSON.stringify(ploam); + } + get [ploamHex] () { + return this.#ploam; + } +} \ No newline at end of file From d351d5237ee7b6dde664158b0a76c1563a9901e9 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Mon, 26 Dec 2022 23:56:56 +0100 Subject: [PATCH 02/20] add some code --- _includes/js/custom.js | 621 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 619 insertions(+), 2 deletions(-) diff --git a/_includes/js/custom.js b/_includes/js/custom.js index b501b4c8..8329b375 100644 --- a/_includes/js/custom.js +++ b/_includes/js/custom.js @@ -1,3 +1,528 @@ +(function (jtd, undefined) { + +// Event handling + +jtd.addEvent = function(el, type, handler) { + if (el.attachEvent) el.attachEvent('on'+type, handler); else el.addEventListener(type, handler); +} +jtd.removeEvent = function(el, type, handler) { + if (el.detachEvent) el.detachEvent('on'+type, handler); else el.removeEventListener(type, handler); +} +jtd.onReady = function(ready) { + // in case the document is already rendered + if (document.readyState!='loading') ready(); + // modern browsers + else if (document.addEventListener) document.addEventListener('DOMContentLoaded', ready); + // IE <= 8 + else document.attachEvent('onreadystatechange', function(){ + if (document.readyState=='complete') ready(); + }); +} + +// Show/hide mobile menu + +function initNav() { + jtd.addEvent(document, 'click', function(e){ + var target = e.target; + while (target && !(target.classList && target.classList.contains('nav-list-expander'))) { + target = target.parentNode; + } + if (target) { + e.preventDefault(); + target.parentNode.classList.toggle('active'); + } + }); + + const siteNav = document.getElementById('site-nav'); + const mainHeader = document.getElementById('main-header'); + const menuButton = document.getElementById('menu-button'); + + jtd.addEvent(menuButton, 'click', function(e){ + e.preventDefault(); + + if (menuButton.classList.toggle('nav-open')) { + siteNav.classList.add('nav-open'); + mainHeader.classList.add('nav-open'); + } else { + siteNav.classList.remove('nav-open'); + mainHeader.classList.remove('nav-open'); + } + }); +} +// Site search + +function initSearch() { + var request = new XMLHttpRequest(); + request.open('GET', '/assets/js/search-data.json', true); + + request.onload = function(){ + if (request.status >= 200 && request.status < 400) { + var docs = JSON.parse(request.responseText); + + lunr.tokenizer.separator = /[\s/]+/ + + var index = lunr(function(){ + this.ref('id'); + this.field('title', { boost: 200 }); + this.field('content', { boost: 2 }); + this.field('relUrl'); + this.metadataWhitelist = ['position'] + + for (var i in docs) { + this.add({ + id: i, + title: docs[i].title, + content: docs[i].content, + relUrl: docs[i].relUrl + }); + } + }); + + searchLoaded(index, docs); + } else { + console.log('Error loading ajax request. Request status:' + request.status); + } + }; + + request.onerror = function(){ + console.log('There was a connection error'); + }; + + request.send(); +} + +function searchLoaded(index, docs) { + var index = index; + var docs = docs; + var searchInput = document.getElementById('search-input'); + var searchResults = document.getElementById('search-results'); + var mainHeader = document.getElementById('main-header'); + var currentInput; + var currentSearchIndex = 0; + + function showSearch() { + document.documentElement.classList.add('search-active'); + } + + function hideSearch() { + document.documentElement.classList.remove('search-active'); + } + + function update() { + currentSearchIndex++; + + var input = searchInput.value; + if (input === '') { + hideSearch(); + } else { + showSearch(); + // scroll search input into view, workaround for iOS Safari + window.scroll(0, -1); + setTimeout(function(){ window.scroll(0, 0); }, 0); + } + if (input === currentInput) { + return; + } + currentInput = input; + searchResults.innerHTML = ''; + if (input === '') { + return; + } + + var results = index.query(function (query) { + var tokens = lunr.tokenizer(input) + query.term(tokens, { + boost: 10 + }); + query.term(tokens, { + wildcard: lunr.Query.wildcard.TRAILING + }); + }); + + if ((results.length == 0) && (input.length > 2)) { + var tokens = lunr.tokenizer(input).filter(function(token, i) { + return token.str.length < 20; + }) + if (tokens.length > 0) { + results = index.query(function (query) { + query.term(tokens, { + editDistance: Math.round(Math.sqrt(input.length / 2 - 1)) + }); + }); + } + } + + if (results.length == 0) { + var noResultsDiv = document.createElement('div'); + noResultsDiv.classList.add('search-no-result'); + noResultsDiv.innerText = 'No results found'; + searchResults.appendChild(noResultsDiv); + + } else { + var resultsList = document.createElement('ul'); + resultsList.classList.add('search-results-list'); + searchResults.appendChild(resultsList); + + addResults(resultsList, results, 0, 10, 100, currentSearchIndex); + } + + function addResults(resultsList, results, start, batchSize, batchMillis, searchIndex) { + if (searchIndex != currentSearchIndex) { + return; + } + for (var i = start; i < (start + batchSize); i++) { + if (i == results.length) { + return; + } + addResult(resultsList, results[i]); + } + setTimeout(function() { + addResults(resultsList, results, start + batchSize, batchSize, batchMillis, searchIndex); + }, batchMillis); + } + + function addResult(resultsList, result) { + var doc = docs[result.ref]; + + var resultsListItem = document.createElement('li'); + resultsListItem.classList.add('search-results-list-item'); + resultsList.appendChild(resultsListItem); + + var resultLink = document.createElement('a'); + resultLink.classList.add('search-result'); + resultLink.setAttribute('href', doc.url); + resultsListItem.appendChild(resultLink); + + var resultTitle = document.createElement('div'); + resultTitle.classList.add('search-result-title'); + resultLink.appendChild(resultTitle); + + var resultDoc = document.createElement('div'); + resultDoc.classList.add('search-result-doc'); + resultDoc.innerHTML = ''; + resultTitle.appendChild(resultDoc); + + var resultDocTitle = document.createElement('div'); + resultDocTitle.classList.add('search-result-doc-title'); + resultDocTitle.innerHTML = doc.doc; + resultDoc.appendChild(resultDocTitle); + var resultDocOrSection = resultDocTitle; + + if (doc.doc != doc.title) { + resultDoc.classList.add('search-result-doc-parent'); + var resultSection = document.createElement('div'); + resultSection.classList.add('search-result-section'); + resultSection.innerHTML = doc.title; + resultTitle.appendChild(resultSection); + resultDocOrSection = resultSection; + } + + var metadata = result.matchData.metadata; + var titlePositions = []; + var contentPositions = []; + for (var j in metadata) { + var meta = metadata[j]; + if (meta.title) { + var positions = meta.title.position; + for (var k in positions) { + titlePositions.push(positions[k]); + } + } + if (meta.content) { + var positions = meta.content.position; + for (var k in positions) { + var position = positions[k]; + var previewStart = position[0]; + var previewEnd = position[0] + position[1]; + var ellipsesBefore = true; + var ellipsesAfter = true; + for (var k = 0; k < 5; k++) { + var nextSpace = doc.content.lastIndexOf(' ', previewStart - 2); + var nextDot = doc.content.lastIndexOf('. ', previewStart - 2); + if ((nextDot >= 0) && (nextDot > nextSpace)) { + previewStart = nextDot + 1; + ellipsesBefore = false; + break; + } + if (nextSpace < 0) { + previewStart = 0; + ellipsesBefore = false; + break; + } + previewStart = nextSpace + 1; + } + for (var k = 0; k < 10; k++) { + var nextSpace = doc.content.indexOf(' ', previewEnd + 1); + var nextDot = doc.content.indexOf('. ', previewEnd + 1); + if ((nextDot >= 0) && (nextDot < nextSpace)) { + previewEnd = nextDot; + ellipsesAfter = false; + break; + } + if (nextSpace < 0) { + previewEnd = doc.content.length; + ellipsesAfter = false; + break; + } + previewEnd = nextSpace; + } + contentPositions.push({ + highlight: position, + previewStart: previewStart, previewEnd: previewEnd, + ellipsesBefore: ellipsesBefore, ellipsesAfter: ellipsesAfter + }); + } + } + } + + if (titlePositions.length > 0) { + titlePositions.sort(function(p1, p2){ return p1[0] - p2[0] }); + resultDocOrSection.innerHTML = ''; + addHighlightedText(resultDocOrSection, doc.title, 0, doc.title.length, titlePositions); + } + + if (contentPositions.length > 0) { + contentPositions.sort(function(p1, p2){ return p1.highlight[0] - p2.highlight[0] }); + var contentPosition = contentPositions[0]; + var previewPosition = { + highlight: [contentPosition.highlight], + previewStart: contentPosition.previewStart, previewEnd: contentPosition.previewEnd, + ellipsesBefore: contentPosition.ellipsesBefore, ellipsesAfter: contentPosition.ellipsesAfter + }; + var previewPositions = [previewPosition]; + for (var j = 1; j < contentPositions.length; j++) { + contentPosition = contentPositions[j]; + if (previewPosition.previewEnd < contentPosition.previewStart) { + previewPosition = { + highlight: [contentPosition.highlight], + previewStart: contentPosition.previewStart, previewEnd: contentPosition.previewEnd, + ellipsesBefore: contentPosition.ellipsesBefore, ellipsesAfter: contentPosition.ellipsesAfter + } + previewPositions.push(previewPosition); + } else { + previewPosition.highlight.push(contentPosition.highlight); + previewPosition.previewEnd = contentPosition.previewEnd; + previewPosition.ellipsesAfter = contentPosition.ellipsesAfter; + } + } + + var resultPreviews = document.createElement('div'); + resultPreviews.classList.add('search-result-previews'); + resultLink.appendChild(resultPreviews); + + var content = doc.content; + for (var j = 0; j < Math.min(previewPositions.length, 3); j++) { + var position = previewPositions[j]; + + var resultPreview = document.createElement('div'); + resultPreview.classList.add('search-result-preview'); + resultPreviews.appendChild(resultPreview); + + if (position.ellipsesBefore) { + resultPreview.appendChild(document.createTextNode('... ')); + } + addHighlightedText(resultPreview, content, position.previewStart, position.previewEnd, position.highlight); + if (position.ellipsesAfter) { + resultPreview.appendChild(document.createTextNode(' ...')); + } + } + } + var resultRelUrl = document.createElement('span'); + resultRelUrl.classList.add('search-result-rel-url'); + resultRelUrl.innerText = doc.relUrl; + resultTitle.appendChild(resultRelUrl); + } + + function addHighlightedText(parent, text, start, end, positions) { + var index = start; + for (var i in positions) { + var position = positions[i]; + var span = document.createElement('span'); + span.innerHTML = text.substring(index, position[0]); + parent.appendChild(span); + index = position[0] + position[1]; + var highlight = document.createElement('span'); + highlight.classList.add('search-result-highlight'); + highlight.innerHTML = text.substring(position[0], index); + parent.appendChild(highlight); + } + var span = document.createElement('span'); + span.innerHTML = text.substring(index, end); + parent.appendChild(span); + } + } + + jtd.addEvent(searchInput, 'focus', function(){ + setTimeout(update, 0); + }); + + jtd.addEvent(searchInput, 'keyup', function(e){ + switch (e.keyCode) { + case 27: // When esc key is pressed, hide the results and clear the field + searchInput.value = ''; + break; + case 38: // arrow up + case 40: // arrow down + case 13: // enter + e.preventDefault(); + return; + } + update(); + }); + + jtd.addEvent(searchInput, 'keydown', function(e){ + switch (e.keyCode) { + case 38: // arrow up + e.preventDefault(); + var active = document.querySelector('.search-result.active'); + if (active) { + active.classList.remove('active'); + if (active.parentElement.previousSibling) { + var previous = active.parentElement.previousSibling.querySelector('.search-result'); + previous.classList.add('active'); + } + } + return; + case 40: // arrow down + e.preventDefault(); + var active = document.querySelector('.search-result.active'); + if (active) { + if (active.parentElement.nextSibling) { + var next = active.parentElement.nextSibling.querySelector('.search-result'); + active.classList.remove('active'); + next.classList.add('active'); + } + } else { + var next = document.querySelector('.search-result'); + if (next) { + next.classList.add('active'); + } + } + return; + case 13: // enter + e.preventDefault(); + var active = document.querySelector('.search-result.active'); + if (active) { + active.click(); + } else { + var first = document.querySelector('.search-result'); + if (first) { + first.click(); + } + } + return; + } + }); + + jtd.addEvent(document, 'click', function(e){ + if (e.target != searchInput) { + hideSearch(); + } + }); +} + +// Switch theme + +jtd.getTheme = function() { + var cssFile = document.querySelector('[rel="stylesheet"]'); + if(cssFile.hasAttribute('media')) return 'auto'; + + var cssFileHref = cssFile.getAttribute('href'); + return cssFileHref.substring(cssFileHref.lastIndexOf('-') + 1, cssFileHref.length - 4); +} + +jtd.setTheme = function(theme) { + var cssFile = document.querySelector('[rel="stylesheet"]'); + var cssFiles = [...document.querySelectorAll('[rel="stylesheet"]')]; + var cssFile = cssFiles[0]; + if(cssFiles.length >= 1) { + cssFiles.shift(); + cssFiles.forEach(it => it.remove()); + cssFile.removeAttribute('media'); + } + if(theme === "auto") { + cssFile.setAttribute('href', '/assets/css/just-the-docs-light.css'); + cssFile.setAttribute('media', '(prefers-color-scheme: light)'); + cssFile.insertAdjacentHTML('afterend', ``); + } else { + cssFile.setAttribute('href', '/assets/css/just-the-docs-' + theme + '.css'); + } +} + +jtd.switchThemeButton = function(button, event) { + const themes = ["auto", "light", "dark"]; + var currentTheme = jtd.getTheme(); + var nextTheme = themes[(themes.indexOf(currentTheme)+1)%themes.length]; + jtd.setTheme(nextTheme); + button.getElementsByTagName('svg')[0].getElementsByTagName('use')[0].setAttribute('href',`#svg-${nextTheme}`); +} + +function initSwitchThemeButton() { + var buttons = [...document.getElementsByClassName("color-scheme-switch-theme-button")]; + buttons.forEach(button => jtd.addEvent(button, 'click', event => jtd.switchThemeButton(button, event))); +} + +// Scroll site-nav to ensure the link to the current page is visible + +function scrollNav() { + const href = document.location.pathname; + const siteNav = document.getElementById('site-nav'); + const targetLink = siteNav.querySelector('a[href="' + href + '"], a[href="' + href + '/"]'); + if(targetLink){ + const rect = targetLink.getBoundingClientRect(); + siteNav.scrollBy(0, rect.top - 3*rect.height); + } +} + +// Document ready + +jtd.onReady(function(){ + initNav(); + initSearch(); + initSwitchThemeButton(); + scrollNav(); +}); + +// Copy button on code + +jtd.onReady(function(){ + + var codeBlocks = document.querySelectorAll('div.highlighter-rouge, div.listingblock, figure.highlight'); + + var svgCopied = ''; + var svgCopy = ''; + + codeBlocks.forEach(codeBlock => { + var copyButton = document.createElement('button'); + var timeout = null; + copyButton.type = 'button'; + copyButton.ariaLabel = 'Copy code to clipboard'; + copyButton.innerHTML = svgCopy; + codeBlock.append(copyButton); + + copyButton.addEventListener('click', function () { + if(timeout === null) { + var code = codeBlock.querySelector('code').innerText.trim(); + window.navigator.clipboard.writeText(code); + + copyButton.innerHTML = svgCopied; + + var timeoutSetting = 4000; + + timeout = setTimeout(function () { + copyButton.innerHTML = svgCopy; + timeout = null; + }, timeoutSetting); + } + }); + }); + +}); + +})(window.jtd = window.jtd || {}); + + + class uuencoding { /** * uuencode a value @@ -154,7 +679,7 @@ class asciiHex { return ascii; } } - +/* class gponSerial { #vendor; #progressive; @@ -220,4 +745,96 @@ class gponPloam { get [ploamHex] () { return this.#ploam; } -} \ No newline at end of file +}*/ + +class eeprom1 { + hex; + + constructor(hex) { + this.hex = hex; + } + + getPart = function(startIndex, endIndex) { + return this.hex.slice(startIndex*2, (endIndex+1)*2); + } + + setPart = function(startIndex, endIndex, value) { + let calcLength = (endIndex+1-startIndex)*2; + console.log(value.length); + if(value.length != calcLength) { + value += '0'.repeat(calcLength-value.length); + } + console.log(calcLength); + console.log(value.length); + /*for(var i = startIndex, j =0; i<= endIndex; i++, j++) { + this.hex[i*2] = value[i*2]; + this.hex[i*2+1] = value[i*2+1]; + }*/ + + this.hex.splice(startIndex, calcLength, ...value); + } + + get serial() { + return this.getPart(233, 240); + } + + set serial(value) { + this.setPart(233, 240, value); + } + + get ploam() { + return this.getPart(191, 214); + } + + set ploam(value) { + this.setPart(191, 214, value); + } + + get loid() { + return this.getPart(191, 214); + } + + set loid(value) { + this.setPart(191, 214, value); + } + + get lpwd() { + return this.getPart(215, 231); + } + + set lpwd(value) { + this.setPart(215, 231, value); + } + + get loidPloamSwitch() { + return this.getPart(232, 232); + } + + set loidPloamSwitch(value) { + this.setPart(232, 232, value); + } + + get equipmentID() { + return this.getPart(512, 531); + } + + set equipmentID(value) { + this.setPart(512, 531, value); + } + + get vendorID() { + return this.getPart(532, 535); + } + + set vendorID(value) { + this.setPart(532, 535, value); + } + + get macAddress() { + return this.getPart(384, 389); + } + + set macAddress(value) { + this.setPart(384, 389, value); + } +} From 3b7853e472a32b84fd4dc7f55cb9565f47e04548 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Tue, 27 Dec 2022 15:41:59 +0100 Subject: [PATCH 03/20] add some thing --- _includes/js/custom.js | 584 ++--------------------------------------- 1 file changed, 27 insertions(+), 557 deletions(-) diff --git a/_includes/js/custom.js b/_includes/js/custom.js index 8329b375..3e14a68c 100644 --- a/_includes/js/custom.js +++ b/_includes/js/custom.js @@ -1,528 +1,3 @@ -(function (jtd, undefined) { - -// Event handling - -jtd.addEvent = function(el, type, handler) { - if (el.attachEvent) el.attachEvent('on'+type, handler); else el.addEventListener(type, handler); -} -jtd.removeEvent = function(el, type, handler) { - if (el.detachEvent) el.detachEvent('on'+type, handler); else el.removeEventListener(type, handler); -} -jtd.onReady = function(ready) { - // in case the document is already rendered - if (document.readyState!='loading') ready(); - // modern browsers - else if (document.addEventListener) document.addEventListener('DOMContentLoaded', ready); - // IE <= 8 - else document.attachEvent('onreadystatechange', function(){ - if (document.readyState=='complete') ready(); - }); -} - -// Show/hide mobile menu - -function initNav() { - jtd.addEvent(document, 'click', function(e){ - var target = e.target; - while (target && !(target.classList && target.classList.contains('nav-list-expander'))) { - target = target.parentNode; - } - if (target) { - e.preventDefault(); - target.parentNode.classList.toggle('active'); - } - }); - - const siteNav = document.getElementById('site-nav'); - const mainHeader = document.getElementById('main-header'); - const menuButton = document.getElementById('menu-button'); - - jtd.addEvent(menuButton, 'click', function(e){ - e.preventDefault(); - - if (menuButton.classList.toggle('nav-open')) { - siteNav.classList.add('nav-open'); - mainHeader.classList.add('nav-open'); - } else { - siteNav.classList.remove('nav-open'); - mainHeader.classList.remove('nav-open'); - } - }); -} -// Site search - -function initSearch() { - var request = new XMLHttpRequest(); - request.open('GET', '/assets/js/search-data.json', true); - - request.onload = function(){ - if (request.status >= 200 && request.status < 400) { - var docs = JSON.parse(request.responseText); - - lunr.tokenizer.separator = /[\s/]+/ - - var index = lunr(function(){ - this.ref('id'); - this.field('title', { boost: 200 }); - this.field('content', { boost: 2 }); - this.field('relUrl'); - this.metadataWhitelist = ['position'] - - for (var i in docs) { - this.add({ - id: i, - title: docs[i].title, - content: docs[i].content, - relUrl: docs[i].relUrl - }); - } - }); - - searchLoaded(index, docs); - } else { - console.log('Error loading ajax request. Request status:' + request.status); - } - }; - - request.onerror = function(){ - console.log('There was a connection error'); - }; - - request.send(); -} - -function searchLoaded(index, docs) { - var index = index; - var docs = docs; - var searchInput = document.getElementById('search-input'); - var searchResults = document.getElementById('search-results'); - var mainHeader = document.getElementById('main-header'); - var currentInput; - var currentSearchIndex = 0; - - function showSearch() { - document.documentElement.classList.add('search-active'); - } - - function hideSearch() { - document.documentElement.classList.remove('search-active'); - } - - function update() { - currentSearchIndex++; - - var input = searchInput.value; - if (input === '') { - hideSearch(); - } else { - showSearch(); - // scroll search input into view, workaround for iOS Safari - window.scroll(0, -1); - setTimeout(function(){ window.scroll(0, 0); }, 0); - } - if (input === currentInput) { - return; - } - currentInput = input; - searchResults.innerHTML = ''; - if (input === '') { - return; - } - - var results = index.query(function (query) { - var tokens = lunr.tokenizer(input) - query.term(tokens, { - boost: 10 - }); - query.term(tokens, { - wildcard: lunr.Query.wildcard.TRAILING - }); - }); - - if ((results.length == 0) && (input.length > 2)) { - var tokens = lunr.tokenizer(input).filter(function(token, i) { - return token.str.length < 20; - }) - if (tokens.length > 0) { - results = index.query(function (query) { - query.term(tokens, { - editDistance: Math.round(Math.sqrt(input.length / 2 - 1)) - }); - }); - } - } - - if (results.length == 0) { - var noResultsDiv = document.createElement('div'); - noResultsDiv.classList.add('search-no-result'); - noResultsDiv.innerText = 'No results found'; - searchResults.appendChild(noResultsDiv); - - } else { - var resultsList = document.createElement('ul'); - resultsList.classList.add('search-results-list'); - searchResults.appendChild(resultsList); - - addResults(resultsList, results, 0, 10, 100, currentSearchIndex); - } - - function addResults(resultsList, results, start, batchSize, batchMillis, searchIndex) { - if (searchIndex != currentSearchIndex) { - return; - } - for (var i = start; i < (start + batchSize); i++) { - if (i == results.length) { - return; - } - addResult(resultsList, results[i]); - } - setTimeout(function() { - addResults(resultsList, results, start + batchSize, batchSize, batchMillis, searchIndex); - }, batchMillis); - } - - function addResult(resultsList, result) { - var doc = docs[result.ref]; - - var resultsListItem = document.createElement('li'); - resultsListItem.classList.add('search-results-list-item'); - resultsList.appendChild(resultsListItem); - - var resultLink = document.createElement('a'); - resultLink.classList.add('search-result'); - resultLink.setAttribute('href', doc.url); - resultsListItem.appendChild(resultLink); - - var resultTitle = document.createElement('div'); - resultTitle.classList.add('search-result-title'); - resultLink.appendChild(resultTitle); - - var resultDoc = document.createElement('div'); - resultDoc.classList.add('search-result-doc'); - resultDoc.innerHTML = ''; - resultTitle.appendChild(resultDoc); - - var resultDocTitle = document.createElement('div'); - resultDocTitle.classList.add('search-result-doc-title'); - resultDocTitle.innerHTML = doc.doc; - resultDoc.appendChild(resultDocTitle); - var resultDocOrSection = resultDocTitle; - - if (doc.doc != doc.title) { - resultDoc.classList.add('search-result-doc-parent'); - var resultSection = document.createElement('div'); - resultSection.classList.add('search-result-section'); - resultSection.innerHTML = doc.title; - resultTitle.appendChild(resultSection); - resultDocOrSection = resultSection; - } - - var metadata = result.matchData.metadata; - var titlePositions = []; - var contentPositions = []; - for (var j in metadata) { - var meta = metadata[j]; - if (meta.title) { - var positions = meta.title.position; - for (var k in positions) { - titlePositions.push(positions[k]); - } - } - if (meta.content) { - var positions = meta.content.position; - for (var k in positions) { - var position = positions[k]; - var previewStart = position[0]; - var previewEnd = position[0] + position[1]; - var ellipsesBefore = true; - var ellipsesAfter = true; - for (var k = 0; k < 5; k++) { - var nextSpace = doc.content.lastIndexOf(' ', previewStart - 2); - var nextDot = doc.content.lastIndexOf('. ', previewStart - 2); - if ((nextDot >= 0) && (nextDot > nextSpace)) { - previewStart = nextDot + 1; - ellipsesBefore = false; - break; - } - if (nextSpace < 0) { - previewStart = 0; - ellipsesBefore = false; - break; - } - previewStart = nextSpace + 1; - } - for (var k = 0; k < 10; k++) { - var nextSpace = doc.content.indexOf(' ', previewEnd + 1); - var nextDot = doc.content.indexOf('. ', previewEnd + 1); - if ((nextDot >= 0) && (nextDot < nextSpace)) { - previewEnd = nextDot; - ellipsesAfter = false; - break; - } - if (nextSpace < 0) { - previewEnd = doc.content.length; - ellipsesAfter = false; - break; - } - previewEnd = nextSpace; - } - contentPositions.push({ - highlight: position, - previewStart: previewStart, previewEnd: previewEnd, - ellipsesBefore: ellipsesBefore, ellipsesAfter: ellipsesAfter - }); - } - } - } - - if (titlePositions.length > 0) { - titlePositions.sort(function(p1, p2){ return p1[0] - p2[0] }); - resultDocOrSection.innerHTML = ''; - addHighlightedText(resultDocOrSection, doc.title, 0, doc.title.length, titlePositions); - } - - if (contentPositions.length > 0) { - contentPositions.sort(function(p1, p2){ return p1.highlight[0] - p2.highlight[0] }); - var contentPosition = contentPositions[0]; - var previewPosition = { - highlight: [contentPosition.highlight], - previewStart: contentPosition.previewStart, previewEnd: contentPosition.previewEnd, - ellipsesBefore: contentPosition.ellipsesBefore, ellipsesAfter: contentPosition.ellipsesAfter - }; - var previewPositions = [previewPosition]; - for (var j = 1; j < contentPositions.length; j++) { - contentPosition = contentPositions[j]; - if (previewPosition.previewEnd < contentPosition.previewStart) { - previewPosition = { - highlight: [contentPosition.highlight], - previewStart: contentPosition.previewStart, previewEnd: contentPosition.previewEnd, - ellipsesBefore: contentPosition.ellipsesBefore, ellipsesAfter: contentPosition.ellipsesAfter - } - previewPositions.push(previewPosition); - } else { - previewPosition.highlight.push(contentPosition.highlight); - previewPosition.previewEnd = contentPosition.previewEnd; - previewPosition.ellipsesAfter = contentPosition.ellipsesAfter; - } - } - - var resultPreviews = document.createElement('div'); - resultPreviews.classList.add('search-result-previews'); - resultLink.appendChild(resultPreviews); - - var content = doc.content; - for (var j = 0; j < Math.min(previewPositions.length, 3); j++) { - var position = previewPositions[j]; - - var resultPreview = document.createElement('div'); - resultPreview.classList.add('search-result-preview'); - resultPreviews.appendChild(resultPreview); - - if (position.ellipsesBefore) { - resultPreview.appendChild(document.createTextNode('... ')); - } - addHighlightedText(resultPreview, content, position.previewStart, position.previewEnd, position.highlight); - if (position.ellipsesAfter) { - resultPreview.appendChild(document.createTextNode(' ...')); - } - } - } - var resultRelUrl = document.createElement('span'); - resultRelUrl.classList.add('search-result-rel-url'); - resultRelUrl.innerText = doc.relUrl; - resultTitle.appendChild(resultRelUrl); - } - - function addHighlightedText(parent, text, start, end, positions) { - var index = start; - for (var i in positions) { - var position = positions[i]; - var span = document.createElement('span'); - span.innerHTML = text.substring(index, position[0]); - parent.appendChild(span); - index = position[0] + position[1]; - var highlight = document.createElement('span'); - highlight.classList.add('search-result-highlight'); - highlight.innerHTML = text.substring(position[0], index); - parent.appendChild(highlight); - } - var span = document.createElement('span'); - span.innerHTML = text.substring(index, end); - parent.appendChild(span); - } - } - - jtd.addEvent(searchInput, 'focus', function(){ - setTimeout(update, 0); - }); - - jtd.addEvent(searchInput, 'keyup', function(e){ - switch (e.keyCode) { - case 27: // When esc key is pressed, hide the results and clear the field - searchInput.value = ''; - break; - case 38: // arrow up - case 40: // arrow down - case 13: // enter - e.preventDefault(); - return; - } - update(); - }); - - jtd.addEvent(searchInput, 'keydown', function(e){ - switch (e.keyCode) { - case 38: // arrow up - e.preventDefault(); - var active = document.querySelector('.search-result.active'); - if (active) { - active.classList.remove('active'); - if (active.parentElement.previousSibling) { - var previous = active.parentElement.previousSibling.querySelector('.search-result'); - previous.classList.add('active'); - } - } - return; - case 40: // arrow down - e.preventDefault(); - var active = document.querySelector('.search-result.active'); - if (active) { - if (active.parentElement.nextSibling) { - var next = active.parentElement.nextSibling.querySelector('.search-result'); - active.classList.remove('active'); - next.classList.add('active'); - } - } else { - var next = document.querySelector('.search-result'); - if (next) { - next.classList.add('active'); - } - } - return; - case 13: // enter - e.preventDefault(); - var active = document.querySelector('.search-result.active'); - if (active) { - active.click(); - } else { - var first = document.querySelector('.search-result'); - if (first) { - first.click(); - } - } - return; - } - }); - - jtd.addEvent(document, 'click', function(e){ - if (e.target != searchInput) { - hideSearch(); - } - }); -} - -// Switch theme - -jtd.getTheme = function() { - var cssFile = document.querySelector('[rel="stylesheet"]'); - if(cssFile.hasAttribute('media')) return 'auto'; - - var cssFileHref = cssFile.getAttribute('href'); - return cssFileHref.substring(cssFileHref.lastIndexOf('-') + 1, cssFileHref.length - 4); -} - -jtd.setTheme = function(theme) { - var cssFile = document.querySelector('[rel="stylesheet"]'); - var cssFiles = [...document.querySelectorAll('[rel="stylesheet"]')]; - var cssFile = cssFiles[0]; - if(cssFiles.length >= 1) { - cssFiles.shift(); - cssFiles.forEach(it => it.remove()); - cssFile.removeAttribute('media'); - } - if(theme === "auto") { - cssFile.setAttribute('href', '/assets/css/just-the-docs-light.css'); - cssFile.setAttribute('media', '(prefers-color-scheme: light)'); - cssFile.insertAdjacentHTML('afterend', ``); - } else { - cssFile.setAttribute('href', '/assets/css/just-the-docs-' + theme + '.css'); - } -} - -jtd.switchThemeButton = function(button, event) { - const themes = ["auto", "light", "dark"]; - var currentTheme = jtd.getTheme(); - var nextTheme = themes[(themes.indexOf(currentTheme)+1)%themes.length]; - jtd.setTheme(nextTheme); - button.getElementsByTagName('svg')[0].getElementsByTagName('use')[0].setAttribute('href',`#svg-${nextTheme}`); -} - -function initSwitchThemeButton() { - var buttons = [...document.getElementsByClassName("color-scheme-switch-theme-button")]; - buttons.forEach(button => jtd.addEvent(button, 'click', event => jtd.switchThemeButton(button, event))); -} - -// Scroll site-nav to ensure the link to the current page is visible - -function scrollNav() { - const href = document.location.pathname; - const siteNav = document.getElementById('site-nav'); - const targetLink = siteNav.querySelector('a[href="' + href + '"], a[href="' + href + '/"]'); - if(targetLink){ - const rect = targetLink.getBoundingClientRect(); - siteNav.scrollBy(0, rect.top - 3*rect.height); - } -} - -// Document ready - -jtd.onReady(function(){ - initNav(); - initSearch(); - initSwitchThemeButton(); - scrollNav(); -}); - -// Copy button on code - -jtd.onReady(function(){ - - var codeBlocks = document.querySelectorAll('div.highlighter-rouge, div.listingblock, figure.highlight'); - - var svgCopied = ''; - var svgCopy = ''; - - codeBlocks.forEach(codeBlock => { - var copyButton = document.createElement('button'); - var timeout = null; - copyButton.type = 'button'; - copyButton.ariaLabel = 'Copy code to clipboard'; - copyButton.innerHTML = svgCopy; - codeBlock.append(copyButton); - - copyButton.addEventListener('click', function () { - if(timeout === null) { - var code = codeBlock.querySelector('code').innerText.trim(); - window.navigator.clipboard.writeText(code); - - copyButton.innerHTML = svgCopied; - - var timeoutSetting = 4000; - - timeout = setTimeout(function () { - copyButton.innerHTML = svgCopy; - timeout = null; - }, timeoutSetting); - } - }); - }); - -}); - -})(window.jtd = window.jtd || {}); - - - class uuencoding { /** * uuencode a value @@ -664,7 +139,7 @@ class uuencoding { outBytes[outIndex + 2] = b3 & 0xFF; } } - +/* class asciiHex { static asciiToHex(str, prefix = "0x", glue = " ") { var prefixi = glue !== "" ? prefix : ""; @@ -679,7 +154,7 @@ class asciiHex { return ascii; } } -/* + class gponSerial { #vendor; #progressive; @@ -748,93 +223,88 @@ class gponPloam { }*/ class eeprom1 { - hex; - + #hex; constructor(hex) { - this.hex = hex; + this.#hex = [...hex]; } getPart = function(startIndex, endIndex) { - return this.hex.slice(startIndex*2, (endIndex+1)*2); + return this.#hex.slice(startIndex*2, (endIndex+1)*2).join(''); } setPart = function(startIndex, endIndex, value) { let calcLength = (endIndex+1-startIndex)*2; - console.log(value.length); if(value.length != calcLength) { value += '0'.repeat(calcLength-value.length); - } - console.log(calcLength); - console.log(value.length); - /*for(var i = startIndex, j =0; i<= endIndex; i++, j++) { - this.hex[i*2] = value[i*2]; - this.hex[i*2+1] = value[i*2+1]; - }*/ - - this.hex.splice(startIndex, calcLength, ...value); + } + this.#hex.splice(startIndex, calcLength, ...[...value]); + } + + getHex() { + return this.#hex.join(''); } - get serial() { + getSerial() { return this.getPart(233, 240); } - set serial(value) { + setSerial(value) { this.setPart(233, 240, value); } - get ploam() { + getPloam() { return this.getPart(191, 214); } - set ploam(value) { + setPloam(value) { this.setPart(191, 214, value); } - get loid() { + getLoid() { return this.getPart(191, 214); } - set loid(value) { + setLoid(value) { this.setPart(191, 214, value); } - get lpwd() { + getLpwd() { return this.getPart(215, 231); } - set lpwd(value) { + setLpwd(value) { this.setPart(215, 231, value); } - get loidPloamSwitch() { + getLoidPloamSwitch() { return this.getPart(232, 232); } - set loidPloamSwitch(value) { + setLoidPloamSwitch(value) { this.setPart(232, 232, value); } - get equipmentID() { + getEquipmentID() { return this.getPart(512, 531); } - set equipmentID(value) { + setEquipmentID(value) { this.setPart(512, 531, value); } - get vendorID() { + getVendorID() { return this.getPart(532, 535); } - set vendorID(value) { + setVendorID(value) { this.setPart(532, 535, value); } - get macAddress() { + getMacAddress() { return this.getPart(384, 389); } - set macAddress(value) { + setMacAddress(value) { this.setPart(384, 389, value); } } From 367d77a31ee18c41bc8a47536ea187dad755e98b Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Tue, 27 Dec 2022 16:41:48 +0100 Subject: [PATCH 04/20] add new logic and form item --- _includes/js/custom.js | 196 ++++++++++++++++++++++-------- _ont/ont-huawei-ma5671a-rooted.md | 51 ++++++-- 2 files changed, 186 insertions(+), 61 deletions(-) diff --git a/_includes/js/custom.js b/_includes/js/custom.js index 3e14a68c..228f2ee3 100644 --- a/_includes/js/custom.js +++ b/_includes/js/custom.js @@ -139,7 +139,13 @@ class uuencoding { outBytes[outIndex + 2] = b3 & 0xFF; } } -/* + +function getChunks(s, i) { + var a = []; + do{ a.push(s.substring(0, i)) } while( (s = s.substring(i)) != "" ); + return a; +} + class asciiHex { static asciiToHex(str, prefix = "0x", glue = " ") { var prefixi = glue !== "" ? prefix : ""; @@ -159,40 +165,41 @@ class gponSerial { #vendor; #progressive; constructor(vendor, progressive) { - if(vendor.length == 4) { - this.#vendor = vendor.toUpperCase(); - } else if(vendor.length == 8) { - this.#vendor = asciiHex.hexToAscii(vendor,'','').toUpperCase(); - } else { - throw "vendor length unvalid"; - } - if(progressive.length == 8) { - this.#progressive = progressive.toLowerCase(); + if(progressive !== undefined) { + if(vendor.length == 4) { + this.#vendor = vendor.toUpperCase(); + } else if(vendor.length == 8) { + this.#vendor = asciiHex.hexToAscii(vendor,'','').toUpperCase(); + } else { + throw "vendor length unvalid"; + } + if(progressive.length == 8) { + this.#progressive = progressive.toLowerCase(); + } else { + throw "progressive length unvalid"; + } } else { - throw "progressive length unvalid"; - } - } - constructor(serial) { - if(serial.length == 12) { - this.#vendor = serial.substring(0, 4).toUpperCase(); - this.#progressive = serial.substring(4).toLowerCase(); - } else if(serial.length == 16) { - this.#vendor = asciiHex.hexToAscii(serial.substring(0, 8)).toUpperCase(); - this.#progressive = serial.substring(8).toLowerCase(); - } else { - throw "serial length unvalid"; + if(vendor.length == 12) { + this.#vendor = vendor.substring(0, 4).toUpperCase(); + this.#progressive = vendor.substring(4).toLowerCase(); + } else if(vendor.length == 16) { + this.#vendor = asciiHex.hexToAscii(serial.substring(0, 8)).toUpperCase(); + this.#progressive = vendor.substring(8).toLowerCase(); + } else { + throw "serial length unvalid"; + } } } - get [vendorHex]() { - return ([...this.#vendor].map((elem, n) => Number(this.#vendor.charCodeAt(n)).toString(16)).join('')); + get vendorHex() { + return ([...this.#vendor].map((_, n) => Number(this.#vendor.charCodeAt(n)).toString(16)).join('')); } - get [vendor]() { + get vendor() { return this.#vendor; } - get [progressive]() { + get progressive() { return this.#progressive; } - get [serial]() { + get serial() { return `${this.#vendor}${this.#progressive}`; } } @@ -201,26 +208,26 @@ class gponPloam { #ploam; constructor(ploam) { if(ploam.length <= 10) { - this.#ploam = ([...gpon_password].map((elem, n) => Number(gpon_password.charCodeAt(n)).toString(16)).join('')); + this.#ploam = ([...gpon_password].map((_, n) => Number(gpon_password.charCodeAt(n)).toString(16)).join('')); this.#ploam += '0'.repeat(20-gpon_password.length); } else if(ploam.length === 20) { this.#ploam = ploam; } - else if(ploam.length === 22 && ploam.startsWith("0x")) { - this.#ploam = ploam.substring(2); + else { + throw "ploam length unvalid"; } } - get [ploam]() { + get ploam() { return asciiHex.hexToAscii(this.#ploam, '',''); } - get [ploamEncoding]() { + get ploamEncoding() { return JSON.stringify(ploam); } - get [ploamHex] () { + get ploamHex() { return this.#ploam; } -}*/ +} class eeprom1 { #hex; @@ -237,74 +244,159 @@ class eeprom1 { if(value.length != calcLength) { value += '0'.repeat(calcLength-value.length); } - this.#hex.splice(startIndex, calcLength, ...[...value]); + this.#hex.splice(startIndex*2, calcLength, ...[...value]); } - getHex() { + get hex() { return this.#hex.join(''); } - getSerial() { + get serial() { return this.getPart(233, 240); } - setSerial(value) { + set serial(value) { this.setPart(233, 240, value); } - getPloam() { + get ploam() { return this.getPart(191, 214); } - setPloam(value) { + set ploam(value) { this.setPart(191, 214, value); } - getLoid() { + get loid() { return this.getPart(191, 214); } - setLoid(value) { + set loid(value) { this.setPart(191, 214, value); } - getLpwd() { + get lpwd() { return this.getPart(215, 231); } - setLpwd(value) { + set lpwd(value) { this.setPart(215, 231, value); } - getLoidPloamSwitch() { + get loidPloamSwitch() { return this.getPart(232, 232); } - setLoidPloamSwitch(value) { + set loidPloamSwitch(value) { this.setPart(232, 232, value); } - getEquipmentID() { + get equipmentID() { return this.getPart(512, 531); } - setEquipmentID(value) { + set equipmentID(value) { this.setPart(512, 531, value); } - getVendorID() { + get vendorID() { return this.getPart(532, 535); } - setVendorID(value) { + set vendorID(value) { this.setPart(532, 535, value); } - getMacAddress() { + get macAddress() { return this.getPart(384, 389); } - setMacAddress(value) { + set macAddress(value) { this.setPart(384, 389, value); } } + +function populateForm(form, data, basename) { + for (const key in data) { + if (!data.hasOwnProperty(key)) { + continue; + } + + let name = key; + let value = data[key]; + + if ('undefined' === typeof value) + value = ''; + + if (null === value) + value = ''; + + // add basename + if (typeof(basename) !== "undefined") + name = basename + "-" + key; + + if (value.constructor === Array) { + if(typeof(basename) !== "undefined") + name += '[]'; + } else if(typeof value == "object") { + if(Object.keys(value).length === 1) { + if (typeof(basename) !== "undefined") + name += "-" + Object.keys(value)[0]; + value = value[Object.keys(value)[0]]; + } else { + if (typeof(basename) !== "undefined") + populateForm(form, value, name); + else + populateForm(form, value); + continue; + } + } + + // only proceed if element is set + let element = form.elements.namedItem(name); + if (! element) { + continue; + } + + let type = element.type || element[0].type; + + switch(type ) { + default: + element.value = value; + break; + + case 'radio': + case 'checkbox': { + let values = value.constructor === Array ? value : [value]; + for (let j = 0; j < element.length; j++) { + element[j].checked = (values.findIndex(it => it.toString() === element[j].value) > -1); + } + break; + } + case 'select-multiple': { + let values = value.constructor === Array ? value : [value]; + for (let j = 0; j < element.options.length; j++) { + element.options[j].selected = (values.findIndex(it => it.toString() === element.options[j].value) > -1); + } + break; + } + case 'select': + case 'select-one': + element.value = value.toString() || value; + break; + + case 'date': + let date = new Date(value); + date.setMinutes(date.getMinutes() - date.getTimezoneOffset()); + element.value = date.toISOString().substring(0, 10); + break; + + case 'datetime-local': + let datetime = new Date(value); + datetime.setMinutes(datetime.getMinutes() - datetime.getTimezoneOffset()); + element.value = datetime.toISOString().substring(0, 16); + break; + } + + } +} diff --git a/_ont/ont-huawei-ma5671a-rooted.md b/_ont/ont-huawei-ma5671a-rooted.md index 93bace53..222b4c4c 100644 --- a/_ont/ont-huawei-ma5671a-rooted.md +++ b/_ont/ont-huawei-ma5671a-rooted.md @@ -20,20 +20,35 @@ layout: default +
+ +
+
+ + +
+
+ + +
- - + +
- - + + +
+
+ +
- +
@@ -47,7 +62,26 @@ layout: default var fomrdata = new FormData(form); var sfp_a2_info = fomrdata.get('sfp-a2-info'); var sfp_a2_info_arr = sfp_a2_info.split('@'); - if(sfp_a2_info_arr.length > 10 && sfp_a2_info_arr[0] === 'begin-base64 644 sfp_a2_info ') { + var sfp_a2_info_0 = sfp_a2_info_arr.splice(0); + var sfp_a2_decode = sfp_a2_info_arr.map(it => base64ToHex(it)).join(''); + var eeprom = new eeprom1(sfp_a2_decode); + console.log(eeprom); + if(fomrdata.get('submit') == "Show!") { + fomrdata.set('gpon-serial', eeprom.serial); + fomrdata.set('gpon-ploam', eeprom.ploam); + fomrdata.set('gpon-loid', eeprom.loid); + fomrdata.set('gpon-lpwd', eeprom.lopw); + fomrdata.set('gpon-loid-ploam-switch', eeprom.loidPloamSwitch); + populateForm(form, fomrdata); + } else { + eeprom.serial = fomrdata.get('gpon-serial'); + eeprom.ploam = fomrdata.get('gpon-ploam'); + eeprom.loid = fomrdata.get('gpon-loid'); + eeprom.lopw = fomrdata.get('gpon-lopw'); + eeprom.loidPloamSwitch = fomrdata.get('gpon-loid-ploam-switch'); + document.getElementById('result').value = eeprom.hex; + } + /*if(sfp_a2_info_arr.length > 10 && sfp_a2_info_arr[0] === 'begin-base64 644 sfp_a2_info ') { var gpon_sn = fomrdata.get('gpon-sn'); if(gpon_sn.length == 12) { var vendor_id = gpon_sn.substring(0, 4); @@ -84,11 +118,10 @@ layout: default var hex = base64ToHex(sfp_a2_info_arr[9]); hex = hex.substring(0,48) + mac_addr + hex.substring(61); sfp_a2_info_arr[9] = hexToBase64(hex); - } - document.getElementById('result').value = sfp_a2_info_arr.join('@'); + } } else { document.getElementById('result').value = 'sfp_a2_info variable in wrong format!'; - } + }*/ }); function hexToBase64(hexStr) { return btoa([...hexStr].reduce((acc, _, i) => acc += !(i - 1 & 1) ? String.fromCharCode(parseInt(hexStr.substring(i - 1, i + 1), 16)) : '', '')); From 433faeedcc79779f5bc734a435b63c5352ea4721 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Wed, 8 Feb 2023 14:26:37 +0100 Subject: [PATCH 05/20] update --- _ont/ont-huawei-ma5671a-rooted.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/_ont/ont-huawei-ma5671a-rooted.md b/_ont/ont-huawei-ma5671a-rooted.md index 222b4c4c..81e72ddf 100644 --- a/_ont/ont-huawei-ma5671a-rooted.md +++ b/_ont/ont-huawei-ma5671a-rooted.md @@ -132,10 +132,18 @@ layout: default {:style="counter-reset:none"} -2. Transfer modified file back into variable `sfp_a2_info`, replace `` with the output of web form. +{% include alert.html content="Executing these commands requires a minimum of familiarity with `vim`. If you do not know `vim`, follow the commands precisely." alert="Danger" icon="svg-warning" color="red" %} + + +1. Copy the script's output to the clipboard +1. Run the comman `vim /tmp/sfp_a2.txt` in the stick +1. Press the right mouse button in the terminal or `CTRL`+`V` +1. Press `ESC` command from keyboard +1. Type `:wq` +1. Run: ```shell -fw_setenv sfp_a2_info "" +fw_setenv sfp_a2_info ($cat /tmp/sfp_a2.txt) ``` ## Temporary file procedure From 82cc5680d138774bc67e8914830683a4c3bc5102 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Wed, 8 Feb 2023 14:28:11 +0100 Subject: [PATCH 06/20] fix --- _ont/ont-huawei-ma5671a-rooted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_ont/ont-huawei-ma5671a-rooted.md b/_ont/ont-huawei-ma5671a-rooted.md index 81e72ddf..d8071e28 100644 --- a/_ont/ont-huawei-ma5671a-rooted.md +++ b/_ont/ont-huawei-ma5671a-rooted.md @@ -132,7 +132,7 @@ layout: default {:style="counter-reset:none"} -{% include alert.html content="Executing these commands requires a minimum of familiarity with `vim`. If you do not know `vim`, follow the commands precisely." alert="Danger" icon="svg-warning" color="red" %} +{% include alert.html content="Executing these commands requires a minimum of familiarity with `vim`. If you do not know `vim`, follow the commands precisely." alert="Danger" icon="svg-warning" color="red" %} 1. Copy the script's output to the clipboard From 960c5b9aadaab7114b0bb5592c9d65954f059526 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Wed, 8 Feb 2023 17:14:24 +0100 Subject: [PATCH 07/20] update --- _includes/js/custom.js | 127 ++++-- _ont/ont-huawei-ma5671a-rooted.md | 36 +- _tools/ont-lantiq-print-eeprom.md | 731 ++++++++++++++++++++++++++++++ 3 files changed, 837 insertions(+), 57 deletions(-) create mode 100644 _tools/ont-lantiq-print-eeprom.md diff --git a/_includes/js/custom.js b/_includes/js/custom.js index 228f2ee3..bd1dcfd4 100644 --- a/_includes/js/custom.js +++ b/_includes/js/custom.js @@ -142,7 +142,7 @@ class uuencoding { function getChunks(s, i) { var a = []; - do{ a.push(s.substring(0, i)) } while( (s = s.substring(i)) != "" ); + do { a.push(s.substring(0, i)) } while ((s = s.substring(i)) != ""); return a; } @@ -150,13 +150,13 @@ class asciiHex { static asciiToHex(str, prefix = "0x", glue = " ") { var prefixi = glue !== "" ? prefix : ""; var prefixs = glue === "" ? prefix : ""; - var hex = prefixs + ([...str].map((elem, n) => prefixi+Number(str.charCodeAt(n)).toString(16)).join(glue)); + var hex = prefixs + ([...str].map((elem, n) => prefixi + Number(str.charCodeAt(n)).toString(16)).join(glue)); return hex; } static hexToAscii(str, prefix = "0x", separator = " ") { - if(prefix != "" && str.startsWith(prefix)) + if (prefix != "" && str.startsWith(prefix)) str = str.substring(prefix.length); - var ascii = separator === "" ? getChunks(str.substring(2),2).map(el => String.fromCharCode(parseInt(el, 16))).join('') : str.split(separator).map(el => String.fromCharCode(Number(el))).join(''); + var ascii = separator === "" ? getChunks(str.substring(2), 2).map(el => String.fromCharCode(parseInt(el, 16))).join('') : str.split(separator).map(el => String.fromCharCode(Number(el))).join(''); return ascii; } } @@ -165,27 +165,27 @@ class gponSerial { #vendor; #progressive; constructor(vendor, progressive) { - if(progressive !== undefined) { - if(vendor.length == 4) { + if (progressive !== undefined) { + if (vendor.length == 4) { this.#vendor = vendor.toUpperCase(); - } else if(vendor.length == 8) { - this.#vendor = asciiHex.hexToAscii(vendor,'','').toUpperCase(); + } else if (vendor.length == 8) { + this.#vendor = asciiHex.hexToAscii(vendor, '', '').toUpperCase(); } else { throw "vendor length unvalid"; } - if(progressive.length == 8) { + if (progressive.length == 8) { this.#progressive = progressive.toLowerCase(); } else { throw "progressive length unvalid"; } } else { - if(vendor.length == 12) { + if (vendor.length == 12) { this.#vendor = vendor.substring(0, 4).toUpperCase(); this.#progressive = vendor.substring(4).toLowerCase(); - } else if(vendor.length == 16) { + } else if (vendor.length == 16) { this.#vendor = asciiHex.hexToAscii(serial.substring(0, 8)).toUpperCase(); this.#progressive = vendor.substring(8).toLowerCase(); - } else { + } else { throw "serial length unvalid"; } } @@ -201,17 +201,17 @@ class gponSerial { } get serial() { return `${this.#vendor}${this.#progressive}`; - } + } } class gponPloam { #ploam; constructor(ploam) { - if(ploam.length <= 10) { + if (ploam.length <= 10) { this.#ploam = ([...gpon_password].map((_, n) => Number(gpon_password.charCodeAt(n)).toString(16)).join('')); - this.#ploam += '0'.repeat(20-gpon_password.length); + this.#ploam += '0'.repeat(20 - gpon_password.length); } - else if(ploam.length === 20) { + else if (ploam.length === 20) { this.#ploam = ploam; } else { @@ -219,7 +219,7 @@ class gponPloam { } } get ploam() { - return asciiHex.hexToAscii(this.#ploam, '',''); + return asciiHex.hexToAscii(this.#ploam, '', ''); } get ploamEncoding() { return JSON.stringify(ploam); @@ -229,28 +229,31 @@ class gponPloam { } } -class eeprom1 { +class eeprom { #hex; - constructor(hex) { + constructor(hex, size=256) { this.#hex = [...hex]; + if (this.#hex.length < size*2) throw new Error('EEPROM size error!'); } - getPart = function(startIndex, endIndex) { - return this.#hex.slice(startIndex*2, (endIndex+1)*2).join(''); + getPart = function (startIndex, endIndex) { + return this.#hex.slice(startIndex * 2, (endIndex + 1) * 2).join(''); } - setPart = function(startIndex, endIndex, value) { - let calcLength = (endIndex+1-startIndex)*2; - if(value.length != calcLength) { - value += '0'.repeat(calcLength-value.length); - } - this.#hex.splice(startIndex*2, calcLength, ...[...value]); + setPart = function (startIndex, endIndex, value) { + let calcLength = (endIndex + 1 - startIndex) * 2; + if (value.length != calcLength) { + value += '0'.repeat(calcLength - value.length); + } + this.#hex.splice(startIndex * 2, calcLength, ...[...value]); } get hex() { - return this.#hex.join(''); + return this.#hex.join(''); } +} +class eeprom1 extends eeprom { get serial() { return this.getPart(233, 240); } @@ -332,19 +335,19 @@ function populateForm(form, data, basename) { value = ''; // add basename - if (typeof(basename) !== "undefined") + if (typeof (basename) !== "undefined") name = basename + "-" + key; if (value.constructor === Array) { - if(typeof(basename) !== "undefined") + if (typeof (basename) !== "undefined") name += '[]'; - } else if(typeof value == "object") { - if(Object.keys(value).length === 1) { - if (typeof(basename) !== "undefined") + } else if (typeof value == "object") { + if (Object.keys(value).length === 1) { + if (typeof (basename) !== "undefined") name += "-" + Object.keys(value)[0]; value = value[Object.keys(value)[0]]; } else { - if (typeof(basename) !== "undefined") + if (typeof (basename) !== "undefined") populateForm(form, value, name); else populateForm(form, value); @@ -354,13 +357,13 @@ function populateForm(form, data, basename) { // only proceed if element is set let element = form.elements.namedItem(name); - if (! element) { + if (!element) { continue; } let type = element.type || element[0].type; - switch(type ) { + switch (type) { default: element.value = value; break; @@ -400,3 +403,55 @@ function populateForm(form, data, basename) { } } + + +var _table_ = document.createElement('table'), + _tr_ = document.createElement('tr'), + _th_ = document.createElement('th'), + _td_ = document.createElement('td'); + +// Builds the HTML Table out of myList json data from Ivy restful service. +function buildHtmlTable(arr) { + var table = _table_.cloneNode(false), + columns = addAllColumnHeaders(arr, table); + for (var i = 0, maxi = arr.length; i < maxi; ++i) { + var tr = _tr_.cloneNode(false); + for (var j = 0, maxj = columns.length; j < maxj; ++j) { + var td = _td_.cloneNode(false); + var cellValue = arr[i][columns[j]]; + td.appendChild(document.createTextNode(arr[i][columns[j]] || '')); + tr.appendChild(td); + } + table.appendChild(tr); + } + return table; +} + +// Adds a header row to the table and returns the set of columns. +// Need to do union of keys from all records as some records may not contain +// all records +function addAllColumnHeaders(arr, table) { + var columnSet = [], + tr = _tr_.cloneNode(false); + for (var i = 0, l = arr.length; i < l; i++) { + for (var key in arr[i]) { + if (arr[i].hasOwnProperty(key) && columnSet.indexOf(key) === -1) { + columnSet.push(key); + var th = _th_.cloneNode(false); + th.appendChild(document.createTextNode(key)); + tr.appendChild(th); + } + } + } + table.appendChild(tr); + return columnSet; +} + +function hexToBase64(hexStr) { + return btoa([...hexStr].reduce((acc, _, i) => acc += !(i - 1 & 1) ? String.fromCharCode(parseInt(hexStr.substring(i - 1, i + 1), 16)) : '', '')); +} +function base64ToHex(base64Value) { + try { + return [...atob(base64Value)].map(c=> c.charCodeAt(0).toString(16).padStart(2,0)).join(''); + } catch { return ''; } +} \ No newline at end of file diff --git a/_ont/ont-huawei-ma5671a-rooted.md b/_ont/ont-huawei-ma5671a-rooted.md index bc15ad86..24d51f34 100644 --- a/_ont/ont-huawei-ma5671a-rooted.md +++ b/_ont/ont-huawei-ma5671a-rooted.md @@ -12,7 +12,7 @@ layout: default ## Web procedure -1. Get `sfp_a2_info` and paste into the form +1. Get `fw_printenv sfp_a2_info` and paste into the form
@@ -55,30 +55,30 @@ layout: default
{:style="counter-reset:none"} diff --git a/_tools/ont-lantiq-print-eeprom.md b/_tools/ont-lantiq-print-eeprom.md new file mode 100644 index 00000000..2f6ec46b --- /dev/null +++ b/_tools/ont-lantiq-print-eeprom.md @@ -0,0 +1,731 @@ +--- +title: Lantiq Print EEPROM +has_children: false +layout: default +--- + +
+
+ + +
+
+ +
+
+ + + +
+
+ + +
+
+ +
+
+ + + + +{% include alert.html content="For more information, see the SFF-8472 Rev 10.2 specification." alert="Info" icon="svg-info" color="blue" %} \ No newline at end of file From 15008a238ac09feb7dcd3ce5c2d77533fc50bb88 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Wed, 8 Feb 2023 17:16:43 +0100 Subject: [PATCH 08/20] fix --- _tools/ont-lantiq-print-eeprom.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_tools/ont-lantiq-print-eeprom.md b/_tools/ont-lantiq-print-eeprom.md index 2f6ec46b..382daa25 100644 --- a/_tools/ont-lantiq-print-eeprom.md +++ b/_tools/ont-lantiq-print-eeprom.md @@ -34,7 +34,7 @@ layout: default var sfp_a2_info_arr = sfp_a2_info.split('@'); var sfp_a2_info_0 = sfp_a2_info_arr.shift(); var sfp_a2_decode = sfp_a2_info_arr.map(it => base64ToHex(it)).join(''); - var eeprom = new eeprom1(sfp_a2_decode); + var eeprom = new eeprom(sfp_a2_decode); var table = eepromTable(eeprom,0); var htmlTable = buildHtmlTable(table); eepromA0.parentNode.insertBefore(htmlTable, eepromA0.nextSibling); From 98e1d01e517b9a07734207336ebc3d1796016a2c Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Wed, 8 Feb 2023 17:30:07 +0100 Subject: [PATCH 09/20] fix --- _ont/ont-huawei-ma5671a-rooted.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/_ont/ont-huawei-ma5671a-rooted.md b/_ont/ont-huawei-ma5671a-rooted.md index 24d51f34..d2721bb4 100644 --- a/_ont/ont-huawei-ma5671a-rooted.md +++ b/_ont/ont-huawei-ma5671a-rooted.md @@ -20,7 +20,7 @@ layout: default
- +
@@ -47,7 +47,7 @@ layout: default
- +
@@ -59,13 +59,14 @@ layout: default var form = document.getElementById('huawei-rooted'); form.addEventListener('submit',(event) => { event.preventDefault(); + console.log(event.submitter.getAttribute('data-js')); var fomrdata = new FormData(form); var sfp_a2_info = fomrdata.get('sfp-a2-info'); var sfp_a2_info_arr = sfp_a2_info.split('@'); var sfp_a2_info_0 = sfp_a2_info_arr.shift(); var sfp_a2_decode = sfp_a2_info_arr.map(it => base64ToHex(it)).join(''); theeeprom = new eeprom1(sfp_a2_decode); - if(fomrdata.get('submit') == "Show!") { + if(event.submitter.getAttribute('data-js') === "show") { fomrdata.set('gpon-serial', theeeprom.serial); fomrdata.set('gpon-ploam', theeeprom.ploam); fomrdata.set('gpon-loid', theeeprom.loid); From 1e416d9a62d7d8f3f3c4092ec271c5206688f8ae Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Wed, 8 Feb 2023 17:42:00 +0100 Subject: [PATCH 10/20] update --- _ont/ont-huawei-ma5671a-rooted.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/_ont/ont-huawei-ma5671a-rooted.md b/_ont/ont-huawei-ma5671a-rooted.md index d2721bb4..0fdcec77 100644 --- a/_ont/ont-huawei-ma5671a-rooted.md +++ b/_ont/ont-huawei-ma5671a-rooted.md @@ -67,12 +67,14 @@ layout: default var sfp_a2_decode = sfp_a2_info_arr.map(it => base64ToHex(it)).join(''); theeeprom = new eeprom1(sfp_a2_decode); if(event.submitter.getAttribute('data-js') === "show") { - fomrdata.set('gpon-serial', theeeprom.serial); - fomrdata.set('gpon-ploam', theeeprom.ploam); - fomrdata.set('gpon-loid', theeeprom.loid); - fomrdata.set('gpon-lpwd', theeeprom.lopw); - fomrdata.set('gpon-loid-ploam-switch', theeeprom.loidPloamSwitch); - populateForm(form, fomrdata); + object = { + 'gpon-serial': theeeprom.serial, + 'gpon-ploam': theeeprom.ploam, + 'gpon-loid': theeeprom.loid, + 'gpon-lpwd': theeeprom.lopw, + 'gpon-loid-ploam-switch': theeeprom.loidPloamSwitch + }; + populateForm(form, object); } else { theeeprom.serial = fomrdata.get('gpon-serial'); theeeprom.ploam = fomrdata.get('gpon-ploam'); From 7d2055e405b8257f90b60fb42039ed0bc01c49b0 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Wed, 8 Feb 2023 17:52:06 +0100 Subject: [PATCH 11/20] update --- _ont/ont-huawei-ma5671a-rooted.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/_ont/ont-huawei-ma5671a-rooted.md b/_ont/ont-huawei-ma5671a-rooted.md index 0fdcec77..6832f92c 100644 --- a/_ont/ont-huawei-ma5671a-rooted.md +++ b/_ont/ont-huawei-ma5671a-rooted.md @@ -64,6 +64,7 @@ layout: default var sfp_a2_info = fomrdata.get('sfp-a2-info'); var sfp_a2_info_arr = sfp_a2_info.split('@'); var sfp_a2_info_0 = sfp_a2_info_arr.shift(); + var sfp_a2_info_last = sfp_a2_info_arr.pop(); var sfp_a2_decode = sfp_a2_info_arr.map(it => base64ToHex(it)).join(''); theeeprom = new eeprom1(sfp_a2_decode); if(event.submitter.getAttribute('data-js') === "show") { @@ -81,7 +82,11 @@ layout: default theeeprom.loid = fomrdata.get('gpon-loid'); theeeprom.lopw = fomrdata.get('gpon-lopw'); theeeprom.loidPloamSwitch = fomrdata.get('gpon-loid-ploam-switch'); - document.getElementById('result').value = theeeprom.hex; + var sfp_a2_new = (theeeprom.hex.match(/.{1,90}/g) ?? []).map(it => hexToBase64(it)); + sfp_a2_new.unshift(sfp_a2_info_0); + sfp_a2_new.push(sfp_a2_info_last); + sfp_a2_new.push(''); + document.getElementById('result').value = sfp_a2_new.join('@'); } /*if(sfp_a2_info_arr.length > 10 && sfp_a2_info_arr[0] === 'begin-base64 644 sfp_a2_info ') { var gpon_sn = fomrdata.get('gpon-sn'); From 37228d6063552b0303c6d5d53bca2f922d2bcf3e Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Thu, 9 Feb 2023 00:49:41 +0100 Subject: [PATCH 12/20] fix --- _includes/js/custom.js | 178 +++++++++++++++++++++++------- _ont/ont-huawei-ma5671a-rooted.md | 71 +++--------- 2 files changed, 154 insertions(+), 95 deletions(-) diff --git a/_includes/js/custom.js b/_includes/js/custom.js index bd1dcfd4..f53fb161 100644 --- a/_includes/js/custom.js +++ b/_includes/js/custom.js @@ -142,7 +142,7 @@ class uuencoding { function getChunks(s, i) { var a = []; - do { a.push(s.substring(0, i)) } while ((s = s.substring(i)) != ""); + do { a.push(s?.substring(0, i)) } while (s = s?.substring(i)); return a; } @@ -154,44 +154,89 @@ class asciiHex { return hex; } static hexToAscii(str, prefix = "0x", separator = " ") { - if (prefix != "" && str.startsWith(prefix)) - str = str.substring(prefix.length); - var ascii = separator === "" ? getChunks(str.substring(2), 2).map(el => String.fromCharCode(parseInt(el, 16))).join('') : str.split(separator).map(el => String.fromCharCode(Number(el))).join(''); + if(prefix) + str = stripHexPrefix(str, prefix); + var ascii = separator === "" ? getChunks(str, 2).map(el => String.fromCharCode(parseInt(el, 16))).join('') : str.split(separator).map(el => String.fromCharCode(Number(el))).join(''); return ascii; } } + +function isHexPrefixed(str, prefix = '0x') { + if (typeof str !== 'string') { + throw new Error("[is-hex-prefixed] value must be type 'string', is currently type " + (typeof str) + ", while checking isHexPrefixed."); + } + + return str.slice(0, 2) === prefix; +} + +function stripHexPrefix(str, prefix = '0x') { + if (typeof str !== 'string') { + return str; + } + + return isHexPrefixed(str, prefix) ? str.slice(prefix.length) : str; +} + +class mac { + #mac; + constructor(mac) { + if(mac.length == 12) { + this.#mac = mac; + } + if(mac.length == 14) { + this.#mac = stripHexPrefix(mac); + } + if(mac.length == 17) { + this.#mac = mac.split(mac[2]).join(''); + } + } + get hex() { + return this.#mac; + } + + prettier(glue=':') { + return getChunks(this.#mac,2).join(glue); + } +} + class gponSerial { #vendor; #progressive; - constructor(vendor, progressive) { - if (progressive !== undefined) { - if (vendor.length == 4) { - this.#vendor = vendor.toUpperCase(); - } else if (vendor.length == 8) { - this.#vendor = asciiHex.hexToAscii(vendor, '', '').toUpperCase(); + constructor(first, second) { + first = first.replace(/\0/g, ''); + second = second?.replace(/\0/g, ''); + if (second !== undefined) { + if (first.length == 4) { + this.#vendor = first.toUpperCase(); + } else if (first.length == 8) { + this.#vendor = asciiHex.hexToAscii(first, '', '').toUpperCase(); } else { throw "vendor length unvalid"; } - if (progressive.length == 8) { - this.#progressive = progressive.toLowerCase(); + if (second.length == 8) { + this.#progressive = second.toLowerCase(); } else { throw "progressive length unvalid"; } } else { - if (vendor.length == 12) { - this.#vendor = vendor.substring(0, 4).toUpperCase(); - this.#progressive = vendor.substring(4).toLowerCase(); - } else if (vendor.length == 16) { - this.#vendor = asciiHex.hexToAscii(serial.substring(0, 8)).toUpperCase(); - this.#progressive = vendor.substring(8).toLowerCase(); + if (first.length == 12) { + this.#vendor = first.substring(0, 4).toUpperCase(); + this.#progressive = first.substring(4).toLowerCase(); + } else if (first.length == 16) { + this.#vendor = asciiHex.hexToAscii(first.substring(0, 8), '', '').toUpperCase(); + this.#progressive = first.substring(8).toLowerCase(); + } else if (first.length == 18) { + first = stripHexPrefix(first); + this.#vendor = asciiHex.hexToAscii(first.substring(0, 8), '', '').toUpperCase(); + this.#progressive = first.substring(8).toLowerCase(); } else { throw "serial length unvalid"; } } } get vendorHex() { - return ([...this.#vendor].map((_, n) => Number(this.#vendor.charCodeAt(n)).toString(16)).join('')); + return asciiHex.asciiToHex(this.#vendor,'',''); } get vendor() { return this.#vendor; @@ -202,17 +247,34 @@ class gponSerial { get serial() { return `${this.#vendor}${this.#progressive}`; } + get serialHex() { + return `${this.vendorHex}${this.#progressive}`; + } +} + +class gponHexItem { + #value; + constructor(value) { + value = stripHexPrefix(value); + } + get hex() { + return this.#value; + } + get ascii() { + return asciiHex.hexToAscii(this.#value, '', ''); + } } class gponPloam { #ploam; constructor(ploam) { + ploam = ploam.replace(/\0/g, ''); if (ploam.length <= 10) { - this.#ploam = ([...gpon_password].map((_, n) => Number(gpon_password.charCodeAt(n)).toString(16)).join('')); - this.#ploam += '0'.repeat(20 - gpon_password.length); + this.#ploam = asciiHex.asciiToHex(ploam,'',''); + this.#ploam += '0'.repeat(20 - this.#ploam.length); } - else if (ploam.length === 20) { - this.#ploam = ploam; + else if (ploam.length >= 20) { + this.#ploam = stripHexPrefix(ploam); } else { throw "ploam length unvalid"; @@ -242,6 +304,9 @@ class eeprom { setPart = function (startIndex, endIndex, value) { let calcLength = (endIndex + 1 - startIndex) * 2; + if(!value) { + return; + } if (value.length != calcLength) { value += '0'.repeat(calcLength - value.length); } @@ -255,35 +320,58 @@ class eeprom { class eeprom1 extends eeprom { get serial() { - return this.getPart(233, 240); + return new gponSerial(this.getPart(233, 240)); } set serial(value) { - this.setPart(233, 240, value); + if(value instanceof gponSerial) { + this.setPart(233, 240, value.serialHex); + } else { + this.setPart(233, 240, value); + } } get ploam() { - return this.getPart(191, 214); + return this.loidPloamSwitch === "02" ? new gponPloam(this.getPart(191, 214)) : undefined; } set ploam(value) { - this.setPart(191, 214, value); + if(this.loidPloamSwitch === "02") { + if(value instanceof gponPloam) { + console.log(this.getPart(191, 214)); + console.log(value.ploam); + console.log(value.ploamHex); + this.setPart(191, 214, value.ploamHex); + } else { + this.setPart(191, 214, value); + } + } } get loid() { - return this.getPart(191, 214); + return this.loidPloamSwitch === "01" ? new gponHexItem(this.getPart(191, 214)) : undefined; } set loid(value) { - this.setPart(191, 214, value); + if(this.loidPloamSwitch === "01") { + if(value instanceof gponHexItem) { + this.setPart(191, 214, value.hex); + } else { + this.setPart(191, 214, value); + } + } } - get lpwd() { - return this.getPart(215, 231); + get lopw() { + return new gponHexItem(this.getPart(215, 231)); } - set lpwd(value) { - this.setPart(215, 231, value); + set lopw(value) { + if(value instanceof gponHexItem) { + this.setPart(215, 231, value.hex); + } else { + this.setPart(215, 231, value); + } } get loidPloamSwitch() { @@ -295,27 +383,39 @@ class eeprom1 extends eeprom { } get equipmentID() { - return this.getPart(512, 531); + return new gponHexItem(this.getPart(512, 531)); } set equipmentID(value) { - this.setPart(512, 531, value); + if(value instanceof gponHexItem) { + this.setPart(512, 531, value.hex); + } else { + this.setPart(512, 531, value); + } } get vendorID() { - return this.getPart(532, 535); + return new gponHexItem(this.getPart(532, 535)); } set vendorID(value) { - this.setPart(532, 535, value); + if(value instanceof gponHexItem) { + this.setPart(532, 535, value.hex); + } else { + this.setPart(532, 535, value); + } } get macAddress() { - return this.getPart(384, 389); + return new mac(this.getPart(384, 389)); } set macAddress(value) { - this.setPart(384, 389, value); + if(value instanceof mac) { + this.setPart(384, 389, value.hex); + } else { + this.setPart(384, 389, value); + } } } diff --git a/_ont/ont-huawei-ma5671a-rooted.md b/_ont/ont-huawei-ma5671a-rooted.md index 6832f92c..162c9224 100644 --- a/_ont/ont-huawei-ma5671a-rooted.md +++ b/_ont/ont-huawei-ma5671a-rooted.md @@ -54,81 +54,40 @@ layout: default
- From 88880fa08826a59a40c3723235dbb53620b12bf6 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Fri, 10 Feb 2023 00:17:30 +0100 Subject: [PATCH 13/20] migrated to vue --- _includes/js/custom.js | 557 ------------- _ont/ont-huawei-ma5671a-rooted.md | 87 +- _tools/ont-lantiq-print-eeprom.md | 728 +---------------- assets/js/vue-eeprom.js | 28 + assets/js/vue/vue-lantiq-eeprom.vue | 1142 +++++++++++++++++++++++++++ 5 files changed, 1185 insertions(+), 1357 deletions(-) delete mode 100644 _includes/js/custom.js create mode 100644 assets/js/vue-eeprom.js create mode 100644 assets/js/vue/vue-lantiq-eeprom.vue diff --git a/_includes/js/custom.js b/_includes/js/custom.js deleted file mode 100644 index f53fb161..00000000 --- a/_includes/js/custom.js +++ /dev/null @@ -1,557 +0,0 @@ -class uuencoding { - /** - * uuencode a value - * - * @param {(String|Buffer)} The value to be encoded. - * @returns {String} The encoded value. - */ - static encode(inString) { - var stop = false; - var inIndex = 0; - var outIndex = 0; - var bytesRead = 0; - - var inBytes = new Buffer(inString); - var buffLen = inBytes.length; - var outBytes = new Buffer(buffLen + buffLen / 3 + 1 + buffLen / 45 * 2 + 2 + 4); - - do { - var n; - var bytesLeft = buffLen - bytesRead; - - if (bytesLeft === 0) { - break; - } - - if (bytesLeft <= 45) { - n = bytesLeft; - } else { - n = 45; - } - - outBytes[outIndex++] = (n & 0x3F) + 32; - - for (var i = 0; i < n; i += 3) { - if (buffLen - inIndex < 3) { - var padding = new Array(3); - var z = 0; - - while (inIndex + z < buffLen) { - padding[z] = inBytes[inIndex + z]; - ++z; - } - - this.#encodeBytes(padding, 0, outBytes, outIndex); - } else { - this.#encodeBytes(inBytes, inIndex, outBytes, outIndex); - } - - inIndex += 3; - outIndex += 4; - } - - outBytes[outIndex++] = 10; - bytesRead += n; - - if (n >= 45) { - continue; - } - - stop = true; - } while (!stop); - - return outBytes.toString().substring(0, outIndex); - } - - /** - * uudecode a value - * - * @param {(String|Buffer)} The value to be decoded. - * @returns {Buffer} The decoded value. - */ - static decode(inString) { - var stop = false; - var inIndex = 0; - var outIndex = 0; - var totalLen = 0; - - var inBytes = new Buffer(inString); - var buffLen = inBytes.length; - var outBytes = new Buffer(buffLen); - - do { - if (inIndex < buffLen) { - var n = inBytes[inIndex] - 32 & 0x3F; - - ++inIndex; - - if (n > 45) { - throw 'Invalid Data'; - } - - if (n < 45) { - stop = true; - } - - totalLen += n; - - while (n > 0) { - this.#decodeChars(inBytes, inIndex, outBytes, outIndex); - outIndex += 3; - inIndex += 4; - n -= 3; - } - - ++inIndex; - } else { - stop = true; - } - } while (!stop); - - return outBytes.slice(0, totalLen); - } - - // private helper functions - static #encodeBytes(inBytes, inIndex, outBytes, outIndex) { - var c1 = inBytes[inIndex] >>> 2; - var c2 = inBytes[inIndex] << 4 & 0x30 | inBytes[inIndex + 1] >>> 4 & 0xF; - var c3 = inBytes[inIndex + 1] << 2 & 0x3C | inBytes[inIndex + 2] >>> 6 & 0x3; - var c4 = inBytes[inIndex + 2] & 0x3F; - - outBytes[outIndex] = (c1 & 0x3F) + 32; - outBytes[outIndex + 1] = (c2 & 0x3F) + 32; - outBytes[outIndex + 2] = (c3 & 0x3F) + 32; - outBytes[outIndex + 3] = (c4 & 0x3F) + 32; - } - - static #decodeChars(inBytes, inIndex, outBytes, outIndex) { - var c1 = inBytes[inIndex]; - var c2 = inBytes[inIndex + 1]; - var c3 = inBytes[inIndex + 2]; - var c4 = inBytes[inIndex + 3]; - - var b1 = (c1 - 32 & 0x3F) << 2 | (c2 - 32 & 0x3F) >> 4; - var b2 = (c2 - 32 & 0x3F) << 4 | (c3 - 32 & 0x3F) >> 2; - var b3 = (c3 - 32 & 0x3F) << 6 | c4 - 32 & 0x3F; - - outBytes[outIndex] = b1 & 0xFF; - outBytes[outIndex + 1] = b2 & 0xFF; - outBytes[outIndex + 2] = b3 & 0xFF; - } -} - -function getChunks(s, i) { - var a = []; - do { a.push(s?.substring(0, i)) } while (s = s?.substring(i)); - return a; -} - -class asciiHex { - static asciiToHex(str, prefix = "0x", glue = " ") { - var prefixi = glue !== "" ? prefix : ""; - var prefixs = glue === "" ? prefix : ""; - var hex = prefixs + ([...str].map((elem, n) => prefixi + Number(str.charCodeAt(n)).toString(16)).join(glue)); - return hex; - } - static hexToAscii(str, prefix = "0x", separator = " ") { - if(prefix) - str = stripHexPrefix(str, prefix); - var ascii = separator === "" ? getChunks(str, 2).map(el => String.fromCharCode(parseInt(el, 16))).join('') : str.split(separator).map(el => String.fromCharCode(Number(el))).join(''); - return ascii; - } -} - - -function isHexPrefixed(str, prefix = '0x') { - if (typeof str !== 'string') { - throw new Error("[is-hex-prefixed] value must be type 'string', is currently type " + (typeof str) + ", while checking isHexPrefixed."); - } - - return str.slice(0, 2) === prefix; -} - -function stripHexPrefix(str, prefix = '0x') { - if (typeof str !== 'string') { - return str; - } - - return isHexPrefixed(str, prefix) ? str.slice(prefix.length) : str; -} - -class mac { - #mac; - constructor(mac) { - if(mac.length == 12) { - this.#mac = mac; - } - if(mac.length == 14) { - this.#mac = stripHexPrefix(mac); - } - if(mac.length == 17) { - this.#mac = mac.split(mac[2]).join(''); - } - } - get hex() { - return this.#mac; - } - - prettier(glue=':') { - return getChunks(this.#mac,2).join(glue); - } -} - -class gponSerial { - #vendor; - #progressive; - constructor(first, second) { - first = first.replace(/\0/g, ''); - second = second?.replace(/\0/g, ''); - if (second !== undefined) { - if (first.length == 4) { - this.#vendor = first.toUpperCase(); - } else if (first.length == 8) { - this.#vendor = asciiHex.hexToAscii(first, '', '').toUpperCase(); - } else { - throw "vendor length unvalid"; - } - if (second.length == 8) { - this.#progressive = second.toLowerCase(); - } else { - throw "progressive length unvalid"; - } - } else { - if (first.length == 12) { - this.#vendor = first.substring(0, 4).toUpperCase(); - this.#progressive = first.substring(4).toLowerCase(); - } else if (first.length == 16) { - this.#vendor = asciiHex.hexToAscii(first.substring(0, 8), '', '').toUpperCase(); - this.#progressive = first.substring(8).toLowerCase(); - } else if (first.length == 18) { - first = stripHexPrefix(first); - this.#vendor = asciiHex.hexToAscii(first.substring(0, 8), '', '').toUpperCase(); - this.#progressive = first.substring(8).toLowerCase(); - } else { - throw "serial length unvalid"; - } - } - } - get vendorHex() { - return asciiHex.asciiToHex(this.#vendor,'',''); - } - get vendor() { - return this.#vendor; - } - get progressive() { - return this.#progressive; - } - get serial() { - return `${this.#vendor}${this.#progressive}`; - } - get serialHex() { - return `${this.vendorHex}${this.#progressive}`; - } -} - -class gponHexItem { - #value; - constructor(value) { - value = stripHexPrefix(value); - } - get hex() { - return this.#value; - } - get ascii() { - return asciiHex.hexToAscii(this.#value, '', ''); - } -} - -class gponPloam { - #ploam; - constructor(ploam) { - ploam = ploam.replace(/\0/g, ''); - if (ploam.length <= 10) { - this.#ploam = asciiHex.asciiToHex(ploam,'',''); - this.#ploam += '0'.repeat(20 - this.#ploam.length); - } - else if (ploam.length >= 20) { - this.#ploam = stripHexPrefix(ploam); - } - else { - throw "ploam length unvalid"; - } - } - get ploam() { - return asciiHex.hexToAscii(this.#ploam, '', ''); - } - get ploamEncoding() { - return JSON.stringify(ploam); - } - get ploamHex() { - return this.#ploam; - } -} - -class eeprom { - #hex; - constructor(hex, size=256) { - this.#hex = [...hex]; - if (this.#hex.length < size*2) throw new Error('EEPROM size error!'); - } - - getPart = function (startIndex, endIndex) { - return this.#hex.slice(startIndex * 2, (endIndex + 1) * 2).join(''); - } - - setPart = function (startIndex, endIndex, value) { - let calcLength = (endIndex + 1 - startIndex) * 2; - if(!value) { - return; - } - if (value.length != calcLength) { - value += '0'.repeat(calcLength - value.length); - } - this.#hex.splice(startIndex * 2, calcLength, ...[...value]); - } - - get hex() { - return this.#hex.join(''); - } -} - -class eeprom1 extends eeprom { - get serial() { - return new gponSerial(this.getPart(233, 240)); - } - - set serial(value) { - if(value instanceof gponSerial) { - this.setPart(233, 240, value.serialHex); - } else { - this.setPart(233, 240, value); - } - } - - get ploam() { - return this.loidPloamSwitch === "02" ? new gponPloam(this.getPart(191, 214)) : undefined; - } - - set ploam(value) { - if(this.loidPloamSwitch === "02") { - if(value instanceof gponPloam) { - console.log(this.getPart(191, 214)); - console.log(value.ploam); - console.log(value.ploamHex); - this.setPart(191, 214, value.ploamHex); - } else { - this.setPart(191, 214, value); - } - } - } - - get loid() { - return this.loidPloamSwitch === "01" ? new gponHexItem(this.getPart(191, 214)) : undefined; - } - - set loid(value) { - if(this.loidPloamSwitch === "01") { - if(value instanceof gponHexItem) { - this.setPart(191, 214, value.hex); - } else { - this.setPart(191, 214, value); - } - } - } - - get lopw() { - return new gponHexItem(this.getPart(215, 231)); - } - - set lopw(value) { - if(value instanceof gponHexItem) { - this.setPart(215, 231, value.hex); - } else { - this.setPart(215, 231, value); - } - } - - get loidPloamSwitch() { - return this.getPart(232, 232); - } - - set loidPloamSwitch(value) { - this.setPart(232, 232, value); - } - - get equipmentID() { - return new gponHexItem(this.getPart(512, 531)); - } - - set equipmentID(value) { - if(value instanceof gponHexItem) { - this.setPart(512, 531, value.hex); - } else { - this.setPart(512, 531, value); - } - } - - get vendorID() { - return new gponHexItem(this.getPart(532, 535)); - } - - set vendorID(value) { - if(value instanceof gponHexItem) { - this.setPart(532, 535, value.hex); - } else { - this.setPart(532, 535, value); - } - } - - get macAddress() { - return new mac(this.getPart(384, 389)); - } - - set macAddress(value) { - if(value instanceof mac) { - this.setPart(384, 389, value.hex); - } else { - this.setPart(384, 389, value); - } - } -} - -function populateForm(form, data, basename) { - for (const key in data) { - if (!data.hasOwnProperty(key)) { - continue; - } - - let name = key; - let value = data[key]; - - if ('undefined' === typeof value) - value = ''; - - if (null === value) - value = ''; - - // add basename - if (typeof (basename) !== "undefined") - name = basename + "-" + key; - - if (value.constructor === Array) { - if (typeof (basename) !== "undefined") - name += '[]'; - } else if (typeof value == "object") { - if (Object.keys(value).length === 1) { - if (typeof (basename) !== "undefined") - name += "-" + Object.keys(value)[0]; - value = value[Object.keys(value)[0]]; - } else { - if (typeof (basename) !== "undefined") - populateForm(form, value, name); - else - populateForm(form, value); - continue; - } - } - - // only proceed if element is set - let element = form.elements.namedItem(name); - if (!element) { - continue; - } - - let type = element.type || element[0].type; - - switch (type) { - default: - element.value = value; - break; - - case 'radio': - case 'checkbox': { - let values = value.constructor === Array ? value : [value]; - for (let j = 0; j < element.length; j++) { - element[j].checked = (values.findIndex(it => it.toString() === element[j].value) > -1); - } - break; - } - case 'select-multiple': { - let values = value.constructor === Array ? value : [value]; - for (let j = 0; j < element.options.length; j++) { - element.options[j].selected = (values.findIndex(it => it.toString() === element.options[j].value) > -1); - } - break; - } - case 'select': - case 'select-one': - element.value = value.toString() || value; - break; - - case 'date': - let date = new Date(value); - date.setMinutes(date.getMinutes() - date.getTimezoneOffset()); - element.value = date.toISOString().substring(0, 10); - break; - - case 'datetime-local': - let datetime = new Date(value); - datetime.setMinutes(datetime.getMinutes() - datetime.getTimezoneOffset()); - element.value = datetime.toISOString().substring(0, 16); - break; - } - - } -} - - -var _table_ = document.createElement('table'), - _tr_ = document.createElement('tr'), - _th_ = document.createElement('th'), - _td_ = document.createElement('td'); - -// Builds the HTML Table out of myList json data from Ivy restful service. -function buildHtmlTable(arr) { - var table = _table_.cloneNode(false), - columns = addAllColumnHeaders(arr, table); - for (var i = 0, maxi = arr.length; i < maxi; ++i) { - var tr = _tr_.cloneNode(false); - for (var j = 0, maxj = columns.length; j < maxj; ++j) { - var td = _td_.cloneNode(false); - var cellValue = arr[i][columns[j]]; - td.appendChild(document.createTextNode(arr[i][columns[j]] || '')); - tr.appendChild(td); - } - table.appendChild(tr); - } - return table; -} - -// Adds a header row to the table and returns the set of columns. -// Need to do union of keys from all records as some records may not contain -// all records -function addAllColumnHeaders(arr, table) { - var columnSet = [], - tr = _tr_.cloneNode(false); - for (var i = 0, l = arr.length; i < l; i++) { - for (var key in arr[i]) { - if (arr[i].hasOwnProperty(key) && columnSet.indexOf(key) === -1) { - columnSet.push(key); - var th = _th_.cloneNode(false); - th.appendChild(document.createTextNode(key)); - tr.appendChild(th); - } - } - } - table.appendChild(tr); - return columnSet; -} - -function hexToBase64(hexStr) { - return btoa([...hexStr].reduce((acc, _, i) => acc += !(i - 1 & 1) ? String.fromCharCode(parseInt(hexStr.substring(i - 1, i + 1), 16)) : '', '')); -} -function base64ToHex(base64Value) { - try { - return [...atob(base64Value)].map(c=> c.charCodeAt(0).toString(16).padStart(2,0)).join(''); - } catch { return ''; } -} \ No newline at end of file diff --git a/_ont/ont-huawei-ma5671a-rooted.md b/_ont/ont-huawei-ma5671a-rooted.md index 162c9224..95d579ef 100644 --- a/_ont/ont-huawei-ma5671a-rooted.md +++ b/_ont/ont-huawei-ma5671a-rooted.md @@ -14,87 +14,16 @@ layout: default 1. Get `fw_printenv sfp_a2_info` and paste into the form -
-
- - -
-
- -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
-
- - -
-
- - -{:style="counter-reset:none"} -{% include alert.html content="Executing these commands requires a minimum of familiarity with `vim`. If you do not know `vim`, follow the commands precisely." alert="Danger" icon="svg-warning" color="red" %} +
+ +
+ + + +{% include alert.html content="Executing these commands requires a minimum of familiarity with `vim`. If you do not know `vim`, follow the commands precisely." alert="Danger" icon="svg-warning" color="red" %} +{:style="counter-reset:none"} 1. Copy the script's output to the clipboard 1. Run the comman `vim /tmp/sfp_a2.txt` in the stick 1. Press the right mouse button in the terminal or `CTRL`+`V` diff --git a/_tools/ont-lantiq-print-eeprom.md b/_tools/ont-lantiq-print-eeprom.md index 382daa25..6d95ebf9 100644 --- a/_tools/ont-lantiq-print-eeprom.md +++ b/_tools/ont-lantiq-print-eeprom.md @@ -4,728 +4,14 @@ has_children: false layout: default --- -
-
- - -
-
- -
-
+1. Get `sfp_a0_low_128` or `sfp_a2_info` and paste into the form - -
-
- - -
-
- -
-
- - - +
+ +
+ + + {% include alert.html content="For more information, see the SFF-8472 Rev 10.2 specification." alert="Info" icon="svg-info" color="blue" %} \ No newline at end of file diff --git a/assets/js/vue-eeprom.js b/assets/js/vue-eeprom.js new file mode 100644 index 00000000..63f9bfb0 --- /dev/null +++ b/assets/js/vue-eeprom.js @@ -0,0 +1,28 @@ +const { createApp } = Vue; +const { loadModule } = window['vue3-sfc-loader']; +const options = { + moduleCache: { + vue: Vue, + }, + getFile(url) { + return fetch(url).then((resp) => + resp.ok ? resp.text() : Promise.reject(resp) + ); + }, + addStyle(styleStr) { + const style = document.createElement('style'); + style.textContent = styleStr; + const ref = document.head.getElementsByTagName('style')[0] || null; + document.head.insertBefore(style, ref); + }, + log(type, ...args) { + console.log(type, ...args); + }, +}; +const app = createApp({ + components: { + VueLantiqEeprom: Vue.defineAsyncComponent(() => + loadModule('/assets/js/vue/vue-lantiq-eeprom.vue', options) + ), + }, +}).mount('#app'); \ No newline at end of file diff --git a/assets/js/vue/vue-lantiq-eeprom.vue b/assets/js/vue/vue-lantiq-eeprom.vue new file mode 100644 index 00000000..18bcb0bd --- /dev/null +++ b/assets/js/vue/vue-lantiq-eeprom.vue @@ -0,0 +1,1142 @@ + + + \ No newline at end of file From d05e95fcf5ea7d9a8ad5b707fe4ad93c724b453c Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Fri, 10 Feb 2023 00:24:14 +0100 Subject: [PATCH 14/20] minor fix --- assets/js/vue/vue-lantiq-eeprom.vue | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/assets/js/vue/vue-lantiq-eeprom.vue b/assets/js/vue/vue-lantiq-eeprom.vue index 18bcb0bd..ced79e67 100644 --- a/assets/js/vue/vue-lantiq-eeprom.vue +++ b/assets/js/vue/vue-lantiq-eeprom.vue @@ -37,7 +37,7 @@
- +
- +
- +
- +
- +
@@ -1029,7 +1029,7 @@ export default { return [...atob(base64Value)].map(c=> c.charCodeAt(0).toString(16).padStart(2,0)).join(''); } catch { return ''; } }, - parseInt2complement: function(bitstring,bitcount) + parseInt2complement: function(bitstring, bitcount) { var value = parseInt(bitstring, 2); @@ -1124,7 +1124,7 @@ export default { return `${parseInt(hex,16)/10}Gbps`; }, asciiToHex: function(str) { - return Number(str.charCodeAt(n)).toString(16).join(''); + return ([...str].map((_, n) => Number(str.charCodeAt(n)).toString(16)).join('')); }, addHexPrefix: function(str, prefix = '0x') { if(this.isHexPrefixed(str, prefix)) return str; From 6f6de9b6d3ab08300552bd04735e0f4f648d2402 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Fri, 10 Feb 2023 00:28:46 +0100 Subject: [PATCH 15/20] clear code --- assets/js/vue/vue-lantiq-eeprom.vue | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/assets/js/vue/vue-lantiq-eeprom.vue b/assets/js/vue/vue-lantiq-eeprom.vue index ced79e67..7dbdf42b 100644 --- a/assets/js/vue/vue-lantiq-eeprom.vue +++ b/assets/js/vue/vue-lantiq-eeprom.vue @@ -734,7 +734,7 @@ export default { "size": "8", "name": "GPON SN", "description": "GPON Serial Number (ME 256)", - "parse": "hexToSN" + "parse": "hexToSerial" }, { "address": "241-247", @@ -853,7 +853,7 @@ export default { }, serial_ascii: { get() { - if(this.serial) return this.hexToAscii(this.serial.substring(0,8))+this.serial.substring(8); + if(this.serial) return this.hexToSerial(this.serial); }, set(value) { if(value.length == 12) @@ -907,7 +907,7 @@ export default { }, loid_ascii: { get() { - if(this.loid) return this.hexToAscii(this.loid.substring(0,20)).replace(/\0/g, ''); + if(this.loid) return this.hexToAscii(this.loid.substring(0,20)); }, set(value) { if(value.length <= 10) @@ -926,7 +926,7 @@ export default { }, lopw_hex: { get() { - if(this.lopw) return this.addHexPrefix(this.lopw.substring(0,20)); + if(this.lopw) return this.hexToAscii(this.lopw.substring(0,20)); }, set(value) { this.lopw = this.stripHexPrefix(value); @@ -934,7 +934,7 @@ export default { }, lopw_ascii: { get() { - if(this.lopw) return this.hexToAscii(this.lopw.substring(0,20)).replace(/\0/g, ''); + if(this.lopw) return this.hexToAscii(this.lopw.substring(0,20)); }, set(value) { if(value.length <= 10) @@ -1062,7 +1062,7 @@ export default { hexToAscii: function (hex) { return this.chunk(hex)?.map(el => String.fromCharCode(parseInt(el, 16)))?.join('')?.replace(/\0/g, ''); }, - hexToSN: function (hex) { + hexToSerial: function (hex) { if(hex) return this.hexToAscii(hex.substring(0,8))+hex.substring(8); }, table_3_2: function (hex) { From 48af2424a1edf63c227bf99f77b2b20660672117 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Fri, 10 Feb 2023 00:29:02 +0100 Subject: [PATCH 16/20] clear code --- assets/js/vue/vue-lantiq-eeprom.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/vue/vue-lantiq-eeprom.vue b/assets/js/vue/vue-lantiq-eeprom.vue index 7dbdf42b..4ae85906 100644 --- a/assets/js/vue/vue-lantiq-eeprom.vue +++ b/assets/js/vue/vue-lantiq-eeprom.vue @@ -880,7 +880,7 @@ export default { }, ploam_ascii: { get() { - if(this.ploam) return this.hexToAscii(this.ploam.substring(0,20)).replace(/\0/g, ''); + if(this.ploam) return this.hexToAscii(this.ploam.substring(0,20)); }, set(value) { if(value.length <= 10) From e348908f9cd66e006ace4d04996fc018a028343a Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Fri, 10 Feb 2023 00:32:22 +0100 Subject: [PATCH 17/20] prettier code --- assets/js/vue/vue-lantiq-eeprom.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/vue/vue-lantiq-eeprom.vue b/assets/js/vue/vue-lantiq-eeprom.vue index 4ae85906..bd8907e7 100644 --- a/assets/js/vue/vue-lantiq-eeprom.vue +++ b/assets/js/vue/vue-lantiq-eeprom.vue @@ -965,7 +965,7 @@ export default { this.setPart(532, 535, value); } }, - mac: { + mac_rooted: { get() { return this.getPart(384, 389); }, @@ -975,7 +975,7 @@ export default { }, mac_prettier: { get() { - return this.chunk(this.mac)?.join(':'); + return this.hexToMac(this.mac_rooted); }, set(value) { if(value.length == 12) { From 3752f8e5e1361f195dea2d99255a3011133422c7 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Fri, 10 Feb 2023 14:20:22 +0100 Subject: [PATCH 18/20] add some new field --- assets/js/vue/vue-lantiq-eeprom.vue | 101 ++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 6 deletions(-) diff --git a/assets/js/vue/vue-lantiq-eeprom.vue b/assets/js/vue/vue-lantiq-eeprom.vue index bd8907e7..159f6485 100644 --- a/assets/js/vue/vue-lantiq-eeprom.vue +++ b/assets/js/vue/vue-lantiq-eeprom.vue @@ -269,19 +269,22 @@ export default { "address": "92", "size": "1", "name": "Diagnostic Monitoring Type", - "description": "Indicates which type of diagnostic monitoring is implemented" + "description": "Indicates which type of diagnostic monitoring is implemented", + "parse":"table_3_9" }, { "address": "93", "size": "1", "name": "Enhanced Options", - "description": "Indicates which optional enhanced features are implemented" + "description": "Indicates which optional enhanced features are implemented", + "parse":"table_3_10" }, { "address": "94", "size": "1", "name": "SFF-8472 Compliance", - "description": "Indicates which revision of SFF-8472 the transceiver complies with" + "description": "Indicates which revision of SFF-8472 the transceiver complies with", + "parse":"table_3_12" }, { "address": "95", @@ -641,7 +644,8 @@ export default { "address": "110", "size": "1", "name": "Status/Control", - "description": "Optional Status and Control Bits" + "description": "Optional Status and Control Bits", + "parse": "table_3_17" }, { "address": "111", @@ -653,7 +657,8 @@ export default { "address": "112-113", "size": "2", "name": "Alarm Flags", - "description": "Diagnostic Alarm Flag Status Bits" + "description": "Diagnostic Alarm Flag Status Bits", + "parse": "table_3_18" }, { "address": "114", @@ -671,7 +676,8 @@ export default { "address": "116-117", "size": "2", "name": "Warning Flags", - "description": "Diagnostic Warning Flag Status Bits" + "description": "Diagnostic Warning Flag Status Bits", + "parse": "table_3_18" }, { "address": "118-119", @@ -1065,6 +1071,18 @@ export default { hexToSerial: function (hex) { if(hex) return this.hexToAscii(hex.substring(0,8))+hex.substring(8); }, + flagDecoder: function(element, table, not_table) { + var list = [] + var flags = parseInt(element, 16) + for(const [key, value] of Object.entries(table)) { + if(flags & key) { + list.push(value) + } else if(not_table && not_table[key]) { + list.push(not_table[key]) + } + } + return list; + }, table_3_2: function (hex) { var table = { "03":"SFP", @@ -1105,6 +1123,77 @@ export default { } return table[hex] ?? "Unallocated"; }, + table_3_17: function(hex) { + var table = { + 128:"TX Disable State", + 64:"Soft TX Disable", + 32:"RS(1) State", + 16:"Rate Select State", + 8:"Soft Rate Select", + 4:"TX Fault", + 2:"LOS", + 1:"Data_Ready_Bar" + } + return this.flagDecoder(hex, table)?.join(', '); + }, + table_3_18: function(hex) { + var table = [{ + 128:"Temp High", + 64:"Temp Low", + 32:"Vcc High", + 16:"Vcc Low", + 8:"TX Bias High", + 4:"TX Bias Low", + 2:"TX Power High", + 1:"TX Power Low" + },{ + 128:"RX Power High", + 64:"RX Power Low", + }] + return this.chunk(hex)?.flatMap((element, index) => this.flagDecoder(element, table[index]))?.join(', '); + }, + table_3_9: function(hex) { + var table = { + 64:"Digital diagnostic monitoring implemented", + 32:"Internally calibrated", + 16:"Externally calibrated", + 8:"Received power measurement type: average power", + 4:"Address change required" + } + var not_table = { + 128:"Reserved for legacy diagnostic implementations", + 8:"Received power measurement type: OMA", + 4:"Address change required" + } + return this.flagDecoder(hex, table, not_table)?.join(', '); + }, + table_3_10: function(hex) { + var table = { + 128:"Alarm/warning flags implemented for all monitored quantities", + 64:"Soft TX_DISABLE control and monitoring implemented", + 32:"Soft TX_FAULT monitoring implemented", + 16:"Soft RX_LOS monitoring implemented", + 8:"Soft RATE_SELECT control and monitoring implemented", + 4:"Application Select control implemented per SFF-8079", + 2:"Rate Select control implemented per SFF-8431" + } + return this.flagDecoder(hex, table)?.join(', '); + }, + table_3_12: function(hex) { + var table = { + "00":"Digital diagnostic functionality not included or undefined.", + "01":"Rev 9.3 of SFF-8472.", + "02":"Rev 9.5 of SFF-8472.", + "03":"Rev 10.2 of SFF-8472.", + "04":"Rev 10.4 of SFF-8472.", + "05":"Rev 11.0 of SFF-8472.", + "06":"Rev 11.3 of SFF-8472.", + "07":"Rev 11.4 of SFF-8472.", + "08":"Rev 12.3 of SFF-8472.", + "09":"Rev 12.4 of SFF-8472.", + } + return table[hex] ?? "Unallocated"; + }, hexTo_km: function(hex) { return `${parseInt(hex,16)}km`; }, From 4b9f50d7ae27a78c21d52c84e342529e777f8421 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Fri, 10 Feb 2023 14:24:48 +0100 Subject: [PATCH 19/20] add auto switch for A0/A2 --- assets/js/vue/vue-lantiq-eeprom.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/assets/js/vue/vue-lantiq-eeprom.vue b/assets/js/vue/vue-lantiq-eeprom.vue index 159f6485..5e800dcd 100644 --- a/assets/js/vue/vue-lantiq-eeprom.vue +++ b/assets/js/vue/vue-lantiq-eeprom.vue @@ -819,6 +819,12 @@ export default { set(val) { var sfp_a2_info_arr = val.split('@'); this.sfp_a2_info_0 = sfp_a2_info_arr.shift(); + if(this.sfp_a2_info_0.includes("sfp_a2_info")) { + this.eeprom_switch = 1; + } + else if(this.sfp_a2_info_0.includes("sfp_a0_low_128")) { + this.eeprom_switch = 0; + } this.sfp_a2_info_last = sfp_a2_info_arr.slice(-2); var sfp_a2_decode = sfp_a2_info_arr.map(it => this.base64ToHex(it)).join(''); this.the_eeprom = [...sfp_a2_decode]; From 1d0899721e8b43d1dbc0523b85b8da701ac76dd4 Mon Sep 17 00:00:00 2001 From: Simone Bortolin Date: Fri, 10 Feb 2023 14:25:21 +0100 Subject: [PATCH 20/20] update text --- assets/js/vue/vue-lantiq-eeprom.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/vue/vue-lantiq-eeprom.vue b/assets/js/vue/vue-lantiq-eeprom.vue index 5e800dcd..94c3db7f 100644 --- a/assets/js/vue/vue-lantiq-eeprom.vue +++ b/assets/js/vue/vue-lantiq-eeprom.vue @@ -1,7 +1,7 @@