Commit c1cf0ef6 by Corey Koval

Receiver handling improvements

parent b3aa7c67
# DF Aggregator # DF Aggregator
## New Features 1 December 2020:
- Receivers can be added from the WebUI
- Click the + at the bottom of the receiver cards, enter the URL, click save.
Click the refresh button to update the cards and map.
- A list of receiver URLs is now optional. Receivers are saved to the database.
- Receivers are read from the database first. Duplicate receiver URLs are ignored.
- You can mark a receiver as mobile.
- Click the edit icon for the applicable receiver, click the checkbox to mark
it as mobile, then click save.
- You can now delete receivers from the list. This will remove it from the map
and database. No historical data is affected.
- You can now enable/disable LOB collection from individual receivers.
Click the power button to enable/disable.
- Black is enabled, red is disabled.
- If you lose connectivity to a receiver, that particular receiver will be disabled.
Click the power button to try to reconnect.
## Dependencies: ## Dependencies:
- Python >= 3.6 - Python >= 3.6
- [numpy](https://numpy.org/install/) - [numpy](https://numpy.org/install/)
......
...@@ -46,15 +46,14 @@ class receiver: ...@@ -46,15 +46,14 @@ class receiver:
self.isAuto = True self.isAuto = True
# hashed_url = hashlib.md5(station_url.encode('utf-8')).hexdigest() # hashed_url = hashlib.md5(station_url.encode('utf-8')).hexdigest()
# self.uid = hashed_url[:5] + hashed_url[-5:] # self.uid = hashed_url[:5] + hashed_url[-5:]
try: self.update(first_run=True)
self.update() self.isActive = True
except:
raise IOError
# Updates receiver from the remote URL # Updates receiver from the remote URL
def update(self): 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')
...@@ -81,7 +80,20 @@ class receiver: ...@@ -81,7 +80,20 @@ class receiver:
except KeyboardInterrupt: except KeyboardInterrupt:
finish() finish()
except: except:
raise IOError if first_run:
self.station_id = "Unknown"
self.latitude = 0.0
self.longitude = 0.0
self.heading = 0.0
self.raw_doa = 0.0
self.doa = 0.0
self.frequency = 0.0
self.power = 0.0
self.confidence = 0
self.doa_time = 0
self.isActive = False
print(f"Problem connecting to {self.station_url}, receiver deactivated. Reactivate in WebUI.")
# raise IOError
# Returns receivers properties as a dict, # Returns receivers properties as a dict,
# useful for passing data to the WebUI # useful for passing data to the WebUI
...@@ -102,7 +114,6 @@ class receiver: ...@@ -102,7 +114,6 @@ class receiver:
confidence = 0 confidence = 0
doa_time = 0 doa_time = 0
isMobile = False isMobile = False
isActive = True
############################################### ###############################################
# Converts Lat/Lon to polar coordinates # Converts Lat/Lon to polar coordinates
...@@ -473,9 +484,11 @@ def update_cesium(): ...@@ -473,9 +484,11 @@ def update_cesium():
############################################### ###############################################
@get('/rx_params') @get('/rx_params')
def rx_params(): def rx_params():
write_czml(*process_data(database_name, geofile))
all_rx = {'receivers':{}} all_rx = {'receivers':{}}
rx_properties = [] rx_properties = []
for index, x in enumerate(receivers): for index, x in enumerate(receivers):
x.update()
rx = x.receiver_dict() rx = x.receiver_dict()
rx['uid'] = index rx['uid'] = index
rx_properties.append(rx) rx_properties.append(rx)
...@@ -497,6 +510,10 @@ def update_rx(action): ...@@ -497,6 +510,10 @@ def update_rx(action):
index = int(data['uid']) index = int(data['uid'])
del_receiver(receivers[index].station_id) del_receiver(receivers[index].station_id)
del receivers[index] del receivers[index]
elif action == "activate":
index = int(data['uid'])
receivers[index].isActive = data['state']
# print(f"RX {index} changed state to {data['state']}")
else: else:
action = int(action) action = int(action)
try: try:
...@@ -564,10 +581,10 @@ def run_receiver(receivers): ...@@ -564,10 +581,10 @@ def run_receiver(receivers):
for rx in receivers: for rx in receivers:
try: try:
rx.update() if rx.isActive: rx.update()
except IOError: except IOError:
print("Problem connecting to receiver.") print("Problem connecting to receiver.")
ms.receiving = False # ms.receiving = False
time.sleep(1) time.sleep(1)
if dots > 5: if dots > 5:
...@@ -607,8 +624,9 @@ def add_receiver(receiver_url): ...@@ -607,8 +624,9 @@ def add_receiver(receiver_url):
[new_rx['station_id']]).fetchone()[0] [new_rx['station_id']]).fetchone()[0]
receivers[-1].isMobile = bool(mobile) receivers[-1].isMobile = bool(mobile)
print("Created new DF Station at " + receiver_url) print("Created new DF Station at " + receiver_url)
except IOError: except AttributeError:
ms.receiving = False pass
conn.close() conn.close()
############################################### ###############################################
...@@ -716,7 +734,6 @@ if __name__ == '__main__': ...@@ -716,7 +734,6 @@ if __name__ == '__main__':
############################################### ###############################################
read_rx_table() read_rx_table()
if rx_file: if rx_file:
print("I got a file!")
with open(rx_file, "r") as file2: with open(rx_file, "r") as file2:
receiver_list = file2.readlines() receiver_list = file2.readlines()
for x in receiver_list: for x in receiver_list:
......
...@@ -110,6 +110,21 @@ body { ...@@ -110,6 +110,21 @@ body {
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0); transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
} }
#add_station {
width: 23px;
height: 23px;
}
#new_rx_div {
position: relative;
background: #d4d4d4;
color: #111;
font-weight: bold;
padding: 5px;
margin: 5px;
vertical-align: middle;
}
.receiver { .receiver {
position: relative; position: relative;
background: #d4d4d4; background: #d4d4d4;
...@@ -138,6 +153,20 @@ body { ...@@ -138,6 +153,20 @@ body {
font-size: 23pt; font-size: 23pt;
} }
.delete-icon {
display: block;
position: absolute;
top: 5px;
right: 30px;
}
.activate-icon {
display: block;
position: absolute;
top: 5px;
right: 60px;
}
.edit-checkbox { .edit-checkbox {
cursor: pointer; cursor: pointer;
opacity: 0; /* hide this */ opacity: 0; /* hide this */
...@@ -146,13 +175,6 @@ body { ...@@ -146,13 +175,6 @@ body {
height: 20px; height: 20px;
} }
.delete-icon {
display: block;
position: absolute;
top: 5px;
right: 30px;
}
.no-select { .no-select {
-webkit-user-select: none; /* Safari */ -webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */ -khtml-user-select: none; /* Konqueror HTML */
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
loadRx(refreshRx); loadRx(refreshRx);
clearOld(); clearOld();
loadCzml(); loadCzml();
console.log(response); // console.log(response);
} }
}) })
} }
...@@ -45,13 +45,13 @@ ...@@ -45,13 +45,13 @@
function loadCzml() { function loadCzml() {
var dataSourcePromise = Cesium.CzmlDataSource.load('/static/output.czml'); var dataSourcePromise = Cesium.CzmlDataSource.load('/static/output.czml');
viewer.dataSources.add(dataSourcePromise); viewer.dataSources.add(dataSourcePromise);
console.log("Loaded CZML"); // console.log("Loaded CZML");
return dataSourcePromise; return dataSourcePromise;
} }
function clearOld() { function clearOld() {
viewer.dataSources.removeAll(true); viewer.dataSources.removeAll(true);
console.log("Cleared old"); // console.log("Cleared old");
} }
// Add Cesium OSM Buildings, a global 3D buildings layer. // Add Cesium OSM Buildings, a global 3D buildings layer.
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
<input id="add_station" class="edit-checkbox add-icon" type="checkbox" style="width: 23px; height: 23px;"/> <input id="add_station" class="edit-checkbox add-icon" type="checkbox" style="width: 23px; height: 23px;"/>
<span id="add_station_icon" class="material-icons add-icon no-select">add_circle_outline</span> <span id="add_station_icon" class="material-icons add-icon no-select">add_circle_outline</span>
<div style="visibility: hidden; height: 0;" id="new_rx_div" style="padding: 0;" class="receiver"> <div style="visibility: hidden; height: 0;" id="new_rx_div" style="padding: 0;">
<span id="new-url">Station URL: <span id="new-url">Station URL:
</span> </span>
</div> </div>
......
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