canfestival/config_utils.py
changeset 2450 5024c19ca8f0
parent 2418 5587c490a070
child 3750 f62625418bff
equal deleted inserted replaced
2449:b0560adec4b7 2450:5024c19ca8f0
    26 from __future__ import absolute_import
    26 from __future__ import absolute_import
    27 from __future__ import print_function
    27 from __future__ import print_function
    28 import os
    28 import os
    29 import sys
    29 import sys
    30 import getopt
    30 import getopt
    31 from types import *
    31 from past.builtins import long
    32 
    32 
    33 # Translation between IEC types and Can Open types
    33 # Translation between IEC types and Can Open types
    34 IECToCOType = {
    34 IECToCOType = {
    35     "BOOL":    0x01,
    35     "BOOL":    0x01,
    36     "SINT":    0x02,
    36     "SINT":    0x02,
   463                             mapping.append(value % 0x100)
   463                             mapping.append(value % 0x100)
   464                     self.MasterMapping[cobid] = {"type": InvertPDOType[locationinfos["pdotype"]], "mapping": mapping}
   464                     self.MasterMapping[cobid] = {"type": InvertPDOType[locationinfos["pdotype"]], "mapping": mapping}
   465 
   465 
   466                 # Indicate that this PDO entry must be saved
   466                 # Indicate that this PDO entry must be saved
   467                 if locationinfos["bit"] is not None:
   467                 if locationinfos["bit"] is not None:
   468                     if not isinstance(self.MasterMapping[cobid]["mapping"][subindex], ListType):
   468                     if not isinstance(self.MasterMapping[cobid]["mapping"][subindex], list):
   469                         self.MasterMapping[cobid]["mapping"][subindex] = [1] * self.MasterMapping[cobid]["mapping"][subindex]
   469                         self.MasterMapping[cobid]["mapping"][subindex] = [1] * self.MasterMapping[cobid]["mapping"][subindex]
   470                     if locationinfos["bit"] < len(self.MasterMapping[cobid]["mapping"][subindex]):
   470                     if locationinfos["bit"] < len(self.MasterMapping[cobid]["mapping"][subindex]):
   471                         self.MasterMapping[cobid]["mapping"][subindex][locationinfos["bit"]] = (locationinfos["type"], name)
   471                         self.MasterMapping[cobid]["mapping"][subindex][locationinfos["bit"]] = (locationinfos["type"], name)
   472                 else:
   472                 else:
   473                     self.MasterMapping[cobid]["mapping"][subindex] = (locationinfos["type"], name)
   473                     self.MasterMapping[cobid]["mapping"][subindex] = (locationinfos["type"], name)
   555             else:
   555             else:
   556                 self.MasterNode.SetEntry(current_idx, 0x02, 0xFF)
   556                 self.MasterNode.SetEntry(current_idx, 0x02, 0xFF)
   557 
   557 
   558             mapping = []
   558             mapping = []
   559             for item in pdo_infos["mapping"]:
   559             for item in pdo_infos["mapping"]:
   560                 if isinstance(item, ListType):
   560                 if isinstance(item, list):
   561                     mapping.extend(item)
   561                     mapping.extend(item)
   562                 else:
   562                 else:
   563                     mapping.append(item)
   563                     mapping.append(item)
   564 
   564 
   565             # Add some subentries to PDO mapping if there is not enough
   565             # Add some subentries to PDO mapping if there is not enough
   570             for subindex, variable in enumerate(mapping):
   570             for subindex, variable in enumerate(mapping):
   571                 if subindex == 0:
   571                 if subindex == 0:
   572                     continue
   572                     continue
   573                 new_index = False
   573                 new_index = False
   574 
   574 
   575                 if isinstance(variable, (IntType, LongType)):
   575                 if isinstance(variable, (int, long)):
   576                     # If variable is an integer then variable is unexpected
   576                     # If variable is an integer then variable is unexpected
   577                     self.MasterNode.SetEntry(current_idx + 0x200, subindex, self.TrashVariables[variable])
   577                     self.MasterNode.SetEntry(current_idx + 0x200, subindex, self.TrashVariables[variable])
   578                 else:
   578                 else:
   579                     typeidx, varname = variable
   579                     typeidx, varname = variable
   580                     variable_infos = self.IECLocations[varname]
   580                     variable_infos = self.IECLocations[varname]