40 it_assert(
poly(0) == 1,
"CRC_Code::set_polynomial: not a valid polynomial");
42 no_parity = polynomial.size() - 1;
47 std::string crccode[18][2] = {
48 {
"CRC-4",
"1 1 1 1 1"},
49 {
"CRC-7",
"1 1 0 1 0 0 0 1"},
50 {
"CRC-8",
"1 1 1 0 1 0 1 0 1"},
51 {
"CRC-12",
"1 1 0 0 0 0 0 0 0 1 1 1 1"},
52 {
"CRC-24",
"1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 1"},
53 {
"CRC-32",
"1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 0 0 0 1 1 1 0 0 0 1 0"},
54 {
"CCITT-4",
"1 0 0 1 1"},
55 {
"CCITT-5",
"1 1 0 1 0 1"},
56 {
"CCITT-6",
"1 0 0 0 0 1 1"},
57 {
"CCITT-16",
"1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1"},
58 {
"CCITT-32",
"1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 0 1 1 0 1 1 1"},
59 {
"WCDMA-8",
"1 1 0 0 1 1 0 1 1"},
60 {
"WCDMA-12",
"1 1 0 0 0 0 0 0 0 1 1 1 1"},
61 {
"WCDMA-16",
"1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1"},
62 {
"WCDMA-24",
"1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1"},
63 {
"ATM-8",
"1 0 0 0 0 0 1 1 1"},
64 {
"ANSI-16",
"1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1"},
65 {
"SDLC-16",
"1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 1 1"},
73 for (
int i = 0; i < 18;i++) {
74 if (crccode[i][0] == code)
75 poly = bvec(crccode[i][1]);
78 if ((code ==
"WCDMA-8") || (code ==
"WCDMA-12") || (code ==
"WCDMA-16") || (code ==
"WCDMA-24")) {
79 reverse_parity =
true;
82 it_assert(
poly.size() > 0,
"This CRC code doesn't exist in the tables");
91 for (
int i = 0; i < temp.size() - polynomial.size() + 1; i++) {
93 temp.set_subvector(i, temp(i, i + no_parity) + polynomial);
97 out = temp(temp.size() - no_parity, temp.size() - 1);
108 int n = coded_bits.size();
111 if (reverse_parity) {
112 temp =
concat(coded_bits.left(n - no_parity),
reverse(coded_bits.right(no_parity)));
118 for (
int i = 0; i < temp.size() - polynomial.size() + 1; i++) {
120 temp.set_subvector(i, temp(i, i + no_parity) + polynomial);
124 if (temp(temp.size() - no_parity, temp.size() - 1) ==
zeros_b(no_parity))
146 out = coded_bits(0, coded_bits.size() - no_parity - 1);
Various functions on vectors and matrices - header file.
Vec< T > reverse(const Vec< T > &in)
Reverse the input vector.
void set_code(const std::string &code)
Set CRC code to one of the standardpolynomials using the string value.
ITPP_EXPORT bvec zeros_b(int size)
A Binary vector of zeros.
Definition of a CRC code class.
#define it_assert(t, s)
Abort if t is not true.
bool check_parity(const bvec &coded_bits) const
Return true if parity checks OK otherwise flase.
Definitions of special vectors and matrices.
bool decode(const bvec &coded_bits, bvec &out) const
Return true if parity checks OK otherwise flase. Also returns the message part in out...
void poly(const vec &r, vec &p)
Create a polynomial of the given rootsCreate a polynomial p with roots r.
void encode(const bvec &in_bits, bvec &out) const
Calculate and add parity to the in_bits.
void parity(const bvec &in_bits, bvec &out) const
Calulate the parity bits.
void set_generator(const bvec &poly)
Set an arbitary polynomial in bvec form. Start with highest order terms.
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.