From 980693bd29eeae03c6bdeffdf376d50f0b793e5e Mon Sep 17 00:00:00 2001 From: Brent Allen Date: Thu, 22 Jan 2026 08:35:04 -0800 Subject: [PATCH] Add simulator support: wake time registry and thread-local contact table diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index cccbd36c..621aa5c3 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -4,6 +4,10 @@ #include #endif +#ifdef MESHCORE_SIMULATOR + #include "sim_context.h" +#endif + #include namespace mesh { @@ -385,7 +389,16 @@ bool Dispatcher::millisHasNowPassed(unsigned long timestamp) const { } unsigned long Dispatcher::futureMillis(int millis_from_now) const { - return _ms->getMillis() + millis_from_now; + unsigned long wake_time = _ms->getMillis() + millis_from_now; + +#ifdef MESHCORE_SIMULATOR + // Register wake time with simulator for accurate scheduling + if (auto* ctx = SIM_CTX()) { + ctx->wake_registry.registerWakeTime(wake_time); + } +#endif + + return wake_time; } } diff --git a/src/MeshCore.h b/src/MeshCore.h index 2db1d4c3..b519beb8 100644 --- a/src/MeshCore.h +++ b/src/MeshCore.h @@ -21,7 +21,7 @@ #define MAX_PATH_SIZE 64 #define MAX_TRANS_UNIT 255 -#if MESH_DEBUG && ARDUINO +#if (MESH_DEBUG && ARDUINO) || defined(MESHCORE_SIMULATOR) #include #define MESH_DEBUG_PRINT(F, ...) Serial.printf("DEBUG: " F, ##__VA_ARGS__) #define MESH_DEBUG_PRINTLN(F, ...) Serial.printf("DEBUG: " F "\n", ##__VA_ARGS__) diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index 7ddc461d..81f6024b 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -780,7 +780,7 @@ void BaseChatMesh::resetPathTo(ContactInfo& recipient) { recipient.out_path_len = OUT_PATH_UNKNOWN; } -static ContactInfo* table; // pass via global :-( +static thread_local ContactInfo* table; // pass via global (thread_local for simulation) static int cmp_adv_timestamp(const void *a, const void *b) { int a_idx = *((int *)a); -- 2.46.2