94 lines
3.1 KiB
Python
94 lines
3.1 KiB
Python
"""
|
|
1756-L83ES Controller L5X Generator (Boilerplate-based)
|
|
======================================================
|
|
|
|
This module provides functionality to generate L83ES controller L5X files by
|
|
loading a boilerplate template and modifying specific fields.
|
|
"""
|
|
|
|
from dataclasses import dataclass
|
|
from .base_boilerplate_model import BaseModuleConfig, BaseBoilerplateGenerator
|
|
|
|
|
|
@dataclass
|
|
class L83ESControllerConfig(BaseModuleConfig):
|
|
"""Configuration for an L83ES controller."""
|
|
name: str
|
|
boilerplate_path: str = "boilerplate/SLOT0_L83ES.L5X"
|
|
processor_type: str = "1756-L83ES"
|
|
major_rev: str = "36"
|
|
minor_rev: str = "11"
|
|
|
|
def get_updates(self):
|
|
"""Get dictionary of updates to apply."""
|
|
return {
|
|
"name": self.name,
|
|
"processor_type": self.processor_type,
|
|
"major_rev": self.major_rev,
|
|
"minor_rev": self.minor_rev
|
|
}
|
|
|
|
|
|
class L83ESControllerGenerator(BaseBoilerplateGenerator):
|
|
"""Generator for L83ES controller L5X files using boilerplate template."""
|
|
|
|
def apply_updates(self):
|
|
"""Apply L83ES-specific updates to the boilerplate."""
|
|
# Update TargetName in root element
|
|
self.root.set("TargetName", self.config.name)
|
|
|
|
# Update Controller name and attributes
|
|
controller = self.root.find(".//Controller[@Use='Target']")
|
|
if controller is not None:
|
|
controller.set("Name", self.config.name)
|
|
controller.set("ProcessorType", self.config.processor_type)
|
|
controller.set("MajorRev", self.config.major_rev)
|
|
controller.set("MinorRev", self.config.minor_rev)
|
|
|
|
# Update Local module name to match controller name
|
|
local_module = self.root.find(".//Module[@Name='Local']")
|
|
if local_module is not None:
|
|
# Local module always has same name as controller
|
|
local_module.set("Name", "Local") # Actually, it stays "Local"
|
|
|
|
|
|
# Factory function
|
|
def create_l83es_controller(
|
|
name: str,
|
|
processor_type: str = "1756-L83ES",
|
|
major_rev: str = "36",
|
|
minor_rev: str = "11"
|
|
) -> L83ESControllerConfig:
|
|
"""
|
|
Create an L83ES controller configuration.
|
|
|
|
Args:
|
|
name: Controller name
|
|
processor_type: Processor type (default: "1756-L83ES")
|
|
major_rev: Major revision
|
|
minor_rev: Minor revision
|
|
|
|
Returns:
|
|
L83ESControllerConfig object
|
|
"""
|
|
return L83ESControllerConfig(
|
|
name=name,
|
|
processor_type=processor_type,
|
|
major_rev=major_rev,
|
|
minor_rev=minor_rev
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Example usage
|
|
config = create_l83es_controller(
|
|
name="MTN7",
|
|
processor_type="1756-L83ES",
|
|
major_rev="36",
|
|
minor_rev="11"
|
|
)
|
|
|
|
# Generate the controller
|
|
generator = L83ESControllerGenerator(config)
|
|
generator.save_to_file("generated/MTN7_Controller.L5X")
|
|
print(f"Generated L83ES controller configuration saved to generated/MTN7_Controller.L5X") |