def channel_list_from_config(self, rc): channels = [] for ssect in rc.sections(): if ssect == MAINSECTION: continue ch = channel() ch.freq = engnum(rc.get(ssect, "freq")) ch.bw = engnum(rc.get(ssect, "bw")) ch.pipe = cfg_safe(rc.get, ssect, 'pipe', None) channels.append(ch) return channels
def __init__(self): confdir = os.path.join(os.path.expanduser('~'), ".kukuruku/scanner/") # Read global config rc = configparser.ConfigParser() cfpath = os.path.join(confdir, "main.conf") rc.read(cfpath) self.bufsize = cfg_safe(rc.getint, MAINSECTION, 'bufsize', 2048000, cfpath) self.rate = cfg_safe(rc.getint, MAINSECTION, 'rate', 2048000, cfpath) self.interval = cfg_safe(rc.getint, MAINSECTION, 'interval', 5, cfpath) self.skip = cfg_safe(rc.getint, MAINSECTION, 'skip', 3, cfpath) self.fftw = cfg_safe(rc.getint, MAINSECTION, 'fftw', 2048, cfpath) self.fftskip = cfg_safe(rc.getint, MAINSECTION, 'fftskip', 32, cfpath) self.overlap = cfg_safe(rc.getfloat, MAINSECTION, 'overlap', 0.2, cfpath) self.nonce = cfg_safe(rc.get, MAINSECTION, 'nonce', "abcdef", cfpath) self.floor = cfg_safe(rc.getfloat, MAINSECTION, 'floor', 0.4, cfpath) self.sql = cfg_safe(rc.getfloat, MAINSECTION, 'sql', 0.5, cfpath) self.filtermargin = cfg_safe(rc.getfloat, MAINSECTION, 'filtermargin', 1.5, cfpath) self.transition = cfg_safe(rc.getfloat, MAINSECTION, 'transition', 0.2, cfpath) self.minw = cfg_safe(rc.get, MAINSECTION, 'minw', 10000, cfpath) self.maxw = cfg_safe(rc.get, MAINSECTION, 'maxw', 200000, cfpath) self.messgain = cfg_safe(rc.getint, MAINSECTION, 'messgain', 1, cfpath) self.mingain = cfg_safe(rc.getint, MAINSECTION, 'mingain', 10, cfpath) self.maxgain = cfg_safe(rc.getint, MAINSECTION, 'maxgain', 49, cfpath) self.gain = cfg_safe(rc.get, MAINSECTION, 'gain', "0,30,30,30", cfpath) self.stickactivity = cfg_safe(rc.getboolean, MAINSECTION, 'stickactivity', False, cfpath) self.stick = cfg_safe(rc.getint, MAINSECTION, 'stick', 10, cfpath) self.silencegap = cfg_safe(rc.getint, MAINSECTION, 'silencegap', 5, cfpath) self.dumpspectrum = cfg_safe(rc.get, MAINSECTION, 'dumpspectrum', "never", cfpath) self.gainpcs = self.gain.split(",") if len(self.gainpcs) != 4: print("Wrong gain string format in configuration %s, should be \"N,N,N,N\""%self.gain) sys.exit(1) if self.messgain < -1 or self.messgain > 3: print("messagin parameter must be an integer from range [-1, 3]") sys.exit(1) defaultgain = int(self.gainpcs[self.messgain]) self.minw = engnum(self.minw) self.maxw = engnum(self.maxw) self.rate = engnum(self.rate) files = [f for f in os.listdir(confdir) if os.path.isfile(os.path.join(confdir, f))] self.scanframes = [] self.cronframes = [] step = float(self.rate) * (1.0-self.overlap) # Read scanframe and channel config files for f in files: if f == "main.conf" or f == "blacklist.conf": continue if f[-5:] != ".conf": continue print("file %s"%f) rc = configparser.ConfigParser() rc.read(os.path.join(confdir, f)) floor = cfg_safe(rc.getfloat, MAINSECTION, 'floor', self.floor) sql = cfg_safe(rc.getfloat, MAINSECTION, 'sql', self.sql) stickactivity = cfg_safe(rc.getboolean, MAINSECTION, 'stickactivity', self.stickactivity) stick = cfg_safe(rc.getfloat, MAINSECTION, 'stick', self.stick) silencegap = cfg_safe(rc.getfloat, MAINSECTION, 'silencegap', self.silencegap) if "freqstart" in rc.options(MAINSECTION): # range randscan freqstart = rc.get(MAINSECTION, "freqstart") freqstart = engnum(freqstart) + step/2 freqstop = rc.get(MAINSECTION, "freqstop") freqstop = engnum(freqstop) - step/2 numf = int(math.ceil(float(freqstop - freqstart)/step)) if numf == 0: # freqstart == freqstop numf = 1 delta = freqstop else: delta = float(freqstop - freqstart) / numf cf = freqstart while cf <= math.ceil(freqstop): frm = scanframe() frm.freq = cf frm.floor = floor frm.stickactivity = stickactivity frm.stick = stick frm.silencegap = silencegap frm.sql = sql frm.gain = defaultgain self.scanframes.append(frm) print("insert %f"%cf) cf += math.floor(delta) elif "cron" in rc.options(MAINSECTION): # scheduled recording channels = self.channel_list_from_config(rc) frm = cronframe() frm.freq = engnum(rc.get(MAINSECTION, "freq")) frm.floor = self.floor frm.stickactivity = stickactivity frm.stick = stick frm.silencegap = silencegap frm.sql = sql frm.gain = defaultgain frm.cron = rc.get(MAINSECTION, "cron") frm.channels = channels self.cronframes.append(frm) randscan = cfg_safe(rc.getboolean, MAINSECTION, "randscan", True) if ((not ("freqstart" in rc.options(MAINSECTION))) and randscan): frm = scanframe() frm.freq = engnum(rc.get(MAINSECTION, "freq")) frm.floor = floor frm.stickactivity = stickactivity frm.stick = stick frm.silencegap = silencegap frm.sql = sql frm.gain = defaultgain channels = self.channel_list_from_config(rc) frm.channels = channels self.scanframes.append(frm) # read blacklist and archivelist blpath = os.path.join(confdir, "blacklist.conf") self.blacklist = self.read_sorted_list("h", blpath) self.archivelist = self.read_sorted_list("i", blpath)
def __init__(self, path): rc = configparser.ConfigParser() rc.read(path) section = "Main" cfpath = path self.HOST = cfg_safe(rc.get, section, 'host', "localhost", cfpath) self.PORT = cfg_safe(rc.getint, section, 'port', 4444, cfpath) self.mousechangedelay = cfg_safe(rc.getint, section, 'mousechangedelay', 1, cfpath) self.histooffs = cfg_safe(rc.getint, section, 'histooffs', 1, cfpath) self.histow = cfg_safe(rc.getint, section, 'histow', 50, cfpath) self.histobars = cfg_safe(rc.getint, section, 'histobars', 256, cfpath) self.drawingheight = cfg_safe(rc.getint, section, 'drawingheight', 540, cfpath) self.borderleft = cfg_safe(rc.getint, section, 'borderleft', 80, cfpath) self.areabottom = cfg_safe(rc.getint, section, 'areabottom', 120, cfpath) self.fontsize = cfg_safe(rc.getint, section, 'fontsize', 12, cfpath) self.antialias = cfg_safe(rc.getboolean, section, 'antialias', False, cfpath) self.spectrumscale = cfg_safe(rc.getint, section, 'spectrumscale', 50, cfpath) self.spectrumoffset = cfg_safe(rc.getint, section, 'spectrumoffset', 6, cfpath) self.sqltrim = cfg_safe(rc.getfloat, section, 'sqltrim', 0.3, cfpath) self.sqldelta = cfg_safe(rc.getfloat, section, 'sqldelta', 10, cfpath) self.afcdecim = cfg_safe(rc.getfloat, section, 'afcdecim', 5, cfpath) self.afcmult = cfg_safe(rc.getfloat, section, 'afcmult', 0.1, cfpath) self.modepath = cfg_safe(rc.get, section, 'modepath', "./modes", cfpath) self.preferformat = cfg_safe(rc.get, section, 'preferformat', "F32", cfpath) self.fftw = None
def __init__(self): confdir = os.path.join(os.path.expanduser('~'), ".kukuruku/scanner/") # Read global config rc = configparser.ConfigParser() cfpath = os.path.join(confdir, "main.conf") rc.read(cfpath) self.bufsize = cfg_safe(rc.getint, MAINSECTION, 'bufsize', 2048000, cfpath) self.rate = cfg_safe(rc.getint, MAINSECTION, 'rate', 2048000, cfpath) self.interval = cfg_safe(rc.getint, MAINSECTION, 'interval', 5, cfpath) self.skip = cfg_safe(rc.getint, MAINSECTION, 'skip', 3, cfpath) self.fftw = cfg_safe(rc.getint, MAINSECTION, 'fftw', 2048, cfpath) self.fftskip = cfg_safe(rc.getint, MAINSECTION, 'fftskip', 32, cfpath) self.overlap = cfg_safe(rc.getfloat, MAINSECTION, 'overlap', 0.2, cfpath) self.nonce = cfg_safe(rc.get, MAINSECTION, 'nonce', "abcdef", cfpath) self.floor = cfg_safe(rc.getfloat, MAINSECTION, 'floor', 0.4, cfpath) self.sql = cfg_safe(rc.getfloat, MAINSECTION, 'sql', 0.5, cfpath) self.filtermargin = cfg_safe(rc.getfloat, MAINSECTION, 'filtermargin', 1.5, cfpath) self.transition = cfg_safe(rc.getfloat, MAINSECTION, 'transition', 0.2, cfpath) self.minw = cfg_safe(rc.get, MAINSECTION, 'minw', 10000, cfpath) self.maxw = cfg_safe(rc.get, MAINSECTION, 'maxw', 200000, cfpath) self.messgain = cfg_safe(rc.getint, MAINSECTION, 'messgain', 1, cfpath) self.mingain = cfg_safe(rc.getint, MAINSECTION, 'mingain', 10, cfpath) self.maxgain = cfg_safe(rc.getint, MAINSECTION, 'maxgain', 49, cfpath) self.gain = cfg_safe(rc.get, MAINSECTION, 'gain', "0,30,30,30", cfpath) self.stickactivity = cfg_safe(rc.getboolean, MAINSECTION, 'stickactivity', False, cfpath) self.stick = cfg_safe(rc.getint, MAINSECTION, 'stick', 10, cfpath) self.silencegap = cfg_safe(rc.getint, MAINSECTION, 'silencegap', 5, cfpath) self.dumpspectrum = cfg_safe(rc.get, MAINSECTION, 'dumpspectrum', "never", cfpath) self.gainpcs = self.gain.split(",") if len(self.gainpcs) != 4: print( "Wrong gain string format in configuration %s, should be \"N,N,N,N\"" % self.gain) sys.exit(1) if self.messgain < -1 or self.messgain > 3: print("messagin parameter must be an integer from range [-1, 3]") sys.exit(1) defaultgain = int(self.gainpcs[self.messgain]) self.minw = engnum(self.minw) self.maxw = engnum(self.maxw) self.rate = engnum(self.rate) files = [ f for f in os.listdir(confdir) if os.path.isfile(os.path.join(confdir, f)) ] self.scanframes = [] self.cronframes = [] step = float(self.rate) * (1.0 - self.overlap) # Read scanframe and channel config files for f in files: if f == "main.conf" or f == "blacklist.conf": continue if f[-5:] != ".conf": continue print("file %s" % f) rc = configparser.ConfigParser() rc.read(os.path.join(confdir, f)) floor = cfg_safe(rc.getfloat, MAINSECTION, 'floor', self.floor) sql = cfg_safe(rc.getfloat, MAINSECTION, 'sql', self.sql) stickactivity = cfg_safe(rc.getboolean, MAINSECTION, 'stickactivity', self.stickactivity) stick = cfg_safe(rc.getfloat, MAINSECTION, 'stick', self.stick) silencegap = cfg_safe(rc.getfloat, MAINSECTION, 'silencegap', self.silencegap) if "freqstart" in rc.options(MAINSECTION): # range randscan freqstart = rc.get(MAINSECTION, "freqstart") freqstart = engnum(freqstart) + step / 2 freqstop = rc.get(MAINSECTION, "freqstop") freqstop = engnum(freqstop) - step / 2 numf = int(math.ceil(float(freqstop - freqstart) / step)) if numf == 0: # freqstart == freqstop numf = 1 delta = freqstop else: delta = float(freqstop - freqstart) / numf cf = freqstart while cf <= math.ceil(freqstop): frm = scanframe() frm.freq = cf frm.floor = floor frm.stickactivity = stickactivity frm.stick = stick frm.silencegap = silencegap frm.sql = sql frm.gain = defaultgain self.scanframes.append(frm) print("insert %f" % cf) cf += math.floor(delta) elif "cron" in rc.options(MAINSECTION): # scheduled recording channels = self.channel_list_from_config(rc) frm = cronframe() frm.freq = engnum(rc.get(MAINSECTION, "freq")) frm.floor = self.floor frm.stickactivity = stickactivity frm.stick = stick frm.silencegap = silencegap frm.sql = sql frm.gain = defaultgain frm.cron = rc.get(MAINSECTION, "cron") frm.channels = channels self.cronframes.append(frm) randscan = cfg_safe(rc.getboolean, MAINSECTION, "randscan", True) if ((not ("freqstart" in rc.options(MAINSECTION))) and randscan): frm = scanframe() frm.freq = engnum(rc.get(MAINSECTION, "freq")) frm.floor = floor frm.stickactivity = stickactivity frm.stick = stick frm.silencegap = silencegap frm.sql = sql frm.gain = defaultgain channels = self.channel_list_from_config(rc) frm.channels = channels self.scanframes.append(frm) # read blacklist and archivelist blpath = os.path.join(confdir, "blacklist.conf") self.blacklist = self.read_sorted_list("h", blpath) self.archivelist = self.read_sorted_list("i", blpath)