summaryrefslogtreecommitdiff
path: root/gnuradio-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r--gnuradio-core/src/lib/general/gr_framer_sink_1.cc17
-rw-r--r--gnuradio-core/src/lib/general/gr_framer_sink_1.h11
-rw-r--r--gnuradio-core/src/python/gnuradio/blksimpl/pkt.py17
-rw-r--r--gnuradio-core/src/python/gnuradio/packet_utils.py31
4 files changed, 48 insertions, 28 deletions
diff --git a/gnuradio-core/src/lib/general/gr_framer_sink_1.cc b/gnuradio-core/src/lib/general/gr_framer_sink_1.cc
index d6f87df1e..1d939adbd 100644
--- a/gnuradio-core/src/lib/general/gr_framer_sink_1.cc
+++ b/gnuradio-core/src/lib/general/gr_framer_sink_1.cc
@@ -52,13 +52,14 @@ gr_framer_sink_1::enter_have_sync()
}
inline void
-gr_framer_sink_1::enter_have_header(int payload_len)
+gr_framer_sink_1::enter_have_header(int payload_len, int whitener_offset)
{
if (VERBOSE)
- fprintf(stderr, "@ enter_have_header (payload_len = %d)\n", payload_len);
+ fprintf(stderr, "@ enter_have_header (payload_len = %d) (offset = %d)\n", payload_len, whitener_offset);
d_state = STATE_HAVE_HEADER;
d_packetlen = payload_len;
+ d_packet_whitener_offset = whitener_offset;
d_packetlen_cnt = 0;
d_packet_byte = 0;
d_packet_byte_index = 0;
@@ -125,11 +126,10 @@ gr_framer_sink_1::work (int noutput_items,
// we have a full header, check to see if it has been received properly
if (header_ok()){
- int payload_len = header_payload_len();
- if (payload_len <= MAX_PKT_LEN) // reasonable?
- enter_have_header(payload_len); // yes.
- else
- enter_search(); // no.
+ int payload_len;
+ int payload_offset;
+ header_payload(&payload_len, &payload_offset);
+ enter_have_header(payload_len, payload_offset);
}
else
enter_search(); // no.
@@ -151,7 +151,8 @@ gr_framer_sink_1::work (int noutput_items,
if (d_packetlen_cnt == d_packetlen){ // packet is filled
// build a message
- gr_message_sptr msg = gr_make_message(0, 0, 0, d_packetlen_cnt);
+ // NOTE: passing header field as arg1 is not scalable
+ gr_message_sptr msg = gr_make_message(0, d_packet_whitener_offset, 0, d_packetlen_cnt);
memcpy(msg->msg(), d_packet, d_packetlen_cnt);
d_target_queue->insert_tail(msg); // send it
diff --git a/gnuradio-core/src/lib/general/gr_framer_sink_1.h b/gnuradio-core/src/lib/general/gr_framer_sink_1.h
index dab346755..ba50184b8 100644
--- a/gnuradio-core/src/lib/general/gr_framer_sink_1.h
+++ b/gnuradio-core/src/lib/general/gr_framer_sink_1.h
@@ -70,6 +70,7 @@ class gr_framer_sink_1 : public gr_sync_block
unsigned char d_packet_byte; // byte being assembled
int d_packet_byte_index; // which bit of d_packet_byte we're working on
int d_packetlen; // length of packet
+ int d_packet_whitener_offset; // offset into whitener string to use
int d_packetlen_cnt; // how many so far
protected:
@@ -77,7 +78,7 @@ class gr_framer_sink_1 : public gr_sync_block
void enter_search();
void enter_have_sync();
- void enter_have_header(int payload_len);
+ void enter_have_header(int payload_len, int whitener_offset);
bool header_ok()
{
@@ -85,11 +86,13 @@ class gr_framer_sink_1 : public gr_sync_block
return ((d_header >> 16) ^ (d_header & 0xffff)) == 0;
}
- int header_payload_len()
+ void header_payload(int *len, int *offset)
{
// header consists of two 16-bit shorts in network byte order
- int t = (d_header >> 16) & 0xffff;
- return t;
+ // payload length is lower 12 bits
+ // whitener offset is upper 4 bits
+ *len = (d_header >> 16) & 0x0fff;
+ *offset = (d_header >> 28) & 0x000f;
}
public:
diff --git a/gnuradio-core/src/python/gnuradio/blksimpl/pkt.py b/gnuradio-core/src/python/gnuradio/blksimpl/pkt.py
index a1ece893d..96b48657f 100644
--- a/gnuradio-core/src/python/gnuradio/blksimpl/pkt.py
+++ b/gnuradio-core/src/python/gnuradio/blksimpl/pkt.py
@@ -36,7 +36,7 @@ class mod_pkts(gr.hier_block):
Send packets by calling send_pkt
"""
- def __init__(self, fg, modulator, access_code=None, msgq_limit=2, pad_for_usrp=True):
+ def __init__(self, fg, modulator, access_code=None, msgq_limit=2, pad_for_usrp=True, use_whitener_offset=False):
"""
Hierarchical block for sending packets
@@ -52,12 +52,15 @@ class mod_pkts(gr.hier_block):
@param msgq_limit: maximum number of messages in message queue
@type msgq_limit: int
@param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples
-
+ @param use_whitener_offset: If true, start of whitener XOR string is incremented each packet
+
See gmsk_mod for remaining parameters
"""
self._modulator = modulator
self._pad_for_usrp = pad_for_usrp
-
+ self._use_whitener_offset = use_whitener_offset
+ self._whitener_offset = 0
+
if access_code is None:
access_code = packet_utils.default_access_code
if not packet_utils.is_1_0_string(access_code):
@@ -84,9 +87,13 @@ class mod_pkts(gr.hier_block):
self._modulator.samples_per_symbol(),
self._modulator.bits_per_symbol(),
self._access_code,
- self._pad_for_usrp)
+ self._pad_for_usrp,
+ self._whitener_offset)
#print "pkt =", string_to_hex_list(pkt)
msg = gr.message_from_string(pkt)
+ if self._use_whitener_offset is True:
+ self._whitener_offset = (self._whitener_offset + 1) % 16
+
self._pkt_input.msgq().insert_tail(msg)
@@ -151,6 +158,6 @@ class _queue_watcher_thread(_threading.Thread):
def run(self):
while self.keep_running:
msg = self.rcvd_pktq.delete_head()
- ok, payload = packet_utils.unmake_packet(msg.to_string())
+ ok, payload = packet_utils.unmake_packet(msg.to_string(), int(msg.arg1()))
if self.callback:
self.callback(ok, payload)
diff --git a/gnuradio-core/src/python/gnuradio/packet_utils.py b/gnuradio-core/src/python/gnuradio/packet_utils.py
index 59b135366..182c80cdc 100644
--- a/gnuradio-core/src/python/gnuradio/packet_utils.py
+++ b/gnuradio-core/src/python/gnuradio/packet_utils.py
@@ -86,22 +86,26 @@ def string_to_hex_list(s):
return map(lambda x: hex(ord(x)), s)
-def whiten(s):
+def whiten(s, o):
sa = Numeric.fromstring(s, Numeric.UnsignedInt8)
- z = sa ^ random_mask_vec8[0:len(sa)]
+ z = sa ^ random_mask_vec8[o:len(sa)+o]
return z.tostring()
-def dewhiten(s):
- return whiten(s) # self inverse
+def dewhiten(s, o):
+ return whiten(s, o) # self inverse
-def make_header(payload_len):
- return struct.pack('!HH', payload_len, payload_len)
+def make_header(payload_len, whitener_offset=0):
+ # Upper nibble is offset, lower 12 bits is len
+ val = ((whitener_offset & 0xf) << 12) | (payload_len & 0x0fff)
+ #print "offset =", whitener_offset, " len =", payload_len, " val=", val
+ 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):
+ access_code=default_access_code, pad_for_usrp=True,
+ whitener_offset=0):
"""
- Build a packet, given access code and payload.
+ Build a packet, given access code, payload, and whitener offset
@param payload: packet payload, len [0, 4096]
@param samples_per_symbol: samples per symbol (needed for padding calculation)
@@ -109,6 +113,7 @@ def make_packet(payload, samples_per_symbol, bits_per_symbol,
@param bits_per_symbol: (needed for padding calculation)
@type bits_per_symbol: int
@param access_code: string of ascii 0's and 1's
+ @param 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.
@@ -116,6 +121,9 @@ def make_packet(payload, samples_per_symbol, bits_per_symbol,
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,)
+ if not whitener_offset >=0 and whitener_offset < 16:
+ raise ValueError, "whitener_offset must be between 0 and 15, inclusive (%i)" % (whitener_offset,)
+
(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)
@@ -127,7 +135,8 @@ def make_packet(payload, samples_per_symbol, bits_per_symbol,
if L > MAXLEN:
raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN,)
- pkt = ''.join((packed_preamble, packed_access_code, make_header(L), whiten(payload_with_crc), '\x55'))
+ pkt = ''.join((packed_preamble, packed_access_code, make_header(L, whitener_offset),
+ whiten(payload_with_crc, whitener_offset), '\x55'))
if pad_for_usrp:
pkt = pkt + (_npadding_bytes(len(pkt), samples_per_symbol, bits_per_symbol) * '\x55')
@@ -156,13 +165,13 @@ def _npadding_bytes(pkt_byte_len, samples_per_symbol, bits_per_symbol):
return byte_modulus - r
-def unmake_packet(whitened_payload_with_crc):
+def unmake_packet(whitened_payload_with_crc, whitener_offset=0):
"""
Return (ok, payload)
@param whitened_payload_with_crc: string
"""
- payload_with_crc = dewhiten(whitened_payload_with_crc)
+ payload_with_crc = dewhiten(whitened_payload_with_crc, whitener_offset)
ok, payload = gru.check_crc32(payload_with_crc)
if 0: