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
11 changes: 11 additions & 0 deletions src/infuse_iot/generated/kv_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ class bluetooth_ctlr_version(VLACompatLittleEndianStruct):
]
_pack_ = 1

class device_name(VLACompatLittleEndianStruct):
"""Personalised name for the device"""

NAME = "DEVICE_NAME"
BASE_ID = 4
RANGE = 1
_fields_ = []
vla_field = ("name", structs.kv_string)
_pack_ = 1

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

Expand Down Expand Up @@ -327,6 +337,7 @@ class secure_storage_reserved(VLACompatLittleEndianStruct):
1: bluetooth_addr,
2: exfat_disk_info,
3: bluetooth_ctlr_version,
4: device_name,
10: fixed_location,
20: wifi_ssid,
21: wifi_psk,
Expand Down
21 changes: 21 additions & 0 deletions src/infuse_iot/generated/rpc_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class rpc_enum_data_logger(enum.IntEnum):

FLASH_ONBOARD = 1
FLASH_REMOVABLE = 2
UDP = 3


class rpc_enum_zperf_data_source(enum.IntEnum):
Expand Down Expand Up @@ -718,6 +719,26 @@ class response(VLACompatLittleEndianStruct):
_pack_ = 1


class annotate:
"""Write an annotation to the device"""

HELP = "Write an annotation to the device"
DESCRIPTION = "Write an annotation to the device"
COMMAND_ID = 41

class request(VLACompatLittleEndianStruct):
_fields_ = [
("logger", ctypes.c_uint8),
("timestamp", ctypes.c_uint32),
]
vla_field = ("annotation", 0 * ctypes.c_char)
_pack_ = 1

class response(VLACompatLittleEndianStruct):
_fields_ = []
_pack_ = 1


class bt_connect_infuse:
"""Connect to an Infuse-IoT Bluetooth device"""

Expand Down
19 changes: 19 additions & 0 deletions src/infuse_iot/generated/tdf_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,24 @@ class adc_raw_32(TdfReadingBase):
"val": "{}",
}

class annotation(TdfReadingBase):
"""Generic event annotation"""

name = "ANNOTATION"
_fields_ = [
("timestamp", ctypes.c_uint32),
("event", 0 * ctypes.c_char),
]
_pack_ = 1
_postfix_ = {
"timestamp": "",
"event": "",
}
_display_fmt_ = {
"timestamp": "{}",
"event": "{}",
}

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

Expand Down Expand Up @@ -1300,5 +1318,6 @@ class array_type(TdfReadingBase):
40: readings.adc_raw_8,
41: readings.adc_raw_16,
42: readings.adc_raw_32,
43: readings.annotation,
100: readings.array_type,
}
28 changes: 25 additions & 3 deletions src/infuse_iot/rpc_wrappers/kv_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import ctypes
import os
import sys

import infuse_iot.generated.kv_definitions as kv_defs
import infuse_iot.generated.rpc_definitions as defs
from infuse_iot.commands import InfuseRpcCommand
from infuse_iot.util.ctypes import VLACompatLittleEndianStruct, bytes_to_uint8
Expand Down Expand Up @@ -36,12 +38,32 @@ class kv_store_value(ctypes.LittleEndianStructure):

@classmethod
def add_parser(cls, parser):
parser.add_argument("--key", type=int, required=True, help="KV key ID")
parser.add_argument("--value", type=str, required=True, help="KV value as hex string")
parser.add_argument("--key", "-k", type=int, required=True, help="KV key ID")
v_parser = parser.add_mutually_exclusive_group(required=True)
v_parser.add_argument("--value", "-v", type=str, help="KV value as hex string")
v_parser.add_argument("--string", "-s", type=str, help="KV string")

def __init__(self, args):
self.key = args.key
self.value = bytes.fromhex(args.value)
if args.value is not None:
self.value = bytes.fromhex(args.value)
elif args.string is not None:
if self.key not in kv_defs.slots.ID_MAPPING:
sys.exit(f"Key ID {self.key} not known, cannot validate")
kv_type = kv_defs.slots.ID_MAPPING[self.key]
# Validate key type is a string
if (
len(kv_type._fields_) != 0
or not hasattr(kv_type, "vla_field")
or not isinstance(kv_type.vla_field, tuple)
or kv_type.vla_field[1] != kv_defs.structs.kv_string
):
sys.exit(f"Key ID {self.key} is not a string value")

str_val = args.string.encode("utf-8") + b"\x00"
self.value = len(str_val).to_bytes(1, "little") + str_val
else:
raise NotImplementedError("Unimplmented value parsing")

def request_struct(self):
kv_struct = self.kv_store_value_factory(self.key, self.value)
Expand Down
4 changes: 2 additions & 2 deletions src/infuse_iot/rpc_wrappers/wifi_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def request_struct(self):
ssid_bytes = self.args.ssid.encode("utf-8") + b"\x00"
psk_bytes = self.args.psk.encode("utf-8") + b"\x00"

ssid_struct = self.kv_store_value_factory(20, (len(ssid_bytes) + 1).to_bytes(1, "little") + ssid_bytes)
psk_struct = self.kv_store_value_factory(21, (len(psk_bytes) + 1).to_bytes(1, "little") + psk_bytes)
ssid_struct = self.kv_store_value_factory(20, len(ssid_bytes).to_bytes(1, "little") + ssid_bytes)
psk_struct = self.kv_store_value_factory(21, len(psk_bytes).to_bytes(1, "little") + psk_bytes)

request_bytes = bytes(ssid_struct) + bytes(psk_struct)
return bytes(self.request(2)) + request_bytes
Expand Down
10 changes: 6 additions & 4 deletions src/infuse_iot/tools/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,17 @@ def info(self, client):
]
if state is not None:
v = state.application_version
v_str = f"{v.major}.{v.minor}.{v.revision}+{v.build_num:08x}" if v else "Unknown"

table += [
("~~~State~~~", ""),
("Updated", state.updated_at),
("Application ID", f"0x{state.application_id:08x}"),
("Version", v_str),
("Last Heard", state.last_route_interface),
]
if state.application_id:
table += [("Application ID", f"0x{state.application_id:08x}")]
if v:
table += [("Version", f"{v.major}.{v.minor}.{v.revision}+{v.build_num:08x}")]
if state.last_route_interface:
table += [("Last Heard", state.last_route_interface)]

print(tabulate(table))

Expand Down
5 changes: 2 additions & 3 deletions src/infuse_iot/util/elftools.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ def dwarf_die_variable_inf(
type_name = None
info_name = name_override if name_override is not None else field_name

# print(field_name, type_name, type_die.tag)

if type_die.tag == "DW_TAG_array_type":
count = 0
for child in type_die.iter_children():
Expand All @@ -172,7 +170,8 @@ def dwarf_die_variable_inf(
if "DW_AT_byte_size" in element_die.attributes:
element_offset += element_die.attributes["DW_AT_byte_size"].value
else:
element_offset += ctypes.sizeof(child.ctype)
if child.ctype is not None:
element_offset += ctypes.sizeof(child.ctype)
children.append(child)

return dwarf_field(info_name, type_die.tag, None, children, offset)
Expand Down