Merge branch 'master' into sx126x-rx-boosted-gain

This commit is contained in:
Ben Meadors 2023-01-24 10:04:31 -06:00 committed by GitHub
commit 006cddd5cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 24 deletions

View File

@ -1,9 +1,9 @@
#include "OSThread.h" #include "OSThread.h"
#include "configuration.h" #include "configuration.h"
#ifdef DEBUG_HEAP #ifdef HAS_SCREEN
#include "graphics/Screen.h" #include "graphics/Screen.h"
#include "main.h"
#endif #endif
#include "main.h"
#include <assert.h> #include <assert.h>
namespace concurrency namespace concurrency
@ -83,18 +83,21 @@ void OSThread::run()
#endif #endif
currentThread = this; currentThread = this;
auto newDelay = runOnce(); auto newDelay = runOnce();
#ifdef DEBUG_HEAP #ifdef ARCH_ESP32
auto newHeap = ESP.getFreeHeap(); auto newHeap = ESP.getFreeHeap();
if (newHeap < 10000) {
LOG_DEBUG("\n\n====== heap too low [10000] -> reboot in 5s ======\n\n");
#ifdef HAS_SCREEN
screen->startRebootScreen();
#endif
rebootAtMsec = millis() + 5000;
}
#ifdef DEBUG_HEAP
if (newHeap < heap) if (newHeap < heap)
LOG_DEBUG("------ Thread %s leaked heap %d -> %d (%d) ------\n", ThreadName.c_str(), heap, newHeap, newHeap - heap); LOG_DEBUG("------ Thread %s leaked heap %d -> %d (%d) ------\n", ThreadName.c_str(), heap, newHeap, newHeap - heap);
if (heap < newHeap) if (heap < newHeap)
LOG_DEBUG("++++++ Thread %s freed heap %d -> %d (%d) ++++++\n", ThreadName.c_str(), heap, newHeap, newHeap - heap); LOG_DEBUG("++++++ Thread %s freed heap %d -> %d (%d) ++++++\n", ThreadName.c_str(), heap, newHeap, newHeap - heap);
#endif
if (newHeap < 10000) {
LOG_DEBUG("\n\n====== heap too low [10000] -> reboot in 5s ======\n\n");
screen->startRebootScreen();
rebootAtMsec = millis() + 5000;
}
#endif #endif
runned(); runned();

View File

@ -295,7 +295,8 @@ bool GPS::setup()
notifyDeepSleepObserver.observe(&notifyDeepSleep); notifyDeepSleepObserver.observe(&notifyDeepSleep);
notifyGPSSleepObserver.observe(&notifyGPSSleep); notifyGPSSleepObserver.observe(&notifyGPSSleep);
} }
if (config.position.gps_enabled == false) {
if (config.position.gps_enabled == false && config.position.fixed_position == false) {
setAwake(false); setAwake(false);
doGPSpowersave(false); doGPSpowersave(false);
} }
@ -402,7 +403,8 @@ uint32_t GPS::getSleepTime() const
uint32_t t = config.position.gps_update_interval; uint32_t t = config.position.gps_update_interval;
bool gps_enabled = config.position.gps_enabled; bool gps_enabled = config.position.gps_enabled;
if (!gps_enabled) // We'll not need the GPS thread to wake up again after first acq. with fixed position.
if (!gps_enabled || config.position.fixed_position)
t = UINT32_MAX; // Sleep forever now t = UINT32_MAX; // Sleep forever now
if (t == UINT32_MAX) if (t == UINT32_MAX)
@ -437,6 +439,7 @@ int32_t GPS::runOnce()
LOG_DEBUG("GPS is not communicating, trying factory reset on next bootup.\n"); LOG_DEBUG("GPS is not communicating, trying factory reset on next bootup.\n");
devicestate.did_gps_reset = false; devicestate.did_gps_reset = false;
nodeDB.saveDeviceStateToDisk(); nodeDB.saveDeviceStateToDisk();
disable(); // Stop the GPS thread as it can do nothing useful until next reboot.
} }
} }
} }
@ -498,6 +501,14 @@ int32_t GPS::runOnce()
// If state has changed do a publish // If state has changed do a publish
publishUpdate(); publishUpdate();
if (!(fixeddelayCtr >= 20) && config.position.fixed_position && hasValidLocation) {
fixeddelayCtr++;
// LOG_DEBUG("Our delay counter is %d\n", fixeddelayCtr);
if (fixeddelayCtr >= 20) {
doGPSpowersave(false);
forceWake(false);
}
}
// 9600bps is approx 1 byte per msec, so considering our buffer size we never need to wake more often than 200ms // 9600bps is approx 1 byte per msec, so considering our buffer size we never need to wake more often than 200ms
// if not awake we can run super infrquently (once every 5 secs?) to see if we need to wake. // if not awake we can run super infrquently (once every 5 secs?) to see if we need to wake.
return isAwake ? GPS_THREAD_INTERVAL : 5000; return isAwake ? GPS_THREAD_INTERVAL : 5000;

View File

@ -168,6 +168,9 @@ class GPS : private concurrency::OSThread
int getAck(uint8_t *buffer, uint16_t size, uint8_t requestedClass, uint8_t requestedID); int getAck(uint8_t *buffer, uint16_t size, uint8_t requestedClass, uint8_t requestedID);
// delay counter to allow more sats before fixed position stops GPS thread
uint8_t fixeddelayCtr = 0;
protected: protected:
GnssModel_t gnssModel = GNSS_MODEL_UNKONW; GnssModel_t gnssModel = GNSS_MODEL_UNKONW;
}; };

View File

@ -378,8 +378,10 @@ bool PhoneAPI::available()
if (xmodemPacketForPhone.control == meshtastic_XModem_Control_NUL) if (xmodemPacketForPhone.control == meshtastic_XModem_Control_NUL)
xmodemPacketForPhone = xModem.getForPhone(); xmodemPacketForPhone = xModem.getForPhone();
if (xmodemPacketForPhone.control != meshtastic_XModem_Control_NUL) if (xmodemPacketForPhone.control != meshtastic_XModem_Control_NUL) {
xModem.resetForPhone();
return true; return true;
}
if (!packetForPhone) if (!packetForPhone)
packetForPhone = service.getForPhone(); packetForPhone = service.getForPhone();

View File

@ -12,7 +12,7 @@
A simple interface to send messages over the mesh network by sending strings A simple interface to send messages over the mesh network by sending strings
over a serial port. over a serial port.
Default is to use RX GPIO 16 and TX GPIO 17. There are no PIN defaults, you have to enable the second serial port yourself.
Need help with this module? Post your question on the Meshtastic Discourse: Need help with this module? Post your question on the Meshtastic Discourse:
https://meshtastic.discourse.group https://meshtastic.discourse.group
@ -46,8 +46,6 @@
#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2) #if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) && !defined(TTGO_T_ECHO) && !defined(CONFIG_IDF_TARGET_ESP32S2)
#define RXD2 16
#define TXD2 17
#define RX_BUFFER 128 #define RX_BUFFER 128
#define TIMEOUT 250 #define TIMEOUT 250
#define BAUD 38400 #define BAUD 38400
@ -102,7 +100,7 @@ int32_t SerialModule::runOnce()
// moduleConfig.serial.timeout = 1000; // moduleConfig.serial.timeout = 1000;
// moduleConfig.serial.echo = 1; // moduleConfig.serial.echo = 1;
if (moduleConfig.serial.enabled) { if (moduleConfig.serial.enabled && moduleConfig.serial.rxd && moduleConfig.serial.txd) {
if (firstTime) { if (firstTime) {
@ -165,9 +163,6 @@ int32_t SerialModule::runOnce()
if (moduleConfig.serial.rxd && moduleConfig.serial.txd) { if (moduleConfig.serial.rxd && moduleConfig.serial.txd) {
Serial2.begin(baud, SERIAL_8N1, moduleConfig.serial.rxd, moduleConfig.serial.txd); Serial2.begin(baud, SERIAL_8N1, moduleConfig.serial.rxd, moduleConfig.serial.txd);
} else {
Serial2.begin(baud, SERIAL_8N1, RXD2, TXD2);
} }
#else #else
if (moduleConfig.serial.rxd && moduleConfig.serial.txd) if (moduleConfig.serial.rxd && moduleConfig.serial.txd)

View File

@ -53,10 +53,8 @@ void MQTT::onPublish(char *topic, byte *payload, unsigned int length)
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
ptr = strtok(NULL, "/"); ptr = strtok(NULL, "/");
} }
LOG_DEBUG("Looking for Channel name: %s\n", ptr);
meshtastic_Channel sendChannel = channels.getByName(ptr); meshtastic_Channel sendChannel = channels.getByName(ptr);
LOG_DEBUG("Found Channel name: %s (Index %d)\n", channels.getGlobalId(sendChannel.settings.channel_num), LOG_DEBUG("Found Channel name: %s (Index %d)\n", channels.getGlobalId(sendChannel.index), sendChannel.index);
sendChannel.settings.channel_num);
if ((json.find("sender") != json.end()) && (json.find("payload") != json.end()) && if ((json.find("sender") != json.end()) && (json.find("payload") != json.end()) &&
(json.find("type") != json.end()) && json["type"]->IsString() && (json.find("type") != json.end()) && json["type"]->IsString() &&
@ -70,7 +68,7 @@ void MQTT::onPublish(char *topic, byte *payload, unsigned int length)
// construct protobuf data packet using TEXT_MESSAGE, send it to the mesh // construct protobuf data packet using TEXT_MESSAGE, send it to the mesh
meshtastic_MeshPacket *p = router->allocForSending(); meshtastic_MeshPacket *p = router->allocForSending();
p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP; p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP;
p->channel = sendChannel.settings.channel_num; p->channel = sendChannel.index;
if (sendChannel.settings.downlink_enabled) { if (sendChannel.settings.downlink_enabled) {
if (jsonPayloadStr.length() <= sizeof(p->decoded.payload.bytes)) { if (jsonPayloadStr.length() <= sizeof(p->decoded.payload.bytes)) {
memcpy(p->decoded.payload.bytes, jsonPayloadStr.c_str(), jsonPayloadStr.length()); memcpy(p->decoded.payload.bytes, jsonPayloadStr.c_str(), jsonPayloadStr.length());
@ -104,7 +102,7 @@ void MQTT::onPublish(char *topic, byte *payload, unsigned int length)
// construct protobuf data packet using POSITION, send it to the mesh // construct protobuf data packet using POSITION, send it to the mesh
meshtastic_MeshPacket *p = router->allocForSending(); meshtastic_MeshPacket *p = router->allocForSending();
p->decoded.portnum = meshtastic_PortNum_POSITION_APP; p->decoded.portnum = meshtastic_PortNum_POSITION_APP;
p->channel = sendChannel.settings.channel_num; p->channel = sendChannel.index;
if (sendChannel.settings.downlink_enabled) { if (sendChannel.settings.downlink_enabled) {
p->decoded.payload.size = p->decoded.payload.size =
pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes),

View File

@ -74,6 +74,11 @@ meshtastic_XModem XModemAdapter::getForPhone()
return xmodemStore; return xmodemStore;
} }
void XModemAdapter::resetForPhone()
{
xmodemStore = meshtastic_XModem_init_zero;
}
void XModemAdapter::handlePacket(meshtastic_XModem xmodemPacket) void XModemAdapter::handlePacket(meshtastic_XModem xmodemPacket)
{ {
switch (xmodemPacket.control) { switch (xmodemPacket.control) {

View File

@ -48,6 +48,7 @@ class XModemAdapter
void handlePacket(meshtastic_XModem xmodemPacket); void handlePacket(meshtastic_XModem xmodemPacket);
meshtastic_XModem getForPhone(); meshtastic_XModem getForPhone();
void resetForPhone();
private: private:
bool isReceiving = false; bool isReceiving = false;