Move init code from variable to module
authorlaurent
Fri, 04 Jun 2010 13:47:02 +0200
changeset 553 d071efd2a94b
parent 552 ab7916df0de7
child 554 6bd3f220b886
Move init code from variable to module
LPCBeremiz.py
--- a/LPCBeremiz.py	Fri Jun 04 13:09:35 2010 +0200
+++ b/LPCBeremiz.py	Fri Jun 04 13:47:02 2010 +0200
@@ -144,13 +144,15 @@
   #include "iec_std_lib.h"
 #endif
 
+%(declare_code)s
+
 /* LPCBus plugin user variables definition */
 %(var_decl)s
 
 /* LPCBus plugin functions */
 int __init_%(location_str)s(int argc,char **argv)
 {
-%(declare_code)s
+%(init_code)s
   return 0;
 }
 
@@ -288,13 +290,14 @@
         code_str = {"location_str": location_str,
                     "var_decl": "",
                     "declare_code": "",
+                    "init_code": "",
                     "retrieve_code": "",
                     "publish_code": "",
                    }
         
-        for variable in _GetVariables(self):
-            if variable["declare"] != "":
-                code_str["declare_code"] += "  %s\n" % variable["declare"]
+        for module in _GetModuleChildren(self):
+            if module["init"] != "":
+                code_str["init_code"] += "  %s\n" % module["init"]
         
         # Adding variables
         vars = []
@@ -337,7 +340,7 @@
             if var["Publish"] != "":
                 code_str["publish_code"] += "  " + var["Publish"] % ("*" + var["location"]) + "\n"
         
-        Gen_Module_path = os.path.join(buildpath, "Module_%s.c"%location_str)
+        Gen_Module_path = os.path.join(buildpath, "Bus_%s.c"%location_str)
         module = open(Gen_Module_path,'w')
         module.write(BUS_TEXT % code_str)
         module.close()
@@ -1232,7 +1235,7 @@
             self.PluginRoot.PluggedChilds["LPCBus"].remove(bus)
             self.RestartTimer()
     
-        def AddModule(self, parent, iec_channel, name, icon=None):
+        def AddModule(self, parent, iec_channel, name, icode, icon=None):
             module = self.PluginRoot.GetChildByIECLocation(parent)
             if module is None:
                 return "Error: No parent found\n"
@@ -1245,6 +1248,7 @@
                                                 "type": LOCATION_MODULE, 
                                                 "IEC_Channel": iec_channel, 
                                                 "icon": icon, 
+                                                "init": icode, 
                                                 "children": []})
             self.RestartTimer()
     
@@ -1276,7 +1280,13 @@
             self.PluginRoot.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
             module["IEC_Channel"] = new_iec_channel
             self.RestartTimer()
-    
+        
+        def ChangeModuleInitCode(self, iec_location, icode):
+            module = self.PluginRoot.GetChildByIECLocation(iec_location)
+            if module is None:
+                return "Error: No module found\n"
+            module["init"] = icode
+        
         def RemoveModule(self, parent, iec_channel):
             module = self.PluginRoot.GetChildByIECLocation(parent)
             if module is None:
@@ -1301,7 +1311,7 @@
                                       "children": []})
             self.RestartTimer()
     
-        def AddVariable(self, parent, location, name, direction, type, dcode, rcode, pcode, description=""):
+        def AddVariable(self, parent, location, name, direction, type, rcode, pcode, description=""):
             module = self.PluginRoot.GetChildByIECLocation(parent)
             if module is None:
                 return "Error: No parent found\n"
@@ -1315,12 +1325,11 @@
                                                 "type": LOCATION_TYPES[direction], 
                                                 "IEC_type": type, 
                                                 "description": description, 
-                                                "declare": dcode, 
                                                 "retrieve": rcode, 
                                                 "publish": pcode})
             self.RestartTimer()
 
-        def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_dcode, new_rcode, new_pcode, new_description=None):
+        def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_rcode, new_pcode, new_description=None):
             module = self.PluginRoot.GetChildByIECLocation(parent)
             if module is None:
                 return "Error: No parent found\n"
@@ -1337,7 +1346,6 @@
                 variable["name"] = new_name
             variable["type"] = LOCATION_TYPES[new_direction]
             variable["IEC_type"] = new_type
-            variable["declare"] = new_dcode
             variable["retrieve"] = new_rcode
             variable["publish"] = new_pcode
             if new_description is not None:
@@ -1434,13 +1442,14 @@
                                            "RenameBus": ([int, str], 0),
                                            "ChangeBusIECChannel": ([int, int], 0),
                                            "RemoveBus": ([int], 0),
-                                           "AddModule": ([location, int, str, str], 1), 
+                                           "AddModule": ([location, int, str, str, str], 1), 
                                            "RenameModule": ([location, str], 0),
                                            "ChangeModuleIECChannel": ([location, int], 0),
+                                           "ChangeModuleInitCode": ([location, str], 0),
                                            "RemoveModule": ([location, int], 0),
                                            "StartGroup": ([location, str, str], 1),
-                                           "AddVariable": ([location, location, str, str, str, str, str, str, str], 1),
-                                           "ChangeVariableParams": ([location, location, str, str, str, str, str, str, str], 1),
+                                           "AddVariable": ([location, location, str, str, str, str, str, str], 1),
+                                           "ChangeVariableParams": ([location, location, str, str, str, str, str, str], 1),
                                            "RemoveVariable": ([location, location], 0)}.iteritems():
             
             setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))