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
46 changes: 45 additions & 1 deletion src/infuse_iot/generated/tdf_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ class activity_metric(TdfReadingBase):
}

class algorithm_output(TdfReadingBase):
"""Generic activity metric"""
"""Instantaneous algorithm output"""

name = "ALGORITHM_OUTPUT"
_fields_ = [
Expand Down Expand Up @@ -861,6 +861,48 @@ class bluetooth_data_throughput(TdfReadingBase):
"throughput": "{}",
}

class algorithm_class_histogram(TdfReadingBase):
"""Algorithm output class histogram over a time window"""

name = "ALGORITHM_CLASS_HISTOGRAM"
_fields_ = [
("algorithm_id", ctypes.c_uint32),
("algorithm_version", ctypes.c_uint16),
("classes", 0 * ctypes.c_uint8),
]
_pack_ = 1
_postfix_ = {
"algorithm_id": "",
"algorithm_version": "",
"classes": "",
}
_display_fmt_ = {
"algorithm_id": "0x{:08x}",
"algorithm_version": "{}",
"classes": "{}",
}

class algorithm_class_time_series(TdfReadingBase):
"""Algorithm output class time series vector"""

name = "ALGORITHM_CLASS_TIME_SERIES"
_fields_ = [
("algorithm_id", ctypes.c_uint32),
("algorithm_version", ctypes.c_uint16),
("values", 0 * ctypes.c_uint8),
]
_pack_ = 1
_postfix_ = {
"algorithm_id": "",
"algorithm_version": "",
"values": "",
}
_display_fmt_ = {
"algorithm_id": "0x{:08x}",
"algorithm_version": "{}",
"values": "{}",
}

class array_type(TdfReadingBase):
"""Example array type"""

Expand Down Expand Up @@ -906,5 +948,7 @@ class array_type(TdfReadingBase):
29: readings.bluetooth_connection,
30: readings.bluetooth_rssi,
31: readings.bluetooth_data_throughput,
32: readings.algorithm_class_histogram,
33: readings.algorithm_class_time_series,
100: readings.array_type,
}
7 changes: 7 additions & 0 deletions src/infuse_iot/rpc_wrappers/coap_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def add_parser(cls, parser):
const=rpc_enum_file_action.APP_IMG,
help="Download complete image file and perform DFU",
)
group.add_argument(
"--cpatch",
dest="action",
action="store_const",
const=rpc_enum_file_action.APP_CPATCH,
help="Download CPatch binary diff and perform DFU",
)
group.add_argument(
"--nrf91-modem",
dest="action",
Expand Down
31 changes: 25 additions & 6 deletions src/infuse_iot/tools/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from infuse_iot.common import InfuseID, InfuseType
from infuse_iot.epacket.packet import PacketOutput, PacketReceived
from infuse_iot.socket_comms import (
ClientNotification,
ClientNotificationConnectionDropped,
ClientNotificationEpacketReceived,
GatewayRequestConnectionRequest,
Expand All @@ -36,6 +37,7 @@ def add_parser(cls, parser):
addr_group = parser.add_mutually_exclusive_group(required=True)
addr_group.add_argument("--gateway", action="store_true", help="Run command on local gateway")
addr_group.add_argument("--id", type=lambda x: int(x, 0), help="Infuse ID to run command on")
parser.add_argument("--conn-log", action="store_true", help="Request logs from remote device")
command_list_parser = parser.add_subparsers(title="commands", metavar="<command>", required=True)

for _, name, _ in pkgutil.walk_packages(wrappers.__path__):
Expand Down Expand Up @@ -73,9 +75,20 @@ def _finalise_command(self, rpc_rsp: PacketReceived):
print(f"INFUSE ID: {rpc_rsp.route[0].infuse_id:016x}")
self._command.handle_response(rsp_header.return_code, rsp_data)

def _client_recv(self) -> ClientNotification | None:
rsp = self._client.receive()
if (
rsp
and self._args.conn_log
and isinstance(rsp, ClientNotificationEpacketReceived)
and rsp.epacket.ptype == InfuseType.SERIAL_LOG
):
print(rsp.epacket.payload.decode("utf-8"), end="")
return rsp

def _wait_data_ack(self) -> PacketReceived:
while True:
rsp = self._client.receive()
rsp = self._client_recv()
if rsp is None:
continue
if not isinstance(rsp, ClientNotificationEpacketReceived):
Expand All @@ -95,7 +108,7 @@ def _wait_data_ack(self) -> PacketReceived:
def _wait_rpc_rsp(self) -> PacketReceived:
# Wait for responses
while True:
rsp = self._client.receive()
rsp = self._client_recv()
if rsp is None:
continue
if not isinstance(rsp, ClientNotificationEpacketReceived):
Expand Down Expand Up @@ -180,7 +193,7 @@ def _run_data_recv_cmd(self):
req = GatewayRequestEpacketSend(pkt)
self._client.send(req)

while rsp := self._client.receive():
while rsp := self._client_recv():
if isinstance(rsp, ClientNotificationConnectionDropped):
break
if not isinstance(rsp, ClientNotificationEpacketReceived):
Expand Down Expand Up @@ -224,15 +237,21 @@ def _run_standard_cmd(self):

def run(self):
try:
self._max_payload = self._client.connection_create(
self._id, GatewayRequestConnectionRequest.DataType.COMMAND
)
types = GatewayRequestConnectionRequest.DataType.COMMAND
if self._args.conn_log:
types |= GatewayRequestConnectionRequest.DataType.LOGGING
self._max_payload = self._client.connection_create(self._id, types)
if self._command.RPC_DATA_SEND:
self._run_data_send_cmd()
elif self._command.RPC_DATA_RECEIVE:
self._run_data_recv_cmd()
else:
self._run_standard_cmd()

if self._args.conn_log:
while True:
self._client_recv()

except ConnectionRefusedError:
print(f"Unable to connect to {self._id:016x}")
finally:
Expand Down
Loading