plugins/canfestival/canfestival.py
changeset 12 a1f9e514f708
parent 11 75ae893d5eed
child 13 f1f0edbeb313
equal deleted inserted replaced
11:75ae893d5eed 12:a1f9e514f708
       
     1 import os
     1 from nodelist import NodeList
     2 from nodelist import NodeList
     2 from nodemanager import NodeManager
     3 from nodemanager import NodeManager
     3 import config_utils, gen_cfile
     4 import config_utils, gen_cfile
       
     5 from networkedit import networkedit
     4 
     6 
     5 class _Beremiz_CanFestival_Controller(NodeList):
     7 class _NetworkEditPlugg(networkedit):
     6     def __init__(self, buspath, bus_id):
     8     def OnCloseFrame(self, event):
     7         self.bus_id = bus_id
     9         self.OnPluggClose()
       
    10         event.Skip()
       
    11 
       
    12 class BusController(NodeList):
       
    13     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
       
    14     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       
    15       <xsd:element name="CanFestivalNode">
       
    16         <xsd:complexType>
       
    17           <xsd:attribute name="CAN_Device" type="xsd:string" use="required" />
       
    18         </xsd:complexType>
       
    19       </xsd:element>
       
    20     </xsd:schema>
       
    21     """
       
    22 
       
    23     ViewClass = _NetworkEditPlugg
       
    24     
       
    25     def __init__(self, buspath):
     8         manager = NodeManager()
    26         manager = NodeManager()
     9         NodeList.__init__(self, manager)
    27         NodeList.__init__(self, manager)
    10         self.LoadProject(buspath)
    28         self.LoadProject(buspath)
    11 
    29 
    12     def SaveBus(self):
    30     def TestModified(self):
       
    31         return self.HasChanged()
       
    32         
       
    33     def ReqSave(self):
    13         self.SaveProject()
    34         self.SaveProject()
       
    35         return True
       
    36 
       
    37     def Generate_C(self, dirpath, locations):
       
    38         """
       
    39         return C code for network dictionnary
       
    40         """
       
    41         filepath = os.path.join(dirpath, "master.c")
       
    42         master = config_utils.GenerateConciseDCF(locations, self)
       
    43         res = gen_cfile.GenerateFile(filepath, master)
       
    44         if not res:
       
    45              s = str(self.BaseParams.BusId)+"_IN(){}\n"
       
    46              s += "CanOpen(str(\""+self.CanFestivalNode.CAN_Device)+"\")"
       
    47              f = file(filepath, 'a')
       
    48              f.write(s)
       
    49         else:
       
    50              pass # error
       
    51         return {"headers":["master.h"],"sources":["master.c"]}
       
    52     
       
    53 class PluginController:
       
    54     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
       
    55     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       
    56       <xsd:element name="CanFestivalInstance">
       
    57         <xsd:complexType>
       
    58           <xsd:attribute name="CAN_Driver" type="xsd:string" use="required" />
       
    59         </xsd:complexType>
       
    60       </xsd:element>
       
    61     </xsd:schema>
       
    62     """
    14 
    63 
    15     def Generate_C(self, filepath, locations):
    64     def Generate_C(self, filepath, locations):
    16         """
    65         """
    17         return C code for network dictionnary
    66         return C code for network dictionnary
    18         """
    67         """
    19         master = config_utils.GenerateConciseDCF(locations, self)
    68         master = config_utils.GenerateConciseDCF(locations, self)
    20         res = gen_cfile.GenerateFile(filepath, master)
    69         res = gen_cfile.GenerateFile(filepath, master)
    21         if not res:
    70         if not res:
    22              s = str(self.bus_id)+"_IN(){}\n"
    71              s = str(self.BaseParams.BusId)+"_IN(){}\n"
       
    72              s += "CanOpen(str(\""+self.CanFestivalNode.CAN_Device)+"\")"
    23              f = file(filepath, 'a')
    73              f = file(filepath, 'a')
    24              f.write(s)
    74              f.write(s)
    25         else:
    75         else:
    26              pass # error
    76              pass # error
    27 
    77 
    28 def BlockListFactory(bmz_inst):
       
    29     return []
       
    30 
       
    31 def ControllerFactory():
       
    32   return _Beremiz_CanFestival_Controller()