339 raise ValueError, "Conflict type for location \"%s\"" % name |
339 raise ValueError, "Conflict type for location \"%s\"" % name |
340 else: |
340 else: |
341 # Get only the part of the location that concern this node |
341 # Get only the part of the location that concern this node |
342 loc = location["LOC"][len(current_location):] |
342 loc = location["LOC"][len(current_location):] |
343 # loc correspond to (ID, INDEX, SUBINDEX [,BIT]) |
343 # loc correspond to (ID, INDEX, SUBINDEX [,BIT]) |
344 if len(loc) not in (3, 4): |
344 if len(loc) not in (2, 3, 4): |
345 raise ValueError, "Bad location size : %s"%str(loc) |
345 raise ValueError, "Bad location size : %s"%str(loc) |
|
346 elif len(loc) == 2: |
|
347 continue |
346 |
348 |
347 direction = location["DIR"] |
349 direction = location["DIR"] |
348 |
350 |
349 sizelocation = location["SIZE"] |
351 sizelocation = location["SIZE"] |
350 |
352 |
372 elif sizelocation != "X" and len(loc) > 3: |
374 elif sizelocation != "X" and len(loc) > 3: |
373 raise ValueError, "Cannot set bit offset for non bool '%s' variable (ID:%d,Idx:%x,sIdx:%x))" % (name,nodeid,index,subindex) |
375 raise ValueError, "Cannot set bit offset for non bool '%s' variable (ID:%d,Idx:%x,sIdx:%x))" % (name,nodeid,index,subindex) |
374 else: |
376 else: |
375 numbit = None |
377 numbit = None |
376 |
378 |
377 entryinfos = node.GetSubentryInfos(index, subindex) |
379 if location["IEC_TYPE"] != "BOOL" and subentry_infos["type"] != COlocationtype: |
378 if location["IEC_TYPE"] != "BOOL" and entryinfos["type"] != COlocationtype: |
380 raise ValueError, "Invalid type \"%s\"-> %d != %d for location\"%s\"" % (location["IEC_TYPE"], COlocationtype, subentry_infos["type"] , name) |
379 raise ValueError, "Invalid type \"%s\"-> %d != %d for location\"%s\"" % (location["IEC_TYPE"], COlocationtype, entryinfos["type"] , name) |
|
380 |
381 |
381 typeinfos = node.GetEntryInfos(COlocationtype) |
382 typeinfos = node.GetEntryInfos(COlocationtype) |
382 self.IECLocations[name] = {"type":COlocationtype, "pdotype":SlavePDOType[direction], |
383 self.IECLocations[name] = {"type":COlocationtype, "pdotype":SlavePDOType[direction], |
383 "nodeid": nodeid, "index": index,"subindex": subindex, |
384 "nodeid": nodeid, "index": index,"subindex": subindex, |
384 "bit": numbit, "size": typeinfos["size"], "sizelocation": sizelocation} |
385 "bit": numbit, "size": typeinfos["size"], "sizelocation": sizelocation} |
582 |
583 |
583 dcfgenerator = ConciseDCFGenerator(nodelist, nodename) |
584 dcfgenerator = ConciseDCFGenerator(nodelist, nodename) |
584 dcfgenerator.GenerateDCF(locations, current_location, sync_TPDOs) |
585 dcfgenerator.GenerateDCF(locations, current_location, sync_TPDOs) |
585 return dcfgenerator.GetMasterNode(), dcfgenerator.GetPointedVariables() |
586 return dcfgenerator.GetMasterNode(), dcfgenerator.GetPointedVariables() |
586 |
587 |
|
588 def LocalODPointers(locations, current_location, slave): |
|
589 IECLocations = {} |
|
590 pointers = {} |
|
591 for location in locations: |
|
592 COlocationtype = IECToCOType[location["IEC_TYPE"]] |
|
593 name = location["NAME"] |
|
594 if name in IECLocations: |
|
595 if IECLocations[name] != COlocationtype: |
|
596 raise ValueError, "Conflict type for location \"%s\"" % name |
|
597 else: |
|
598 # Get only the part of the location that concern this node |
|
599 loc = location["LOC"][len(current_location):] |
|
600 # loc correspond to (ID, INDEX, SUBINDEX [,BIT]) |
|
601 if len(loc) not in (2, 3, 4): |
|
602 raise ValueError, "Bad location size : %s"%str(loc) |
|
603 elif len(loc) != 2: |
|
604 continue |
|
605 |
|
606 # Extract and check nodeid |
|
607 index, subindex = loc[:2] |
|
608 |
|
609 # Extract and check index and subindex |
|
610 if not slave.IsEntry(index, subindex): |
|
611 raise ValueError, "No such index/subindex (%x,%x) (variable %s)" % (index, subindex, name) |
|
612 |
|
613 # Get the entry info |
|
614 subentry_infos = slave.GetSubentryInfos(index, subindex) |
|
615 if subentry_infos["type"] != COlocationtype: |
|
616 raise ValueError, "Invalid type \"%s\"-> %d != %d for location\"%s\"" % (location["IEC_TYPE"], COlocationtype, subentry_infos["type"] , name) |
|
617 |
|
618 IECLocations[name] = COlocationtype |
|
619 pointers[(index, subindex)] = name |
|
620 return pointers |
|
621 |
587 if __name__ == "__main__": |
622 if __name__ == "__main__": |
588 import os, sys, getopt |
623 import os, sys, getopt |
589 |
624 |
590 def usage(): |
625 def usage(): |
591 print """ |
626 print """ |