summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gr-digital/python/digital/packet_utils.py10
-rw-r--r--grc/blocks/blks2_packet_encoder.xml9
-rw-r--r--grc/grc_gnuradio/blks2/packet.py8
3 files changed, 23 insertions, 4 deletions
diff --git a/gr-digital/python/digital/packet_utils.py b/gr-digital/python/digital/packet_utils.py
index 2929758ef0..865f3adbb4 100644
--- a/gr-digital/python/digital/packet_utils.py
+++ b/gr-digital/python/digital/packet_utils.py
@@ -71,7 +71,7 @@ def conv_1_0_string_to_packed_binary_string(s):
default_access_code = \
conv_packed_binary_string_to_1_0_string('\xAC\xDD\xA4\xE2\xF2\x8C\x20\xFC')
-preamble = \
+default_preamble = \
conv_packed_binary_string_to_1_0_string('\xA4\xF2')
def is_1_0_string(s):
@@ -102,8 +102,8 @@ def make_header(payload_len, whitener_offset=0):
return struct.pack('!HH', val, val)
def make_packet(payload, samples_per_symbol, bits_per_symbol,
- access_code=default_access_code, pad_for_usrp=True,
- whitener_offset=0, whitening=True):
+ preamble=default_preamble, access_code=default_access_code,
+ pad_for_usrp=True, whitener_offset=0, whitening=True):
"""
Build a packet, given access code, payload, and whitener offset
@@ -111,12 +111,16 @@ def make_packet(payload, samples_per_symbol, bits_per_symbol,
payload: packet payload, len [0, 4096]
samples_per_symbol: samples per symbol (needed for padding calculation) (int)
bits_per_symbol: (needed for padding calculation) (int)
+ preamble: string of ascii 0's and 1's
access_code: string of ascii 0's and 1's
whitener_offset: offset into whitener string to use [0-16)
Packet will have access code at the beginning, followed by length, payload
and finally CRC-32.
"""
+ if not is_1_0_string(preamble):
+ raise ValueError, "preamble must be a string containing only 0's and 1's (%r)" % (preamble,)
+
if not is_1_0_string(access_code):
raise ValueError, "access_code must be a string containing only 0's and 1's (%r)" % (access_code,)
diff --git a/grc/blocks/blks2_packet_encoder.xml b/grc/blocks/blks2_packet_encoder.xml
index b184ebd31c..88e1ba350c 100644
--- a/grc/blocks/blks2_packet_encoder.xml
+++ b/grc/blocks/blks2_packet_encoder.xml
@@ -11,6 +11,7 @@
<make>grc_blks2.packet_mod_$(type.fcn)(grc_blks2.packet_encoder(
samples_per_symbol=$samples_per_symbol,
bits_per_symbol=$bits_per_symbol,
+ preamble=$preamble,
access_code=$access_code,
pad_for_usrp=$pad_for_usrp,
),
@@ -58,6 +59,12 @@
<type>int</type>
</param>
<param>
+ <name>Preamble</name>
+ <key>preamble</key>
+ <value></value>
+ <type>string</type>
+ </param>
+ <param>
<name>Access Code</name>
<key>access_code</key>
<value></value>
@@ -93,6 +100,8 @@
<doc>
Packet encoder block, for use with the gnuradio modulator blocks: gmsk, dpsk, qam.
+Preamble: string of 1's and 0's, leave blank for automatic.
+
Access Code: string of 1's and 0's, leave blank for automatic.
Payload Length: 0 for automatic.
diff --git a/grc/grc_gnuradio/blks2/packet.py b/grc/grc_gnuradio/blks2/packet.py
index 10dd002471..872f08ca2e 100644
--- a/grc/grc_gnuradio/blks2/packet.py
+++ b/grc/grc_gnuradio/blks2/packet.py
@@ -68,7 +68,7 @@ class packet_encoder(gr.hier_block2):
Hierarchical block for wrapping packet-based modulators.
"""
- def __init__(self, samples_per_symbol, bits_per_symbol, access_code='', pad_for_usrp=True):
+ def __init__(self, samples_per_symbol, bits_per_symbol, preamble='', access_code='', pad_for_usrp=True):
"""
packet_mod constructor.
@@ -83,10 +83,15 @@ class packet_encoder(gr.hier_block2):
self._samples_per_symbol = samples_per_symbol
self._bits_per_symbol = bits_per_symbol
self._pad_for_usrp = pad_for_usrp
+ if not preamble: #get preamble
+ preamble = packet_utils.default_preamble
if not access_code: #get access code
access_code = packet_utils.default_access_code
+ if not packet_utils.is_1_0_string(preamble):
+ raise ValueError, "Invalid preamble %r. Must be string of 1's and 0's" % (preamble,)
if not packet_utils.is_1_0_string(access_code):
raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,)
+ self._preamble = preamble
self._access_code = access_code
self._pad_for_usrp = pad_for_usrp
#create blocks
@@ -113,6 +118,7 @@ class packet_encoder(gr.hier_block2):
payload,
self._samples_per_symbol,
self._bits_per_symbol,
+ self._preamble,
self._access_code,
self._pad_for_usrp
)