Browse Source

added mutex to lcl_dict and made matchFilter method static

dev
Clemens Richter 9 years ago
parent
commit
193753e0e5
  1. 8
      python/rds_parser_table_qt.py
  2. 47
      python/tmc_classes.py
  3. 25
      python/tmc_parser.py

8
python/rds_parser_table_qt.py

@ -18,18 +18,19 @@
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from __future__ import print_function#print without newline print('.', end="")
import numpy
from gnuradio import gr
import pmt,functools,csv,md5,collections,copy,sqlite3,atexit,time,re,sys
#old imports: folium
from datetime import datetime
from datetime import timedelta
import multirds.chart as chart
from multirds.tmc_classes import tmc_dict,tmc_message,language
from multirds.tmc_classes import language
from PyQt4 import Qt, QtCore, QtGui
import pprint,code,pickle#for easier testing
import pprint,code
pp = pprint.PrettyPrinter()
import cProfile, pstats, StringIO #for profiling
pr = cProfile.Profile()
@ -95,7 +96,6 @@ class rds_parser_table_qt(gr.sync_block):#START
self.colorder=['ID','freq','name','buttons','PTY','AF','time','text','quality','pilot_SNR','RT+']
self.workdir=workdir
self.PI_dict={}#contains PI:numpackets (string:integer)
self.tmc_messages=tmc_dict()
if self.writeDB:
#create new DB file

47
python/tmc_classes.py

@ -584,8 +584,30 @@ class tmc_dict:
def __init__(self):
self.messages={}
self.message_list=[]
self.dict_lock=threading.Lock()
self.list_lock=threading.Lock()
@staticmethod
def matchFilter(msg,filters):
if not msg.location.is_valid:
return True#always show invalid messages
loc_str=str(msg.location)+str(msg.location.reflocs)
if not msg.location.linRef==None:
loc_str+=str(msg.location.linRef.roadnumber)
for f in filters:#filters is list of dicts {"type":"event","str":"Stau"}
stringlist=f["str"].lower().split(";")
for string in stringlist:
if f["type"]=="event" and unicode(str(msg.event), encoding="UTF-8").lower().find(string)==-1:#if event filter does not match
return False
elif f["type"]=="location" and unicode(loc_str, encoding="UTF-8").lower().find(string)==-1:#if location filter does not match
return False
return True
def add(self,message):
self.list_lock.acquire()
self.message_list.append(message)
self.list_lock.release()
self.dict_lock.acquire()
try:
lcn=message.location.lcn
updateClass=message.event.updateClass
@ -605,33 +627,22 @@ class tmc_dict:
#print("added message: "+str(message))
except AttributeError:
print("ERROR, not adding: "+str(message))
def matchFilter(self,msg,filters):
if not msg.location.is_valid:
return True#always show invalid messages
loc_str=str(msg.location)+str(msg.location.reflocs)
if not msg.location.linRef==None:
loc_str+=str(msg.location.linRef.roadnumber)
for f in filters:#filters is list of dicts {"type":"event","str":"Stau"}
stringlist=f["str"].lower().split(";")
for string in stringlist:
if f["type"]=="event" and unicode(str(msg.event), encoding="UTF-8").lower().find(string)==-1:#if event filter does not match
return False
elif f["type"]=="location" and unicode(loc_str, encoding="UTF-8").lower().find(string)==-1:#if location filter does not match
return False
return True
finally:
self.dict_lock.release()
def getLogString(self,filters):
self.list_lock.acquire()
retStr=""
for message in self.message_list:
if self.matchFilter(message,filters):
if tmc_dict.matchFilter(message,filters):
retStr+=message.log_string()
retStr+="\n"
retStr+=message.multi_str()
retStr+="\n"
self.list_lock.release()
return retStr
def getMarkerString(self):
markerstring=""
self.dict_lock.acquire()
try:
for lcn in self.messages:
loc=None
@ -665,6 +676,8 @@ class tmc_dict:
print(e)
code.interact(local=locals())
pass
finally:
self.dict_lock.release()
return markerstring

25
python/tmc_parser.py

@ -18,6 +18,7 @@
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from __future__ import print_function#print without newline print('.', end="")
import numpy
from gnuradio import gr
@ -29,6 +30,7 @@ from multirds.tmc_classes import tmc_dict,tmc_message,language,lcl
from datetime import datetime
from datetime import timedelta
class tmc_parser(gr.sync_block):
"""
docstring for block tmc_parser
@ -119,8 +121,7 @@ class tmc_parser(gr.sync_block):
self.qtwidget.print_tmc_msg(tmc_msg)
#if self.debug:
# print("new tmc message %s"%tmc_msg)
def initialize_data_for_PI(self,PI):
self.unfinished_messages[PI]={}
def handle_msg(self,msg):
if time.time()-self.save_data_timer > 3:#every 3 seconds
self.save_data_timer=time.time()
@ -128,12 +129,10 @@ class tmc_parser(gr.sync_block):
m=pmt.to_python(msg)
PI=m["PI"]
if not self.unfinished_messages.has_key(PI):
self.initialize_data_for_PI(PI)
self.unfinished_messages[PI]={}
if m["type"]=="3A_meta":
self.tmc_meta[PI]=m["data"]
elif m["type"]=="alert-c":
#self.qtwidget.updateui()
#print(m)
psn=m["PSN"]
try:
ltn=self.tmc_meta[PI]["LTN"]
@ -257,27 +256,35 @@ class tmc_parser(gr.sync_block):
class tmc_parser_Widget(QtGui.QWidget):
def print_tmc_msg(self,tmc_msg):
self.logMutex.acquire(1)
print("got mutex,",end="")
sb=self.logOutput.verticalScrollBar()
print(".",end="")
oldmax=sb.maximum()
print(".",end="")
auto_scroll= abs(oldmax-sb.value())<60#auto_scroll if scrollbar was at max
print(".",end="")
#print("%i %i %r"%(sb.maximum(),sb.value(),auto_scroll))
ef=unicode(self.event_filter.text().toUtf8(), encoding="UTF-8").lower()
lf=unicode(self.location_filter.text().toUtf8(), encoding="UTF-8").lower()
filters=[{"type":"location", "str":lf},{"type":"event", "str":ef}]
if self.parser.tmc_messages.matchFilter(tmc_msg,filters):
if tmc_dict.matchFilter(tmc_msg,filters):
print("a",end="")
self.logOutput.append(Qt.QString.fromUtf8(tmc_msg.log_string()))
print("a",end="")
self.logOutput.append(Qt.QString.fromUtf8(tmc_msg.multi_str()))
print("a",end="")
#print("new message")
if auto_scroll:
sb=self.logOutput.verticalScrollBar()
#sb=self.logOutput.verticalScrollBar() #disabled 2017-04-28 might be cause of double free
new_max=sb.maximum()
print("s",end="")
sb.setValue(new_max)
print("s",end="")
print("\tdone")
# code.interact(local=locals())
#print("scrolling %i %i %r"%(oldmax,new_max,sb.value()))
#code.interact(local=locals())
self.logMutex.release(1)
def updateui(self):
print("updating ui")
def filterChanged(self):
self.logMutex.acquire(1)
self.parser.isDone=False

Loading…
Cancel
Save