Skip to content

Commit af3a2bc

Browse files
committed
Show RF path temperature for 8812eu
1 parent 035d0ca commit af3a2bc

File tree

3 files changed

+80
-8
lines changed

3 files changed

+80
-8
lines changed

wfb_ng/cli.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def draw_tx(self, attrs):
193193
p = attrs['packets']
194194
latency_d = attrs['latency']
195195
tx_id = attrs['id']
196+
rf_temperature = attrs['rf_temperature']
196197

197198
window = self.factory.windows.get(tx_id)
198199
if window is None:
@@ -218,12 +219,23 @@ def draw_tx(self, attrs):
218219
human_rate(p['injected_bytes'][0])))
219220

220221
if latency_d:
221-
addstr_markup(window, 2, 20, '{[ANT] pkt/s} {Injection} [us]')
222+
addstr_markup(window, 2, 20, '{[ANT] pkt/s} {\u00b0C} {Injection} [us]')
222223
for y, (k, v) in enumerate(sorted(latency_d.items()), 3):
223224
k = int(k) # json doesn't support int keys
224225
injected, dropped, lat_min, lat_avg, lat_max = v
226+
227+
# Show max temperature from all antenna's RF paths
228+
temp = max((_v for _k, _v in rf_temperature.items() if (_k >> 8) == (k >> 8)), default=None)
229+
if temp is not None:
230+
if temp >= settings.common.temp_overheat_warning:
231+
temp = '{%d}' % (temp,)
232+
else:
233+
temp = str(temp)
234+
else:
235+
temp = ' (--)'
236+
225237
if y < ymax:
226-
addstr_markup(window, y, 21, '{%02x}(XX) %4d %4d < {%4d} < %4d' % (k >> 8, injected, lat_min, lat_avg, lat_max))
238+
addstr_markup(window, y, 21, '{%02x}(XX) %4d %3s %4d < {%4d} < %4d' % (k >> 8, injected, temp, lat_min, lat_avg, lat_max))
227239
else:
228240
addstr_noerr(window, 2, 20, '[No data]', curses.A_REVERSE)
229241

wfb_ng/conf/master.cfg

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ wifi_channel = 165 # radio channel @5825 MHz, range: 5815-5835 MHz, width
2727
# {'wlan0': 161, 'wlan1': 165}
2828

2929
wifi_region = 'BO' # Set CRDA region
30-
wifi_txpower = None # Some cards don't support tx power settings
31-
#wifi_txpower = 58 # Doesn't affect 8812au drivers, use module parameter instead
30+
wifi_txpower = None # Leave None to use default power settings from driver.
31+
# For 8812au set to -dBm * 100. I.e for 30dBm set to -3000
32+
# For 8812eu set to dBm * 100. I.e for 30dBm set to 3000
33+
34+
temp_measurement_interval = 10 # [s] (8812eu only) Internal RF path temp measurement.
35+
temp_overheat_warning = 60 # [*C] (8812eu only) Overheat warning threshold.
3236

3337

3438
## Stream allocation scheme:

wfb_ng/server.py

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from itertools import groupby
2828
from twisted.python import log, failure
2929
from twisted.python.logfile import LogFile
30-
from twisted.internet import reactor, defer, main as ti_main
30+
from twisted.internet import reactor, defer, main as ti_main, threads, task
3131
from twisted.internet.protocol import ProcessProtocol, Protocol, Factory
3232
from twisted.protocols.basic import LineReceiver, Int32StringReceiver
3333
from twisted.internet.serialport import SerialPort
@@ -83,6 +83,7 @@ class StatsAndSelectorFactory(Factory):
8383
"""
8484

8585
def __init__(self, profile, wlans, link_domain):
86+
self.wlans = tuple(wlans)
8687
self.ant_sel_cb_list = []
8788
self.rssi_cb_l = []
8889

@@ -96,6 +97,46 @@ def __init__(self, profile, wlans, link_domain):
9697
# CLI title
9798
self.cli_title = 'WFB-ng_%s @%s %s [%s]' % (settings.common.version, profile, ', '.join(wlans), link_domain)
9899

100+
# RF module temperature by rf_path
101+
self.rf_temperature = {}
102+
103+
self.lc = task.LoopingCall(self.read_temperature)
104+
self.lc.start(settings.common.temp_measurement_interval, now=True)
105+
106+
def _cleanup(self):
107+
self.lc.stop()
108+
109+
def read_temperature(self):
110+
def _read_temperature():
111+
res = {}
112+
for idx, wlan in enumerate(self.wlans):
113+
fname = '/proc/net/rtl88x2eu/%s/thermal_state' % (wlan,)
114+
try:
115+
with open(fname) as fd:
116+
for line in fd:
117+
line = line.strip()
118+
if not line:
119+
continue
120+
121+
d = {}
122+
for f in line.split(','):
123+
k, v = f.split(':', 1)
124+
d[k.strip()] = int(v.strip())
125+
126+
ant_id = (idx << 8) + d['rf_path']
127+
res[ant_id] = d['temperature']
128+
except FileNotFoundError:
129+
pass
130+
except Exception as v:
131+
reactor.callFromThread(log.err, v, 'Unable to parse %s:' % (fname,))
132+
return res
133+
134+
def _got_temp(temp_d):
135+
self.rf_temperature = temp_d
136+
137+
return threads.deferToThread(_read_temperature).addCallback(_got_temp)
138+
139+
99140
def add_ant_sel_cb(self, ant_sel_cb):
100141
self.ant_sel_cb_list.append(ant_sel_cb)
101142
ant_sel_cb(self.tx_sel)
@@ -208,7 +249,10 @@ def update_tx_stats(self, tx_id, packet_stats, ant_latency):
208249

209250
# Send stats to CLI sessions
210251
for s in self.ui_sessions:
211-
s.send_stats(dict(type='tx', id=tx_id, packets=packet_stats, latency=ant_latency))
252+
s.send_stats(dict(type='tx', id=tx_id,
253+
packets=packet_stats,
254+
latency=ant_latency,
255+
rf_temperature=self.rf_temperature))
212256

213257

214258

@@ -506,21 +550,33 @@ def init(profiles, wlans):
506550
yield init_wlans(max_bw, wlans)
507551

508552
dl = []
553+
sockets = []
554+
ant_sel_l = []
555+
556+
def _cleanup(x):
557+
for s in sockets:
558+
s.stopListening()
559+
560+
for f in ant_sel_l:
561+
f._cleanup()
562+
563+
return x
509564

510565
for profile, service_list in services:
511566
# Domain wide antenna selector
512567
profile_cfg = getattr(settings, profile)
513568
ant_sel_f = StatsAndSelectorFactory(profile, wlans, profile_cfg.link_domain)
569+
ant_sel_l.append(ant_sel_f)
514570
link_id = int.from_bytes(hashlib.sha1(profile_cfg.link_domain.encode('utf-8')).digest()[:3], 'big')
515571

516572
if profile_cfg.stats_port:
517-
reactor.listenTCP(profile_cfg.stats_port, ant_sel_f)
573+
sockets.append(reactor.listenTCP(profile_cfg.stats_port, ant_sel_f))
518574

519575
for service_name, service_type, srv_cfg in service_list:
520576
log.msg('Starting %s/%s@%s on %s' % (profile, service_name, profile_cfg.link_domain, ', '.join(wlans)))
521577
dl.append(defer.maybeDeferred(type_map[service_type], service_name, srv_cfg, wlans, link_id, ant_sel_f))
522578

523-
yield defer.gatherResults(dl, consumeErrors=True).addErrback(lambda f: f.trap(defer.FirstError) and f.value.subFailure)
579+
yield defer.gatherResults(dl, consumeErrors=True).addBoth(_cleanup).addErrback(lambda f: f.trap(defer.FirstError) and f.value.subFailure)
524580

525581

526582
def init_udp_direct_tx(service_name, cfg, wlans, link_id, ant_sel_f):

0 commit comments

Comments
 (0)