-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_3.py
52 lines (44 loc) · 2.19 KB
/
backup_3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Embedded Python Blocks:
Each time 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 numpy as np
from gnuradio import gr
class blk(gr.sync_block): # other base classes are basic_block, decim_block, interp_block
"""Embedded Python Block Remover - separetes the data by only passing the counter length samples to output 1, otherwise pass zeros.
Output 1 - Packet Counter
Output 2 - Data """
def __init__(self, counter_length=1.0, payload_length=1.0): # only default arguments here
"""arguments to this function show up as parameters in GRC"""
gr.sync_block.__init__(
self,
name='Split Packet Counter', # will show up in GRC
in_sig=[np.int8],
out_sig=[np.int8,np.int8]
)
# if an attribute with the same name as a parameter is found,
# a callback is registered (properties work, too).
self.counter_length = counter_length
self.payload_length = payload_length
self.last_run_position = 0
self.offset_position = 0
self.data_period = (self.payload_length+self.counter_length)
def work(self, input_items, output_items):
# """example: multiply with constant"""
#when loop counter resets work funtion is called again
input_len = len(input_items[0]);
self.offset_position = self.last_run_position # offset of the samples from last run
print('offset run ->{}' .format(self.offset_position))
print('Input -> {}' .format(input_len))
for i in range(0,input_len):
if (i+1+self.offset_position) % self.data_period == 0:
output_items[0][i] = input_items[0][i]
output_items[1][i] = 43 # prints + on the data stream
self.last_run_position = input_len-(i+1)# stores last correct relative index before counter reset
print('Packet Counter -> {}' .format(input_items[0][i]))
else:
output_items[0][i] = 43 # prints + on the counter stream
output_items[1][i] = input_items[0][i]
return len(output_items[0])