update lastHeard handling

This commit is contained in:
mverch67
2024-03-05 21:36:20 +01:00
parent 8ac671a871
commit cfe808d308
5 changed files with 37 additions and 28 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ public:
virtual void updatePaxCounterModule(const meshtastic_ModuleConfig_PaxcounterConfig& cfg) {}
//
virtual void packetReceived(uint32_t from, uint32_t to, uint32_t portnum, const uint8_t* bytes, uint32_t size);
virtual void packetReceived(uint32_t from, const meshtastic_MeshPacket& p);
virtual void updateNodesOnline(const char* str);
virtual void updateLastHeard(uint32_t nodeNum);
+1 -1
View File
@@ -23,7 +23,7 @@ public:
virtual void updatePosition(uint32_t nodeNum, int32_t lat, int32_t lon, int32_t alt, uint32_t precision);
virtual void updateMetrics(uint32_t nodeNum, uint32_t bat_level, float voltage, float chUtil, float airUtil, uint32_t lastHeard);
virtual void updateSignalStrength(uint32_t nodeNum, int32_t rssi, float snr);
virtual void packetReceived(uint32_t from, uint32_t to, uint32_t portnum, const uint8_t* bytes, uint32_t size);
virtual void packetReceived(uint32_t from, const meshtastic_MeshPacket& p);
// methods to update device config
virtual void updateChannelConfig(uint32_t index, const char* name, const uint8_t* psk, uint32_t psk_size, uint8_t role);
+15 -12
View File
@@ -55,19 +55,24 @@ void MeshtasticView::updateSignalStrength(uint32_t nodeNum, int32_t rssi, float
{
}
void MeshtasticView::updateNodesOnline(const char* str) {
void MeshtasticView::updateNodesOnline(const char *str)
{
char buf[30];
sprintf(buf, str, nodesOnline, nodeCount);
lv_label_set_text(ui_TopNodesOnlineLabel, buf);
lv_label_set_text(ui_HomeNodesLabel, buf);
}
void MeshtasticView::updateLastHeard(uint32_t nodeNum) {
void MeshtasticView::updateLastHeard(uint32_t nodeNum)
{
}
void MeshtasticView::packetReceived(uint32_t from, uint32_t to, uint32_t portnum, const uint8_t* bytes, uint32_t size) {
void MeshtasticView::packetReceived(uint32_t from, const meshtastic_MeshPacket &p)
{
if (p.hop_limit - p.hop_start == 0)
{
updateSignalStrength(p.from, p.rx_rssi, p.rx_snr);
}
updateLastHeard(from);
}
@@ -75,7 +80,6 @@ void MeshtasticView::removeNode(uint32_t nodeNum)
{
}
// -------- helpers --------
uint32_t MeshtasticView::nodeColor(uint32_t nodeNum)
@@ -93,9 +97,9 @@ uint32_t MeshtasticView::nodeColor(uint32_t nodeNum)
}
/**
* @brief
*
* @param lastHeard
* @brief
*
* @param lastHeard
* @param buf - result string
* @return true, if heard within 15min
*/
@@ -112,9 +116,8 @@ bool MeshtasticView::lastHeartToString(uint32_t lastHeard, char *buf)
sprintf(buf, "%d h", timediff / 3600);
else if (timediff < 3600 * 24 * 60)
sprintf(buf, "%d d", timediff / 86400);
else // after 60 days
else // after 60 days
buf[0] = '\0';
return timediff <= 910; // 15min + some tolerance
}
+19 -12
View File
@@ -476,8 +476,8 @@ void TFTView_320x240::updateSignalStrength(uint32_t nodeNum, int32_t rssi, float
}
}
void TFTView_320x240::packetReceived(uint32_t from, uint32_t to, uint32_t portnum, const uint8_t* bytes, uint32_t size) {
MeshtasticView::packetReceived(from, to, portnum, bytes, size);
void TFTView_320x240::packetReceived(uint32_t from, const meshtastic_MeshPacket& p) {
MeshtasticView::packetReceived(from, p);
}
void TFTView_320x240::updateChannelConfig(uint32_t index, const char* name, const uint8_t* psk, uint32_t psk_size, uint8_t role) {
@@ -535,16 +535,21 @@ void TFTView_320x240::setNodeImage(uint32_t nodeNum, eRole role, lv_obj_t* img)
* @param nodeNum
*/
void TFTView_320x240::updateLastHeard(uint32_t nodeNum) {
time_t curtime;
time(&curtime);
auto it = nodes.find(nodeNum);
if (it != nodes.end()) {
time_t curtime;
time(&curtime);
time_t lastHeard = (time_t)it->second->LV_OBJ_IDX(node_lh_idx)->user_data;
it->second->LV_OBJ_IDX(node_lh_idx)->user_data = (void*)curtime;
lv_label_set_text(it->second->LV_OBJ_IDX(node_lh_idx), "now");
if (curtime - lastHeard >= 900) {
nodesOnline++;
updateNodesOnline("%d of %d nodes online");
if (lastHeard) {
it->second->LV_OBJ_IDX(node_lh_idx)->user_data = (void*)curtime;
lv_label_set_text(it->second->LV_OBJ_IDX(node_lh_idx), "now");
if (curtime - lastHeard >= 900) {
nodesOnline++;
updateNodesOnline("%d of %d nodes online");
}
// move to top position
if (it->first != ownNode)
lv_obj_move_to_index(it->second, 1);
}
}
}
@@ -568,9 +573,11 @@ void TFTView_320x240::updateAllLastHeard(void) {
else {
lastHeard = (time_t)it.second->LV_OBJ_IDX(node_lh_idx)->user_data;
}
bool isOnline = lastHeartToString(lastHeard, buf);
lv_label_set_text(it.second->LV_OBJ_IDX(node_lh_idx), buf);
if (isOnline) online++;
if (lastHeard) {
bool isOnline = lastHeartToString(lastHeard, buf);
lv_label_set_text(it.second->LV_OBJ_IDX(node_lh_idx), buf);
if (isOnline) online++;
}
}
nodesOnline = online;
updateNodesOnline("%d of %d nodes online");
+1 -2
View File
@@ -42,8 +42,7 @@ void ViewController::handleFromRadio(const meshtastic_FromRadio& from) {
}
case meshtastic_FromRadio_packet_tag: {
const meshtastic_MeshPacket& p = from.packet;
view->updateSignalStrength(p.from, p.rx_rssi, p.rx_snr);
view->packetReceived(p.from, p.to, p.decoded.portnum, p.decoded.payload.bytes, p.decoded.payload.size);
view->packetReceived(p.from, p);
break;
}
case meshtastic_FromRadio_node_info_tag: {