mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-31 10:41:09 -05:00
* Fix type of nodeNum Type of nodeNum is NodeNum, not uint * typo fixed typo "resumeAdverising()" * fix missing #include "time.h" Missing include breaks compilation with gccnoneeabi 12.3.1 for nrf52 targets on windows hosts. * change type uint to unsigned int uint is not a standard type. Using uint breaks compilation with gccnoneeabi 12.3.1 for nRF52 targets on windows hosts. * fix type of channel_num Type of channel_num should be uint32_t (as this is the type of hash() and numChannels). Using uint non-standard type uint breaks compilation with gccnoneeabi 12.3.1 for nRF52 targets on windows hosts. * Update nrf52.ini Default build type should be "release" as this is the default of platformio. * Update GPS.cpp uint to unsigned int
91 lines
2.5 KiB
C++
91 lines
2.5 KiB
C++
#include "SerialConsole.h"
|
|
#include "NodeDB.h"
|
|
#include "PowerFSM.h"
|
|
#include "configuration.h"
|
|
#include "time.h"
|
|
|
|
#ifdef RP2040_SLOW_CLOCK
|
|
#define Port Serial2
|
|
#else
|
|
#define Port Serial
|
|
#endif
|
|
// Defaulting to the formerly removed phone_timeout_secs value of 15 minutes
|
|
#define SERIAL_CONNECTION_TIMEOUT (15 * 60) * 1000UL
|
|
|
|
SerialConsole *console;
|
|
|
|
void consoleInit()
|
|
{
|
|
new SerialConsole(); // Must be dynamically allocated because we are now inheriting from thread
|
|
DEBUG_PORT.rpInit(); // Simply sets up semaphore
|
|
}
|
|
|
|
void consolePrintf(const char *format, ...)
|
|
{
|
|
va_list arg;
|
|
va_start(arg, format);
|
|
console->vprintf(format, arg);
|
|
va_end(arg);
|
|
console->flush();
|
|
}
|
|
|
|
SerialConsole::SerialConsole() : StreamAPI(&Port), RedirectablePrint(&Port), concurrency::OSThread("SerialConsole")
|
|
{
|
|
assert(!console);
|
|
console = this;
|
|
canWrite = false; // We don't send packets to our port until it has talked to us first
|
|
// setDestination(&noopPrint); for testing, try turning off 'all' debug output and see what leaks
|
|
|
|
#ifdef RP2040_SLOW_CLOCK
|
|
Port.setTX(SERIAL2_TX);
|
|
Port.setRX(SERIAL2_RX);
|
|
#endif
|
|
Port.begin(SERIAL_BAUD);
|
|
#if defined(ARCH_NRF52) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARCH_RP2040)
|
|
time_t timeout = millis();
|
|
while (!Port) {
|
|
if ((millis() - timeout) < 5000) {
|
|
delay(100);
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
#endif
|
|
emitRebooted();
|
|
}
|
|
|
|
int32_t SerialConsole::runOnce()
|
|
{
|
|
return runOncePart();
|
|
}
|
|
|
|
void SerialConsole::flush()
|
|
{
|
|
Port.flush();
|
|
}
|
|
|
|
// 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()
|
|
{
|
|
uint32_t now = millis();
|
|
return (now - lastContactMsec) < SERIAL_CONNECTION_TIMEOUT;
|
|
}
|
|
|
|
/**
|
|
* we override this to notice when we've received a protobuf over the serial
|
|
* stream. Then we shut off debug serial output.
|
|
*/
|
|
bool SerialConsole::handleToRadio(const uint8_t *buf, size_t len)
|
|
{
|
|
// only talk to the API once the configuration has been loaded and we're sure the serial port is not disabled.
|
|
if (config.has_lora && config.device.serial_enabled) {
|
|
// Turn off debug serial printing once the API is activated, because other threads could print and corrupt packets
|
|
if (!config.device.debug_log_enabled)
|
|
setDestination(&noopPrint);
|
|
canWrite = true;
|
|
|
|
return StreamAPI::handleToRadio(buf, len);
|
|
} else {
|
|
return false;
|
|
}
|
|
} |