Add more or less working prototype

Signed-off-by: Severin Kaderli <severin@kaderli.dev>
This commit is contained in:
Severin Kaderli 2022-12-07 23:32:44 +01:00
parent 99d93c573d
commit 0403bbb270
Signed by: severinkaderli
GPG key ID: F419F8835B72F0C4
12 changed files with 321 additions and 17 deletions

View file

@ -81,7 +81,7 @@ async function startCalibration() {
return;
}
await transmitBit(Constants.CALIBRATION_SIGNAL[i]);
await transmitBit(Constants.CALIBRATION_SIGNAL[i], Constants.CLOCK_TIME);
}
}
}
@ -124,6 +124,7 @@ function startSending() {
stopSendingButton.classList.remove(Constants.HIDE_CLASS);
const packet = new Packet(textInput.value);
console.log(packet);
const signal = Utility.manchesterEncode(packet.getData());
isTransmitting = true;
@ -158,7 +159,7 @@ async function transmitSignal(signal) {
}
console.log(`Sending preamble: ${bit}`);
await transmitBit(bit);
await transmitBit(bit, Constants.PREAMBLE_CLOCK_TIME);
}
for (let i = 0; i < signal.length; i++) {
@ -167,24 +168,24 @@ async function transmitSignal(signal) {
return;
}
console.log(`Sending bit ${i + 1} of ${signal.length} of packet: ${signal[i]}`);
await transmitBit(signal[i]);
console.log(`Sending symbol ${i + 1} of ${signal.length} of packet: ${signal[i]}`);
await transmitBit(signal[i], Constants.CLOCK_TIME);
}
}
}
/**
* Starts or stops the web workers depending on the bit value and then waits
* for a duration of Constants.CLOCK_TIME.
* for a duration of clockTime.
*
* @param {Number} bit
*/
function transmitBit(bit) {
function transmitBit(bit, clockTime) {
if (bit === 1) {
startWorkers();
return new Promise((resolve) => setTimeout(resolve, Constants.CLOCK_TIME));
return new Promise((resolve) => setTimeout(resolve, clockTime));
}
stopWorkers();
return new Promise((resolve) => setTimeout(resolve, Constants.CLOCK_TIME));
return new Promise((resolve) => setTimeout(resolve, clockTime));
}