⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ramsymbols.py

📁 无线通信的主要编程软件,是无线通信工作人员的必备工具,关天相关教程我会在后续传上.
💻 PY
📖 第 1 页 / 共 2 页
字号:
# "Copyright (c) 2000-2003 The Regents of the University of California.  # All rights reserved.## Permission to use, copy, modify, and distribute this software and its# documentation for any purpose, without fee, and without written agreement# is hereby granted, provided that the above copyright notice, the following# two paragraphs and the author appear in all copies of this software.# # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT# OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY# OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.# # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY# AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS# ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."## @author Kamin Whitehouse #"""\RamSymbols.py -- a tool for poking and peeking ram symbols on motes.To be used in conjunction with tinyos-1.x/contrib/nestfe/nesc/lib/RamSymbols"""import sys, string, time, typesfrom xml.dom import minidomimport pytos.util.nescDecls as nescDeclsimport pytos.util.RoutingMessages as RoutingMessagesimport pytos.Comm as Comm from copy import deepcopyclass RamSymbol( RoutingMessages.RoutingMessage ) :  #this is the variable the determines, on a blocking rpc call, how  #many messages will be queued up.  Should perhaps be bigger for large  #networks, but will generally be the same number for all rpc  #functions that use the same send and receive comm stacks.  msgQueueSize = 10    def __init__(self, xmlDefinition=None, parent=None) :    if xmlDefinition==None :      return    self.pokeResponseMsg = None    self.memAddress = int(xmlDefinition.getAttribute("address"))    length = int(xmlDefinition.getAttribute("length"))    typeDef = xmlDefinition.getElementsByTagName("type")[0]    self.isPointer = typeDef.getAttribute("typeClass") == "pointer"    self.isArray = xmlDefinition.hasAttribute("array")    symbolType = parent.app.types[typeDef.getAttribute("typeName")]    #if symbolType.size > parent.app.enums.MAX_RAM_SYMBOL_SIZE :    if self.isPointer :      symbolType = nescDecls.nescPointer(parent.app, symbolType)    if self.isArray :      if length % symbolType.size == 0 :        numElements = length // symbolType.size      else :        raise Exception("Could not discern ram symbol array length")      symbolType = nescDecls.nescArray(numElements, symbolType)    structArgs = []    if type(symbolType) == nescDecls.nescStruct :      self.isStruct = True      structArgs.append(symbolType)    else :      structArgs.append(xmlDefinition.getAttribute("name"))      structArgs.append( ("value", symbolType) )    #now initialize this command as a TosMsg object (which is really a nescStruct)    RoutingMessages.RoutingMessage.__init__(self, parent, 0, *structArgs)    if self.isStruct :      self.__dict__["name"] = xmlDefinition.getAttribute("name")    if length != self.size :        raise Exception("Ram symbol size incorrect")    self.pokeResponseMsg = nescDecls.TosMsg(self.memAddress, "PokeResponseMsg",                                          ("value", parent.app.types.result_t))     def poke(self, value=None, arrayIndex = None, dereference=False, **nameArgs) :    if not self.parent.app.__dict__.has_key("RamSymbolsM") :      raise Exception("You must include the contrib/hood/tos/lib/RamSymbols/RamSymbolsM module in your nesc application in order to poke or peek at ram symbols")    func = self.parent.app.RamSymbolsM.poke    if arrayIndex != None :      if self.isArray :        if dereference == True :          if self.isPointer:            ptr = self.value["value"].elementType            newValue = deepcopy(ptr.value)            func.symbol.memAddress = self.memAddress + ptr.size * arrayIndex            func.symbol.length = newValue.size          else :            raise Exception("Dereferencing is only allowed for pointer types")        else :          newValue = deepcopy(self.value["value"].elementType)          func.symbol.memAddress = self.memAddress + newValue.size * arrayIndex          func.symbol.length = newValue.size      else :        raise Exception("Indexing a poke is only supported for arrays")    elif dereference == True :      if self.isPointer and self.isArray :        raise Exception("Poke cannot be used to dereference an entire array of pointers")      elif not self.isPointer :        raise Exception("Dereferencing is only allowed for pointer types")      newValue = deepcopy(self.value["value"].value)      func.symbol.memAddress = self.memAddress      func.symbol.length = newValue.size    else :       if self.isArray and self.size > self.parent.app.ramSymbol_t.data.size :          raise Exception("Array is too large for poking.  You must index the poke")      if self.isStruct :        newValue = deepcopy(self)      elif self.isPointer :        newValue = self.parent.app.types["unsigned int"]      else :        newValue = deepcopy(self.value["value"])      func.symbol.memAddress = self.memAddress      func.symbol.length = newValue.size    if func.symbol.length > self.parent.app.types.ramSymbol_t.data.size :      raise Exception("Ram symbol size too large for msg buffer")    if value != None :      self._assignParam(newValue, value, "value")    newBytes = newValue.getBytes()    oldBytes = func.symbol.data.getBytes()    newBytes = oldBytes.replace(oldBytes[:func.symbol.length], newBytes, 1)    func.symbol.data.setBytes(newBytes)    func.symbol.dereference = dereference    result = func(**nameArgs)    if result != None:      return map(self.parsePokeResponse, result)      def parsePokeResponse(self, msg) :    response = deepcopy(self.pokeResponseMsg)    if msg.nescType == "RpcResponseMsg":      response.value=0      addr = msg.sourceAddress    else :      if msg.value["value"].value != self.memAddress and (not self.isArray or          (msg.value["value"].value -self.memAddress) % self.value["value"].elementType.size !=0 or          msg.memAddress >= self.memAddress + self.len * self.value["value"].elementType.size):        raise Exception("Memory address mismatch in poke response")      response.value = 1      addr = msg.parentMsg.sourceAddress    response.parentMsg = msg    response.nescType = "".join( [self.nescType, ".poke(),  nodeID=%d"%addr] )    return response  def peek(self, arrayIndex = None, dereference=False, **nameArgs) :    if not self.parent.app.__dict__.has_key("RamSymbolsM") :      raise Exception("You must include the contrib/hood/tos/lib/RamSymbols/RamSymbolsM module in your nesc application in order to poke or peek at ram symbols")    func = self.parent.app.RamSymbolsM.peek    if arrayIndex != None :      #change memaddress to memAddres + array index      if self.isArray :        if dereference :          if self.isPointer :            func.memAddress = self.memAddress + self.value["value"].elementType.size * arrayIndex            #set length of memcpy to ptr dereferenced value            func.length = self.value["value"].elementType.value.size          else :            raise Exception("Dereferencing a peek is only allowed for pointers")        else :          func.memAddress = self.memAddress + self.value["value"].elementType.size * arrayIndex          func.length = self.value["value"].elementType.size      else :        raise Exception("Indexing a peek is only allowed for arrays")    elif dereference :      #if this is an array or ptrs, fail      if self.isArray :        raise Exception("peek cannot be used to dereference an array of pointers")

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -