Cleanup, random mode in DTMF TX

This commit is contained in:
furrtek 2016-09-23 20:17:29 +02:00
parent bb29efeda6
commit 55ba0b5e06
6 changed files with 106 additions and 64 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/firmware/baseband/baseband_dtmf_tx.img
/firmware/baseband/baseband.img /firmware/baseband/baseband.img
/firmware/baseband/baseband_afsk.img /firmware/baseband/baseband_afsk.img
/firmware/baseband/baseband_ais.img /firmware/baseband/baseband_ais.img

View File

@ -24,7 +24,7 @@
#include "ch.h" #include "ch.h"
//#include "lfsr_random.hpp" #include "lfsr_random.hpp"
#include "ui_alphanum.hpp" #include "ui_alphanum.hpp"
#include "portapack.hpp" #include "portapack.hpp"
#include "string_format.hpp" #include "string_format.hpp"
@ -50,15 +50,21 @@ void NuoptixView::transmit(bool setup) {
uint8_t mod; uint8_t mod;
uint8_t c; uint8_t c;
if (!txing) { if (!tx_mode) {
transmitter_model.disable(); transmitter_model.disable();
return; return;
} }
if (tx_mode == IMPROVISE)
timecode = lfsr_iterate(timecode) % 1999; // Should be 9999 but that would be one long audio track !
if (setup) { if (setup) {
pbar.set_max(4); pbar.set_max(4);
timecode = number_timecode.value(); if (tx_mode == NORMAL)
timecode = number_timecode.value();
else
timecode = 0125;
transmitter_model.set_baseband_configuration({ transmitter_model.set_baseband_configuration({
.mode = 0, .mode = 0,
@ -82,7 +88,6 @@ void NuoptixView::transmit(bool setup) {
pbar.set_value(0); pbar.set_value(0);
//strcpy("#00028", shared_memory.tx_data);
shared_memory.tx_data[2] = (timecode / 100) % 10; shared_memory.tx_data[2] = (timecode / 100) % 10;
shared_memory.tx_data[3] = (timecode / 10) % 10; shared_memory.tx_data[3] = (timecode / 10) % 10;
shared_memory.tx_data[4] = timecode % 10; shared_memory.tx_data[4] = timecode % 10;
@ -98,9 +103,9 @@ void NuoptixView::transmit(bool setup) {
shared_memory.tx_data[5] = mod; shared_memory.tx_data[5] = mod;
shared_memory.tx_data[6] = 0xFF; shared_memory.tx_data[6] = 0xFF; // End of message
baseband::set_dtmf_data(number_bw.value(), 49, 49); // 49ms tone, 49ms space baseband::set_dtmf_data(number_bw.value(), 49, 49); // 49ms tone, 49ms space
timecode++; timecode++;
} }
@ -109,7 +114,6 @@ NuoptixView::NuoptixView(
NavigationView& nav NavigationView& nav
) )
{ {
baseband::run_image(portapack::spi_flash::image_tag_dtmf_tx); baseband::run_image(portapack::spi_flash::image_tag_dtmf_tx);
add_children({ { add_children({ {
@ -121,6 +125,7 @@ NuoptixView::NuoptixView(
&text_mod, &text_mod,
&pbar, &pbar,
&button_tx, &button_tx,
&button_impro,
&button_exit &button_exit
} }); } });
@ -143,10 +148,23 @@ NuoptixView::NuoptixView(
}; };
button_tx.on_select = [this](Button&){ button_tx.on_select = [this](Button&){
if (txing) { if (tx_mode == NORMAL) {
txing = false; tx_mode = IDLE;
} else { button_tx.set_text("TX");
txing = true; } else if (tx_mode == IDLE) {
tx_mode = NORMAL;
button_tx.set_text("STOP");
transmit(true);
}
};
button_impro.on_select = [this](Button&){
if (tx_mode == IMPROVISE) {
tx_mode = IDLE;
button_impro.set_text("IMPROVISE");
} else if (tx_mode == IDLE) {
tx_mode = IMPROVISE;
button_impro.set_text("STOP");
transmit(true); transmit(true);
} }
}; };

View File

@ -43,17 +43,17 @@ public:
std::string title() const override { return "Nuoptix sync"; }; std::string title() const override { return "Nuoptix sync"; };
private: private:
/*enum tx_modes { enum tx_modes {
NORMAL = 0, IDLE = 0,
RANDOM NORMAL,
IMPROVISE
}; };
tx_modes tx_mode = NORMAL;*/ tx_modes tx_mode = IDLE;
void on_tuning_frequency_changed(rf::Frequency f); void on_tuning_frequency_changed(rf::Frequency f);
void transmit(bool setup); void transmit(bool setup);
bool txing = false;
uint32_t timecode; uint32_t timecode;
FrequencyField field_frequency { FrequencyField field_frequency {
@ -102,10 +102,15 @@ private:
};*/ };*/
Button button_tx { Button button_tx {
{ 32, 270, 64, 32 }, { 70, 128, 100, 40 },
"TX" "TX"
}; };
Button button_impro {
{ 70, 184, 100, 40 },
"IMPROVISE"
};
Button button_exit { Button button_exit {
{ 160, 270, 64, 32 }, { 160, 270, 64, 32 },
"Exit" "Exit"
@ -115,7 +120,7 @@ private:
Message::ID::TXDone, Message::ID::TXDone,
[this](const Message* const p) { [this](const Message* const p) {
const auto message = *reinterpret_cast<const TXDoneMessage*>(p); const auto message = *reinterpret_cast<const TXDoneMessage*>(p);
if (message.n == 64) if (message.n == 0xFF)
transmit(false); transmit(false);
else else
pbar.set_value(message.n); pbar.set_value(message.n);

View File

@ -28,9 +28,6 @@
#include <cstdint> #include <cstdint>
// 153600 = 1000ms
//
void DTMFTXProcessor::execute(const buffer_c8_t& buffer){ void DTMFTXProcessor::execute(const buffer_c8_t& buffer){
// This is called at 1536000/2048 = 750Hz // This is called at 1536000/2048 = 750Hz
@ -38,7 +35,6 @@ void DTMFTXProcessor::execute(const buffer_c8_t& buffer){
if (!configured) return; if (!configured) return;
//ai = 0;
for (size_t i = 0; i<buffer.count; i++) { for (size_t i = 0; i<buffer.count; i++) {
if (!as) { if (!as) {
@ -47,33 +43,21 @@ void DTMFTXProcessor::execute(const buffer_c8_t& buffer){
if (!timer) { if (!timer) {
if (tone) { if (tone) {
tone = false; tone = false;
timer = pause_length * 154; // 153.6 timer = pause_length;
} else { } else {
tone = true; tone = true;
timer = tone_length * 154; // 153.6 timer = tone_length;
tone_code = shared_memory.tx_data[tone_idx]; //tone_list[tone_idx];
tone_code = shared_memory.tx_data[tone_idx];
if (tone_code == 0xFF) { if (tone_code == 0xFF) {
txdone_message.n = 64; // End of list txdone_message.n = 0xFF; // End of list
shared_memory.application_queue.push(txdone_message); shared_memory.application_queue.push(txdone_message);
configured = false; configured = false;
tone = false; tone = false;
} else { } else {
txdone_message.n = tone_idx; // New tone txdone_message.n = tone_idx; // New tone (progress)
shared_memory.application_queue.push(txdone_message); shared_memory.application_queue.push(txdone_message);
if (tone_code == 'A')
tone_code = 10;
else if (tone_code == 'B')
tone_code = 11;
else if (tone_code == 'C')
tone_code = 12;
else if (tone_code == 'D')
tone_code = 13;
else if (tone_code == '#')
tone_code = 14;
else if (tone_code == '*')
tone_code = 15;
tone_idx++; tone_idx++;
} }
} }
@ -109,18 +93,45 @@ void DTMFTXProcessor::execute(const buffer_c8_t& buffer){
} }
void DTMFTXProcessor::on_message(const Message* const msg) { void DTMFTXProcessor::on_message(const Message* const msg) {
char * tone_ptr;
const auto message = *reinterpret_cast<const DTMFTXConfigMessage*>(msg); const auto message = *reinterpret_cast<const DTMFTXConfigMessage*>(msg);
if (message.id == Message::ID::DTMFTXConfig) { if (message.id == Message::ID::DTMFTXConfig) {
// Translate DTMF message to index in DTMF frequencies table
tone_ptr = &shared_memory.tx_data[0];
for (;;) {
tone_code = *tone_ptr;
if (tone_code == 0xFF)
break; // End of message
else if (tone_code <= 9)
// That's already fine bro.
*tone_ptr = tone_code;
else if (tone_code == 'A')
*tone_ptr = 10;
else if (tone_code == 'B')
*tone_ptr = 11;
else if (tone_code == 'C')
*tone_ptr = 12;
else if (tone_code == 'D')
*tone_ptr = 13;
else if (tone_code == '#')
*tone_ptr = 14;
else if (tone_code == '*')
*tone_ptr = 15;
else {
*tone_ptr = 0xFF; // Invalid character, stop here
}
tone_ptr++;
}
// 1<<18 = 262144 // 1<<18 = 262144
// m = (262144 * a) / 1536000 // m = (262144 * a) / 1536000
// a = 262144 / 1536000 (*1000 = 171) // a = 262144 / 1536000 (*1000 = 171)
bw = 171 * (message.bw); bw = 171 * (message.bw);
tone_length = message.tone_length; tone_length = message.tone_length * 154; // 153.6
pause_length = message.pause_length; pause_length = message.pause_length * 154; // 153.6
as = 0; as = 0;
//memcpy(tone_list, shared_memory.tx_data, 32);
//tone_list[31] = 0;
tone = false; tone = false;
timer = 0; timer = 0;
tone_idx = 0; tone_idx = 0;

View File

@ -26,7 +26,15 @@
#include "baseband_processor.hpp" #include "baseband_processor.hpp"
#include "baseband_thread.hpp" #include "baseband_thread.hpp"
#define DTMF_PHASEINC (436.91) // (65536*1024)/1536000*10 #define DTMF_PHASEINC 436.91 // (65536*1024)/1536000*10
#define DTMF_C0 (uint32_t)(1209*DTMF_PHASEINC)
#define DTMF_C1 (uint32_t)(1336*DTMF_PHASEINC)
#define DTMF_C2 (uint32_t)(1477*DTMF_PHASEINC)
#define DTMF_C3 (uint32_t)(1633*DTMF_PHASEINC)
#define DTMF_R0 (uint32_t)(697*DTMF_PHASEINC)
#define DTMF_R1 (uint32_t)(770*DTMF_PHASEINC)
#define DTMF_R2 (uint32_t)(852*DTMF_PHASEINC)
#define DTMF_R3 (uint32_t)(941*DTMF_PHASEINC)
class DTMFTXProcessor : public BasebandProcessor { class DTMFTXProcessor : public BasebandProcessor {
public: public:
@ -41,32 +49,31 @@ private:
// 0123456789ABCD#* // 0123456789ABCD#*
const uint32_t DTMF_LUT[16][2] = { const uint32_t DTMF_LUT[16][2] = {
{ (uint32_t)(1336*DTMF_PHASEINC), (uint32_t)(941*DTMF_PHASEINC) }, { DTMF_C1, DTMF_R3 },
{ (uint32_t)(1209*DTMF_PHASEINC), (uint32_t)(697*DTMF_PHASEINC) }, { DTMF_C0, DTMF_R0 },
{ (uint32_t)(1336*DTMF_PHASEINC), (uint32_t)(697*DTMF_PHASEINC) }, { DTMF_C1, DTMF_R0 },
{ (uint32_t)(1477*DTMF_PHASEINC), (uint32_t)(697*DTMF_PHASEINC) }, { DTMF_C2, DTMF_R0 },
{ (uint32_t)(1209*DTMF_PHASEINC), (uint32_t)(770*DTMF_PHASEINC) }, { DTMF_C0, DTMF_R1 },
{ (uint32_t)(1336*DTMF_PHASEINC), (uint32_t)(770*DTMF_PHASEINC) }, { DTMF_C1, DTMF_R1 },
{ (uint32_t)(1477*DTMF_PHASEINC), (uint32_t)(770*DTMF_PHASEINC) }, { DTMF_C2, DTMF_R1 },
{ (uint32_t)(1209*DTMF_PHASEINC), (uint32_t)(852*DTMF_PHASEINC) }, { DTMF_C0, DTMF_R2 },
{ (uint32_t)(1336*DTMF_PHASEINC), (uint32_t)(852*DTMF_PHASEINC) }, { DTMF_C1, DTMF_R2 },
{ (uint32_t)(1477*DTMF_PHASEINC), (uint32_t)(852*DTMF_PHASEINC) }, { DTMF_C2, DTMF_R2 },
{ (uint32_t)(1633*DTMF_PHASEINC), (uint32_t)(697*DTMF_PHASEINC) }, { DTMF_C3, DTMF_R0 },
{ (uint32_t)(1633*DTMF_PHASEINC), (uint32_t)(770*DTMF_PHASEINC) }, { DTMF_C3, DTMF_R1 },
{ (uint32_t)(1633*DTMF_PHASEINC), (uint32_t)(852*DTMF_PHASEINC) }, { DTMF_C3, DTMF_R2 },
{ (uint32_t)(1633*DTMF_PHASEINC), (uint32_t)(941*DTMF_PHASEINC) }, { DTMF_C3, DTMF_R3 },
{ (uint32_t)(1477*DTMF_PHASEINC), (uint32_t)(941*DTMF_PHASEINC) }, { DTMF_C2, DTMF_R3 },
{ (uint32_t)(1209*DTMF_PHASEINC), (uint32_t)(941*DTMF_PHASEINC) } { DTMF_C0, DTMF_R3 }
}; };
uint32_t tone_length, pause_length; uint32_t tone_length, pause_length;
uint32_t as, bw; uint32_t as, bw;
uint8_t tone_list[32];
uint8_t tone_idx = 0, tone_code = 0; uint8_t tone_idx = 0, tone_code = 0;
uint32_t timer = 0; uint32_t timer = 0;
bool tone = false; bool tone = false; // Tone / pause
int8_t re, im; int8_t re, im;
int8_t sample; int8_t sample;

Binary file not shown.