346 for location in locations: |
346 for location in locations: |
347 COlocationtype = IECToCOType[location["IEC_TYPE"]] |
347 COlocationtype = IECToCOType[location["IEC_TYPE"]] |
348 name = location["NAME"] |
348 name = location["NAME"] |
349 if name in self.IECLocations: |
349 if name in self.IECLocations: |
350 if self.IECLocations[name]["type"] != COlocationtype: |
350 if self.IECLocations[name]["type"] != COlocationtype: |
351 raise PDOmappingException, _("Type conflict for location \"%s\"") % name |
351 raise PDOmappingException(_("Type conflict for location \"%s\"") % name) |
352 else: |
352 else: |
353 # Get only the part of the location that concern this node |
353 # Get only the part of the location that concern this node |
354 loc = location["LOC"][len(current_location):] |
354 loc = location["LOC"][len(current_location):] |
355 # loc correspond to (ID, INDEX, SUBINDEX [,BIT]) |
355 # loc correspond to (ID, INDEX, SUBINDEX [,BIT]) |
356 if len(loc) not in (2, 3, 4): |
356 if len(loc) not in (2, 3, 4): |
357 raise PDOmappingException, _("Bad location size : %s") % str(loc) |
357 raise PDOmappingException(_("Bad location size : %s") % str(loc)) |
358 elif len(loc) == 2: |
358 elif len(loc) == 2: |
359 continue |
359 continue |
360 |
360 |
361 direction = location["DIR"] |
361 direction = location["DIR"] |
362 |
362 |
365 # Extract and check nodeid |
365 # Extract and check nodeid |
366 nodeid, index, subindex = loc[:3] |
366 nodeid, index, subindex = loc[:3] |
367 |
367 |
368 # Check Id is in slave node list |
368 # Check Id is in slave node list |
369 if nodeid not in self.NodeList.SlaveNodes.keys(): |
369 if nodeid not in self.NodeList.SlaveNodes.keys(): |
370 raise PDOmappingException, _("Non existing node ID : {a1} (variable {a2})").format(a1=nodeid, a2=name) |
370 raise PDOmappingException( |
|
371 _("Non existing node ID : {a1} (variable {a2})"). |
|
372 format(a1=nodeid, a2=name)) |
371 |
373 |
372 # Get the model for this node (made from EDS) |
374 # Get the model for this node (made from EDS) |
373 node = self.NodeList.SlaveNodes[nodeid]["Node"] |
375 node = self.NodeList.SlaveNodes[nodeid]["Node"] |
374 |
376 |
375 # Extract and check index and subindex |
377 # Extract and check index and subindex |
376 if not node.IsEntry(index, subindex): |
378 if not node.IsEntry(index, subindex): |
377 msg = _("No such index/subindex ({a1},{a2}) in ID : {a3} (variable {a4})").\ |
379 msg = _("No such index/subindex ({a1},{a2}) in ID : {a3} (variable {a4})").\ |
378 format(a1="%x" % index, a2="%x" % subindex, a3=nodeid, a4=name) |
380 format(a1="%x" % index, a2="%x" % subindex, a3=nodeid, a4=name) |
379 raise PDOmappingException, msg |
381 raise PDOmappingException(msg) |
380 |
382 |
381 # Get the entry info |
383 # Get the entry info |
382 subentry_infos = node.GetSubentryInfos(index, subindex) |
384 subentry_infos = node.GetSubentryInfos(index, subindex) |
383 |
385 |
384 # If a PDO mappable |
386 # If a PDO mappable |
385 if subentry_infos and subentry_infos["pdo"]: |
387 if subentry_infos and subentry_infos["pdo"]: |
386 if sizelocation == "X" and len(loc) > 3: |
388 if sizelocation == "X" and len(loc) > 3: |
387 numbit = loc[3] |
389 numbit = loc[3] |
388 elif sizelocation != "X" and len(loc) > 3: |
390 elif sizelocation != "X" and len(loc) > 3: |
389 msg = _("Cannot set bit offset for non bool '{a1}' variable (ID:{a2},Idx:{a3},sIdx:{a4}))").\ |
391 raise PDOmappingException( |
390 format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex) |
392 _("Cannot set bit offset for non bool '{a1}' variable (ID:{a2},Idx:{a3},sIdx:{a4}))"). |
391 raise PDOmappingException, msg |
393 format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex)) |
392 else: |
394 else: |
393 numbit = None |
395 numbit = None |
394 |
396 |
395 if location["IEC_TYPE"] != "BOOL" and subentry_infos["type"] != COlocationtype: |
397 if location["IEC_TYPE"] != "BOOL" and subentry_infos["type"] != COlocationtype: |
396 raise PDOmappingException, _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\"").\ |
398 raise PDOmappingException( |
397 format(a1=location["IEC_TYPE"], a2=COlocationtype, a3=subentry_infos["type"], a4=name) |
399 _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\""). |
|
400 format(a1=location["IEC_TYPE"], |
|
401 a2=COlocationtype, |
|
402 a3=subentry_infos["type"], |
|
403 a4=name)) |
398 |
404 |
399 typeinfos = node.GetEntryInfos(COlocationtype) |
405 typeinfos = node.GetEntryInfos(COlocationtype) |
400 self.IECLocations[name] = { |
406 self.IECLocations[name] = { |
401 "type": COlocationtype, |
407 "type": COlocationtype, |
402 "pdotype": SlavePDOType[direction], |
408 "pdotype": SlavePDOType[direction], |
406 "bit": numbit, |
412 "bit": numbit, |
407 "size": typeinfos["size"], |
413 "size": typeinfos["size"], |
408 "sizelocation": sizelocation |
414 "sizelocation": sizelocation |
409 } |
415 } |
410 else: |
416 else: |
411 raise PDOmappingException, _("Not PDO mappable variable : '{a1}' (ID:{a2},Idx:{a3},sIdx:{a4}))").\ |
417 raise PDOmappingException( |
412 format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex) |
418 _("Not PDO mappable variable : '{a1}' (ID:{a2},Idx:{a3},sIdx:{a4}))"). |
|
419 format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex)) |
413 |
420 |
414 #------------------------------------------------------------------------------- |
421 #------------------------------------------------------------------------------- |
415 # Search for locations already mapped |
422 # Search for locations already mapped |
416 #------------------------------------------------------------------------------- |
423 #------------------------------------------------------------------------------- |
417 |
424 |
479 if len(locations[pdotype]) > 0: |
486 if len(locations[pdotype]) > 0: |
480 pdosize = 0 |
487 pdosize = 0 |
481 pdomapping = [] |
488 pdomapping = [] |
482 result = self.GetEmptyPDO(nodeid, pdotype) |
489 result = self.GetEmptyPDO(nodeid, pdotype) |
483 if result is None: |
490 if result is None: |
484 raise PDOmappingException, _("Unable to define PDO mapping for node %02x") % nodeid |
491 raise PDOmappingException( |
|
492 _("Unable to define PDO mapping for node %02x") % nodeid) |
485 pdoindex, pdocobid, pdonbparams = result |
493 pdoindex, pdocobid, pdonbparams = result |
486 for name, loc_infos in locations[pdotype]: |
494 for name, loc_infos in locations[pdotype]: |
487 pdosize += loc_infos["size"] |
495 pdosize += loc_infos["size"] |
488 # If pdo's size > 64 bits |
496 # If pdo's size > 64 bits |
489 if pdosize > 64 or len(pdomapping) >= pdonbparams: |
497 if pdosize > 64 or len(pdomapping) >= pdonbparams: |
493 nbparams += nbaddedparams |
501 nbparams += nbaddedparams |
494 pdosize = loc_infos["size"] |
502 pdosize = loc_infos["size"] |
495 pdomapping = [(name, loc_infos)] |
503 pdomapping = [(name, loc_infos)] |
496 result = self.GetEmptyPDO(nodeid, pdotype, pdoindex + 1) |
504 result = self.GetEmptyPDO(nodeid, pdotype, pdoindex + 1) |
497 if result is None: |
505 if result is None: |
498 raise PDOmappingException, _("Unable to define PDO mapping for node %02x") % nodeid |
506 raise PDOmappingException( |
|
507 _("Unable to define PDO mapping for node %02x") % nodeid) |
499 pdoindex, pdocobid, pdonbparams = result |
508 pdoindex, pdocobid, pdonbparams = result |
500 else: |
509 else: |
501 pdomapping.append((name, loc_infos)) |
510 pdomapping.append((name, loc_infos)) |
502 # If there isn't locations yet but there is still a PDO to generate |
511 # If there isn't locations yet but there is still a PDO to generate |
503 if len(pdomapping) > 0: |
512 if len(pdomapping) > 0: |
643 for location in locations: |
652 for location in locations: |
644 COlocationtype = IECToCOType[location["IEC_TYPE"]] |
653 COlocationtype = IECToCOType[location["IEC_TYPE"]] |
645 name = location["NAME"] |
654 name = location["NAME"] |
646 if name in IECLocations: |
655 if name in IECLocations: |
647 if IECLocations[name] != COlocationtype: |
656 if IECLocations[name] != COlocationtype: |
648 raise PDOmappingException, _("Type conflict for location \"%s\"") % name |
657 raise PDOmappingException(_("Type conflict for location \"%s\"") % name) |
649 else: |
658 else: |
650 # Get only the part of the location that concern this node |
659 # Get only the part of the location that concern this node |
651 loc = location["LOC"][len(current_location):] |
660 loc = location["LOC"][len(current_location):] |
652 # loc correspond to (ID, INDEX, SUBINDEX [,BIT]) |
661 # loc correspond to (ID, INDEX, SUBINDEX [,BIT]) |
653 if len(loc) not in (2, 3, 4): |
662 if len(loc) not in (2, 3, 4): |
654 raise PDOmappingException, _("Bad location size : %s") % str(loc) |
663 raise PDOmappingException(_("Bad location size : %s") % str(loc)) |
655 elif len(loc) != 2: |
664 elif len(loc) != 2: |
656 continue |
665 continue |
657 |
666 |
658 # Extract and check nodeid |
667 # Extract and check nodeid |
659 index, subindex = loc[:2] |
668 index, subindex = loc[:2] |
660 |
669 |
661 # Extract and check index and subindex |
670 # Extract and check index and subindex |
662 if not slave.IsEntry(index, subindex): |
671 if not slave.IsEntry(index, subindex): |
663 raise PDOmappingException, _("No such index/subindex ({a1},{a2}) (variable {a3})").\ |
672 raise PDOmappingException( |
664 format(a1="%x" % index, a2="%x" % subindex, a3=name) |
673 _("No such index/subindex ({a1},{a2}) (variable {a3})"). |
|
674 format(a1="%x" % index, a2="%x" % subindex, a3=name)) |
665 |
675 |
666 # Get the entry info |
676 # Get the entry info |
667 subentry_infos = slave.GetSubentryInfos(index, subindex) |
677 subentry_infos = slave.GetSubentryInfos(index, subindex) |
668 if subentry_infos["type"] != COlocationtype: |
678 if subentry_infos["type"] != COlocationtype: |
669 raise PDOmappingException, _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\"").\ |
679 raise PDOmappingException( |
670 format(a1=location["IEC_TYPE"], a2=COlocationtype, a3=subentry_infos["type"], a4=name) |
680 _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\""). |
|
681 format(a1=location["IEC_TYPE"], |
|
682 a2=COlocationtype, |
|
683 a3=subentry_infos["type"], |
|
684 a4=name)) |
671 |
685 |
672 IECLocations[name] = COlocationtype |
686 IECLocations[name] = COlocationtype |
673 pointers[(index, subindex)] = name |
687 pointers[(index, subindex)] = name |
674 return pointers |
688 return pointers |
675 |
689 |