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: |
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() |