Skip to content

Commit 23d33b3

Browse files
committed
rpc_wrappers: remove custom VLA parsing logic
Remove the custom VLA parsing logic from commands since the builtin classes now handle them from the definitions. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent ff24fc4 commit 23d33b3

3 files changed

Lines changed: 10 additions & 95 deletions

File tree

src/infuse_iot/rpc_wrappers/kv_read.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,6 @@
1212

1313

1414
class kv_read(InfuseRpcCommand, defs.kv_read):
15-
class request(ctypes.LittleEndianStructure):
16-
_fields_ = [
17-
("num", ctypes.c_uint8),
18-
]
19-
_pack_ = 1
20-
21-
class response:
22-
@classmethod
23-
def from_buffer_copy(cls, source: bytes, _offset: int = 0) -> list:
24-
values = []
25-
while len(source) > 0:
26-
27-
class kv_store_header(ctypes.LittleEndianStructure):
28-
_fields_ = [
29-
("id", ctypes.c_uint16),
30-
("len", ctypes.c_int16),
31-
]
32-
_pack_ = 1
33-
34-
header = kv_store_header.from_buffer_copy(source)
35-
struct: ctypes.LittleEndianStructure
36-
if header.len > 0:
37-
38-
class kv_store_value(ctypes.LittleEndianStructure):
39-
_fields_ = [
40-
("id", ctypes.c_uint16),
41-
("len", ctypes.c_int16),
42-
("data", ctypes.c_ubyte * header.len),
43-
]
44-
_pack_ = 1
45-
46-
struct = kv_store_value.from_buffer_copy(source)
47-
else:
48-
struct = header
49-
values.append(struct)
50-
source = source[ctypes.sizeof(struct) :]
51-
return values
52-
53-
@classmethod
54-
def vla_from_buffer_copy(cls, source: bytes, offset: int = 0) -> list:
55-
return cls.from_buffer_copy(source, offset)
56-
5715
@classmethod
5816
def add_parser(cls, parser):
5917
parser.add_argument("--keys", "-k", required=True, type=int, nargs="+", help="Keys to read")
@@ -73,7 +31,7 @@ def handle_response(self, return_code, response):
7331
print(f"Invalid data buffer ({errno.strerror(-return_code)})")
7432
return
7533

76-
for r in response:
34+
for r in response.values:
7735
if r.len > 0:
7836
b = bytes(r.data)
7937
try:

src/infuse_iot/rpc_wrappers/lte_modem_info.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ class lte_modem_info(kv_read.kv_read):
1515
HELP = "Get LTE modem information"
1616
DESCRIPTION = "Get LTE modem information"
1717

18-
class request(kv_read.kv_read.request):
19-
pass
20-
21-
class response(kv_read.kv_read.response):
22-
pass
23-
2418
@classmethod
2519
def add_parser(cls, parser):
2620
return
@@ -43,9 +37,9 @@ def str_decode(r):
4337
return "Unknown"
4438
return str(kv_structs.kv_string.vla_from_buffer_copy(bytes(r.data)))
4539

46-
modem_imei = struct_decode(kv_slots.lte_modem_imei, response[3])
47-
pdp_ctx = struct_decode(kv_slots.lte_pdp_config, response[5])
48-
system_modes = struct_decode(kv_slots.lte_networking_modes, response[6])
40+
modem_imei = struct_decode(kv_slots.lte_modem_imei, response.values[3])
41+
pdp_ctx = struct_decode(kv_slots.lte_pdp_config, response.values[5])
42+
system_modes = struct_decode(kv_slots.lte_networking_modes, response.values[6])
4943

5044
if pdp_ctx:
5145
pdp_str = f'"{str(pdp_ctx.apn)}" ({lte_pdp_ctx.lte_pdp_ctx.PDPFamily(pdp_ctx.family).name})'
@@ -58,10 +52,10 @@ def str_decode(r):
5852
else:
5953
modes_str = "default"
6054

61-
print(f"\t Model: {str_decode(response[0])}")
62-
print(f"\tFirmware: {str_decode(response[1])}")
63-
print(f"\t ESN: {str_decode(response[2])}")
55+
print(f"\t Model: {str_decode(response.values[0])}")
56+
print(f"\tFirmware: {str_decode(response.values[1])}")
57+
print(f"\t ESN: {str_decode(response.values[2])}")
6458
print(f"\t IMEI: {modem_imei.imei}")
65-
print(f"\t SIM: {str_decode(response[4])}")
59+
print(f"\t SIM: {str_decode(response.values[4])}")
6660
print(f"\t APN: {pdp_str}")
6761
print(f"\t Mode: {modes_str}")

src/infuse_iot/rpc_wrappers/wifi_scan.py

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,6 @@
1111

1212

1313
class wifi_scan(InfuseRpcCommand, defs.wifi_scan):
14-
class response(ctypes.LittleEndianStructure):
15-
@classmethod
16-
def from_buffer_copy(cls, source, offset=0):
17-
values = []
18-
source = source[1:]
19-
while len(source) > 0:
20-
21-
class scan_rsp_header(ctypes.LittleEndianStructure):
22-
_fields_ = [
23-
("band", ctypes.c_uint8),
24-
("channel", ctypes.c_uint8),
25-
("security", ctypes.c_uint8),
26-
("rssi", ctypes.c_int8),
27-
("bssid", 6 * ctypes.c_char),
28-
("ssid_length", ctypes.c_uint8),
29-
]
30-
_pack_ = 1
31-
32-
header = scan_rsp_header.from_buffer_copy(source)
33-
34-
class scan_result(ctypes.LittleEndianStructure):
35-
_fields_ = [
36-
("band", ctypes.c_uint8),
37-
("channel", ctypes.c_uint8),
38-
("security", ctypes.c_uint8),
39-
("rssi", ctypes.c_int8),
40-
("bssid", 6 * ctypes.c_char),
41-
("ssid_length", ctypes.c_uint8),
42-
("ssid", header.ssid_length * ctypes.c_char),
43-
]
44-
_pack_ = 1
45-
46-
struct = scan_result.from_buffer_copy(source)
47-
values.append(struct)
48-
source = source[ctypes.sizeof(struct) :]
49-
return values
50-
5114
@classmethod
5215
def add_parser(cls, parser):
5316
return
@@ -64,12 +27,12 @@ def handle_response(self, return_code, response):
6427
return
6528

6629
table = []
67-
for network in response:
30+
for network in response.networks:
6831
bssid = ":".join([f"{b:02x}" for b in network.bssid])
6932

7033
table.append(
7134
[
72-
network.ssid.decode("utf-8"),
35+
bytes(network.ssid).decode("utf-8"),
7336
bssid,
7437
str(z_wifi.FrequencyBand(network.band)),
7538
network.channel,

0 commit comments

Comments
 (0)