Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/infuse_iot/socket_comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def from_json(cls, values: dict) -> Self:
return cast(Self, ClientNotificationConnectionDropped.from_json(values))
elif values["type"] == cls.Type.KNOWN_DEVICES:
return cast(Self, ClientNotificationObservedDevices.from_json(values))
raise NotImplementedError
raise NotImplementedError(f"Unknown notification: {values}")


class ClientNotificationEpacketReceived(ClientNotification):
Expand Down Expand Up @@ -147,7 +147,7 @@ def from_json(cls, values: dict) -> Self:
return cast(Self, GatewayRequestConnectionRelease.from_json(values))
elif values["type"] == cls.Type.KNOWN_DEVICES:
return cast(Self, GatewayRequestObservedDevices.from_json(values))
raise NotImplementedError
raise NotImplementedError(f"Unknown request: {values}")


class GatewayRequestEpacketSend(GatewayRequest):
Expand Down
11 changes: 8 additions & 3 deletions src/infuse_iot/tools/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ def add_parser(cls, parser):
info_parser = tool_parser.add_parser("info", help="General device information")
info_parser.set_defaults(command_fn=cls.info)
info_parser.add_argument("--id", type=str, required=True, help="Infuse-IoT device ID")
info_parser = tool_parser.add_parser("kv_state", help="Key-Value device state")
info_parser.set_defaults(command_fn=cls.kv_state)
info_parser.add_argument("--id", type=str, required=True, help="Infuse-IoT device ID")
kv_parser = tool_parser.add_parser("kv_state", help="Key-Value device state")
kv_parser.set_defaults(command_fn=cls.kv_state)
kv_parser.add_argument("--id", type=str, required=True, help="Infuse-IoT device ID")
kv_parser.add_argument("--schedules", action="store_true", help="Display task schedules")

def run(self):
with self.client() as client:
Expand Down Expand Up @@ -242,6 +243,10 @@ def kv_state(self, client: Client):
for element in kv_state:
key = element.key_name if isinstance(element.key_name, str) else str(element.key_id)

# Don't display task schedules unless requested
if key == "TASK_SCHEDULES" and not self.args.schedules:
continue

if isinstance(element.data, Unset):
table.append((key, "Not set"))
else:
Expand Down
6 changes: 5 additions & 1 deletion src/infuse_iot/tools/localhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def add_parser(cls, parser):
def __init__(self, args):
self._data_lock = threading.Lock()
self._columns: dict[str, dict] = {}
self._apps: set[str] = set()
self._data: dict[int, dict] = {}
self._port: int = args.port

Expand Down Expand Up @@ -130,6 +131,7 @@ async def websocket_handler(self, request: BaseRequest):
"columns": columns,
"rows": [self._data[d] for d in devices],
"tdfs": sorted(list(self._columns.keys())),
"apps": sorted(list(self._apps)),
}
self._data_lock.release()

Expand Down Expand Up @@ -219,7 +221,9 @@ def recv_thread(self) -> None:
if t.NAME not in self._data[source.infuse_id]:
self._data[source.infuse_id][t.NAME] = {}
if t.NAME in ["ANNOUNCE", "ANNOUNCE_V2"]:
self._data[source.infuse_id]["application"] = f"0x{t.application:08x}"
app_str = f"0x{t.application:08x}"
self._data[source.infuse_id]["application"] = app_str
self._apps.add(app_str)

for field in t.iter_fields(nested_iter=False):
if isinstance(field.val, structs.tdf_struct_mcuboot_img_sem_ver):
Expand Down
21 changes: 13 additions & 8 deletions src/infuse_iot/tools/localhost/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ <h1>Infuse-IoT TDF Viewer</h1>
a.every((element, index) => element === b[index]);

ws.onmessage = function (event) {
const { columns, rows, tdfs } = JSON.parse(event.data);
const { columns, rows, tdfs, apps } = JSON.parse(event.data);

if (!arraysEqual(currentTDFs, tdfs)) {
// Merge new data with the existing table data
Expand All @@ -150,13 +150,18 @@ <h1>Infuse-IoT TDF Viewer</h1>
disableData.map(row => [row.name, row.checked])
);

const uniqueApplications = [
...new Set(rows.map(obj => obj.application).filter(app => app !== undefined).sort())
];
if (!arraysEqual(currentApps, uniqueApplications)) {
versions = uniqueApplications.map((v, idx) => { return { id: `row-${idx}`, name: v, checked: true }; })
shownAppTable.replaceData(versions);
currentApps = uniqueApplications
if (!arraysEqual(currentApps, apps)) {
// Merge new data with the existing table data
const currentRows = shownAppTable.getData();
const updatedData = apps.map((str, index) => {
const existingRow = currentRows.find(row => row.name === str);
console.log(str, existingRow);
return existingRow
? existingRow // Preserve the existing row if found
: { id: `row-${index}`, name: str, checked: true };
});
shownAppTable.replaceData(updatedData);
currentApps = apps
filtering_update = true;
}

Expand Down