[Tinyos-commits] CVS: tinyos-1.x/tools/python/pytos/tools Drain.py,
1.1, 1.2 Drip.py, 1.1, 1.2 RamSymbols.py, 1.2, 1.3 Rpc.py, 1.2, 1.3
Kamin Whitehouse
kaminw at users.sourceforge.net
Wed Oct 26 19:23:39 PDT 2005
- Previous message: [Tinyos-commits] CVS: tinyos-1.x/tools/python/pytos Comm.py, 1.1,
1.2
- Next message: [Tinyos-commits] CVS: tinyos-1.x/tools/python/pytos/util
MessageFilter.py, 1.1, 1.2 MessageSnooper.py, 1.1,
1.2 NescApp.py, 1.2, 1.3 RoutingMessages.py, 1.2, 1.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/tools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv871/tools
Modified Files:
Drain.py Drip.py RamSymbols.py Rpc.py
Log Message:
Added register/unregister functions to Drip and RamSymbols and updated the messageSnooper to know how to snoop on these messages. Added "get" functions to comm, drip and drain, so that only a single instance of each needs to be instantiated. Added a logically "negative" message filter.
Index: Drain.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/tools/Drain.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Drain.py 23 Sep 2005 10:20:33 -0000 1.1
--- Drain.py 27 Oct 2005 02:23:37 -0000 1.2
***************
*** 31,34 ****
--- 31,53 ----
drain = jimport.net.tinyos.drain
+ def getDrainObject(app, motecom=None, treeID=None) :
+ """This function returns the drain objects stored in app that is connected to optional motecom
+ with a optional treeID. If motecome and treeID are specified but there is no drain object
+ with these specs, it creates one"""
+ drains = []
+ for conn in app.connections :
+ if isinstance(conn, Drain) :
+ # if motecom==None or conn.motecom == motecom : #we need this funtion in java
+ # if treeID=None or conn.treeID == treeID : #we need this funtion in java
+ drains.append( conn )
+ if len(drains)==0 and motecom != None and treeID != None :
+ drain = Drain(app, treeID, app.motecom)
+ drain.delay=60 #rebuild every 5 mins #can we make this a parameter?
+ drain.forever=True
+ drain.VERBOSE=False
+ app.connections.append(drain)
+ drains.append(drain)
+ return drains
+
class Drain( JavaInheritor ) :
"""The Drain object inherits from both the Drain.java and
Index: Drip.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/tools/Drip.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Drip.py 23 Sep 2005 10:20:33 -0000 1.1
--- Drip.py 27 Oct 2005 02:23:37 -0000 1.2
***************
*** 24,30 ****
--- 24,48 ----
from pytos.util.JavaInheritor import JavaInheritor
import pytos.Comm as Comm
+ from copy import *
drip = jimport.net.tinyos.drip
+ def getDripObject(app, motecom=None, channel=None) :
+ """This function returns the drip object stored in app that is connected to optional motecom
+ with a optional channel. If motecome and channel are specified but there is no drip object
+ with these specs, it creates one"""
+ drips = []
+ for conn in app.connections :
+ if isinstance(conn, Drip) :
+ # if motecom == None or conn.motecom == motecom : #we need this funtion in java
+ # if channel == None or drip.channel == channel : #we need this funtion in java
+ drips.append( conn )
+ if len(drips) == 0 and motecom != None and channel != None :
+ drip = Drip(app, channel, app.motecom)
+ app.connections.append(drip)
+ drips.append(drip)
+ return drips
+
+
class Drip( JavaInheritor ) :
"""The Drip object inherits from the Drip.java object. It overrides the
***************
*** 43,46 ****
--- 61,65 ----
def __init__( self , app, channel, moteIF ) :
+ self.app = app
if type(moteIF) == str :
moteIF = Comm.openMoteIF(moteIF, app)
***************
*** 65,66 ****
--- 84,132 ----
self._javaParents[0].sendWakeup(msg, size)
+
+ def register( self , msg , callback, *comm ) :
+ comm = Comm.getCommObject(self.app)
+ comm.register(self.app.msgs.DripMsg, DripMsgPeeler(self.app, msg, callback))
+
+ def unregister( self , msg , callback , *comm ) :
+ comm = Comm.getCommObject(self.app)
+ comm.unregister(self.app.msgs.DripMsg, DripMsgPeeler(self.app, msg, callback))
+
+ def getCommObject(self, motecom) :
+ """This function returns the comm object stored in app. If there
+ is none, it creates one"""
+ for conn in self.app.connections :
+ if isinstance(conn, Comm.Comm) :
+ if motecom not in conn._connected :
+ conn.connect(motecom)
+ return conn
+ comm = Comm.Comm()
+ comm.connect(self.motecom)
+ self.app.connections.append(comm)
+ return comm
+
+ class DripMsgPeeler( Comm.MessageListener ) :
+ """This is a wrapper callback object that peels the Drip headers out
+ of a DripMsg mig object and creates a python TosMsg with the remaining data """
+
+ def __init__(self, app, msg, callback) :
+ self.app = app
+ self.msg = msg
+ Comm.MessageListener.__init__(self, callback )
+ self._firstHashFunction = self._hashFunction
+ self._hashFunction = self._combinedHash
+
+ def _combinedHash(self):
+ return self._firstHashFunction() + self.msg.amType #this will have to change
+
+ def messageReceived( self , addr , dripMsg ) :
+ if dripMsg.metadata.id == self.msg.amType :
+ try:
+ msg = deepcopy(self.msg)
+ bytes = dripMsg.data.getBytes()
+ msg.setBytes( bytes )
+ msg.parentMsg = dripMsg
+ self.callback( addr, msg )
+ except Exception, inst:
+ print inst
+ raise
Index: RamSymbols.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/tools/RamSymbols.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RamSymbols.py 28 Sep 2005 06:59:11 -0000 1.2
--- RamSymbols.py 27 Oct 2005 02:23:37 -0000 1.3
***************
*** 128,132 ****
func.symbol.dereference = dereference
result = func(**nameArgs)
! return map(self.parsePokeResponse, result)
def parsePokeResponse(self, msg) :
--- 128,133 ----
func.symbol.dereference = dereference
result = func(**nameArgs)
! if result != None:
! return map(self.parsePokeResponse, result)
def parsePokeResponse(self, msg) :
***************
*** 137,146 ****
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) :
raise Exception("Memory address mismatch in poke response")
response.value = 1
addr = msg.parentMsg.sourceAddress
response.parentMsg = msg
! response.nescType = "".join( [response.nescType, ", nodeID=%d"%addr] )
return response
--- 138,148 ----
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
***************
*** 183,187 ****
func.dereference = dereference
result = func(**nameArgs)
! return map(self.parsePeekResponse, result)
def parsePeekResponse(self, msg) :
--- 185,190 ----
func.dereference = dereference
result = func(**nameArgs)
! if result != None :
! return map(self.parsePeekResponse, result)
def parsePeekResponse(self, msg) :
***************
*** 200,212 ****
value = deepcopy(self.value["value"])
elif (self.isArray and msg.length == self.value["value"].elementType.size and
! (msg.memAddress -self.memAddress) % self.value["value"].elementType.size ==0):
value = deepcopy(self.value["value"].elementType)
elif (self.isArray and self.isPointer
and msg.length == self.value["value"].elementType.value.size and
! (msg.memAddress -self.memAddress) % self.value["value"].elementType.value.size ==0):
value = deepcopy(self.value["value"].elementType.value)
elif (self.isPointer
and msg.length == self.value["value"].value.size and
! (msg.memAddress -self.memAddress) % self.value["value"].value.size ==0):
value = deepcopy(self.value["value"].value)
else :
--- 203,217 ----
value = deepcopy(self.value["value"])
elif (self.isArray and msg.length == self.value["value"].elementType.size and
! (msg.memAddress -self.memAddress) % self.value["value"].elementType.size ==0 and
! msg.memAddress < self.memAddress + self.len * self.value["value"].elementType.size):
value = deepcopy(self.value["value"].elementType)
elif (self.isArray and self.isPointer
and msg.length == self.value["value"].elementType.value.size and
! (msg.memAddress -self.memAddress) % self.value["value"].elementType.value.size ==0 and
! msg.memAddress < self.memAddress + self.len * self.value["value"].elementType.size):
value = deepcopy(self.value["value"].elementType.value)
elif (self.isPointer
and msg.length == self.value["value"].value.size and
! msg.memAddress == self.memAddress ) :
value = deepcopy(self.value["value"].value)
else :
***************
*** 228,232 ****
addr = msg.parentMsg.sourceAddress
response.parentMsg = msg
! response.nescType = "".join( [response.nescType, ", nodeID=%d"%addr])
return response
--- 233,237 ----
addr = msg.parentMsg.sourceAddress
response.parentMsg = msg
! response.nescType = "".join( [self.nescType, ".peek(), nodeID=%d"%addr])
return response
***************
*** 247,250 ****
--- 252,289 ----
return result
+
+ def registerPeek(self, listener, comm=()) :
+ self.parent.app.RamSymbolsM.peek.register(SymbolResponseListener(listener, self.parsePeekResponse), *comm)
+
+ def unregisterPeek(self, listener, comm=()) :
+ self.parent.app.RamSymbols.peek.unregister(SymbolResponseListener(listener, self.parsePeekResponse), *comm)
+
+ def registerPoke(self, listener, comm=()) :
+ self.parent.app.RamSymbolsM.poke.register(SymbolResponseListener(listener, self.parsePokeResponse), *comm)
+
+ def unregisterPoke(self, listener, comm=()) :
+ self.parent.app.RamSymbols.poke.unregister(SymbolResponseListener(listener, self.parsePokeResponse), *comm)
+
+
+
+
+ class SymbolResponseListener( Comm.MessageListener ):
+
+ def __init__(self, callback, parseFunction ):
+ self.parseFunction = parseFunction
+ Comm.MessageListener.__init__(self, callback)
+ self._firstHashFunction = self._hashFunction
+ self._hashFunction = self._combinedHash
+
+ def _combinedHash(self):
+ return self._firstHashFunction() + self.parseFunction.__hash__()
+
+ def messageReceived( self , addr , msg ) :
+ try:
+ msg = self.parseFunction(msg)
+ self.callback(addr, msg)
+ except Exception, e:
+ pass
+
Index: Rpc.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/python/pytos/tools/Rpc.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Rpc.py 28 Sep 2005 06:59:11 -0000 1.2
--- Rpc.py 27 Oct 2005 02:23:37 -0000 1.3
***************
*** 106,110 ****
commArgs = ()
callParams = self.parseCallParams(nameArgs)
! self.rpcHeader.transactionID+=1
thisCall = deepcopy(self)
thisCall.rpcHeader.address = callParams["address"]
--- 106,110 ----
commArgs = ()
callParams = self.parseCallParams(nameArgs)
! self.rpcHeader.transactionID = self.rpcHeader.transactionID+1 % 256
thisCall = deepcopy(self)
thisCall.rpcHeader.address = callParams["address"]
***************
*** 113,117 ****
#If this is a blocking call, get ready to process response msgs for timeout time
! if callParams["blocking"] \
and callParams["timeout"] > 0 \
and callParams["responseDesired"]==True:
--- 113,118 ----
#If this is a blocking call, get ready to process response msgs for timeout time
! processMsgs = False
! if callParams["blocking"] ==True \
and callParams["timeout"] > 0 \
and callParams["responseDesired"]==True:
***************
*** 134,142 ****
if rxdTransactionID == thisCall.rpcHeader.transactionID :
responses.append(msg)
- print '.',
except Exception, e:
if len(e.args) >0 :
print "rpc error: %s" % str(e)
- print ' '
self.unregister(responseQueue)
return responses
--- 135,141 ----
***************
*** 169,177 ****
def register(self, listener, comm=()) :
self.parent.receiveComm.register(self.parent.app.msgs.RpcResponseMsg,
! RpcResponseListener(self.parent.app, self.responseMsg, listener), *comm)
def unregister(self, listener, comm=()) :
self.parent.receiveComm.unregister(self.parent.app.msgs.RpcResponseMsg,
! RpcResponseListener(self.parent.app, self.responseMsg, listener), *comm)
--- 168,178 ----
def register(self, listener, comm=()) :
self.parent.receiveComm.register(self.parent.app.msgs.RpcResponseMsg,
! RpcResponseListener(self.parent.app, self.responseMsg,
! listener, self.nescType, self.__call__.__hash__), *comm)
def unregister(self, listener, comm=()) :
self.parent.receiveComm.unregister(self.parent.app.msgs.RpcResponseMsg,
! RpcResponseListener(self.parent.app, self.responseMsg,
! listener, self.nescType, self.__call__.__hash__), *comm)
***************
*** 180,188 ****
class RpcResponseListener( Comm.MessageListener ):
! def __init__(self, app, responseMsg, callback ):
self.app = app
self.responseMsg = responseMsg
Comm.MessageListener.__init__(self, callback)
def messageReceived( self , addr , msg ) :
if msg.commandID == self.responseMsg.amType :
--- 181,196 ----
class RpcResponseListener( Comm.MessageListener ):
! def __init__(self, app, responseMsg, callback, rpcName, hashFunction ):
self.app = app
self.responseMsg = responseMsg
+ self.rpcName = rpcName
+ self._secondHashFunction = hashFunction
Comm.MessageListener.__init__(self, callback)
+ self._firstHashFunction = self._hashFunction
+ self._hashFunction = self._combinedHash
+ def _combinedHash(self):
+ return self._firstHashFunction() + self._secondHashFunction()
+
def messageReceived( self , addr , msg ) :
if msg.commandID == self.responseMsg.amType :
***************
*** 191,195 ****
response.setBytes( msg.data.getBytes() )
response.parentMsg = msg
! response.nescType = "".join( [response.nescType,
", nodeID=%d"%response.parentMsg.sourceAddress] )
self.callback( addr, response )
--- 199,203 ----
response.setBytes( msg.data.getBytes() )
response.parentMsg = msg
! response.nescType = "".join( [self.rpcName,
", nodeID=%d"%response.parentMsg.sourceAddress] )
self.callback( addr, response )
- Previous message: [Tinyos-commits] CVS: tinyos-1.x/tools/python/pytos Comm.py, 1.1,
1.2
- Next message: [Tinyos-commits] CVS: tinyos-1.x/tools/python/pytos/util
MessageFilter.py, 1.1, 1.2 MessageSnooper.py, 1.1,
1.2 NescApp.py, 1.2, 1.3 RoutingMessages.py, 1.2, 1.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-commits
mailing list