Generate the code for the local controller features @param templates: Code templates @type templates: {string,string} @param params: Command line parameters @type params: Parameters @param msg_list: List of OCPP messages per roles @type ms
(templates, params, msg_list)
| 842 | |
| 843 | |
| 844 | def gen_localcontroller(templates, params, msg_list): |
| 845 | ''' |
| 846 | Generate the code for the local controller features |
| 847 | |
| 848 | @param templates: Code templates |
| 849 | @type templates: {string,string} |
| 850 | |
| 851 | @param params: Command line parameters |
| 852 | @type params: Parameters |
| 853 | |
| 854 | @param msg_list: List of OCPP messages per roles |
| 855 | @type msg_list: {string, [string]} |
| 856 | ''' |
| 857 | |
| 858 | # Create output directories |
| 859 | lc_dir = os.path.join(params.output_dir, "localcontroller") |
| 860 | lc_dirs = [lc_dir] |
| 861 | lc_dirs.append(os.path.join(lc_dir, "centralsystem")) |
| 862 | lc_dirs.append(os.path.join(lc_dir, "chargepoint")) |
| 863 | lc_dirs.append(os.path.join(lc_dir, "interface")) |
| 864 | for dir in lc_dirs: |
| 865 | if not os.path.exists(dir): |
| 866 | os.mkdir(dir) |
| 867 | |
| 868 | # Generate interfaces |
| 869 | lc_interface_dir = lc_dirs[3] |
| 870 | ocpp_version_suffix = params.ocpp_version[4:] |
| 871 | if params.ocpp_version == "ocpp20": |
| 872 | ocpp_ws_protocol = "ocpp2.0.1" |
| 873 | elif params.ocpp_version == "ocpp21": |
| 874 | ocpp_ws_protocol = "ocpp2.0.1" |
| 875 | else: |
| 876 | ocpp_ws_protocol = "ocpp1.6" |
| 877 | |
| 878 | gen_file_path = os.path.join(lc_interface_dir, f"IChargePointProxy{ocpp_version_suffix}.h") |
| 879 | gen_file = open(gen_file_path, "wt") |
| 880 | env = jinja2.Environment() |
| 881 | template = env.from_string(templates["lc_ichargepointproxy"]) |
| 882 | rendered_template = template.render(csms_msgs = msg_list["from_csms"], cs_msgs = msg_list["from_cs"], ocpp_version_namespace = params.ocpp_version, ocpp_version_suffix = ocpp_version_suffix) |
| 883 | gen_file.write(rendered_template) |
| 884 | gen_file.close() |
| 885 | |
| 886 | gen_file_path = os.path.join(lc_interface_dir, f"ICentralSystemProxy{ocpp_version_suffix}.h") |
| 887 | gen_file = open(gen_file_path, "wt") |
| 888 | env = jinja2.Environment() |
| 889 | template = env.from_string(templates["lc_icentralsystemproxy"]) |
| 890 | rendered_template = template.render(csms_msgs = msg_list["from_csms"], cs_msgs = msg_list["from_cs"], ocpp_version_namespace = params.ocpp_version, ocpp_version_suffix = ocpp_version_suffix) |
| 891 | gen_file.write(rendered_template) |
| 892 | gen_file.close() |
| 893 | |
| 894 | # Generate central system classes |
| 895 | centralsystem_dir = lc_dirs[1] |
| 896 | gen_file_path = os.path.join(centralsystem_dir, f"CentralSystemProxy{ocpp_version_suffix}.h") |
| 897 | gen_file = open(gen_file_path, "wt") |
| 898 | env = jinja2.Environment() |
| 899 | template = env.from_string(templates["lc_centralsystemproxy_header"]) |
| 900 | rendered_template = template.render(csms_msgs = msg_list["from_csms"], cs_msgs = msg_list["from_cs"], ocpp_version_namespace = params.ocpp_version, ocpp_version_suffix = ocpp_version_suffix) |
| 901 | gen_file.write(rendered_template) |
no test coverage detected