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) {
int remaining = length - start;
int chunkSize = (remaining > 30) ? 30 : remaining;
int chunkSize = (remaining > 29) ? 29 : remaining;
result.push_back(std::string(input + start, chunkSize));
start += chunkSize;
}
@ -203,14 +203,32 @@ void BLETxView::start() {
}
if (found) {
int min = 0;
int max = 15;
uint8_t hexDigit;
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
char randomHexChar = (hexDigit < 10) ? ('0' + hexDigit) : ('A' + hexDigit - 10);
advertisementData[i] = randomHexChar;
advertisementData[i] = uint_to_char(hexDigit, 16);
// 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_channel,
&options_adv_type,
&label_marked_data,
&marked_data_sequence,
&label_packet_index,
&text_packet_index,
&label_packets_sent,
@ -318,9 +338,8 @@ BLETxView::BLETxView(NavigationView& nav)
&label_mac_address,
&text_mac_address,
&label_data_packet,
&label_data_index,
&text_data_index,
&dataEditView,
&button_clear_marked,
&button_save_packet,
&button_switch});
@ -392,19 +411,26 @@ BLETxView::BLETxView(NavigationView& nav)
cursor_pos.line = dataEditView.line();
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()) {
markedBytes.erase(it);
} else {
markedBytes.push_back(dataBytePos);
if (it != markedBytes.end()) {
markedBytes.erase(it);
} else {
markedBytes.push_back(dataBytePos);
}
dataEditView.cursor_mark_selected();
}
};
dataEditView.cursor_mark_selected();
text_data_index.set(to_string_dec_uint(dataBytePos));
button_clear_marked.on_select = [this](Button&) {
marked_counter = 0;
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::vector<uint16_t> markedBytes{};
CursorPos cursor_pos{};
uint8_t marked_counter = 0;
static constexpr uint8_t mac_address_size_str{12};
static constexpr uint8_t max_packet_size_str{62};
@ -179,8 +180,8 @@ class BLETxView : public View {
PKT_TYPE pduType = {PKT_TYPE_DISCOVERY};
static constexpr auto header_height = 9 * 16;
static constexpr auto switch_button_height = 5 * 16;
static constexpr auto header_height = 10 * 16;
static constexpr auto switch_button_height = 6 * 16;
Button button_open{
{0 * 8, 0 * 16, 10 * 8, 2 * 16},
@ -196,7 +197,7 @@ class BLETxView : public View {
Checkbox check_rand_mac{
{21 * 8, 1 * 16},
6,
"Random",
"?? Mac",
true};
TxFrequencyField field_frequency{
@ -251,42 +252,49 @@ class BLETxView : public View {
{"SCAN_RSP", PKT_TYPE_SCAN_RSP},
{"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{
{{0 * 8, 10 * 8}, "Packet Index:", Color::light_grey()}};
{{0 * 8, 12 * 8}, "Packet Index:", Color::light_grey()}};
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},
"-"};
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{
{{0 * 8, 14 * 8}, "Mac Address:", Color::light_grey()}};
{{0 * 8, 16 * 8}, "Mac Address:", Color::light_grey()}};
Text text_mac_address{
{12 * 8, 7 * 16, 20 * 8, 16},
{12 * 8, 8 * 16, 20 * 8, 16},
"-"};
Labels label_data_packet{
{{0 * 8, 8 * 16}, "Packet Data:", Color::light_grey()}};
{{0 * 8, 9 * 16}, "Packet Data:", Color::light_grey()}};
Console console{
{0, 9 * 16, 240, 240}};
{0, 9 * 18, 240, 240}};
TextViewer dataEditView{
{0, 9 * 16, 240, 240}};
{0, 9 * 18, 240, 240}};
Labels label_data_index{
{{0 * 8, 28 * 8}, "Data Index:", Color::light_grey()}};
Text text_data_index{
{11 * 8, 14 * 16, 8 * 8, 16},
"-"};
Button button_clear_marked{
{1 * 8, 14 * 16, 13 * 8, 3 * 8},
"Clear Marked"};
Button button_save_packet{
{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() {
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()) {
pairedVector.erase(it);
if (it != lineColPair.end()) {
lineColPair.erase(it);
} else {
pairedVector.push_back(newMarker);
lineColPair.push_back(newMarker);
}
// Mark pending change.
@ -167,6 +167,11 @@ void TextViewer::cursor_mark_selected() {
redraw();
}
void TextViewer::cursor_clear_marked() {
lineColPair.clear();
redraw(true, true);
}
uint16_t TextViewer::line_length() {
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;
xor_cursor(entry.first, entry.second);
it++;

View File

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