[Tinyos-2-commits] CVS: tinyos-2.x/support/sdk/python tos.py, 1.3, 1.4
Razvan Musaloiu-E.
razvanm at users.sourceforge.net
Wed Dec 24 20:45:39 PST 2008
Update of /cvsroot/tinyos/tinyos-2.x/support/sdk/python
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20789/support/sdk/python
Modified Files:
tos.py
Log Message:
Add a separate timeout for acks in tos.py
When the rate of successful acks is low (as it is right now on my machine)
we need tighter timings to make fast progress for bulk uploads (Deluge T2
for example).
Index: tos.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/support/sdk/python/tos.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** tos.py 15 Dec 2008 00:50:37 -0000 1.3
--- tos.py 25 Dec 2008 04:45:37 -0000 1.4
***************
*** 31,34 ****
--- 31,35 ----
import sys, struct, time, socket, operator, os
+ import traceback
try:
***************
*** 69,88 ****
if source[0] == 'serial':
try:
! return Serial(params[0], int(params[1]), flush=True, debug=False)
except:
! print "ERROR: Unable to initialize serial port connection to", comm
! sys.exit(-1)
elif source[0] == 'network':
try:
return SerialMIB600(params[0], int(params[1]), debug=False)
except:
! print "ERROR: Unable to initialize serial port connection to", comm
! sys.exit(-1)
raise Exception
class Serial:
! def __init__(self, port, baudrate, flush=False, debug=False, timeout=None):
self.debug = debug
! self.timeout = timeout
self._ts = None
--- 70,91 ----
if source[0] == 'serial':
try:
! return Serial(params[0], int(params[1]), flush=True, debug=('--debug' in sys.argv))
except:
! print "ERROR: Unable to initialize a serial connection to", comm
! raise Exception
elif source[0] == 'network':
try:
return SerialMIB600(params[0], int(params[1]), debug=False)
except:
! print "ERROR: Unable to initialize a network connection to", comm
! print "ERROR:", traceback.format_exc()
! raise Exception
raise Exception
class Serial:
! def __init__(self, port, baudrate, flush=False, debug=False, readTimeout=None, ackTimeout=0.02):
self.debug = debug
! self.readTimeout = readTimeout
! self.ackTimeout = ackTimeout
self._ts = None
***************
*** 98,102 ****
sys.stdout.write("\n")
self._s.close()
! self._s = serial.Serial(port, baudrate, rtscts=0, timeout=timeout)
def getByte(self):
--- 101,105 ----
sys.stdout.write("\n")
self._s.close()
! self._s = serial.Serial(port, baudrate, rtscts=0, timeout=readTimeout)
def getByte(self):
***************
*** 119,124 ****
class SerialMIB600:
! def __init__(self, host, port=10002, debug=False):
self.debug = debug
self._ts = None
self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
--- 122,129 ----
class SerialMIB600:
! def __init__(self, host, port=10002, debug=False, readTimeout=None, ackTimeout=0.05):
self.debug = debug
+ self.readTimeout = readTimeout
+ self.ackTimeout = ackTimeout
self._ts = None
self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
***************
*** 127,131 ****
def getByte(self):
! c = self._s.recv(1)
if c == '':
raise Timeout
--- 132,139 ----
def getByte(self):
! try:
! c = self._s.recv(1)
! except socket.timeout:
! c = ''
if c == '':
raise Timeout
***************
*** 256,260 ****
return None
! def write(self, payload, seqno, timeout=0.2):
"""
Write a packet. If the payload argument is a list, it is
--- 264,268 ----
return None
! def write(self, payload, seqno):
"""
Write a packet. If the payload argument is a list, it is
***************
*** 347,382 ****
class SimpleAM(object):
! def __init__(self, s, oobHook=None):
! self._s = HDLC(s)
self.seqno = 0
self.oobHook = oobHook
def read(self, timeout=None):
! f = self._s.read(timeout)
if f:
return ActiveMessage(NoAckDataFrame(f))
return None
! def write(self, packet, amId, timeout=None, blocking=True, inc=1):
self.seqno = (self.seqno + inc) % 256
! while True:
! self._s.write(ActiveMessage(packet, amId=amId), seqno=self.seqno, timeout=timeout)
if not blocking:
return True
! f = self._s.read(timeout)
if f == None:
continue
ack = AckFrame(f)
! while ack.protocol != SERIAL_PROTO_ACK:
if self.oobHook:
self.oobHook(ActiveMessage(NoAckDataFrame(f)))
else:
print 'SimpleAM:write: skip', ack, f
! f = self._s.read(timeout)
if f == None:
break
ack = AckFrame(f)
if f != None:
break
#print 'SimpleAM:write: got an ack:', ack, ack.seqno == self.seqno
return ack.seqno == self.seqno
--- 355,398 ----
class SimpleAM(object):
! def __init__(self, source, oobHook=None):
! self._source = source
! self._hdlc = HDLC(source)
self.seqno = 0
self.oobHook = oobHook
def read(self, timeout=None):
! f = self._hdlc.read(timeout)
if f:
return ActiveMessage(NoAckDataFrame(f))
return None
! def write(self, packet, amId, timeout=5, blocking=True, inc=1):
self.seqno = (self.seqno + inc) % 256
! prevTimeout = self._source.getTimeout()
! end = None
! if timeout: end = time.time() + timeout
! while not end or time.time() < end:
! self._hdlc.write(ActiveMessage(packet, amId=amId), seqno=self.seqno)
if not blocking:
return True
! start = time.time()
! f = self._hdlc.read(self._source.ackTimeout)
if f == None:
+ #print "Ack Timeout!"
continue
ack = AckFrame(f)
! while ack.protocol != SERIAL_PROTO_ACK and (not end or time.time() < end):
if self.oobHook:
self.oobHook(ActiveMessage(NoAckDataFrame(f)))
else:
print 'SimpleAM:write: skip', ack, f
! f = self._hdlc.read(self._source.ackTimeout)
if f == None:
+ #print "Ack Timeout!"
break
ack = AckFrame(f)
if f != None:
break
+ self._source.setTimeout(prevTimeout)
#print 'SimpleAM:write: got an ack:', ack, ack.seqno == self.seqno
return ack.seqno == self.seqno
***************
*** 411,417 ****
try:
s = getSource(os.environ['MOTECOM'])
- print 'third'
except:
! print "ERROR: please indicate a way to connect to the mote"
sys.exit(-1)
if oobHook == None:
--- 427,432 ----
try:
s = getSource(os.environ['MOTECOM'])
except:
! print "ERROR: Please indicate a way to connect to the mote"
sys.exit(-1)
if oobHook == None:
More information about the Tinyos-2-commits
mailing list