F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
CRC16.hpp
Go to the documentation of this file.
1 #ifndef SVC_CCSDS_UTILS_CRC16_HPP
2 #define SVC_CCSDS_UTILS_CRC16_HPP
3 
5 // Include the lic crc c library:
6 extern "C" {
8 }
9 
10 namespace Svc {
11 namespace CCSDS {
12 namespace Utils {
13 
18 class CRC16 {
19  public:
20  // Initial value is 0xFFFF
21  CRC16() : m_crc(std::numeric_limits<U16>::max()) {}
22 
28  void update(U8 new_byte) { this->m_crc = static_cast<U16>(update_crc_ccitt(m_crc, static_cast<char>(new_byte))); };
29 
31  U16 finalize() {
32  // Specified XOR value is 0x0000
33  return this->m_crc ^ static_cast<U16>(0);
34  };
35 
43  static U16 compute(const U8* buffer, U32 length) {
44  U16 crc = std::numeric_limits<U16>::max(); // Initial value
45  for (U32 i = 0; i < length; ++i) {
46  crc = static_cast<U16>(update_crc_ccitt(crc, static_cast<char>(buffer[i])));
47  }
48  return crc ^ static_cast<U16>(0); // Finalize with XOR value
49  }
50 
51  U16 m_crc;
52 };
53 
54 } // namespace Utils
55 } // namespace CCSDS
56 } // namespace Svc
57 
58 #endif // SVC_CCSDS_UTILS_CRC16_HPP
static U16 compute(const U8 *buffer, U32 length)
compute CRC16 for a buffer
Definition: CRC16.hpp:43
CRC16 CCITT implementation.
Definition: CRC16.hpp:18
U16 finalize()
finalize and return CRC value
Definition: CRC16.hpp:31
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:56
unsigned short update_crc_ccitt(unsigned short crc, char c)
Definition: lib_crc.c:131
C++ header for working with basic fprime types.
RateGroupDivider component implementation.
void update(U8 new_byte)
update CRC with one new byte
Definition: CRC16.hpp:28