LPCBeremiz.py
changeset 553 d071efd2a94b
parent 552 ab7916df0de7
child 555 7b08cc1ea55a
equal deleted inserted replaced
552:ab7916df0de7 553:d071efd2a94b
   142   #include "iec_types.h"
   142   #include "iec_types.h"
   143 #else
   143 #else
   144   #include "iec_std_lib.h"
   144   #include "iec_std_lib.h"
   145 #endif
   145 #endif
   146 
   146 
       
   147 %(declare_code)s
       
   148 
   147 /* LPCBus plugin user variables definition */
   149 /* LPCBus plugin user variables definition */
   148 %(var_decl)s
   150 %(var_decl)s
   149 
   151 
   150 /* LPCBus plugin functions */
   152 /* LPCBus plugin functions */
   151 int __init_%(location_str)s(int argc,char **argv)
   153 int __init_%(location_str)s(int argc,char **argv)
   152 {
   154 {
   153 %(declare_code)s
   155 %(init_code)s
   154   return 0;
   156   return 0;
   155 }
   157 }
   156 
   158 
   157 void __cleanup_%(location_str)s(void)
   159 void __cleanup_%(location_str)s(void)
   158 {
   160 {
   286         location_str = "_".join(map(str, current_location))
   288         location_str = "_".join(map(str, current_location))
   287         
   289         
   288         code_str = {"location_str": location_str,
   290         code_str = {"location_str": location_str,
   289                     "var_decl": "",
   291                     "var_decl": "",
   290                     "declare_code": "",
   292                     "declare_code": "",
       
   293                     "init_code": "",
   291                     "retrieve_code": "",
   294                     "retrieve_code": "",
   292                     "publish_code": "",
   295                     "publish_code": "",
   293                    }
   296                    }
   294         
   297         
   295         for variable in _GetVariables(self):
   298         for module in _GetModuleChildren(self):
   296             if variable["declare"] != "":
   299             if module["init"] != "":
   297                 code_str["declare_code"] += "  %s\n" % variable["declare"]
   300                 code_str["init_code"] += "  %s\n" % module["init"]
   298         
   301         
   299         # Adding variables
   302         # Adding variables
   300         vars = []
   303         vars = []
   301         self.ResetUsedLocations()
   304         self.ResetUsedLocations()
   302         for location in locations:
   305         for location in locations:
   335             if var["Retrieve"] != "":
   338             if var["Retrieve"] != "":
   336                 code_str["retrieve_code"] += "  " + var["Retrieve"] % ("*" + var["location"]) + "\n"
   339                 code_str["retrieve_code"] += "  " + var["Retrieve"] % ("*" + var["location"]) + "\n"
   337             if var["Publish"] != "":
   340             if var["Publish"] != "":
   338                 code_str["publish_code"] += "  " + var["Publish"] % ("*" + var["location"]) + "\n"
   341                 code_str["publish_code"] += "  " + var["Publish"] % ("*" + var["location"]) + "\n"
   339         
   342         
   340         Gen_Module_path = os.path.join(buildpath, "Module_%s.c"%location_str)
   343         Gen_Module_path = os.path.join(buildpath, "Bus_%s.c"%location_str)
   341         module = open(Gen_Module_path,'w')
   344         module = open(Gen_Module_path,'w')
   342         module.write(BUS_TEXT % code_str)
   345         module.write(BUS_TEXT % code_str)
   343         module.close()
   346         module.close()
   344         
   347         
   345         matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath())
   348         matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath())
  1230                 return "Error: No bus found\n"
  1233                 return "Error: No bus found\n"
  1231             self.PluginRoot.RemoveProjectVariableByFilter(str(iec_channel))
  1234             self.PluginRoot.RemoveProjectVariableByFilter(str(iec_channel))
  1232             self.PluginRoot.PluggedChilds["LPCBus"].remove(bus)
  1235             self.PluginRoot.PluggedChilds["LPCBus"].remove(bus)
  1233             self.RestartTimer()
  1236             self.RestartTimer()
  1234     
  1237     
  1235         def AddModule(self, parent, iec_channel, name, icon=None):
  1238         def AddModule(self, parent, iec_channel, name, icode, icon=None):
  1236             module = self.PluginRoot.GetChildByIECLocation(parent)
  1239             module = self.PluginRoot.GetChildByIECLocation(parent)
  1237             if module is None:
  1240             if module is None:
  1238                 return "Error: No parent found\n"
  1241                 return "Error: No parent found\n"
  1239             for child in _GetModuleChildren(module):
  1242             for child in _GetModuleChildren(module):
  1240                 if child["name"] == name:
  1243                 if child["name"] == name:
  1243                     return "Error: A module with IEC_channel %d already exists\n" % iec_channel 
  1246                     return "Error: A module with IEC_channel %d already exists\n" % iec_channel 
  1244             _GetLastModuleGroup(module).append({"name": name, 
  1247             _GetLastModuleGroup(module).append({"name": name, 
  1245                                                 "type": LOCATION_MODULE, 
  1248                                                 "type": LOCATION_MODULE, 
  1246                                                 "IEC_Channel": iec_channel, 
  1249                                                 "IEC_Channel": iec_channel, 
  1247                                                 "icon": icon, 
  1250                                                 "icon": icon, 
       
  1251                                                 "init": icode, 
  1248                                                 "children": []})
  1252                                                 "children": []})
  1249             self.RestartTimer()
  1253             self.RestartTimer()
  1250     
  1254     
  1251         def RenameModule(self, iec_location, name):
  1255         def RenameModule(self, iec_location, name):
  1252             module = self.PluginRoot.GetChildByIECLocation(iec_location)
  1256             module = self.PluginRoot.GetChildByIECLocation(iec_location)
  1274                     if child["IEC_Channel"] == new_iec_channel:
  1278                     if child["IEC_Channel"] == new_iec_channel:
  1275                         return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel
  1279                         return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel
  1276             self.PluginRoot.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
  1280             self.PluginRoot.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
  1277             module["IEC_Channel"] = new_iec_channel
  1281             module["IEC_Channel"] = new_iec_channel
  1278             self.RestartTimer()
  1282             self.RestartTimer()
  1279     
  1283         
       
  1284         def ChangeModuleInitCode(self, iec_location, icode):
       
  1285             module = self.PluginRoot.GetChildByIECLocation(iec_location)
       
  1286             if module is None:
       
  1287                 return "Error: No module found\n"
       
  1288             module["init"] = icode
       
  1289         
  1280         def RemoveModule(self, parent, iec_channel):
  1290         def RemoveModule(self, parent, iec_channel):
  1281             module = self.PluginRoot.GetChildByIECLocation(parent)
  1291             module = self.PluginRoot.GetChildByIECLocation(parent)
  1282             if module is None:
  1292             if module is None:
  1283                 return "Error: No parent found\n"
  1293                 return "Error: No parent found\n"
  1284             child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
  1294             child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
  1299                                       "type": LOCATION_GROUP, 
  1309                                       "type": LOCATION_GROUP, 
  1300                                       "icon": icon, 
  1310                                       "icon": icon, 
  1301                                       "children": []})
  1311                                       "children": []})
  1302             self.RestartTimer()
  1312             self.RestartTimer()
  1303     
  1313     
  1304         def AddVariable(self, parent, location, name, direction, type, dcode, rcode, pcode, description=""):
  1314         def AddVariable(self, parent, location, name, direction, type, rcode, pcode, description=""):
  1305             module = self.PluginRoot.GetChildByIECLocation(parent)
  1315             module = self.PluginRoot.GetChildByIECLocation(parent)
  1306             if module is None:
  1316             if module is None:
  1307                 return "Error: No parent found\n"
  1317                 return "Error: No parent found\n"
  1308             for child in _GetModuleChildren(module):
  1318             for child in _GetModuleChildren(module):
  1309                 if child["name"] == name:
  1319                 if child["name"] == name:
  1313             _GetLastModuleGroup(module).append({"name": name, 
  1323             _GetLastModuleGroup(module).append({"name": name, 
  1314                                                 "location": location, 
  1324                                                 "location": location, 
  1315                                                 "type": LOCATION_TYPES[direction], 
  1325                                                 "type": LOCATION_TYPES[direction], 
  1316                                                 "IEC_type": type, 
  1326                                                 "IEC_type": type, 
  1317                                                 "description": description, 
  1327                                                 "description": description, 
  1318                                                 "declare": dcode, 
       
  1319                                                 "retrieve": rcode, 
  1328                                                 "retrieve": rcode, 
  1320                                                 "publish": pcode})
  1329                                                 "publish": pcode})
  1321             self.RestartTimer()
  1330             self.RestartTimer()
  1322 
  1331 
  1323         def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_dcode, new_rcode, new_pcode, new_description=None):
  1332         def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_rcode, new_pcode, new_description=None):
  1324             module = self.PluginRoot.GetChildByIECLocation(parent)
  1333             module = self.PluginRoot.GetChildByIECLocation(parent)
  1325             if module is None:
  1334             if module is None:
  1326                 return "Error: No parent found\n"
  1335                 return "Error: No parent found\n"
  1327             variable = None
  1336             variable = None
  1328             for child in _GetModuleChildren(module):
  1337             for child in _GetModuleChildren(module):
  1335             if variable["name"] != new_name:
  1344             if variable["name"] != new_name:
  1336                 self.PluginRoot.UpdateProjectVariableName(variable["name"], new_name)
  1345                 self.PluginRoot.UpdateProjectVariableName(variable["name"], new_name)
  1337                 variable["name"] = new_name
  1346                 variable["name"] = new_name
  1338             variable["type"] = LOCATION_TYPES[new_direction]
  1347             variable["type"] = LOCATION_TYPES[new_direction]
  1339             variable["IEC_type"] = new_type
  1348             variable["IEC_type"] = new_type
  1340             variable["declare"] = new_dcode
       
  1341             variable["retrieve"] = new_rcode
  1349             variable["retrieve"] = new_rcode
  1342             variable["publish"] = new_pcode
  1350             variable["publish"] = new_pcode
  1343             if new_description is not None:
  1351             if new_description is not None:
  1344                 variable["description"] = new_description
  1352                 variable["description"] = new_description
  1345             self.RestartTimer()
  1353             self.RestartTimer()
  1432                                            "SetOnlineMode": ([str, str], 1),
  1440                                            "SetOnlineMode": ([str, str], 1),
  1433                                            "AddBus": ([int, str, str], 1),
  1441                                            "AddBus": ([int, str, str], 1),
  1434                                            "RenameBus": ([int, str], 0),
  1442                                            "RenameBus": ([int, str], 0),
  1435                                            "ChangeBusIECChannel": ([int, int], 0),
  1443                                            "ChangeBusIECChannel": ([int, int], 0),
  1436                                            "RemoveBus": ([int], 0),
  1444                                            "RemoveBus": ([int], 0),
  1437                                            "AddModule": ([location, int, str, str], 1), 
  1445                                            "AddModule": ([location, int, str, str, str], 1), 
  1438                                            "RenameModule": ([location, str], 0),
  1446                                            "RenameModule": ([location, str], 0),
  1439                                            "ChangeModuleIECChannel": ([location, int], 0),
  1447                                            "ChangeModuleIECChannel": ([location, int], 0),
       
  1448                                            "ChangeModuleInitCode": ([location, str], 0),
  1440                                            "RemoveModule": ([location, int], 0),
  1449                                            "RemoveModule": ([location, int], 0),
  1441                                            "StartGroup": ([location, str, str], 1),
  1450                                            "StartGroup": ([location, str, str], 1),
  1442                                            "AddVariable": ([location, location, str, str, str, str, str, str, str], 1),
  1451                                            "AddVariable": ([location, location, str, str, str, str, str, str], 1),
  1443                                            "ChangeVariableParams": ([location, location, str, str, str, str, str, str, str], 1),
  1452                                            "ChangeVariableParams": ([location, location, str, str, str, str, str, str], 1),
  1444                                            "RemoveVariable": ([location, location], 0)}.iteritems():
  1453                                            "RemoveVariable": ([location, location], 0)}.iteritems():
  1445             
  1454             
  1446             setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
  1455             setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
  1447         lpcberemiz_cmd = LPCBeremiz_Cmd(PluginRoot, Log)
  1456         lpcberemiz_cmd = LPCBeremiz_Cmd(PluginRoot, Log)
  1448         lpcberemiz_cmd.cmdloop()
  1457         lpcberemiz_cmd.cmdloop()