Inject Settings packing

This commit is contained in:
Ben Brown
2025-07-17 19:28:09 +10:00
parent 20afa83bd7
commit da7afc3b38
2 changed files with 13 additions and 5 deletions

View File

@@ -99,8 +99,7 @@ def handle_input_file(args, settings) -> Tuple[Settings, int]:
# Add common default values that might be missing from the BSP config
if "QC_VOLTAGE_MAX" not in bsp_config:
bsp_config["QC_VOLTAGE_MAX"] = 120
bsp_config["QC_VOLTAGE_MAX"] = 90
except Exception as e:
print(f"Error loading BSP configuration: {e}")
print("Will use YAML defaults instead")
@@ -179,6 +178,11 @@ def run_editing_settings_file_cli():
else:
print("Running in non-interactive mode, using loaded/default values")
versionMarker = 0x55AA
if args.model == "Pinecilv2":
versionMarker = 0x55AB # Special version marker for Pinecil v2
# Check if output is hex and we need intelhex module
if args.output.lower().endswith(".hex"):
if not HEX_SUPPORT:
@@ -199,7 +203,7 @@ def run_editing_settings_file_cli():
# Save settings to binary or hex file
print(f"\nSaving settings to {args.output}")
if not settings.save_to_binary(args.output, base_address):
if not settings.save_to_binary(args.output, base_address,versionMarker):
print("Failed to save settings")
sys.exit(1)

View File

@@ -166,7 +166,7 @@ class Settings:
print(f"Error loading settings from file: {e}")
return False, 0
def save_to_binary(self, file_path: str, base_address: int = 0) -> bool:
def save_to_binary(self, file_path: str, base_address:int, versionMarker:int) -> bool:
"""Save settings to a binary or hex file
Args:
@@ -186,10 +186,14 @@ class Settings:
# Create binary data
binary_data = bytearray()
binary_data.extend(struct.pack("<H", versionMarker))
binary_data.extend(struct.pack("<H", len(self.values))) # Number of settings
for value in self.values:
# Pack as 16-bit little-endian
binary_data.extend(struct.pack("<H", value))
# Add u32 padding at the end
binary_data.extend(struct.pack("<H", 0))
binary_data.extend(struct.pack("<H", 0))
# Check file extension to determine format
is_hex_file = file_path.lower().endswith(".hex")