Skip to content

Commit e7f9e25

Browse files
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 8b62c15 commit e7f9e25

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/openlifu/io/LIFUDFU.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import logging
1414
import struct
1515
import time
16-
from typing import TYPE_CHECKING, Callable
1716
import unittest
17+
from typing import TYPE_CHECKING, Callable
1818

1919
from openlifu.io.LIFUConfig import OW_ERROR, OW_I2C_PASSTHRU
2020

src/openlifu/io/LIFUTXDevice.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
import struct
77
from dataclasses import dataclass, field
8-
from typing import TYPE_CHECKING, Annotated, Dict, List, Literal, Optional
8+
from typing import TYPE_CHECKING, Annotated, Dict, List, Literal
99

1010
import numpy as np
1111

@@ -397,7 +397,7 @@ def get_hardware_id(self, module:int=0) -> str:
397397
logger.error("Unexpected error during process: %s", e)
398398
raise # Re-raise the exception for the caller to handle
399399

400-
def read_config(self, module:int=0) -> Optional[LifuUserConfig]:
400+
def read_config(self, module:int=0) -> LifuUserConfig | None:
401401
"""
402402
Read the user configuration from device flash.
403403
@@ -450,7 +450,7 @@ def read_config(self, module:int=0) -> Optional[LifuUserConfig]:
450450
logger.exception("Unexpected error reading config")
451451
raise
452452

453-
def write_config(self, config: LifuUserConfig, module:int=0) -> Optional[LifuUserConfig]:
453+
def write_config(self, config: LifuUserConfig, module:int=0) -> LifuUserConfig | None:
454454
"""
455455
Write user configuration to device flash.
456456
@@ -517,7 +517,7 @@ def write_config(self, config: LifuUserConfig, module:int=0) -> Optional[LifuUse
517517
logger.exception("Unexpected error writing config")
518518
raise
519519

520-
def write_config_json(self, json_str: str, module:int=0) -> Optional[LifuUserConfig]:
520+
def write_config_json(self, json_str: str, module:int=0) -> LifuUserConfig | None:
521521
"""
522522
Write user configuration from a JSON string.
523523
@@ -982,7 +982,7 @@ def async_mode(self, enable: bool | None = None) -> bool:
982982
else:
983983
payload = None
984984

985-
r = self.uart.send_packet(id=None, packetType=OW_CONTROLLER, command=OW_CMD_ASYNC, addr=0, data=payload)
985+
r = self.uart.send_packet(id=None, packetType=OW_CMD, command=OW_CMD_ASYNC, addr=0, data=payload)
986986
self.uart.clear_buffer()
987987
# r.print_packet()
988988
if r.packet_type == OW_ERROR:
@@ -1332,7 +1332,7 @@ def write_block(self, identifier: int, start_address: int, reg_values: List[int]
13321332
logger.error("Unexpected error in write_block: %s", e)
13331333
raise # Re-raise the exception for the caller to handle
13341334

1335-
def read_block(self, identifier: int, start_address: int, count: int) -> Optional[List[int]]:
1335+
def read_block(self, identifier: int, start_address: int, count: int) -> List[int] | None:
13361336
"""
13371337
Read a block of consecutive register values from the TX device.
13381338

src/openlifu/io/LIFUUserConfig.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import json
44
import logging
55
import struct
6+
import zlib
67
from dataclasses import dataclass
78
from typing import Any, Dict
89

910
logger = logging.getLogger(__name__)
1011

1112
# Constants from C code
1213
LIFU_MAGIC = 0x4C494655 # 'LIFU'
13-
LIFU_VER = 0x00010002 # v1.0.0
14+
LIFU_VER = 0x00010002 # v1.0.2
1415

1516
@dataclass
1617
class LifuUserConfigHeader:
@@ -139,6 +140,9 @@ def to_wire_bytes(self) -> bytes:
139140
# Update header with JSON length
140141
self.header.json_len = len(json_bytes)
141142

143+
# Update header CRC based on JSON payload (16-bit from CRC32)
144+
self.header.crc = zlib.crc32(json_bytes) & 0xFFFF
145+
142146
# Build wire format
143147
return self.header.to_bytes() + json_bytes
144148

0 commit comments

Comments
 (0)