Added documentation

This commit is contained in:
sam
2023-11-24 10:21:08 +01:00
parent 9772bf721d
commit bc33172053

View File

@@ -32,20 +32,20 @@ async function readLoop() {
else { else {
let sensorString = decoder.decode(new Uint8Array(buffer)); let sensorString = decoder.decode(new Uint8Array(buffer));
console.log(sensorString); //Put all data in a json Array and parse it to a boolean array
//zet alle data in een json array
try { try {
let incomingData = JSON.parse(sensorString.replace(/'/g, '"')); // Parse the incoming data as JSON
// "replace(/'/g, '\"')" replaces all single quotes with double quotes with use of regular expressions. So we can use Jsonparse to parse it into a booleanArray
// Ensure incomingData is an array let SerialArray = JSON.parse(sensorString.replace(/'/g, '"'));
if (Array.isArray(incomingData)) { // Ensure SerialArray is an array
// Convert the array of strings to a boolean array if (Array.isArray(SerialArray)) {
let booleanArray = incomingData.map(bit => bit == '1'); //Convert the array of strings to a boolean array
//When a bit is 1 it becomes true, when a bit is 0 it becomes false
let booleanArray = SerialArray.map(bit => bit == '1');
console.log(booleanArray); console.log(booleanArray);
} else { } else {
console.error("Invalid incoming data format. Expecting an array."); console.error("Dit is geen Array");
} }
} catch (e) { } catch (e) {
console.log("json niet geparserd"); console.log("json niet geparserd");