MCPcopy Create free account
hub / github.com/c-jimenez/open-ocpp / gen_converters

Function gen_converters

tools/json2cpp/json2cpp.py:686–717  ·  view source on GitHub ↗

Generate the code for the message converters @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 msg_list:

(templates, params, msg_list)

Source from the content-addressed store, hash-verified

684 return
685
686def gen_converters(templates, params, msg_list):
687 '''
688 Generate the code for the message converters
689
690 @param templates: Code templates
691 @type templates: {string,string}
692
693 @param params: Command line parameters
694 @type params: Parameters
695
696 @param msg_list: List of OCPP messages per roles
697 @type msg_list: {string, [string]}
698 '''
699
700 # Generate implementations
701 ocpp_version_suffix = params.ocpp_version[4:]
702
703 gen_file_path = os.path.join(params.messages_dir, f"MessagesConverter{ocpp_version_suffix}.cpp")
704 gen_file = open(gen_file_path, "wt")
705 env = jinja2.Environment()
706 template = env.from_string(templates["msg_converter_impl"])
707 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)
708 gen_file.write(rendered_template)
709 gen_file.close()
710
711 gen_file_path = os.path.join(params.messages_dir, f"MessagesValidator{ocpp_version_suffix}.cpp")
712 gen_file = open(gen_file_path, "wt")
713 env = jinja2.Environment()
714 template = env.from_string(templates["msg_validator_impl"])
715 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)
716 gen_file.write(rendered_template)
717 gen_file.close()
718
719def gen_chargepoint(templates, params, msg_list):
720 '''

Callers 1

json2cpp.pyFile · 0.85

Calls 2

writeMethod · 0.80
closeMethod · 0.80

Tested by

no test coverage detected