summaryrefslogtreecommitdiff
path: root/gr-digital/python/digital
diff options
context:
space:
mode:
authorMartin Braun <martin@gnuradio.org>2021-05-17 15:54:08 +0200
committermormj <34754695+mormj@users.noreply.github.com>2021-05-22 14:30:40 -0400
commit60147b42f29f9746a3f8fb5d41193f39a29054eb (patch)
treee354e1b2925270500b696a9baab0feb493b03578 /gr-digital/python/digital
parentb029dc427ea633409069198823390abd912b18e7 (diff)
digital: Remove crc32 utility
This patch removes a crc32 utility that used to be used in our CRC32 blocks, but no longer is. Right now, all this does is expose a generic CRC32 function to the user (both via Python and C++), but there are enough other libraries that let the user do that. Therefore, we'll remove this. Signed-off-by: Martin Braun <martin@gnuradio.org>
Diffstat (limited to 'gr-digital/python/digital')
-rw-r--r--gr-digital/python/digital/bindings/CMakeLists.txt1
-rw-r--r--gr-digital/python/digital/bindings/crc32_python.cc62
-rw-r--r--gr-digital/python/digital/bindings/docstrings/crc32_pydoc_template.h27
-rw-r--r--gr-digital/python/digital/bindings/python_bindings.cc2
-rw-r--r--gr-digital/python/digital/crc.py31
-rw-r--r--gr-digital/python/digital/qa_crc32.py51
6 files changed, 19 insertions, 155 deletions
diff --git a/gr-digital/python/digital/bindings/CMakeLists.txt b/gr-digital/python/digital/bindings/CMakeLists.txt
index a18fc0f0bc..4d24678ec9 100644
--- a/gr-digital/python/digital/bindings/CMakeLists.txt
+++ b/gr-digital/python/digital/bindings/CMakeLists.txt
@@ -28,7 +28,6 @@ list(APPEND digital_python_files
correlate_access_code_tag_ff_python.cc
costas_loop_cc_python.cc
cpmmod_bc_python.cc
- crc32_python.cc
crc32_async_bb_python.cc
crc32_bb_python.cc
decision_feedback_equalizer_python.cc
diff --git a/gr-digital/python/digital/bindings/crc32_python.cc b/gr-digital/python/digital/bindings/crc32_python.cc
deleted file mode 100644
index cea28e8ee7..0000000000
--- a/gr-digital/python/digital/bindings/crc32_python.cc
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2020 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-/***********************************************************************************/
-/* This file is automatically generated using bindtool and can be manually edited */
-/* The following lines can be configured to regenerate this file during cmake */
-/* If manual edits are made, the following tags should be modified accordingly. */
-/* BINDTOOL_GEN_AUTOMATIC(0) */
-/* BINDTOOL_USE_PYGCCXML(0) */
-/* BINDTOOL_HEADER_FILE(crc32.h) */
-/* BINDTOOL_HEADER_FILE_HASH(68481b3e03e592f988af1aa2821ee982) */
-/***********************************************************************************/
-
-#include <pybind11/complex.h>
-#include <pybind11/pybind11.h>
-#include <pybind11/stl.h>
-
-namespace py = pybind11;
-
-#include <gnuradio/digital/crc32.h>
-// pydoc.h is automatically generated in the build directory
-#include <crc32_pydoc.h>
-
-void bind_crc32(py::module& m)
-{
-
-
- m.def("update_crc32",
- (unsigned int (*)(unsigned int, unsigned char const*, size_t)) &
- ::gr::digital::update_crc32,
- py::arg("crc"),
- py::arg("buf"),
- py::arg("len"),
- D(update_crc32, 0));
-
-
- m.def("update_crc32",
- (unsigned int (*)(unsigned int, std::string const)) &
- ::gr::digital::update_crc32,
- py::arg("crc"),
- py::arg("buf"),
- D(update_crc32, 1));
-
-
- m.def("crc32",
- (unsigned int (*)(unsigned char const*, size_t)) & ::gr::digital::crc32,
- py::arg("buf"),
- py::arg("len"),
- D(crc32, 0));
-
-
- m.def("crc32",
- (unsigned int (*)(std::string const)) & ::gr::digital::crc32,
- py::arg("buf"),
- D(crc32, 1));
-}
diff --git a/gr-digital/python/digital/bindings/docstrings/crc32_pydoc_template.h b/gr-digital/python/digital/bindings/docstrings/crc32_pydoc_template.h
deleted file mode 100644
index 75ae8d3814..0000000000
--- a/gr-digital/python/digital/bindings/docstrings/crc32_pydoc_template.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2020 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-#include "pydoc_macros.h"
-#define D(...) DOC(gr, digital, __VA_ARGS__)
-/*
- This file contains placeholders for docstrings for the Python bindings.
- Do not edit! These were automatically extracted during the binding process
- and will be overwritten during the build process
- */
-
-
-static const char* __doc_gr_digital_update_crc32_0 = R"doc()doc";
-
-
-static const char* __doc_gr_digital_update_crc32_1 = R"doc()doc";
-
-
-static const char* __doc_gr_digital_crc32_0 = R"doc()doc";
-
-
-static const char* __doc_gr_digital_crc32_1 = R"doc()doc";
diff --git a/gr-digital/python/digital/bindings/python_bindings.cc b/gr-digital/python/digital/bindings/python_bindings.cc
index 2621412e6a..830902679d 100644
--- a/gr-digital/python/digital/bindings/python_bindings.cc
+++ b/gr-digital/python/digital/bindings/python_bindings.cc
@@ -38,7 +38,6 @@ void bind_correlate_access_code_tag_bb(py::module&);
void bind_correlate_access_code_tag_ff(py::module&);
void bind_costas_loop_cc(py::module&);
void bind_cpmmod_bc(py::module&);
-void bind_crc32(py::module&);
void bind_crc32_async_bb(py::module&);
void bind_crc32_bb(py::module&);
void bind_decision_feedback_equalizer(py::module&);
@@ -140,7 +139,6 @@ PYBIND11_MODULE(digital_python, m)
bind_correlate_access_code_tag_ff(m);
bind_costas_loop_cc(m);
bind_cpmmod_bc(m);
- bind_crc32(m);
bind_crc32_async_bb(m);
bind_crc32_bb(m);
bind_decision_feedback_equalizer(m);
diff --git a/gr-digital/python/digital/crc.py b/gr-digital/python/digital/crc.py
index 0b48da69a6..2cec0d446e 100644
--- a/gr-digital/python/digital/crc.py
+++ b/gr-digital/python/digital/crc.py
@@ -5,21 +5,28 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
-#
+"""
+Backward-compatible wrapper for CRC32
+"""
-from . import digital_python as digital
+import zlib
import struct
-def gen_and_append_crc32(s):
- crc = digital.crc32(s)
- return s + struct.pack(">I", crc)
+def gen_and_append_crc32(data):
+ """
+ Return a binary string with its CRC appended
+ """
+ return data + struct.pack(">I", zlib.crc32(data))
+
+def check_crc32(data):
+ """
+ Check if the byte string 's' has a valid CRC on its last four bytes
-def check_crc32(s):
- if len(s) < 4:
+ Returns a tuple (is CRC valid, string-without-CRC).
+ """
+ if len(data) < 4:
return (False, '')
- msg = s[:-4]
- #print "msg = '%s'" % (msg,)
- actual = digital.crc32(msg)
- (expected,) = struct.unpack(">I", s[-4:])
- # print "actual =", hex(actual), "expected =", hex(expected)
+ msg = data[:-4] # Message without the CRC
+ actual = zlib.crc32(msg)
+ (expected,) = struct.unpack(">I", data[-4:])
return (actual == expected, msg)
diff --git a/gr-digital/python/digital/qa_crc32.py b/gr-digital/python/digital/qa_crc32.py
deleted file mode 100644
index 8207a34e73..0000000000
--- a/gr-digital/python/digital/qa_crc32.py
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2011 Free Software Foundation, Inc.
-#
-# This file is part of GNU Radio
-#
-# SPDX-License-Identifier: GPL-3.0-or-later
-#
-#
-
-
-import cmath
-
-from gnuradio import gr, gr_unittest, digital
-
-
-class test_crc32(gr_unittest.TestCase):
-
- def setUp(self):
- self.tb = gr.top_block()
-
- def tearDown(self):
- self.tb = None
-
- def test01(self):
- data = 100 * "0"
- expected_result = 2943744955
- result = digital.crc32(data)
- # print hex(result)
-
- self.assertEqual(expected_result, result)
-
- def test02(self):
- data = 100 * "1"
- expected_result = 2326594156
- result = digital.crc32(data)
- # print hex(result)
-
- self.assertEqual(expected_result, result)
-
- def test03(self):
- data = 10 * "0123456789"
- expected_result = 3774345973
- result = digital.crc32(data)
- # print hex(result)
-
- self.assertEqual(expected_result, result)
-
-
-if __name__ == '__main__':
- gr_unittest.run(test_crc32)