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 {
let sensorString = decoder.decode(new Uint8Array(buffer));
console.log(sensorString);
//zet alle data in een json array
//Put all data in a json Array and parse it to a boolean array
try {
let incomingData = JSON.parse(sensorString.replace(/'/g, '"'));
// Ensure incomingData is an array
if (Array.isArray(incomingData)) {
// Convert the array of strings to a boolean array
let booleanArray = incomingData.map(bit => bit == '1');
// 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
let SerialArray = JSON.parse(sensorString.replace(/'/g, '"'));
// Ensure SerialArray is an array
if (Array.isArray(SerialArray)) {
//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);
} else {
console.error("Invalid incoming data format. Expecting an array.");
console.error("Dit is geen Array");
}
} catch (e) {
console.log("json niet geparserd");