diff --git a/src/xmlgen.py b/src/xmlgen.py index 4706ffb..8c1e0ef 100755 --- a/src/xmlgen.py +++ b/src/xmlgen.py @@ -12,11 +12,16 @@ import argparse import os import pprint -from typing import IO, Any, Tuple +from typing import IO, Any, Tuple, List import yaml import utils # local import +# CONSTANTS +ZM_NUM_ENTRIES = 1024 +C_OUTPUT_FILE = "ZynqMon_addresses.c" +C_OUTPUT_HEADER = "ZynqMon_addresses.h" + def sensor_size(thedict: dict) -> int: """calculate the size of the sensor in bytes""" sz = 2 # default size @@ -41,7 +46,7 @@ def type_to_format(thedict: dict) -> str: return None return fmt -def open_C_file(fname: str) -> IO[Any]: +def open_C_file(fname: str, header_fname: str) -> IO[Any]: """open the C file and write the header""" fout = open(fname, 'w', encoding='ascii') print(r"// This file is generated by mcu_generate.py", file=fout) @@ -54,11 +59,10 @@ def open_C_file(fname: str) -> IO[Any]: print(r"//", file=fout) print("#include \"Tasks.h\"", file=fout) # include the header file we will write later - header_fname = args.output.replace('.c', '.h') print(f"#include \"{header_fname}\"", file=fout) return fout -def write_C_header(fout: IO[Any], fname: str) -> None: +def write_C_header(header_fname: str, ZMON_VALID_ENTRIES: List[int]) -> None: """write the header file""" with open(header_fname, encoding="ascii", mode='w') as fheader: print(r"// This file is generated by mcu_generate.py", file=fheader) @@ -140,11 +144,14 @@ def main(): if args.directory: print('Output directory:', args.directory) - + # load YAML input file into memory with open(args.input_file, encoding='ascii') as f: y = yaml.load(f, Loader=yaml.FullLoader) - # This is the parent(root) tag onto which other tags would be + # open C output file for writing + c_fout = open_C_file(args.directory + '/' + C_OUTPUT_FILE, C_OUTPUT_HEADER) + + # start XML tree. This is the parent(root) tag onto which other tags will be # created cm = ET.Element('node') cm.set('id', 'CM') @@ -169,6 +176,10 @@ def main(): if args.verbose: print("category_size:", category_size) + + # write the C call to generate the filling of the data structures + write_C_call(c_fout, c, sensor_count) + while True: # if there are devices if device: @@ -194,7 +205,10 @@ def main(): if args.verbose: print("writing to file", out_name) tree.write(out_name) - + # write header file + write_C_header(args.directory + '/' + C_OUTPUT_HEADER, [sensor_count, sensor_count]) pprinter.pprint(summary) + + if __name__ == "__main__": main()