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
13 changes: 13 additions & 0 deletions src/infuse_iot/generated/kv_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ class device_name(VLACompatLittleEndianStruct):
vla_field = ("name", structs.kv_string)
_pack_ = 1

class infuse_application_id(VLACompatLittleEndianStruct):
"""CONFIG_INFUSE_APPLICATION_ID, store will be reset if the values don't match"""

NAME = "INFUSE_APPLICATION_ID"
BASE_ID = 5
RANGE = 1
_fields_ = [
("application_id", ctypes.c_uint32),
]
_pack_ = 1

class fixed_location(VLACompatLittleEndianStruct):
"""Fixed global location of the device"""

Expand Down Expand Up @@ -279,6 +290,7 @@ class lora_config(VLACompatLittleEndianStruct):
("coding_rate", ctypes.c_uint8),
("preamble_len", ctypes.c_uint16),
("tx_power", ctypes.c_int8),
("sync_word", ctypes.c_uint8),
]
_pack_ = 1

Expand Down Expand Up @@ -354,6 +366,7 @@ class secure_storage_reserved(VLACompatLittleEndianStruct):
2: exfat_disk_info,
3: bluetooth_ctlr_version,
4: device_name,
5: infuse_application_id,
10: fixed_location,
20: wifi_ssid,
21: wifi_psk,
Expand Down
10 changes: 8 additions & 2 deletions src/infuse_iot/rpc_wrappers/kv_bt_peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ def handle_response(self, return_code, response):

def print_status(name, rc):
if rc < 0:
print(f"{name} failed to write ({os.strerror(-rc)})")
if self.addr == b"":
print(f"{name} failed to delete ({os.strerror(-rc)})")
else:
print(f"{name} failed to write ({os.strerror(-rc)})")
elif rc == 0:
print(f"{name} already matched")
if self.addr == b"":
print(f"{name} deleted")
else:
print(f"{name} already matched")
else:
print(f"{name} updated")

Expand Down
19 changes: 18 additions & 1 deletion src/infuse_iot/tools/ota_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def __init__(self, args):
TransferSpeedColumn(),
)
self.task = None
if args.log is None:
self._log = None
else:
self._log = open(args.log, "+a", encoding="utf-8") # noqa: SIM115

@classmethod
def add_parser(cls, parser):
Expand All @@ -65,6 +69,7 @@ def add_parser(cls, parser):
)
parser.add_argument("--rssi", type=int, help="Minimum RSSI to attempt upgrade process")
parser.add_argument("--id", type=lambda x: int(x, 0), help="Single device to upgrade")
parser.add_argument("--log", type=str, help="File to write upgrade results to")

def progress_table(self):
table = Table()
Expand Down Expand Up @@ -124,15 +129,27 @@ def run(self):
self._handled.append(source.infuse_id)
if v_str == self._new_ver:
self._updated += 1
result = "upgraded"
else:
self._failed += 1
result = "failed"
if self._log:
self._log.write(
f"{time.time()},0x{source.infuse_id:016x},0x{self._app_id:08x},{v_str},{result}\n"
)
self._log.flush()
continue

# Already running the requested version?
if v_str == self._new_ver:
self._handled.append(source.infuse_id)
self._already += 1
self.state_update(live, "Scanning")
if self._log:
self._log.write(
f"{time.time()},0x{source.infuse_id:016x},0x{self._app_id:08x},{v_str},already\n"
)
self._log.flush()
continue

# Do we have a valid diff?
Expand Down Expand Up @@ -175,7 +192,7 @@ def run(self):
)

if hdr.return_code == 0:
self._pending[source.infuse_id] = time.time() + 30
self._pending[source.infuse_id] = time.time() + 60

except ConnectionRefusedError:
self.state_update(live, "Scanning")
Expand Down