mirror of
https://github.com/meshtastic/firmware.git
synced 2025-10-03 13:55:45 +00:00
Merge branch 'develop' into clear-rangetest-results
This commit is contained in:
commit
7eb0109e33
@ -36,6 +36,7 @@ build_flags =
|
|||||||
-DCONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE=8192
|
-DCONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE=8192
|
||||||
-DESP_OPENSSL_SUPPRESS_LEGACY_WARNING
|
-DESP_OPENSSL_SUPPRESS_LEGACY_WARNING
|
||||||
-DSERIAL_BUFFER_SIZE=4096
|
-DSERIAL_BUFFER_SIZE=4096
|
||||||
|
-DSERIAL_HAS_ON_RECEIVE
|
||||||
-DLIBPAX_ARDUINO
|
-DLIBPAX_ARDUINO
|
||||||
-DLIBPAX_WIFI
|
-DLIBPAX_WIFI
|
||||||
-DLIBPAX_BLE
|
-DLIBPAX_BLE
|
||||||
|
@ -56,6 +56,7 @@ build_flags = -Wno-missing-field-initializers
|
|||||||
#-DBUILD_EPOCH=$UNIX_TIME ; set in platformio-custom.py now
|
#-DBUILD_EPOCH=$UNIX_TIME ; set in platformio-custom.py now
|
||||||
#-D OLED_PL=1
|
#-D OLED_PL=1
|
||||||
#-D DEBUG_HEAP=1 ; uncomment to add free heap space / memory leak debugging logs
|
#-D DEBUG_HEAP=1 ; uncomment to add free heap space / memory leak debugging logs
|
||||||
|
#-D DEBUG_LOOP_TIMING=1 ; uncomment to add main loop timing logs
|
||||||
|
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
monitor_filters = direct
|
monitor_filters = direct
|
||||||
|
@ -26,6 +26,7 @@ class AudioThread : public concurrency::OSThread
|
|||||||
i2sRtttl->begin(rtttlFile, audioOut);
|
i2sRtttl->begin(rtttlFile, audioOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Also handles actually playing the RTTTL, needs to be called in loop
|
||||||
bool isPlaying()
|
bool isPlaying()
|
||||||
{
|
{
|
||||||
if (i2sRtttl != nullptr) {
|
if (i2sRtttl != nullptr) {
|
||||||
|
@ -6,6 +6,14 @@
|
|||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
|
|
||||||
|
#if defined(ARDUINO_USB_CDC_ON_BOOT) && ARDUINO_USB_CDC_ON_BOOT
|
||||||
|
#define IS_USB_SERIAL
|
||||||
|
#ifdef SERIAL_HAS_ON_RECEIVE
|
||||||
|
#undef SERIAL_HAS_ON_RECEIVE
|
||||||
|
#endif
|
||||||
|
#include "HWCDC.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef RP2040_SLOW_CLOCK
|
#ifdef RP2040_SLOW_CLOCK
|
||||||
#define Port Serial2
|
#define Port Serial2
|
||||||
#else
|
#else
|
||||||
@ -22,7 +30,12 @@ SerialConsole *console;
|
|||||||
|
|
||||||
void consoleInit()
|
void consoleInit()
|
||||||
{
|
{
|
||||||
new SerialConsole(); // Must be dynamically allocated because we are now inheriting from thread
|
auto sc = new SerialConsole(); // Must be dynamically allocated because we are now inheriting from thread
|
||||||
|
|
||||||
|
#if defined(SERIAL_HAS_ON_RECEIVE)
|
||||||
|
// onReceive does only exist for HardwareSerial not for USB CDC serial
|
||||||
|
Port.onReceive([sc]() { sc->rxInt(); });
|
||||||
|
#endif
|
||||||
DEBUG_PORT.rpInit(); // Simply sets up semaphore
|
DEBUG_PORT.rpInit(); // Simply sets up semaphore
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +84,15 @@ int32_t SerialConsole::runOnce()
|
|||||||
return 250;
|
return 250;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return runOncePart();
|
|
||||||
|
int32_t delay = runOncePart();
|
||||||
|
#if defined(SERIAL_HAS_ON_RECEIVE)
|
||||||
|
return Port.available() ? delay : INT32_MAX;
|
||||||
|
#elif defined(IS_USB_SERIAL)
|
||||||
|
return HWCDC::isPlugged() ? delay : (1000 * 20);
|
||||||
|
#else
|
||||||
|
return delay;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialConsole::flush()
|
void SerialConsole::flush()
|
||||||
@ -79,6 +100,18 @@ void SerialConsole::flush()
|
|||||||
Port.flush();
|
Port.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trigger tx of serial data
|
||||||
|
void SerialConsole::onNowHasData(uint32_t fromRadioNum)
|
||||||
|
{
|
||||||
|
setIntervalFromNow(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// trigger rx of serial data
|
||||||
|
void SerialConsole::rxInt()
|
||||||
|
{
|
||||||
|
setIntervalFromNow(0);
|
||||||
|
}
|
||||||
|
|
||||||
// For the serial port we can't really detect if any client is on the other side, so instead just look for recent messages
|
// For the serial port we can't really detect if any client is on the other side, so instead just look for recent messages
|
||||||
bool SerialConsole::checkIsConnected()
|
bool SerialConsole::checkIsConnected()
|
||||||
{
|
{
|
||||||
|
@ -32,11 +32,14 @@ class SerialConsole : public StreamAPI, public RedirectablePrint, private concur
|
|||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
void rxInt();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Check the current underlying physical link to see if the client is currently connected
|
/// Check the current underlying physical link to see if the client is currently connected
|
||||||
virtual bool checkIsConnected() override;
|
virtual bool checkIsConnected() override;
|
||||||
|
|
||||||
|
virtual void onNowHasData(uint32_t fromRadioNum) override;
|
||||||
|
|
||||||
/// Possibly switch to protobufs if we see a valid protobuf message
|
/// Possibly switch to protobufs if we see a valid protobuf message
|
||||||
virtual void log_to_serial(const char *logLevel, const char *format, va_list arg);
|
virtual void log_to_serial(const char *logLevel, const char *format, va_list arg);
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
BuzzerFeedbackThread *buzzerFeedbackThread;
|
BuzzerFeedbackThread *buzzerFeedbackThread;
|
||||||
|
|
||||||
BuzzerFeedbackThread::BuzzerFeedbackThread() : OSThread("BuzzerFeedback")
|
BuzzerFeedbackThread::BuzzerFeedbackThread()
|
||||||
{
|
{
|
||||||
if (inputBroker)
|
if (inputBroker)
|
||||||
inputObserver.observe(inputBroker);
|
inputObserver.observe(inputBroker);
|
||||||
@ -19,10 +19,6 @@ int BuzzerFeedbackThread::handleInputEvent(const InputEvent *event)
|
|||||||
return 0; // Let other handlers process the event
|
return 0; // Let other handlers process the event
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track last event time for potential future use
|
|
||||||
lastEventTime = millis();
|
|
||||||
needsUpdate = true;
|
|
||||||
|
|
||||||
// Handle different input events with appropriate buzzer feedback
|
// Handle different input events with appropriate buzzer feedback
|
||||||
switch (event->inputEvent) {
|
switch (event->inputEvent) {
|
||||||
case INPUT_BROKER_USER_PRESS:
|
case INPUT_BROKER_USER_PRESS:
|
||||||
@ -62,14 +58,3 @@ int BuzzerFeedbackThread::handleInputEvent(const InputEvent *event)
|
|||||||
|
|
||||||
return 0; // Allow other handlers to process the event
|
return 0; // Allow other handlers to process the event
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t BuzzerFeedbackThread::runOnce()
|
|
||||||
{
|
|
||||||
// This thread is primarily event-driven, but we can use runOnce
|
|
||||||
// for any periodic tasks if needed in the future
|
|
||||||
|
|
||||||
needsUpdate = false;
|
|
||||||
|
|
||||||
// Run every 100ms when active, less frequently when idle
|
|
||||||
return needsUpdate ? 100 : 1000;
|
|
||||||
}
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "concurrency/OSThread.h"
|
#include "concurrency/OSThread.h"
|
||||||
#include "input/InputBroker.h"
|
#include "input/InputBroker.h"
|
||||||
|
|
||||||
class BuzzerFeedbackThread : public concurrency::OSThread
|
class BuzzerFeedbackThread
|
||||||
{
|
{
|
||||||
CallbackObserver<BuzzerFeedbackThread, const InputEvent *> inputObserver =
|
CallbackObserver<BuzzerFeedbackThread, const InputEvent *> inputObserver =
|
||||||
CallbackObserver<BuzzerFeedbackThread, const InputEvent *>(this, &BuzzerFeedbackThread::handleInputEvent);
|
CallbackObserver<BuzzerFeedbackThread, const InputEvent *>(this, &BuzzerFeedbackThread::handleInputEvent);
|
||||||
@ -12,13 +12,6 @@ class BuzzerFeedbackThread : public concurrency::OSThread
|
|||||||
public:
|
public:
|
||||||
BuzzerFeedbackThread();
|
BuzzerFeedbackThread();
|
||||||
int handleInputEvent(const InputEvent *event);
|
int handleInputEvent(const InputEvent *event);
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual int32_t runOnce() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint32_t lastEventTime = 0;
|
|
||||||
bool needsUpdate = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern BuzzerFeedbackThread *buzzerFeedbackThread;
|
extern BuzzerFeedbackThread *buzzerFeedbackThread;
|
||||||
|
@ -90,7 +90,9 @@ void OSThread::run()
|
|||||||
if (heap < newHeap)
|
if (heap < newHeap)
|
||||||
LOG_HEAP("++++++ Thread %s freed heap %d -> %d (%d) ++++++", ThreadName.c_str(), heap, newHeap, newHeap - heap);
|
LOG_HEAP("++++++ Thread %s freed heap %d -> %d (%d) ++++++", ThreadName.c_str(), heap, newHeap, newHeap - heap);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef DEBUG_LOOP_TIMING
|
||||||
|
LOG_DEBUG("====== Thread next run in: %d", newDelay);
|
||||||
|
#endif
|
||||||
runned();
|
runned();
|
||||||
|
|
||||||
if (newDelay >= 0)
|
if (newDelay >= 0)
|
||||||
|
@ -274,7 +274,12 @@ int32_t ButtonThread::runOnce()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
btnEvent = BUTTON_EVENT_NONE;
|
btnEvent = BUTTON_EVENT_NONE;
|
||||||
return 50;
|
|
||||||
|
// only pull when the button is pressed, we get notified via IRQ on a new press
|
||||||
|
if (!userButton.isIdle() || waitingForLongPress) {
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
return INT32_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1002,6 +1002,7 @@ void setup()
|
|||||||
config.pullupSense = INPUT_PULLUP;
|
config.pullupSense = INPUT_PULLUP;
|
||||||
config.intRoutine = []() {
|
config.intRoutine = []() {
|
||||||
UserButtonThread->userButton.tick();
|
UserButtonThread->userButton.tick();
|
||||||
|
UserButtonThread->setIntervalFromNow(0);
|
||||||
runASAP = true;
|
runASAP = true;
|
||||||
BaseType_t higherWake = 0;
|
BaseType_t higherWake = 0;
|
||||||
mainDelay.interruptFromISR(&higherWake);
|
mainDelay.interruptFromISR(&higherWake);
|
||||||
@ -1022,6 +1023,7 @@ void setup()
|
|||||||
touchConfig.pullupSense = pullup_sense;
|
touchConfig.pullupSense = pullup_sense;
|
||||||
touchConfig.intRoutine = []() {
|
touchConfig.intRoutine = []() {
|
||||||
TouchButtonThread->userButton.tick();
|
TouchButtonThread->userButton.tick();
|
||||||
|
TouchButtonThread->setIntervalFromNow(0);
|
||||||
runASAP = true;
|
runASAP = true;
|
||||||
BaseType_t higherWake = 0;
|
BaseType_t higherWake = 0;
|
||||||
mainDelay.interruptFromISR(&higherWake);
|
mainDelay.interruptFromISR(&higherWake);
|
||||||
@ -1041,6 +1043,7 @@ void setup()
|
|||||||
cancelConfig.pullupSense = pullup_sense;
|
cancelConfig.pullupSense = pullup_sense;
|
||||||
cancelConfig.intRoutine = []() {
|
cancelConfig.intRoutine = []() {
|
||||||
CancelButtonThread->userButton.tick();
|
CancelButtonThread->userButton.tick();
|
||||||
|
CancelButtonThread->setIntervalFromNow(0);
|
||||||
runASAP = true;
|
runASAP = true;
|
||||||
BaseType_t higherWake = 0;
|
BaseType_t higherWake = 0;
|
||||||
mainDelay.interruptFromISR(&higherWake);
|
mainDelay.interruptFromISR(&higherWake);
|
||||||
@ -1061,6 +1064,7 @@ void setup()
|
|||||||
backConfig.pullupSense = pullup_sense;
|
backConfig.pullupSense = pullup_sense;
|
||||||
backConfig.intRoutine = []() {
|
backConfig.intRoutine = []() {
|
||||||
BackButtonThread->userButton.tick();
|
BackButtonThread->userButton.tick();
|
||||||
|
BackButtonThread->setIntervalFromNow(0);
|
||||||
runASAP = true;
|
runASAP = true;
|
||||||
BaseType_t higherWake = 0;
|
BaseType_t higherWake = 0;
|
||||||
mainDelay.interruptFromISR(&higherWake);
|
mainDelay.interruptFromISR(&higherWake);
|
||||||
@ -1095,6 +1099,7 @@ void setup()
|
|||||||
userConfig.pullupSense = pullup_sense;
|
userConfig.pullupSense = pullup_sense;
|
||||||
userConfig.intRoutine = []() {
|
userConfig.intRoutine = []() {
|
||||||
UserButtonThread->userButton.tick();
|
UserButtonThread->userButton.tick();
|
||||||
|
UserButtonThread->setIntervalFromNow(0);
|
||||||
runASAP = true;
|
runASAP = true;
|
||||||
BaseType_t higherWake = 0;
|
BaseType_t higherWake = 0;
|
||||||
mainDelay.interruptFromISR(&higherWake);
|
mainDelay.interruptFromISR(&higherWake);
|
||||||
@ -1112,6 +1117,7 @@ void setup()
|
|||||||
userConfigNoScreen.pullupSense = pullup_sense;
|
userConfigNoScreen.pullupSense = pullup_sense;
|
||||||
userConfigNoScreen.intRoutine = []() {
|
userConfigNoScreen.intRoutine = []() {
|
||||||
UserButtonThread->userButton.tick();
|
UserButtonThread->userButton.tick();
|
||||||
|
UserButtonThread->setIntervalFromNow(0);
|
||||||
runASAP = true;
|
runASAP = true;
|
||||||
BaseType_t higherWake = 0;
|
BaseType_t higherWake = 0;
|
||||||
mainDelay.interruptFromISR(&higherWake);
|
mainDelay.interruptFromISR(&higherWake);
|
||||||
@ -1607,6 +1613,9 @@ void loop()
|
|||||||
|
|
||||||
// We want to sleep as long as possible here - because it saves power
|
// We want to sleep as long as possible here - because it saves power
|
||||||
if (!runASAP && loopCanSleep()) {
|
if (!runASAP && loopCanSleep()) {
|
||||||
|
#ifdef DEBUG_LOOP_TIMING
|
||||||
|
LOG_DEBUG("main loop delay: %d", delayMsec);
|
||||||
|
#endif
|
||||||
mainDelay.delay(delayMsec);
|
mainDelay.delay(delayMsec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,8 +143,7 @@ void FloodingRouter::perhapsRebroadcast(const meshtastic_MeshPacket *p)
|
|||||||
|
|
||||||
LOG_INFO("Rebroadcast received floodmsg");
|
LOG_INFO("Rebroadcast received floodmsg");
|
||||||
// Note: we are careful to resend using the original senders node id
|
// Note: we are careful to resend using the original senders node id
|
||||||
// We are careful not to call our hooked version of send() - because we don't want to check this again
|
send(tosend);
|
||||||
Router::send(tosend);
|
|
||||||
} else {
|
} else {
|
||||||
LOG_DEBUG("No rebroadcast: Role = CLIENT_MUTE or Rebroadcast Mode = NONE");
|
LOG_DEBUG("No rebroadcast: Role = CLIENT_MUTE or Rebroadcast Mode = NONE");
|
||||||
}
|
}
|
||||||
|
@ -110,11 +110,14 @@ void NextHopRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtast
|
|||||||
if (origTx) {
|
if (origTx) {
|
||||||
// Either relayer of ACK was also a relayer of the packet, or we were the *only* relayer and the ACK came directly
|
// Either relayer of ACK was also a relayer of the packet, or we were the *only* relayer and the ACK came directly
|
||||||
// from the destination
|
// from the destination
|
||||||
if (wasRelayer(p->relay_node, p->decoded.request_id, p->to) ||
|
bool wasAlreadyRelayer = wasRelayer(p->relay_node, p->decoded.request_id, p->to);
|
||||||
(p->hop_start != 0 && p->hop_start == p->hop_limit &&
|
bool weWereSoleRelayer = false;
|
||||||
wasSoleRelayer(ourRelayID, p->decoded.request_id, p->to))) {
|
bool weWereRelayer = wasRelayer(ourRelayID, p->decoded.request_id, p->to, &weWereSoleRelayer);
|
||||||
|
if ((weWereRelayer && wasAlreadyRelayer) ||
|
||||||
|
(p->hop_start != 0 && p->hop_start == p->hop_limit && weWereSoleRelayer)) {
|
||||||
if (origTx->next_hop != p->relay_node) { // Not already set
|
if (origTx->next_hop != p->relay_node) { // Not already set
|
||||||
LOG_INFO("Update next hop of 0x%x to 0x%x based on ACK/reply", p->from, p->relay_node);
|
LOG_INFO("Update next hop of 0x%x to 0x%x based on ACK/reply (was relayer %d we were sole %d)", p->from,
|
||||||
|
p->relay_node, wasAlreadyRelayer, weWereSoleRelayer);
|
||||||
origTx->next_hop = p->relay_node;
|
origTx->next_hop = p->relay_node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,14 @@ bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpd
|
|||||||
r.id = p->id;
|
r.id = p->id;
|
||||||
r.sender = getFrom(p); // If 0 then use our ID
|
r.sender = getFrom(p); // If 0 then use our ID
|
||||||
r.next_hop = p->next_hop;
|
r.next_hop = p->next_hop;
|
||||||
r.hop_limit = p->hop_limit;
|
setHighestHopLimit(r, p->hop_limit);
|
||||||
r.relayed_by[0] = p->relay_node;
|
bool weWillRelay = false;
|
||||||
|
uint8_t ourRelayID = nodeDB->getLastByteOfNodeNum(nodeDB->getNodeNum());
|
||||||
|
if (p->relay_node == ourRelayID) { // If the relay_node is us, store it
|
||||||
|
weWillRelay = true;
|
||||||
|
setOurTxHopLimit(r, p->hop_limit);
|
||||||
|
r.relayed_by[0] = p->relay_node;
|
||||||
|
}
|
||||||
|
|
||||||
r.rxTimeMsec = millis(); //
|
r.rxTimeMsec = millis(); //
|
||||||
if (r.rxTimeMsec == 0) // =0 every 49.7 days? 0 is special
|
if (r.rxTimeMsec == 0) // =0 every 49.7 days? 0 is special
|
||||||
@ -94,8 +100,6 @@ bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpd
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (seenRecently) {
|
if (seenRecently) {
|
||||||
uint8_t ourRelayID = nodeDB->getLastByteOfNodeNum(nodeDB->getNodeNum()); // Get our relay ID from our node number
|
|
||||||
|
|
||||||
if (wasFallback) {
|
if (wasFallback) {
|
||||||
// If it was seen with a next-hop not set to us and now it's NO_NEXT_HOP_PREFERENCE, and the relayer relayed already
|
// If it was seen with a next-hop not set to us and now it's NO_NEXT_HOP_PREFERENCE, and the relayer relayed already
|
||||||
// before, it's a fallback to flooding. If we didn't already relay and the next-hop neither, we might need to handle
|
// before, it's a fallback to flooding. If we didn't already relay and the next-hop neither, we might need to handle
|
||||||
@ -137,16 +141,40 @@ bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpd
|
|||||||
found->sender, found->id, found->next_hop, found->relayed_by[0], found->relayed_by[1], found->relayed_by[2],
|
found->sender, found->id, found->next_hop, found->relayed_by[0], found->relayed_by[1], found->relayed_by[2],
|
||||||
millis() - found->rxTimeMsec);
|
millis() - found->rxTimeMsec);
|
||||||
#endif
|
#endif
|
||||||
|
// Only update the relayer if it heard us directly (meaning hopLimit is decreased by 1)
|
||||||
|
uint8_t startIdx = weWillRelay ? 1 : 0;
|
||||||
|
if (!weWillRelay) {
|
||||||
|
bool weWereRelayer = wasRelayer(ourRelayID, *found);
|
||||||
|
// We were a relayer and the packet came in with a hop limit that is one less than when we sent it out
|
||||||
|
if (weWereRelayer && (p->hop_limit == getOurTxHopLimit(*found) || p->hop_limit == getOurTxHopLimit(*found) - 1)) {
|
||||||
|
r.relayed_by[0] = p->relay_node;
|
||||||
|
startIdx = 1; // Start copying existing relayers from index 1
|
||||||
|
}
|
||||||
|
// keep the original ourTxHopLimit
|
||||||
|
setOurTxHopLimit(r, getOurTxHopLimit(*found));
|
||||||
|
}
|
||||||
|
|
||||||
// Preserve the highest hop_limit we've ever seen for this packet so upgrades aren't lost when a later copy has
|
// Preserve the highest hop_limit we've ever seen for this packet so upgrades aren't lost when a later copy has
|
||||||
// fewer hops remaining.
|
// fewer hops remaining.
|
||||||
if (found->hop_limit > r.hop_limit)
|
if (getHighestHopLimit(*found) > getHighestHopLimit(r))
|
||||||
r.hop_limit = found->hop_limit;
|
setHighestHopLimit(r, getHighestHopLimit(*found));
|
||||||
|
|
||||||
// Add the existing relayed_by to the new record
|
// Add the existing relayed_by to the new record, avoiding duplicates
|
||||||
for (uint8_t i = 0; i < (NUM_RELAYERS - 1); i++) {
|
for (uint8_t i = 0; i < (NUM_RELAYERS - startIdx); i++) {
|
||||||
if (found->relayed_by[i] != 0)
|
if (found->relayed_by[i] == 0)
|
||||||
r.relayed_by[i + 1] = found->relayed_by[i];
|
continue;
|
||||||
|
|
||||||
|
bool exists = false;
|
||||||
|
for (uint8_t j = 0; j < NUM_RELAYERS; j++) {
|
||||||
|
if (r.relayed_by[j] == found->relayed_by[i]) {
|
||||||
|
exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exists) {
|
||||||
|
r.relayed_by[i + startIdx] = found->relayed_by[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
r.next_hop = found->next_hop; // keep the original next_hop (such that we check whether we were originally asked)
|
r.next_hop = found->next_hop; // keep the original next_hop (such that we check whether we were originally asked)
|
||||||
#if VERBOSE_PACKET_HISTORY
|
#if VERBOSE_PACKET_HISTORY
|
||||||
@ -369,14 +397,6 @@ bool PacketHistory::wasRelayer(const uint8_t relayer, const PacketRecord &r, boo
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a certain node was the *only* relayer of a packet in the history given an ID and sender
|
|
||||||
bool PacketHistory::wasSoleRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender)
|
|
||||||
{
|
|
||||||
bool wasSole = false;
|
|
||||||
wasRelayer(relayer, id, sender, &wasSole);
|
|
||||||
return wasSole;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove a relayer from the list of relayers of a packet in the history given an ID and sender
|
// Remove a relayer from the list of relayers of a packet in the history given an ID and sender
|
||||||
void PacketHistory::removeRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender)
|
void PacketHistory::removeRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender)
|
||||||
{
|
{
|
||||||
@ -418,3 +438,24 @@ void PacketHistory::removeRelayer(const uint8_t relayer, const uint32_t id, cons
|
|||||||
found->id, found->relayed_by[0], found->relayed_by[1], found->relayed_by[2], relayer, i != j);
|
found->id, found->relayed_by[0], found->relayed_by[1], found->relayed_by[2], relayer, i != j);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Getters and setters for hop limit fields packed in hop_limit
|
||||||
|
inline uint8_t PacketHistory::getHighestHopLimit(PacketRecord &r)
|
||||||
|
{
|
||||||
|
return r.hop_limit & HOP_LIMIT_HIGHEST_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void PacketHistory::setHighestHopLimit(PacketRecord &r, uint8_t hopLimit)
|
||||||
|
{
|
||||||
|
r.hop_limit = (r.hop_limit & ~HOP_LIMIT_HIGHEST_MASK) | (hopLimit & HOP_LIMIT_HIGHEST_MASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint8_t PacketHistory::getOurTxHopLimit(PacketRecord &r)
|
||||||
|
{
|
||||||
|
return (r.hop_limit & HOP_LIMIT_OUR_TX_MASK) >> HOP_LIMIT_OUR_TX_SHIFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void PacketHistory::setOurTxHopLimit(PacketRecord &r, uint8_t hopLimit)
|
||||||
|
{
|
||||||
|
r.hop_limit = (r.hop_limit & ~HOP_LIMIT_OUR_TX_MASK) | ((hopLimit << HOP_LIMIT_OUR_TX_SHIFT) & HOP_LIMIT_OUR_TX_MASK);
|
||||||
|
}
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
#include "NodeDB.h"
|
#include "NodeDB.h"
|
||||||
|
|
||||||
#define NUM_RELAYERS \
|
// Number of relayers we keep track of. Use 6 to be efficient with memory alignment of PacketRecord to 20 bytes
|
||||||
3 // Number of relayer we keep track of. Use 3 to be efficient with memory alignment of PacketRecord to 16 bytes
|
#define NUM_RELAYERS 6
|
||||||
|
#define HOP_LIMIT_HIGHEST_MASK 0x07 // Bits 0-2
|
||||||
|
#define HOP_LIMIT_OUR_TX_MASK 0x38 // Bits 3-5
|
||||||
|
#define HOP_LIMIT_OUR_TX_SHIFT 3 // Bits 3-5
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a mixin that adds a record of past packets we have seen
|
* This is a mixin that adds a record of past packets we have seen
|
||||||
@ -16,9 +19,10 @@ class PacketHistory
|
|||||||
PacketId id;
|
PacketId id;
|
||||||
uint32_t rxTimeMsec; // Unix time in msecs - the time we received it, 0 means empty
|
uint32_t rxTimeMsec; // Unix time in msecs - the time we received it, 0 means empty
|
||||||
uint8_t next_hop; // The next hop asked for this packet
|
uint8_t next_hop; // The next hop asked for this packet
|
||||||
uint8_t hop_limit; // Highest hop limit observed for this packet
|
uint8_t hop_limit; // bit 0-2: Highest hop limit observed for this packet,
|
||||||
|
// bit 3-5: our hop limit when we first transmitted it
|
||||||
uint8_t relayed_by[NUM_RELAYERS]; // Array of nodes that relayed this packet
|
uint8_t relayed_by[NUM_RELAYERS]; // Array of nodes that relayed this packet
|
||||||
}; // 4B + 4B + 4B + 1B + 1B + 3B = 17B (will be padded to 20B)
|
}; // 4B + 4B + 4B + 1B + 1B + 6B = 20B
|
||||||
|
|
||||||
uint32_t recentPacketsCapacity =
|
uint32_t recentPacketsCapacity =
|
||||||
0; // Can be set in constructor, no need to recompile. Used to allocate memory for mx_recentPackets.
|
0; // Can be set in constructor, no need to recompile. Used to allocate memory for mx_recentPackets.
|
||||||
@ -39,6 +43,11 @@ class PacketHistory
|
|||||||
* @return true if node was indeed a relayer, false if not */
|
* @return true if node was indeed a relayer, false if not */
|
||||||
bool wasRelayer(const uint8_t relayer, const PacketRecord &r, bool *wasSole = nullptr);
|
bool wasRelayer(const uint8_t relayer, const PacketRecord &r, bool *wasSole = nullptr);
|
||||||
|
|
||||||
|
uint8_t getHighestHopLimit(PacketRecord &r);
|
||||||
|
void setHighestHopLimit(PacketRecord &r, uint8_t hopLimit);
|
||||||
|
uint8_t getOurTxHopLimit(PacketRecord &r);
|
||||||
|
void setOurTxHopLimit(PacketRecord &r, uint8_t hopLimit);
|
||||||
|
|
||||||
PacketHistory(const PacketHistory &); // non construction-copyable
|
PacketHistory(const PacketHistory &); // non construction-copyable
|
||||||
PacketHistory &operator=(const PacketHistory &); // non copyable
|
PacketHistory &operator=(const PacketHistory &); // non copyable
|
||||||
public:
|
public:
|
||||||
@ -61,9 +70,6 @@ class PacketHistory
|
|||||||
* @return true if node was indeed a relayer, false if not */
|
* @return true if node was indeed a relayer, false if not */
|
||||||
bool wasRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender, bool *wasSole = nullptr);
|
bool wasRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender, bool *wasSole = nullptr);
|
||||||
|
|
||||||
// Check if a certain node was the *only* relayer of a packet in the history given an ID and sender
|
|
||||||
bool wasSoleRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender);
|
|
||||||
|
|
||||||
// Remove a relayer from the list of relayers of a packet in the history given an ID and sender
|
// Remove a relayer from the list of relayers of a packet in the history given an ID and sender
|
||||||
void removeRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender);
|
void removeRelayer(const uint8_t relayer, const uint32_t id, const NodeNum sender);
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ bool ascending = true;
|
|||||||
#endif
|
#endif
|
||||||
#define EXT_NOTIFICATION_MODULE_OUTPUT_MS 1000
|
#define EXT_NOTIFICATION_MODULE_OUTPUT_MS 1000
|
||||||
|
|
||||||
#define EXT_NOTIFICATION_DEFAULT_THREAD_MS 25
|
#define EXT_NOTIFICATION_FAST_THREAD_MS 25
|
||||||
|
|
||||||
#define ASCII_BELL 0x07
|
#define ASCII_BELL 0x07
|
||||||
|
|
||||||
@ -88,12 +88,13 @@ int32_t ExternalNotificationModule::runOnce()
|
|||||||
if (!moduleConfig.external_notification.enabled) {
|
if (!moduleConfig.external_notification.enabled) {
|
||||||
return INT32_MAX; // we don't need this thread here...
|
return INT32_MAX; // we don't need this thread here...
|
||||||
} else {
|
} else {
|
||||||
|
uint32_t delay = EXT_NOTIFICATION_MODULE_OUTPUT_MS;
|
||||||
bool isPlaying = rtttl::isPlaying();
|
bool isRtttlPlaying = rtttl::isPlaying();
|
||||||
#ifdef HAS_I2S
|
#ifdef HAS_I2S
|
||||||
isPlaying = rtttl::isPlaying() || audioThread->isPlaying();
|
// audioThread->isPlaying() also handles actually playing the RTTTL, needs to be called in loop
|
||||||
|
isRtttlPlaying = isRtttlPlaying || audioThread->isPlaying();
|
||||||
#endif
|
#endif
|
||||||
if ((nagCycleCutoff < millis()) && !isPlaying) {
|
if ((nagCycleCutoff < millis()) && !isRtttlPlaying) {
|
||||||
// let the song finish if we reach timeout
|
// let the song finish if we reach timeout
|
||||||
nagCycleCutoff = UINT32_MAX;
|
nagCycleCutoff = UINT32_MAX;
|
||||||
LOG_INFO("Turning off external notification: ");
|
LOG_INFO("Turning off external notification: ");
|
||||||
@ -116,21 +117,16 @@ int32_t ExternalNotificationModule::runOnce()
|
|||||||
|
|
||||||
// If the output is turned on, turn it back off after the given period of time.
|
// If the output is turned on, turn it back off after the given period of time.
|
||||||
if (isNagging) {
|
if (isNagging) {
|
||||||
if (externalTurnedOn[0] + (moduleConfig.external_notification.output_ms ? moduleConfig.external_notification.output_ms
|
delay = (moduleConfig.external_notification.output_ms ? moduleConfig.external_notification.output_ms
|
||||||
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) <
|
: EXT_NOTIFICATION_MODULE_OUTPUT_MS);
|
||||||
millis()) {
|
if (externalTurnedOn[0] + delay < millis()) {
|
||||||
setExternalState(0, !getExternal(0));
|
setExternalState(0, !getExternal(0));
|
||||||
}
|
}
|
||||||
if (externalTurnedOn[1] + (moduleConfig.external_notification.output_ms ? moduleConfig.external_notification.output_ms
|
if (externalTurnedOn[1] + delay < millis()) {
|
||||||
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) <
|
|
||||||
millis()) {
|
|
||||||
setExternalState(1, !getExternal(1));
|
setExternalState(1, !getExternal(1));
|
||||||
}
|
}
|
||||||
// Only toggle buzzer output if not using PWM mode (to avoid conflict with RTTTL)
|
// Only toggle buzzer output if not using PWM mode (to avoid conflict with RTTTL)
|
||||||
if (!moduleConfig.external_notification.use_pwm &&
|
if (!moduleConfig.external_notification.use_pwm && externalTurnedOn[2] + delay < millis()) {
|
||||||
externalTurnedOn[2] + (moduleConfig.external_notification.output_ms ? moduleConfig.external_notification.output_ms
|
|
||||||
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) <
|
|
||||||
millis()) {
|
|
||||||
LOG_DEBUG("EXTERNAL 2 %d compared to %d", externalTurnedOn[2] + moduleConfig.external_notification.output_ms,
|
LOG_DEBUG("EXTERNAL 2 %d compared to %d", externalTurnedOn[2] + moduleConfig.external_notification.output_ms,
|
||||||
millis());
|
millis());
|
||||||
setExternalState(2, !getExternal(2));
|
setExternalState(2, !getExternal(2));
|
||||||
@ -181,6 +177,8 @@ int32_t ExternalNotificationModule::runOnce()
|
|||||||
colorState = 1;
|
colorState = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// we need fast updates for the color change
|
||||||
|
delay = EXT_NOTIFICATION_FAST_THREAD_MS;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef T_WATCH_S3
|
#ifdef T_WATCH_S3
|
||||||
@ -190,12 +188,14 @@ int32_t ExternalNotificationModule::runOnce()
|
|||||||
|
|
||||||
// Play RTTTL over i2s audio interface if enabled as buzzer
|
// Play RTTTL over i2s audio interface if enabled as buzzer
|
||||||
#ifdef HAS_I2S
|
#ifdef HAS_I2S
|
||||||
if (moduleConfig.external_notification.use_i2s_as_buzzer && canBuzz()) {
|
if (moduleConfig.external_notification.use_i2s_as_buzzer) {
|
||||||
if (audioThread->isPlaying()) {
|
if (audioThread->isPlaying()) {
|
||||||
// Continue playing
|
// Continue playing
|
||||||
} else if (isNagging && (nagCycleCutoff >= millis())) {
|
} else if (isNagging && (nagCycleCutoff >= millis())) {
|
||||||
audioThread->beginRttl(rtttlConfig.ringtone, strlen_P(rtttlConfig.ringtone));
|
audioThread->beginRttl(rtttlConfig.ringtone, strlen_P(rtttlConfig.ringtone));
|
||||||
}
|
}
|
||||||
|
// we need fast updates to play the RTTTL
|
||||||
|
delay = EXT_NOTIFICATION_FAST_THREAD_MS;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// now let the PWM buzzer play
|
// now let the PWM buzzer play
|
||||||
@ -206,9 +206,11 @@ int32_t ExternalNotificationModule::runOnce()
|
|||||||
// start the song again if we have time left
|
// start the song again if we have time left
|
||||||
rtttl::begin(config.device.buzzer_gpio, rtttlConfig.ringtone);
|
rtttl::begin(config.device.buzzer_gpio, rtttlConfig.ringtone);
|
||||||
}
|
}
|
||||||
|
// we need fast updates to play the RTTTL
|
||||||
|
delay = EXT_NOTIFICATION_FAST_THREAD_MS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXT_NOTIFICATION_DEFAULT_THREAD_MS;
|
return delay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,8 @@ class BluetoothPhoneAPI : public PhoneAPI, public concurrency::OSThread
|
|||||||
hasChecked = true;
|
hasChecked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 100;
|
// the run is triggered via NimbleBluetoothToRadioCallback and NimbleBluetoothFromRadioCallback
|
||||||
|
return INT32_MAX;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Subclasses can use this as a hook to provide custom notifications for their transport (i.e. bluetooth notifies)
|
* Subclasses can use this as a hook to provide custom notifications for their transport (i.e. bluetooth notifies)
|
||||||
|
Loading…
Reference in New Issue
Block a user