Merge remote-tracking branch 'origin/dev'
Konflikty: - ESP32Board.h: upstream obnovuje čas z RTC backupu přes všechny resety; záchytná hodnota je teď novější z FIRMWARE_BUILD_EPOCH (náš stamping) a RTC_TIME_MIN. - t1000-e: upstream sloučil sleep_gps() do stop_gps() (drží VRTC + Airoha RTC backup sleep) ⇒ gps duty používá stop_gps(), sleep_gps() zrušen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
f79ea79a13
23 files changed
+164
-120
No files matched your search
+5
-2
@@ -147,6 +147,9 @@ int Utils::encryptThenMAC(const uint8_t* shared_secret, uint8_t* dest, const uin
|
||||
int Utils::MACThenDecrypt(const uint8_t* shared_secret, uint8_t* dest, const uint8_t* src, int src_len) {
|
||||
if (src_len <= CIPHER_MAC_SIZE) return 0; // invalid src bytes
|
||||
|
||||
int enc_len = src_len - CIPHER_MAC_SIZE;
|
||||
if (enc_len % CIPHER_BLOCK_SIZE != 0) return 0; // reject non-block-aligned ciphertext
|
||||
|
||||
uint8_t hmac[CIPHER_MAC_SIZE];
|
||||
#ifdef USE_CC310_HW_CRYPTO
|
||||
{
|
||||
@@ -161,12 +164,12 @@ int Utils::MACThenDecrypt(const uint8_t* shared_secret, uint8_t* dest, const uin
|
||||
{
|
||||
SHA256 sha;
|
||||
sha.resetHMAC(shared_secret, PUB_KEY_SIZE);
|
||||
sha.update(src + CIPHER_MAC_SIZE, src_len - CIPHER_MAC_SIZE);
|
||||
sha.update(src + CIPHER_MAC_SIZE, enc_len);
|
||||
sha.finalizeHMAC(shared_secret, PUB_KEY_SIZE, hmac, CIPHER_MAC_SIZE);
|
||||
}
|
||||
#endif
|
||||
if (memcmp(hmac, src, CIPHER_MAC_SIZE) == 0) {
|
||||
return decrypt(shared_secret, dest, src + CIPHER_MAC_SIZE, src_len - CIPHER_MAC_SIZE);
|
||||
return decrypt(shared_secret, dest, src + CIPHER_MAC_SIZE, enc_len);
|
||||
}
|
||||
return 0; // invalid HMAC
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public:
|
||||
|
||||
/**
|
||||
* \brief checks the MAC (in leading bytes of 'src'), then if valid, decrypts remaining bytes in src.
|
||||
* \returns zero if MAC is invalid, otherwise the length of decrypted bytes in 'dest'
|
||||
* \returns zero if MAC is invalid or ciphertext is not block-aligned, otherwise the length of decrypted bytes in 'dest'
|
||||
*/
|
||||
static int MACThenDecrypt(const uint8_t* shared_secret, uint8_t* dest, const uint8_t* src, int src_len);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "ContactInfo.h"
|
||||
|
||||
#define MAX_SEARCH_RESULTS 8
|
||||
#define MAX_SEARCH_RESULTS 24
|
||||
|
||||
#define MSG_SEND_FAILED 0
|
||||
#define MSG_SEND_SENT_FLOOD 1
|
||||
|
||||
@@ -200,19 +200,32 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
static RTC_NOINIT_ATTR uint32_t _rtc_backup_time;
|
||||
static RTC_NOINIT_ATTR uint32_t _rtc_backup_magic;
|
||||
#define RTC_BACKUP_MAGIC 0xAA55CC33
|
||||
#define RTC_TIME_MIN 1772323200 // 1 Mar 2026
|
||||
|
||||
class ESP32RTCClock : public mesh::RTCClock {
|
||||
public:
|
||||
ESP32RTCClock() { }
|
||||
void begin() {
|
||||
esp_reset_reason_t reason = esp_reset_reason();
|
||||
if (reason == ESP_RST_POWERON) {
|
||||
// start with some date/time in the recent past
|
||||
struct timeval tv;
|
||||
tv.tv_sec = FIRMWARE_BUILD_EPOCH; // compile time when stamped, else 15 May 2024
|
||||
if (reason == ESP_RST_DEEPSLEEP) {
|
||||
return; // ESP-IDF preserves system time across deep sleep
|
||||
}
|
||||
// All other resets (power-on, crash, WDT, brownout) lose system time.
|
||||
// Restore from RTC backup if valid, otherwise seed with the build time
|
||||
// (stamped builds) or RTC_TIME_MIN, whichever is newer.
|
||||
uint32_t seed = FIRMWARE_BUILD_EPOCH > RTC_TIME_MIN ? FIRMWARE_BUILD_EPOCH : RTC_TIME_MIN;
|
||||
struct timeval tv;
|
||||
if (_rtc_backup_magic == RTC_BACKUP_MAGIC && _rtc_backup_time > seed) {
|
||||
tv.tv_sec = _rtc_backup_time;
|
||||
} else {
|
||||
tv.tv_sec = seed;
|
||||
}
|
||||
tv.tv_usec = 0;
|
||||
settimeofday(&tv, NULL);
|
||||
}
|
||||
}
|
||||
uint32_t getCurrentTime() override {
|
||||
time_t _now;
|
||||
time(&_now);
|
||||
@@ -223,6 +236,16 @@ public:
|
||||
tv.tv_sec = time;
|
||||
tv.tv_usec = 0;
|
||||
settimeofday(&tv, NULL);
|
||||
_rtc_backup_time = time;
|
||||
_rtc_backup_magic = RTC_BACKUP_MAGIC;
|
||||
}
|
||||
void tick() override {
|
||||
time_t now;
|
||||
time(&now);
|
||||
if (now > RTC_TIME_MIN && (uint32_t)now != _rtc_backup_time) {
|
||||
_rtc_backup_time = (uint32_t)now;
|
||||
_rtc_backup_magic = RTC_BACKUP_MAGIC;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -129,8 +129,12 @@ void SerialBLEInterface::begin(const char* prefix, char* name, uint32_t pin_code
|
||||
char charpin[20];
|
||||
snprintf(charpin, sizeof(charpin), "%lu", (unsigned long)pin_code);
|
||||
|
||||
// If we want to control BLE LED ourselves, uncomment this:
|
||||
// Bluefruit.autoConnLed(false);
|
||||
#ifdef DISABLE_BLE_LED // use variant platformio.ini build_flags macro: -D DISABLE_BLE_LED
|
||||
Bluefruit.autoConnLed(false); // false removes the automatic control of the LED by the Bluefruit library
|
||||
#else
|
||||
Bluefruit.autoConnLed(true); // true leaves the default automatic control of the LED by the Bluefruit library
|
||||
#endif
|
||||
|
||||
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
||||
Bluefruit.begin();
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include <helpers/sensors/LocationProvider.h>
|
||||
|
||||
// Board must keep the GPS RTC backup pin powered and can cut GPS power once we return.
|
||||
// Returns true if the command was acked within 3 attempts, otherwise returns false.
|
||||
static inline bool airohaEnterSleep(LocationProvider* nmea) {
|
||||
for (uint8_t attempt = 0; attempt < 3; attempt++) {
|
||||
nmea->drain();
|
||||
nmea->sendSentence("$PAIR650,0");
|
||||
if (nmea->waitFor("$PAIR001,650,0", 50)) { // wait for the command received signal
|
||||
#ifdef GPS_NMEA_DEBUG
|
||||
Serial.printf("Airoha RTC Backup sleep command accepted by GPS after %u attempts\r\n", attempt + 1);
|
||||
#endif
|
||||
nmea->waitFor("$PAIR650,0", 50); // give the GPS 50ms grace to signal it is ready for sleep
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -844,14 +844,18 @@ void EnvironmentSensorManager::initBasicGPS() {
|
||||
MESH_DEBUG_PRINTLN("No GPS wake/reset pin found for this board. Continuing on...");
|
||||
#endif
|
||||
|
||||
// Give GPS a moment to power up and send data
|
||||
delay(1000);
|
||||
|
||||
// We'll consider GPS detected if we see any data on Serial1
|
||||
// Give the GPS time to power up and emit its first NMEA sentence. Cold-start
|
||||
// modules can take several seconds, so poll for up to ~5s instead of checking
|
||||
// once after a fixed 1s delay -- returning as soon as any data appears, so
|
||||
// fast modules add no boot delay (issue #2258).
|
||||
#ifdef ENV_SKIP_GPS_DETECT
|
||||
gps_detected = true;
|
||||
#else
|
||||
gps_detected = (Serial1.available() > 0);
|
||||
gps_detected = false;
|
||||
for (int i = 0; i < 20 && !gps_detected; i++) {
|
||||
delay(250);
|
||||
gps_detected = (Serial1.available() > 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (gps_detected) {
|
||||
|
||||
@@ -19,6 +19,8 @@ public:
|
||||
virtual bool isValid() = 0;
|
||||
virtual long getTimestamp() = 0;
|
||||
virtual void sendSentence(const char * sentence);
|
||||
virtual bool waitFor(const char* prefix, uint32_t timeout_ms) { return false; }
|
||||
virtual void drain() { }
|
||||
virtual void reset() = 0;
|
||||
virtual void begin() = 0;
|
||||
virtual void stop() = 0;
|
||||
|
||||
@@ -173,10 +173,31 @@ public :
|
||||
return dt.unixtime();
|
||||
}
|
||||
|
||||
void drain() { while (_gps_serial->available()) _gps_serial->read(); }
|
||||
|
||||
const char* getSentence() const { return nmea.getSentence(); }
|
||||
|
||||
void sendSentence(const char *sentence) override {
|
||||
nmea.sendSentence(*_gps_serial, sentence);
|
||||
}
|
||||
|
||||
bool waitFor(const char* prefix, uint32_t timeout_ms) {
|
||||
size_t plen = strlen(prefix);
|
||||
uint32_t timeout = millis() + timeout_ms;
|
||||
while ((int32_t)(millis() - timeout) < 0) {
|
||||
if (_gps_serial->available()) {
|
||||
char c = _gps_serial->read();
|
||||
#ifdef GPS_NMEA_DEBUG
|
||||
Serial.print(c);
|
||||
#endif
|
||||
if (nmea.process(c) && strncmp(nmea.getSentence(), prefix, plen) == 0) return true;
|
||||
} else {
|
||||
yield();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void loop() override {
|
||||
|
||||
while (_gps_serial->available()) {
|
||||
|
||||
Reference in new issue
Block a user