From 9f6428795984503ba56e9cb86bdb48bfa8bffbdf Mon Sep 17 00:00:00 2001 From: Pavel Demin Date: Sat, 31 Mar 2018 20:13:47 +0200 Subject: [PATCH] replace crc10.cpp and crc12.cpp with crc10.c and crc12.c --- Makefile | 8 ++++---- crc10.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ crc10.cpp | 31 ------------------------------ crc12.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ crc12.cpp | 31 ------------------------------ 5 files changed, 118 insertions(+), 66 deletions(-) create mode 100644 crc10.c delete mode 100644 crc10.cpp create mode 100644 crc12.c delete mode 100644 crc12.cpp diff --git a/Makefile b/Makefile index 067db43..391c661 100644 --- a/Makefile +++ b/Makefile @@ -8,19 +8,19 @@ OBJECTS = \ indexx.o shell.o pctile.o polyfit.o twkfreq1.o osd174.o encode174.o \ genft8.o genft8refsig.o subtractft8.o db.o ft8b.o ft8d.o -CXX = g++ +CC = gcc FC = gfortran LD = g++ RM = rm -f -CXXFLAGS = -O3 -Wall -fbounds-check -fpermissive +CFLAGS = -O3 -Wall -fbounds-check FFLAGS = -O3 -Wall -funroll-loops -fno-second-underscore LDFLAGS = -lfftw3f `$(FC) -print-file-name=libgfortran.so` all: $(TARGET) -%.o: %.cpp - ${CXX} -c ${CXXFLAGS} $< -o $@ +%.o: %.c + ${CC} -c ${CFLAGS} $< -o $@ %.o: %.f90 ${FC} -c ${FFLAGS} $< -o $@ diff --git a/crc10.c b/crc10.c new file mode 100644 index 0000000..2ddddcb --- /dev/null +++ b/crc10.c @@ -0,0 +1,57 @@ +static unsigned short table[256] = +{ + 0x0000, 0x048f, 0x091e, 0x0d91, 0x123c, 0x16b3, 0x1b22, 0x1fad, + 0x24f7, 0x2078, 0x2de9, 0x2966, 0x36cb, 0x3244, 0x3fd5, 0x3b5a, + 0x49ee, 0x4d61, 0x40f0, 0x447f, 0x5bd2, 0x5f5d, 0x52cc, 0x5643, + 0x6d19, 0x6996, 0x6407, 0x6088, 0x7f25, 0x7baa, 0x763b, 0x72b4, + 0x93dc, 0x9753, 0x9ac2, 0x9e4d, 0x81e0, 0x856f, 0x88fe, 0x8c71, + 0xb72b, 0xb3a4, 0xbe35, 0xbaba, 0xa517, 0xa198, 0xac09, 0xa886, + 0xda32, 0xdebd, 0xd32c, 0xd7a3, 0xc80e, 0xcc81, 0xc110, 0xc59f, + 0xfec5, 0xfa4a, 0xf7db, 0xf354, 0xecf9, 0xe876, 0xe5e7, 0xe168, + 0x2737, 0x23b8, 0x2e29, 0x2aa6, 0x350b, 0x3184, 0x3c15, 0x389a, + 0x03c0, 0x074f, 0x0ade, 0x0e51, 0x11fc, 0x1573, 0x18e2, 0x1c6d, + 0x6ed9, 0x6a56, 0x67c7, 0x6348, 0x7ce5, 0x786a, 0x75fb, 0x7174, + 0x4a2e, 0x4ea1, 0x4330, 0x47bf, 0x5812, 0x5c9d, 0x510c, 0x5583, + 0xb4eb, 0xb064, 0xbdf5, 0xb97a, 0xa6d7, 0xa258, 0xafc9, 0xab46, + 0x901c, 0x9493, 0x9902, 0x9d8d, 0x8220, 0x86af, 0x8b3e, 0x8fb1, + 0xfd05, 0xf98a, 0xf41b, 0xf094, 0xef39, 0xebb6, 0xe627, 0xe2a8, + 0xd9f2, 0xdd7d, 0xd0ec, 0xd463, 0xcbce, 0xcf41, 0xc2d0, 0xc65f, + 0x4ee1, 0x4a6e, 0x47ff, 0x4370, 0x5cdd, 0x5852, 0x55c3, 0x514c, + 0x6a16, 0x6e99, 0x6308, 0x6787, 0x782a, 0x7ca5, 0x7134, 0x75bb, + 0x070f, 0x0380, 0x0e11, 0x0a9e, 0x1533, 0x11bc, 0x1c2d, 0x18a2, + 0x23f8, 0x2777, 0x2ae6, 0x2e69, 0x31c4, 0x354b, 0x38da, 0x3c55, + 0xdd3d, 0xd9b2, 0xd423, 0xd0ac, 0xcf01, 0xcb8e, 0xc61f, 0xc290, + 0xf9ca, 0xfd45, 0xf0d4, 0xf45b, 0xebf6, 0xef79, 0xe2e8, 0xe667, + 0x94d3, 0x905c, 0x9dcd, 0x9942, 0x86ef, 0x8260, 0x8ff1, 0x8b7e, + 0xb024, 0xb4ab, 0xb93a, 0xbdb5, 0xa218, 0xa697, 0xab06, 0xaf89, + 0x69d6, 0x6d59, 0x60c8, 0x6447, 0x7bea, 0x7f65, 0x72f4, 0x767b, + 0x4d21, 0x49ae, 0x443f, 0x40b0, 0x5f1d, 0x5b92, 0x5603, 0x528c, + 0x2038, 0x24b7, 0x2926, 0x2da9, 0x3204, 0x368b, 0x3b1a, 0x3f95, + 0x04cf, 0x0040, 0x0dd1, 0x095e, 0x16f3, 0x127c, 0x1fed, 0x1b62, + 0xfa0a, 0xfe85, 0xf314, 0xf79b, 0xe836, 0xecb9, 0xe128, 0xe5a7, + 0xdefd, 0xda72, 0xd7e3, 0xd36c, 0xccc1, 0xc84e, 0xc5df, 0xc150, + 0xb3e4, 0xb76b, 0xbafa, 0xbe75, 0xa1d8, 0xa557, 0xa8c6, 0xac49, + 0x9713, 0x939c, 0x9e0d, 0x9a82, 0x852f, 0x81a0, 0x8c31, 0x88be +}; + +short crc10(unsigned char const *data, int length) +{ + unsigned short remainder = 0; + unsigned char index; + int i; + + for(i = 0; i < length; ++i) + { + index = remainder >> 2; + remainder <<= 8; + remainder |= data[i]; + remainder ^= table[index]; + } + + return remainder & 0x03ff; +} + +short crc10_check(unsigned char const *data, int length) +{ + return !crc10(data, length); +} diff --git a/crc10.cpp b/crc10.cpp deleted file mode 100644 index 93f6649..0000000 --- a/crc10.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -extern "C" -{ - short crc10 (unsigned char const * data, int length); - bool crc10_check (unsigned char const * data, int length); -} - -#define POLY 0x08f - -#ifdef BOOST_NO_CXX11_CONSTEXPR -#define TRUNCATED_POLYNOMIAL POLY -#else -namespace -{ - unsigned long constexpr TRUNCATED_POLYNOMIAL = POLY; -} -#endif - -// assumes CRC is last 16 bits of the data and is set to zero -// caller should assign the returned CRC into the message in big endian byte order -short crc10 (unsigned char const * data, int length) -{ - return boost::augmented_crc<10, TRUNCATED_POLYNOMIAL> (data, length); -} - -bool crc10_check (unsigned char const * data, int length) -{ - return !boost::augmented_crc<10, TRUNCATED_POLYNOMIAL> (data, length); -} diff --git a/crc12.c b/crc12.c new file mode 100644 index 0000000..f666edf --- /dev/null +++ b/crc12.c @@ -0,0 +1,57 @@ +static unsigned short table[256] = +{ + 0x0000, 0x1c06, 0x340a, 0x280c, 0x6814, 0x7412, 0x5c1e, 0x4018, + 0xdc2e, 0xc028, 0xe824, 0xf422, 0xb43a, 0xa83c, 0x8030, 0x9c36, + 0xb45a, 0xa85c, 0x8050, 0x9c56, 0xdc4e, 0xc048, 0xe844, 0xf442, + 0x6874, 0x7472, 0x5c7e, 0x4078, 0x0060, 0x1c66, 0x346a, 0x286c, + 0x68b4, 0x74b2, 0x5cbe, 0x40b8, 0x00a0, 0x1ca6, 0x34aa, 0x28ac, + 0xb49a, 0xa89c, 0x8090, 0x9c96, 0xdc8e, 0xc088, 0xe884, 0xf482, + 0xdcee, 0xc0e8, 0xe8e4, 0xf4e2, 0xb4fa, 0xa8fc, 0x80f0, 0x9cf6, + 0x00c0, 0x1cc6, 0x34ca, 0x28cc, 0x68d4, 0x74d2, 0x5cde, 0x40d8, + 0xdd6e, 0xc168, 0xe964, 0xf562, 0xb57a, 0xa97c, 0x8170, 0x9d76, + 0x0140, 0x1d46, 0x354a, 0x294c, 0x6954, 0x7552, 0x5d5e, 0x4158, + 0x6934, 0x7532, 0x5d3e, 0x4138, 0x0120, 0x1d26, 0x352a, 0x292c, + 0xb51a, 0xa91c, 0x8110, 0x9d16, 0xdd0e, 0xc108, 0xe904, 0xf502, + 0xb5da, 0xa9dc, 0x81d0, 0x9dd6, 0xddce, 0xc1c8, 0xe9c4, 0xf5c2, + 0x69f4, 0x75f2, 0x5dfe, 0x41f8, 0x01e0, 0x1de6, 0x35ea, 0x29ec, + 0x0180, 0x1d86, 0x358a, 0x298c, 0x6994, 0x7592, 0x5d9e, 0x4198, + 0xddae, 0xc1a8, 0xe9a4, 0xf5a2, 0xb5ba, 0xa9bc, 0x81b0, 0x9db6, + 0xb6da, 0xaadc, 0x82d0, 0x9ed6, 0xdece, 0xc2c8, 0xeac4, 0xf6c2, + 0x6af4, 0x76f2, 0x5efe, 0x42f8, 0x02e0, 0x1ee6, 0x36ea, 0x2aec, + 0x0280, 0x1e86, 0x368a, 0x2a8c, 0x6a94, 0x7692, 0x5e9e, 0x4298, + 0xdeae, 0xc2a8, 0xeaa4, 0xf6a2, 0xb6ba, 0xaabc, 0x82b0, 0x9eb6, + 0xde6e, 0xc268, 0xea64, 0xf662, 0xb67a, 0xaa7c, 0x8270, 0x9e76, + 0x0240, 0x1e46, 0x364a, 0x2a4c, 0x6a54, 0x7652, 0x5e5e, 0x4258, + 0x6a34, 0x7632, 0x5e3e, 0x4238, 0x0220, 0x1e26, 0x362a, 0x2a2c, + 0xb61a, 0xaa1c, 0x8210, 0x9e16, 0xde0e, 0xc208, 0xea04, 0xf602, + 0x6bb4, 0x77b2, 0x5fbe, 0x43b8, 0x03a0, 0x1fa6, 0x37aa, 0x2bac, + 0xb79a, 0xab9c, 0x8390, 0x9f96, 0xdf8e, 0xc388, 0xeb84, 0xf782, + 0xdfee, 0xc3e8, 0xebe4, 0xf7e2, 0xb7fa, 0xabfc, 0x83f0, 0x9ff6, + 0x03c0, 0x1fc6, 0x37ca, 0x2bcc, 0x6bd4, 0x77d2, 0x5fde, 0x43d8, + 0x0300, 0x1f06, 0x370a, 0x2b0c, 0x6b14, 0x7712, 0x5f1e, 0x4318, + 0xdf2e, 0xc328, 0xeb24, 0xf722, 0xb73a, 0xab3c, 0x8330, 0x9f36, + 0xb75a, 0xab5c, 0x8350, 0x9f56, 0xdf4e, 0xc348, 0xeb44, 0xf742, + 0x6b74, 0x7772, 0x5f7e, 0x4378, 0x0360, 0x1f66, 0x376a, 0x2b6c +}; + +short crc12(unsigned char const *data, int length) +{ + unsigned short remainder = 0; + unsigned char index; + int i; + + for(i = 0; i < length; ++i) + { + index = remainder >> 4; + remainder <<= 8; + remainder |= data[i]; + remainder ^= table[index]; + } + + return remainder & 0x0fff; +} + +short crc12_check(unsigned char const *data, int length) +{ + return !crc12(data, length); +} diff --git a/crc12.cpp b/crc12.cpp deleted file mode 100644 index 44e50fe..0000000 --- a/crc12.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -extern "C" -{ - short crc12 (unsigned char const * data, int length); - bool crc12_check (unsigned char const * data, int length); -} - -#define POLY 0xc06 - -#ifdef BOOST_NO_CXX11_CONSTEXPR -#define TRUNCATED_POLYNOMIAL POLY -#else -namespace -{ - unsigned long constexpr TRUNCATED_POLYNOMIAL = POLY; -} -#endif - -// assumes CRC is last 16 bits of the data and is set to zero -// caller should assign the returned CRC into the message in big endian byte order -short crc12 (unsigned char const * data, int length) -{ - return boost::augmented_crc<12, TRUNCATED_POLYNOMIAL> (data, length); -} - -bool crc12_check (unsigned char const * data, int length) -{ - return !boost::augmented_crc<12, TRUNCATED_POLYNOMIAL> (data, length); -}