Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions examples/simple_repeater/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
if (data[0] == 0) { // blank password, just check if sender is in ACL
client = acl.getClient(sender.pub_key, PUB_KEY_SIZE);
if (client == NULL) {
#if MESH_DEBUG
MESH_DEBUG_PRINTLN("Login, sender not in ACL");
#endif
}
}
if (client == NULL) {
Expand All @@ -104,9 +102,7 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
} else if (strcmp((char *)data, _prefs.guest_password) == 0) { // check guest password
perms = PERM_ACL_GUEST;
} else {
#if MESH_DEBUG
MESH_DEBUG_PRINTLN("Invalid password: %s", data);
#endif
return 0;
}

Expand Down
2 changes: 0 additions & 2 deletions examples/simple_room_server/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,7 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
if (data[8] == 0) { // blank password, just check if sender is in ACL
client = acl.getClient(sender.pub_key, PUB_KEY_SIZE);
if (client == NULL) {
#if MESH_DEBUG
MESH_DEBUG_PRINTLN("Login, sender not in ACL");
#endif
}
}
if (client == NULL) {
Expand Down
10 changes: 2 additions & 8 deletions examples/simple_sensor/SensorMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,12 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
if (data[0] == 0) { // blank password, just check if sender is in ACL
client = acl.getClient(sender.pub_key, PUB_KEY_SIZE);
if (client == NULL) {
#if MESH_DEBUG
MESH_DEBUG_PRINTLN("Login, sender not in ACL");
#endif
return 0;
}
} else {
if (strcmp((char *) data, _prefs.password) != 0) { // check for valid admin password
#if MESH_DEBUG
MESH_DEBUG_PRINTLN("Invalid password: %s", &data[4]);
#endif
return 0;
}

Expand Down Expand Up @@ -615,10 +611,8 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i

bool SensorMesh::handleIncomingMsg(ClientInfo& from, uint32_t timestamp, uint8_t* data, uint8_t flags, size_t len) {
MESH_DEBUG_PRINT("handleIncomingMsg: unhandled msg from ");
#ifdef MESH_DEBUG
mesh::Utils::printHex(Serial, from.id.pub_key, PUB_KEY_SIZE);
Serial.printf(": %s\n", data);
#endif
MESH_DEBUG_PRINT_HEX(from.id.pub_key, PUB_KEY_SIZE);
MESH_DEBUG_PRINT_RAW(": %s\n", data);
return false;
}

Expand Down
50 changes: 50 additions & 0 deletions src/EndianTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include <stdint.h>

/**
* @brief Endianness-safe integer types for network/protocol communication
*
* These types automatically handle byte order conversion between wire format
* and host format, preventing endianness bugs in protocol implementations.
*/

// Big-endian 32-bit unsigned integer
struct be_uint32_t {
uint32_t wireBytes;
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
operator uint32_t() const { return __builtin_bswap32(wireBytes); }
#else
operator uint32_t() const { return wireBytes; }
#endif
} __attribute__((packed));

// Big-endian 16-bit unsigned integer
struct be_uint16_t {
uint16_t wireBytes;
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
operator uint16_t() const { return __builtin_bswap16(wireBytes); }
#else
operator uint16_t() const { return wireBytes; }
#endif
} __attribute__((packed));

// Little-endian 16-bit unsigned integer
struct le_uint16_t {
uint16_t wireBytes;
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
operator uint16_t() const { return wireBytes; }
#else
operator uint16_t() const { return __builtin_bswap16(wireBytes); }
#endif
} __attribute__((packed));

// Little-endian 32-bit unsigned integer
struct le_uint32_t {
uint32_t wireBytes;
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
operator uint32_t() const { return wireBytes; }
#else
operator uint32_t() const { return __builtin_bswap32(wireBytes); }
#endif
} __attribute__((packed));
4 changes: 4 additions & 0 deletions src/MeshCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
#include <Arduino.h>
#define MESH_DEBUG_PRINT(F, ...) Serial.printf("DEBUG: " F, ##__VA_ARGS__)
#define MESH_DEBUG_PRINTLN(F, ...) Serial.printf("DEBUG: " F "\n", ##__VA_ARGS__)
#define MESH_DEBUG_PRINT_RAW(F, ...) Serial.printf(F, ##__VA_ARGS__)
#define MESH_DEBUG_PRINT_HEX(src,len) mesh::Utils::printHex(Serial, src, len)
#else
#define MESH_DEBUG_PRINT(...) {}
#define MESH_DEBUG_PRINTLN(...) {}
#define MESH_DEBUG_PRINT_RAW(F, ...) {}
#define MESH_DEBUG_PRINT_HEX(src,len) {}
#endif

#if BRIDGE_DEBUG && ARDUINO
Expand Down
1 change: 1 addition & 0 deletions src/helpers/SensorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SensorManager {

SensorManager() { node_lat = 0; node_lon = 0; node_altitude = 0; }
virtual bool begin() { return false; }
virtual bool hasPendingWork() { return false; }
virtual bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) { return false; }
virtual void loop() { }
virtual int getNumSettings() const { return 0; }
Expand Down
Loading