From 5b70a45f2a314d4d045bd7f964a9dd880abe7ea6 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 28 Apr 2015 15:40:54 +0200 Subject: [PATCH 1/3] pocsag regex validation --- boswatch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boswatch.py b/boswatch.py index c2793c8..302541a 100644 --- a/boswatch.py +++ b/boswatch.py @@ -342,7 +342,7 @@ try: else: poc_text = "" - if len(poc_id) == 7: #if POC is valid + if re.search("[0-9]{7}", poc_id): #if POC is valid if poc_id >= poc_filter_range_start: if poc_id >= poc_filter_range_start: if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm @@ -400,7 +400,7 @@ try: else: poc_text = "" - if len(poc_id) == 7: #if POC is valid + if re.search("[0-9]{7}", poc_id): #if POC is valid if poc_id >= poc_filter_range_start: if poc_id >= poc_filter_range_start: if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm From 745984e45b33899bb311926283e46deaaebbc63f Mon Sep 17 00:00:00 2001 From: Schrolli Date: Tue, 28 Apr 2015 15:43:47 +0200 Subject: [PATCH 2/3] better error handling, except in clean-up routine --- boswatch.py | 75 ++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/boswatch.py b/boswatch.py index 302541a..5f7d8b1 100644 --- a/boswatch.py +++ b/boswatch.py @@ -40,39 +40,38 @@ def log(msg, level="log"): bos_log.close() # Programm - -#Clear the Logfiles try: - script_path = os.path.dirname(os.path.abspath(__file__)) - bos_log = open(script_path+"/log_bos.txt", "w") - rtl_log = open(script_path+"/log_rtl.txt", "w") - mon_log = open(script_path+"/log_mon.txt", "w") - bos_log.write("##### "+curtime()+" #####\n\n") - rtl_log.write("##### "+curtime()+" #####\n\n") - mon_log.write("##### "+curtime()+" #####\n\n") - bos_log.close() - rtl_log.close() - mon_log.close() -except: - log("cannot clear logfiles","error") -try: - #With -h or --help you get the Args help - #ArgsParser - parser = argparse.ArgumentParser(prog="boswatch.py", description="BOSWatch is a Python Script to Recive and Decode German BOS Information with rtl_fm and multimon-NG", epilog="More Options you can find in the extern config.ini File in this Folder") - #parser.add_argument("-c", "--channel", help="BOS Channel you want to listen") - parser.add_argument("-f", "--freq", help="Frequency you want to listen", required=True) - parser.add_argument("-d", "--device", help="Device you want to use (Check with rtl_test)", type=int, default=0) - parser.add_argument("-e", "--error", help="Frequency-Error of your Device in PPM", type=int, default=0) - parser.add_argument("-a", "--demod", help="Demodulation Functions", choices=['FMS', 'ZVEI', 'POC512', 'POC1200', 'POC2400'], required=True, nargs="+") - parser.add_argument("-s", "--squelch", help="Level of Squelch", type=int, default=0) - parser.add_argument("-v", "--verbose", help="Shows more Information", action="store_true") - parser.add_argument("-q", "--quiet", help="Shows no Information. Only Logfiles", action="store_true") - args = parser.parse_args() -except: - log("cannot parse Args","error") + #Clear the Logfiles + try: + script_path = os.path.dirname(os.path.abspath(__file__)) + bos_log = open(script_path+"/log_bos.txt", "w") + rtl_log = open(script_path+"/log_rtl.txt", "w") + mon_log = open(script_path+"/log_mon.txt", "w") + bos_log.write("##### "+curtime()+" #####\n\n") + rtl_log.write("##### "+curtime()+" #####\n\n") + mon_log.write("##### "+curtime()+" #####\n\n") + bos_log.close() + rtl_log.close() + mon_log.close() + except: + log("cannot clear logfiles","error") -try: + try: + #With -h or --help you get the Args help + #ArgsParser + parser = argparse.ArgumentParser(prog="boswatch.py", description="BOSWatch is a Python Script to Recive and Decode German BOS Information with rtl_fm and multimon-NG", epilog="More Options you can find in the extern config.ini File in this Folder") + #parser.add_argument("-c", "--channel", help="BOS Channel you want to listen") + parser.add_argument("-f", "--freq", help="Frequency you want to listen", required=True) + parser.add_argument("-d", "--device", help="Device you want to use (Check with rtl_test)", type=int, default=0) + parser.add_argument("-e", "--error", help="Frequency-Error of your Device in PPM", type=int, default=0) + parser.add_argument("-a", "--demod", help="Demodulation Functions", choices=['FMS', 'ZVEI', 'POC512', 'POC1200', 'POC2400'], required=True, nargs="+") + parser.add_argument("-s", "--squelch", help="Level of Squelch", type=int, default=0) + parser.add_argument("-v", "--verbose", help="Shows more Information", action="store_true") + parser.add_argument("-q", "--quiet", help="Shows no Information. Only Logfiles", action="store_true") + args = parser.parse_args() + except: + log("cannot parse Args","error") #Read Data from Args, Put it into working Variables freq = args.freq @@ -449,9 +448,13 @@ except KeyboardInterrupt: except: log("unknown Error","error") finally: - rtl_fm.terminate() - log("rtl_fm terminated") - multimon_ng.terminate() - log("multimon-ng terminated") - log("exiting BOSWatch") - exit(0) + try: + rtl_fm.terminate() + log("rtl_fm terminated") + multimon_ng.terminate() + log("multimon-ng terminated") + log("exiting BOSWatch") + except: + log("failed in clean-up routine","error") + finally: + exit(0) From e88fff0a3553496e49f82c76604daa265d39d32f Mon Sep 17 00:00:00 2001 From: Schrolli91 Date: Thu, 7 May 2015 22:04:39 +0200 Subject: [PATCH 3/3] Update boswatch.py --- boswatch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boswatch.py b/boswatch.py index 5f7d8b1..8f9de8d 100644 --- a/boswatch.py +++ b/boswatch.py @@ -339,7 +339,7 @@ try: if "Alpha:" in decoded: #check if there is a text message poc_text = decoded.split('Alpha: ')[1].strip().rstrip('').strip() else: - poc_text = "" + poc_text = "" if re.search("[0-9]{7}", poc_id): #if POC is valid if poc_id >= poc_filter_range_start: @@ -397,7 +397,7 @@ try: if "Alpha:" in decoded: #check if there is a text message poc_text = decoded.split('Alpha: ')[1].strip().rstrip('').strip() else: - poc_text = "" + poc_text = "" if re.search("[0-9]{7}", poc_id): #if POC is valid if poc_id >= poc_filter_range_start: