Add more or less working prototype
Signed-off-by: Severin Kaderli <severin@kaderli.dev>
This commit is contained in:
parent
99d93c573d
commit
0403bbb270
12 changed files with 321 additions and 17 deletions
|
@ -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));
|
||||
}
|
||||
|
|
Reference in a new issue