Skip to content

Commit

Permalink
improving online website https://maebli.github.io/m-bus-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
maebli committed Jun 15, 2024
1 parent 1ed86dc commit f79ac9e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 29 deletions.
35 changes: 25 additions & 10 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 600px;
max-width: 1100px;
margin: 0 auto;
}

Expand All @@ -63,6 +63,7 @@
border: none;
border-radius: 4px;
cursor: pointer;
margin-right: 10px;
}

input[type="button"]:hover {
Expand All @@ -79,7 +80,7 @@

#output {
margin-top: 20px;
max-width: 600px;
max-width: 1100px;
margin: 20px auto 0;
padding: 20px;
border-radius: 8px;
Expand All @@ -91,12 +92,15 @@
<body>
<div class="header">
<img id="banner" src="meter.png" alt="Meter Banner">
<h1>Wired M-Bus Parser with WASM</h1>
<h1> Online M-Bus parser (wired) <i>https://maebli.github.io/m-bus-parser</i></h1>
</div>
<form>
<label for="inputstring">Input String:</label>
<textarea rows="5" cols="80" id="inputstring"></textarea>
<input id="m_bus_parse" type="button" value="Parse JSON" />
<textarea rows="5" cols="80"
id="inputstring">68 3D 3D 68 08 01 72 00 51 20 02 82 4D 02 04 00 88 00 00 04 07 00 00 00 00 0C 15 03 00 00 00 0B 2E 00 00 00 0B 3B 00 00 00 0A 5A 88 12 0A 5E 16 05 0B 61 23 77 00 02 6C 8C 11 02 27 37 0D 0F 60 00 67 16</textarea>
<input id="parse_json" type="button" value="Parse to JSON" />
<input id="parse_yaml" type="button" value="Parse to YAML" />
<input id="parse_table" type="button" value="Parse to Table" />
</form>
<pre id="output"></pre>
<script type="module">
Expand All @@ -105,14 +109,25 @@ <h1>Wired M-Bus Parser with WASM</h1>
async function setup() {
await init(); // Ensure the WASM module is initialized

document.getElementById('m_bus_parse').addEventListener('click', () => {
document.getElementById('parse_json').addEventListener('click', () => {
parseInput("json");
});

document.getElementById('parse_yaml').addEventListener('click', () => {
parseInput("yaml");
});

document.getElementById('parse_table').addEventListener('click', () => {
parseInput("table_format");
});

function parseInput(format) {
const inputString = document.getElementById('inputstring').value;
const result = m_bus_parse(inputString);
const formattedResult = JSON.stringify(JSON.parse(result), null, 2); // Pretty-print the JSON
const formattedResult = m_bus_parse(inputString, format);
const outputElement = document.getElementById("output");
outputElement.textContent = formattedResult;
hljs.highlightElement(outputElement); // Apply syntax highlighting
});
//hljs.highlightElement(outputElement); // Apply syntax highlighting
}
}

setup(); // Set up the event listeners after the page is loaded
Expand Down
21 changes: 12 additions & 9 deletions docs/m_bus_parser_wasm_pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,28 @@ function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}
/**
* @param {string} s
* @param {string} data
* @param {string} format
* @returns {string}
*/
export function m_bus_parse(s) {
let deferred2_0;
let deferred2_1;
export function m_bus_parse(data, format) {
let deferred3_0;
let deferred3_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const ptr0 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.m_bus_parse(retptr, ptr0, len0);
const ptr1 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
wasm.m_bus_parse(retptr, ptr0, len0, ptr1, len1);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
deferred2_0 = r0;
deferred2_1 = r1;
deferred3_0 = r0;
deferred3_1 = r1;
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
}
}

Expand Down
21 changes: 12 additions & 9 deletions docs/m_bus_parser_wasm_pack_bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,28 @@ function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}
/**
* @param {string} s
* @param {string} data
* @param {string} format
* @returns {string}
*/
export function m_bus_parse(s) {
let deferred2_0;
let deferred2_1;
export function m_bus_parse(data, format) {
let deferred3_0;
let deferred3_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const ptr0 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.m_bus_parse(retptr, ptr0, len0);
const ptr1 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
wasm.m_bus_parse(retptr, ptr0, len0, ptr1, len1);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
deferred2_0 = r0;
deferred2_1 = r1;
deferred3_0 = r0;
deferred3_1 = r1;
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
}
}

Binary file modified docs/m_bus_parser_wasm_pack_bg.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Michael Aebli"
],
"description": "A wasm-pack to use the library for parsing M-Bus frames",
"version": "0.0.0",
"version": "0.0.2",
"license": "MIT",
"repository": {
"type": "git",
Expand Down

0 comments on commit f79ac9e

Please sign in to comment.