Fri Nov 17 16:02:40 2017
options
author
window_size
category
Custom
comment
description
_enabled
True
_coordinate
(24, 5)
_rotation
0
generate_options
qt_gui
hier_block_src_path
.:
id
bruteforce
max_nouts
0
qt_qss_theme
realtime_scheduling
run_command
{python} -u {filename}
run_options
prompt
run
True
thread_safe_setters
title
variable
comment
_enabled
True
_coordinate
(24, 77)
_rotation
0
id
baseband_freq
value
676
variable
comment
_enabled
True
_coordinate
(136, 77)
_rotation
0
id
carrier_freq
value
432.867e6
variable
comment
_enabled
True
_coordinate
(280, 77)
_rotation
0
id
packet
value
"010000010[01]0[01]0101000[01]0[01]0[01]0"
variable
comment
_enabled
True
_coordinate
(24, 149)
_rotation
0
id
samp_rate
value
2e6
variable
comment
_enabled
True
_coordinate
(120, 149)
_rotation
0
id
samples_per_symbol
value
int (samp_rate / baseband_freq)
blocks_float_to_complex
alias
comment
affinity
_enabled
1
_coordinate
(488, 537)
_rotation
0
id
blocks_float_to_complex_0
maxoutbuf
0
minoutbuf
0
vlen
1
blocks_moving_average_xx
alias
comment
affinity
_enabled
1
_coordinate
(272, 390)
_rotation
0
id
blocks_moving_average_xx_0
length
samples_per_symbol / 4
max_iter
4000
maxoutbuf
0
minoutbuf
0
scale
1
type
float
blocks_multiply_const_vxx
alias
comment
const
1
affinity
_enabled
1
_coordinate
(448, 404)
_rotation
0
id
blocks_multiply_const_vxx_0
type
float
maxoutbuf
0
minoutbuf
0
vlen
1
blocks_throttle
alias
comment
affinity
_enabled
0
_coordinate
(720, 484)
_rotation
0
id
blocks_throttle_0
ignoretag
True
maxoutbuf
0
minoutbuf
0
samples_per_second
samp_rate
type
complex
vlen
1
blocks_uchar_to_float
alias
comment
affinity
_enabled
1
_coordinate
(576, 257)
_rotation
0
id
blocks_uchar_to_float_0
maxoutbuf
0
minoutbuf
0
blocks_unpack_k_bits_bb
alias
comment
affinity
_enabled
1
_coordinate
(408, 252)
_rotation
0
id
blocks_unpack_k_bits_bb_0
k
4
maxoutbuf
0
minoutbuf
0
digital_map_bb
alias
comment
affinity
_enabled
1
_coordinate
(272, 252)
_rotation
0
id
digital_map_bb_0
map
[0x8, 0xE, 0x0]
maxoutbuf
0
minoutbuf
0
epy_block
alias
_io_cache
('Packet source', 'blk', [('n', '2'), ('repetitions', '1'), ('pattern', "'.*'"), ('spacing', '3'), ('comb_spacing', '30')], [], [('0', 'byte')], "\n Generates all possible combinations of 'n' bits packets that match the given pattern\n ")
_source_code
"""
Embedded Python Blocks:
Each this file is saved, GRC will instantiate the first class it finds to get
ports and parameters of your block. The arguments to __init__ will be the
parameters. All of them are required to have default values!
"""
import re \
, exrex
import numpy as np
from gnuradio import gr
class blk (gr.sync_block):
"""
Generates all possible combinations of 'n' bits packets that match the given pattern
"""
def __init__ (self
, n = 2
, repetitions = 1
, pattern = ".*"
, spacing = 3
, comb_spacing = 30
): # only default arguments here
"""
Constructor
Args:
n -> Number of bits per packet
repetitions -> Number of times that every matched combination should be
repeated
pattern -> Regex (accepted by 're') to filter the accepted bit strings
spacing -> Number of periods left blank between packets
comb_spacing -> Number of periods left blank between the last packet
of one combination and the first of the next combination.
"""
gr.sync_block.__init__ (
self,
name = 'Packet source',
in_sig = [],
out_sig = [np.int8]
)
self.n = n
self.repetitions = repetitions
self.pattern = pattern
self.spacing = spacing
self.comb_spacing = comb_spacing
self.remaining = []
self.generator = self.gen_packet ()
def gen_packet (self):
"""
Infinite generator
Generates all combinations of n_bits that matches the given pattern and repeats
them again.
Returns:
A list with the generated combination
"""
n = self.n
spacing = self.spacing
repetitions = self.repetitions
pattern = self.pattern
# Substitues '.' for '[01]', as packets are a binary string
pattern = re.sub ("[.]", "[01]", pattern)
# Python's regex substitutes '*' for {0, 4294967295}, and '+' for {1, 4294967295}.
# To reduce the output of exrex, 4294967295 is changed for n
pattern = re.sub ("[*]", "{0," + str (n) + "}", pattern)
pattern = re.sub ("[+]", "{1," + str (n) + "}", pattern)
if exrex.count (pattern, limit = n + 1) < (2 ** self.n):
# Generated with exrex (reversing the regular expression)
while True:
for b in exrex.generate (pattern, limit = n + 1):
if len (b) == n:
# Repeats the current combination 'repetitions' times, if it matches
for i in xrange (repetitions):
if (i == 0):
yield [2] * self.comb_spacing \
+ [ int (x) for x in b ] + [2] * spacing
else:
yield [ int (x) for x in b ] + [2] * spacing
print b
else:
# Normal generation (pure bruteforcing)
regex = re.compile (pattern)
b = 0
while True:
s = "{0:b}".format (b).zfill (n)
if regex.match (s):
# Repeats the current combination 'repetitions' times, if it matches
for i in xrange (repetitions):
if (i == 0):
yield [2] * self.comb_spacing \
+ [ int (x) for x in s ] + [2] * spacing
else:
yield [ int (x) for x in s ] + [2] * spacing
print s
# Restarts the counter
if b >= ((2 ** n) - 1):
b = 0
else:
b += 1
def work (self, input_items, output_items):
"""
Signal processing
"""
extra_pkt = []
# Fills the buffer with the current packet
room = (len (output_items [0]) - len (self.remaining))
# To avoid exceptions when output_items is little, takes only the previous items
if room <= 0:
output_items [0][:] = np.array (self.remaining [:len (output_items [0])])
self.remaining = self.remaining [len (output_items [0]):]
return len (output_items [0])
packet = []
acc_len = 0
while len (packet) < room:
tmp = self.generator.next ()
acc_len += len (tmp)
packet += tmp
output_items [0][:] = np.array (
self.remaining
+ packet [:room]
)
# Stores the remaining bits to be sent on the next buffer
if acc_len > room:
self.remaining = packet [room:]
else:
self.remaining = []
return len (output_items [0])
comb_spacing
10
comment
_enabled
1
_coordinate
(16, 224)
_rotation
0
id
gen_packets
n
25
pattern
packet
repetitions
5
spacing
3
osmosdr_sink
alias
ant0
bb_gain0
20
bw0
0
corr0
0
freq0
carrier_freq
if_gain0
20
gain0
10
ant10
bb_gain10
20
bw10
0
corr10
0
freq10
100e6
if_gain10
20
gain10
10
ant11
bb_gain11
20
bw11
0
corr11
0
freq11
100e6
if_gain11
20
gain11
10
ant12
bb_gain12
20
bw12
0
corr12
0
freq12
100e6
if_gain12
20
gain12
10
ant13
bb_gain13
20
bw13
0
corr13
0
freq13
100e6
if_gain13
20
gain13
10
ant14
bb_gain14
20
bw14
0
corr14
0
freq14
100e6
if_gain14
20
gain14
10
ant15
bb_gain15
20
bw15
0
corr15
0
freq15
100e6
if_gain15
20
gain15
10
ant16
bb_gain16
20
bw16
0
corr16
0
freq16
100e6
if_gain16
20
gain16
10
ant17
bb_gain17
20
bw17
0
corr17
0
freq17
100e6
if_gain17
20
gain17
10
ant18
bb_gain18
20
bw18
0
corr18
0
freq18
100e6
if_gain18
20
gain18
10
ant19
bb_gain19
20
bw19
0
corr19
0
freq19
100e6
if_gain19
20
gain19
10
ant1
bb_gain1
20
bw1
0
corr1
0
freq1
100e6
if_gain1
20
gain1
10
ant20
bb_gain20
20
bw20
0
corr20
0
freq20
100e6
if_gain20
20
gain20
10
ant21
bb_gain21
20
bw21
0
corr21
0
freq21
100e6
if_gain21
20
gain21
10
ant22
bb_gain22
20
bw22
0
corr22
0
freq22
100e6
if_gain22
20
gain22
10
ant23
bb_gain23
20
bw23
0
corr23
0
freq23
100e6
if_gain23
20
gain23
10
ant24
bb_gain24
20
bw24
0
corr24
0
freq24
100e6
if_gain24
20
gain24
10
ant25
bb_gain25
20
bw25
0
corr25
0
freq25
100e6
if_gain25
20
gain25
10
ant26
bb_gain26
20
bw26
0
corr26
0
freq26
100e6
if_gain26
20
gain26
10
ant27
bb_gain27
20
bw27
0
corr27
0
freq27
100e6
if_gain27
20
gain27
10
ant28
bb_gain28
20
bw28
0
corr28
0
freq28
100e6
if_gain28
20
gain28
10
ant29
bb_gain29
20
bw29
0
corr29
0
freq29
100e6
if_gain29
20
gain29
10
ant2
bb_gain2
20
bw2
0
corr2
0
freq2
100e6
if_gain2
20
gain2
10
ant30
bb_gain30
20
bw30
0
corr30
0
freq30
100e6
if_gain30
20
gain30
10
ant31
bb_gain31
20
bw31
0
corr31
0
freq31
100e6
if_gain31
20
gain31
10
ant3
bb_gain3
20
bw3
0
corr3
0
freq3
100e6
if_gain3
20
gain3
10
ant4
bb_gain4
20
bw4
0
corr4
0
freq4
100e6
if_gain4
20
gain4
10
ant5
bb_gain5
20
bw5
0
corr5
0
freq5
100e6
if_gain5
20
gain5
10
ant6
bb_gain6
20
bw6
0
corr6
0
freq6
100e6
if_gain6
20
gain6
10
ant7
bb_gain7
20
bw7
0
corr7
0
freq7
100e6
if_gain7
20
gain7
10
ant8
bb_gain8
20
bw8
0
corr8
0
freq8
100e6
if_gain8
20
gain8
10
ant9
bb_gain9
20
bw9
0
corr9
0
freq9
100e6
if_gain9
20
gain9
10
comment
affinity
args
_enabled
1
_coordinate
(912, 513)
_rotation
0
id
osmosdr_sink_0
type
fc32
clock_source0
time_source0
clock_source1
time_source1
clock_source2
time_source2
clock_source3
time_source3
clock_source4
time_source4
clock_source5
time_source5
clock_source6
time_source6
clock_source7
time_source7
nchan
1
num_mboards
1
sample_rate
samp_rate
sync
qtgui_sink_x
bw
samp_rate
alias
fc
carrier_freq
freqchangevar
None
comment
affinity
_enabled
1
fftsize
1024
_coordinate
(920, 255)
gui_hint
0, 0, 1, 1
_rotation
0
id
qtgui_sink_x_0
maxoutbuf
0
minoutbuf
0
name
""
plotconst
True
plotfreq
True
plottime
True
plotwaterfall
True
showports
True
showrf
True
type
complex
rate
10
wintype
firdes.WIN_BLACKMAN_hARRIS
qtgui_time_sink_x
autoscale
False
alias
comment
ctrlpanel
True
affinity
entags
True
_enabled
1
_coordinate
(920, 366)
gui_hint
1, 0, 1, 1
_rotation
0
grid
False
id
qtgui_time_sink_x_0
legend
True
alpha1
1.0
color1
"blue"
label1
marker1
-1
style1
1
width1
1
alpha10
1.0
color10
"blue"
label10
marker10
-1
style10
1
width10
1
alpha2
1.0
color2
"red"
label2
marker2
-1
style2
1
width2
1
alpha3
1.0
color3
"green"
label3
marker3
-1
style3
1
width3
1
alpha4
1.0
color4
"black"
label4
marker4
-1
style4
1
width4
1
alpha5
1.0
color5
"cyan"
label5
marker5
-1
style5
1
width5
1
alpha6
1.0
color6
"magenta"
label6
marker6
-1
style6
1
width6
1
alpha7
1.0
color7
"yellow"
label7
marker7
-1
style7
1
width7
1
alpha8
1.0
color8
"dark red"
label8
marker8
-1
style8
1
width8
1
alpha9
1.0
color9
"dark green"
label9
marker9
-1
style9
1
width9
1
name
""
nconnections
1
size
1024
srate
samp_rate
tr_chan
0
tr_delay
0
tr_level
0.0
tr_mode
qtgui.TRIG_MODE_FREE
tr_slope
qtgui.TRIG_SLOPE_POS
tr_tag
""
type
complex
update_time
0.10
ylabel
Amplitude
yunit
""
ymax
1
ymin
-1
rational_resampler_xxx
alias
comment
affinity
decim
1
_enabled
1
fbw
4
_coordinate
(56, 383)
_rotation
0
id
rational_resampler_xxx_0
interp
samples_per_symbol / 4
maxoutbuf
0
minoutbuf
0
taps
1
type
fff
blocks_float_to_complex_0
blocks_throttle_0
0
0
blocks_float_to_complex_0
osmosdr_sink_0
0
0
blocks_float_to_complex_0
qtgui_sink_x_0
0
0
blocks_float_to_complex_0
qtgui_time_sink_x_0
0
0
blocks_moving_average_xx_0
blocks_multiply_const_vxx_0
0
0
blocks_multiply_const_vxx_0
blocks_float_to_complex_0
0
0
blocks_throttle_0
qtgui_sink_x_0
0
0
blocks_throttle_0
qtgui_time_sink_x_0
0
0
blocks_uchar_to_float_0
rational_resampler_xxx_0
0
0
blocks_unpack_k_bits_bb_0
blocks_uchar_to_float_0
0
0
digital_map_bb_0
blocks_unpack_k_bits_bb_0
0
0
gen_packets
digital_map_bb_0
0
0
rational_resampler_xxx_0
blocks_moving_average_xx_0
0
0