def test_txsleep(self): t1 = time.time() yield util.txsleep(1.2) t2 = time.time() tdiff = t2 - t1 self.assertTrue(tdiff >= 1.2)
def _processADRRequests(self): """Updates devices with target data rate, and sends ADR requests. This method is called every adrcycletime seconds as a looping task. """ # If we are running, return if self.adrprocessing is True: returnValue(None) self.adrprocessing = True devices = yield Device.all() sendtime = time.time() for device in devices: # Check this device is enabled if not device.enabled: continue # Check ADR is enabled if not device.adr: continue # Set the target data rate target = device.getADRDatarate(self.band, self.config.adrmargin) # If no target, or the current data rate is the target, continue if target is None: continue # Set the device adr_datr yield device.update(adr_datr=target) # Only send a request if we need to change if device.tx_datr == device.adr_datr: continue # If we are queueing commands, create the command and add to the queue. # Replace any existing requests. if self.config.macqueueing: log.info("Queuing ADR MAC Command") command = self._createLinkADRRequest(device) self._dequeueMACCommand(device.deveui, command) self._queueMACCommand(device.deveui, command) continue # Check we have reached the next scheduled ADR message time scheduled = sendtime + self.config.adrmessagetime current = time.time() if current < scheduled: yield txsleep(scheduled - current) # Refresh and send the LinkADRRequest sendtime = time.time() yield self._sendLinkADRRequest(device) self.adrprocessing = False