diff --git a/gr_grc/scripts/show_enocean_telegram_from_file.py b/gr_grc/scripts/show_enocean_telegram_from_file.py new file mode 100644 index 0000000000000000000000000000000000000000..44b7e1228ca95ddcb8d01991750b54070aa3c14a --- /dev/null +++ b/gr_grc/scripts/show_enocean_telegram_from_file.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python2.7 +# -*- encoding: utf-8 -*- + +import numpy as np +import sys +import re + +data = np.memmap(open(sys.argv[1]), mode="r", dtype=np.float32) + +string = "" +messages = [] +for i, val in enumerate(data): + string += str(int(val)) + + if i%1000 == 0: + if re.search(r"[1]{6,7}[0]{1,2}", string): + messages.append(string) + elif re.search(r"[1]{5,6}[0]{6,7}", string): + messages.append(string) + + string = "" + +for i in messages: + print(i) diff --git a/gr_grc/scripts/show_live_transmissions.py b/gr_grc/scripts/show_live_transmissions.py new file mode 100644 index 0000000000000000000000000000000000000000..81b9247c5ab6c068897255982433cfda59c72d03 --- /dev/null +++ b/gr_grc/scripts/show_live_transmissions.py @@ -0,0 +1,148 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +################################################## +# GNU Radio Python Flow Graph +# Title: Top Block +# Generated: Wed Feb 17 15:45:00 2016 +################################################## + +from gnuradio import blocks +from gnuradio import eng_notation +from gnuradio import filter +from gnuradio import gr +from gnuradio.eng_option import eng_option +from gnuradio.filter import firdes +from optparse import OptionParser + +import osmosdr + +import numpy as np +import time + + +class top_block(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self, "Top Block") + + ################################################## + # Variables + ################################################## + self.cutoff_freq = cutoff_freq = 4e5 + self.transition_width = transition_width = cutoff_freq/2 + self.samp_rate = samp_rate = 2e6 + self.freq = freq = 868e6 + + ################################################## + # Message Queues + ################################################## + # Queue + self.msgq_out = blocks_message_sink_0_msgq_out = gr.msg_queue(0) + + ################################################## + # Blocks + ################################################## + self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" ) + self.osmosdr_source_0.set_sample_rate(samp_rate) + self.osmosdr_source_0.set_center_freq(freq, 0) + self.osmosdr_source_0.set_freq_corr(0, 0) + self.osmosdr_source_0.set_dc_offset_mode(0, 0) + self.osmosdr_source_0.set_iq_balance_mode(0, 0) + self.osmosdr_source_0.set_gain_mode(False, 0) + self.osmosdr_source_0.set_gain(10, 0) + self.osmosdr_source_0.set_if_gain(20, 0) + self.osmosdr_source_0.set_bb_gain(20, 0) + self.osmosdr_source_0.set_antenna("", 0) + self.osmosdr_source_0.set_bandwidth(0, 0) + + self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(1, (firdes.low_pass(1, samp_rate, transition_width, cutoff_freq, firdes.WIN_HAMMING, 6.76)), 3.5e5, samp_rate) + self.blocks_threshold_ff_0 = blocks.threshold_ff(0.00686, 0.00686, 0) + self.blocks_message_sink_0 = blocks.message_sink(gr.sizeof_float*1, blocks_message_sink_0_msgq_out, False) + self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) + + ################################################## + # Connections + ################################################## + self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_threshold_ff_0, 0)) + self.connect((self.blocks_threshold_ff_0, 0), (self.blocks_message_sink_0, 0)) + self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) + self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) + + def get_cutoff_freq(self): + return self.cutoff_freq + + def set_cutoff_freq(self, cutoff_freq): + self.cutoff_freq = cutoff_freq + self.set_transition_width(self.cutoff_freq/2) + self.freq_xlating_fir_filter_xxx_0.set_taps((firdes.low_pass(1, self.samp_rate, self.transition_width, self.cutoff_freq, firdes.WIN_HAMMING, 6.76))) + + def get_transition_width(self): + return self.transition_width + + def set_transition_width(self, transition_width): + self.transition_width = transition_width + self.freq_xlating_fir_filter_xxx_0.set_taps((firdes.low_pass(1, self.samp_rate, self.transition_width, self.cutoff_freq, firdes.WIN_HAMMING, 6.76))) + + def get_samp_rate(self): + return self.samp_rate + + def set_samp_rate(self, samp_rate): + self.samp_rate = samp_rate + self.freq_xlating_fir_filter_xxx_0.set_taps((firdes.low_pass(1, self.samp_rate, self.transition_width, self.cutoff_freq, firdes.WIN_HAMMING, 6.76))) + self.osmosdr_source_0.set_sample_rate(self.samp_rate) + + def get_freq(self): + return self.freq + + def set_freq(self, freq): + self.freq = freq + self.osmosdr_source_0.set_center_freq(self.freq, 0) + + +def main(top_block_cls=top_block, options=None): + tb = top_block_cls() + tb.start() + + samples_count = 0 + messages = [] + time_added = 0 + samples_len = 0 + while True: + msg = tb.msgq_out.delete_head() + samples = np.fromstring(msg.to_string(), dtype='float32') + samples_len = len(samples) + + if np.count_nonzero(samples) != 0: + string = "" + for i in samples: + string += str(int(i)) + + if len(messages) == 0: + block_samples_start = samples_count + + messages.append(string) + time_added = time.time() + + if time_added != 0 and (time.time()-time_added) > 0.5 : + msg = "".join(messages) + transmission_time = round(1/tb.samp_rate*(int(msg.count("1"))*1000), 2) + first_one = msg.index("1") + last_one = msg.rfind("1") + real_transmission_time = round(1/tb.samp_rate*(int(last_one-first_one)*1000), 2) + + print(msg) + print("Transmission time: \t\t" + str(transmission_time) + "ms") + print("Real transmission time: \t" + str(real_transmission_time) + "ms\n") + print("Transmission block starts at sample: \t" + str(block_samples_start)) + print("Transmission starts at sample: \t\t" + str(block_samples_start + first_one)) + print("Sample count: \t\t\t\t" + str(samples_count)) + print("\n\n") + + messages = [] + block_samples_start = 0 + time_added = 0 + + samples_count += samples_len + +if __name__ == '__main__': + main()