mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 10:37:44 +00:00
implement ook scan
This commit is contained in:
@@ -27,15 +27,88 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
void OOKProcessor::execute(const buffer_c8_t& buffer) {
|
||||
inline void OOKProcessor::write_sample(const buffer_c8_t& buffer, uint8_t bit_value, size_t i) {
|
||||
int8_t re, im;
|
||||
|
||||
|
||||
if (bit_value) {
|
||||
phase = (phase + 200); // What ?
|
||||
sphase = phase + (64 << 18);
|
||||
|
||||
re = (sine_table_i8[(sphase & 0x03FC0000) >> 18]);
|
||||
im = (sine_table_i8[(phase & 0x03FC0000) >> 18]);
|
||||
} else {
|
||||
re = 0;
|
||||
im = 0;
|
||||
}
|
||||
|
||||
buffer.p[i] = {re, im};
|
||||
}
|
||||
|
||||
inline void OOKProcessor::duval_algo(const buffer_c8_t& buffer) {
|
||||
size_t buf_ptr = 0;
|
||||
const unsigned int w = de_bruijn_length;
|
||||
|
||||
// Duval's algorithm for generating de Bruijn sequence
|
||||
while (idx) {
|
||||
if (w % idx == 0) {
|
||||
for (; k < idx; k++) {
|
||||
size_t available_size = buffer.count - buf_ptr;
|
||||
size_t len = (samples_per_bit > available_size) ? available_size : samples_per_bit;
|
||||
|
||||
for (; bit_ptr < len; bit_ptr++) {
|
||||
write_sample(buffer, v[k], buf_ptr);
|
||||
buf_ptr++;
|
||||
}
|
||||
|
||||
if (buf_ptr == buffer.count) {
|
||||
txprogress_message.done = false;
|
||||
txprogress_message.progress = scan_progress++;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
return;
|
||||
}
|
||||
|
||||
bit_ptr = 0;
|
||||
}
|
||||
|
||||
k = 0;
|
||||
}
|
||||
|
||||
for (unsigned int j = 0; j < w - idx; j++)
|
||||
v[idx + j] = v[j];
|
||||
|
||||
for (idx = w; idx > 0 && v[idx - 1]; idx--) ;
|
||||
|
||||
if (idx)
|
||||
v[idx - 1] = 1;
|
||||
}
|
||||
|
||||
// clear the buffer in case we have any bytes left
|
||||
if (buf_ptr < buffer.count) {
|
||||
for (size_t i = buf_ptr; i < buffer.count; i++) {
|
||||
buffer.p[i] = {0, 0};
|
||||
}
|
||||
}
|
||||
|
||||
if (!scan_done) {
|
||||
txprogress_message.done = true;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
}
|
||||
|
||||
scan_done = 1;
|
||||
}
|
||||
|
||||
void OOKProcessor::execute(const buffer_c8_t& buffer) {
|
||||
// This is called at 2.28M/2048 = 1113Hz
|
||||
|
||||
|
||||
if (!configured) return;
|
||||
|
||||
|
||||
if (de_bruijn_length) {
|
||||
duval_algo(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
|
||||
|
||||
// Synthesis at 2.28M/10 = 228kHz
|
||||
if (!s) {
|
||||
s = 10 - 1;
|
||||
@@ -71,7 +144,7 @@ void OOKProcessor::execute(const buffer_c8_t& buffer) {
|
||||
bit_pos++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sample_count = 0;
|
||||
} else {
|
||||
sample_count++;
|
||||
@@ -79,31 +152,49 @@ void OOKProcessor::execute(const buffer_c8_t& buffer) {
|
||||
} else {
|
||||
s--;
|
||||
}
|
||||
|
||||
if (cur_bit) {
|
||||
phase = (phase + 200); // What ?
|
||||
sphase = phase + (64 << 18);
|
||||
|
||||
re = (sine_table_i8[(sphase & 0x03FC0000) >> 18]);
|
||||
im = (sine_table_i8[(phase & 0x03FC0000) >> 18]);
|
||||
} else {
|
||||
re = 0;
|
||||
im = 0;
|
||||
}
|
||||
|
||||
buffer.p[i] = {re, im};
|
||||
write_sample(buffer, cur_bit, i);
|
||||
}
|
||||
}
|
||||
|
||||
void OOKProcessor::on_message(const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const OOKConfigureMessage*>(p);
|
||||
|
||||
|
||||
if (message.id == Message::ID::OOKConfigure) {
|
||||
samples_per_bit = message.samples_per_bit / 10;
|
||||
configured = false;
|
||||
|
||||
repeat = message.repeat - 1;
|
||||
length = message.stream_length;
|
||||
pause = message.pause_symbols + 1;
|
||||
|
||||
de_bruijn_length = message.de_bruijn_length;
|
||||
samples_per_bit = message.samples_per_bit;
|
||||
|
||||
if (!length && !samples_per_bit) {
|
||||
// shutdown
|
||||
return;
|
||||
}
|
||||
|
||||
if (de_bruijn_length) {
|
||||
if (de_bruijn_length > sizeof(v)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (samples_per_bit > 2048) {
|
||||
// can't handle more than dma::transfer_samples
|
||||
return;
|
||||
}
|
||||
|
||||
k = 0;
|
||||
bit_ptr = 0;
|
||||
idx = 1;
|
||||
scan_done = false;
|
||||
scan_progress = 0;
|
||||
|
||||
memset(v, 0, sizeof(v));
|
||||
} else {
|
||||
samples_per_bit /= 10;
|
||||
}
|
||||
|
||||
pause_counter = 0;
|
||||
s = 0;
|
||||
sample_count = samples_per_bit;
|
||||
|
@@ -29,19 +29,20 @@
|
||||
class OOKProcessor : public BasebandProcessor {
|
||||
public:
|
||||
void execute(const buffer_c8_t& buffer) override;
|
||||
|
||||
|
||||
void on_message(const Message* const p) override;
|
||||
|
||||
private:
|
||||
bool configured = false;
|
||||
|
||||
|
||||
BasebandThread baseband_thread { 2280000, this, NORMALPRIO + 20, baseband::Direction::Transmit };
|
||||
|
||||
|
||||
uint32_t samples_per_bit { 0 };
|
||||
uint8_t repeat { 0 };
|
||||
uint32_t length { 0 };
|
||||
uint32_t pause { 0 };
|
||||
|
||||
uint8_t de_bruijn_length { 0 };
|
||||
|
||||
uint32_t pause_counter { 0 };
|
||||
uint8_t repeat_counter { 0 };
|
||||
uint8_t s { 0 };
|
||||
@@ -50,8 +51,19 @@ private:
|
||||
uint32_t sample_count { 0 };
|
||||
uint32_t tone_phase { 0 }, phase { 0 }, sphase { 0 };
|
||||
int32_t tone_sample { 0 }, sig { 0 }, frq { 0 };
|
||||
|
||||
|
||||
TXProgressMessage txprogress_message { };
|
||||
|
||||
static constexpr auto MAX_DE_BRUIJN_ORDER = 24;
|
||||
uint8_t v[MAX_DE_BRUIJN_ORDER];
|
||||
unsigned int idx { 0 };
|
||||
unsigned int k { 0 };
|
||||
size_t bit_ptr{ 0 };
|
||||
size_t scan_progress{ 0 };
|
||||
uint8_t scan_done { true };
|
||||
|
||||
void write_sample(const buffer_c8_t& buffer, uint8_t bit_value, size_t i);
|
||||
void duval_algo(const buffer_c8_t& buffer);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user