mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 14:42:05 +00:00
Merge branch 'master' into RGBLED
This commit is contained in:
commit
78d915b454
@ -2,6 +2,7 @@
|
|||||||
#include <NodeDB.h>
|
#include <NodeDB.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#define ONE_DAY 24 * 60 * 60
|
#define ONE_DAY 24 * 60 * 60
|
||||||
|
#define ONE_MINUTE_MS 60 * 1000
|
||||||
|
|
||||||
#define default_gps_update_interval IF_ROUTER(ONE_DAY, 2 * 60)
|
#define default_gps_update_interval IF_ROUTER(ONE_DAY, 2 * 60)
|
||||||
#define default_broadcast_interval_secs IF_ROUTER(ONE_DAY / 2, 15 * 60)
|
#define default_broadcast_interval_secs IF_ROUTER(ONE_DAY / 2, 15 * 60)
|
||||||
|
@ -813,6 +813,7 @@ size_t NodeDB::getNumOnlineMeshNodes(bool localOnly)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include "MeshModule.h"
|
#include "MeshModule.h"
|
||||||
|
#include "Throttle.h"
|
||||||
|
|
||||||
/** Update position info for this node based on received position data
|
/** Update position info for this node based on received position data
|
||||||
*/
|
*/
|
||||||
@ -907,8 +908,10 @@ bool NodeDB::updateUser(uint32_t nodeId, const meshtastic_User &p, uint8_t chann
|
|||||||
powerFSM.trigger(EVENT_NODEDB_UPDATED);
|
powerFSM.trigger(EVENT_NODEDB_UPDATED);
|
||||||
notifyObservers(true); // Force an update whether or not our node counts have changed
|
notifyObservers(true); // Force an update whether or not our node counts have changed
|
||||||
|
|
||||||
// We just changed something important about the user, store our DB
|
// We just changed something about the user, store our DB
|
||||||
saveToDisk(SEGMENT_DEVICESTATE);
|
Throttle::execute(
|
||||||
|
&lastNodeDbSave, ONE_MINUTE_MS, []() { nodeDB->saveToDisk(SEGMENT_DEVICESTATE); },
|
||||||
|
[]() { LOG_DEBUG("Deferring NodeDB saveToDisk for now, since we saved less than a minute ago\n"); });
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
|
@ -160,6 +160,7 @@ class NodeDB
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
uint32_t lastNodeDbSave = 0; // when we last saved our db to flash
|
||||||
/// Find a node in our DB, create an empty NodeInfoLite if missing
|
/// Find a node in our DB, create an empty NodeInfoLite if missing
|
||||||
meshtastic_NodeInfoLite *getOrCreateMeshNode(NodeNum n);
|
meshtastic_NodeInfoLite *getOrCreateMeshNode(NodeNum n);
|
||||||
|
|
||||||
|
27
src/mesh/Throttle.cpp
Normal file
27
src/mesh/Throttle.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "Throttle.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
/// @brief Execute a function throttled to a minimum interval
|
||||||
|
/// @param lastExecutionMs Pointer to the last execution time in milliseconds
|
||||||
|
/// @param minumumIntervalMs Minimum execution interval in milliseconds
|
||||||
|
/// @param throttleFunc Function to execute if the execution is not deferred
|
||||||
|
/// @param onDefer Default to NULL, execute the function if the execution is deferred
|
||||||
|
/// @return true if the function was executed, false if it was deferred
|
||||||
|
bool Throttle::execute(uint32_t *lastExecutionMs, uint32_t minumumIntervalMs, void (*throttleFunc)(void), void (*onDefer)(void))
|
||||||
|
{
|
||||||
|
if (*lastExecutionMs == 0) {
|
||||||
|
*lastExecutionMs = millis();
|
||||||
|
throttleFunc();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
uint32_t now = millis();
|
||||||
|
|
||||||
|
if ((now - *lastExecutionMs) >= minumumIntervalMs) {
|
||||||
|
throttleFunc();
|
||||||
|
*lastExecutionMs = now;
|
||||||
|
return true;
|
||||||
|
} else if (onDefer != NULL) {
|
||||||
|
onDefer();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
9
src/mesh/Throttle.h
Normal file
9
src/mesh/Throttle.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
class Throttle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool execute(uint32_t *lastExecutionMs, uint32_t minumumIntervalMs, void (*func)(void), void (*onDefer)(void) = NULL);
|
||||||
|
};
|
@ -506,7 +506,7 @@ bool StoreForwardModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(0); // unexpected state
|
break; // no need to do anything
|
||||||
}
|
}
|
||||||
return true; // There's no need for others to look at this message.
|
return true; // There's no need for others to look at this message.
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user