Added documentation
This commit is contained in:
@@ -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
|
||||||
|
if (Array.isArray(SerialArray)) {
|
||||||
//Convert the array of strings to a boolean array
|
//Convert the array of strings to a boolean array
|
||||||
let booleanArray = incomingData.map(bit => bit == '1');
|
//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");
|
||||||
|
Reference in New Issue
Block a user