plugins/canfestival/canfestival.py
changeset 52 eaffcd0a2f03
parent 49 45dc6a944ab6
child 57 3b53f9a509d9
equal deleted inserted replaced
51:c31c55601556 52:eaffcd0a2f03
    20     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
    20     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
    21     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    21     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    22       <xsd:element name="CanFestivalNode">
    22       <xsd:element name="CanFestivalNode">
    23         <xsd:complexType>
    23         <xsd:complexType>
    24           <xsd:attribute name="CAN_Device" type="xsd:string" use="required" />
    24           <xsd:attribute name="CAN_Device" type="xsd:string" use="required" />
       
    25           <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="required" />
       
    26           <xsd:attribute name="NodeId" type="xsd:string" use="required" />
    25           <xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="required" default="true"/>
    27           <xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="required" default="true"/>
    26         </xsd:complexType>
    28         </xsd:complexType>
    27       </xsd:element>
    29       </xsd:element>
    28     </xsd:schema>
    30     </xsd:schema>
    29     """
    31     """
    79         # define a unique name for the generated C file
    81         # define a unique name for the generated C file
    80         prefix = "_".join(map(lambda x:str(x), current_location))
    82         prefix = "_".join(map(lambda x:str(x), current_location))
    81         Gen_OD_path = os.path.join(buildpath, "OD_%s.c"%prefix )
    83         Gen_OD_path = os.path.join(buildpath, "OD_%s.c"%prefix )
    82         # Create a new copy of the model with DCF loaded with PDO mappings for desired location
    84         # Create a new copy of the model with DCF loaded with PDO mappings for desired location
    83         master = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs())
    85         master = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs())
       
    86         master.SetNodeName("OD_%s"%prefix)
    84         res = gen_cfile.GenerateFile(Gen_OD_path, master)
    87         res = gen_cfile.GenerateFile(Gen_OD_path, master)
    85         if res :
    88         if res :
    86             raise Exception, res
    89             raise Exception, res
    87         
    90         
    88         return [(Gen_OD_path,canfestival_config.getCFLAGS(CanFestivalPath))],""
    91         return [(Gen_OD_path,canfestival_config.getCFLAGS(CanFestivalPath))],"",False
    89     
    92     
    90 class RootClass:
    93 class RootClass:
    91     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
    94     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
    92     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    95     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    93       <xsd:element name="CanFestivalInstance">
    96       <xsd:element name="CanFestivalInstance">
    99     """
   102     """
   100 
   103 
   101     PlugChildsTypes = [("CanOpenNode",_NodeListPlug)]
   104     PlugChildsTypes = [("CanOpenNode",_NodeListPlug)]
   102     
   105     
   103     def PlugGenerate_C(self, buildpath, locations, logger):
   106     def PlugGenerate_C(self, buildpath, locations, logger):
   104         return [],canfestival_config.getLDFLAGS(CanFestivalPath)
   107         
       
   108         format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())),
       
   109                        "candriver" : self.CanFestivalInstance.getCAN_Driver(),
       
   110                        "nodes_includes" : "",
       
   111                        "board_decls" : "",
       
   112                        "nodes_init" : "",
       
   113                        "nodes_open" : "",
       
   114                        "nodes_close" : ""}
       
   115         for child in self.IECSortedChilds():
       
   116             childlocstr = "_".join(map(str,child.GetCurrentLocation()))
       
   117             nodename = "OD_%s" % childlocstr
       
   118 
       
   119             format_dict["nodes_includes"] += '#include "%s.h"\n'%(nodename)
       
   120             format_dict["board_decls"] += 'BOARD_DECL(%s, "%s", "%s")\n'%(
       
   121                    nodename,
       
   122                    child.CanFestivalNode.getCAN_Device(),
       
   123                    child.CanFestivalNode.getCAN_Baudrate())
       
   124             format_dict["nodes_init"] += 'NODE_INIT(%s, %s)\n'%(
       
   125                    nodename,
       
   126                    child.CanFestivalNode.getNodeId())
       
   127             format_dict["nodes_open"] += 'NODE_OPEN(%s)\n'%(nodename)
       
   128             format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n'%(nodename)
       
   129         filename = os.path.join(os.path.split(__file__)[0],"cf_runtime.c")
       
   130         cf_main = open(filename).read() % format_dict
       
   131         cf_main_path = os.path.join(buildpath, "CF_%(locstr)s.c"%format_dict)
       
   132         f = open(cf_main_path,'w')
       
   133         f.write(cf_main)
       
   134         f.close()
       
   135         
       
   136         return [(cf_main_path, canfestival_config.getCFLAGS(CanFestivalPath))],canfestival_config.getLDFLAGS(CanFestivalPath), True
   105 
   137 
   106 
   138