From d73e4522fe3a98f0125701e44dc81cdefd245cc6 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Mon, 13 Jan 2025 17:53:23 +1000 Subject: [PATCH 1/5] README: update with credential storage info Update the README with useful information for the `keyring` credential storage, which is particulary relevant on WSL. Signed-off-by: Jordan Yates --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index e04170d..8e50e65 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,23 @@ commands: tdf_csv Save received TDFs in CSV files tdf_list Display received TDFs in a list ``` + +## Credential Storage + +Under linux, the preferred credential storage provider for the python ``keyring`` +package is provided by ``gnome-keyring``. The available backends can be listed with +``keyring --list-backends``. + +``` +sudo apt install gnome-keyring +``` + +### WSL Issues + +Under WSL, they keyring has been observed to consistently raise +``secretstorage.exceptions.PromptDismissedException: Prompt dismissed``. +This can be resolved by adding the following to ``~/.bashrc`` and reloading +the terminal. +``` +dbus-update-activation-environment --all > /dev/null 2>&1 +``` From 93061c6b0288c533f28a81d5d8d5e97fd21f5653 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Mon, 13 Jan 2025 17:55:10 +1000 Subject: [PATCH 2/5] README: update `infuse --help` output Update the example output of `infuse --help` with the various new tools. Signed-off-by: Jordan Yates --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8e50e65..c7f3673 100644 --- a/README.md +++ b/README.md @@ -22,18 +22,27 @@ eval "$(register-python-argcomplete infuse)" ## Usage ``` -infuse --help -usage: infuse [-h] ... +> infuse --help +usage: infuse [-h] [--version] ... options: -h, --help show this help message and exit + --version show program's version number and exit commands: + bt_log Connect to remote Bluetooth device serial logs + cloud Infuse-IoT cloud interaction + credentials Manage Infuse-IoT credentials csv_annotate Annotate CSV data csv_plot Plot CSV data gateway Connect to a local gateway device + localhost Run a local server for TDF viewing + native_bt Native Bluetooth gateway + ota_upgrade Automatically OTA upgrade observed devices + provision Provision device on Infuse Cloud rpc Run remote procedure calls on devices + rpc_cloud Manage remote procedure calls through Infuse-IoT cloud serial_throughput Test serial throughput to local gateway tdf_csv Save received TDFs in CSV files From d608b9e9542367949a8d92065e5b1b09aab0bba6 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Fri, 17 Jan 2025 11:50:16 +1000 Subject: [PATCH 3/5] tools: tdf_list: use local time for unknown TDF times Display the local PC time for TDF's that arrive without explicit timestamps. Signed-off-by: Jordan Yates --- src/infuse_iot/tools/tdf_list.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/infuse_iot/tools/tdf_list.py b/src/infuse_iot/tools/tdf_list.py index 56b58f2..f828fca 100644 --- a/src/infuse_iot/tools/tdf_list.py +++ b/src/infuse_iot/tools/tdf_list.py @@ -5,6 +5,8 @@ __author__ = "Jordan Yates" __copyright__ = "Copyright 2024, Embeint Inc" +import time + import tabulate from infuse_iot.commands import InfuseCommand @@ -44,7 +46,7 @@ def run(self) -> None: t = tdf.data[-1] num = len(tdf.data) if num > 1: - tdf_name = f"{t.name}[{num-1}]" + tdf_name = f"{t.name}[{num - 1}]" else: tdf_name = t.name @@ -52,13 +54,13 @@ def run(self) -> None: if idx == 0: if tdf.time is not None: if tdf.period is None: - time = InfuseTime.utc_time_string(tdf.time) + time_str = InfuseTime.utc_time_string(tdf.time) else: offset = (len(tdf.data) - 1) * tdf.period - time = InfuseTime.utc_time_string(tdf.time + offset) + time_str = InfuseTime.utc_time_string(tdf.time + offset) else: - time = "N/A" - table.append((time, tdf_name, field.name, field.val_fmt(), field.postfix)) + time_str = InfuseTime.utc_time_string(time.time()) + table.append((time_str, tdf_name, field.name, field.val_fmt(), field.postfix)) else: table.append((None, None, field.name, field.val_fmt(), field.postfix)) From f6a36545628d10eb99c74cb846cde6600041bc62 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Fri, 17 Jan 2025 11:51:32 +1000 Subject: [PATCH 4/5] tdf: handle iterating over unknown TDFs If a TDF ID is unknown, return it as a generic data blob. Signed-off-by: Jordan Yates --- src/infuse_iot/generated/tdf_definitions.py | 2 +- src/infuse_iot/tdf.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/infuse_iot/generated/tdf_definitions.py b/src/infuse_iot/generated/tdf_definitions.py index ad2016c..a9fceec 100644 --- a/src/infuse_iot/generated/tdf_definitions.py +++ b/src/infuse_iot/generated/tdf_definitions.py @@ -919,7 +919,7 @@ class array_type(TdfReadingBase): } -id_type_mapping: dict[int, TdfReadingBase] = { +id_type_mapping: dict[int, type[TdfReadingBase]] = { 1: readings.announce, 2: readings.battery_state, 3: readings.ambient_temp_pres_hum, diff --git a/src/infuse_iot/tdf.py b/src/infuse_iot/tdf.py index 3070347..5e15ec9 100644 --- a/src/infuse_iot/tdf.py +++ b/src/infuse_iot/tdf.py @@ -8,6 +8,19 @@ from infuse_iot.time import InfuseTime +def unknown_tdf_factory(tdf_id: int, tdf_len: int) -> type[tdf_base.TdfReadingBase]: + class UnknownTDF(tdf_base.TdfReadingBase): + name = str(tdf_id) + _fields_ = [ + ("data", tdf_len * ctypes.c_uint8), + ] + _pack_ = 1 + _postfix_ = {"data": ""} + _display_fmt_ = {"data": "{}"} + + return UnknownTDF + + class TDF: class flags(enum.IntEnum): TIMESTAMP_NONE = 0x0000 @@ -83,7 +96,10 @@ def decode(self, buffer: bytes) -> Generator[Reading, None, None]: time_flags = header.id_flags & self.flags.TIMESTAMP_MASK tdf_id = header.id_flags & 0x0FFF - id_type = tdf_definitions.id_type_mapping[tdf_id] + try: + id_type = tdf_definitions.id_type_mapping[tdf_id] + except KeyError: + id_type = unknown_tdf_factory(tdf_id, header.len) if time_flags == self.flags.TIMESTAMP_NONE: time = None From 446988c6decd173b2f26f095fbdff04c90cd080b Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Fri, 17 Jan 2025 14:29:16 +1000 Subject: [PATCH 5/5] LICENSE: added Add initial license for the python tools. Signed-off-by: Jordan Yates --- LICENSE | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..29441e0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,33 @@ +LicenseID: LicenseRef-Embeint + +Copyright (c) 2024 - Present, Embeint Inc +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code or in binary form must reproduce +the above copyright notice, this list of conditions and the following +disclaimer in the documentation and/or other materials provided with the +distribution. + +2. Neither the name of Embeint nor the names of its contributors may be +used to endorse or promote products derived from this software without +specific prior written permission. + +3. This software, with or without modification, must only be used with +Embeint services and integrated with the INFUSE-IoT platform. + +4. Any software provided in binary form under this license must not be +reverse engineered, decompiled, modified and/or disassembled. + +THIS SOFTWARE IS PROVIDED BY EMBEINT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, +NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL EMBEINT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE.