From 7f367fd6e313053c1ee1692146c8869d1a57f060 Mon Sep 17 00:00:00 2001 From: Hayodea Hakol Date: Sat, 6 Sep 2025 21:37:53 -0400 Subject: [PATCH] Debug: silence excessive couts --- commonLibs/livoxProto1/protocol.cpp | 56 ++++++++++++++++++----------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/commonLibs/livoxProto1/protocol.cpp b/commonLibs/livoxProto1/protocol.cpp index 3f10d59..b48eef7 100644 --- a/commonLibs/livoxProto1/protocol.cpp +++ b/commonLibs/livoxProto1/protocol.cpp @@ -63,12 +63,16 @@ bool Header::validateCrc16() const // Calculate CRC16 for the header excluding the crc_16 field itself uint16_t calculatedCrc = calculateCrc16(); - // Debug output - std::cout << "CRC16 Debug: calculated=0x" << std::hex << calculatedCrc - << ", received=0x" << crc_16 << std::dec << std::endl; - // Compare with the CRC in the header - return calculatedCrc == crc_16; + bool isValid = (calculatedCrc == crc_16); + + // Debug output only if validation fails + if (!isValid) { + std::cout << "CRC16 Debug: calculated=0x" << std::hex << calculatedCrc + << ", received=0x" << crc_16 << std::dec << std::endl; + } + + return isValid; } void Header::setCrc16FromRawBytes() @@ -167,12 +171,16 @@ bool BroadcastMessage::validateCrc32() const calculatedCrc = comms::calculateCrc32(messageData, messageSize); - // Debug output - std::cout << "BroadcastMessage CRC32 Debug: calculated=0x" << std::hex << calculatedCrc - << ", received=0x" << footer.crc_32 << std::dec << std::endl; + // Compare with the CRC in the footer + bool isValid = (calculatedCrc == footer.crc_32); - // Compare with the CRC in the footer - return calculatedCrc == footer.crc_32; + // Debug output only if validation fails + if (!isValid) { + std::cout << "BroadcastMessage CRC32 Debug: calculated=0x" << std::hex << calculatedCrc + << ", received=0x" << footer.crc_32 << std::dec << std::endl; + } + + return isValid; } // HandshakeRequest methods @@ -284,12 +292,16 @@ bool HandshakeResponse::validateCrc32() const size_t messageSize = sizeof(HandshakeResponse) - sizeof(footer.crc_32); uint32_t calculatedCrc = comms::calculateCrc32(messageData, messageSize); - // Debug output - std::cout << "HandshakeResponse CRC32 Debug: calculated=0x" << std::hex << calculatedCrc - << ", received=0x" << footer.crc_32 << std::dec << std::endl; - // Compare with the CRC in the footer - return calculatedCrc == footer.crc_32; + bool isValid = (calculatedCrc == footer.crc_32); + + // Debug output only if validation fails + if (!isValid) { + std::cout << "HandshakeResponse CRC32 Debug: calculated=0x" << std::hex << calculatedCrc + << ", received=0x" << footer.crc_32 << std::dec << std::endl; + } + + return isValid; } // Standalone CRC16 calculation utility @@ -614,12 +626,16 @@ bool HeartbeatMessage::validateCrc32() const // Use the calculateCrc32 method to avoid code duplication uint32_t calculatedCrc = calculateCrc32(); - // Debug output - std::cout << "HeartbeatMessage CRC32 Debug: calculated=0x" << std::hex << calculatedCrc - << ", received=0x" << footer.crc_32 << std::dec << std::endl; - // Compare with the CRC in the footer - return calculatedCrc == footer.crc_32; + bool isValid = (calculatedCrc == footer.crc_32); + + // Debug output only if validation fails + if (!isValid) { + std::cout << "HeartbeatMessage CRC32 Debug: calculated=0x" << std::hex << calculatedCrc + << ", received=0x" << footer.crc_32 << std::dec << std::endl; + } + + return isValid; } } // namespace comms