109109
110110#define MAX_SIGN_DATA_LEN (8 * 1024 ) // 8K
111111
112- #ifdef DISPLAY_CLASS
113- #include " UITask.h"
114- #endif
115-
116112void MyMesh::writeOKFrame () {
117113 uint8_t buf[1 ];
118114 buf[0 ] = RESP_CODE_OK;
@@ -247,7 +243,7 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
247243 }
248244 } else {
249245#ifdef DISPLAY_CLASS
250- ui_task. soundBuzzer (UIEventType::newContactMessage);
246+ if (_ui) _ui-> soundBuzzer (UIEventType::newContactMessage);
251247#endif
252248 }
253249
@@ -267,6 +263,7 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
267263 }
268264
269265 memcpy (p->pubkey_prefix , contact.id .pub_key , sizeof (p->pubkey_prefix ));
266+ strcpy (p->name , contact.name );
270267 p->recv_timestamp = getRTCClock ()->getCurrentTime ();
271268 p->path_len = path_len;
272269 memcpy (p->path , path, p->path_len );
@@ -275,6 +272,20 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
275272 dirty_contacts_expiry = futureMillis (LAZY_CONTACTS_WRITE_DELAY);
276273}
277274
275+ static int sort_by_recent (const void *a, const void *b) {
276+ return ((AdvertPath *) b)->recv_timestamp - ((AdvertPath *) a)->recv_timestamp ;
277+ }
278+
279+ int MyMesh::getRecentlyHeard (AdvertPath dest[], int max_num) {
280+ if (max_num > ADVERT_PATH_TABLE_SIZE) max_num = ADVERT_PATH_TABLE_SIZE;
281+ qsort (advert_paths, ADVERT_PATH_TABLE_SIZE, sizeof (advert_paths[0 ]), sort_by_recent);
282+
283+ for (int i = 0 ; i < max_num; i++) {
284+ dest[i] = advert_paths[i];
285+ }
286+ return max_num;
287+ }
288+
278289void MyMesh::onContactPathUpdated (const ContactInfo &contact) {
279290 out_frame[0 ] = PUSH_CODE_PATH_UPDATED;
280291 memcpy (&out_frame[1 ], contact.id .pub_key , PUB_KEY_SIZE);
@@ -339,10 +350,10 @@ void MyMesh::queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packe
339350#ifdef DISPLAY_CLASS
340351 // we only want to show text messages on display, not cli data
341352 bool should_display = txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN;
342- if (should_display) {
343- ui_task. newMsg (path_len, from.name , text, offline_queue_len);
353+ if (should_display && _ui ) {
354+ _ui-> newMsg (path_len, from.name , text, offline_queue_len);
344355 if (!_serial->isConnected ()) {
345- ui_task. soundBuzzer (UIEventType::contactMessage);
356+ _ui-> soundBuzzer (UIEventType::contactMessage);
346357 }
347358 }
348359#endif
@@ -401,7 +412,7 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
401412 _serial->writeFrame (frame, 1 );
402413 } else {
403414#ifdef DISPLAY_CLASS
404- ui_task. soundBuzzer (UIEventType::channelMessage);
415+ if (_ui) _ui-> soundBuzzer (UIEventType::channelMessage);
405416#endif
406417 }
407418#ifdef DISPLAY_CLASS
@@ -411,7 +422,7 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
411422 if (getChannel (channel_idx, channel_details)) {
412423 channel_name = channel_details.name ;
413424 }
414- ui_task. newMsg (path_len, channel_name, text, offline_queue_len);
425+ if (_ui) _ui-> newMsg (path_len, channel_name, text, offline_queue_len);
415426#endif
416427}
417428
@@ -620,9 +631,9 @@ uint32_t MyMesh::calcDirectTimeoutMillisFor(uint32_t pkt_airtime_millis, uint8_t
620631
621632void MyMesh::onSendTimeout () {}
622633
623- MyMesh::MyMesh (mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store)
634+ MyMesh::MyMesh (mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store, AbstractUITask* ui )
624635 : BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16 ), tables),
625- _serial(NULL ), telemetry(MAX_PACKET_PAYLOAD - 4 ), _store(&store) {
636+ _serial(NULL ), telemetry(MAX_PACKET_PAYLOAD - 4 ), _store(&store), _ui(ui) {
626637 _iter_started = false ;
627638 _cli_rescue = false ;
628639 offline_queue_len = 0 ;
@@ -1026,7 +1037,7 @@ void MyMesh::handleCmdFrame(size_t len) {
10261037 if ((out_len = getFromOfflineQueue (out_frame)) > 0 ) {
10271038 _serial->writeFrame (out_frame, out_len);
10281039#ifdef DISPLAY_CLASS
1029- ui_task. msgRead (offline_queue_len);
1040+ if (_ui) _ui-> msgRead (offline_queue_len);
10301041#endif
10311042 } else {
10321043 out_frame[0 ] = RESP_CODE_NO_MORE_MESSAGES;
@@ -1628,7 +1639,7 @@ void MyMesh::loop() {
16281639 }
16291640
16301641#ifdef DISPLAY_CLASS
1631- ui_task. setHasConnection (_serial->isConnected ());
1642+ if (_ui) _ui-> setHasConnection (_serial->isConnected ());
16321643#endif
16331644}
16341645
0 commit comments