From 35f8db40205f1743af81e6fc9c0960e778d02818 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Fri, 15 Jul 2022 17:10:25 +0100 Subject: More work on multicast --- .../MulticastDiscovery/MulticastResponder.cpp | 19 ++++++++++++++++--- .../MulticastDiscovery/MulticastResponder.h | 1 + src/Networking/MulticastDiscovery/fgmc_header.h | 5 ++--- src/Networking/MulticastDiscovery/fgmc_protocol.cpp | 14 +++----------- src/Networking/MulticastDiscovery/fgmc_protocol.h | 4 ++-- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/Networking/MulticastDiscovery/MulticastResponder.cpp b/src/Networking/MulticastDiscovery/MulticastResponder.cpp index 7cd1d66b..96630a58 100644 --- a/src/Networking/MulticastDiscovery/MulticastResponder.cpp +++ b/src/Networking/MulticastDiscovery/MulticastResponder.cpp @@ -20,17 +20,18 @@ extern "C" { extern struct netif gs_net_if; } +static constexpr ip_addr_t ourGroup = IPADDR4_INIT_BYTES(239, 255, 2, 3); + static udp_pcb *ourPcb = nullptr; static pbuf * volatile receivedPbuf = nullptr; static volatile uint32_t receivedIpAddr; static volatile uint16_t receivedPort; +static uint16_t lastMessageReceivedPort; static unsigned int messagesProcessed = 0; static FGMCProtocol *fgmcHandler = nullptr; static bool active = false; -static constexpr ip_addr_t ourGroup = IPADDR4_INIT_BYTES(239, 255, 2, 3); - // Receive callback function extern "C" void rcvFunc(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) noexcept { @@ -57,8 +58,9 @@ void MulticastResponder::Spin() noexcept pbuf *rxPbuf = receivedPbuf; if (rxPbuf != nullptr) { + lastMessageReceivedPort = receivedPort; debugPrintf("Rx UDP: addr %u.%u.%u.%u port %u data", - (unsigned int)(receivedIpAddr & 0xFF), (unsigned int)((receivedIpAddr >> 8) & 0xFF), (unsigned int)((receivedIpAddr >> 16) & 0xFF), (unsigned int)((receivedIpAddr >> 24) & 0xFF), receivedPort); + (unsigned int)(receivedIpAddr & 0xFF), (unsigned int)((receivedIpAddr >> 8) & 0xFF), (unsigned int)((receivedIpAddr >> 16) & 0xFF), (unsigned int)((receivedIpAddr >> 24) & 0xFF), lastMessageReceivedPort); for (size_t i = 0; i < rxPbuf->len; ++i) { debugPrintf(" %02x", ((const uint8_t*)(rxPbuf->payload))[i]); @@ -121,6 +123,17 @@ void MulticastResponder::Stop() noexcept active = false; } +void MulticastResponder::SendResponse(uint8_t *data, size_t length) noexcept +{ + debugPrintf("Tx UDP: port %u data", lastMessageReceivedPort); + for (size_t i = 0; i < length; ++i) + { + debugPrintf(" %02x", data[i]); + } + debugPrintf("\n"); + //TODO actually send it +} + #endif // End diff --git a/src/Networking/MulticastDiscovery/MulticastResponder.h b/src/Networking/MulticastDiscovery/MulticastResponder.h index 2d57581e..25b717d7 100644 --- a/src/Networking/MulticastDiscovery/MulticastResponder.h +++ b/src/Networking/MulticastDiscovery/MulticastResponder.h @@ -19,6 +19,7 @@ namespace MulticastResponder void Spin() noexcept; void Start(TcpPort port) noexcept; void Stop() noexcept; + void SendResponse(uint8_t *data, size_t length) noexcept; void Diagnostics(MessageType mtype) noexcept; } diff --git a/src/Networking/MulticastDiscovery/fgmc_header.h b/src/Networking/MulticastDiscovery/fgmc_header.h index 2c708940..89f5aead 100644 --- a/src/Networking/MulticastDiscovery/fgmc_header.h +++ b/src/Networking/MulticastDiscovery/fgmc_header.h @@ -40,9 +40,8 @@ enum class FGMCCommandVersion : uint16_t { MCD_COMMAND_VERSION = 0 }; #define INVALID_EEPROM_DATA_STRING_LEN sizeof(INVALID_EEPROM_DATA_STRING) - 1 /// array size definitions -#define FGMC_NAME "FESTOMULTICAST" - -constexpr size_t SIZE_FGMC_NAME = 14; +constexpr const char *FGMC_NAME = "FESTOMULTICAST"; +constexpr size_t SIZE_FGMC_NAME = strlen(FGMC_NAME); constexpr size_t SIZE_FGMC_DEST_ID = 16; constexpr size_t SIZE_FGMC_RES_MAX = 464; // 461 Bytes for FGMC_ResUploadNetInfoHeader diff --git a/src/Networking/MulticastDiscovery/fgmc_protocol.cpp b/src/Networking/MulticastDiscovery/fgmc_protocol.cpp index 832053bc..cb936772 100644 --- a/src/Networking/MulticastDiscovery/fgmc_protocol.cpp +++ b/src/Networking/MulticastDiscovery/fgmc_protocol.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -174,7 +175,7 @@ void FGMCProtocol::handleStream(unsigned int iFaceId, uint8_t* inputBufferAddres } } -void FGMCProtocol::sendGenericHeader(char* tx_netbuf, FGMCCommand cmd, uint32_t length, uint32_t packetId, uint32_t segmentIndex, uint32_t segmentCount) noexcept +void FGMCProtocol::sendGenericHeader(uint8_t* tx_netbuf, FGMCCommand cmd, uint32_t length, uint32_t packetId, uint32_t segmentIndex, uint32_t segmentCount) noexcept { FGMC_GenericHeader* pOutGenericHeader = reinterpret_cast(tx_netbuf); @@ -196,16 +197,7 @@ void FGMCProtocol::sendGenericHeader(char* tx_netbuf, FGMCCommand cmd, uint32_t // Send Message insertPacketId(pOutGenericHeader->fgmc_packet_id_); -#if 1 - //TODO -#else - IP_PACKET* pPacket = nullptr; - pPacket = ::IP_UDP_AllocEx(iface_id_, static_cast(length)); - if (pPacket != nullptr) { - (void)memcpy(pPacket->pData, tx_netbuf, static_cast(length)); - ::IP_UDP_SendAndFree(iface_id_, htonl(FGMC_IP), FGMC_PORT, FGMC_PORT, pPacket); - } -#endif + MulticastResponder::SendResponse(tx_netbuf, length); } void FGMCProtocol::cmdUnetinf(uint32_t inPacketId) noexcept diff --git a/src/Networking/MulticastDiscovery/fgmc_protocol.h b/src/Networking/MulticastDiscovery/fgmc_protocol.h index bc8719d5..2155fa32 100644 --- a/src/Networking/MulticastDiscovery/fgmc_protocol.h +++ b/src/Networking/MulticastDiscovery/fgmc_protocol.h @@ -68,7 +68,7 @@ public: /// \param packetId packedId /// \param segmentIndex segmentIndex /// \param segmentCount segmentCount - void sendGenericHeader(char* tx_netbuf, FGMCCommand cmd, uint32_t length, uint32_t packetId, uint32_t segmentIndex, uint32_t segmentCount) noexcept; + void sendGenericHeader(uint8_t* tx_netbuf, FGMCCommand cmd, uint32_t length, uint32_t packetId, uint32_t segmentIndex, uint32_t segmentCount) noexcept; /// fgmc command "upload network informations" /// \param inPacketId packedId @@ -120,7 +120,7 @@ public: uint32_t fgmc_application_type_; char fgmc_device_type_[SIZE_DEVICE_TYPE]; - char tx_netbuf_[SIZE_FGMC_RES_MAX]; + uint8_t tx_netbuf_[SIZE_FGMC_RES_MAX]; /// Object that holds communication related parameter. #if 0 -- cgit v1.2.3