Merge branch 'main' of ssh://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-2/cuujooceevii61
This commit is contained in:
@@ -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)) {
|
||||
// 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
|
||||
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);
|
||||
} else {
|
||||
console.error("Invalid incoming data format. Expecting an array.");
|
||||
console.error("Dit is geen Array");
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("json niet geparserd");
|
||||
|
Reference in New Issue
Block a user