From a16728ba5220db60635c92f9279d577faed4bbd1 Mon Sep 17 00:00:00 2001 From: dk5ra Date: Sun, 22 Oct 2017 00:21:11 +0200 Subject: [PATCH 1/4] add record_plugin --- plugins/record/record.py | 118 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 plugins/record/record.py diff --git a/plugins/record/record.py b/plugins/record/record.py new file mode 100644 index 00000000..bf83f0ec --- /dev/null +++ b/plugins/record/record.py @@ -0,0 +1,118 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +""" + +@author: DK5RA Alex(trollkopp) + +@requires: arecord >= 1.1.3 +""" + +# ADD THIS TO YOUR Pulseaudio config file /etc/pulse/default.pa +# load-module module-null-sink sink_name=playbackstream +# update-sink-proplist playbackstream device.description=playbackstream +# load-module module-loopback sink=playbackstream +# set-default-sink playbackstream +# set-default-source playbackstream.monitor + + +# +# Imports +# + +import logging # Global logger +from includes import globalVars # Global variables + + +import os # for log mkdir +import time # for time.sleep() +import subprocess # for starting record + +# Helper function, uncomment to use +from includes.helper import timeHandler +from includes.helper import wildcardHandler +from includes.helper import configHandler + +## +# +# onLoad (init) function of plugin +# will be called one time by the pluginLoader on start +# +def onLoad(): + """ + While loading the plugins by pluginLoader.loadPlugins() + this onLoad() routine is called one time for initialize the plugin + + @requires: nothing + + @return: nothing + @exception: Exception if init has an fatal error so that the plugin couldn't work + + """ + + try: + ########## User onLoad CODE ########## + pass + ########## User onLoad CODE ########## + except: + logging.error("unknown error") + logging.debug("unknown error", exc_info=True) + raise + +## +# +# Main function of plugin +# will be called by the alarmHandler +# +def run(typ,freq,data): + """ + This function is the implementation of the Plugin. + + If necessary the configuration hast to be set in the config.ini. + + @type typ: string (FMS|ZVEI|POC) + @param typ: Typ of the dataset + @type data: map of data (structure see readme.md in plugin folder) + @param data: Contains the parameter for dispatch + @type freq: string + @keyword freq: frequency of the SDR Stick + + @requires: If necessary the configuration hast to be set in the config.ini. + + @return: nothing + @exception: nothing, make sure this function will never thrown an exception + """ + try: + if configHandler.checkConfig("record"): #read and debug the config (let empty if no config used) + + logging.debug(globalVars.config.get("Plugins", "record")) +# logging.debug(globalVars.config.get("template", "test2")) + rec_duration = globalVars.config.get("record", "rec_duration") + if (globalVars.config.get("Plugins", "record") == "1"): + ########## User Plugin CODE ########## + if typ == "FMS": + logging.warning("%s not supported", typ) + elif typ == "ZVEI": + logging.debug("record plugin: detected ZVEI decode") + timestamp = str(timeHandler.getDate())+"-"+str(timeHandler.getTime()) + zveicode = "%ZVEI%" + zveicode = wildcardHandler.replaceWildcards(zveicode, data) + filename = "aufnahme_"+"5-ton"+str(zveicode)+"_"+str(timestamp)+".wav" + rec_filepath = globalVars.config.get("record", "filepath") + logging.debug(filename) + logging.debug(rec_filepath) + command = "" + command = command+"arecord -D pulse -f cd -d "+str(rec_duration)+" -c 1 "+str(rec_filepath)+str(filename)+"" + recordstream = subprocess.Popen(command.split(), + stderr=open(globalVars.log_path+"record.log","a"), + shell=False) + elif typ == "POC": + logging.warning("%s not supported", typ) + else: + logging.warning("Invalid Typ: %s", typ) + ########## User Plugin CODE ########## + else: + logging.debug("record plugin not activated. activate it in the config.ini") + except: + logging.error("unknown error") + logging.debug("unknown error", exc_info=True) From 8f06b961b808068fe1413ebdd428114bc9ab2ea4 Mon Sep 17 00:00:00 2001 From: dk5ra Date: Sun, 22 Oct 2017 00:28:24 +0200 Subject: [PATCH 2/4] add record_plugin --- boswatch.py | 50 +++++++++++++++++++++++++++++--------- config/config.template.ini | 6 +++++ 2 files changed, 44 insertions(+), 12 deletions(-) mode change 100755 => 100644 boswatch.py diff --git a/boswatch.py b/boswatch.py old mode 100755 new mode 100644 index df1e5e6d..4d473ad7 --- a/boswatch.py +++ b/boswatch.py @@ -18,12 +18,11 @@ import logging import logging.handlers -import argparse # for parse the args -import ConfigParser # for parse the config file -import os # for log mkdir -import sys # for py version -import time # for time.sleep() -import subprocess # for starting rtl_fm and multimon-ng +import argparse # for parse the args +import ConfigParser # for parse the config file +import os # for log mkdir +import time # for time.sleep() +import subprocess # for starting rtl_fm and multimon-ng from includes import globalVars # Global variables from includes import MyTimedRotatingFileHandler # extension of TimedRotatingFileHandler @@ -57,6 +56,7 @@ parser.add_argument("-u", "--usevarlog", help="Use '/var/log/boswatch' for logfiles instead of subdir 'log' in BOSWatch directory", action="store_true") parser.add_argument("-v", "--verbose", help="Show more information", action="store_true") parser.add_argument("-q", "--quiet", help="Show no information. Only logfiles", action="store_true") + # We need this argument for testing (skip instantiate of rtl-fm and multimon-ng): parser.add_argument("-t", "--test", help=argparse.SUPPRESS, action="store_true") args = parser.parse_args() @@ -163,9 +163,7 @@ # try: logging.debug("SW Version: %s",globalVars.versionNr) - logging.debug("Branch: %s",globalVars.branch) logging.debug("Build Date: %s",globalVars.buildDate) - logging.debug("Python Vers: %s",sys.version) logging.debug("BOSWatch given arguments") if args.test: logging.debug(" - Test-Mode!") @@ -223,9 +221,6 @@ configHandler.checkConfig("FMS") configHandler.checkConfig("ZVEI") configHandler.checkConfig("POC") - configHandler.checkConfig("Plugins") - configHandler.checkConfig("Filters") - #NMAHandler is outputed below except: # we couldn't work without config -> exit logging.critical("cannot read config file") @@ -334,10 +329,41 @@ logging.critical("cannot start rtl_fm") logging.debug("cannot start rtl_fm", exc_info=True) exit(1) + + #duplicate rtl_fm stdout for the record plugin and multimon-ng + pipe_r, pipe_w = os.pipe() + tee = subprocess.Popen(["tee", "/dev/fd/{}".format(pipe_w)], + stdin=rtl_fm.stdout, stdout=subprocess.PIPE) + + # + # Start audioplaybackstream for the record plugin + # + if (globalVars.config.get("Plugins", "record") == "1"): + try: + if not args.test: + logging.debug("starting playbackaudiostream") + command = "" + command = "aplay -t raw -r 22050 -D pulse -f S16_LE /dev/stdin" + playbackstream = subprocess.Popen(command.split(), + stdin=tee.stdout, + stdout=subprocess.PIPE, + stderr=open(globalVars.log_path+"playbackstream.log","a"), + shell=False) + time.sleep(3) + else: + logging.warning("!!! Test-Mode: !!! Playbackstream not started !!!") + except: + logging.critical("cannot start playbackstream") + logging.debug("cannot start playbackstream", exc_info=True) + exit(1) + else: + logging.debug("record plugin not activated. activate it in the config.ini") + # # Start multimon # + try: if not args.test: logging.debug("starting multimon-ng") @@ -346,7 +372,7 @@ command = globalVars.config.get("BOSWatch","multimon_path") command = command+"multimon-ng "+str(demodulation)+" -f alpha -t raw /dev/stdin - " multimon_ng = subprocess.Popen(command.split(), - stdin=rtl_fm.stdout, + stdin=pipe_r, stdout=subprocess.PIPE, stderr=open(globalVars.log_path+"multimon.log","a"), shell=False) diff --git a/config/config.template.ini b/config/config.template.ini index 7a959f27..17b144a1 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -163,6 +163,7 @@ FFAgent = 0 Pushover = 0 Telegram = 0 yowsup = 0 +record = 0 # for developing - template-module template = 0 @@ -414,6 +415,11 @@ zvei_message = %DATE% %TIME%: %ZVEI% poc_message = %MSG% +[record] +#duration in seconds +rec_duration = 40 +#filepath = #INSERT FILE PATH HERE# ex: /home/user/BOSWatch/recordings/ + ##################### ##### Not ready yet # ##################### From da378fcbc707e2e6890dcf4455716dbc719c7ea1 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sun, 22 Oct 2017 09:28:25 +0200 Subject: [PATCH 3/4] Update globalVars.py --- includes/globalVars.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/globalVars.py b/includes/globalVars.py index fb2179a7..55a693e6 100644 --- a/includes/globalVars.py +++ b/includes/globalVars.py @@ -8,11 +8,11 @@ @author: Bastian Schroll """ +# version info versionNr = "2.3" branch = "dev" buildDate = "unreleased" - # Global variables config = 0 script_path = "" From ed9a05214b75953013376f235828a4b99195bb77 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sun, 22 Oct 2017 09:36:22 +0200 Subject: [PATCH 4/4] some edits from actual dev-branch --- boswatch.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/boswatch.py b/boswatch.py index 4d473ad7..681e41b0 100644 --- a/boswatch.py +++ b/boswatch.py @@ -18,11 +18,12 @@ import logging import logging.handlers -import argparse # for parse the args -import ConfigParser # for parse the config file -import os # for log mkdir -import time # for time.sleep() -import subprocess # for starting rtl_fm and multimon-ng +import argparse # for parse the args +import ConfigParser # for parse the config file +import os # for log mkdir +import sys # for py version +import time # for time.sleep() +import subprocess # for starting rtl_fm and multimon-ng from includes import globalVars # Global variables from includes import MyTimedRotatingFileHandler # extension of TimedRotatingFileHandler @@ -56,7 +57,7 @@ parser.add_argument("-u", "--usevarlog", help="Use '/var/log/boswatch' for logfiles instead of subdir 'log' in BOSWatch directory", action="store_true") parser.add_argument("-v", "--verbose", help="Show more information", action="store_true") parser.add_argument("-q", "--quiet", help="Show no information. Only logfiles", action="store_true") - + # We need this argument for testing (skip instantiate of rtl-fm and multimon-ng): parser.add_argument("-t", "--test", help=argparse.SUPPRESS, action="store_true") args = parser.parse_args() @@ -163,7 +164,10 @@ # try: logging.debug("SW Version: %s",globalVars.versionNr) + logging.debug("Branch: %s",globalVars.branch) logging.debug("Build Date: %s",globalVars.buildDate) + logging.debug("Python Vers: %s",sys.version) + logging.debug("BOSWatch given arguments") if args.test: logging.debug(" - Test-Mode!") @@ -221,6 +225,9 @@ configHandler.checkConfig("FMS") configHandler.checkConfig("ZVEI") configHandler.checkConfig("POC") + configHandler.checkConfig("Plugins") + configHandler.checkConfig("Filters") + #NMAHandler is outputed below except: # we couldn't work without config -> exit logging.critical("cannot read config file") @@ -329,13 +336,13 @@ logging.critical("cannot start rtl_fm") logging.debug("cannot start rtl_fm", exc_info=True) exit(1) - + #duplicate rtl_fm stdout for the record plugin and multimon-ng pipe_r, pipe_w = os.pipe() tee = subprocess.Popen(["tee", "/dev/fd/{}".format(pipe_w)], stdin=rtl_fm.stdout, stdout=subprocess.PIPE) - + # # Start audioplaybackstream for the record plugin # @@ -359,11 +366,11 @@ exit(1) else: logging.debug("record plugin not activated. activate it in the config.ini") - + # # Start multimon # - + try: if not args.test: logging.debug("starting multimon-ng")