mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-11-02 19:02:00 +00:00
ui: repeater discover screen
This commit is contained in:
@@ -134,6 +134,10 @@
|
|||||||
#define ERR_CODE_FILE_IO_ERROR 5
|
#define ERR_CODE_FILE_IO_ERROR 5
|
||||||
#define ERR_CODE_ILLEGAL_ARG 6
|
#define ERR_CODE_ILLEGAL_ARG 6
|
||||||
|
|
||||||
|
// Copied from simple_repeater (could probably be shared)
|
||||||
|
#define CTL_TYPE_NODE_DISCOVER_REQ 0x80
|
||||||
|
#define CTL_TYPE_NODE_DISCOVER_RESP 0x90
|
||||||
|
|
||||||
#define MAX_SIGN_DATA_LEN (8 * 1024) // 8K
|
#define MAX_SIGN_DATA_LEN (8 * 1024) // 8K
|
||||||
|
|
||||||
// Auto-add config bitmask
|
// Auto-add config bitmask
|
||||||
@@ -403,6 +407,51 @@ int MyMesh::getRecentlyHeard(AdvertPath dest[], int max_num) {
|
|||||||
return max_num;
|
return max_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MyMesh::getDiscoveredNodes(DiscoveredNode nodes[], int max_num) {
|
||||||
|
if (max_num > DISCOVERED_NODES_TABLE_SIZE) max_num = DISCOVERED_NODES_TABLE_SIZE;
|
||||||
|
if (max_num > disc_nodes_count) max_num = disc_nodes_count;
|
||||||
|
|
||||||
|
for (int i = 0; i < max_num; i++) {
|
||||||
|
nodes[i] = discovered_nodes[i];
|
||||||
|
}
|
||||||
|
return max_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MyMesh::requestRepeatersDiscovery() {
|
||||||
|
uint8_t cmd_bytes[6];
|
||||||
|
cmd_bytes[0] = CTL_TYPE_NODE_DISCOVER_REQ | 1; // DISCOVER_REQ | prefix only
|
||||||
|
cmd_bytes[1] = 0xFF; // Repeaters
|
||||||
|
getRNG()->random(&cmd_bytes[2], 4); // tag
|
||||||
|
disc_nodes_count = 0;
|
||||||
|
disc_node_req_tag = *((uint32_t*)&cmd_bytes[2]);
|
||||||
|
mesh::Packet* req = createControlData(cmd_bytes, sizeof(cmd_bytes));
|
||||||
|
if (req) {
|
||||||
|
sendZeroHop(req);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyMesh::checkControlDataForPendingDiscovery(uint8_t payload[], size_t p_len) {
|
||||||
|
if ((p_len < 12)
|
||||||
|
|| (payload[0] & 0xF0 != CTL_TYPE_NODE_DISCOVER_RESP)
|
||||||
|
|| (disc_nodes_count >= DISCOVERED_NODES_TABLE_SIZE)
|
||||||
|
|| (memcmp(&payload[2], &disc_node_req_tag, 4))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memcpy(&discovered_nodes[disc_nodes_count].pubkey_prefix, &payload[6], 8);
|
||||||
|
discovered_nodes[disc_nodes_count].type = payload[0] & 0xF;
|
||||||
|
discovered_nodes[disc_nodes_count].snr_out = ((int8_t)payload[1]) / 4.0;
|
||||||
|
discovered_nodes[disc_nodes_count].snr_in = _radio->getLastSNR();
|
||||||
|
ContactInfo* c = lookupContactByPubKey(&payload[6], 8);
|
||||||
|
if (c != NULL) {
|
||||||
|
strncpy(discovered_nodes[disc_nodes_count].name, c->name, 32);
|
||||||
|
} else {
|
||||||
|
discovered_nodes[disc_nodes_count].name[0] = 0;
|
||||||
|
}
|
||||||
|
disc_nodes_count ++;
|
||||||
|
}
|
||||||
|
|
||||||
void MyMesh::onContactPathUpdated(const ContactInfo &contact) {
|
void MyMesh::onContactPathUpdated(const ContactInfo &contact) {
|
||||||
out_frame[0] = PUSH_CODE_PATH_UPDATED;
|
out_frame[0] = PUSH_CODE_PATH_UPDATED;
|
||||||
memcpy(&out_frame[1], contact.id.pub_key, PUB_KEY_SIZE);
|
memcpy(&out_frame[1], contact.id.pub_key, PUB_KEY_SIZE);
|
||||||
@@ -783,6 +832,7 @@ void MyMesh::onControlDataRecv(mesh::Packet *packet) {
|
|||||||
MESH_DEBUG_PRINTLN("onControlDataRecv(), payload_len too long: %d", packet->payload_len);
|
MESH_DEBUG_PRINTLN("onControlDataRecv(), payload_len too long: %d", packet->payload_len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
checkControlDataForPendingDiscovery(packet->payload, packet->payload_len);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
out_frame[i++] = PUSH_CODE_CONTROL_DATA;
|
out_frame[i++] = PUSH_CODE_CONTROL_DATA;
|
||||||
out_frame[i++] = (int8_t)(_radio->getLastSNR() * 4);
|
out_frame[i++] = (int8_t)(_radio->getLastSNR() * 4);
|
||||||
|
|||||||
@@ -84,6 +84,14 @@ struct AdvertPath {
|
|||||||
uint8_t path[MAX_PATH_SIZE];
|
uint8_t path[MAX_PATH_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DiscoveredNode {
|
||||||
|
uint8_t pubkey_prefix[9];
|
||||||
|
float snr_in;
|
||||||
|
float snr_out;
|
||||||
|
char name[32];
|
||||||
|
uint8_t type;
|
||||||
|
};
|
||||||
|
|
||||||
class MyMesh : public BaseChatMesh, public DataStoreHost {
|
class MyMesh : public BaseChatMesh, public DataStoreHost {
|
||||||
public:
|
public:
|
||||||
MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store, AbstractUITask* ui=NULL);
|
MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store, AbstractUITask* ui=NULL);
|
||||||
@@ -102,6 +110,9 @@ public:
|
|||||||
|
|
||||||
int getRecentlyHeard(AdvertPath dest[], int max_num);
|
int getRecentlyHeard(AdvertPath dest[], int max_num);
|
||||||
|
|
||||||
|
bool requestRepeatersDiscovery();
|
||||||
|
int getDiscoveredNodes(DiscoveredNode nodes[], int max_num);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float getAirtimeBudgetFactor() const override;
|
float getAirtimeBudgetFactor() const override;
|
||||||
int getInterferenceThreshold() const override;
|
int getInterferenceThreshold() const override;
|
||||||
@@ -256,6 +267,13 @@ private:
|
|||||||
|
|
||||||
#define ADVERT_PATH_TABLE_SIZE 16
|
#define ADVERT_PATH_TABLE_SIZE 16
|
||||||
AdvertPath advert_paths[ADVERT_PATH_TABLE_SIZE]; // circular table
|
AdvertPath advert_paths[ADVERT_PATH_TABLE_SIZE]; // circular table
|
||||||
|
|
||||||
|
#define DISCOVERED_NODES_TABLE_SIZE 10
|
||||||
|
DiscoveredNode discovered_nodes[DISCOVERED_NODES_TABLE_SIZE]; // not circular, latest discovered nodes are not kept
|
||||||
|
uint32_t disc_node_req_tag = 0;
|
||||||
|
uint32_t disc_nodes_count = 0;
|
||||||
|
|
||||||
|
void checkControlDataForPendingDiscovery(uint8_t payload[], size_t p_len);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MyMesh the_mesh;
|
extern MyMesh the_mesh;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#define LONG_PRESS_MILLIS 1200
|
#define LONG_PRESS_MILLIS 1200
|
||||||
|
|
||||||
|
// Used both for recent adverts and discovered nodes
|
||||||
#ifndef UI_RECENT_LIST_SIZE
|
#ifndef UI_RECENT_LIST_SIZE
|
||||||
#define UI_RECENT_LIST_SIZE 4
|
#define UI_RECENT_LIST_SIZE 4
|
||||||
#endif
|
#endif
|
||||||
@@ -102,6 +103,7 @@ class HomeScreen : public UIScreen {
|
|||||||
#if UI_SENSORS_PAGE == 1
|
#if UI_SENSORS_PAGE == 1
|
||||||
SENSORS,
|
SENSORS,
|
||||||
#endif
|
#endif
|
||||||
|
DISCOVERY,
|
||||||
SHUTDOWN,
|
SHUTDOWN,
|
||||||
Count // keep as last
|
Count // keep as last
|
||||||
};
|
};
|
||||||
@@ -113,7 +115,9 @@ class HomeScreen : public UIScreen {
|
|||||||
uint8_t _page;
|
uint8_t _page;
|
||||||
bool _shutdown_init;
|
bool _shutdown_init;
|
||||||
AdvertPath recent[UI_RECENT_LIST_SIZE];
|
AdvertPath recent[UI_RECENT_LIST_SIZE];
|
||||||
|
DiscoveredNode discovered[UI_RECENT_LIST_SIZE];
|
||||||
|
uint32_t discovery_req_time = 0;
|
||||||
|
bool discovery_disp_names = true; // by default desplay names if available (removes SNR_O)
|
||||||
|
|
||||||
void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts) {
|
void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts) {
|
||||||
// Convert millivolts to percentage
|
// Convert millivolts to percentage
|
||||||
@@ -459,6 +463,39 @@ public:
|
|||||||
if (sensors_scroll) sensors_scroll_offset = (sensors_scroll_offset+1)%sensors_nb;
|
if (sensors_scroll) sensors_scroll_offset = (sensors_scroll_offset+1)%sensors_nb;
|
||||||
else sensors_scroll_offset = 0;
|
else sensors_scroll_offset = 0;
|
||||||
#endif
|
#endif
|
||||||
|
} else if (_page == HomePage::DISCOVERY) {
|
||||||
|
int count = the_mesh.getDiscoveredNodes(discovered, UI_RECENT_LIST_SIZE);
|
||||||
|
display.setColor(UIColor::primary_txt);
|
||||||
|
int y = 20;
|
||||||
|
for (int i = 0; i < count; i++, y += 11) {
|
||||||
|
char name[32];
|
||||||
|
auto a = &discovered[i];
|
||||||
|
if ((a->name[0] == 0) || !discovery_disp_names) {
|
||||||
|
mesh::Utils::toHex(name, a->pubkey_prefix, 4);
|
||||||
|
} else {
|
||||||
|
strncpy(name, a->name, 32);
|
||||||
|
}
|
||||||
|
char filtered_name[sizeof(name)];
|
||||||
|
char snr_s[12];
|
||||||
|
if (strlen(name) <= 8) { // display snr_o
|
||||||
|
sprintf(snr_s, "%02.1f>%02.1f", a->snr_out, a->snr_in);
|
||||||
|
} else {
|
||||||
|
sprintf(snr_s, "%02.1f", a->snr_in);
|
||||||
|
}
|
||||||
|
int snr_width = display.getTextWidth(snr_s);
|
||||||
|
int max_name_width = display.width() - snr_width - 1;
|
||||||
|
display.translateUTF8ToBlocks(filtered_name, name, sizeof(filtered_name));
|
||||||
|
display.drawTextEllipsized(0, y, max_name_width, filtered_name);
|
||||||
|
display.setCursor(display.width() - snr_width - 1, y);
|
||||||
|
display.print(snr_s);
|
||||||
|
}
|
||||||
|
if (millis() < discovery_req_time + 5000) {
|
||||||
|
return 1000; // more frequent updates just after req
|
||||||
|
} else if (count < UI_RECENT_LIST_SIZE -1) { // show only 5 sec after last disc
|
||||||
|
y = 10 + 11 * UI_RECENT_LIST_SIZE;
|
||||||
|
display.drawTextCentered(display.width() / 2, y, "discover: " PRESS_LABEL);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (_page == HomePage::SHUTDOWN) {
|
} else if (_page == HomePage::SHUTDOWN) {
|
||||||
display.setColor(UIColor::corp_blue);
|
display.setColor(UIColor::corp_blue);
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
@@ -484,6 +521,9 @@ public:
|
|||||||
if (_page == HomePage::RECENT) {
|
if (_page == HomePage::RECENT) {
|
||||||
_task->showAlert("Recent adverts", 800);
|
_task->showAlert("Recent adverts", 800);
|
||||||
}
|
}
|
||||||
|
if (_page == HomePage::DISCOVERY) {
|
||||||
|
_task->showAlert("Repeater disc", 800);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (c == KEY_ENTER && _page == HomePage::BLUETOOTH) {
|
if (c == KEY_ENTER && _page == HomePage::BLUETOOTH) {
|
||||||
@@ -516,6 +556,17 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (c == KEY_ENTER && _page == HomePage::DISCOVERY) {
|
||||||
|
if (millis() > discovery_req_time + 5000) { // rate limiter
|
||||||
|
the_mesh.requestRepeatersDiscovery();
|
||||||
|
discovery_req_time = millis();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c == KEY_SELECT && _page == HomePage::DISCOVERY) {
|
||||||
|
discovery_disp_names = !discovery_disp_names;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (c == KEY_ENTER && _page == HomePage::SHUTDOWN) {
|
if (c == KEY_ENTER && _page == HomePage::SHUTDOWN) {
|
||||||
_shutdown_init = true; // need to wait for button to be released
|
_shutdown_init = true; // need to wait for button to be released
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user