Random data selection feature done. (#1617)

This commit is contained in:
Netro 2023-12-02 02:05:29 -05:00 committed by GitHub
parent b7b4a10485
commit 7354ba8fd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 47 deletions

View File

@ -67,7 +67,7 @@ std::vector<std::string> splitIntoStrings(const char* input) {
while (start < length) { while (start < length) {
int remaining = length - start; int remaining = length - start;
int chunkSize = (remaining > 30) ? 30 : remaining; int chunkSize = (remaining > 29) ? 29 : remaining;
result.push_back(std::string(input + start, chunkSize)); result.push_back(std::string(input + start, chunkSize));
start += chunkSize; start += chunkSize;
} }
@ -203,14 +203,32 @@ void BLETxView::start() {
} }
if (found) { if (found) {
int min = 0; uint8_t hexDigit;
int max = 15; switch (marked_data_sequence.selected_index_value()) {
case 0:
hexDigit = marked_counter++;
break;
case 1:
hexDigit = marked_counter--;
break;
case 2: {
uint8_t min = 0x00;
uint8_t max = 0x0F;
int hexDigit = min + std::rand() % (max - min + 1); hexDigit = min + std::rand() % (max - min + 1);
} break;
default:
break;
}
// Map the random number to a hexadecimal digit advertisementData[i] = uint_to_char(hexDigit, 16);
char randomHexChar = (hexDigit < 10) ? ('0' + hexDigit) : ('A' + hexDigit - 10);
advertisementData[i] = randomHexChar; // Bounding to Hex.
if (marked_counter == 16) {
marked_counter = 0;
} else if (marked_counter == 255) {
marked_counter = 15;
}
} }
} }
} }
@ -311,6 +329,8 @@ BLETxView::BLETxView(NavigationView& nav)
&options_speed, &options_speed,
&options_channel, &options_channel,
&options_adv_type, &options_adv_type,
&label_marked_data,
&marked_data_sequence,
&label_packet_index, &label_packet_index,
&text_packet_index, &text_packet_index,
&label_packets_sent, &label_packets_sent,
@ -318,9 +338,8 @@ BLETxView::BLETxView(NavigationView& nav)
&label_mac_address, &label_mac_address,
&text_mac_address, &text_mac_address,
&label_data_packet, &label_data_packet,
&label_data_index,
&text_data_index,
&dataEditView, &dataEditView,
&button_clear_marked,
&button_save_packet, &button_save_packet,
&button_switch}); &button_switch});
@ -392,19 +411,26 @@ BLETxView::BLETxView(NavigationView& nav)
cursor_pos.line = dataEditView.line(); cursor_pos.line = dataEditView.line();
cursor_pos.col = dataEditView.col(); cursor_pos.col = dataEditView.col();
uint16_t dataBytePos = ((dataEditView.line()) * 30) + dataEditView.col(); // Reject setting newline at index 29.
if (cursor_pos.col != 29) {
uint16_t dataBytePos = (cursor_pos.line * 29) + cursor_pos.col;
auto it = std::find(markedBytes.begin(), markedBytes.end(), dataBytePos); auto it = std::find(markedBytes.begin(), markedBytes.end(), dataBytePos);
if (it != markedBytes.end()) { if (it != markedBytes.end()) {
markedBytes.erase(it); markedBytes.erase(it);
} else { } else {
markedBytes.push_back(dataBytePos); markedBytes.push_back(dataBytePos);
}
dataEditView.cursor_mark_selected();
} }
};
dataEditView.cursor_mark_selected(); button_clear_marked.on_select = [this](Button&) {
marked_counter = 0;
text_data_index.set(to_string_dec_uint(dataBytePos)); markedBytes.clear();
dataEditView.cursor_clear_marked();
}; };
} }

View File

@ -168,6 +168,7 @@ class BLETxView : public View {
std::filesystem::path dataTempFilePath{u"BLETX/dataFileTemp.TXT"}; std::filesystem::path dataTempFilePath{u"BLETX/dataFileTemp.TXT"};
std::vector<uint16_t> markedBytes{}; std::vector<uint16_t> markedBytes{};
CursorPos cursor_pos{}; CursorPos cursor_pos{};
uint8_t marked_counter = 0;
static constexpr uint8_t mac_address_size_str{12}; static constexpr uint8_t mac_address_size_str{12};
static constexpr uint8_t max_packet_size_str{62}; static constexpr uint8_t max_packet_size_str{62};
@ -179,8 +180,8 @@ class BLETxView : public View {
PKT_TYPE pduType = {PKT_TYPE_DISCOVERY}; PKT_TYPE pduType = {PKT_TYPE_DISCOVERY};
static constexpr auto header_height = 9 * 16; static constexpr auto header_height = 10 * 16;
static constexpr auto switch_button_height = 5 * 16; static constexpr auto switch_button_height = 6 * 16;
Button button_open{ Button button_open{
{0 * 8, 0 * 16, 10 * 8, 2 * 16}, {0 * 8, 0 * 16, 10 * 8, 2 * 16},
@ -196,7 +197,7 @@ class BLETxView : public View {
Checkbox check_rand_mac{ Checkbox check_rand_mac{
{21 * 8, 1 * 16}, {21 * 8, 1 * 16},
6, 6,
"Random", "?? Mac",
true}; true};
TxFrequencyField field_frequency{ TxFrequencyField field_frequency{
@ -251,42 +252,49 @@ class BLETxView : public View {
{"SCAN_RSP", PKT_TYPE_SCAN_RSP}, {"SCAN_RSP", PKT_TYPE_SCAN_RSP},
{"CONNECT_REQ", PKT_TYPE_CONNECT_REQ}}}; {"CONNECT_REQ", PKT_TYPE_CONNECT_REQ}}};
Labels label_marked_data{
{{0 * 8, 4 * 16}, "Marked Data:", Color::light_grey()}};
OptionsField marked_data_sequence{
{12 * 8, 8 * 8},
8,
{{"Ascend", 0},
{"Descend", 1},
{"Random", 2}}};
Labels label_packet_index{ Labels label_packet_index{
{{0 * 8, 10 * 8}, "Packet Index:", Color::light_grey()}}; {{0 * 8, 12 * 8}, "Packet Index:", Color::light_grey()}};
Text text_packet_index{ Text text_packet_index{
{13 * 8, 5 * 16, 12 * 8, 16},
"-"};
Labels label_packets_sent{
{{0 * 8, 12 * 8}, "Repeat Count:", Color::light_grey()}};
Text text_packets_sent{
{13 * 8, 6 * 16, 12 * 8, 16}, {13 * 8, 6 * 16, 12 * 8, 16},
"-"}; "-"};
Labels label_packets_sent{
{{0 * 8, 14 * 8}, "Repeat Count:", Color::light_grey()}};
Text text_packets_sent{
{13 * 8, 7 * 16, 12 * 8, 16},
"-"};
Labels label_mac_address{ Labels label_mac_address{
{{0 * 8, 14 * 8}, "Mac Address:", Color::light_grey()}}; {{0 * 8, 16 * 8}, "Mac Address:", Color::light_grey()}};
Text text_mac_address{ Text text_mac_address{
{12 * 8, 7 * 16, 20 * 8, 16}, {12 * 8, 8 * 16, 20 * 8, 16},
"-"}; "-"};
Labels label_data_packet{ Labels label_data_packet{
{{0 * 8, 8 * 16}, "Packet Data:", Color::light_grey()}}; {{0 * 8, 9 * 16}, "Packet Data:", Color::light_grey()}};
Console console{ Console console{
{0, 9 * 16, 240, 240}}; {0, 9 * 18, 240, 240}};
TextViewer dataEditView{ TextViewer dataEditView{
{0, 9 * 16, 240, 240}}; {0, 9 * 18, 240, 240}};
Labels label_data_index{ Button button_clear_marked{
{{0 * 8, 28 * 8}, "Data Index:", Color::light_grey()}}; {1 * 8, 14 * 16, 13 * 8, 3 * 8},
"Clear Marked"};
Text text_data_index{
{11 * 8, 14 * 16, 8 * 8, 16},
"-"};
Button button_save_packet{ Button button_save_packet{
{1 * 8, 16 * 16, 13 * 8, 2 * 16}, {1 * 8, 16 * 16, 13 * 8, 2 * 16},

View File

@ -153,12 +153,12 @@ void TextViewer::cursor_set(uint16_t line, uint16_t col) {
void TextViewer::cursor_mark_selected() { void TextViewer::cursor_mark_selected() {
LineColPair newMarker = std::make_pair(cursor_.line, cursor_.col); LineColPair newMarker = std::make_pair(cursor_.line, cursor_.col);
auto it = std::find(pairedVector.begin(), pairedVector.end(), newMarker); auto it = std::find(lineColPair.begin(), lineColPair.end(), newMarker);
if (it != pairedVector.end()) { if (it != lineColPair.end()) {
pairedVector.erase(it); lineColPair.erase(it);
} else { } else {
pairedVector.push_back(newMarker); lineColPair.push_back(newMarker);
} }
// Mark pending change. // Mark pending change.
@ -167,6 +167,11 @@ void TextViewer::cursor_mark_selected() {
redraw(); redraw();
} }
void TextViewer::cursor_clear_marked() {
lineColPair.clear();
redraw(true, true);
}
uint16_t TextViewer::line_length() { uint16_t TextViewer::line_length() {
return file_->line_length(cursor_.line); return file_->line_length(cursor_.line);
} }
@ -313,9 +318,9 @@ void TextViewer::paint_marked(Painter& painter) {
} }
}; };
auto it = pairedVector.begin(); auto it = lineColPair.begin();
while (it != pairedVector.end()) { while (it != lineColPair.end()) {
LineColPair entry = (LineColPair)*it; LineColPair entry = (LineColPair)*it;
xor_cursor(entry.first, entry.second); xor_cursor(entry.first, entry.second);
it++; it++;

View File

@ -73,9 +73,10 @@ class TextViewer : public Widget {
void cursor_end(); void cursor_end();
void cursor_set(uint16_t line, uint16_t col); void cursor_set(uint16_t line, uint16_t col);
void cursor_mark_selected(); void cursor_mark_selected();
void cursor_clear_marked();
typedef std::pair<uint16_t, uint16_t> LineColPair; typedef std::pair<uint16_t, uint16_t> LineColPair;
std::vector<LineColPair> pairedVector{}; std::vector<LineColPair> lineColPair{};
// Gets the length of the current line. // Gets the length of the current line.
uint16_t line_length(); uint16_t line_length();