From d4e4f1a416dad86a908eb68399e941b6e624d67f Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Tue, 11 Feb 2014 12:36:54 +0400 Subject: [PATCH] Added CRC initializing constructor --- libuavcan/include/uavcan/internal/transport/crc.hpp | 6 ++++++ libuavcan/test/transport/crc.cpp | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libuavcan/include/uavcan/internal/transport/crc.hpp b/libuavcan/include/uavcan/internal/transport/crc.hpp index ece09ae5e2..88788b528c 100644 --- a/libuavcan/include/uavcan/internal/transport/crc.hpp +++ b/libuavcan/include/uavcan/internal/transport/crc.hpp @@ -24,6 +24,12 @@ public: : value_(0x0000) { } + Crc16(const uint8_t* bytes, int len) + : value_(0x0000) + { + add(bytes, len); + } + uint16_t add(uint8_t byte); uint16_t add(const uint8_t* bytes, int len); diff --git a/libuavcan/test/transport/crc.cpp b/libuavcan/test/transport/crc.cpp index 46442e6192..f21ddc2412 100644 --- a/libuavcan/test/transport/crc.cpp +++ b/libuavcan/test/transport/crc.cpp @@ -9,9 +9,7 @@ TEST(Crc16, Correctness) { - using uavcan::Crc16; - - Crc16 crc; + uavcan::Crc16 crc; ASSERT_EQ(0x0000, crc.get()); @@ -22,4 +20,7 @@ TEST(Crc16, Correctness) crc.add(reinterpret_cast("Foobar"), 6); ASSERT_EQ(53881, crc.get()); + + // Initializing constructor + ASSERT_EQ(crc.get(), uavcan::Crc16(reinterpret_cast("123Foobar"), 9).get()); }