2019-05-04 18:26:11 +00:00
|
|
|
import subprocess
|
2019-05-07 15:09:29 +00:00
|
|
|
from owrx.config import PropertyManager, FeatureDetector
|
2019-05-04 18:26:11 +00:00
|
|
|
import threading
|
|
|
|
import csdr
|
2019-05-05 15:34:40 +00:00
|
|
|
import time
|
2019-05-07 15:30:30 +00:00
|
|
|
import os
|
|
|
|
import signal
|
2019-05-04 18:26:11 +00:00
|
|
|
|
2019-05-09 20:44:29 +00:00
|
|
|
class SdrService(object):
|
|
|
|
sdrProps = None
|
|
|
|
sources = {}
|
|
|
|
lastPort = None
|
|
|
|
@staticmethod
|
|
|
|
def getNextPort():
|
|
|
|
pm = PropertyManager.getSharedInstance()
|
|
|
|
(start, end) = pm["iq_port_range"]
|
|
|
|
if SdrService.lastPort is None:
|
|
|
|
SdrService.lastPort = start
|
|
|
|
else:
|
|
|
|
SdrService.lastPort += 1
|
|
|
|
if SdrService.lastPort > end:
|
|
|
|
raise IndexError("no more available ports to start more sdrs")
|
|
|
|
return SdrService.lastPort
|
|
|
|
@staticmethod
|
|
|
|
def getSource(id = None):
|
|
|
|
if SdrService.sdrProps is None:
|
|
|
|
pm = PropertyManager.getSharedInstance()
|
|
|
|
def loadIntoPropertyManager(dict: dict):
|
|
|
|
propertyManager = PropertyManager()
|
|
|
|
for (name, value) in dict.items():
|
|
|
|
propertyManager[name] = value
|
|
|
|
return propertyManager
|
|
|
|
SdrService.sdrProps = dict((name, loadIntoPropertyManager(value)) for (name, value) in pm["sdrs"].items())
|
|
|
|
print(SdrService.sdrProps)
|
|
|
|
if id is None:
|
|
|
|
# TODO: configure default sdr in config? right now it will pick the first one off the list.
|
|
|
|
id = list(SdrService.sdrProps.keys())[0]
|
|
|
|
if not id in SdrService.sources:
|
|
|
|
SdrService.sources[id] = SdrSource(SdrService.sdrProps[id], SdrService.getNextPort())
|
|
|
|
return SdrService.sources[id]
|
|
|
|
|
|
|
|
sdr_types = {
|
|
|
|
"rtl_sdr": {
|
|
|
|
"command": "rtl_sdr -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain} -",
|
|
|
|
"format_conversion": "csdr convert_u8_f"
|
|
|
|
},
|
|
|
|
"hackrf": {
|
|
|
|
"command": "hackrf_transfer -s {samp_rate} -f {center_freq} -g {rf_gain} -l{lna_gain} -a{rf_amp} -r-",
|
|
|
|
"format_conversion": "csdr convert_s8_f"
|
|
|
|
},
|
|
|
|
"sdrplay": {
|
|
|
|
"command": "rx_sdr -F CF32 -s {samp_rate} -f {center_freq} -p {ppm} -g {rf_gain} -",
|
|
|
|
"format_conversion": None,
|
|
|
|
"sleep": 1
|
2019-05-07 15:30:30 +00:00
|
|
|
}
|
2019-05-09 20:44:29 +00:00
|
|
|
}
|
2019-05-07 15:30:30 +00:00
|
|
|
|
2019-05-09 20:44:29 +00:00
|
|
|
class SdrSource(object):
|
|
|
|
def __init__(self, props, port):
|
|
|
|
self.props = props
|
|
|
|
self.rtlProps = self.props.collect(
|
|
|
|
"type", "samp_rate", "nmux_memory", "center_freq", "ppm", "rf_gain", "lna_gain", "rf_amp"
|
|
|
|
).defaults(PropertyManager.getSharedInstance())
|
2019-05-07 15:09:29 +00:00
|
|
|
|
|
|
|
def restart(name, value):
|
2019-05-09 20:44:29 +00:00
|
|
|
print("restarting sdr source due to property change: {0} changed to {1}".format(name, value))
|
2019-05-07 15:30:30 +00:00
|
|
|
self.stop()
|
|
|
|
self.start()
|
2019-05-09 20:44:29 +00:00
|
|
|
self.rtlProps.wire(restart)
|
|
|
|
self.port = port
|
|
|
|
self.monitor = None
|
2019-05-07 15:09:29 +00:00
|
|
|
|
2019-05-09 20:44:29 +00:00
|
|
|
def getProps(self):
|
|
|
|
return self.props
|
|
|
|
|
|
|
|
def getPort(self):
|
|
|
|
return self.port
|
2019-05-07 15:09:29 +00:00
|
|
|
|
2019-05-07 15:30:30 +00:00
|
|
|
def start(self):
|
2019-05-09 20:44:29 +00:00
|
|
|
if self.monitor: return
|
2019-05-07 15:30:30 +00:00
|
|
|
|
2019-05-09 20:44:29 +00:00
|
|
|
props = self.rtlProps
|
2019-05-07 15:30:30 +00:00
|
|
|
|
2019-05-07 18:06:06 +00:00
|
|
|
featureDetector = FeatureDetector()
|
2019-05-09 20:44:29 +00:00
|
|
|
if not featureDetector.is_available(props["type"]):
|
2019-05-07 18:06:06 +00:00
|
|
|
print("The RTL source type {0} is not available. please check requirements.".format(props["rtl_type"]))
|
|
|
|
return
|
|
|
|
|
2019-05-09 20:44:29 +00:00
|
|
|
self.params = sdr_types[props["type"]]
|
2019-05-07 15:09:29 +00:00
|
|
|
|
2019-05-09 14:12:32 +00:00
|
|
|
start_sdr_command = self.params["command"].format(
|
2019-05-07 15:09:29 +00:00
|
|
|
samp_rate = props["samp_rate"],
|
|
|
|
center_freq = props["center_freq"],
|
|
|
|
ppm = props["ppm"],
|
|
|
|
rf_gain = props["rf_gain"],
|
|
|
|
lna_gain = props["lna_gain"],
|
|
|
|
rf_amp = props["rf_amp"]
|
|
|
|
)
|
|
|
|
|
2019-05-09 14:12:32 +00:00
|
|
|
if self.params["format_conversion"] is not None:
|
|
|
|
start_sdr_command += " | " + self.params["format_conversion"]
|
2019-05-04 18:26:11 +00:00
|
|
|
|
|
|
|
nmux_bufcnt = nmux_bufsize = 0
|
2019-05-07 14:32:53 +00:00
|
|
|
while nmux_bufsize < props["samp_rate"]/4: nmux_bufsize += 4096
|
|
|
|
while nmux_bufsize * nmux_bufcnt < props["nmux_memory"] * 1e6: nmux_bufcnt += 1
|
2019-05-04 18:26:11 +00:00
|
|
|
if nmux_bufcnt == 0 or nmux_bufsize == 0:
|
2019-05-05 20:09:48 +00:00
|
|
|
print("[RtlNmuxSource] Error: nmux_bufsize or nmux_bufcnt is zero. These depend on nmux_memory and samp_rate options in config_webrx.py")
|
2019-05-04 18:26:11 +00:00
|
|
|
return
|
2019-05-05 20:09:48 +00:00
|
|
|
print("[RtlNmuxSource] nmux_bufsize = %d, nmux_bufcnt = %d" % (nmux_bufsize, nmux_bufcnt))
|
2019-05-09 20:44:29 +00:00
|
|
|
cmd = start_sdr_command + " | nmux --bufsize %d --bufcnt %d --port %d --address 127.0.0.1" % (nmux_bufsize, nmux_bufcnt, self.port)
|
2019-05-07 15:30:30 +00:00
|
|
|
self.process = subprocess.Popen(cmd, shell=True, preexec_fn=os.setpgrp)
|
2019-05-05 20:09:48 +00:00
|
|
|
print("[RtlNmuxSource] Started rtl source: " + cmd)
|
2019-05-07 15:30:30 +00:00
|
|
|
|
|
|
|
# TODO use this to monitor unexpected failures / shutdowns and react accordingly
|
|
|
|
def wait_for_process_to_end():
|
|
|
|
rc = self.process.wait()
|
|
|
|
print("[RtlNmuxSource] shut down with RC={0}".format(rc))
|
2019-05-09 20:44:29 +00:00
|
|
|
self.monitor = None
|
2019-05-07 15:30:30 +00:00
|
|
|
|
2019-05-09 14:12:32 +00:00
|
|
|
self.monitor = threading.Thread(target = wait_for_process_to_end)
|
|
|
|
self.monitor.start()
|
2019-05-07 15:30:30 +00:00
|
|
|
|
2019-05-09 20:44:29 +00:00
|
|
|
self.spectrumThread = SpectrumThread(self)
|
|
|
|
|
2019-05-07 15:30:30 +00:00
|
|
|
def stop(self):
|
|
|
|
os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)
|
2019-05-09 14:12:32 +00:00
|
|
|
self.monitor.join()
|
|
|
|
if "sleep" in self.params:
|
|
|
|
time.sleep(self.params["sleep"])
|
2019-05-04 18:26:11 +00:00
|
|
|
|
2019-05-09 20:44:29 +00:00
|
|
|
class SpectrumThread(object):
|
|
|
|
def __init__(self, sdrSource):
|
2019-05-04 18:26:11 +00:00
|
|
|
self.clients = []
|
2019-05-09 20:44:29 +00:00
|
|
|
self.doRun = False
|
|
|
|
self.sdrSource = sdrSource
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
threading.Thread(target = self.run).start()
|
2019-05-04 18:26:11 +00:00
|
|
|
|
|
|
|
def run(self):
|
2019-05-09 20:44:29 +00:00
|
|
|
props = self.sdrSource.props.collect(
|
2019-05-07 15:09:29 +00:00
|
|
|
"samp_rate", "fft_size", "fft_fps", "fft_voverlap_factor", "fft_compression",
|
2019-05-09 20:44:29 +00:00
|
|
|
"csdr_dynamic_bufsize", "csdr_print_bufsizes", "csdr_through"
|
|
|
|
).defaults(PropertyManager.getSharedInstance())
|
2019-05-07 14:32:53 +00:00
|
|
|
|
|
|
|
dsp = csdr.dsp()
|
2019-05-09 20:44:29 +00:00
|
|
|
dsp.nc_port = self.sdrSource.getPort()
|
2019-05-04 18:26:11 +00:00
|
|
|
dsp.set_demodulator("fft")
|
2019-05-09 14:52:42 +00:00
|
|
|
props.getProperty("samp_rate").wire(dsp.set_samp_rate)
|
|
|
|
props.getProperty("fft_size").wire(dsp.set_fft_size)
|
|
|
|
props.getProperty("fft_fps").wire(dsp.set_fft_fps)
|
|
|
|
props.getProperty("fft_compression").wire(dsp.set_fft_compression)
|
|
|
|
|
|
|
|
def set_fft_averages(key, value):
|
|
|
|
samp_rate = props["samp_rate"]
|
|
|
|
fft_size = props["fft_size"]
|
|
|
|
fft_fps = props["fft_fps"]
|
|
|
|
fft_voverlap_factor = props["fft_voverlap_factor"]
|
|
|
|
|
|
|
|
dsp.set_fft_averages(int(round(1.0 * samp_rate / fft_size / fft_fps / (1.0 - fft_voverlap_factor))) if fft_voverlap_factor>0 else 0)
|
|
|
|
props.collect("samp_rate", "fft_size", "fft_fps", "fft_voverlap_factor").wire(set_fft_averages)
|
|
|
|
set_fft_averages(None, None)
|
|
|
|
|
2019-05-07 14:32:53 +00:00
|
|
|
dsp.csdr_dynamic_bufsize = props["csdr_dynamic_bufsize"]
|
|
|
|
dsp.csdr_print_bufsizes = props["csdr_print_bufsizes"]
|
|
|
|
dsp.csdr_through = props["csdr_through"]
|
2019-05-04 18:26:11 +00:00
|
|
|
print("[openwebrx-spectrum] Spectrum thread initialized successfully.")
|
|
|
|
dsp.start()
|
2019-05-07 14:32:53 +00:00
|
|
|
if props["csdr_dynamic_bufsize"]:
|
2019-05-04 18:26:11 +00:00
|
|
|
dsp.read(8) #dummy read to skip bufsize & preamble
|
|
|
|
print("[openwebrx-spectrum] Note: CSDR_DYNAMIC_BUFSIZE_ON = 1")
|
|
|
|
print("[openwebrx-spectrum] Spectrum thread started.")
|
|
|
|
bytes_to_read=int(dsp.get_fft_bytes_to_read())
|
|
|
|
while self.doRun:
|
|
|
|
data=dsp.read(bytes_to_read)
|
2019-05-07 13:21:16 +00:00
|
|
|
if len(data) == 0:
|
2019-05-07 16:19:53 +00:00
|
|
|
time.sleep(1)
|
2019-05-07 13:21:16 +00:00
|
|
|
else:
|
|
|
|
for c in self.clients:
|
|
|
|
c.write_spectrum_data(data)
|
2019-05-04 18:26:11 +00:00
|
|
|
|
2019-05-07 16:19:53 +00:00
|
|
|
dsp.stop()
|
2019-05-04 18:26:11 +00:00
|
|
|
print("spectrum thread shut down")
|
|
|
|
|
|
|
|
def add_client(self, c):
|
|
|
|
self.clients.append(c)
|
2019-05-09 20:44:29 +00:00
|
|
|
if not self.doRun:
|
|
|
|
self.doRun = True
|
|
|
|
self.start()
|
2019-05-04 18:26:11 +00:00
|
|
|
|
|
|
|
def remove_client(self, c):
|
2019-05-09 20:44:29 +00:00
|
|
|
try:
|
|
|
|
self.clients.remove(c)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2019-05-04 18:26:11 +00:00
|
|
|
if not self.clients:
|
|
|
|
self.shutdown()
|
|
|
|
|
|
|
|
def shutdown(self):
|
|
|
|
print("shutting down spectrum thread")
|
2019-05-04 21:11:13 +00:00
|
|
|
self.doRun = False
|
|
|
|
|
2019-05-05 14:17:55 +00:00
|
|
|
class DspManager(object):
|
2019-05-09 20:44:29 +00:00
|
|
|
def __init__(self, handler, sdrSource):
|
2019-05-04 21:11:13 +00:00
|
|
|
self.doRun = True
|
|
|
|
self.handler = handler
|
2019-05-09 20:44:29 +00:00
|
|
|
self.sdrSource = sdrSource
|
2019-05-04 21:11:13 +00:00
|
|
|
|
2019-05-09 20:44:29 +00:00
|
|
|
self.localProps = self.sdrSource.getProps().collect(
|
2019-05-07 15:09:29 +00:00
|
|
|
"audio_compression", "fft_compression", "digimodes_fft_size", "csdr_dynamic_bufsize",
|
2019-05-09 20:44:29 +00:00
|
|
|
"csdr_print_bufsizes", "csdr_through", "digimodes_enable", "samp_rate"
|
|
|
|
).defaults(PropertyManager.getSharedInstance())
|
2019-05-04 21:11:13 +00:00
|
|
|
|
|
|
|
self.dsp = csdr.dsp()
|
|
|
|
#dsp_initialized=False
|
2019-05-07 14:32:53 +00:00
|
|
|
self.localProps.getProperty("audio_compression").wire(self.dsp.set_audio_compression)
|
|
|
|
self.localProps.getProperty("fft_compression").wire(self.dsp.set_fft_compression)
|
2019-05-04 21:11:13 +00:00
|
|
|
self.dsp.set_offset_freq(0)
|
|
|
|
self.dsp.set_bpf(-4000,4000)
|
2019-05-07 14:32:53 +00:00
|
|
|
self.localProps.getProperty("digimodes_fft_size").wire(self.dsp.set_secondary_fft_size)
|
2019-05-05 13:51:33 +00:00
|
|
|
|
2019-05-09 20:44:29 +00:00
|
|
|
self.dsp.nc_port = self.sdrSource.getPort()
|
2019-05-07 14:32:53 +00:00
|
|
|
self.dsp.csdr_dynamic_bufsize = self.localProps["csdr_dynamic_bufsize"]
|
|
|
|
self.dsp.csdr_print_bufsizes = self.localProps["csdr_print_bufsizes"]
|
|
|
|
self.dsp.csdr_through = self.localProps["csdr_through"]
|
2019-05-05 13:51:33 +00:00
|
|
|
|
2019-05-07 14:32:53 +00:00
|
|
|
self.localProps.getProperty("samp_rate").wire(self.dsp.set_samp_rate)
|
2019-05-05 13:51:33 +00:00
|
|
|
|
|
|
|
self.localProps.getProperty("output_rate").wire(self.dsp.set_output_rate)
|
|
|
|
self.localProps.getProperty("offset_freq").wire(self.dsp.set_offset_freq)
|
|
|
|
self.localProps.getProperty("squelch_level").wire(self.dsp.set_squelch_level)
|
|
|
|
|
|
|
|
def set_low_cut(cut):
|
|
|
|
bpf = self.dsp.get_bpf()
|
|
|
|
bpf[0] = cut
|
|
|
|
self.dsp.set_bpf(*bpf)
|
|
|
|
self.localProps.getProperty("low_cut").wire(set_low_cut)
|
|
|
|
|
|
|
|
def set_high_cut(cut):
|
|
|
|
bpf = self.dsp.get_bpf()
|
|
|
|
bpf[1] = cut
|
|
|
|
self.dsp.set_bpf(*bpf)
|
|
|
|
self.localProps.getProperty("high_cut").wire(set_high_cut)
|
|
|
|
|
2019-05-08 14:31:52 +00:00
|
|
|
self.localProps.getProperty("mod").wire(self.dsp.set_demodulator)
|
2019-05-05 13:51:33 +00:00
|
|
|
|
2019-05-07 14:32:53 +00:00
|
|
|
if (self.localProps["digimodes_enable"]):
|
2019-05-05 18:36:50 +00:00
|
|
|
def set_secondary_mod(mod):
|
2019-05-07 13:21:16 +00:00
|
|
|
if mod == False: mod = None
|
|
|
|
if self.dsp.get_secondary_demodulator() == mod: return
|
2019-05-05 20:09:48 +00:00
|
|
|
self.stopSecondaryThreads()
|
2019-05-05 18:36:50 +00:00
|
|
|
self.dsp.stop()
|
2019-05-08 14:31:52 +00:00
|
|
|
self.dsp.set_secondary_demodulator(mod)
|
|
|
|
if mod is not None:
|
2019-05-05 20:09:48 +00:00
|
|
|
self.handler.write_secondary_dsp_config({
|
2019-05-07 14:32:53 +00:00
|
|
|
"secondary_fft_size":self.localProps["digimodes_fft_size"],
|
2019-05-05 20:09:48 +00:00
|
|
|
"if_samp_rate":self.dsp.if_samp_rate(),
|
|
|
|
"secondary_bw":self.dsp.secondary_bw()
|
|
|
|
})
|
2019-05-05 18:36:50 +00:00
|
|
|
self.dsp.start()
|
|
|
|
|
2019-05-05 20:09:48 +00:00
|
|
|
if mod:
|
|
|
|
self.startSecondaryThreads()
|
|
|
|
|
2019-05-05 18:36:50 +00:00
|
|
|
self.localProps.getProperty("secondary_mod").wire(set_secondary_mod)
|
|
|
|
|
|
|
|
self.localProps.getProperty("secondary_offset_freq").wire(self.dsp.set_secondary_offset_freq)
|
|
|
|
|
2019-05-04 21:11:13 +00:00
|
|
|
super().__init__()
|
|
|
|
|
2019-05-05 14:17:55 +00:00
|
|
|
def start(self):
|
2019-05-04 21:11:13 +00:00
|
|
|
self.dsp.start()
|
2019-05-05 14:17:55 +00:00
|
|
|
threading.Thread(target = self.readDspOutput).start()
|
|
|
|
threading.Thread(target = self.readSMeterOutput).start()
|
|
|
|
|
2019-05-05 20:09:48 +00:00
|
|
|
def startSecondaryThreads(self):
|
|
|
|
self.runSecondary = True
|
|
|
|
self.secondaryDemodThread = threading.Thread(target = self.readSecondaryDemod)
|
|
|
|
self.secondaryDemodThread.start()
|
|
|
|
self.secondaryFftThread = threading.Thread(target = self.readSecondaryFft)
|
|
|
|
self.secondaryFftThread.start()
|
|
|
|
|
|
|
|
def stopSecondaryThreads(self):
|
|
|
|
self.runSecondary = False
|
|
|
|
self.secondaryDemodThread = None
|
|
|
|
self.secondaryFftThread = None
|
|
|
|
|
2019-05-05 14:17:55 +00:00
|
|
|
def readDspOutput(self):
|
2019-05-04 21:11:13 +00:00
|
|
|
while (self.doRun):
|
|
|
|
data = self.dsp.read(256)
|
2019-05-07 13:21:16 +00:00
|
|
|
if len(data) != 256:
|
|
|
|
time.sleep(1)
|
|
|
|
else:
|
|
|
|
self.handler.write_dsp_data(data)
|
2019-05-04 21:11:13 +00:00
|
|
|
|
2019-05-05 14:17:55 +00:00
|
|
|
def readSMeterOutput(self):
|
|
|
|
while (self.doRun):
|
|
|
|
level = self.dsp.get_smeter_level()
|
|
|
|
self.handler.write_s_meter_level(level)
|
|
|
|
|
2019-05-05 20:09:48 +00:00
|
|
|
def readSecondaryDemod(self):
|
|
|
|
while (self.runSecondary):
|
|
|
|
data = self.dsp.read_secondary_demod(1)
|
|
|
|
self.handler.write_secondary_demod(data)
|
|
|
|
|
|
|
|
def readSecondaryFft(self):
|
|
|
|
while (self.runSecondary):
|
|
|
|
data = self.dsp.read_secondary_fft(int(self.dsp.get_secondary_fft_bytes_to_read()))
|
|
|
|
self.handler.write_secondary_fft(data)
|
|
|
|
|
2019-05-04 21:11:13 +00:00
|
|
|
def stop(self):
|
|
|
|
self.doRun = False
|
2019-05-07 13:21:16 +00:00
|
|
|
self.runSecondary = False
|
2019-05-05 17:46:13 +00:00
|
|
|
self.dsp.stop()
|
2019-05-04 21:11:13 +00:00
|
|
|
|
2019-05-05 13:51:33 +00:00
|
|
|
def setProperty(self, prop, value):
|
|
|
|
self.localProps.getProperty(prop).setValue(value)
|
2019-05-05 15:34:40 +00:00
|
|
|
|
|
|
|
class CpuUsageThread(threading.Thread):
|
|
|
|
sharedInstance = None
|
|
|
|
@staticmethod
|
|
|
|
def getSharedInstance():
|
|
|
|
if CpuUsageThread.sharedInstance is None:
|
|
|
|
CpuUsageThread.sharedInstance = CpuUsageThread()
|
|
|
|
CpuUsageThread.sharedInstance.start()
|
|
|
|
return CpuUsageThread.sharedInstance
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.clients = []
|
|
|
|
self.doRun = True
|
|
|
|
self.last_worktime = 0
|
|
|
|
self.last_idletime = 0
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
while self.doRun:
|
|
|
|
time.sleep(3)
|
|
|
|
try:
|
|
|
|
cpu_usage = self.get_cpu_usage()
|
|
|
|
except:
|
|
|
|
cpu_usage = 0
|
|
|
|
for c in self.clients:
|
|
|
|
c.write_cpu_usage(cpu_usage)
|
|
|
|
print("cpu usage thread shut down")
|
|
|
|
|
|
|
|
def get_cpu_usage(self):
|
|
|
|
try:
|
|
|
|
f = open("/proc/stat","r")
|
|
|
|
except:
|
|
|
|
return 0 #Workaround, possibly we're on a Mac
|
|
|
|
line = ""
|
|
|
|
while not "cpu " in line: line=f.readline()
|
|
|
|
f.close()
|
|
|
|
spl = line.split(" ")
|
|
|
|
worktime = int(spl[2]) + int(spl[3]) + int(spl[4])
|
|
|
|
idletime = int(spl[5])
|
|
|
|
dworktime = (worktime - self.last_worktime)
|
|
|
|
didletime = (idletime - self.last_idletime)
|
|
|
|
rate = float(dworktime) / (didletime+dworktime)
|
|
|
|
self.last_worktime = worktime
|
|
|
|
self.last_idletime = idletime
|
|
|
|
if (self.last_worktime==0): return 0
|
|
|
|
return rate
|
|
|
|
|
|
|
|
def add_client(self, c):
|
|
|
|
self.clients.append(c)
|
|
|
|
|
|
|
|
def remove_client(self, c):
|
2019-05-09 20:44:29 +00:00
|
|
|
try:
|
|
|
|
self.clients.remove(c)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2019-05-05 15:34:40 +00:00
|
|
|
if not self.clients:
|
|
|
|
self.shutdown()
|
|
|
|
|
|
|
|
def shutdown(self):
|
|
|
|
print("shutting down cpu usage thread")
|
|
|
|
CpuUsageThread.sharedInstance = None
|
|
|
|
self.doRun = False
|