plugins/canfestival/config_utils.py
author greg
Tue, 11 Sep 2007 15:10:56 +0200
changeset 27 1db681d34579
parent 26 7bc11b005c8b
child 34 2721e6910f5a
permissions -rw-r--r--
CONFIG_UTILS (sync)
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     3
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     4
#This file is part of Beremiz, a Integrated Development Environment for
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     5
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. 
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     6
#
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     8
#
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    10
#
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    15
#
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    19
#General Public License for more details.
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    20
#
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    24
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    25
from types import *
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    26
27
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    27
# Translation between IEC types and Can Open types
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    28
DicoTypes = {"BOOL":0x01, "SINT":0x02, "INT":0x03,"DINT":0x04,"LINT":0x10,
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    29
             "USINT":0x05,"UINT":0x06,"UDINT":0x07,"ULINT":0x1B,"REAL":0x08,
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 22
diff changeset
    30
             "LREAL":0x11,"STRING":0x09,"BYTE":0x05,"WORD":0x06,"DWORD":0x07,
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    31
             "LWORD":0x1B,"WSTRING":0x0B}
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    32
27
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    33
DictNameVariable = { "" : 1, "X": 2, "B": 3, "W": 4, "D": 5, "L": 6, "increment": 0x100, 1:("__I", 0x2000), 2:("__Q", 0x4000)}
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    34
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    35
# Constants for PDO types 
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    36
RPDO = 1
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    37
TPDO = 2
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    38
SlavePDOType = {"I" : TPDO, "Q" : RPDO}
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    39
InvertPDOType = {RPDO : TPDO, TPDO : RPDO}
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    40
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    41
GenerateMasterMapping = lambda x:[None] + [(loc_infos["type"], name) for name, loc_infos in x]
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    42
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    43
TrashVariableSizes = {1 : 0x01, 8 : 0x05, 16 : 0x06, 32 : 0x07, 64 : 0x1B}
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    44
27
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    45
def LE_to_BE(value, size):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    46
    """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    47
    Convert Little Endian to Big Endian
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    48
    @param value: value expressed in integer
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    49
    @param size: number of bytes generated
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    50
    @return: a string containing the value converted
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    51
    """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    52
    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    53
    data = ("%" + str(size * 2) + "." + str(size * 2) + "X") % value
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    54
    list_car = [data[i:i+2] for i in xrange(0, len(data), 2)]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    55
    list_car.reverse()
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    56
    return "".join([chr(int(car, 16)) for car in list_car])
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    57
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    58
def GetNodePDOIndexes(node, type, parameters = False):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    59
    """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    60
    Find the PDO indexes of a node
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    61
    @param node: node 
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    62
    @param type: type of PDO searched (RPDO or TPDO or both)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    63
    @param parameters: indicate which indexes are expected (PDO paramaters : True or PDO mappings : False)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    64
    @return: a list of indexes found
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    65
    """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    66
    
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    67
    indexes = []
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    68
    if type & RPDO:
27
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    69
        indexes.extend([idx for idx in node.GetIndexes() if 0x1400 <= idx <= 0x15FF])
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    70
    if type & TPDO:
27
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    71
        indexes.extend([idx for idx in node.GetIndexes() if 0x1800 <= idx <= 0x19FF])
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    72
    if not parameters:
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    73
        return [idx + 0x200 for idx in indexes]
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    74
    else:
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    75
        return indexes
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    76
27
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    77
def SearchNodePDOMapping(loc_infos, node):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    78
    """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    79
    Find the PDO indexes of a node
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    80
    @param node: node 
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    81
    @param type: type of PDO searched (RPDO or TPDO or both)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    82
    @param parameters: indicate which indexes are expected (PDO paramaters : True or PDO mappings : False)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    83
    @return: a list of indexes found
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    84
    """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    85
    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    86
    typeinfos = node.GetEntryInfos(loc_infos["type"])
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    87
    model = (loc_infos["index"] << 16) + (loc_infos["subindex"] << 8) + typeinfos["size"]
27
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    88
    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    89
    for PDOidx in GetNodePDOIndexes(node, loc_infos["pdotype"]):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    90
        values = node.GetEntry(PDOidx)
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    91
        if values != None:
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    92
            for subindex, mapping in enumerate(values):
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    93
                if subindex != 0 and mapping == model:
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    94
                    return PDOidx, subindex
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    95
    return None
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    96
27
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    97
class ConciseDCFGenerator:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    98
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
    99
    def __init__(self, nodelist):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   100
        # Dictionary of location informations classed by name
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   101
        self.DictLocations = {}
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   102
        # Dictionary of location informations classed by name
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   103
        self.DictCobID = {}
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   104
        # Dictionary of location that have not been mapped yet
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   105
        self.DictLocationsNotMapped = {}
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   106
        # List of COB IDs available
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   107
        self.ListCobIDAvailable = range(0x180, 0x580)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   108
        self.SlavesPdoNumber = {}
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   109
        # Dictionary of mapping value where unexpected variables are stored
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   110
        TrashVariableValue = {}
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   111
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   112
        self.NodeList = nodelist
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   113
        self.Manager = self.NodeList.Manager
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   114
        self.MasterNode = self.Manager.GetCurrentNodeCopy()
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   115
        self.PrepareMasterNode()
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   116
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   117
    def RemoveUsedNodeCobId(self, node):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   118
        """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   119
        Remove all PDO COB ID used by the given node from the list of available COB ID
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   120
        @param node: node
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   121
        @return: a tuple of number of RPDO and TPDO for the node
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   122
        """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   123
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   124
        # Get list of all node TPDO and RPDO indexes
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   125
        nodeRpdoIndexes = GetNodePDOIndexes(node, RPDO, True)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   126
        nodeTpdoIndexes = GetNodePDOIndexes(node, TPDO, True)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   127
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   128
        # Mark all the COB ID of the node already mapped PDO as not available
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   129
        for PdoIdx in nodeRpdoIndexes + nodeTpdoIndexes:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   130
            pdo_cobid = node.GetEntry(PdoIdx, 0x01)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   131
            # Extract COB ID, if PDO isn't active
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   132
            if pdo_cobid > 0x600 :
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   133
                pdo_cobid -= 0x80000000
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   134
            # Remove COB ID from the list of available COB ID
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   135
            if pdo_cobid in self.ListCobIDAvailable:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   136
                self.ListCobIDAvailable.remove(pdo_cobid)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   137
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   138
        return len(nodeRpdoIndexes), len(nodeTpdoIndexes)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   139
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   140
    def PrepareMasterNode(self):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   141
        """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   142
        Add mandatory entries for DCF generation into MasterNode.
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   143
        """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   144
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   145
        # Adding DCF entry into Master node
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   146
        if not self.MasterNode.IsEntry(0x1F22):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   147
            self.MasterNode.AddEntry(0x1F22, 1, "")
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   148
        self.Manager.AddSubentriesToCurrent(0x1F22, 127, masternode)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   149
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   150
        # Adding trash mappable variables for unused mapped datas
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   151
        idxTrashVariables = 0x2000 + masternode.GetNodeID()
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   152
        # Add an entry for storing unexpected all variable
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   153
        self.Manager.AddMapVariableToCurrent(idxTrashVariables, "trashvariables", 3, len(TrashVariableSizes), self.MasterNode)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   154
        for subidx, (size, typeidx) in enumerate(TrashVariableSizes.items()):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   155
            # Add a subentry for storing unexpected variable of this size
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   156
            self.Manager.SetCurrentEntry(idxTrashVariables, subidx + 1, "TRASH%d" % size, "name", None, self.MasterNode)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   157
            self.Manager.SetCurrentEntry(idxTrashVariables, subidx + 1, typeidx, "type", None, self.MasterNode)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   158
            # Store the mapping value for this entry
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   159
            self.TrashVariableValue[size] = (idxTrashVariables << 16) + ((subidx + 1) << 8) + size
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   160
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   161
        RPDOnumber, TPDOnumber = self.RemoveUsedNodeCobId(self.MasterNode)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   162
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   163
        # Store the indexes of the first RPDO and TPDO available for MasterNode
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   164
        self.CurrentPDOParamsIdx = {RPDO : 0x1400 + RPDOnumber, TPDO : 0x1800 + TPDOnumber}
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   165
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   166
        # Prepare MasterNode with all nodelist slaves
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   167
        for nodeid, nodeinfos in self.NodeList.SlaveNodes.items():
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   168
            node = nodeinfos["Node"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   169
            node.SetNodeID(nodeid)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   170
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   171
            RPDOnumber, TPDOnumber = self.RemoveUsedNodeCobId(node)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   172
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   173
            # Store the number of TPDO and RPDO for this node
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   174
            self.SlavesPdoNumber[nodeid] = {RPDO : RPDOnumber, TPDO : TPDOnumber}
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   175
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   176
            # Get Slave's default SDO server parameters
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   177
            RSDO_cobid = node.GetEntry(0x1200,0x01)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   178
            if not RSDO_cobid:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   179
                RSDO_cobid = 0x600 + nodeid
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   180
            TSDO_cobid = node.GetEntry(0x1200,0x02)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   181
            if not TSDO_cobid:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   182
                TSDO_cobid = 0x580 + nodeid
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   183
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   184
            # Configure Master's SDO parameters entries
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   185
            self.Manager.ManageEntriesOfCurrent([0x1280 + nodeid], [], self.MasterNode)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   186
            self.MasterNode.SetEntry(0x1280 + nodeid, 0x01, RSDO_cobid)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   187
            self.MasterNode.SetEntry(0x1280 + nodeid, 0x02, TSDO_cobid)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   188
            self.MasterNode.SetEntry(0x1280 + nodeid, 0x03, nodeid)        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   189
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   190
    def GetMasterNode(self):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   191
        """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   192
        Return MasterNode.
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   193
        """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   194
        return self.MasterNode
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   195
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   196
    # Build concise DCF
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   197
    def GenerateMappingDCF(cobid, idx, pdomapping, mapped):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   198
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   199
        # Create entry for RPDO or TPDO parameters and Disable PDO
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   200
        dcfdata = LE_to_BE(idx, 2) + LE_to_BE(0x01, 1) + LE_to_BE(0x04, 4) + LE_to_BE((0x80000000 + cobid), 4)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   201
        # Set Transmit type synchrone
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   202
        dcfdata += LE_to_BE(idx, 2) + LE_to_BE(0x02, 1) + LE_to_BE(0x01, 4) + LE_to_BE(DefaultTransmitTypeSlave, 1)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   203
        # Re-Enable PDO
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   204
        #         ---- INDEX -----   --- SUBINDEX ----   ----- SIZE ------   ------ DATA ------
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   205
        dcfdata += LE_to_BE(idx, 2) + LE_to_BE(0x01, 1) + LE_to_BE(0x04, 4) + LE_to_BE(0x00000000 + cobid, 4)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   206
        nbparams = 3
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   207
        if mapped == False and pdomapping != None:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   208
        # Map Variables
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   209
            for subindex, (name, loc_infos) in enumerate(pdomapping):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   210
                value = (loc_infos["index"] << 16) + (loc_infos["subindex"] << 8) + loc_infos["size"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   211
                dcfdata += LE_to_BE(idx + 0x200, 2) + LE_to_BE(subindex + 1, 1) + LE_to_BE(0x04, 4) + LE_to_BE(value, 4)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   212
                nbparams += 1
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   213
        return dcfdata, nbparams
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   214
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   215
    # Return a cobid not used
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   216
    def GetNewCobID(self, nodeid, type):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   217
        """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   218
        Select a COB ID from the list of those available
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   219
        @param nodeid: id of the slave node
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   220
        @param type: type of PDO (RPDO or TPDO)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   221
        @return: a tuple of the COD ID and PDO index or None
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   222
        """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   223
        # Verify that there is still some cobid available
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   224
        if len(self.ListCobIDAvailable) == 0:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   225
            return None
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   226
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   227
        # Get the number of PDO of the type given for the node
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   228
        nbSlavePDO = self.SlavesPdoNumber[nodeid][type]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   229
        if type == RPDO:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   230
            if nbSlavePDO < 4:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   231
                # For the four first RPDO -> cobid = 0x200 + ( numPdo parameters * 0x100) + nodeid
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   232
                newcobid = (0x200 + nbSlavePDO * 0x100 + nodeid)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   233
                # Return calculated cobid if it's still available
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   234
                if newcobid in self.ListCobIDAvailable:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   235
                    self.ListCobIDAvailable.remove(newcobid)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   236
                    return newcobid, 0x1400 + nbSlavePDO
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   237
            # Return the first cobid available if no cobid found
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   238
            return self.ListCobIDAvailable.pop(0), 0x1400 + nbSlavePDO
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   239
    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   240
        elif type == TPDO:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   241
            if nbSlavePDO < 4:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   242
                # For the four first TPDO -> cobid = 0x180 + ( numPdo parameters * 0x100) + nodeid
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   243
                newcobid = (0x180 + nbSlavePDO * 0x100 + nodeid)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   244
                # Return calculated cobid if it's still available
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   245
                if newcobid in self.ListCobIDAvailable:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   246
                    self.ListCobIDAvailable.remove(newcobid)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   247
                    return newcobid, 0x1800 + nbSlavePDO
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   248
            # Return the first cobid available if no cobid found
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   249
            return self.ListCobIDAvailable.pop(0), 0x1800 + nbSlavePDO
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   250
        
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   251
        return None
27
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   252
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   253
    def GenerateDCF(self, locations, current_location, sync_TPDOs):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   254
        """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   255
        Generate Concise DCF of MasterNode for the locations list given
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   256
        @param locations: list of locations to be mapped
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   257
        @param current_location: tuple of the located prefixes not to be considered
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   258
        @param sync_TPDOs: indicate if TPDO must be synchronous
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   259
        """
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   260
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   261
        # Get list of locations check if exists and mappables -> put them in DictLocations
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   262
        for location in locations:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   263
            COlocationtype = DicoTypes[location["IEC_TYPE"]]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   264
            name = location["NAME"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   265
            if name in DictLocations:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   266
                if DictLocations[name]["type"] != COlocationtype:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   267
                    raise ValueError, "Conflict type for location \"%s\"" % name 
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   268
            else:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   269
                # Get only the part of the location that concern this node
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   270
                loc = location["LOC"][len(current_location):]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   271
                # loc correspond to (ID, INDEX, SUBINDEX [,BIT])
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   272
                if len(loc) not in (3, 4):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   273
                    raise ValueError, "Bad location size : %s"%str(loc)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   274
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   275
                direction = location["DIR"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   276
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   277
                sizelocation = location["SIZE"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   278
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   279
                # Extract and check nodeid
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   280
                nodeid, index, subindex = loc[:3]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   281
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   282
                # Check Id is in slave node list
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   283
                if nodeid not in nodelist.SlaveNodes.keys():
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   284
                    raise ValueError, "Non existing node ID : %d (variable %s)" % (nodeid,name)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   285
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   286
                # Get the model for this node (made from EDS)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   287
                node = nodelist.SlaveNodes[nodeid]["Node"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   288
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   289
                # Extract and check index and subindex
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   290
                if not node.IsEntry(index, subindex):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   291
                    raise ValueError, "No such index/subindex (%x,%x) in ID : %d (variable %s)" % (index,subindex,nodeid,name)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   292
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   293
                #Get the entry info
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   294
                subentry_infos = node.GetSubentryInfos(index, subindex)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   295
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   296
                # If a PDO mappable
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   297
                if subentry_infos and subentry_infos["pdo"]:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   298
                    if sizelocation == "X" and len(loc) > 3:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   299
                        numbit = loc[4]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   300
                    elif sizelocation != "X" and len(loc) > 3:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   301
                        raise ValueError, "Cannot set bit offset for non bool '%s' variable (ID:%d,Idx:%x,sIdx:%x))" % (name,nodeid,index,subindex)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   302
                    else:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   303
                        numbit = None
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   304
                    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   305
                    entryinfos = node.GetSubentryInfos(index, subindex)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   306
                    if entryinfos["type"] != COlocationtype:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   307
                        raise ValueError, "Invalid type \"%s\"-> %d != %d  for location\"%s\"" % (location["IEC_TYPE"], COlocationtype, entryinfos["type"] , name)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   308
                    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   309
                    typeinfos = node.GetEntryInfos(COlocationtype)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   310
                    DictLocations[name] = {"type":COlocationtype, "pdotype":SlavePDOType[direction],
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   311
                                           "nodeid": nodeid, "index": index,"subindex": subindex,
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   312
                                           "bit": numbit, "size": typeinfos["size"], "sizelocation": sizelocation}
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   313
                else:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   314
                    raise ValueError, "Not PDO mappable variable : '%s' (ID:%d,Idx:%x,sIdx:%x))" % (name,nodeid,index,subindex)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   315
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   316
        # Create DictCobID with variables already mapped and add them in DictValidLocations
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   317
        for name, locationinfos in DictLocations.items():
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   318
            node = self.NodeList.SlaveNodes[locationinfos["nodeid"]]["Node"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   319
            result = SearchNodePDOMapping(locationinfos, node)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   320
            if result != None:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   321
                index, subindex = result
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   322
                cobid = nodelist.GetSlaveNodeEntry(locationinfos["nodeid"], index - 0x200, 1)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   323
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   324
                transmittype = nodelist.GetSlaveNodeEntry(locationinfos["nodeid"], index - 0x200, 2)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   325
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   326
                if transmittype != sync_TPDOs:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   327
                    if sync_TPDOs : # Change TransmitType to ASYCHRONE
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   328
                        node = nodelist.SlaveNodes[nodeid]["Node"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   329
                        nodeDCF = masternode.GetEntry(0x1F22, nodeid)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   330
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   331
                        if nodeDCF != None and nodeDCF != '':
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   332
                            tmpnbparams = [i for i in nodeDCF[:4]]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   333
                            tmpnbparams.reverse()
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   334
                            nbparams = int(''.join(["%2.2x"%ord(i) for i in tmpnbparams]), 16)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   335
                            dataparams = nodeDCF[4:]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   336
                        else:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   337
                            nbparams = 0
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   338
                            dataparams = ""
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   339
                    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   340
                    else: # Change TransmitType to SYNCHRONE  
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   341
                        pass
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   342
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   343
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   344
                if cobid not in DictCobID.keys():
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   345
                    mapping = [None]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   346
                    values = node.GetEntry(index)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   347
                    for value in values[1:]:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   348
                        mapping.append(value % 0x100)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   349
                    DictCobID[cobid] = {"type" : InvertPDOType[locationinfos["pdotype"]], "mapping" : mapping}
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   350
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   351
                DictCobID[cobid]["mapping"][subindex] = (locationinfos["type"], name)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   352
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   353
            else:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   354
                if locationinfos["nodeid"] not in DictLocationsNotMapped.keys():
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   355
                    DictLocationsNotMapped[locationinfos["nodeid"]] = {TPDO : [], RPDO : []}
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   356
                DictLocationsNotMapped[locationinfos["nodeid"]][locationinfos["pdotype"]].append((name, locationinfos))
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   357
    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   358
        #-------------------------------------------------------------------------------
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   359
        #                         Build concise DCF for the others locations
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   360
        #-------------------------------------------------------------------------------
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   361
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   362
        for nodeid, locations in DictLocationsNotMapped.items():
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   363
            # Get current concise DCF
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   364
            node = nodelist.SlaveNodes[nodeid]["Node"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   365
            nodeDCF = masternode.GetEntry(0x1F22, nodeid)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   366
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   367
            if nodeDCF != None and nodeDCF != '':
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   368
                tmpnbparams = [i for i in nodeDCF[:4]]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   369
                tmpnbparams.reverse()
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   370
                nbparams = int(''.join(["%2.2x"%ord(i) for i in tmpnbparams]), 16)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   371
                dataparams = nodeDCF[4:]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   372
            else:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   373
                nbparams = 0
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   374
                dataparams = ""
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   375
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   376
            for pdotype in (TPDO, RPDO):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   377
                pdosize = 0
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   378
                pdomapping = []
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   379
                for name, loc_infos in locations[pdotype]:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   380
                    pdosize += loc_infos["size"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   381
                    # If pdo's size > 64 bits
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   382
                    if pdosize > 64:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   383
                        result = GetNewCobID(nodeid, pdotype)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   384
                        if result:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   385
                            SlavesPdoNumber[nodeid][pdotype] += 1
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   386
                            new_cobid, new_idx = result
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   387
                            data, nbaddedparams = GenerateMappingDCF(new_cobid, new_idx, pdomapping, False)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   388
                            dataparams += data
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   389
                            nbparams += nbaddedparams
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   390
                            DictCobID[new_cobid] = {"type" : InvertPDOType[pdotype], "mapping" : GenerateMasterMapping(pdomapping)}
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   391
                        pdosize = loc_infos["size"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   392
                        pdomapping = [(name, loc_infos)]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   393
                    else:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   394
                        pdomapping.append((name, loc_infos))
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   395
                if len(pdomapping) > 0:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   396
                    result = GetNewCobID(nodeid, pdotype)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   397
                    if result:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   398
                        SlavesPdoNumber[nodeid][pdotype] += 1
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   399
                        new_cobid, new_idx = result
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   400
                        data, nbaddedparams = GenerateMappingDCF(new_cobid, new_idx, pdomapping, False)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   401
                        dataparams += data
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   402
                        nbparams += nbaddedparams
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   403
                        DictCobID[new_cobid] = {"type" : InvertPDOType[pdotype], "mapping" : GenerateMasterMapping(pdomapping)}
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   404
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   405
            dcf = LE_to_BE(nbparams, 0x04) + dataparams
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   406
            masternode.SetEntry(0x1F22, nodeid, dcf)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   407
    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   408
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   409
        #-------------------------------------------------------------------------------
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   410
        #                         Master Node Configuration
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   411
        #-------------------------------------------------------------------------------
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   412
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   413
    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   414
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   415
        # Configure Master's PDO parameters entries and set cobid, transmit type
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   416
        for cobid, pdo_infos in DictCobID.items():
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   417
            current_idx = CurrentPDOParamsIdx[pdo_infos["type"]]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   418
            addinglist = [current_idx, current_idx + 0x200]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   419
            manager.ManageEntriesOfCurrent(addinglist, [], masternode)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   420
            masternode.SetEntry(current_idx, 0x01, cobid)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   421
            masternode.SetEntry(current_idx, 0x02, DefaultTransmitTypeMaster)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   422
            if len(pdo_infos["mapping"]) > 2:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   423
                manager.AddSubentriesToCurrent(current_idx + 0x200, len(pdo_infos["mapping"]) - 2, masternode)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   424
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   425
            # Create Master's PDO mapping
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   426
            for subindex, variable in enumerate(pdo_infos["mapping"]):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   427
                if subindex == 0:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   428
                    continue
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   429
                new_index = False
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   430
                
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   431
                if type(variable) != IntType:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   432
                    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   433
                    typeidx, varname = variable
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   434
                    indexname = \
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   435
                        DictNameVariable[DictLocations[variable[1]]["pdotype"]][0] + \
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   436
                        DictLocations[variable[1]]["sizelocation"] + \
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   437
                        '_'.join(map(str,current_location)) + \
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   438
                        "_" + \
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   439
                        str(DictLocations[variable[1]]["nodeid"])
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   440
                    mapvariableidx = DictNameVariable[DictLocations[variable[1]]["pdotype"]][1] +  DictNameVariable[DictLocations[variable[1]]["sizelocation"]] * DictNameVariable["increment"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   441
    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   442
                    #indexname = DictNameVariable[DictLocations[variable[1]]["pdotype"]][0] + DictLocations[variable[1]]["sizelocation"] + str(DictLocations[variable[1]]["prefix"]) + "_" + str(DictLocations[variable[1]]["nodeid"])
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   443
                    #mapvariableidx = DictNameVariable[DictLocations[variable[1]]["pdotype"]][1] +  DictNameVariable[DictLocations[variable[1]]["sizelocation"]] * DictNameVariable["increment"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   444
                    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   445
                    if not masternode.IsEntry(mapvariableidx):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   446
                        manager.AddMapVariableToCurrent(mapvariableidx, indexname, 3, 1, masternode)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   447
                        new_index = True
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   448
                        nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   449
                    else:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   450
                        nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   451
                        mapvariableidxbase = mapvariableidx 
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   452
                        while mapvariableidx < (mapvariableidxbase + 0x1FF) and nbsubentries == 0xFF:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   453
                            mapvariableidx += 0x800
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   454
                            if not manager.IsCurrentEntry(mapvariableidx):
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   455
                                manager.AddMapVariableToCurrent(mapvariableidx, indexname, 3, 1, masternode)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   456
                                new_index = True
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   457
                            nbsubentries = masternode.GetEntry(mapvariableidx, 0x00)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   458
                    
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   459
                    if mapvariableidx < 0x6000:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   460
                        if DictLocations[variable[1]]["bit"] != None:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   461
                            subindexname = str(DictLocations[variable[1]]["index"]) + "_" + str(DictLocations[variable[1]]["subindex"]) + "_" + str(DictLocations[variable[1]]["bit"])
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   462
                        else:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   463
                            subindexname = str(DictLocations[variable[1]]["index"]) + "_" + str(DictLocations[variable[1]]["subindex"])
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   464
                        if not new_index:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   465
                            manager.AddSubentriesToCurrent(mapvariableidx, 1, masternode)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   466
                            nbsubentries += 1
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   467
                        masternode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"name" : subindexname})
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   468
                        masternode.SetMappingEntry(mapvariableidx, nbsubentries, values = {"type" : typeidx})
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   469
                        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   470
                        # Map Variable
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   471
                        typeinfos = manager.GetEntryInfos(typeidx)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   472
                        if typeinfos != None:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   473
                            value = (mapvariableidx << 16) + ((nbsubentries) << 8) + typeinfos["size"]
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   474
                            masternode.SetEntry(current_idx + 0x200, subindex, value)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   475
                else:
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   476
                    masternode.SetEntry(current_idx + 0x200, subindex, TrashVariableValue[variable])
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   477
            
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   478
            CurrentPDOParamsIdx[pdo_infos["type"]] += 1
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   479
        
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   480
26
7bc11b005c8b added sync option
etisserant
parents: 24
diff changeset
   481
def GenerateConciseDCF(locations, current_location, nodelist, sync_TPDOs):
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   482
    """
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   483
    Fills a CanFestival network editor model, with DCF with requested PDO mappings.
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   484
    @param locations: List of complete variables locations \
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   485
        [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   486
        "NAME" : name of the variable (generally "__IW0_1_2" style)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   487
        "DIR" : direction "Q","I" or "M"
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   488
        "SIZE" : size "X", "B", "W", "D", "L"
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   489
        "LOC" : tuple of interger for IEC location (0,1,2,...)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   490
        }, ...]
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   491
    @param nodelist: CanFestival network editor model
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   492
    @return: a modified copy of the given CanFestival network editor model
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   493
    """
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 11
diff changeset
   494
    
27
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   495
    dcfgenerator = ConciseDCFGenerator(nodelist)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   496
    dcfgenerator.GenerateDCF(locations, current_location, sync_TPDOs)
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   497
    return dcfgenerator.GetMasterNode()
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   498
1db681d34579 CONFIG_UTILS (sync)
greg
parents: 26
diff changeset
   499
if __name__ == "__main__": 
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   500
    from nodemanager import *
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   501
    from nodelist import *
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   502
    import sys
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   503
    
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   504
    manager = NodeManager(sys.path[0])
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   505
    nodelist = NodeList(manager)
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   506
    result = nodelist.LoadProject("/home/deobox/Desktop/TestMapping")
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   507
   
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   508
##    if result != None:
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   509
##        print result
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   510
##    else:
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   511
##        print "MasterNode :"
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   512
##        manager.CurrentNode.Print()
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   513
##        for nodeid, node in nodelist.SlaveNodes.items():
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   514
##            print "SlaveNode name=%s id=0x%2.2X :"%(node["Name"], nodeid)
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   515
##            node["Node"].Print()
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   516
            
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   517
    #filepath = "/home/deobox/beremiz/test_nodelist/listlocations.txt"
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   518
    filepath = "/home/deobox/Desktop/TestMapping/listlocations.txt"
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   519
    
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   520
    file = open(filepath,'r')
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   521
    locations = [location.split(' ') for location in [line.strip() for line in file.readlines() if len(line) > 0]] 
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   522
    file.close()
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   523
    GenerateConciseDCF(locations, 32, nodelist)
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   524
    print "MasterNode :"
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   525
    manager.CurrentNode.Print()
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   526
    #masternode.Print()