Compare commits

...

2 Commits

Author SHA1 Message Date
Jonathan Bennett
4243d258a4 trunk 2025-08-17 15:45:42 -05:00
Jonathan Bennett
6b5ee2f10a Loopback support in portduino with crc check to ignore own packets 2025-08-17 15:34:04 -05:00
2 changed files with 16 additions and 3 deletions

View File

@@ -2,7 +2,7 @@
[portduino_base] [portduino_base]
platform = platform =
# renovate: datasource=git-refs depName=platform-native packageName=https://github.com/meshtastic/platform-native gitBranch=develop # renovate: datasource=git-refs depName=platform-native packageName=https://github.com/meshtastic/platform-native gitBranch=develop
https://github.com/meshtastic/platform-native/archive/6cb7a455b440dd0738e8ed74a18136ed5cf7ea63.zip https://github.com/meshtastic/platform-native/archive/cd32f4ed20812d1fe9c8f74c0b6e80dc93dfce54.zip
framework = arduino framework = arduino
build_src_filter = build_src_filter =

View File

@@ -10,6 +10,10 @@
#include <WiFi.h> #include <WiFi.h>
#endif #endif
#if ARCH_PORTDUINO
#include <ErriezCRC32.h>
#endif
#include <AsyncUDP.h> #include <AsyncUDP.h>
#if HAS_ETHERNET && defined(USE_WS5500) #if HAS_ETHERNET && defined(USE_WS5500)
@@ -45,8 +49,11 @@ class UdpMulticastHandler final
#if defined(ARCH_NRF52) #if defined(ARCH_NRF52)
IPAddress ip = packet.remoteIP(); IPAddress ip = packet.remoteIP();
LOG_DEBUG("UDP broadcast from: %u.%u.%u.%u, len=%u", ip[0], ip[1], ip[2], ip[3], packetLength); LOG_DEBUG("UDP broadcast from: %u.%u.%u.%u, len=%u", ip[0], ip[1], ip[2], ip[3], packetLength);
#elif !defined(ARCH_PORTDUINO) #elif defined(ARCH_PORTDUINO)
// FIXME(PORTDUINO): arduino lacks IPAddress::toString() if (packetLength == 0 || crc32Buffer(packet.data(), packetLength) == last_crc) {
return;
}
#else // FIXME(PORTDUINO): arduino lacks IPAddress::toString()
LOG_DEBUG("UDP broadcast from: %s, len=%u", packet.remoteIP().toString().c_str(), packetLength); LOG_DEBUG("UDP broadcast from: %s, len=%u", packet.remoteIP().toString().c_str(), packetLength);
#endif #endif
meshtastic_MeshPacket mp; meshtastic_MeshPacket mp;
@@ -85,6 +92,9 @@ class UdpMulticastHandler final
LOG_DEBUG("Broadcasting packet over UDP (id=%u)", mp->id); LOG_DEBUG("Broadcasting packet over UDP (id=%u)", mp->id);
uint8_t buffer[meshtastic_MeshPacket_size]; uint8_t buffer[meshtastic_MeshPacket_size];
size_t encodedLength = pb_encode_to_bytes(buffer, sizeof(buffer), &meshtastic_MeshPacket_msg, mp); size_t encodedLength = pb_encode_to_bytes(buffer, sizeof(buffer), &meshtastic_MeshPacket_msg, mp);
#if ARCH_PORTDUINO
last_crc = crc32Buffer(buffer, encodedLength);
#endif
udp.writeTo(buffer, encodedLength, udpIpAddress, UDP_MULTICAST_DEFAUL_PORT); udp.writeTo(buffer, encodedLength, udpIpAddress, UDP_MULTICAST_DEFAUL_PORT);
return true; return true;
} }
@@ -92,5 +102,8 @@ class UdpMulticastHandler final
private: private:
IPAddress udpIpAddress; IPAddress udpIpAddress;
AsyncUDP udp; AsyncUDP udp;
#if ARCH_PORTDUINO
uint32_t last_crc;
#endif
}; };
#endif // HAS_UDP_MULTICAST #endif // HAS_UDP_MULTICAST