Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsusid committed Oct 18, 2022
1 parent 139d18e commit 1c68d44
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
19 changes: 13 additions & 6 deletions third_party/infineon/cyw30739_sdk/merge_hex.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
def main():
args = parse_args()

configs = OrderedDict()
add_thread_factory_config(configs)
add_matter_factory_config(configs, args.config_header)
configs = gen_thread_factory_config()
configs.update(gen_matter_factory_config(args.config_header))

parse_config_args(configs, args.config)

Expand All @@ -62,11 +61,13 @@ def parse_args():
return parser.parse_args()


def add_thread_factory_config(configs: OrderedDict):
def gen_thread_factory_config() -> OrderedDict:
configs = OrderedDict()
configs["ExtendedAddress"] = {"key": THREAD_FACTORY_KEY_BASE, "value": os.urandom(8)}
return configs


def add_matter_factory_config(configs: OrderedDict, path: pathlib.Path):
def gen_matter_factory_config(path: pathlib.Path) -> OrderedDict:
# compile the regex for extracting name and key of factory configurations.
factory_config_re = re.compile(r"""
.* # Prefix
Expand All @@ -77,19 +78,25 @@ def add_matter_factory_config(configs: OrderedDict, path: pathlib.Path):
(0x[0-9a-fA-F]+) # Parse the config key
""", re.VERBOSE)

configs = OrderedDict()
with open(str(path), mode="r") as config_file:
for line in config_file:
match = factory_config_re.match(line.strip())
if match:
name = match[1]
key = MATTER_FACTORY_KEY_BASE + int(match[2], 0)
configs[name] = {"key": key}
return configs


def parse_config_args(configs: OrderedDict, args: list):
for arg in args:
name, category, value = arg.split(":")

if name not in configs:
print(f"[Warning] Ignored unknown config: {name}")
continue

if category == "address":
addr = bytearray.fromhex(value)

Expand Down Expand Up @@ -134,4 +141,4 @@ def insert_config(origin_hex: IntelHex, configs: OrderedDict):


if __name__ == "__main__":
sys.exit(main())
main()
9 changes: 5 additions & 4 deletions third_party/infineon/cyw30739_sdk/scripts/gen_ss_cgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
def main():
args = parse_args()

configs = OrderedDict()
add_thread_factory_config(configs)
configs = gen_thread_factory_config()

gen_ss_hdf(args.ss_hdf, configs)
gen_ss_cgs(args.ss_cgs, args.ss_hdf, configs)
Expand All @@ -51,8 +50,10 @@ def parse_args():
return parser.parse_args()


def add_thread_factory_config(configs: OrderedDict):
def gen_thread_factory_config() -> OrderedDict:
configs = OrderedDict()
configs["ExtendedAddress"] = {"key": THREAD_FACTORY_KEY_BASE, "value": os.urandom(8)}
return configs


def gen_ss_hdf(path: pathlib.Path, configs: OrderedDict):
Expand Down Expand Up @@ -125,4 +126,4 @@ def write_cgs_data(cgs: io.TextIOBase, name: str, data: bytes = b""):


if __name__ == "__main__":
sys.exit(main())
main()

0 comments on commit 1c68d44

Please sign in to comment.