From 0ed0bd98ebd19771c69913de0e03ed7be1c73706 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 3 Apr 2015 22:38:53 +0200 Subject: [PATCH] FMS and ZVEI validation insert FMS validation edit ZVEI validation --- README.md | 5 +++-- boswatch.py | 50 +++++++++++++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index fe3789d..4a1d8e2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Python Script to Recive and Decode BOS Information with rtl_fm ans multimon-NG #####Implementeted Features: - FMS and ZVEI decoding and Displaying - Filtering double alarms with adjustable time -- ZVEI validation (plausibility test) +- FMS and ZVEI validation (plausibility test) - MySQL Database Support for FMS and ZVEI - All configurations in seperate File "config.ini" - simple Web Frontend @@ -51,7 +51,8 @@ optional arguments: Device you want to use (Check with rtl_test) -e ERROR, --error ERROR Frequency-Error of your Device in PPM - -a {FMS,ZVEI,POC512,POC1200,POC2400} [{FMS,ZVEI,POC512,POC1200,POC2400} ...], --demod {FMS,ZVEI,POC512,POC1200,POC2400} [{FMS,ZVEI,POC512,POC1200,POC2400} ...] + -a {FMS,ZVEI,POC512,POC1200,POC2400} [{FMS,ZVEI,POC512,POC1200,POC2400} ...], + --demod {FMS,ZVEI,POC512,POC1200,POC2400} [{FMS,ZVEI,POC512,POC1200,POC2400} ...] Demodulation Functions -s SQUELCH, --squelch SQUELCH Level of Squelch diff --git a/boswatch.py b/boswatch.py index 151d554..92f6393 100644 --- a/boswatch.py +++ b/boswatch.py @@ -23,6 +23,7 @@ def curtime(format="%Y-%m-%d %H:%M:%S"): return time.strftime(format) def stop_script(err): + print "" print "ERR: "+err try: if useMySQL: #only if MySQL is active @@ -165,7 +166,8 @@ try: exit(0) - if args.verbose: print "start decoding" + if args.verbose: print "start decoding" + print "" while True: #RAW Data from Multimon-NG #ZVEI2: 25832 @@ -178,6 +180,7 @@ try: #if args.verbose: print "RAW: "+decoded #for verbose mode, print Raw input data #FMS Decoder Section + #check FMS: -> check CRC -> validate -> check double alarm -> print -> (MySQL) if "FMS:" in decoded: if args.verbose: print "recived FMS" @@ -189,34 +192,35 @@ try: fms_direction = decoded[101] #Richtung fms_tsi = decoded[114:117] #Taktische Kruzinformation - if "CRC correct" in decoded: #check CRC is correct + if "CRC correct" in decoded: #check CRC is correct fms_id = fms_service+fms_country+fms_location+fms_vehicle+fms_status+fms_direction #build FMS id - if fms_id == fms_id_old and timestamp < fms_time_old + fms_double_ignore_time: #check for double alarm - if args.verbose: print "FMS double alarm: "+fms_id_old - fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new - else: - print curtime("%H:%M:%S")+" BOS:"+fms_service+" Bundesland:"+fms_country+" Ort:"+fms_location+" Fahrzeug:"+fms_vehicle+" Status:"+fms_status+" Richtung:"+fms_direction+" TKI:"+fms_tsi - fms_id_old = fms_id #save last id - fms_time_old = timestamp #save last time - - if useMySQL: #only if MySQL is active - cursor = connection.cursor() - cursor.execute("INSERT INTO "+tableFMS+" (time,service,country,location,vehicle,status,direction,tsi) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",(curtime(),fms_service,fms_country,fms_location,fms_vehicle,fms_status,fms_direction,fms_tsi)) - cursor.close() - connection.commit() - + if re.search("[0-9]{8}[0-9a-f]{1}[01]{1}", fms_id): #if FMS is valid + if fms_id == fms_id_old and timestamp < fms_time_old + fms_double_ignore_time: #check for double alarm + if args.verbose: print "FMS double alarm: "+fms_id_old + fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new + else: + print curtime("%H:%M:%S")+" BOS:"+fms_service+" Bundesland:"+fms_country+" Ort:"+fms_location+" Fahrzeug:"+fms_vehicle+" Status:"+fms_status+" Richtung:"+fms_direction+" TKI:"+fms_tsi + fms_id_old = fms_id #save last id + fms_time_old = timestamp #save last time + + if useMySQL: #only if MySQL is active + cursor = connection.cursor() + cursor.execute("INSERT INTO "+tableFMS+" (time,service,country,location,vehicle,status,direction,tsi) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",(curtime(),fms_service,fms_country,fms_location,fms_vehicle,fms_status,fms_direction,fms_tsi)) + cursor.close() + connection.commit() + elif args.verbose: #Invalid error only in verbose mode + print "No valid FMS: "+fms_id elif args.verbose: #crc error only in verbose mode - print "CRC error" + print "CRC incorrect" - #ZVEI Decoder Section + #ZVEI Decoder Section + #check ZVEI: -> validate -> check double alarm -> print -> (MySQL) if "ZVEI2:" in decoded: if args.verbose: print "recived ZVEI" - #ZVEI RegEX Pattern: http://www.regexr.com/3ao2u - zvei = re.search("[0-9F]{5}", decoded) - if zvei: #if ZVEI is valid - zvei_id = zvei.group() #save ZVEI in working var + zvei_id = decoded[7:12] #ZVEI Code + if re.search("[0-9F]{5}", zvei_id): #if ZVEI is valid if zvei_id == zvei_id_old and timestamp < zvei_time_old + zvei_double_ignore_time: #check for double alarm if args.verbose: print "ZVEI double alarm: "+zvei_id_old zvei_time_old = timestamp #in case of double alarm, zvei_double_ignore_time set new @@ -232,7 +236,7 @@ try: connection.commit() elif args.verbose: #Invalid error only in verbose mode - print "No valid ZVEI: "+decoded + print "No valid ZVEI: "+zvei_id except KeyboardInterrupt: