parameters: ()
docstring: Transmits a message and an incrementing integer every second, then
      wait for a response for up to 200 ms.
docstring_summary: Transmits a message and an incrementing integer every second, then
      wait for a response for up to 200 ms.
docstring_tokens: Transmits a message and an incrementing integer every second then wait for a response for up to 200 ms .
function: def master():
      """Transmits a message and an incrementing integer every second, then
      wait for a response for up to 200 ms.
      """
      radio.stopListening()  # put radio in TX mode
      failures = 0
      while failures < 6:
          # use bytes() to pack our counter data into the payload
          # NOTE b"\x00" byte is a c-string's NULL terminating 0
          buffer = b"Hello \x00" + bytes(counter)
          start_timer = time.monotonic_ns()  # start timer
          result = radio.write(buffer)
          if not result:
              failures += 1
              print("Transmission failed or timed out")
          else:
              radio.startListening()  # put radio in RX mode
              timout = time.monotonic() * 1000 + 200  # use 200 ms timeout
              # declare a variable to save the incoming response
              while not radio.available() and time.monotonic() * 1000 < timout:
                  pass  # wait for incoming payload or timeout
              radio.stopListening()  # put radio in TX mode
              end_timer = time.monotonic_ns()  # end timer
              print(
                  "Transmission successful. Sent: {}{}.".format(
                      buffer[:6].decode("utf-8"),
                      counter[0]
                  ),
                  end=" "
              )
              has_payload, pipe_number = radio.available_pipe()
              if has_payload:
                  # grab the incoming payload
                  received = radio.read(radio.payloadSize)
                  # NOTE received[7:8] discards NULL terminating 0
                  counter[0] = received[7:8][0]  # save the counter
                  print(
                      "Received {} bytes on pipe {}: {}{}. "
                      "Round-trip delay: {} us.".format(
                          radio.payloadSize,
                          pipe_number,
                          bytes(received[:6]).decode("utf-8"),
                          counter[0],
                          (end_timer - start_timer) / 1000
                      )
                  )
              else:
                  print("No response received.")
          time.sleep(1)  # make example readable by slowing down transmissions
      print(failures, "failures detected. Leaving TX role.")
function_tokens: def master ( ) : radio . stopListening ( ) # put radio in TX mode failures = 0 while failures < 6 : # use bytes() to pack our counter data into the payload # NOTE b"\x00" byte is a c-string's NULL terminating 0 buffer = b"Hello \x00" + bytes ( counter ) start_timer = time . monotonic_ns ( ) # start timer result = radio . write ( buffer ) if not result : failures += 1 print ( "Transmission failed or timed out" ) else : radio . startListening ( ) # put radio in RX mode timout = time . monotonic ( ) * 1000 + 200 # use 200 ms timeout # declare a variable to save the incoming response while not radio . available ( ) and time . monotonic ( ) * 1000 < timout : pass # wait for incoming payload or timeout radio . stopListening ( ) # put radio in TX mode end_timer = time . monotonic_ns ( ) # end timer print ( "Transmission successful. Sent: {}{}." . format ( buffer [ : 6 ] . decode ( "utf-8" ) , counter [ 0 ] ) , end = " " ) has_payload , pipe_number = radio . available_pipe ( ) if has_payload : # grab the incoming payload received = radio . read ( radio . payloadSize ) # NOTE received[7:8] discards NULL terminating 0 counter [ 0 ] = received [ 7 : 8 ] [ 0 ] # save the counter print ( "Received {} bytes on pipe {}: {}{}. " "Round-trip delay: {} us." . format ( radio . payloadSize , pipe_number , bytes ( received [ : 6 ] ) . decode ( "utf-8" ) , counter [ 0 ] , ( end_timer - start_timer ) / 1000 ) ) else : print ( "No response received." ) time . sleep ( 1 ) # make example readable by slowing down transmissions print ( failures , "failures detected. Leaving TX role." )