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