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
9 changes: 6 additions & 3 deletions src/infuse_iot/epacket/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from typing_extensions import Self

from infuse_iot.common import InfuseType
from infuse_iot.common import InfuseID, InfuseType
from infuse_iot.database import DeviceDatabase, NoKeyError
from infuse_iot.epacket.common import Serializable
from infuse_iot.epacket.interface import ID as Interface
Expand Down Expand Up @@ -263,7 +263,6 @@ def to_serial(self, database: DeviceDatabase) -> bytes:

# Validation
assert key_metadata is not None
assert database.gateway is not None

# Create header
header = CtypeSerialFrame(
Expand All @@ -275,7 +274,11 @@ def to_serial(self, database: DeviceDatabase) -> bytes:
entropy=random.randint(0, 65535),
)
header.key_metadata = key_metadata
header.device_id = database.gateway
if serial.infuse_id == InfuseID.GATEWAY:
assert database.gateway is not None
header.device_id = database.gateway
else:
header.device_id = serial.infuse_id

# Encrypt and return payload
header_bytes = bytes(header)
Expand Down
13 changes: 11 additions & 2 deletions src/infuse_iot/generated/kv_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ class kv_mcuboot_img_sem_ver(VLACompatLittleEndianStruct):
]
_pack_ = 1

class kv_range_u8(VLACompatLittleEndianStruct):
"""Generic range structure"""

_fields_ = [
("lower", ctypes.c_uint8),
("upper", ctypes.c_uint8),
]
_pack_ = 1


class slots:
class reboots(VLACompatLittleEndianStruct):
Expand Down Expand Up @@ -302,8 +311,8 @@ class task_schedules(VLACompatLittleEndianStruct):
("validity", ctypes.c_uint8),
("periodicity_type", ctypes.c_uint8),
("timeout_s", ctypes.c_uint32),
("battery_start_threshold", ctypes.c_uint8),
("battery_terminate_threshold", ctypes.c_uint8),
("battery_start", structs.kv_range_u8),
("battery_terminate", structs.kv_range_u8),
("periodicity", ctypes.c_uint32),
]
vla_field = ("_remainder", 0 * ctypes.c_uint8)
Expand Down
35 changes: 35 additions & 0 deletions src/infuse_iot/generated/tdf_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,39 @@ def v_dop(self):
def t_dop(self):
return self._t_dop * 0.01

class battery_charge_accumulated(TdfReadingBase):
"""Battery charge accumulated over time (+ve entering battery, -ve exiting battery)"""

name = "BATTERY_CHARGE_ACCUMULATED"
_fields_ = [
("charge", ctypes.c_int32),
]
_pack_ = 1
_postfix_ = {
"charge": "uAs",
}
_display_fmt_ = {
"charge": "{}",
}

class infuse_bluetooth_rssi(TdfReadingBase):
"""Received signal strength of Infuse-IoT Bluetooth device"""

name = "INFUSE_BLUETOOTH_RSSI"
_fields_ = [
("infuse_id", ctypes.c_uint64),
("rssi", ctypes.c_int8),
]
_pack_ = 1
_postfix_ = {
"infuse_id": "",
"rssi": "dBm",
}
_display_fmt_ = {
"infuse_id": "{}",
"rssi": "{}",
}

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

Expand Down Expand Up @@ -1217,5 +1250,7 @@ class array_type(TdfReadingBase):
35: readings.wifi_ap_info,
36: readings.device_tilt,
37: readings.nrf9x_gnss_pvt,
38: readings.battery_charge_accumulated,
39: readings.infuse_bluetooth_rssi,
100: readings.array_type,
}
4 changes: 3 additions & 1 deletion src/infuse_iot/tdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ def offset(self):
class Reading:
def __init__(
self,
tdf_id: int,
time: None | float,
period: None | float,
data: list[tdf_base.TdfReadingBase],
):
self.id = tdf_id
self.time = time
self.period = period
self.data = data
Expand Down Expand Up @@ -202,4 +204,4 @@ def decode(self, buffer: bytes) -> Generator[Reading, None, None]:
if array_header is not None:
period = array_header.period / 65536

yield self.Reading(time, period, data)
yield self.Reading(tdf_id, time, period, data)
2 changes: 1 addition & 1 deletion src/infuse_iot/tools/native_bt.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def connection_lost(self, exc):
class SubCommand(InfuseCommand):
NAME = "native_bt"
HELP = "Native Bluetooth gateway"
DESCRIPTION = "Use the local Bluetooth adapater for Bluetooth interaction"
DESCRIPTION = "Use the local Bluetooth adapter for Bluetooth interaction"

@classmethod
def add_parser(cls, parser):
Expand Down
8 changes: 4 additions & 4 deletions src/infuse_iot/util/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ def log_info(message):
Console.log(datetime.datetime.now(), colorama.Fore.MAGENTA, message)

@staticmethod
def log_tx(data_type, length):
def log_tx(data_type, length, prefix=""):
"""Log transmitted packet to terminal"""
Console.log(
datetime.datetime.now(),
colorama.Fore.BLUE,
f"TX {data_type.name} {length} bytes",
f"{prefix}TX {data_type.name} {length} bytes",
)

@staticmethod
def log_rx(data_type, length):
def log_rx(data_type, length, prefix=""):
"""Log received packet to terminal"""
Console.log(
datetime.datetime.now(),
colorama.Fore.GREEN,
f"RX {data_type.name} {length} bytes",
f"{prefix}RX {data_type.name} {length} bytes",
)

@staticmethod
Expand Down