From 08872c2b2f02f97a92e3f1e9c153c2578c5b4c01 Mon Sep 17 00:00:00 2001 From: csrichter Date: Mon, 20 Feb 2017 17:09:22 +0100 Subject: [PATCH] fft-multi-decoder fixed and auto-freq with 9 decoders, decoder_compare block --- grc/CMakeLists.txt | 3 +- grc/crfa_decoder_compare.xml | 28 +++++++++++++++ grc/crfa_rds_parser_table_qt.xml | 2 +- grc/crfa_vector_cutter.xml | 1 - lib/rds_decoder_impl.cc | 2 +- python/CMakeLists.txt | 3 +- python/__init__.py | 1 + python/decoder_compare.py | 62 ++++++++++++++++++++++++++++++++ python/max_freq.py | 18 +++++----- python/rds_parser_table_qt.py | 1 + 10 files changed, 106 insertions(+), 15 deletions(-) create mode 100644 grc/crfa_decoder_compare.xml create mode 100644 python/decoder_compare.py diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index 724310f..203134f 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -25,5 +25,6 @@ install(FILES crfa_max_freq.xml crfa_smooth_vectors.xml crfa_stream_selector.xml - crfa_vector_cutter.xml DESTINATION share/gnuradio/grc/blocks + crfa_vector_cutter.xml + crfa_decoder_compare.xml DESTINATION share/gnuradio/grc/blocks ) diff --git a/grc/crfa_decoder_compare.xml b/grc/crfa_decoder_compare.xml new file mode 100644 index 0000000..bdf2eaf --- /dev/null +++ b/grc/crfa_decoder_compare.xml @@ -0,0 +1,28 @@ + + + decoder_compare + crfa_decoder_compare + [crfa] + import crfa + crfa.decoder_compare($nPorts) + + + Number of Ports + nPorts + 2 + int + part + + + $nPorts > 0 + + in + message + $nPorts + + + diff --git a/grc/crfa_rds_parser_table_qt.xml b/grc/crfa_rds_parser_table_qt.xml index eda70e9..075896a 100644 --- a/grc/crfa_rds_parser_table_qt.xml +++ b/grc/crfa_rds_parser_table_qt.xml @@ -125,7 +125,7 @@ check if pty list file exists $nPorts - + freq message 1 diff --git a/grc/crfa_vector_cutter.xml b/grc/crfa_vector_cutter.xml index 63f6dec..a433454 100644 --- a/grc/crfa_vector_cutter.xml +++ b/grc/crfa_vector_cutter.xml @@ -71,7 +71,6 @@ complex $insize - out complex diff --git a/lib/rds_decoder_impl.cc b/lib/rds_decoder_impl.cc index ee51394..259d287 100644 --- a/lib/rds_decoder_impl.cc +++ b/lib/rds_decoder_impl.cc @@ -110,7 +110,7 @@ unsigned int rds_decoder_impl::calc_syndrome(unsigned long message, void rds_decoder_impl::decode_group(unsigned int *group) { // raw data bytes, as received from RDS. // 8 info bytes, followed by 4 RDS offset chars: ABCD/ABcD/EEEE (in US) - unsigned char bytes[12]; + unsigned char bytes[13]; // RDS information words bytes[0] = (group[0] >> 8U) & 0xffU; diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 3b2bd3e..ad66a93 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -39,7 +39,8 @@ GR_PYTHON_INSTALL( smooth_vectors.py chart.py stream_selector.py - vector_cutter.py DESTINATION ${GR_PYTHON_DIR}/crfa + vector_cutter.py + decoder_compare.py DESTINATION ${GR_PYTHON_DIR}/crfa ) ######################################################################## diff --git a/python/__init__.py b/python/__init__.py index 9ed1cda..e9a4272 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -40,4 +40,5 @@ from smooth_vectors import smooth_vectors from chart import Chart from stream_selector import stream_selector from vector_cutter import vector_cutter +from decoder_compare import decoder_compare # diff --git a/python/decoder_compare.py b/python/decoder_compare.py new file mode 100644 index 0000000..2f1d8c5 --- /dev/null +++ b/python/decoder_compare.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2017 <+YOU OR YOUR COMPANY+>. +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import numpy +from gnuradio import gr +import pmt,functools,time + +class decoder_compare(gr.sync_block): + """ + docstring for block decoder_compare + """ + def __init__(self, nPorts=2): + gr.sync_block.__init__(self, + name="decoder_compare", + in_sig=None, + out_sig=None) + if nPorts==1: + self.message_port_register_in(pmt.intern('in')) + self.set_msg_handler(pmt.intern('in'), functools.partial(self.handle_msg, port=0)) + else: + for i in range(nPorts): + self.message_port_register_in(pmt.intern('in%d'%i)) + self.set_msg_handler(pmt.intern('in%d'%i), functools.partial(self.handle_msg, port=i)) + self.nPorts=nPorts + self.synced=[False]*nPorts + self.numErrors=[0]*nPorts + self.numPackets=[0]*nPorts + self.printTime=time.time() + def handle_msg(self,msg,port): + #print("port:%i, msg:%s"%(port,pmt.to_python(msg))) + if pmt.to_long(pmt.car(msg))==1L: + data=pmt.to_python(pmt.cdr(msg)) + #print("port:%i, data: %s"%(port,data)) + self.synced[port]=data + print("errors:%s,Packets:%s, sync:%s"%(self.numErrors,self.numPackets,self.synced)) + else: #elif pmt.to_long(pmt.car(msg))==0L + array=pmt.to_python(msg)[1] + self.numErrors[port]=array[12] + self.numPackets[port]+=1 + if time.time()-self.printTime>2:#max every 2 sec + print("errors:%s,Packets:%s, sync:%s"%(self.numErrors,self.numPackets,self.synced)) + self.printTime=time.time() + self.numPackets=[0]*self.nPorts + diff --git a/python/max_freq.py b/python/max_freq.py index 763f70e..ac1467a 100644 --- a/python/max_freq.py +++ b/python/max_freq.py @@ -21,7 +21,7 @@ import numpy as np from gnuradio import gr -import code,math,pmt +import code,math,pmt,time class max_freq(gr.sync_block): """ @@ -40,10 +40,10 @@ class max_freq(gr.sync_block): self.debug=debug self.last_station_indices=[0]*self.num_decoders self.message_port_register_out(pmt.intern('out')) - self.counter=0 + self.timer=time.time() self.message_port_register_in(pmt.intern('ctrl')) self.set_msg_handler(pmt.intern('ctrl'), self.handle_ctrl_msg) - self.searchMode=True + self.searchMode=False self.index_fixed=[False]*self.num_decoders def freq_to_index(self,freq): startfreq=self.center_freq-self.samp_rate/2 @@ -85,11 +85,9 @@ class max_freq(gr.sync_block): else: self.center_freq = int(freq) def work(self, input_items, output_items): - if self.counter<5: - self.counter+=1 + if time.time()-self.timer<1:#every 1 seconds return len(input_items[0]) elif self.searchMode: - self.counter=0 #in0 = input_items[0] #ii=input_items carrier_width=2 @@ -184,10 +182,10 @@ class max_freq(gr.sync_block): send_pmt = pmt.string_to_symbol(msg_string) self.message_port_pub(pmt.intern('out'), send_pmt) if self.debug: - print(max_indices) - print(station_indices_sorted) - print(station_indices_tune) - print(station_strength) + #print(max_indices) + #print(station_indices_sorted) + #print(station_indices_tune) + #print(station_strength) print(station_freqs) return len(input_items[0]) diff --git a/python/rds_parser_table_qt.py b/python/rds_parser_table_qt.py index 11c71d9..1ace89a 100644 --- a/python/rds_parser_table_qt.py +++ b/python/rds_parser_table_qt.py @@ -1024,6 +1024,7 @@ class rds_parser_table_qt(gr.sync_block):#START #249 1111 1001 = 25AF fillercode=205#1100 1101 if not self.RDS_data[PI]["AF"].has_key("main") and self.RDS_data[PI].has_key("tuned_freq"): + #if self.RDS_data[PI].has_key("tuned_freq"):#update main freq even if one exists -> DB problem freq=self.decode_AF_freq(array[4]) if freq==self.RDS_data[PI]["tuned_freq"]: self.RDS_data[PI]["AF"]["main"]=freq