Commit 62015ec9 by Corey Koval

Adding a "Single Receiver" mode

parent 692be715
......@@ -55,9 +55,8 @@ class receiver:
def update(self, first_run=False):
try:
xml_contents = etree.parse(self.station_url)
if first_run:
xml_station_id = xml_contents.find('STATION_ID')
self.station_id = xml_station_id.text
xml_station_id = xml_contents.find('STATION_ID')
self.station_id = xml_station_id.text
xml_doa_time = xml_contents.find('TIME')
self.doa_time = int(xml_doa_time.text)
xml_freq = xml_contents.find('FREQUENCY')
......@@ -110,7 +109,8 @@ class receiver:
'latitude':self.latitude, 'longitude':self.longitude, 'heading':self.heading,
'doa':self.doa, 'frequency':self.frequency, 'power':self.power,
'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
longitude = 0.0
......@@ -122,6 +122,9 @@ class receiver:
confidence = 0
doa_time = 0
isMobile = False
isSingle = False
previous_doa_time = 0
last_processed_at = 0
###############################################
# Converts Lat/Lon to polar coordinates
......@@ -425,7 +428,6 @@ def write_rx_czml():
return output
###############################################
# Converts HSV color values to RGB.
###############################################
......@@ -581,6 +583,7 @@ def update_rx(action):
try:
receivers[action].isMobile = data['mobile']
receivers[action].inverted = data['inverted']
receivers[action].isSingle = data['single']
# receivers[action].station_url = data['station_url']
receivers[action].update()
update_rx_table()
......@@ -643,6 +646,11 @@ def run_receiver(receivers):
conn.commit()
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:
if rx.isActive: rx.update()
except IOError:
......@@ -658,6 +666,22 @@ def run_receiver(receivers):
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
# in the database.
......@@ -670,6 +694,7 @@ def add_receiver(receiver_url):
station_url TEXT,
isAuto INTEGER,
isMobile INTEGER,
isSingle INTEGER,
latitude REAL,
longitude REAL)
''')
......@@ -680,12 +705,15 @@ def add_receiver(receiver_url):
receivers.append(receiver(receiver_url))
new_rx = receivers[-1].receiver_dict()
to_table = [new_rx['station_id'], new_rx['station_url'], new_rx['auto'],
new_rx['mobile'], new_rx['latitude'], new_rx['longitude']]
c.execute("INSERT OR IGNORE INTO receivers VALUES (?,?,?,?,?,?)", to_table)
new_rx['mobile'],new_rx['single'], new_rx['latitude'], new_rx['longitude']]
c.execute("INSERT OR IGNORE INTO receivers VALUES (?,?,?,?,?,?,?)", to_table)
conn.commit()
mobile = c.execute("SELECT isMobile FROM receivers WHERE station_id = ?",
[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].isSingle = bool(single)
print("Created new DF Station at " + receiver_url)
except AttributeError:
pass
......@@ -718,10 +746,11 @@ def update_rx_table():
c = conn.cursor()
for item in receivers:
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
isAuto=?,
isMobile=?,
isSingle=?,
latitude=?,
longitude=?
WHERE station_id = ?''', to_table)
......
......@@ -19,8 +19,9 @@ function updateRx(callBack, id) {
// ******************************************************
function editReceivers(rx_json, id) {
const receivers = rx_json['receivers'];
// var stationUrlHtml =
// "<input type=\"hidden\" id=\"url_" + id + "\"/>";
let isSingle = "";
if (receivers[id].single) isSingle = "checked";
var stationIDhtml =
"Station ID: <a href=\"" + receivers[id].station_url + "\" target=\"_blank\">" + receivers[id].station_id + "</a>";
......@@ -28,6 +29,8 @@ function editReceivers(rx_json, id) {
// var manualInfo =
// "<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 =
"Location: " + receivers[id].latitude + "&#176;, " + receivers[id].longitude + "&#176;";
......@@ -37,9 +40,6 @@ function editReceivers(rx_json, id) {
var freqHtml =
"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 =
"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) {
var edit_freqHtml =
"Frequency:<input style=\"width: 105px;\" type=\"text\" value=\"" + receivers[id].frequency + "\" name=\"frequency_" + id + "\" />";
var mobile = id + "-mobile";
var isMobileCheck = document.getElementById("mobilerx_toggle_" + id);
const mobilespan = document.getElementById(id + "-mobile");
const singlespan = document.getElementById(id + "-single");
// var mobile = id + "-mobile";
var isMobileCheck;
var isInvertedCheck;
var isSingleCheck;
var editButton = document.getElementById(id + "-edit");
if (editButton.checked) {
clearInterval(autoRefresh);
......@@ -67,12 +70,26 @@ function editReceivers(rx_json, id) {
let isInverted = "";
if (receivers[id].inverted) isInverted = "checked";
document.getElementById(id + "-editicon").innerHTML = "save";
document.getElementById(mobile).innerHTML =
mobilespan.innerHTML =
"Mobile Receiver: <input " + isMobile + " id=\"mobilerx_toggle_" + id + "\" type=\"checkbox\" />";
document.getElementById(id + "-invert").innerHTML =
"Inverted DOA: <input " + isInverted + " id=\"invert_toggle_" + id + "\" type=\"checkbox\" />";
isInvertedCheck = document.getElementById("invert_toggle_" + id);
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 + "-url").innerHTML = edit_stationUrlHtml;
// document.getElementById("manual_toggle_" + id).onchange = function() {
......@@ -103,6 +120,18 @@ function editReceivers(rx_json, id) {
} else {
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 = {
headers: {
"content-type": "application/json"
......@@ -225,6 +254,7 @@ function showReceivers(rx_json, id) {
const urlspan = document.getElementById(id + "-url");
const mobilespan = document.getElementById(id + "-mobile");
const invertspan = document.getElementById(id + "-invert");
const singlespan = document.getElementById(id + "-single");
// const manualspan = document.getElementById(id + "-manual");
const idspan = document.getElementById(id + "-id");
const locationspan = document.getElementById(id + "-location");
......@@ -246,6 +276,7 @@ function showReceivers(rx_json, id) {
// document.getElementById(id + "-mobile").innerHTML = "";
mobilespan.innerHTML = "";
invertspan.innerHTML = "";
singlespan.innerHTML = "";
document.getElementById(id + "-editicon").innerHTML = "edit";
// document.getElementById(id + "-manual").innerHTML = manualInfo;
// document.getElementById(id + "-url").innerHTML = stationUrlHtml;
......@@ -273,6 +304,7 @@ function createReceivers(rx_json, id) {
// const urlspan = document.createElement('span');
const mobilespan = document.createElement('span');
const invertspan = document.createElement('span');
const singlespan = document.createElement('span');
// const manualspan = document.createElement('span');
const idspan = document.createElement('span');
const locationspan = document.createElement('span');
......@@ -323,6 +355,7 @@ function createReceivers(rx_json, id) {
// urlspan.id = receivers[i].uid + "-url";
mobilespan.id = receivers[i].uid + "-mobile";
invertspan.id = receivers[i].uid + "-invert";
singlespan.id = receivers[i].uid + "-single";
// manualspan.id = receivers[i].uid + "-manual";
idspan.id = receivers[i].uid + "-id";
locationspan.id = receivers[i].uid + "-location";
......@@ -333,6 +366,7 @@ function createReceivers(rx_json, id) {
// rxcard.appendChild(urlspan);
rxcard.appendChild(mobilespan);
rxcard.appendChild(singlespan);
rxcard.appendChild(invertspan);
// rxcard.appendChild(manualspan);
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