@alteriom/painlessmesh 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -127,6 +127,22 @@ class Layout {
127
127
  bool hasTimeAuthority = false;
128
128
  };
129
129
 
130
+ /** How many of this node's connections are up.
131
+ *
132
+ * Zero means the node is out of the mesh: it has no route to anywhere, and
133
+ * nothing it is told about the topology can be acted on. A closed
134
+ * connection stays in `subs` until eraseClosedConnections() next runs, and
135
+ * a count of `subs` therefore says a node is connected when it is not --
136
+ * which is the same trap findRoute() was fixed for.
137
+ */
138
+ template <class T>
139
+ size_t liveSubs(const Layout<T>& layout) {
140
+ size_t live = 0;
141
+ for (auto&& sub : layout.subs)
142
+ if (sub->connected()) ++live;
143
+ return live;
144
+ }
145
+
130
146
  template <class T>
131
147
  void syncLayout(Layout<T>& layout, uint32_t changedId) {
132
148
  // TODO: this should be called from changed connections and dropped
@@ -30,6 +30,19 @@ typedef enum {
30
30
  DEBUG = 1 << 11
31
31
  } LogLevel;
32
32
 
33
+ // Log() is printf-like. In the desktop test build the compiler is told so,
34
+ // and -Wall -Werror in CI then rejects any argument that does not match its
35
+ // specifier. That class of bug reached main twice in routePackage(): size_t
36
+ // through %d/%u, and a DeserializationError object through %u (CodeQL
37
+ // cpp/wrong-type-format-argument). The check is kept to the desktop build on
38
+ // purpose: ESP-IDF 5 makes uint32_t `unsigned long`, so on ESP32 every %u of
39
+ // a node id would warn, harmlessly, in every user's build.
40
+ #if defined(PAINLESSMESH_BOOST) && defined(__GNUC__)
41
+ #define PAINLESSMESH_LOG_FORMAT __attribute__((format(printf, 3, 4)))
42
+ #else
43
+ #define PAINLESSMESH_LOG_FORMAT
44
+ #endif
45
+
33
46
  class LogClass {
34
47
  public:
35
48
  // Where messages go instead of Serial. The sketch owns framing: on a board
@@ -83,7 +96,7 @@ class LogClass {
83
96
  Serial.println();
84
97
  return;
85
98
  }
86
- void operator()(LogLevel type, const char *format...) {
99
+ void operator()(LogLevel type, const char *format...) PAINLESSMESH_LOG_FORMAT {
87
100
  if (type & types) { // Print only the message types set for output
88
101
  va_list args;
89
102
  va_start(args, format);