etisserant@0: #!/usr/bin/env python etisserant@0: # -*- coding: utf-8 -*- etisserant@0: etisserant@0: #This file is part of CanFestival, a library implementing CanOpen Stack. etisserant@0: # etisserant@0: #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD etisserant@0: # etisserant@0: #See COPYING file for copyrights details. etisserant@0: # etisserant@0: #This library is free software; you can redistribute it and/or etisserant@0: #modify it under the terms of the GNU Lesser General Public etisserant@0: #License as published by the Free Software Foundation; either etisserant@0: #version 2.1 of the License, or (at your option) any later version. etisserant@0: # etisserant@0: #This library is distributed in the hope that it will be useful, etisserant@0: #but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@0: #Lesser General Public License for more details. etisserant@0: # etisserant@0: #You should have received a copy of the GNU Lesser General Public etisserant@0: #License along with this library; if not, write to the Free Software etisserant@0: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: etisserant@0: from gnosis.xml.pickle import * etisserant@0: from gnosis.xml.pickle.util import setParanoia etisserant@0: setParanoia(0) etisserant@0: etisserant@0: from node import * lbessard@182: import eds_utils, gen_cfile etisserant@0: etisserant@0: from types import * etisserant@0: import os, re etisserant@0: etisserant@0: UndoBufferLength = 20 etisserant@0: etisserant@0: type_model = re.compile('([\_A-Z]*)([0-9]*)') etisserant@0: range_model = re.compile('([\_A-Z]*)([0-9]*)\[([\-0-9]*)-([\-0-9]*)\]') lbessard@205: lbessard@205: # ID for the file viewed lbessard@205: CurrentID = 0 lbessard@205: lbessard@205: # Returns a new id lbessard@205: def GetNewId(): lbessard@205: global CurrentID lbessard@205: CurrentID += 1 lbessard@205: return CurrentID etisserant@0: etisserant@0: """ etisserant@0: Class implementing a buffer of changes made on the current editing Object Dictionary etisserant@0: """ etisserant@0: etisserant@0: class UndoBuffer: etisserant@0: etisserant@0: """ etisserant@0: Constructor initialising buffer etisserant@0: """ etisserant@0: def __init__(self, currentstate, issaved = False): etisserant@0: self.Buffer = [] etisserant@0: self.CurrentIndex = -1 etisserant@0: self.MinIndex = -1 etisserant@0: self.MaxIndex = -1 etisserant@0: # if current state is defined etisserant@0: if currentstate: etisserant@0: self.CurrentIndex = 0 etisserant@0: self.MinIndex = 0 etisserant@0: self.MaxIndex = 0 etisserant@0: # Initialising buffer with currentstate at the first place etisserant@0: for i in xrange(UndoBufferLength): etisserant@0: if i == 0: etisserant@0: self.Buffer.append(currentstate) etisserant@0: else: etisserant@0: self.Buffer.append(None) etisserant@0: # Initialising index of state saved etisserant@0: if issaved: etisserant@0: self.LastSave = 0 etisserant@0: else: etisserant@0: self.LastSave = -1 etisserant@0: etisserant@0: """ etisserant@0: Add a new state in buffer etisserant@0: """ etisserant@0: def Buffering(self, currentstate): etisserant@0: self.CurrentIndex = (self.CurrentIndex + 1) % UndoBufferLength etisserant@0: self.Buffer[self.CurrentIndex] = currentstate etisserant@0: # Actualising buffer limits etisserant@0: self.MaxIndex = self.CurrentIndex etisserant@0: if self.MinIndex == self.CurrentIndex: etisserant@0: # If the removed state was the state saved, there is no state saved in the buffer etisserant@0: if self.LastSave == self.MinIndex: etisserant@0: self.LastSave = -1 etisserant@0: self.MinIndex = (self.MinIndex + 1) % UndoBufferLength etisserant@0: self.MinIndex = max(self.MinIndex, 0) etisserant@0: etisserant@0: """ etisserant@0: Return current state of buffer etisserant@0: """ etisserant@0: def Current(self): etisserant@0: return self.Buffer[self.CurrentIndex] etisserant@0: etisserant@0: """ etisserant@0: Change current state to previous in buffer and return new current state etisserant@0: """ etisserant@0: def Previous(self): etisserant@0: if self.CurrentIndex != self.MinIndex: etisserant@0: self.CurrentIndex = (self.CurrentIndex - 1) % UndoBufferLength etisserant@0: return self.Buffer[self.CurrentIndex] etisserant@0: return None etisserant@0: etisserant@0: """ etisserant@0: Change current state to next in buffer and return new current state etisserant@0: """ etisserant@0: def Next(self): etisserant@0: if self.CurrentIndex != self.MaxIndex: etisserant@0: self.CurrentIndex = (self.CurrentIndex + 1) % UndoBufferLength etisserant@0: return self.Buffer[self.CurrentIndex] etisserant@0: return None etisserant@0: etisserant@0: """ etisserant@0: Return True if current state is the first in buffer etisserant@0: """ etisserant@0: def IsFirst(self): etisserant@0: return self.CurrentIndex == self.MinIndex etisserant@0: etisserant@0: """ etisserant@0: Return True if current state is the last in buffer etisserant@0: """ etisserant@0: def IsLast(self): etisserant@0: return self.CurrentIndex == self.MaxIndex etisserant@0: etisserant@0: """ etisserant@0: Note that current state is saved etisserant@0: """ etisserant@0: def CurrentSaved(self): etisserant@0: self.LastSave = self.CurrentIndex etisserant@0: etisserant@0: """ etisserant@0: Return True if current state is saved etisserant@0: """ etisserant@0: def IsCurrentSaved(self): etisserant@0: return self.LastSave == self.CurrentIndex etisserant@0: etisserant@0: etisserant@0: etisserant@0: """ etisserant@0: Class which control the operations made on the node and answer to view requests etisserant@0: """ etisserant@0: etisserant@0: class NodeManager: etisserant@0: etisserant@0: """ etisserant@0: Constructor etisserant@0: """ lbessard@258: def __init__(self): etisserant@0: self.LastNewIndex = 0 lbessard@205: self.FilePaths = {} lbessard@205: self.FileNames = {} lbessard@205: self.NodeIndex = None etisserant@0: self.CurrentNode = None lbessard@205: self.UndoBuffers = {} etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Type and Map Variable Lists etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Return the list of types defined for the current node etisserant@0: """ etisserant@0: def GetCurrentTypeList(self): lbessard@205: if self.CurrentNode: lbessard@205: return self.CurrentNode.GetTypeList() lbessard@205: else: lbessard@205: return "" etisserant@0: etisserant@0: """ etisserant@0: Return the list of variables that can be mapped for the current node etisserant@0: """ etisserant@0: def GetCurrentMapList(self): lbessard@205: if self.CurrentNode: lbessard@205: return self.CurrentNode.GetMapList() lbessard@205: else: lbessard@205: return "" etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Create Load and Save Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Create a new node and add a new buffer for storing it etisserant@0: """ lbessard@182: def CreateNewNode(self, name, id, type, description, profile, filepath, NMT, options): etisserant@0: # Create a new node etisserant@0: node = Node() etisserant@0: # Try to load profile given etisserant@0: result = self.LoadProfile(profile, filepath, node) lbessard@182: if not result: etisserant@0: # if success, initialising node etisserant@0: self.CurrentNode = node etisserant@0: self.CurrentNode.SetNodeName(name) etisserant@0: self.CurrentNode.SetNodeID(id) etisserant@0: self.CurrentNode.SetNodeType(type) lbessard@182: self.CurrentNode.SetNodeDescription(description) etisserant@0: AddIndexList = self.GetMandatoryIndexes() etisserant@492: AddSubIndexList = [] etisserant@0: if NMT == "NodeGuarding": etisserant@0: AddIndexList.extend([0x100C, 0x100D]) etisserant@0: elif NMT == "Heartbeat": etisserant@0: AddIndexList.append(0x1017) etisserant@0: for option in options: etisserant@0: if option == "DS302": lbessard@258: DS302Path = os.path.join(os.path.split(__file__)[0], "config/DS-302.prf") etisserant@0: # Charging DS-302 profile if choosen by user lbessard@182: if os.path.isfile(DS302Path): etisserant@0: try: lbessard@182: execfile(DS302Path) lbessard@182: self.CurrentNode.SetDS302Profile(Mapping) lbessard@182: self.CurrentNode.ExtendSpecificMenu(AddMenuEntries) etisserant@0: except: laurent@580: return _("Problem with DS-302! Syntax Error.") etisserant@0: else: laurent@580: return _("Couldn't find DS-302 in 'config' folder!") etisserant@0: elif option == "GenSYNC": etisserant@0: AddIndexList.extend([0x1005, 0x1006]) etisserant@0: elif option == "Emergency": etisserant@0: AddIndexList.append(0x1014) etisserant@0: elif option == "SaveConfig": etisserant@0: AddIndexList.extend([0x1010, 0x1011, 0x1020]) etisserant@0: elif option == "StoreEDS": etisserant@0: AddIndexList.extend([0x1021, 0x1022]) etisserant@487: if type == "slave": etisserant@487: # add default SDO server etisserant@492: AddIndexList.append(0x1200) etisserant@492: # add default 4 receive and 4 transmit PDO etisserant@492: for comm, mapping in [(0x1400, 0x1600),(0x1800, 0x1A00)]: etisserant@492: firstparamindex = self.GetLineFromIndex(comm) etisserant@492: firstmappingindex = self.GetLineFromIndex(mapping) etisserant@492: AddIndexList.extend(range(firstparamindex, firstparamindex + 4)) etisserant@492: for idx in range(firstmappingindex, firstmappingindex + 4): etisserant@492: AddIndexList.append(idx) etisserant@492: AddSubIndexList.append((idx, 8)) etisserant@0: # Add a new buffer lbessard@242: index = self.AddNodeBuffer(self.CurrentNode.Copy(), False) etisserant@0: self.SetCurrentFilePath("") etisserant@0: # Add Mandatory indexes etisserant@0: self.ManageEntriesOfCurrent(AddIndexList, []) etisserant@492: for idx, num in AddSubIndexList: etisserant@492: self.AddSubentriesToCurrent(idx, num) lbessard@205: return index etisserant@0: else: etisserant@0: return result etisserant@0: etisserant@0: """ etisserant@0: Load a profile in node etisserant@0: """ etisserant@0: def LoadProfile(self, profile, filepath, node): etisserant@0: if profile != "None": etisserant@0: # Try to charge the profile given etisserant@0: try: etisserant@0: execfile(filepath) etisserant@0: node.SetProfileName(profile) etisserant@0: node.SetProfile(Mapping) etisserant@0: node.SetSpecificMenu(AddMenuEntries) lbessard@182: return None etisserant@0: except: laurent@580: return _("Syntax Error\nBad OD Profile file!") etisserant@0: else: etisserant@0: # Default profile etisserant@0: node.SetProfileName("None") etisserant@0: node.SetProfile({}) etisserant@0: node.SetSpecificMenu([]) lbessard@182: return None etisserant@0: etisserant@0: """ etisserant@0: Open a file and store it in a new buffer etisserant@0: """ etisserant@0: def OpenFileInCurrent(self, filepath): lbessard@268: try: lbessard@268: # Open and load file lbessard@268: file = open(filepath, "r") lbessard@268: node = load(file) lbessard@268: file.close() lbessard@268: self.CurrentNode = node lbessard@299: self.CurrentNode.SetNodeID(0) lbessard@268: # Add a new buffer and defining current state lbessard@268: index = self.AddNodeBuffer(self.CurrentNode.Copy(), True) lbessard@268: self.SetCurrentFilePath(filepath) lbessard@268: return index lbessard@268: except: laurent@580: return _("Unable to load file \"%s\"!")%filepath etisserant@0: etisserant@0: """ etisserant@0: Save current node in a file etisserant@0: """ etisserant@0: def SaveCurrentInFile(self, filepath = None): etisserant@0: # if no filepath given, verify if current node has a filepath defined etisserant@0: if not filepath: etisserant@0: filepath = self.GetCurrentFilePath() etisserant@0: if filepath == "": etisserant@0: return False etisserant@0: # Save node in file etisserant@0: file = open(filepath, "w") etisserant@0: dump(self.CurrentNode, file) etisserant@0: file.close() etisserant@0: self.SetCurrentFilePath(filepath) etisserant@0: # Update saved state in buffer etisserant@0: self.UndoBuffers[self.NodeIndex].CurrentSaved() etisserant@0: return True etisserant@0: etisserant@0: """ etisserant@0: Close current state etisserant@0: """ etisserant@0: def CloseCurrent(self, ignore = False): etisserant@0: # Verify if it's not forced that the current node is saved before closing it lbessard@490: if self.NodeIndex in self.UndoBuffers and (self.UndoBuffers[self.NodeIndex].IsCurrentSaved() or ignore): etisserant@0: self.RemoveNodeBuffer(self.NodeIndex) lbessard@299: if len(self.UndoBuffers) > 0: lbessard@299: previousindexes = [idx for idx in self.UndoBuffers.keys() if idx < self.NodeIndex] lbessard@299: nextindexes = [idx for idx in self.UndoBuffers.keys() if idx > self.NodeIndex] lbessard@299: if len(previousindexes) > 0: lbessard@299: previousindexes.sort() lbessard@299: self.NodeIndex = previousindexes[-1] lbessard@299: elif len(nextindexes) > 0: lbessard@299: nextindexes.sort() lbessard@299: self.NodeIndex = nextindexes[0] lbessard@299: else: lbessard@299: self.NodeIndex = None lbessard@299: else: lbessard@299: self.NodeIndex = None etisserant@0: return True etisserant@0: return False etisserant@0: etisserant@0: """ lbessard@182: Import an eds file and store it in a new buffer if no node edited lbessard@182: """ lbessard@182: def ImportCurrentFromEDSFile(self, filepath): etisserant@0: # Generate node from definition in a xml file lbessard@258: result = eds_utils.GenerateNode(filepath) lbessard@182: if isinstance(result, Node): lbessard@182: self.CurrentNode = result lbessard@242: index = self.AddNodeBuffer(self.CurrentNode.Copy(), False) lbessard@223: self.SetCurrentFilePath("") lbessard@205: return index lbessard@182: else: lbessard@182: return result lbessard@182: lbessard@182: """ lbessard@182: Export to an eds file and store it in a new buffer if no node edited lbessard@182: """ lbessard@182: def ExportCurrentToEDSFile(self, filepath): lbessard@490: return eds_utils.GenerateEDSFile(filepath, self.CurrentNode) etisserant@0: etisserant@0: """ etisserant@0: Build the C definition of Object Dictionary for current node etisserant@0: """ lbessard@182: def ExportCurrentToCFile(self, filepath): lbessard@245: if self.CurrentNode: lbessard@245: return gen_cfile.GenerateFile(filepath, self.CurrentNode) etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Add Entries to Current Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Add the specified number of subentry for the given entry. Verify that total etisserant@0: number of subentry (except 0) doesn't exceed nbmax defined etisserant@0: """ greg@244: def AddSubentriesToCurrent(self, index, number, node = None): lbessard@254: disable_buffer = node != None greg@244: if node == None: lbessard@254: node = self.CurrentNode etisserant@0: # Informations about entry greg@244: length = node.GetEntry(index, 0) greg@244: infos = node.GetEntryInfos(index) greg@244: subentry_infos = node.GetSubentryInfos(index, 1) etisserant@0: # Get default value for subindex etisserant@0: if "default" in subentry_infos: etisserant@0: default = subentry_infos["default"] etisserant@0: else: etisserant@0: default = self.GetTypeDefaultValue(subentry_infos["type"]) etisserant@0: # First case entry is record greg@244: if infos["struct"] & OD_IdenticalSubindexes: etisserant@0: for i in xrange(1, min(number,subentry_infos["nbmax"]-length) + 1): greg@244: node.AddEntry(index, length + i, default) greg@244: if not disable_buffer: lbessard@245: self.BufferCurrentNode() greg@244: return None etisserant@0: # Second case entry is array, only possible for manufacturer specific etisserant@0: elif infos["struct"] & OD_MultipleSubindexes and 0x2000 <= index <= 0x5FFF: etisserant@0: values = {"name" : "Undefined", "type" : 5, "access" : "rw", "pdo" : True} etisserant@0: for i in xrange(1, min(number,0xFE-length) + 1): greg@244: node.AddMappingEntry(index, length + i, values = values.copy()) greg@244: node.AddEntry(index, length + i, 0) greg@244: if not disable_buffer: lbessard@245: self.BufferCurrentNode() greg@244: return None greg@244: etisserant@0: etisserant@0: """ etisserant@0: Remove the specified number of subentry for the given entry. Verify that total etisserant@0: number of subentry (except 0) isn't less than 1 etisserant@0: """ etisserant@0: def RemoveSubentriesFromCurrent(self, index, number): etisserant@0: # Informations about entry etisserant@0: infos = self.GetEntryInfos(index) etisserant@0: length = self.CurrentNode.GetEntry(index, 0) lbessard@299: if "nbmin" in infos: lbessard@299: nbmin = infos["nbmin"] lbessard@299: else: lbessard@299: nbmin = 1 etisserant@0: # Entry is a record, or is an array of manufacturer specific etisserant@0: if infos["struct"] & OD_IdenticalSubindexes or 0x2000 <= index <= 0x5FFF and infos["struct"] & OD_IdenticalSubindexes: lbessard@299: for i in xrange(min(number, length - nbmin)): etisserant@0: self.RemoveCurrentVariable(index, length - i) etisserant@0: self.BufferCurrentNode() etisserant@0: etisserant@0: """ etisserant@0: Add a SDO Server to current node etisserant@0: """ etisserant@0: def AddSDOServerToCurrent(self): etisserant@0: # An SDO Server is already defined at index 0x1200 etisserant@0: if self.CurrentNode.IsEntry(0x1200): etisserant@0: indexlist = [self.GetLineFromIndex(0x1201)] etisserant@0: if None not in indexlist: etisserant@0: self.ManageEntriesOfCurrent(indexlist, []) etisserant@0: # Add an SDO Server at index 0x1200 etisserant@0: else: etisserant@0: self.ManageEntriesOfCurrent([0x1200], []) etisserant@0: etisserant@0: """ etisserant@0: Add a SDO Server to current node etisserant@0: """ etisserant@0: def AddSDOClientToCurrent(self): etisserant@0: indexlist = [self.GetLineFromIndex(0x1280)] etisserant@0: if None not in indexlist: etisserant@0: self.ManageEntriesOfCurrent(indexlist, []) etisserant@0: etisserant@0: """ etisserant@0: Add a Transmit PDO to current node etisserant@0: """ etisserant@0: def AddPDOTransmitToCurrent(self): etisserant@0: indexlist = [self.GetLineFromIndex(0x1800),self.GetLineFromIndex(0x1A00)] etisserant@0: if None not in indexlist: etisserant@0: self.ManageEntriesOfCurrent(indexlist, []) etisserant@0: etisserant@0: """ etisserant@0: Add a Receive PDO to current node etisserant@0: """ etisserant@0: def AddPDOReceiveToCurrent(self): etisserant@0: indexlist = [self.GetLineFromIndex(0x1400),self.GetLineFromIndex(0x1600)] etisserant@0: if None not in indexlist: etisserant@0: self.ManageEntriesOfCurrent(indexlist, []) etisserant@0: etisserant@0: """ etisserant@0: Add a list of entries defined in profile for menu item selected to current node etisserant@0: """ etisserant@0: def AddSpecificEntryToCurrent(self, menuitem): etisserant@0: indexlist = [] etisserant@0: for menu, indexes in self.CurrentNode.GetSpecificMenu(): etisserant@0: if menuitem == menu: etisserant@0: for index in indexes: etisserant@0: indexlist.append(self.GetLineFromIndex(index)) etisserant@0: if None not in indexlist: etisserant@0: self.ManageEntriesOfCurrent(indexlist, []) etisserant@0: etisserant@0: """ etisserant@0: Search the first index available for a pluri entry from base_index etisserant@0: """ etisserant@0: def GetLineFromIndex(self, base_index): etisserant@0: found = False etisserant@0: index = base_index etisserant@0: infos = self.GetEntryInfos(base_index) etisserant@0: while index < base_index + infos["incr"]*infos["nbmax"] and not found: etisserant@0: if not self.CurrentNode.IsEntry(index): etisserant@0: found = True etisserant@0: else: etisserant@0: index += infos["incr"] etisserant@0: if found: etisserant@0: return index etisserant@0: return None etisserant@0: etisserant@0: """ etisserant@0: Add entries specified in addinglist and remove entries specified in removinglist etisserant@0: """ greg@244: def ManageEntriesOfCurrent(self, addinglist, removinglist, node = None): lbessard@254: disable_buffer = node != None greg@244: if node == None: greg@244: node = self.CurrentNode etisserant@0: # Add all the entries in addinglist etisserant@0: for index in addinglist: etisserant@0: infos = self.GetEntryInfos(index) etisserant@0: if infos["struct"] & OD_MultipleSubindexes: etisserant@0: # First case entry is a record etisserant@0: if infos["struct"] & OD_IdenticalSubindexes: etisserant@0: subentry_infos = self.GetSubentryInfos(index, 1) etisserant@0: if "default" in subentry_infos: etisserant@0: default = subentry_infos["default"] etisserant@0: else: etisserant@0: default = self.GetTypeDefaultValue(subentry_infos["type"]) lbessard@299: node.AddEntry(index, value = []) lbessard@299: if "nbmin" in subentry_infos: lbessard@299: for i in xrange(subentry_infos["nbmin"]): lbessard@299: node.AddEntry(index, i + 1, default) lbessard@299: else: lbessard@299: node.AddEntry(index, 1, default) etisserant@0: # Second case entry is a record etisserant@0: else: etisserant@0: i = 1 etisserant@0: subentry_infos = self.GetSubentryInfos(index, i) etisserant@0: while subentry_infos: etisserant@0: if "default" in subentry_infos: etisserant@0: default = subentry_infos["default"] etisserant@0: else: etisserant@0: default = self.GetTypeDefaultValue(subentry_infos["type"]) greg@244: node.AddEntry(index, i, default) etisserant@0: i += 1 etisserant@0: subentry_infos = self.GetSubentryInfos(index, i) etisserant@0: # Third case entry is a record etisserant@0: else: etisserant@0: subentry_infos = self.GetSubentryInfos(index, 0) etisserant@0: if "default" in subentry_infos: etisserant@0: default = subentry_infos["default"] etisserant@0: else: etisserant@0: default = self.GetTypeDefaultValue(subentry_infos["type"]) greg@244: node.AddEntry(index, 0, default) etisserant@0: # Remove all the entries in removinglist etisserant@0: for index in removinglist: etisserant@0: self.RemoveCurrentVariable(index) greg@244: if not disable_buffer: greg@244: self.BufferCurrentNode() greg@244: return None etisserant@0: lbessard@182: etisserant@0: """ lbessard@299: Reset an subentry from current node to its default value lbessard@299: """ lbessard@299: def SetCurrentEntryToDefault(self, index, subindex, node = None): lbessard@299: disable_buffer = node != None lbessard@299: if node == None: lbessard@299: node = self.CurrentNode lbessard@299: if node.IsEntry(index, subindex): lbessard@299: subentry_infos = self.GetSubentryInfos(index, subindex) lbessard@299: if "default" in subentry_infos: lbessard@299: default = subentry_infos["default"] lbessard@299: else: lbessard@299: default = self.GetTypeDefaultValue(subentry_infos["type"]) lbessard@299: node.SetEntry(index, subindex, default) lbessard@299: if not disable_buffer: lbessard@299: self.BufferCurrentNode() lbessard@299: lbessard@299: """ etisserant@0: Remove an entry from current node. Analize the index to perform the correct etisserant@0: method etisserant@0: """ etisserant@0: def RemoveCurrentVariable(self, index, subIndex = None): etisserant@0: Mappings = self.CurrentNode.GetMappings() etisserant@0: if index < 0x1000 and subIndex == None: etisserant@0: type = self.CurrentNode.GetEntry(index, 1) etisserant@0: for i in Mappings[-1]: etisserant@0: for value in Mappings[-1][i]["values"]: etisserant@0: if value["type"] == index: etisserant@0: value["type"] = type etisserant@0: self.CurrentNode.RemoveMappingEntry(index) etisserant@0: self.CurrentNode.RemoveEntry(index) etisserant@0: elif index == 0x1200 and subIndex == None: etisserant@0: self.CurrentNode.RemoveEntry(0x1200) etisserant@0: elif 0x1201 <= index <= 0x127F and subIndex == None: etisserant@0: self.CurrentNode.RemoveLine(index, 0x127F) etisserant@0: elif 0x1280 <= index <= 0x12FF and subIndex == None: etisserant@0: self.CurrentNode.RemoveLine(index, 0x12FF) etisserant@0: elif 0x1400 <= index <= 0x15FF or 0x1600 <= index <= 0x17FF and subIndex == None: etisserant@0: if 0x1600 <= index <= 0x17FF and subIndex == None: etisserant@0: index -= 0x200 etisserant@0: self.CurrentNode.RemoveLine(index, 0x15FF) etisserant@0: self.CurrentNode.RemoveLine(index + 0x200, 0x17FF) etisserant@0: elif 0x1800 <= index <= 0x19FF or 0x1A00 <= index <= 0x1BFF and subIndex == None: etisserant@0: if 0x1A00 <= index <= 0x1BFF: etisserant@0: index -= 0x200 etisserant@0: self.CurrentNode.RemoveLine(index, 0x19FF) etisserant@0: self.CurrentNode.RemoveLine(index + 0x200, 0x1BFF) etisserant@0: else: etisserant@0: found = False etisserant@0: for menu,list in self.CurrentNode.GetSpecificMenu(): etisserant@0: for i in list: etisserant@0: iinfos = self.GetEntryInfos(i) etisserant@0: indexes = [i + incr * iinfos["incr"] for incr in xrange(iinfos["nbmax"])] etisserant@0: if index in indexes: etisserant@0: found = True etisserant@0: diff = index - i etisserant@0: for j in list: etisserant@0: jinfos = self.GetEntryInfos(j) etisserant@0: self.CurrentNode.RemoveLine(j + diff, j + jinfos["incr"]*jinfos["nbmax"], jinfos["incr"]) etisserant@0: self.CurrentNode.RemoveMapVariable(index, subIndex) etisserant@0: if not found: etisserant@0: infos = self.GetEntryInfos(index) etisserant@0: if not infos["need"]: etisserant@0: self.CurrentNode.RemoveEntry(index, subIndex) etisserant@0: if index in Mappings[-1]: etisserant@0: self.CurrentNode.RemoveMappingEntry(index, subIndex) etisserant@0: greg@244: def AddMapVariableToCurrent(self, index, name, struct, number, node = None): etisserant@0: if 0x2000 <= index <= 0x5FFF: lbessard@254: disable_buffer = node != None greg@244: if node == None: greg@244: node = self.CurrentNode greg@244: if not node.IsEntry(index): greg@244: node.AddMappingEntry(index, name = name, struct = struct) etisserant@0: if struct == var: lbessard@205: values = {"name" : name, "type" : 0x05, "access" : "rw", "pdo" : True} greg@244: node.AddMappingEntry(index, 0, values = values) greg@244: node.AddEntry(index, 0, 0) etisserant@0: else: lbessard@205: values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False} greg@244: node.AddMappingEntry(index, 0, values = values) etisserant@0: if struct == rec: lbessard@205: values = {"name" : name + " %d[(sub)]", "type" : 0x05, "access" : "rw", "pdo" : True, "nbmax" : 0xFE} greg@244: node.AddMappingEntry(index, 1, values = values) etisserant@0: for i in xrange(number): greg@244: node.AddEntry(index, i + 1, 0) etisserant@0: else: etisserant@0: for i in xrange(number): lbessard@205: values = {"name" : "Undefined", "type" : 0x05, "access" : "rw", "pdo" : True} greg@244: node.AddMappingEntry(index, i + 1, values = values) greg@244: node.AddEntry(index, i + 1, 0) greg@244: if not disable_buffer: greg@244: self.BufferCurrentNode() etisserant@0: return None etisserant@0: else: laurent@580: return _("Index 0x%04X already defined!")%index laurent@580: else: laurent@580: return _("Index 0x%04X isn't a valid index for Map Variable!")%index etisserant@0: etisserant@0: def AddUserTypeToCurrent(self, type, min, max, length): etisserant@0: index = 0xA0 etisserant@0: while index < 0x100 and self.CurrentNode.IsEntry(index): etisserant@0: index += 1 etisserant@0: if index < 0x100: etisserant@0: customisabletypes = self.GetCustomisableTypes() etisserant@0: name, valuetype = customisabletypes[type] etisserant@0: size = self.GetEntryInfos(type)["size"] etisserant@0: default = self.GetTypeDefaultValue(type) etisserant@0: if valuetype == 0: etisserant@0: self.CurrentNode.AddMappingEntry(index, name = "%s[%d-%d]"%(name, min, max), struct = 3, size = size, default = default) lbessard@205: self.CurrentNode.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False}) lbessard@205: self.CurrentNode.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x05, "access" : "ro", "pdo" : False}) etisserant@0: self.CurrentNode.AddMappingEntry(index, 2, values = {"name" : "Minimum Value", "type" : type, "access" : "ro", "pdo" : False}) etisserant@0: self.CurrentNode.AddMappingEntry(index, 3, values = {"name" : "Maximum Value", "type" : type, "access" : "ro", "pdo" : False}) etisserant@0: self.CurrentNode.AddEntry(index, 1, type) etisserant@0: self.CurrentNode.AddEntry(index, 2, min) etisserant@0: self.CurrentNode.AddEntry(index, 3, max) etisserant@0: elif valuetype == 1: etisserant@0: self.CurrentNode.AddMappingEntry(index, name = "%s%d"%(name, length), struct = 3, size = length * size, default = default) lbessard@205: self.CurrentNode.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False}) lbessard@205: self.CurrentNode.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x05, "access" : "ro", "pdo" : False}) lbessard@205: self.CurrentNode.AddMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x05, "access" : "ro", "pdo" : False}) etisserant@0: self.CurrentNode.AddEntry(index, 1, type) etisserant@0: self.CurrentNode.AddEntry(index, 2, length) etisserant@0: self.BufferCurrentNode() etisserant@0: return None etisserant@0: else: laurent@580: return _("Too many User Types have already been defined!") etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Modify Entry and Mapping Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def SetCurrentEntryCallbacks(self, index, value): etisserant@0: if self.CurrentNode and self.CurrentNode.IsEntry(index): etisserant@0: entry_infos = self.GetEntryInfos(index) etisserant@0: if "callback" not in entry_infos: etisserant@0: self.CurrentNode.SetParamsEntry(index, None, callback = value) etisserant@0: self.BufferCurrentNode() etisserant@0: greg@244: def SetCurrentEntry(self, index, subIndex, value, name, editor, node = None): lbessard@254: disable_buffer = node != None greg@244: if node == None: lbessard@254: node = self.CurrentNode greg@244: if node and node.IsEntry(index): etisserant@0: if name == "value": lbessard@242: if editor == "map": greg@244: value = node.GetMapValue(value) lbessard@545: if value is not None: greg@244: node.SetEntry(index, subIndex, value) etisserant@0: elif editor == "bool": etisserant@0: value = value == "True" greg@244: node.SetEntry(index, subIndex, value) lbessard@68: elif editor == "time": greg@244: node.SetEntry(index, subIndex, value) lbessard@182: elif editor == "number": lbessard@188: try: greg@244: node.SetEntry(index, subIndex, int(value)) lbessard@188: except: lbessard@188: pass lbessard@453: elif editor == "float": lbessard@453: try: lbessard@453: node.SetEntry(index, subIndex, float(value)) lbessard@453: except: lbessard@453: pass greg@176: elif editor == "domain": greg@176: try: greg@176: if len(value) % 2 != 0: greg@176: value = "0" + value greg@176: value = value.decode('hex_codec') greg@244: node.SetEntry(index, subIndex, value) greg@176: except: greg@176: pass lbessard@327: elif editor == "dcf": lbessard@327: node.SetEntry(index, subIndex, value) etisserant@0: else: etisserant@0: subentry_infos = self.GetSubentryInfos(index, subIndex) lbessard@30: type = subentry_infos["type"] etisserant@0: dic = {} etisserant@0: for typeindex, typevalue in CustomisableTypes: etisserant@0: dic[typeindex] = typevalue lbessard@30: if type not in dic: greg@244: type = node.GetEntry(type)[1] lbessard@30: if dic[type] == 0: etisserant@0: try: lbessard@299: if value.startswith("$NODEID"): lbessard@299: value = "\"%s\""%value lbessard@299: elif value.startswith("0x"): lbessard@233: value = int(value, 16) lbessard@233: else: lbessard@233: value = int(value) greg@244: node.SetEntry(index, subIndex, value) etisserant@0: except: etisserant@0: pass etisserant@0: else: greg@244: node.SetEntry(index, subIndex, value) etisserant@0: elif name in ["comment", "save"]: etisserant@0: if editor == "option": etisserant@0: value = value == "Yes" etisserant@0: if name == "save": greg@244: node.SetParamsEntry(index, subIndex, save = value) etisserant@0: elif name == "comment": greg@244: node.SetParamsEntry(index, subIndex, comment = value) etisserant@0: else: etisserant@0: if editor == "type": lbessard@205: value = self.GetTypeIndex(value) lbessard@63: size = self.GetEntryInfos(value)["size"] greg@244: node.UpdateMapVariable(index, subIndex, size) lbessard@68: elif editor in ["access","raccess"]: etisserant@0: dic = {} etisserant@0: for abbrev,access in AccessType.iteritems(): etisserant@0: dic[access] = abbrev etisserant@0: value = dic[value] greg@244: if editor == "raccess" and not node.IsMappingEntry(index): lbessard@68: entry_infos = self.GetEntryInfos(index) laurent@584: subIndex0_infos = self.GetSubentryInfos(index, 0, False).copy() laurent@584: subIndex1_infos = self.GetSubentryInfos(index, 1, False).copy() greg@244: node.AddMappingEntry(index, name = entry_infos["name"], struct = 7) laurent@584: node.AddMappingEntry(index, 0, values = subIndex0_infos) laurent@584: node.AddMappingEntry(index, 1, values = subIndex1_infos) greg@244: node.SetMappingEntry(index, subIndex, values = {name : value}) greg@244: if not disable_buffer: greg@244: self.BufferCurrentNode() greg@244: return None etisserant@0: etisserant@0: def SetCurrentEntryName(self, index, name): etisserant@0: self.CurrentNode.SetMappingEntry(index, name=name) etisserant@0: self.BufferCurrentNode() etisserant@0: etisserant@0: def SetCurrentUserType(self, index, type, min, max, length): etisserant@0: customisabletypes = self.GetCustomisableTypes() etisserant@0: values, valuetype = self.GetCustomisedTypeValues(index) etisserant@0: name, new_valuetype = customisabletypes[type] etisserant@0: size = self.GetEntryInfos(type)["size"] etisserant@0: default = self.GetTypeDefaultValue(type) etisserant@0: if new_valuetype == 0: etisserant@0: self.CurrentNode.SetMappingEntry(index, name = "%s[%d-%d]"%(name, min, max), struct = 3, size = size, default = default) etisserant@0: if valuetype == 1: etisserant@0: self.CurrentNode.SetMappingEntry(index, 2, values = {"name" : "Minimum Value", "type" : type, "access" : "ro", "pdo" : False}) etisserant@0: self.CurrentNode.AddMappingEntry(index, 3, values = {"name" : "Maximum Value", "type" : type, "access" : "ro", "pdo" : False}) etisserant@0: self.CurrentNode.SetEntry(index, 1, type) etisserant@0: self.CurrentNode.SetEntry(index, 2, min) etisserant@0: if valuetype == 1: etisserant@0: self.CurrentNode.AddEntry(index, 3, max) etisserant@0: else: etisserant@0: self.CurrentNode.SetEntry(index, 3, max) etisserant@0: elif new_valuetype == 1: etisserant@0: self.CurrentNode.SetMappingEntry(index, name = "%s%d"%(name, length), struct = 3, size = size, default = default) etisserant@0: if valuetype == 0: etisserant@0: self.CurrentNode.SetMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x02, "access" : "ro", "pdo" : False}) etisserant@0: self.CurrentNode.RemoveMappingEntry(index, 3) etisserant@0: self.CurrentNode.SetEntry(index, 1, type) etisserant@0: self.CurrentNode.SetEntry(index, 2, length) etisserant@0: if valuetype == 0: etisserant@0: self.CurrentNode.RemoveEntry(index, 3) etisserant@0: self.BufferCurrentNode() etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Current Buffering Management Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def BufferCurrentNode(self): etisserant@0: self.UndoBuffers[self.NodeIndex].Buffering(self.CurrentNode.Copy()) etisserant@0: etisserant@0: def CurrentIsSaved(self): etisserant@0: return self.UndoBuffers[self.NodeIndex].IsCurrentSaved() etisserant@0: etisserant@0: def OneFileHasChanged(self): etisserant@0: result = False lbessard@205: for buffer in self.UndoBuffers.values(): etisserant@0: result |= not buffer.IsCurrentSaved() etisserant@0: return result etisserant@0: etisserant@0: def GetBufferNumber(self): etisserant@0: return len(self.UndoBuffers) etisserant@0: etisserant@485: def GetBufferIndexes(self): etisserant@485: return self.UndoBuffers.keys() etisserant@485: etisserant@0: def LoadCurrentPrevious(self): etisserant@0: self.CurrentNode = self.UndoBuffers[self.NodeIndex].Previous().Copy() etisserant@0: etisserant@0: def LoadCurrentNext(self): etisserant@0: self.CurrentNode = self.UndoBuffers[self.NodeIndex].Next().Copy() etisserant@0: etisserant@0: def AddNodeBuffer(self, currentstate = None, issaved = False): lbessard@205: self.NodeIndex = GetNewId() lbessard@205: self.UndoBuffers[self.NodeIndex] = UndoBuffer(currentstate, issaved) lbessard@205: self.FilePaths[self.NodeIndex] = "" lbessard@205: self.FileNames[self.NodeIndex] = "" lbessard@205: return self.NodeIndex etisserant@0: etisserant@0: def ChangeCurrentNode(self, index): lbessard@205: if index in self.UndoBuffers.keys(): etisserant@0: self.NodeIndex = index etisserant@0: self.CurrentNode = self.UndoBuffers[self.NodeIndex].Current().Copy() etisserant@0: etisserant@0: def RemoveNodeBuffer(self, index): etisserant@0: self.UndoBuffers.pop(index) etisserant@0: self.FilePaths.pop(index) etisserant@0: self.FileNames.pop(index) etisserant@0: etisserant@0: def GetCurrentNodeIndex(self): etisserant@0: return self.NodeIndex etisserant@0: etisserant@0: def GetCurrentFilename(self): etisserant@0: return self.GetFilename(self.NodeIndex) etisserant@0: etisserant@0: def GetAllFilenames(self): lbessard@205: indexes = self.UndoBuffers.keys() lbessard@205: indexes.sort() lbessard@205: return [self.GetFilename(idx) for idx in indexes] etisserant@0: etisserant@0: def GetFilename(self, index): etisserant@0: if self.UndoBuffers[index].IsCurrentSaved(): etisserant@0: return self.FileNames[index] etisserant@0: else: etisserant@0: return "~%s~"%self.FileNames[index] etisserant@0: etisserant@0: def SetCurrentFilePath(self, filepath): etisserant@0: self.FilePaths[self.NodeIndex] = filepath etisserant@0: if filepath == "": etisserant@0: self.LastNewIndex += 1 laurent@580: self.FileNames[self.NodeIndex] = _("Unnamed%d")%self.LastNewIndex etisserant@0: else: etisserant@0: self.FileNames[self.NodeIndex] = os.path.splitext(os.path.basename(filepath))[0] etisserant@0: etisserant@0: def GetCurrentFilePath(self): etisserant@0: if len(self.FilePaths) > 0: etisserant@0: return self.FilePaths[self.NodeIndex] etisserant@0: else: etisserant@0: return "" etisserant@0: etisserant@0: def GetCurrentBufferState(self): etisserant@0: first = self.UndoBuffers[self.NodeIndex].IsFirst() etisserant@0: last = self.UndoBuffers[self.NodeIndex].IsLast() etisserant@0: return not first, not last etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Profiles Management Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def GetCurrentCommunicationLists(self): etisserant@0: list = [] etisserant@0: for index in MappingDictionary.iterkeys(): etisserant@0: if 0x1000 <= index < 0x1200: etisserant@0: list.append(index) etisserant@0: return self.GetProfileLists(MappingDictionary, list) etisserant@0: etisserant@0: def GetCurrentDS302Lists(self): etisserant@0: return self.GetSpecificProfileLists(self.CurrentNode.GetDS302Profile()) etisserant@0: etisserant@0: def GetCurrentProfileLists(self): etisserant@0: return self.GetSpecificProfileLists(self.CurrentNode.GetProfile()) etisserant@0: etisserant@0: def GetSpecificProfileLists(self, mappingdictionary): etisserant@0: validlist = [] etisserant@0: exclusionlist = [] etisserant@0: for name, list in self.CurrentNode.GetSpecificMenu(): etisserant@0: exclusionlist.extend(list) etisserant@0: for index in mappingdictionary.iterkeys(): etisserant@0: if index not in exclusionlist: etisserant@0: validlist.append(index) etisserant@0: return self.GetProfileLists(mappingdictionary, validlist) etisserant@0: etisserant@0: def GetProfileLists(self, mappingdictionary, list): etisserant@0: dictionary = {} etisserant@0: current = [] etisserant@0: for index in list: etisserant@0: dictionary[index] = (mappingdictionary[index]["name"], mappingdictionary[index]["need"]) etisserant@0: if self.CurrentNode.IsEntry(index): etisserant@0: current.append(index) etisserant@0: return dictionary, current etisserant@0: lbessard@39: def GetCurrentNextMapIndex(self): lbessard@39: if self.CurrentNode: lbessard@39: index = 0x2000 lbessard@39: while self.CurrentNode.IsEntry(index) and index < 0x5FFF: lbessard@39: index += 1 lbessard@39: if index < 0x6000: lbessard@39: return index lbessard@39: else: lbessard@39: return None lbessard@39: etisserant@0: def CurrentDS302Defined(self): etisserant@0: if self.CurrentNode: etisserant@0: return len(self.CurrentNode.GetDS302Profile()) > 0 etisserant@0: return False etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Node State and Values Functions etisserant@0: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: def GetCurrentNodeName(self): lbessard@205: if self.CurrentNode: lbessard@205: return self.CurrentNode.GetNodeName() lbessard@205: else: lbessard@205: return "" lbessard@205: greg@244: def GetCurrentNodeCopy(self): greg@244: if self.CurrentNode: greg@244: return self.CurrentNode.Copy() greg@244: else: greg@244: return None greg@244: greg@244: def GetCurrentNodeID(self, node = None): lbessard@205: if self.CurrentNode: lbessard@205: return self.CurrentNode.GetNodeID() lbessard@205: else: lbessard@205: return None etisserant@0: etisserant@0: def GetCurrentNodeInfos(self): etisserant@0: name = self.CurrentNode.GetNodeName() etisserant@0: id = self.CurrentNode.GetNodeID() etisserant@0: type = self.CurrentNode.GetNodeType() lbessard@182: description = self.CurrentNode.GetNodeDescription() lbessard@182: return name, id, type, description lbessard@418: lbessard@182: def SetCurrentNodeInfos(self, name, id, type, description): etisserant@0: self.CurrentNode.SetNodeName(name) etisserant@0: self.CurrentNode.SetNodeID(id) etisserant@0: self.CurrentNode.SetNodeType(type) lbessard@182: self.CurrentNode.SetNodeDescription(description) etisserant@0: self.BufferCurrentNode() etisserant@0: lbessard@418: def GetCurrentNodeDefaultStringSize(self): lbessard@418: if self.CurrentNode: lbessard@418: return self.CurrentNode.GetDefaultStringSize() lbessard@418: else: lbessard@418: return Node.DefaultStringSize lbessard@418: lbessard@418: def SetCurrentNodeDefaultStringSize(self, size): lbessard@418: if self.CurrentNode: lbessard@418: self.CurrentNode.SetDefaultStringSize(size) lbessard@418: else: lbessard@418: Node.DefaultStringSize = size lbessard@418: etisserant@0: def GetCurrentProfileName(self): etisserant@0: if self.CurrentNode: etisserant@0: return self.CurrentNode.GetProfileName() etisserant@0: return "" etisserant@0: etisserant@0: def IsCurrentEntry(self, index): etisserant@0: if self.CurrentNode: etisserant@0: return self.CurrentNode.IsEntry(index) etisserant@0: return False etisserant@0: lbessard@299: def GetCurrentEntry(self, index, subIndex = None, compute = True): lbessard@299: if self.CurrentNode: lbessard@299: return self.CurrentNode.GetEntry(index, subIndex, compute) etisserant@0: return None etisserant@0: etisserant@0: def GetCurrentParamsEntry(self, index, subIndex = None): etisserant@0: if self.CurrentNode: etisserant@0: return self.CurrentNode.GetParamsEntry(index, subIndex) etisserant@0: return None etisserant@0: etisserant@0: def GetCurrentValidIndexes(self, min, max): etisserant@0: validindexes = [] etisserant@0: for index in self.CurrentNode.GetIndexes(): etisserant@0: if min <= index <= max: etisserant@0: validindexes.append((self.GetEntryName(index), index)) etisserant@0: return validindexes etisserant@0: etisserant@0: def GetCurrentValidChoices(self, min, max): etisserant@0: validchoices = [] etisserant@0: exclusionlist = [] etisserant@0: for menu, indexes in self.CurrentNode.GetSpecificMenu(): etisserant@0: exclusionlist.extend(indexes) etisserant@0: good = True etisserant@0: for index in indexes: etisserant@0: good &= min <= index <= max etisserant@0: if good: etisserant@0: validchoices.append((menu, None)) etisserant@0: list = [index for index in MappingDictionary.keys() if index >= 0x1000] etisserant@0: profiles = self.CurrentNode.GetMappings(False) etisserant@0: for profile in profiles: etisserant@0: list.extend(profile.keys()) etisserant@0: list.sort() etisserant@0: for index in list: etisserant@0: if min <= index <= max and not self.CurrentNode.IsEntry(index) and index not in exclusionlist: etisserant@0: validchoices.append((self.GetEntryName(index), index)) etisserant@0: return validchoices etisserant@0: etisserant@0: def HasCurrentEntryCallbacks(self, index): lbessard@245: if self.CurrentNode: etisserant@0: return self.CurrentNode.HasEntryCallbacks(index) etisserant@0: return False etisserant@0: etisserant@0: def GetCurrentEntryValues(self, index): lbessard@205: if self.CurrentNode: lbessard@205: return self.GetNodeEntryValues(self.CurrentNode, index) lbessard@205: lbessard@205: def GetNodeEntryValues(self, node, index): lbessard@205: if node and node.IsEntry(index): lbessard@205: entry_infos = node.GetEntryInfos(index) etisserant@0: data = [] etisserant@0: editors = [] lbessard@299: values = node.GetEntry(index, compute = False) lbessard@205: params = node.GetParamsEntry(index) lbessard@512: if isinstance(values, ListType): etisserant@0: for i, value in enumerate(values): etisserant@0: data.append({"value" : value}) greg@176: data[-1].update(params[i]) etisserant@0: else: etisserant@0: data.append({"value" : values}) etisserant@0: data[-1].update(params) etisserant@0: for i, dic in enumerate(data): lbessard@205: infos = node.GetSubentryInfos(index, i) etisserant@0: dic["subindex"] = "0x%02X"%i etisserant@0: dic["name"] = infos["name"] lbessard@205: dic["type"] = node.GetTypeName(infos["type"]) laurent@582: if dic["type"] is None: laurent@582: dic["type"] = "Unknown" etisserant@0: dic["access"] = AccessType[infos["access"]] etisserant@0: dic["save"] = OptionType[dic["save"]] laurent@582: editor = {"subindex" : None, "name" : None, laurent@582: "type" : None, "value" : None, laurent@582: "access" : None, "save" : "option", laurent@582: "callback" : "option", "comment" : "string"} lbessard@512: if isinstance(values, ListType) and i == 0: lbessard@68: if 0x1600 <= index <= 0x17FF or 0x1A00 <= index <= 0x1C00: lbessard@68: editor["access"] = "raccess" etisserant@0: else: etisserant@0: if infos["user_defined"]: etisserant@0: if entry_infos["struct"] & OD_IdenticalSubindexes: Laurent@762: if i == 1: etisserant@0: editor["type"] = "type" etisserant@0: editor["access"] = "access" etisserant@0: else: etisserant@0: if entry_infos["struct"] & OD_MultipleSubindexes: etisserant@0: editor["name"] = "string" etisserant@0: editor["type"] = "type" etisserant@0: editor["access"] = "access" etisserant@0: if index < 0x260: etisserant@0: if i == 1: lbessard@205: dic["value"] = node.GetTypeName(dic["value"]) etisserant@0: elif 0x1600 <= index <= 0x17FF or 0x1A00 <= index <= 0x1C00: etisserant@0: editor["value"] = "map" lbessard@205: dic["value"] = node.GetMapName(dic["value"]) etisserant@0: else: lbessard@333: if dic["type"].startswith("VISIBLE_STRING") or dic["type"].startswith("OCTET_STRING"): etisserant@0: editor["value"] = "string" greg@176: elif dic["type"] in ["TIME_OF_DAY","TIME_DIFFERENCE"]: lbessard@68: editor["value"] = "time" greg@176: elif dic["type"] == "DOMAIN": lbessard@327: if index == 0x1F22: lbessard@327: editor["value"] = "dcf" lbessard@327: else: lbessard@327: editor["value"] = "domain" greg@176: dic["value"] = dic["value"].encode('hex_codec') etisserant@0: elif dic["type"] == "BOOLEAN": etisserant@0: editor["value"] = "bool" etisserant@0: dic["value"] = BoolType[dic["value"]] etisserant@0: result = type_model.match(dic["type"]) etisserant@0: if result: etisserant@0: values = result.groups() lbessard@182: if values[0] == "UNSIGNED": lbessard@299: try: lbessard@299: format = "0x%0" + str(int(values[1])/4) + "X" lbessard@299: dic["value"] = format%dic["value"] lbessard@299: except: lbessard@299: pass etisserant@0: editor["value"] = "string" lbessard@182: if values[0] == "INTEGER": lbessard@182: editor["value"] = "number" etisserant@0: elif values[0] == "REAL": etisserant@0: editor["value"] = "float" lbessard@333: elif values[0] in ["VISIBLE_STRING", "OCTET_STRING"]: etisserant@0: editor["length"] = values[0] etisserant@0: result = range_model.match(dic["type"]) etisserant@0: if result: etisserant@0: values = result.groups() lbessard@182: if values[0] in ["UNSIGNED", "INTEGER", "REAL"]: etisserant@0: editor["min"] = values[2] etisserant@0: editor["max"] = values[3] etisserant@0: editors.append(editor) etisserant@0: return data, editors etisserant@0: else: etisserant@0: return None lbessard@205: lbessard@327: def AddToDCF(self, node_id, index, subindex, size, value): lbessard@327: if self.CurrentNode.IsEntry(0x1F22, node_id): lbessard@327: dcf_value = self.CurrentNode.GetEntry(0x1F22, node_id) lbessard@338: if dcf_value != "": lbessard@338: nbparams = BE_to_LE(dcf_value[:4]) lbessard@338: else: lbessard@338: nbparams = 0 lbessard@327: new_value = LE_to_BE(nbparams + 1, 4) + dcf_value[4:] lbessard@327: new_value += LE_to_BE(index, 2) + LE_to_BE(subindex, 1) + LE_to_BE(size, 4) + LE_to_BE(value, size) lbessard@327: self.CurrentNode.SetEntry(0x1F22, node_id, new_value) lbessard@327: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Node Informations Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def GetCustomisedTypeValues(self, index): lbessard@205: if self.CurrentNode: lbessard@205: values = self.CurrentNode.GetEntry(index) lbessard@205: customisabletypes = self.GetCustomisableTypes() lbessard@205: return values, customisabletypes[values[1]][1] lbessard@205: else: lbessard@205: return None, None lbessard@205: laurent@584: def GetEntryName(self, index, compute=True): laurent@584: if self.CurrentNode: laurent@584: return self.CurrentNode.GetEntryName(index, compute) laurent@584: else: laurent@584: return FindEntryName(index, MappingDictionary, compute) laurent@584: laurent@584: def GetEntryInfos(self, index, compute=True): laurent@584: if self.CurrentNode: laurent@584: return self.CurrentNode.GetEntryInfos(index, compute) laurent@584: else: laurent@584: return FindEntryInfos(index, MappingDictionary, compute) laurent@584: laurent@584: def GetSubentryInfos(self, index, subindex, compute=True): laurent@584: if self.CurrentNode: laurent@584: return self.CurrentNode.GetSubentryInfos(index, subindex, compute) laurent@584: else: laurent@584: result = FindSubentryInfos(index, subindex, MappingDictionary, compute) lbessard@68: if result: lbessard@68: result["user_defined"] = False lbessard@205: return result lbessard@205: lbessard@205: def GetTypeIndex(self, typename): lbessard@205: if self.CurrentNode: lbessard@205: return self.CurrentNode.GetTypeIndex(typename) lbessard@205: else: lbessard@205: return FindTypeIndex(typename, MappingDictionary) lbessard@205: lbessard@205: def GetTypeName(self, typeindex): lbessard@205: if self.CurrentNode: lbessard@205: return self.CurrentNode.GetTypeName(typeindex) lbessard@205: else: lbessard@205: return FindTypeName(typeindex, MappingDictionary) lbessard@205: lbessard@205: def GetTypeDefaultValue(self, typeindex): lbessard@205: if self.CurrentNode: lbessard@205: return self.CurrentNode.GetTypeDefaultValue(typeindex) lbessard@205: else: lbessard@205: return FindTypeDefaultValue(typeindex, MappingDictionary) lbessard@205: laurent@584: def GetMapVariableList(self, compute=True): laurent@584: if self.CurrentNode: laurent@584: return self.CurrentNode.GetMapVariableList(compute) lbessard@205: else: lbessard@205: return [] lbessard@205: greg@244: def GetMandatoryIndexes(self): lbessard@205: if self.CurrentNode: lbessard@220: return self.CurrentNode.GetMandatoryIndexes() lbessard@205: else: lbessard@205: return FindMandatoryIndexes(MappingDictionary) etisserant@0: etisserant@0: def GetCustomisableTypes(self): etisserant@0: dic = {} etisserant@0: for index, valuetype in CustomisableTypes: etisserant@0: name = self.GetTypeName(index) etisserant@0: dic[index] = [name, valuetype] etisserant@0: return dic etisserant@0: etisserant@0: def GetCurrentSpecificMenu(self): etisserant@0: if self.CurrentNode: etisserant@0: return self.CurrentNode.GetSpecificMenu() etisserant@0: return [] etisserant@0: