Skip to content

Commit 73090b7

Browse files
committed
rpc_wrappers: json handling
Add json handling for a number of RPCs. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent cd33985 commit 73090b7

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/infuse_iot/rpc_wrappers/application_info.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,23 @@ def handle_response(self, return_code, response):
3535
print(f"\t KV CRC: 0x{r.kv_crc:08x}")
3636
print(f"\t O Blocks: {r.data_blocks_internal}")
3737
print(f"\t E Blocks: {r.data_blocks_external}")
38+
39+
@classmethod
40+
def handle_json_response(cls, response: dict) -> None:
41+
rsp = defs.application_info.response(
42+
int(response["application_id"]),
43+
defs.rpc_struct_mcuboot_img_sem_ver(
44+
int(response["version"]["major"]),
45+
int(response["version"]["minor"]),
46+
int(response["version"]["revision"]),
47+
int(response["version"]["build_num"]),
48+
),
49+
int(response["network_id"]),
50+
int(response["uptime"]),
51+
int(response["reboots"]),
52+
int(response["kv_crc"]),
53+
int(response["data_blocks_internal"]),
54+
int(response["data_blocks_external"]),
55+
)
56+
x = cls({})
57+
x.handle_response(0, rsp)

src/infuse_iot/rpc_wrappers/last_reboot.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,18 @@ def handle_response(self, return_code, response):
3838
print(f"\t Thread: {response.thread.decode('utf-8')}")
3939
for idx, val in enumerate(response.esf):
4040
print(f"\t ESF[{idx:2d}]: 0x{val:08x}")
41+
42+
@classmethod
43+
def handle_json_response(cls, response: dict) -> None:
44+
rsp = defs.last_reboot.response(
45+
int(response["reason"]),
46+
int(response["epoch_time_source"]),
47+
int(response["epoch_time"]),
48+
int(response["hardware_flags"]),
49+
int(response["uptime"]),
50+
int(response["param_1"]),
51+
int(response["param_2"]),
52+
)
53+
rsp.esf = [int(x) for x in response["esf"]]
54+
x = cls({})
55+
x.handle_response(0, rsp)

src/infuse_iot/rpc_wrappers/wifi_scan.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,28 @@ def handle_response(self, return_code, response):
4141

4242
headers = ["SSID", "BSSID", "Band", "Channel", "Security", "RSSI"]
4343
print(tabulate.tabulate(table, headers=headers))
44+
45+
@classmethod
46+
def handle_json_response(cls, response: dict) -> None:
47+
table = []
48+
for network in response["networks"]:
49+
bssid = ":".join([f"{int(b):02x}" for b in network["bssid"]])
50+
try:
51+
security = str(z_wifi.SecurityType(int(network["security"])))
52+
except ValueError:
53+
security = f"Unknown ({network['security']})"
54+
55+
table.append(
56+
[
57+
network["ssid"],
58+
bssid,
59+
str(z_wifi.FrequencyBand(int(network["band"]))),
60+
network["channel"],
61+
security,
62+
f"{network['rssi']} dBm",
63+
]
64+
)
65+
66+
headers = ["SSID", "BSSID", "Band", "Channel", "Security", "RSSI"]
67+
print(f"Total Networks: {response['network_count']}")
68+
print(tabulate.tabulate(table, headers=headers))

0 commit comments

Comments
 (0)