plugins/canfestival/config_utils.py
changeset 24 585d5b387b6a
parent 22 9a0c535c3272
child 26 7bc11b005c8b
equal deleted inserted replaced
23:e007d9d466d7 24:585d5b387b6a
    24 
    24 
    25 from types import *
    25 from types import *
    26 
    26 
    27 DicoTypes = {"BOOL":0x01, "SINT":0x02, "INT":0x03,"DINT":0x04,"LINT":0x10,
    27 DicoTypes = {"BOOL":0x01, "SINT":0x02, "INT":0x03,"DINT":0x04,"LINT":0x10,
    28              "USINT":0x05,"UINT":0x06,"UDINT":0x07,"ULINT":0x1B,"REAL":0x08,
    28              "USINT":0x05,"UINT":0x06,"UDINT":0x07,"ULINT":0x1B,"REAL":0x08,
    29              "LREAL":0x11,"STRING":0x09,"BYTE":0x02,"WORD":0x03,"DWORD":0x04,
    29              "LREAL":0x11,"STRING":0x09,"BYTE":0x05,"WORD":0x06,"DWORD":0x07,
    30              "LWORD":0x1B,"WSTRING":0x0B}
    30              "LWORD":0x1B,"WSTRING":0x0B}
    31 
    31 
    32 DictLocations = {}
    32 DictLocations = {}
    33 DictCobID = {}
    33 DictCobID = {}
    34 DictLocationsNotMapped = {}
    34 DictLocationsNotMapped = {}
   209         else:
   209         else:
   210             #get only the part of the location that concern this node
   210             #get only the part of the location that concern this node
   211             loc = location["LOC"][len(current_location):]
   211             loc = location["LOC"][len(current_location):]
   212             # loc correspond to (ID, INDEX, SUBINDEX [,BIT])
   212             # loc correspond to (ID, INDEX, SUBINDEX [,BIT])
   213             if len(loc) not in (3, 4):
   213             if len(loc) not in (3, 4):
   214                 raise ValueError, "Bad location size"
   214                 raise ValueError, "Bad location size : %s"%str(loc)
   215             
   215             
   216             direction = location["DIR"]
   216             direction = location["DIR"]
   217             
   217             
   218             sizelocation = location["SIZE"]
   218             sizelocation = location["SIZE"]
   219             
   219             
   241                 elif sizelocation != "X" and len(loc) > 3:
   241                 elif sizelocation != "X" and len(loc) > 3:
   242                     raise ValueError, "Cannot set bit offset for non bool '%s' variable (ID:%d,Idx:%x,sIdx:%x))" % (name,nodeid,index,subindex)
   242                     raise ValueError, "Cannot set bit offset for non bool '%s' variable (ID:%d,Idx:%x,sIdx:%x))" % (name,nodeid,index,subindex)
   243                 else:
   243                 else:
   244                     numbit = None
   244                     numbit = None
   245                 
   245                 
   246                 locationtype = DicoTypes[locationtype]
   246                 COlocationtype = DicoTypes[locationtype]
   247                 entryinfos = node.GetSubentryInfos(index, subindex)
   247                 entryinfos = node.GetSubentryInfos(index, subindex)
   248                 if entryinfos["type"] != locationtype:
   248                 if entryinfos["type"] != COlocationtype:
   249                     raise ValueError, "Invalid type for location \"%s\"" % name
   249                     raise ValueError, "Invalid type \"%s\"-> %d != %d  for location\"%s\"" % (locationtype,COlocationtype, entryinfos["type"] , name)
   250                 
   250                 
   251                 typeinfos = node.GetEntryInfos(locationtype)
   251                 typeinfos = node.GetEntryInfos(COlocationtype)
   252                 DictLocations[name] = {"type":locationtype, "pdotype":SlavePDOType[direction],
   252                 DictLocations[name] = {"type":COlocationtype, "pdotype":SlavePDOType[direction],
   253                                        "nodeid": nodeid, "index": index,"subindex": subindex, 
   253                                        "nodeid": nodeid, "index": index,"subindex": subindex,
   254                                        "bit": numbit, "size": typeinfos["size"], "busname": busname, "sizelocation": sizelocation}
   254                                        "bit": numbit, "size": typeinfos["size"], "sizelocation": sizelocation}
   255             else:
   255             else:
   256                 raise ValueError, "Not PDO mappable variable : '%s' (ID:%d,Idx:%x,sIdx:%x))" % (name,nodeid,index,subindex)
   256                 raise ValueError, "Not PDO mappable variable : '%s' (ID:%d,Idx:%x,sIdx:%x))" % (name,nodeid,index,subindex)
   257                 
   257                 
   258     # Create DictCobID with variables already mapped and add them in DictValidLocations
   258     # Create DictCobID with variables already mapped and add them in DictValidLocations
   259     for name, locationinfos in DictLocations.items():
   259     for name, locationinfos in DictLocations.items():
   373             new_index = False
   373             new_index = False
   374             
   374             
   375             if type(variable) != IntType:
   375             if type(variable) != IntType:
   376                 
   376                 
   377                 typeidx, varname = variable
   377                 typeidx, varname = variable
   378                 indexname = DictNameVariable[DictLocations[variable[1]]["pdotype"]][0] + DictLocations[variable[1]]["sizelocation"] + str(DictLocations[variable[1]]["busname"]) + "_" + str(DictLocations[variable[1]]["nodeid"])
   378                 indexname = \
       
   379                     DictNameVariable[DictLocations[variable[1]]["pdotype"]][0] + \
       
   380                     DictLocations[variable[1]]["sizelocation"] + \
       
   381                     '_'.join(map(str,current_location)) + \
       
   382                     "_" + \
       
   383                     str(DictLocations[variable[1]]["nodeid"])
   379                 mapvariableidx = DictNameVariable[DictLocations[variable[1]]["pdotype"]][1] +  DictNameVariable[DictLocations[variable[1]]["sizelocation"]] * DictNameVariable["increment"]
   384                 mapvariableidx = DictNameVariable[DictLocations[variable[1]]["pdotype"]][1] +  DictNameVariable[DictLocations[variable[1]]["sizelocation"]] * DictNameVariable["increment"]
       
   385 
       
   386                 #indexname = DictNameVariable[DictLocations[variable[1]]["pdotype"]][0] + DictLocations[variable[1]]["sizelocation"] + str(DictLocations[variable[1]]["prefix"]) + "_" + str(DictLocations[variable[1]]["nodeid"])
       
   387                 #mapvariableidx = DictNameVariable[DictLocations[variable[1]]["pdotype"]][1] +  DictNameVariable[DictLocations[variable[1]]["sizelocation"]] * DictNameVariable["increment"]
   380                 
   388                 
   381                 if not masternode.IsEntry(mapvariableidx):
   389                 if not masternode.IsEntry(mapvariableidx):
   382                     manager.AddMapVariableToCurrent(mapvariableidx, indexname, 3, 1, masternode)
   390                     manager.AddMapVariableToCurrent(mapvariableidx, indexname, 3, 1, masternode)
   383                     new_index = True
   391                     new_index = True
   384                     nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)
   392                     nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)