From b6abb22d1244421e205e945f39004d4f10257df9 Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Tue, 15 Aug 2023 00:12:55 -0400 Subject: [PATCH] Adding automatic bookmarks based on the EIBI data. --- owrx/connection.py | 2 ++ owrx/eibi.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++ owrx/markers.py | 2 +- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/owrx/connection.py b/owrx/connection.py index e37ac201..d2b60492 100644 --- a/owrx/connection.py +++ b/owrx/connection.py @@ -8,6 +8,7 @@ from owrx.feature import FeatureDetector from owrx.version import openwebrx_version from owrx.bands import Bandplan from owrx.bookmarks import Bookmarks +from owrx.eibi import EIBI from owrx.map import Map from owrx.property import PropertyStack, PropertyDeleted from owrx.modes import Modes, DigitalMode @@ -212,6 +213,7 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient): frequencyRange = (cf - srh, cf + srh) dial_frequencies = Bandplan.getSharedInstance().collectDialFrequencies(frequencyRange) bookmarks = [b.__dict__() for b in Bookmarks.getSharedInstance().getBookmarks(frequencyRange)] + bookmarks += [b.__dict__() for b in EIBI.getSharedInstance().currentBookmarks(frequencyRange)] self.write_dial_frequencies(dial_frequencies) self.write_bookmarks(bookmarks) diff --git a/owrx/eibi.py b/owrx/eibi.py index f40856dc..dfa6b691 100644 --- a/owrx/eibi.py +++ b/owrx/eibi.py @@ -1,4 +1,5 @@ from owrx.config.core import CoreConfig +from owrx.bookmarks import Bookmark from datetime import datetime from json import JSONEncoder @@ -179,6 +180,54 @@ class EIBI(object): # Done return result + # Create list of current bookmarks for a frequency range + def currentBookmarks(self, frequencyRange, hours: int = 1): + # Make sure freq2>freq1 + (f1, f2) = frequencyRange + if f1>f2: + f = f1 + f1 = f2 + f2 = f + # Get entries active at the current time + 1 hour + now = datetime.utcnow() + day = now.weekday() + date = now.year * 10000 + now.month * 100 + now.day + t1 = now.hour * 100 + now.minute + t2 = t1 + hours * 100 + result = {} + logger.debug("Searching bookmarks for {0}-{1}kHz...".format(f1//1000, f2//1000)) + # Search for current entries + with self.lock: + for entry in self.schedule: + try: + # Check if entry active and within frequency range + f = entry["freq"] + entryActive = ( + f >= f1 and f <= f2 and entry["days"][day] != "." + and (entry["date1"] == 0 or entry["date1"] <= date) + and (entry["date2"] == 0 or entry["date2"] >= date) + ) + # Check the hours, rolling over to the next day + if entryActive: + e1 = entry["time1"] + e2 = entry["time2"] + e2 = e2 if e2 > e1 else e2 + 2400 + entryActive = e1 < t2 and e2 > t1 + # For every currently active schedule entry... + if entryActive: + result[f] = Bookmark({ + "name" : entry["name"], + "modulation" : entry["mode"], + "frequency" : f + }, srcFile = "EIBI") + + except Exception as e: + logger.debug("currentBookmarks() exception: {0}".format(e)) + + # Done + logger.debug("Found {0} bookmarks for {1}-{2}kHz.".format(len(result), f1//1000, f2//1000)) + return result.values() + def convertDate(self, date: str): # No-date is a common case if date == "": diff --git a/owrx/markers.py b/owrx/markers.py index 22e41ad1..ef8e76fa 100644 --- a/owrx/markers.py +++ b/owrx/markers.py @@ -2,7 +2,7 @@ from owrx.config.core import CoreConfig from owrx.map import Map, Location from owrx.aprs import getSymbolData from json import JSONEncoder -from owrx.eibi import EIBI_Locations, EIBI +from owrx.eibi import EIBI from datetime import datetime import urllib