Bitstream Interpretation Library (BIL)  0.1
V5CRCRegister.cpp
Go to the documentation of this file.
1 
7 #include <util/CRC32.hpp>
10 
11 using namespace bil;
12 
13 
15  Register(V5RegisterAddress::CRC, V5RegisterAddress::CRC_STRING, true, true)
16 {
17  reset();
18 }
19 
20 
21 void V5CRCRegister::write(const boost::uint32_t* words, size_t wordCount)
22 {
23  Register::write(words, wordCount);
24 
25  // word count has to be 1
26  if (1 != wordCount) throw Exception();
27  // do CRC check (input data can be ignored, since CRC value is already
28  // updated using them)
29  check();
30 }
31 
32 
33 void V5CRCRegister::read(boost::uint32_t* words, size_t wordCount) const
34 {
35  Register::read(words, wordCount);
36 
37  // word count has to be 1
38  if (1 != wordCount) throw Exception();
39  // return current CRC value
40  *words = m_crcValue;
41 }
42 
43 
44 boost::uint32_t V5CRCRegister::crcValue() const
45 {
46  return m_crcValue;
47 }
48 
49 
51 {
52  m_crcValue = 0;
53 }
54 
55 
56 void V5CRCRegister::update(const boost::uint32_t* words, size_t wordCount, RegisterAddress::address_t registerAddress)
57 {
58  // calculate CRC value over all data words
59  for (size_t i = 0; i < wordCount; ++i)
60  {
61  // each word's CRC value is calculated from its four bytes
62  boost::uint32_t data = *words++;
63  m_crcValue = calc8BitCRC32(m_crcValue, static_cast<boost::uint8_t>(data));
64  m_crcValue = calc8BitCRC32(m_crcValue, static_cast<boost::uint8_t>(data >> 8));
65  m_crcValue = calc8BitCRC32(m_crcValue, static_cast<boost::uint8_t>(data >> 16));
66  m_crcValue = calc8BitCRC32(m_crcValue, static_cast<boost::uint8_t>(data >> 24));
67  // 5 byte register address also gets included
68  m_crcValue = calc5BitCRC32(m_crcValue, static_cast<boost::uint8_t>(registerAddress));
69  }
70 }
71 
72 
74 {
75  if (0 != m_crcValue) throw Exception();
76 }