Skip to content

Commit 82ef951

Browse files
committed
rpc_wrappers: lte_state_v2: added
Add wrapper for `lte_state_v2`, copied from `lte_state`. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 13078a0 commit 82ef951

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env python3
2+
3+
import ipaddress
4+
5+
import infuse_iot.definitions.rpc as defs
6+
from infuse_iot.commands import InfuseRpcCommand
7+
from infuse_iot.zephyr import lte as z_lte
8+
from infuse_iot.zephyr import net_if as z_nif
9+
from infuse_iot.zephyr.errno import errno
10+
11+
12+
class lte_state_v2(InfuseRpcCommand, defs.lte_state_v2):
13+
@classmethod
14+
def add_parser(cls, parser):
15+
return
16+
17+
def __init__(self, args):
18+
self.args = args
19+
20+
def request_struct(self):
21+
return self.request()
22+
23+
def request_json(self):
24+
return {}
25+
26+
def handle_response(self, return_code, response):
27+
if return_code != 0:
28+
print(f"Failed to query current time ({errno.strerror(-return_code)})")
29+
return
30+
31+
common = response.common
32+
lte = response.lte
33+
34+
# Address formatting
35+
ipv4 = ipaddress.IPv4Address(bytes(common.ipv4))
36+
ipv6 = ipaddress.IPv6Address(bytes(common.ipv6))
37+
38+
reg_class = z_lte.RegistrationState
39+
lte_state = reg_class(lte.registration_state)
40+
41+
print("Interface State:")
42+
print(f"\t State: {z_nif.OperationalState(common.state).name}")
43+
print(f"\t IF Flags: {z_nif.InterfaceFlags(common.if_flags)}")
44+
print(f"\t L2 Flags: {z_nif.L2Flags(common.l2_flags)}")
45+
print(f"\t MTU: {common.mtu}")
46+
print(f"\t IPv4: {ipv4}")
47+
print(f"\t IPv6: {ipv6}")
48+
print("LTE State:")
49+
print(f"\t Reg State: {lte_state}")
50+
51+
valid = (
52+
lte_state == reg_class.REGISTERED_HOME
53+
or lte_state == reg_class.REGISTERED_ROAMING
54+
or lte_state == reg_class.SEARCHING
55+
)
56+
access_tech = z_lte.AccessTechnology(lte.access_technology)
57+
if valid:
58+
if lte.earfcn != 0:
59+
freq_dl, freq_ul = z_lte.LteBands.earfcn_to_freq(lte.earfcn)
60+
freq_string = f" (UL: {int(freq_ul)}MHz, DL: {int(freq_dl)}MHz)"
61+
else:
62+
freq_string = ""
63+
country = z_lte.MobileCountryCodes.name_from_mcc(lte.mcc)
64+
active_str = f"{lte.psm_active_time} s" if lte.psm_active_time != 65535 else "N/A"
65+
edrx_interval_str = f"{lte.edrx_interval} s" if lte.edrx_interval != -1.0 else "N/A"
66+
edrx_window_str = f"{lte.edrx_paging_window} s" if lte.edrx_paging_window != -1.0 else "N/A"
67+
as_rai = defs.rpc_enum_support_status(lte.as_rai)
68+
cp_rai = defs.rpc_enum_support_status(lte.cp_rai)
69+
70+
print(f"\t Access Tech: {access_tech}")
71+
print(f"\t Country Code: {lte.mcc} ({country})")
72+
print(f"\t Network Code: {lte.mnc}")
73+
print(f"\t Cell ID: {lte.cell_id}")
74+
print(f"\t Tracking Area: {lte.tac}")
75+
print(f"\t TAU: {lte.tau} s")
76+
print(f"\t EARFCN: {lte.earfcn}{freq_string}")
77+
print(f"\t Band: {lte.band}")
78+
print(f"\tPSM Active Time: {active_str}")
79+
print(f"\t eDRX Interval: {edrx_interval_str}")
80+
print(f"\t eDRX Window: {edrx_window_str}")
81+
print(f"\t RSRP: {lte.rsrp} dBm")
82+
print(f"\t RSRQ: {lte.rsrq} dB")
83+
print(f"\t AS-RAI: {as_rai.name}")
84+
print(f"\t CP-RAI: {cp_rai.name}")

0 commit comments

Comments
 (0)