Added RFM69 helper

LGE tool: new frames
Text entry string length bugfix
This commit is contained in:
furrtek 2019-05-05 00:43:36 +01:00
parent dd35bda197
commit b1e72c788b
18 changed files with 417 additions and 130 deletions

View file

@ -20,12 +20,15 @@
* Boston, MA 02110-1301, USA.
*/
// The UI for this app is in French because it concerns leisure centers
// only established in France. "LGE" stands for a trademark I'd rather
// not spell out completely here.
#include "lge_app.hpp"
#include "baseband_api.hpp"
#include "portapack_persistent_memory.hpp"
#include "ui_textentry.hpp"
#include "crc.hpp"
#include "string_format.hpp"
#include <cstring>
@ -36,7 +39,7 @@ using namespace portapack;
namespace ui {
void LGEView::focus() {
tx_view.focus();
options_trame.focus();
}
LGEView::~LGEView() {
@ -44,64 +47,145 @@ LGEView::~LGEView() {
baseband::shutdown();
}
void LGEView::generate_frame() {
CRC<16> crc { 0x1021, 0x90BE };
std::vector<uint8_t> frame { };
uint8_t payload[9] = { 0x06, 0x0D, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00 };
uint8_t out = 0;
void LGEView::generate_lge_frame(const uint8_t command, const uint16_t address_a, const uint16_t address_b, std::vector<uint8_t>& data) {
std::array<uint8_t, 5> header = {
command,
(uint8_t)(address_a & 255),
(uint8_t)(address_a >> 8),
(uint8_t)(address_b & 255),
(uint8_t)(address_b >> 8),
};
data.insert(data.begin(), header.begin(), header.end());
frame_size = rfm69.gen_frame(data);
for (auto b : data)
console.write(to_string_hex(b, 2) + " ");
}
void LGEView::generate_frame_pseudo() {
// 0040.48s:
// 30 02 1A 00 19 00 FF 00 02 19 42 52 45 42 49 53 20 00 00 00 00 00 00 00 00 00
// 04 01 B0 04 7F 1F 11 33 40 1F 22 01 07 00 00 01 07 00 00 63 05 00 00 99 A2
std::vector<uint8_t> data { };
std::array<uint8_t, 3> data_header = { 0xFF, 0x00, 0x02 };
std::array<uint8_t, 22> data_footer = {
0x01, 0xB0, 0x04, 0x7F,
0x1F, 0x11, 0x33, 0x40,
0x1F, 0x22, 0x01, 0x07,
0x00, 0x00, 0x01, 0x07,
0x00, 0x00, 0x63, 0x05,
0x00, 0x00
};
uint32_t c;
payload[6] = field_zone.value(); // Zone
//data_header[2] = field_salle.value(); // ?
//data_footer[0] = field_salle.value(); // ?
// Preamble
// Really is 0xAA but the RFM69 skips the very last bit (bug ?)
// so the whole preamble should be shifted right 1 bit to simulate that
for (c = 0; c < 5; c++)
frame.push_back(0x55);
data.insert(data.begin(), data_header.begin(), data_header.end());
frame.push_back(0x2D); // Sync word
frame.push_back(0xD4);
data.push_back(field_joueur.value());
crc.process_bytes(payload, 9 - 2);
payload[7] = crc.checksum() >> 8;
payload[8] = crc.checksum() & 0xFF;
// Manchester-encode payload
for (c = 0; c < 9; c++) {
uint8_t byte = payload[c];
for (uint32_t b = 0; b < 8; b++) {
out <<= 2;
if (byte & 0x80)
out |= 0b10;
else
out |= 0b01;
if ((b & 3) == 3)
frame.push_back(out);
byte <<= 1;
}
c = 0;
for (auto &ch : pseudo) {
data.push_back(ch);
c++;
}
// Space at the end, is this required ?
data.push_back(0x20);
// Pad with zeroes
while (++c < 16)
data.push_back(0x00);
frame_size = frame.size();
data.push_back(field_equipe.value());
/*std::string debug_str { "" };
data.insert(data.end(), data_footer.begin(), data_footer.end());
for (c = 0; c < 10; c++)
debug_str += (to_string_hex(frame[c], 2) + " ");
console.write("\n\x1B\x0ESet pseudo:\x1B\x10");
text_messagea.set(debug_str);
generate_lge_frame(0x02, 0x001A, field_joueur.value(), data);
}
debug_str = "";
for (c = 15; c < frame_size; c++)
debug_str += (to_string_hex(frame[c], 2) + " ");
text_messageb.set(debug_str);*/
void LGEView::generate_frame_equipe() {
// 0041.83s:
// 3D 03 FF FF FF FF 02 03 01 52 4F 55 47 45 00 00 00 00 00 00 00 00 00 00 00 00
// 02 56 45 52 54 45 00 00 00 00 00 00 00 00 00 00 00 01 03 42 4C 45 55 45 00 00
// 00 00 00 00 00 00 00 00 00 02 43 29
// Copy for baseband
memcpy(shared_memory.bb_data.data, frame.data(), frame_size);
std::vector<uint8_t> data { };
std::array<uint8_t, 2> data_header = { 0x02, 0x01 };
uint32_t c;
data.insert(data.begin(), data_header.begin(), data_header.end());
data.push_back(field_equipe.value());
c = 0;
for (auto &ch : pseudo) {
data.push_back(ch);
c++;
}
// Pad with zeroes
while (c++ < 16)
data.push_back(0x00);
data.push_back(field_equipe.value() - 1); // Color ?
console.write("\n\x1B\x0ASet equipe:\x1B\x10");
generate_lge_frame(0x03, data);
}
void LGEView::generate_frame_broadcast_pseudo() {
// 0043.86s:
// 3D 04 FF FF FF FF 02 03 19 42 52 45 42 49 53 20 00 00 00 00 00 00 00 00 00 04
// 07 50 4F 4E 45 59 20 00 00 00 00 00 00 00 00 00 00 05 1B 41 42 42 59 20 00 00
// 00 00 00 00 00 00 00 00 00 04 0A 02
std::vector<uint8_t> data { };
std::array<uint8_t, 2> data_header = { 0x02, 0x01 };
uint32_t c;
data.insert(data.begin(), data_header.begin(), data_header.end());
data.push_back(field_joueur.value());
c = 0;
for (auto &ch : pseudo) {
data.push_back(ch);
c++;
}
// Space at the end, is this required ?
data.push_back(0x20);
// Pad with zeroes
while (++c < 16)
data.push_back(0x00);
data.push_back(field_equipe.value());
console.write("\n\x1B\x09" "Broadcast pseudo:\x1B\x10");
generate_lge_frame(0x04, data);
}
void LGEView::generate_frame_start() {
// 0166.13s:
// 0A 05 FF FF FF FF 02 EC FF FF FF A3 35
std::vector<uint8_t> data { 0x02, 0xEC, 0xFF, 0xFF, 0xFF };
//data[0] = field_salle.value(); // ?
console.write("\n\x1B\x0DStart:\x1B\x10");
generate_lge_frame(0x05, data);
}
void LGEView::generate_frame_gameover() {
std::vector<uint8_t> data { field_salle.value() };
console.write("\n\x1B\x0CGameover:\x1B\x10");
generate_lge_frame(0x0D, data);
}
void LGEView::start_tx() {
@ -115,7 +199,7 @@ void LGEView::start_tx() {
transmitter_model.set_baseband_bandwidth(1750000);
transmitter_model.enable();
chThdSleep(100);
chThdSleep(100);
baseband::set_fsk_data(frame_size * 8, 2280000 / 9600, 4000, 256);
}
@ -157,20 +241,29 @@ LGEView::LGEView(NavigationView& nav) {
add_children({
&labels,
&field_zone,
&options_trame,
&field_salle,
&button_texte,
&field_equipe,
&field_joueur,
&checkbox_channels,
&text_messagea,
&text_messageb,
&console,
&tx_view
});
field_zone.set_value(1);
field_salle.set_value(1);
field_equipe.set_value(1);
field_joueur.set_value(1);
checkbox_channels.set_value(true);
generate_frame();
field_zone.on_change = [this](int32_t) {
generate_frame();
button_texte.on_select = [this, &nav](Button&) {
text_prompt(
nav,
pseudo,
15,
[this](std::string& buffer) {
button_texte.set_text(buffer);
});
};
tx_view.on_edit_frequency = [this, &nav]() {
@ -182,7 +275,18 @@ LGEView::LGEView(NavigationView& nav) {
tx_view.on_start = [this]() {
if (tx_mode == IDLE) {
generate_frame();
auto i = options_trame.selected_index_value();
if (i == 0)
generate_frame_pseudo();
else if (i == 1)
generate_frame_equipe();
else if (i == 2)
generate_frame_broadcast_pseudo();
else if (i == 3)
generate_frame_start();
else if (i == 4)
generate_frame_gameover();
repeats = 0;
channel_index = 0;
tx_mode = checkbox_channels.value() ? ALL : SINGLE;

View file

@ -25,6 +25,7 @@
#include "ui_navigation.hpp"
#include "ui_transmitter.hpp"
#include "ui_font_fixed_8x16.hpp"
#include "rfm69.hpp"
#include "message.hpp"
#include "transmitter_model.hpp"
@ -50,27 +51,77 @@ private:
tx_modes tx_mode = IDLE;
RFM69 rfm69 { 5, 0x2DD4, true, true };
uint32_t frame_size { 0 };
uint32_t repeats { 0 };
uint32_t channel_index { 0 };
std::string pseudo { "ABCDEF" };
rf::Frequency channels[3] = { 868067000, 868183000, 868295000 };
void start_tx();
void stop_tx();
void generate_frame();
void generate_lge_frame(const uint8_t command, std::vector<uint8_t>& data) {
generate_lge_frame(command, 0xFFFF, 0xFFFF, data);
}
void generate_lge_frame(const uint8_t command, const uint16_t address_a, const uint16_t address_b, std::vector<uint8_t>& data);
void generate_frame_pseudo();
void generate_frame_equipe();
void generate_frame_broadcast_pseudo();
void generate_frame_start();
void generate_frame_gameover();
void on_tx_progress(const uint32_t progress, const bool done);
Labels labels {
{ { 7 * 8, 4 * 8 }, "NO FUN ALLOWED !", Color::red() },
{ { 11 * 8, 8 * 8 }, "Zone:", Color::light_grey() }
{ { 7 * 8, 1 * 8 }, "NO FUN ALLOWED !", Color::red() },
{ { 4 * 8, 4 * 8 }, "Trame:", Color::light_grey() },
{ { 4 * 8, 6 * 8 }, "Salle:", Color::light_grey() },
{ { 14 * 8, 6 * 8 }, "Texte:", Color::light_grey() },
{ { 3 * 8, 8 * 8 }, "Equipe:", Color::light_grey() },
{ { 3 * 8, 10 * 8 }, "Joueur:", Color::light_grey() }
};
NumberField field_zone {
{ 16 * 8, 8 * 8 },
OptionsField options_trame {
{ 10 * 8, 4 * 8 },
16,
{
{ "Set pseudo", 0 },
{ "Set equipe", 1 },
{ "Broadcast pseudo", 2 },
{ "Start", 3 },
{ "Game over", 4 }
}
};
NumberField field_salle {
{ 10 * 8, 6 * 8 },
1,
{ 1, 2 },
1,
'0'
};
Button button_texte {
{ 14 * 8, 8 * 8, 16 * 8, 3 * 8 },
"ABCDEF"
};
NumberField field_equipe {
{ 10 * 8, 8 * 8 },
1,
{ 1, 6 },
16,
1,
'0'
};
NumberField field_joueur {
{ 10 * 8, 10 * 8 },
2,
{ 1, 50 },
1,
'0'
};
@ -80,13 +131,8 @@ private:
"All channels"
};
Text text_messagea {
{ 0 * 8, 10 * 16, 30 * 8, 16 },
""
};
Text text_messageb {
{ 0 * 8, 11 * 16, 30 * 8, 16 },
""
Console console {
{ 0, 18 * 8, 30 * 8, 7 * 16 }
};
TransmitterView tx_view {

View file

@ -134,10 +134,10 @@ ADSBCallsignView::ADSBCallsignView(
button_callsign.on_select = [this, &nav](Button&) {
text_prompt(
nav,
&callsign,
callsign,
8,
[this](std::string* s) {
button_callsign.set_text(*s);
[this](std::string& s) {
button_callsign.set_text(s);
}
);
};

View file

@ -99,10 +99,10 @@ APRSTXView::APRSTXView(NavigationView& nav) {
button_set.on_select = [this, &nav](Button&) {
text_prompt(
nav,
&payload,
payload,
30,
[this](std::string* s) {
text_payload.set(*s);
[this](std::string& s) {
text_payload.set(s);
}
);
};

View file

@ -237,8 +237,8 @@ FileLoadView::FileLoadView(
}
void FileManagerView::on_rename(NavigationView& nav) {
text_prompt(nav, &name_buffer, max_filename_length, [this](std::string * buffer) {
rename_file(get_selected_path(), *buffer);
text_prompt(nav, name_buffer, max_filename_length, [this](std::string& buffer) {
rename_file(get_selected_path(), buffer);
load_directory_contents(current_path);
refresh_list();
});
@ -298,10 +298,8 @@ FileManagerView::FileManagerView(
button_new_dir.on_select = [this, &nav](Button&) {
name_buffer.clear();
text_prompt(nav, &name_buffer, max_filename_length, [this](std::string * buffer) {
std::string path_str = *buffer;
make_new_directory(current_path.string() + '/' + path_str);
text_prompt(nav, name_buffer, max_filename_length, [this](std::string& buffer) {
make_new_directory(current_path.string() + '/' + buffer);
load_directory_contents(current_path);
refresh_list();
});

View file

@ -146,8 +146,8 @@ void FrequencySaveView::save_current_file() {
}
void FrequencySaveView::on_save_name() {
text_prompt(nav_, &desc_buffer, 28, [this](std::string * buffer) {
database.push_back({ value_, 0, *buffer, SINGLE });
text_prompt(nav_, desc_buffer, 28, [this](std::string& buffer) {
database.push_back({ value_, 0, buffer, SINGLE });
save_current_file();
});
}
@ -249,17 +249,17 @@ void FrequencyManagerView::on_edit_freq(rf::Frequency f) {
}
void FrequencyManagerView::on_edit_desc(NavigationView& nav) {
text_prompt(nav, &desc_buffer, 28, [this](std::string * buffer) {
database[menu_view.highlighted_index()].description = *buffer;
text_prompt(nav, desc_buffer, 28, [this](std::string& buffer) {
database[menu_view.highlighted_index()].description = buffer;
refresh_list();
save_freqman_file(file_list[categories[current_category_id].second], database);
});
}
void FrequencyManagerView::on_new_category(NavigationView& nav) {
text_prompt(nav, &desc_buffer, 8, [this](std::string * buffer) {
text_prompt(nav, desc_buffer, 8, [this](std::string& buffer) {
File freqman_file;
create_freqman_file(*buffer, freqman_file);
create_freqman_file(buffer, freqman_file);
});
populate_categories();
refresh_list();

View file

@ -149,10 +149,10 @@ void LCRView::start_tx(const bool scan) {
void LCRView::on_button_set_am(NavigationView& nav, int16_t button_id) {
text_prompt(
nav,
&litteral[button_id],
litteral[button_id],
7,
[this, button_id](std::string* buffer) {
texts[button_id].set(*buffer);
[this, button_id](std::string& buffer) {
texts[button_id].set(buffer);
});
}
@ -227,10 +227,10 @@ LCRView::LCRView(NavigationView& nav) {
button_set_rgsb.on_select = [this, &nav](Button&) {
text_prompt(
nav,
&rgsb,
rgsb,
4,
[this](std::string* buffer) {
button_set_rgsb.set_text(*buffer);
[this](std::string& buffer) {
button_set_rgsb.set_text(buffer);
});
};

View file

@ -70,7 +70,7 @@ static msg_t ookthread_fn(void * arg) {
}
void MorseView::on_set_text(NavigationView& nav) {
text_prompt(nav, &buffer, 28);
text_prompt(nav, buffer, 28);
}
void MorseView::focus() {

View file

@ -114,7 +114,7 @@ void POCSAGTXView::paint(Painter&) {
}
void POCSAGTXView::on_set_text(NavigationView& nav) {
text_prompt(nav, &buffer, 30);
text_prompt(nav, buffer, 30);
}
POCSAGTXView::POCSAGTXView(

View file

@ -66,10 +66,10 @@ RDSPSNView::RDSPSNView(
button_set.on_select = [this, &nav](Button&) {
text_prompt(
nav,
&PSN,
PSN,
8,
[this](std::string* s) {
text_psn.set(*s);
[this](std::string& s) {
text_psn.set(s);
}
);
};
@ -91,10 +91,10 @@ RDSRadioTextView::RDSRadioTextView(
button_set.on_select = [this, &nav](Button&){
text_prompt(
nav,
&radiotext,
radiotext,
28,
[this](std::string* s) {
text_radiotext.set(*s);
[this](std::string& s) {
text_radiotext.set(s);
}
);
};