Skip to content

Commit 1d4d426

Browse files
Steve EasleyhgonzaleDigi
authored andcommitted
Fix timeouts on unix platform
1 parent 840c024 commit 1d4d426

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

digi/xbee/devices.py

100644100755
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,11 +2528,11 @@ def __build_xbee_message(self, packet, explicit=False):
25282528
remote = RemoteXBeeDevice(self, x64addr, x16addr)
25292529

25302530
if explicit:
2531-
msg = ExplicitXBeeMessage(packet.rf_data, remote, time.clock(), packet.source_endpoint,
2531+
msg = ExplicitXBeeMessage(packet.rf_data, remote, time.time(), packet.source_endpoint,
25322532
packet.dest_endpoint, packet.cluster_id,
25332533
packet.profile_id, packet.is_broadcast())
25342534
else:
2535-
msg = XBeeMessage(packet.rf_data, remote, time.clock(), packet.is_broadcast())
2535+
msg = XBeeMessage(packet.rf_data, remote, time.time(), packet.is_broadcast())
25362536

25372537
return msg
25382538

@@ -4312,8 +4312,8 @@ def packet_receive_callback(xbee_packet):
43124312
try:
43134313
self.send_packet(ATCommPacket(self.get_next_frame_id(), "AS"), False)
43144314

4315-
dead_line = time.clock() + self.__DISCOVER_TIMEOUT
4316-
while self.__scanning_aps and time.clock() < dead_line:
4315+
dead_line = time.time() + self.__DISCOVER_TIMEOUT
4316+
while self.__scanning_aps and time.time() < dead_line:
43174317
time.sleep(0.1)
43184318

43194319
# Check if we exited because of a timeout.
@@ -4376,8 +4376,8 @@ def connect_by_ap(self, access_point, password=None):
43764376
self.set_parameter("PK", bytearray(password, "utf8"))
43774377

43784378
# Wait for the module to connect to the access point.
4379-
dead_line = time.clock() + self.__ap_timeout
4380-
while time.clock() < dead_line:
4379+
dead_line = time.time() + self.__ap_timeout
4380+
while time.time() < dead_line:
43814381
time.sleep(0.1)
43824382
# Get the association indication value of the module.
43834383
status = self.get_parameter("AI")
@@ -4459,8 +4459,8 @@ def disconnect(self):
44594459
| :meth:`.WiFiDevice.set_access_point_timeout`
44604460
"""
44614461
self.execute_command("NR")
4462-
dead_line = time.clock() + self.__ap_timeout
4463-
while time.clock() < dead_line:
4462+
dead_line = time.time() + self.__ap_timeout
4463+
while time.time() < dead_line:
44644464
time.sleep(0.1)
44654465
# Get the association indication value of the module.
44664466
status = self.get_parameter("AI")
@@ -5686,7 +5686,7 @@ def __discover_devices(self, node_id=None):
56865686
node_id (String, optional): node identifier of the remote XBee device to discover. Optional.
56875687
"""
56885688
try:
5689-
init_time = time.clock()
5689+
init_time = time.time()
56905690

56915691
# In 802.15.4 devices, the discovery finishes when the 'end' command
56925692
# is received, so it's not necessary to calculate the timeout.
@@ -5704,7 +5704,7 @@ def __discover_devices(self, node_id=None):
57045704
if not is_802_compatible:
57055705
# If XBee device is not 802.15.4, wait until timeout expires.
57065706
while self.__discovering or self.__sought_device_id is not None:
5707-
if (time.clock() - init_time) > timeout:
5707+
if (time.time() - init_time) > timeout:
57085708
with self.__lock:
57095709
self.__discovering = False
57105710
break

digi/xbee/models/message.py

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ def __is_broadcast(self):
6666

6767
def __get_timestamp(self):
6868
"""
69-
Returns the moment when the message was received as a ``time.clock()``
69+
Returns the moment when the message was received as a ``time.time()``
7070
function returned value.
7171
7272
Returns:
73-
Float: the returned value of using :meth:`time.clock()` function when the message was received.
73+
Float: the returned value of using :meth:`time.time()` function when the message was received.
7474
"""
7575
return self.__timestamp
7676

digi/xbee/reader.py

100644100755
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def __execute_user_callbacks(self, xbee_packet, remote=None):
561561
xbee_packet.get_frame_type() == ApiFrameType.RECEIVE_PACKET):
562562
_data = xbee_packet.rf_data
563563
is_broadcast = xbee_packet.receive_options == ReceiveOptions.BROADCAST_PACKET
564-
self.__data_received(XBeeMessage(_data, remote, time.clock(), is_broadcast))
564+
self.__data_received(XBeeMessage(_data, remote, time.time(), is_broadcast))
565565
self._log.info(self._LOG_PATTERN.format(port=self.__xbee_device.serial_port.port,
566566
event="RECEIVED",
567567
fr_type="DATA",
@@ -583,7 +583,7 @@ def __execute_user_callbacks(self, xbee_packet, remote=None):
583583
elif (xbee_packet.get_frame_type() == ApiFrameType.RX_IO_16 or
584584
xbee_packet.get_frame_type() == ApiFrameType.RX_IO_64 or
585585
xbee_packet.get_frame_type() == ApiFrameType.IO_DATA_SAMPLE_RX_INDICATOR):
586-
self.__io_sample_received(xbee_packet.io_sample, remote, time.clock())
586+
self.__io_sample_received(xbee_packet.io_sample, remote, time.time())
587587
self._log.info(self._LOG_PATTERN.format(port=self.__xbee_device.serial_port.port,
588588
event="RECEIVED",
589589
fr_type="IOSAMPLE",
@@ -596,7 +596,7 @@ def __execute_user_callbacks(self, xbee_packet, remote=None):
596596
is_broadcast = False
597597
# If it's 'special' packet, notify the data_received callbacks too:
598598
if self.__is_special_explicit_packet(xbee_packet):
599-
self.__data_received(XBeeMessage(xbee_packet.rf_data, remote, time.clock(), is_broadcast))
599+
self.__data_received(XBeeMessage(xbee_packet.rf_data, remote, time.time(), is_broadcast))
600600
self.__explicit_packet_received(PacketListener.__expl_to_message(remote, is_broadcast, xbee_packet))
601601
self._log.info(self._LOG_PATTERN.format(port=self.__xbee_device.serial_port.port,
602602
event="RECEIVED",
@@ -816,7 +816,7 @@ def __expl_to_message(remote, broadcast, xbee_packet):
816816
Returns:
817817
:class:`.ExplicitXBeeMessage`: the explicit message generated from the provided parameters.
818818
"""
819-
return ExplicitXBeeMessage(xbee_packet.rf_data, remote, time.clock(), xbee_packet.source_endpoint,
819+
return ExplicitXBeeMessage(xbee_packet.rf_data, remote, time.time(), xbee_packet.source_endpoint,
820820
xbee_packet.dest_endpoint, xbee_packet.cluster_id,
821821
xbee_packet.profile_id, broadcast)
822822

@@ -899,8 +899,8 @@ def get_by_remote(self, remote_xbee_device, timeout=None):
899899
return None
900900
else:
901901
xbee_packet = self.get_by_remote(remote_xbee_device, None)
902-
dead_line = time.clock() + timeout
903-
while xbee_packet is None and dead_line > time.clock():
902+
dead_line = time.time() + timeout
903+
while xbee_packet is None and dead_line > time.time():
904904
time.sleep(0.1)
905905
xbee_packet = self.get_by_remote(remote_xbee_device, None)
906906
if xbee_packet is None:
@@ -937,8 +937,8 @@ def get_by_ip(self, ip_addr, timeout=None):
937937
return None
938938
else:
939939
xbee_packet = self.get_by_ip(ip_addr, None)
940-
dead_line = time.clock() + timeout
941-
while xbee_packet is None and dead_line > time.clock():
940+
dead_line = time.time() + timeout
941+
while xbee_packet is None and dead_line > time.time():
942942
time.sleep(0.1)
943943
xbee_packet = self.get_by_ip(ip_addr, None)
944944
if xbee_packet is None:

doc/user_doc/handling_analog_and_digital_io_lines.rst

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ event is raised:
599599
* The received IO sample as an ``IOSample`` object.
600600
* The remote XBee device that sent the IO sample as a ``RemoteXBeeDevice``
601601
object.
602-
* The time in which the IO sample was received as an ``Integer`` (calculated
603-
with Python standard ``time.clock()``).
602+
* The time in which the IO sample was received as an ``Float`` (calculated
603+
with Python standard ``time.time()``).
604604

605605
To stop receiving notifications of new IO samples, remove the added callback
606606
using the ``del_io_sample_received_callback()`` method.

functional_tests/long_test.py

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ def data_callback(message):
8888

8989
print("Sending data...\n")
9090

91-
dead_line = time.clock() + duration
91+
dead_line = time.time() + duration
9292

93-
while dead_line > time.clock():
93+
while dead_line > time.time():
9494
retries = MAX_RETRIES
9595
data_received = False
9696
while not data_received:

0 commit comments

Comments
 (0)