Commit 62015ec9 by Corey Koval

Adding a "Single Receiver" mode

parent 692be715
...@@ -55,9 +55,8 @@ class receiver: ...@@ -55,9 +55,8 @@ class receiver:
def update(self, first_run=False): def update(self, first_run=False):
try: try:
xml_contents = etree.parse(self.station_url) xml_contents = etree.parse(self.station_url)
if first_run: xml_station_id = xml_contents.find('STATION_ID')
xml_station_id = xml_contents.find('STATION_ID') self.station_id = xml_station_id.text
self.station_id = xml_station_id.text
xml_doa_time = xml_contents.find('TIME') xml_doa_time = xml_contents.find('TIME')
self.doa_time = int(xml_doa_time.text) self.doa_time = int(xml_doa_time.text)
xml_freq = xml_contents.find('FREQUENCY') xml_freq = xml_contents.find('FREQUENCY')
...@@ -110,7 +109,8 @@ class receiver: ...@@ -110,7 +109,8 @@ class receiver:
'latitude':self.latitude, 'longitude':self.longitude, 'heading':self.heading, 'latitude':self.latitude, 'longitude':self.longitude, 'heading':self.heading,
'doa':self.doa, 'frequency':self.frequency, 'power':self.power, 'doa':self.doa, 'frequency':self.frequency, 'power':self.power,
'confidence':self.confidence, 'doa_time':self.doa_time, 'mobile': self.isMobile, 'confidence':self.confidence, 'doa_time':self.doa_time, 'mobile': self.isMobile,
'active':self.isActive, 'auto':self.isAuto, 'inverted':self.inverted}) 'active':self.isActive, 'auto':self.isAuto, 'inverted':self.inverted,
'single':self.isSingle})
latitude = 0.0 latitude = 0.0
longitude = 0.0 longitude = 0.0
...@@ -122,6 +122,9 @@ class receiver: ...@@ -122,6 +122,9 @@ class receiver:
confidence = 0 confidence = 0
doa_time = 0 doa_time = 0
isMobile = False isMobile = False
isSingle = False
previous_doa_time = 0
last_processed_at = 0
############################################### ###############################################
# Converts Lat/Lon to polar coordinates # Converts Lat/Lon to polar coordinates
...@@ -425,7 +428,6 @@ def write_rx_czml(): ...@@ -425,7 +428,6 @@ def write_rx_czml():
return output return output
############################################### ###############################################
# Converts HSV color values to RGB. # Converts HSV color values to RGB.
############################################### ###############################################
...@@ -581,6 +583,7 @@ def update_rx(action): ...@@ -581,6 +583,7 @@ def update_rx(action):
try: try:
receivers[action].isMobile = data['mobile'] receivers[action].isMobile = data['mobile']
receivers[action].inverted = data['inverted'] receivers[action].inverted = data['inverted']
receivers[action].isSingle = data['single']
# receivers[action].station_url = data['station_url'] # receivers[action].station_url = data['station_url']
receivers[action].update() receivers[action].update()
update_rx_table() update_rx_table()
...@@ -643,6 +646,11 @@ def run_receiver(receivers): ...@@ -643,6 +646,11 @@ def run_receiver(receivers):
conn.commit() conn.commit()
for rx in receivers: for rx in receivers:
if (rx.isSingle and rx.isMobile and rx.isActive and
rx.confidence >= ms.min_conf and
rx.power >= ms.min_power and
rx.doa_time >= rx.previous_doa_time + 5):
write_single_rx_table(rx.station_id, rx.doa_time, rx.latitude, rx.longitude, rx.doa)
try: try:
if rx.isActive: rx.update() if rx.isActive: rx.update()
except IOError: except IOError:
...@@ -658,6 +666,22 @@ def run_receiver(receivers): ...@@ -658,6 +666,22 @@ def run_receiver(receivers):
conn.close() conn.close()
def scrub(table_name):
return ''.join( chr for chr in table_name if chr.isalnum() )
#################################################
# If a receiver is in Single RX Mode, the LOBs
# get written to this table for later processing.
#################################################
def write_single_rx_table(station_id, time, lat, lon, lob):
tablename = scrub(station_id) + "_lobs"
conn = sqlite3.connect(database_name)
c = conn.cursor()
c.execute(f"CREATE TABLE IF NOT EXISTS {tablename} (time INTEGER, latitude REAL, longitude REAL, lob INTEGER)")
to_table = [time, lat, lon, lob]
c.execute(f"INSERT INTO {tablename} VALUES (?,?,?,?)", to_table)
conn.commit()
############################################### ###############################################
# Adds a new receiver to the program, saves it # Adds a new receiver to the program, saves it
# in the database. # in the database.
...@@ -670,6 +694,7 @@ def add_receiver(receiver_url): ...@@ -670,6 +694,7 @@ def add_receiver(receiver_url):
station_url TEXT, station_url TEXT,
isAuto INTEGER, isAuto INTEGER,
isMobile INTEGER, isMobile INTEGER,
isSingle INTEGER,
latitude REAL, latitude REAL,
longitude REAL) longitude REAL)
''') ''')
...@@ -680,12 +705,15 @@ def add_receiver(receiver_url): ...@@ -680,12 +705,15 @@ def add_receiver(receiver_url):
receivers.append(receiver(receiver_url)) receivers.append(receiver(receiver_url))
new_rx = receivers[-1].receiver_dict() new_rx = receivers[-1].receiver_dict()
to_table = [new_rx['station_id'], new_rx['station_url'], new_rx['auto'], to_table = [new_rx['station_id'], new_rx['station_url'], new_rx['auto'],
new_rx['mobile'], new_rx['latitude'], new_rx['longitude']] new_rx['mobile'],new_rx['single'], new_rx['latitude'], new_rx['longitude']]
c.execute("INSERT OR IGNORE INTO receivers VALUES (?,?,?,?,?,?)", to_table) c.execute("INSERT OR IGNORE INTO receivers VALUES (?,?,?,?,?,?,?)", to_table)
conn.commit() conn.commit()
mobile = c.execute("SELECT isMobile FROM receivers WHERE station_id = ?", mobile = c.execute("SELECT isMobile FROM receivers WHERE station_id = ?",
[new_rx['station_id']]).fetchone()[0] [new_rx['station_id']]).fetchone()[0]
single = c.execute("SELECT isSingle FROM receivers WHERE station_id = ?",
[new_rx['station_id']]).fetchone()[0]
receivers[-1].isMobile = bool(mobile) receivers[-1].isMobile = bool(mobile)
receivers[-1].isSingle = bool(single)
print("Created new DF Station at " + receiver_url) print("Created new DF Station at " + receiver_url)
except AttributeError: except AttributeError:
pass pass
...@@ -718,10 +746,11 @@ def update_rx_table(): ...@@ -718,10 +746,11 @@ def update_rx_table():
c = conn.cursor() c = conn.cursor()
for item in receivers: for item in receivers:
rx = item.receiver_dict() rx = item.receiver_dict()
to_table = [rx['auto'], rx['mobile'], rx['latitude'], rx['longitude'], rx['station_id']] to_table = [rx['auto'], rx['mobile'], rx['single'], rx['latitude'], rx['longitude'], rx['station_id']]
c.execute('''UPDATE receivers SET c.execute('''UPDATE receivers SET
isAuto=?, isAuto=?,
isMobile=?, isMobile=?,
isSingle=?,
latitude=?, latitude=?,
longitude=? longitude=?
WHERE station_id = ?''', to_table) WHERE station_id = ?''', to_table)
......
...@@ -19,8 +19,9 @@ function updateRx(callBack, id) { ...@@ -19,8 +19,9 @@ function updateRx(callBack, id) {
// ****************************************************** // ******************************************************
function editReceivers(rx_json, id) { function editReceivers(rx_json, id) {
const receivers = rx_json['receivers']; const receivers = rx_json['receivers'];
// var stationUrlHtml =
// "<input type=\"hidden\" id=\"url_" + id + "\"/>"; let isSingle = "";
if (receivers[id].single) isSingle = "checked";
var stationIDhtml = var stationIDhtml =
"Station ID: <a href=\"" + receivers[id].station_url + "\" target=\"_blank\">" + receivers[id].station_id + "</a>"; "Station ID: <a href=\"" + receivers[id].station_url + "\" target=\"_blank\">" + receivers[id].station_id + "</a>";
...@@ -28,6 +29,8 @@ function editReceivers(rx_json, id) { ...@@ -28,6 +29,8 @@ function editReceivers(rx_json, id) {
// var manualInfo = // var manualInfo =
// "<input type=\"hidden\" id=\"manual_toggle_" + receivers[id].uid + "\"/>"; // "<input type=\"hidden\" id=\"manual_toggle_" + receivers[id].uid + "\"/>";
var singleModeHtml = "&emsp;Single Receiver Mode: <input " + isSingle + " id=\"singlerx_toggle_" + id + "\" type=\"checkbox\" />";
var locationHtml = var locationHtml =
"Location: " + receivers[id].latitude + "&#176;, " + receivers[id].longitude + "&#176;"; "Location: " + receivers[id].latitude + "&#176;, " + receivers[id].longitude + "&#176;";
...@@ -37,9 +40,6 @@ function editReceivers(rx_json, id) { ...@@ -37,9 +40,6 @@ function editReceivers(rx_json, id) {
var freqHtml = var freqHtml =
"Tuned to " + receivers[id].frequency + " MHz"; "Tuned to " + receivers[id].frequency + " MHz";
// var edit_stationUrlHtml =
// "Station URL:<input style=\"width: 300px;\" type=\"text\" value=\"" + receivers[id].station_url + "\" name=\"station_url_" + id + "\" />";
var edit_stationIDhtml = var edit_stationIDhtml =
"Station ID:<input style=\"width: 105px;\" type=\"text\" value=\"" + receivers[id].station_id + "\" name=\"station_id_" + id + "\" />"; "Station ID:<input style=\"width: 105px;\" type=\"text\" value=\"" + receivers[id].station_id + "\" name=\"station_id_" + id + "\" />";
...@@ -56,9 +56,12 @@ function editReceivers(rx_json, id) { ...@@ -56,9 +56,12 @@ function editReceivers(rx_json, id) {
var edit_freqHtml = var edit_freqHtml =
"Frequency:<input style=\"width: 105px;\" type=\"text\" value=\"" + receivers[id].frequency + "\" name=\"frequency_" + id + "\" />"; "Frequency:<input style=\"width: 105px;\" type=\"text\" value=\"" + receivers[id].frequency + "\" name=\"frequency_" + id + "\" />";
var mobile = id + "-mobile"; const mobilespan = document.getElementById(id + "-mobile");
var isMobileCheck = document.getElementById("mobilerx_toggle_" + id); const singlespan = document.getElementById(id + "-single");
// var mobile = id + "-mobile";
var isMobileCheck;
var isInvertedCheck; var isInvertedCheck;
var isSingleCheck;
var editButton = document.getElementById(id + "-edit"); var editButton = document.getElementById(id + "-edit");
if (editButton.checked) { if (editButton.checked) {
clearInterval(autoRefresh); clearInterval(autoRefresh);
...@@ -67,12 +70,26 @@ function editReceivers(rx_json, id) { ...@@ -67,12 +70,26 @@ function editReceivers(rx_json, id) {
let isInverted = ""; let isInverted = "";
if (receivers[id].inverted) isInverted = "checked"; if (receivers[id].inverted) isInverted = "checked";
document.getElementById(id + "-editicon").innerHTML = "save"; document.getElementById(id + "-editicon").innerHTML = "save";
document.getElementById(mobile).innerHTML = mobilespan.innerHTML =
"Mobile Receiver: <input " + isMobile + " id=\"mobilerx_toggle_" + id + "\" type=\"checkbox\" />"; "Mobile Receiver: <input " + isMobile + " id=\"mobilerx_toggle_" + id + "\" type=\"checkbox\" />";
document.getElementById(id + "-invert").innerHTML = document.getElementById(id + "-invert").innerHTML =
"Inverted DOA: <input " + isInverted + " id=\"invert_toggle_" + id + "\" type=\"checkbox\" />"; "Inverted DOA: <input " + isInverted + " id=\"invert_toggle_" + id + "\" type=\"checkbox\" />";
isInvertedCheck = document.getElementById("invert_toggle_" + id); isInvertedCheck = document.getElementById("invert_toggle_" + id);
isInvertedCheck.setAttribute("title", "KerberosSDR users keep this checked."); isInvertedCheck.setAttribute("title", "KerberosSDR users keep this checked.");
isMobileCheck = document.getElementById("mobilerx_toggle_" + id);
if (isMobileCheck.checked) {
if (isMobileCheck.checked) {
singlespan.innerHTML = singleModeHtml;
}
}
isMobileCheck.onchange = function() {
if (isMobileCheck.checked) {
singlespan.innerHTML = singleModeHtml;
} else {
singlespan.innerHTML = "";
}
}
// document.getElementById(id + "-manual").innerHTML = edit_manualInfo; // document.getElementById(id + "-manual").innerHTML = edit_manualInfo;
// // document.getElementById(id + "-url").innerHTML = edit_stationUrlHtml; // // document.getElementById(id + "-url").innerHTML = edit_stationUrlHtml;
// document.getElementById("manual_toggle_" + id).onchange = function() { // document.getElementById("manual_toggle_" + id).onchange = function() {
...@@ -103,6 +120,18 @@ function editReceivers(rx_json, id) { ...@@ -103,6 +120,18 @@ function editReceivers(rx_json, id) {
} else { } else {
receivers[id].inverted = false; receivers[id].inverted = false;
} }
try {
isSingleCheck = document.getElementById("singlerx_toggle_" + id);
if (isSingleCheck.checked) {
receivers[id].single = true;
} else {
receivers[id].single = false;
}
} catch {
receivers[id].single = false;
}
const otherParams = { const otherParams = {
headers: { headers: {
"content-type": "application/json" "content-type": "application/json"
...@@ -225,6 +254,7 @@ function showReceivers(rx_json, id) { ...@@ -225,6 +254,7 @@ function showReceivers(rx_json, id) {
const urlspan = document.getElementById(id + "-url"); const urlspan = document.getElementById(id + "-url");
const mobilespan = document.getElementById(id + "-mobile"); const mobilespan = document.getElementById(id + "-mobile");
const invertspan = document.getElementById(id + "-invert"); const invertspan = document.getElementById(id + "-invert");
const singlespan = document.getElementById(id + "-single");
// const manualspan = document.getElementById(id + "-manual"); // const manualspan = document.getElementById(id + "-manual");
const idspan = document.getElementById(id + "-id"); const idspan = document.getElementById(id + "-id");
const locationspan = document.getElementById(id + "-location"); const locationspan = document.getElementById(id + "-location");
...@@ -246,6 +276,7 @@ function showReceivers(rx_json, id) { ...@@ -246,6 +276,7 @@ function showReceivers(rx_json, id) {
// document.getElementById(id + "-mobile").innerHTML = ""; // document.getElementById(id + "-mobile").innerHTML = "";
mobilespan.innerHTML = ""; mobilespan.innerHTML = "";
invertspan.innerHTML = ""; invertspan.innerHTML = "";
singlespan.innerHTML = "";
document.getElementById(id + "-editicon").innerHTML = "edit"; document.getElementById(id + "-editicon").innerHTML = "edit";
// document.getElementById(id + "-manual").innerHTML = manualInfo; // document.getElementById(id + "-manual").innerHTML = manualInfo;
// document.getElementById(id + "-url").innerHTML = stationUrlHtml; // document.getElementById(id + "-url").innerHTML = stationUrlHtml;
...@@ -273,6 +304,7 @@ function createReceivers(rx_json, id) { ...@@ -273,6 +304,7 @@ function createReceivers(rx_json, id) {
// const urlspan = document.createElement('span'); // const urlspan = document.createElement('span');
const mobilespan = document.createElement('span'); const mobilespan = document.createElement('span');
const invertspan = document.createElement('span'); const invertspan = document.createElement('span');
const singlespan = document.createElement('span');
// const manualspan = document.createElement('span'); // const manualspan = document.createElement('span');
const idspan = document.createElement('span'); const idspan = document.createElement('span');
const locationspan = document.createElement('span'); const locationspan = document.createElement('span');
...@@ -323,6 +355,7 @@ function createReceivers(rx_json, id) { ...@@ -323,6 +355,7 @@ function createReceivers(rx_json, id) {
// urlspan.id = receivers[i].uid + "-url"; // urlspan.id = receivers[i].uid + "-url";
mobilespan.id = receivers[i].uid + "-mobile"; mobilespan.id = receivers[i].uid + "-mobile";
invertspan.id = receivers[i].uid + "-invert"; invertspan.id = receivers[i].uid + "-invert";
singlespan.id = receivers[i].uid + "-single";
// manualspan.id = receivers[i].uid + "-manual"; // manualspan.id = receivers[i].uid + "-manual";
idspan.id = receivers[i].uid + "-id"; idspan.id = receivers[i].uid + "-id";
locationspan.id = receivers[i].uid + "-location"; locationspan.id = receivers[i].uid + "-location";
...@@ -333,6 +366,7 @@ function createReceivers(rx_json, id) { ...@@ -333,6 +366,7 @@ function createReceivers(rx_json, id) {
// rxcard.appendChild(urlspan); // rxcard.appendChild(urlspan);
rxcard.appendChild(mobilespan); rxcard.appendChild(mobilespan);
rxcard.appendChild(singlespan);
rxcard.appendChild(invertspan); rxcard.appendChild(invertspan);
// rxcard.appendChild(manualspan); // rxcard.appendChild(manualspan);
rxcard.appendChild(idspan); rxcard.appendChild(idspan);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment