-
Notifications
You must be signed in to change notification settings - Fork 0
/
_calculated.py
89 lines (66 loc) · 2.44 KB
/
_calculated.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python3
from fw_sim7600.sim7600._definitions import *
# Calculation defaults and constants
# N/A
# Calculation methods
# SIM and Network
def calc_network_registration(property_cache) -> bool:
try:
status_code = property_cache['network_status_code']['value']
except KeyError as err:
raise ValueError("Missing required property: {}".format(err))
return status_code == 1 or status_code == 5
def calc_network_searching(property_cache) -> bool:
try:
status_code = property_cache['network_status_code']['value']
except KeyError as err:
raise ValueError("Missing required property: {}".format(err))
return status_code == 2
def calc_network_roaming(property_cache) -> bool:
try:
status_code = property_cache['network_status_code']['value']
except KeyError as err:
raise ValueError("Missing required property: {}".format(err))
return status_code == 5
def calc_network_signal_quality(property_cache) -> float:
try:
rssi = property_cache['network_signal_quality_rssi']['value']
ber = property_cache['network_signal_quality_ber']['value']
except KeyError as err:
raise ValueError("Missing required property: {}".format(err))
# Default values from SIM7600
# RSSI_MIN = -116
# RSSI_MAX = -25
# BER_MIN = 0
# BER_MAX = 10
# Adjusted constants on 2G/3G and LTE requirements
RSSI_MIN = -100
RSSI_MAX = -60
BER_MIN = 0
BER_MAX = 10
if rssi == 0:
return -1 # Invalid
if rssi <= RSSI_MIN:
return 0.0 # No signal
if rssi >= RSSI_MAX:
rssi = RSSI_MAX
rssi_percent = min((rssi - RSSI_MIN) / (RSSI_MAX - RSSI_MIN), 100.0)
if ber == -1:
return round(rssi_percent * 100, 2)
if ber <= BER_MIN:
return round(rssi_percent * 100, 2)
if ber >= BER_MAX:
ber = BER_MAX
ber_percent = (ber - BER_MIN) / (BER_MAX - BER_MIN)
ber_weight = -0.2
signal_quality = rssi_percent + (ber_percent * ber_weight)
return max(0.0, round(signal_quality * 100, 2))
def calc_network_sim_status(property_cache) -> bool:
status_code = property_cache['network_sim_status_code']['value']
return status_code == SIM_STATUSES_WORKING_KEY
# GNSS
def calc_pos_gnss_sat_count(property_cache):
try:
return property_cache['pos_gnss_sat_gps_count']['value']
except KeyError as err:
raise ValueError("Missing required property: {}".format(err))