-
Notifications
You must be signed in to change notification settings - Fork 0
/
receive_ook2bin.py
160 lines (124 loc) · 5.06 KB
/
receive_ook2bin.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"""
Embedded Python Blocks:
Each this file is saved, GRC will instantiate the first class it finds to get в секунде миллион микросекунд т.е делитель 2
ports and parameters of your block. The arguments to __init__ will be the
parameters. All of them are required to have default values!
"""
import time
import numpy as np
from gnuradio import gr
from datetime import datetime
class blk (gr.sync_block):
"""
Block to decode the data on an already squared signal, comprised of 0's and 1's.
"""
def __init__ (self
, baseband_freq = 600
, sample_rate = 2e6
, sink_file = None): # only default arguments here
"""
Constructor.
Args:
baseband_freq -> Frequency of the baseband signal
sample_rate -> Number of samples per second
sink_file -> File to dump the packets. If it's 'None', prints them on STDOUT
"""
gr.sync_block.__init__(
self,
name = 'OOK to bin sink',
in_sig = [np.float32],
out_sig = []
)
# Number of samples to discern long and short bursts
# sample_rate / baseband_freq = samples_per_period
self.threshold = (sample_rate / baseband_freq) / 2
self.sink_file = sink_file
self.time_delta = 0 # Timer to measure the time between edges
self.rising_timestamps = []
self.falling_timestamps = []
self.previous_sample = 0 #posl sig rx
self.lastRxValue = 1
self.Rxpin = 0 #posl sig rx
# Counter to determine the end of a packet. If more than (2 * threshold) samples
# are set to 0, the packet is done
self.allzero_count = 0
self.starline_counter_pre = 0
self.starline_counter = 0
self.staline_state = 0
self.bValidPacket=False
self.lastRxTime=0
self.lastRx=0
self.difTime=0
self.tempTime=0
self.packet = [] # List to store the bits of the packet
self.starline_code= [0,0,0,0,0,0,0,0]
self.state = 0
self.sym_count = 0
self.bit_count = 0
self.byte = 0
self.sym = 0
self.packet = []
self.dt = datetime.now()
self.mic=self.dt.microsecond
def reset_state(self):
self.state = 0
self.sym_count = 0
self.bit_count = 0
self.byte = 0
self.sym = 0
self.packet = []
def decodestarline (self) :
if (self.difTime >900*2 and self.difTime <1100*2 and self.staline_state ==0 and self.lastRx==1):
#print("starline preambule")
self.starline_counter_pre +=1
if self.starline_counter_pre == 6:
print("starline preambule")
self.staline_state = 1
# print(self.difTime)
# preambule good
elif (self.staline_state==1):
if (self.difTime >350*2 and self.difTime <650*2 and self.lastRx==1):
self.packet.append ("0")
self.bValidPacket = True
elif (self.difTime >150*2 and self.difTime <350*2 and self.lastRx==1):
self.packet.append ("1")
self.bValidPacket = True
else:
self.staline_state = 1
self.starline_counter=0
if(self.bValidPacket ==True):
self.starline_counter+=1
# print(self.starline_counter)
if(self.starline_counter==64):
print("getcode")
self.starline_counter=0
self.staline_state=0
self.time_delta=0
self.starline_counter_pre=0
#bin_strstar = str (self.packet)
# print(self.packet)
print(self.packet)
self.packet = []
def work (self, input_items, *args, **kwargs):
samples = input_items [0]
in0 = input_items[0]
processed = 0
for i in range(0, len(input_items[0])):
self.time_delta += 1
self.Rxpin=round(input_items[0][i])
if(self.Rxpin!=self.lastRx):
self.tempTime=self.time_delta
self.difTime=self.tempTime-self.lastRxTime
# print(self.difTime)
self.decodestarline()
self.lastRxTime=self.tempTime
self.lastRx=self.Rxpin
# for sym in in0:
# print(in0)
#self.time_delta += len (samples)
# if self.time_delta>1000000 and self.time_delta<2000005:
# print(self.time_delta)
# print(self.Rxpin)
#self.consume(0, len(input_items[0])) ///uvelichivaet kakto v hz
#print(self.time_delta)
return len (samples)