Skip to content

Commit

Permalink
Add network_type to thermald (#1030)
Browse files Browse the repository at this point in the history
* add network_type to thermal log

* move get_network_type to android library
  • Loading branch information
valish committed Feb 1, 2020
1 parent 75fdebb commit 7709035
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cereal
Submodule cereal updated 1 files
+10 −0 log.capnp
31 changes: 31 additions & 0 deletions common/android.py
Expand Up @@ -89,3 +89,34 @@ def parse_service_call_bytes(ret):
return r
except Exception:
return None

def get_network_type(NetworkType):

This comment has been minimized.

Copy link
@geohot

geohot Feb 3, 2020

Contributor

@valish Why is NetworkType passed in here! Also, this didn't check if parse_service_call_string returned None, and as such, would crash on PC.

wifi_check = parse_service_call_string(service_call(["connectivity", "2"]))
if 'WIFI' in wifi_check:
return NetworkType.wifi
else:
cell_check = parse_service_call_unpack(service_call(['phone', '59']), ">q")
cell_networks = {
0: NetworkType.none,
1: NetworkType.cell2G,
2: NetworkType.cell2G,
4: NetworkType.cell2G,
7: NetworkType.cell2G,
11: NetworkType.cell2G,
16: NetworkType.cell2G,
3: NetworkType.cell3G,
5: NetworkType.cell3G,
6: NetworkType.cell3G,
8: NetworkType.cell3G,
9: NetworkType.cell3G,
10: NetworkType.cell3G,
12: NetworkType.cell3G,
13: NetworkType.cell3G,
14: NetworkType.cell3G,
15: NetworkType.cell3G,
17: NetworkType.cell3G,
18: NetworkType.cell4G,
19: NetworkType.cell4G,
20: NetworkType.cell5G
}
return cell_networks.get(cell_check, NetworkType.none)
5 changes: 3 additions & 2 deletions selfdrive/thermald.py
Expand Up @@ -6,7 +6,7 @@
import psutil
from smbus2 import SMBus
from cereal import log
from common.android import ANDROID
from common.android import ANDROID, get_network_type
from common.basedir import BASEDIR
from common.params import Params
from common.realtime import sec_since_boot, DT_TRML
Expand All @@ -21,6 +21,7 @@
FW_SIGNATURE = get_expected_signature()

ThermalStatus = log.ThermalData.ThermalStatus
NetworkType = log.ThermalData.NetworkType
CURRENT_TAU = 15. # 15s time constant
DAYS_NO_CONNECTIVITY_MAX = 7 # do not allow to engage after a week without internet
DAYS_NO_CONNECTIVITY_PROMPT = 4 # send an offroad prompt after 4 days with no internet
Expand Down Expand Up @@ -135,7 +136,6 @@ def handle_fan_uno(max_cpu_temp, bat_temp, fan_speed, ignition):

return new_speed


def thermald_thread():
# prevent LEECO from undervoltage
BATT_PERC_OFF = 10 if LEON else 3
Expand Down Expand Up @@ -192,6 +192,7 @@ def thermald_thread():
msg.thermal.freeSpace = get_available_percent(default=100.0) / 100.0
msg.thermal.memUsedPercent = int(round(psutil.virtual_memory().percent))
msg.thermal.cpuPerc = int(round(psutil.cpu_percent()))
msg.thermal.networkType = get_network_type(NetworkType)

try:
with open("/sys/class/power_supply/battery/capacity") as f:
Expand Down

0 comments on commit 7709035

Please sign in to comment.