コード例 #1
0
ファイル: travel_time_sender.py プロジェクト: xz-group/PiCar
def main():
    """A simple test to calculate the round trip time of
    packets

    This test was performed on: 3/21/2018
    Results: Overwhelmingly successful. See a fuller description
    on the log page:
    (https://classes.engineering.wustl.edu/ese205/core/index.php?title=Pi_Car_Comm_Log#Timing_Test_.28Finally.29)

    :return: None
    """
    network = Network(1024, 10)
    while True:
        message = "<token>Token data</token>"  # send token data every 2 seconds
        network.broadcast(message)
        time.sleep(2)
コード例 #2
0
ファイル: master.py プロジェクト: xz-group/PiCar
def main():
    # Create a serial port with which to communicate with an Arduino
    ser = serial.Serial(
        port='/dev/ttyACM0',
        baudrate=9600,
    )
    # Create a `Network` that can read in packets that are less than
    # or equal to 1024 bytes, and that stores the last 10 messages
    # it received.
    network = Network(1024, 10)
    try:
        while True:
            # noinspection PyBroadException
            try:
                # Decode the info coming from the Arduino
                command = ser.readline().decode('utf-8')
                # Broadcast the command to any Raspberry Pi's that are
                # listening.
                network.broadcast("<command>" + command + "</command>")
            except Exception:
                pass
    except KeyboardInterrupt:
        network.close_broadcast()