def exchange(self, msg_send, block = True): if block: # Blocking read returns message on success, while not self.any(): # None on timeout pass else: # Nonblocking read returns message on success, if not self.any(): # None on timeout, False on no data return False msg_rx = FromMaster() if self.await_message(msg_rx): if self.sendbuf(msg_send): return msg_rx.unpack() return None # Timeout
def exchange(self, msg_send, block = True): if block: # Blocking read returns message on success, while not self.any(): # None on timeout pass else: # Nonblocking read returns message on success, if not self.any(): # None on timeout, False on no data return False msg_rx = FromMaster() if self.await_message(msg_rx): self.sendbuf(msg_send) # Sometimes returns False when it has actually worked. return msg_rx.unpack() # In this instance don't discard received data. return None # Timeout
def exchange(self, msg_send, block=True): if block: # Blocking read returns message on success, while not self.any(): # None on timeout pass else: # Nonblocking read returns message on success, if not self.any(): # None on timeout, False on no data return False msg_rx = FromMaster() if self.await_message(msg_rx): if self.sendbuf(msg_send): return msg_rx.unpack() return None # Timeout
def tm(): m = rf.Master(testbox_config) send_msg = FromMaster() while True: result = m.exchange(send_msg) if result is not None: print(result.i0) else: print('Timeout') send_msg.i0 += 1 pyb.delay(1000)
def test_master(): m = radio_fast.Master(master_config) send_msg = FromMaster() while True: result = m.exchange(send_msg) if result is not None: print(result.i0) print("Just my $0.02 worth") else: print('Timeout') send_msg.i0 += 1 pyb.delay(1000)
def __init__(self, master, config): super().__init__(pyb.SPI(config.spi_no), pyb.Pin(config.csn_pin), pyb.Pin(config.ce_pin), config.channel, FromMaster.payload_size()) if master: self.open_tx_pipe(RadioFast.pipes[0]) self.open_rx_pipe(1, RadioFast.pipes[1]) else: self.open_tx_pipe(RadioFast.pipes[1]) self.open_rx_pipe(1, RadioFast.pipes[0]) self.set_power_speed(POWER_3, SPEED_250K) # Best range for point to point links self.start_listening()
def master(lcd): yield Roundrobin() m = rf.Master(testbox_config) send_msg = FromMaster() while True: start = pyb.millis() result = m.exchange(send_msg) t = pyb.elapsed_millis(start) lcd[1] = 't = {}mS'.format(t) if result is not None: lcd[0] = str(result.i0) else: lcd[0] = 'Timeout' yield from wait(1.0) send_msg.i0 += 1
async def run_master(lcd): await asyncio.sleep(0) m = rf.Master(testbox_config) send_msg = FromMaster() while True: start = ticks_ms() result = m.exchange(send_msg) t = ticks_diff(ticks_ms(), start) lcd[1] = 't = {}mS'.format(t) if result is not None: lcd[0] = str(result.i0) else: lcd[0] = 'Timeout' await asyncio.sleep(1) send_msg.i0 += 1