Skip to content

Commit

Permalink
added P key shortcut to turn off DXCLUSTER client
Browse files Browse the repository at this point in the history
  • Loading branch information
mcogoni committed Feb 15, 2022
1 parent 13e621b commit ae0a6f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
17 changes: 13 additions & 4 deletions supersdr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

import _thread
from optparse import OptionParser
from utils_supersdr import *

Expand Down Expand Up @@ -189,6 +188,7 @@

current_string = []

old_spot_dict = None
if dxclust:
print(dxclust)
dxclust.connect()
Expand Down Expand Up @@ -266,8 +266,16 @@
if keys[pygame.K_i]:
fl.show_eibi_flag = False if fl.show_eibi_flag else True

# Show realtime DX-CLUSTER labels
if keys[pygame.K_d]:
# Disconnect DXCLUSTER, but save previous spot list
if keys[pygame.K_p]:
if dxclust:
old_spot_dict = dxclust.spot_dict
fl.show_dxcluster_flag = False
dxclust.disconnect()
dxclust = None

# Show realtime DX-CLUSTER labels, if DXCLUSTER disabled, enable it first
elif keys[pygame.K_d]:
if dxclust:
fl.show_dxcluster_flag = False if fl.show_dxcluster_flag else True
if fl.show_dxcluster_flag:
Expand Down Expand Up @@ -686,7 +694,8 @@
dxclust.connect()
dx_t = threading.Thread(target=dxclust.run, args=(kiwi_wf,), daemon=True)
dx_t.start()

if old_spot_dict:
dxclust.spot_dict = old_spot_dict
dx_cluster_msg = True
fl.show_dxcluster_flag = True
else:
Expand Down
30 changes: 16 additions & 14 deletions utils_supersdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def bytearray2str(b):
"- Z: Center KIWI RX, shift WF instead",
"- SPACE: FORCE SYNC of WF to RX if no CAT, else sync to CAT",
"- X: AUTO MODE ON/OFF depending on amateur/broadcast band",
"- I/D: displays EIBI/DXCLUSTER labels",
"- D/P: enable or hide DXCLUSTER, P disconnect DXCLUSTER",
"- I: show/hide EIBI database stations",
"- Q: switch to a different KIWI server",
"- 1/2 & 3: adjust AGC threshold, 3 switch WF autoscale",
"- SHIFT+ESC: quits",
Expand Down Expand Up @@ -174,15 +175,25 @@ def __init__(self, mycall_):
host, port = 'dxfun.com', 8000
self.server = (host, port)
self.spot_dict = {}
self.visible_stations = []
self.terminate = False
self.failed_counter = 0
self.update_now = False

def disconnect(self):
self.terminate = True
try:
self.sock.shutdown(1)
self.sock.close()
except:
pass
print("DXCLuster disconnected!")

def connect(self):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connected = False
while not connected:
print(f'Connection to: {self.server}')
print("Connecting to: %s:%d" % self.server)
try:
self.sock.connect(self.server)
except:
Expand All @@ -194,7 +205,6 @@ def connect(self):
connected = True
# self.sock.settimeout(0.1)
self.send(self.mycall)
self.visible_stations = []
self.time_to_live = 1200 # seconds for a spot to live
self.last_update = datetime.utcnow()
self.last_cleanup = datetime.utcnow()
Expand Down Expand Up @@ -253,16 +263,7 @@ def run(self, kiwi_wf):
dx_cluster_msg = self.receive()
except:
continue
# if not dx_cluster_msg:
# self.failed_counter += 1
# print("DX Cluster void response")
# if self.failed_counter > 5:
# self.sock.close()
# time.sleep(5)
# self.connect()
# time.sleep(5)
# continue
# self.failed_counter = 0

spot_str = "%s"%dx_cluster_msg
stored_something_flag = False
for line in spot_str.replace("\x07", "").split("\n"):
Expand All @@ -288,6 +289,7 @@ def run(self, kiwi_wf):
# print("DXCLUST: updated visible spots")
self.last_update = datetime.utcnow()
self.update_now = False
# print("Exited from DXCLUSTER loop")

def store_spot(self, qrg_, callsign_, utc_, spot_msg_):
spot_id = next(self.uniqueid()) # create a unique hash for each spot
Expand Down Expand Up @@ -1275,7 +1277,7 @@ def display_box(self, screen, message, size):
def display_help_box(self, screen, message_list):
font_size = font_size_dict["small"]

window_size = 495
window_size = 505 #495
pygame.draw.rect(screen, (0,0,0),
((screen.get_width() / 2) - window_size/2,
(screen.get_height() / 2) - window_size/3,
Expand Down

0 comments on commit ae0a6f5

Please sign in to comment.