parameters: (car_type, protocol, output_dir)
docstring: doc string:
docstring_summary: doc string:
docstring_tokens: doc string :
function: def gen_control_cpp(car_type, protocol, output_dir):
      """
          doc string:
      """
      control_cpp_tpl_file = "template/control_protocol.cc.tpl"
      FMT = get_tpl_fmt(control_cpp_tpl_file)
      control_cpp_file = output_dir + "%s.cc" % protocol["name"]
      with open(control_cpp_file, 'w') as fp:
          fmt_val = {}
          fmt_val["car_type_lower"] = car_type
          fmt_val["protocol_name_lower"] = protocol["name"]
          protocol_id = int(protocol["id"].upper(), 16)
          if protocol_id > 2048:
              fmt_val["id_upper"] = gen_esd_can_extended(protocol["id"].upper())
          else:
              fmt_val["id_upper"] = protocol["id"].upper()
          classname = protocol["name"].replace('_', '').capitalize()
          fmt_val["classname"] = classname
  
          set_private_var_list = []
          set_private_var_init_list = []
          set_func_impl_list = []
          for var in protocol["vars"]:
              func_impl = gen_control_value_func_impl(classname, var, protocol)
              set_func_impl_list.append(func_impl)
              set_private_var = "  set_p_%s(data, %s_);" % (var["name"].lower(),
                                                            var["name"].lower())
              set_private_var_list.append(set_private_var)
              init_val = "0"
              if var["type"] == "double":
                  init_val = "0.0"
              elif var["type"] == "bool":
                  init_val = "false"
              elif var["type"] == "enum":
                  if 0 in var["enum"]:
                      init_val = protocol["name"].capitalize(
                      ) + "::" + var["enum"][0].upper()
                  else:
                      init_val = protocol["name"].capitalize(
                      ) + "::" + list(var["enum"].values())[0].upper()
  
              set_private_var_init_list.append("  %s_ = %s;" %
                                               (var["name"].lower(), init_val))
          fmt_val["set_private_var_list"] = "\n".join(set_private_var_list)
          fmt_val["set_private_var_init_list"] = "\n".join(
              set_private_var_init_list)
          fmt_val["set_func_impl_list"] = "\n".join(set_func_impl_list)
          fp.write(FMT % fmt_val)
function_tokens: def gen_control_cpp ( car_type , protocol , output_dir ) : control_cpp_tpl_file = "template/control_protocol.cc.tpl" FMT = get_tpl_fmt ( control_cpp_tpl_file ) control_cpp_file = output_dir + "%s.cc" % protocol [ "name" ] with open ( control_cpp_file , 'w' ) as fp : fmt_val = { } fmt_val [ "car_type_lower" ] = car_type fmt_val [ "protocol_name_lower" ] = protocol [ "name" ] protocol_id = int ( protocol [ "id" ] . upper ( ) , 16 ) if protocol_id > 2048 : fmt_val [ "id_upper" ] = gen_esd_can_extended ( protocol [ "id" ] . upper ( ) ) else : fmt_val [ "id_upper" ] = protocol [ "id" ] . upper ( ) classname = protocol [ "name" ] . replace ( '_' , '' ) . capitalize ( ) fmt_val [ "classname" ] = classname set_private_var_list = [ ] set_private_var_init_list = [ ] set_func_impl_list = [ ] for var in protocol [ "vars" ] : func_impl = gen_control_value_func_impl ( classname , var , protocol ) set_func_impl_list . append ( func_impl ) set_private_var = "  set_p_%s(data, %s_);" % ( var [ "name" ] . lower ( ) , var [ "name" ] . lower ( ) ) set_private_var_list . append ( set_private_var ) init_val = "0" if var [ "type" ] == "double" : init_val = "0.0" elif var [ "type" ] == "bool" : init_val = "false" elif var [ "type" ] == "enum" : if 0 in var [ "enum" ] : init_val = protocol [ "name" ] . capitalize ( ) + "::" + var [ "enum" ] [ 0 ] . upper ( ) else : init_val = protocol [ "name" ] . capitalize ( ) + "::" + list ( var [ "enum" ] . values ( ) ) [ 0 ] . upper ( ) set_private_var_init_list . append ( "  %s_ = %s;" % ( var [ "name" ] . lower ( ) , init_val ) ) fmt_val [ "set_private_var_list" ] = "\n" . join ( set_private_var_list ) fmt_val [ "set_private_var_init_list" ] = "\n" . join ( set_private_var_init_list ) fmt_val [ "set_func_impl_list" ] = "\n" . join ( set_func_impl_list ) fp . write ( FMT % fmt_val )