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
22 changes: 21 additions & 1 deletion src/infuse_iot/generated/tdf_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import ctypes

from infuse_iot.generated.tdf_base import TdfReadingBase, TdfStructBase
from infuse_iot.generated.tdf_base import TdfReadingBase, TdfStructBase # noqa F401


class structs:
Expand Down Expand Up @@ -1694,6 +1694,25 @@ class pcm_16bit_chan_dual(TdfReadingBase):
"right": "{}",
}

class kvs_value_changed(TdfReadingBase):
"""Record of key value store data updates"""

ID = 61
NAME = "KVS_VALUE_CHANGED"
_fields_ = [
("key", ctypes.c_uint16),
("value", 0 * ctypes.c_uint8),
]
_pack_ = 1
_postfix_ = {
"key": "",
"value": "",
}
_display_fmt_ = {
"key": "{}",
"value": "{}",
}


id_type_mapping: dict[int, type[TdfReadingBase]] = {
readings.announce.ID: readings.announce,
Expand Down Expand Up @@ -1755,6 +1774,7 @@ class pcm_16bit_chan_dual(TdfReadingBase):
readings.pcm_16bit_chan_left.ID: readings.pcm_16bit_chan_left,
readings.pcm_16bit_chan_right.ID: readings.pcm_16bit_chan_right,
readings.pcm_16bit_chan_dual.ID: readings.pcm_16bit_chan_dual,
readings.kvs_value_changed.ID: readings.kvs_value_changed,
}

__all__ = [
Expand Down
23 changes: 22 additions & 1 deletion src/infuse_iot/serial_comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
from pyocd.debug.rtt import GenericRTTControlBlock


class SerialBadNameException(Exception):
def __init__(self, requested: str, options: list[str]):
self.requested = requested
self.options = options


class SerialFrame:
"""Serial frame reconstructor"""

Expand Down Expand Up @@ -119,7 +125,22 @@ def __init__(self, rtt_device: str, serial_number: str | None = None):
def open(self, timeout: float | None = None):
self._jlink.open(serial_no=self._serial_number)
self._jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)
self._jlink.connect(self._name, 4000)
try:
self._jlink.connect(self._name, 4000)
except pylink.errors.JLinkException as e:
if e.message != "Unsupported device selected.":
# Not a device name error
raise e

# Find valid options
name_lower = self._name.lower()
options = []
for i in range(self._jlink.num_supported_devices()):
info = self._jlink.supported_device(i)
if info.name.lower().startswith(name_lower):
options.append(info.name)
raise SerialBadNameException(self._name, options) from e

self._jlink.rtt_start()

end_time = time.time() + timeout if timeout else None
Expand Down
3 changes: 2 additions & 1 deletion src/infuse_iot/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class base(enum.IntEnum):
GNSS = 1
NTP = 2
RPC = 3
INVALID = 4
EPACKET = 4
INVALID = 5

def __init__(self, value: int):
self.recovered: bool = value & 0x80 != 0
Expand Down
16 changes: 12 additions & 4 deletions src/infuse_iot/tools/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,29 @@ def info(self, client: Client):
]
if route.bt_adv:
table += [("BT Address", f"{route.bt_adv.address} ({route.bt_adv.type_})")]
if route.udp:
table += [("IP Address", route.udp.address)]

if isinstance(logger_states, list) and len(logger_states) > 0:
logger_names = {
0: "Onboard",
1: "Removable",
}

def val_or_na(value) -> str:
if isinstance(value, Unset):
return "N/A"
return str(value)

for logger in logger_states:
name = logger_names.get(logger.index, str(logger.index))
table += [
(f"~~~{name} Logger Sync~~~", ""),
("Last Report Time", logger.last_reported_time),
("Last Downloaded Time", logger.last_downloaded_time),
("Reported Block", logger.last_reported_block),
("Downloaded Block", logger.last_downloaded_block),
("Enabled", logger.download_enabled),
("Last Report Time", val_or_na(logger.last_reported_time)),
("Last Downloaded Time", val_or_na(logger.last_downloaded_time)),
("Reported Block", val_or_na(logger.last_reported_block)),
("Downloaded Block", val_or_na(logger.last_downloaded_block)),
]
if isinstance(logger.last_reported_block, int) and isinstance(logger.last_downloaded_block, int):
table += [("Block Lag", logger.last_reported_block - logger.last_downloaded_block)]
Expand Down
9 changes: 7 additions & 2 deletions src/infuse_iot/tools/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
PacketOutputRouted,
PacketReceived,
)
from infuse_iot.serial_comms import PyOcdPort, RttPort, SerialFrame, SerialLike, SerialPort
from infuse_iot.serial_comms import PyOcdPort, RttPort, SerialBadNameException, SerialFrame, SerialLike, SerialPort
from infuse_iot.socket_comms import (
ClientNotification,
ClientNotificationCommsCheck,
Expand Down Expand Up @@ -552,7 +552,12 @@ def __init__(self, args: argparse.Namespace):

def run(self):
# Open the serial port
self.port.open()
try:
self.port.open()
except SerialBadNameException as e:
tabbed_options = "\n".join(f"\t{o}" for o in e.options)
Console.log_error(f"Unknown name '{e.requested}', possible options:\n{tabbed_options}")
return
Console.log_info(f"Port '{str(self.port)}' opened")
# Ping the port to get the local device ID
self.port.ping()
Expand Down
Loading