From 1cb52da49230c64c3719b4ab944ba1cf5a9abb92 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Sun, 24 Jul 2011 13:25:27 -0400 Subject: digital: moved CRC32 from gnuradio-core to gr-digital. Also added QA code for it. --- gr-digital/python/crc.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 gr-digital/python/crc.py (limited to 'gr-digital/python/crc.py') diff --git a/gr-digital/python/crc.py b/gr-digital/python/crc.py new file mode 100644 index 0000000000..f9d369f4cb --- /dev/null +++ b/gr-digital/python/crc.py @@ -0,0 +1,37 @@ +# +# Copyright 2005,2007,2011 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gru +import struct + +def gen_and_append_crc32(s): + crc = gr.crc32(s) + return s + struct.pack(">I", gru.hexint(crc) & 0xFFFFFFFF) + +def check_crc32(s): + if len(s) < 4: + return (False, '') + msg = s[:-4] + #print "msg = '%s'" % (msg,) + actual = gr.crc32(msg) + (expected,) = struct.unpack(">I", s[-4:]) + # print "actual =", hex(actual), "expected =", hex(expected) + return (actual == expected, msg) -- cgit v1.2.3 From 59c20a3fbdb0860ab4d8a14eb39980a6c46087f7 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Sun, 24 Jul 2011 17:46:07 -0400 Subject: digital: modifications to make Python scripts in digital usable. --- gr-digital/Makefile.am | 2 +- gr-digital/python/__init__.py | 3 +++ gr-digital/python/crc.py | 7 ++++--- gr-digital/python/dbpsk.py | 4 ++-- gr-digital/python/packet_utils.py | 4 ++-- gr-digital/python/pkt.py | 3 ++- 6 files changed, 14 insertions(+), 9 deletions(-) (limited to 'gr-digital/python/crc.py') diff --git a/gr-digital/Makefile.am b/gr-digital/Makefile.am index 62c40f2dfd..f1409793ff 100644 --- a/gr-digital/Makefile.am +++ b/gr-digital/Makefile.am @@ -24,7 +24,7 @@ include $(top_srcdir)/Makefile.common SUBDIRS = lib if PYTHON -SUBDIRS += swig python apps grc +SUBDIRS += swig python apps grc examples endif pkgconfigdir = $(libdir)/pkgconfig diff --git a/gr-digital/python/__init__.py b/gr-digital/python/__init__.py index a17128e7d2..73c69bb27b 100644 --- a/gr-digital/python/__init__.py +++ b/gr-digital/python/__init__.py @@ -27,3 +27,6 @@ from dqpsk import * from d8psk import * from psk2 import * from qam import * +from pkt import * +from packet_utils import * +from crc import * diff --git a/gr-digital/python/crc.py b/gr-digital/python/crc.py index f9d369f4cb..198ab059f5 100644 --- a/gr-digital/python/crc.py +++ b/gr-digital/python/crc.py @@ -19,11 +19,12 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gru +from gnuradio import gru +import digital_swig import struct def gen_and_append_crc32(s): - crc = gr.crc32(s) + crc = digital_swig.crc32(s) return s + struct.pack(">I", gru.hexint(crc) & 0xFFFFFFFF) def check_crc32(s): @@ -31,7 +32,7 @@ def check_crc32(s): return (False, '') msg = s[:-4] #print "msg = '%s'" % (msg,) - actual = gr.crc32(msg) + actual = digital_swig.crc32(msg) (expected,) = struct.unpack(">I", s[-4:]) # print "actual =", hex(actual), "expected =", hex(expected) return (actual == expected, msg) diff --git a/gr-digital/python/dbpsk.py b/gr-digital/python/dbpsk.py index 21ca0474b5..1732c44ea0 100644 --- a/gr-digital/python/dbpsk.py +++ b/gr-digital/python/dbpsk.py @@ -366,5 +366,5 @@ class dbpsk_demod(gr.hier_block2): # # Add these to the mod/demod registry # -modulation_utils2.add_type_1_mod('dbpsk3', dbpsk_mod) -modulation_utils2.add_type_1_demod('dbpsk3', dbpsk_demod) +modulation_utils2.add_type_1_mod('dbpsk', dbpsk_mod) +modulation_utils2.add_type_1_demod('dbpsk', dbpsk_demod) diff --git a/gr-digital/python/packet_utils.py b/gr-digital/python/packet_utils.py index e36b05413e..addbf43f57 100644 --- a/gr-digital/python/packet_utils.py +++ b/gr-digital/python/packet_utils.py @@ -22,7 +22,7 @@ import struct import numpy from gnuradio import gru - +import crc def conv_packed_binary_string_to_1_0_string(s): """ @@ -127,7 +127,7 @@ def make_packet(payload, samples_per_symbol, bits_per_symbol, (packed_access_code, padded) = conv_1_0_string_to_packed_binary_string(access_code) (packed_preamble, ignore) = conv_1_0_string_to_packed_binary_string(preamble) - payload_with_crc = gru.gen_and_append_crc32(payload) + payload_with_crc = crc.gen_and_append_crc32(payload) #print "outbound crc =", string_to_hex_list(payload_with_crc[-4:]) L = len(payload_with_crc) diff --git a/gr-digital/python/pkt.py b/gr-digital/python/pkt.py index aa720d1a52..80001a187b 100644 --- a/gr-digital/python/pkt.py +++ b/gr-digital/python/pkt.py @@ -20,8 +20,9 @@ # from math import pi -from gnuradio import gr, packet_utils +from gnuradio import gr import gnuradio.gr.gr_threading as _threading +import packet_utils # ///////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3