1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-03 06:24:48 -04:00

Scripts API: SuperScanner: add timestamp in log messages

This commit is contained in:
f4exb
2020-05-30 15:18:07 +02:00
parent dd78ae98d9
commit b947724710
+10 -4
View File
@@ -14,6 +14,7 @@ except ImportError:
import _thread as thread
import time
from datetime import datetime
from optparse import OptionParser
import sdrangel
@@ -47,6 +48,11 @@ class SuperScannerOptionsError(SuperScannerError):
class SuperScannerAPIError(SuperScannerError):
pass
# ======================================================================
def log_with_timestamp(message):
t = datetime.utcnow()
print(f'{t.isoformat()} {message}')
# ======================================================================
def get_input_options(args=None):
if args is None:
@@ -139,7 +145,7 @@ def on_ws_close(ws):
# ======================================================================
def on_ws_open(ws):
print('Starting...')
log_with_timestamp('Starting...')
def run(*args):
pass
thread.start_new_thread(run, ())
@@ -324,12 +330,12 @@ def process_hotspots(scanned_hotspots):
channel['usage'] = 2 # mark channel used on this pass
channel['frequency'] = channel_frequency
set_channel_frequency(channel)
print(f'Channel {channel_index} allocated on frequency {channel_frequency} Hz')
log_with_timestamp(f'Channel {channel_index} allocated on frequency {channel_frequency} Hz')
else:
fc = hotspot['fc']
if fc not in UNSERVED_FREQUENCIES:
UNSERVED_FREQUENCIES.append(fc)
print(f'All channels allocated. Cannot process signal at {fc} Hz')
log_with_timestamp(f'All channels allocated. Cannot process signal at {fc} Hz')
# cleanup
for channel in CONFIG['channel_info']:
if channel['usage'] == 1: # channel unused on this pass
@@ -338,7 +344,7 @@ def process_hotspots(scanned_hotspots):
fc = channel['frequency']
set_channel_mute(channel)
UNSERVED_FREQUENCIES.clear() # at least one channel is able to serve next time
print(f'Released channel {channel_index} on frequency {fc} Hz')
log_with_timestamp(f'Released channel {channel_index} on frequency {fc} Hz')
elif channel['usage'] == 2: # channel used on this pass
channel['usage'] = 1 # reset usage for next pass