Exemplo n.º 1
0
def testTalkingToController():
    """
    Start RailroadBig and Controller.
    Start a separate thread to send messages to the railroad.
        Tell Controller to read layout.xml.
        Initialize train 1111 at position [5,1] and assume response is virtual slot 5.
        Tell train to blink lights and change direction five times.
    Should see messages sent and messages received.
    """
    print("Entering function testTalkingToController")
    sak = StartAndKill()
    sak.setPath("../../runSoftware")
    sak.start("simulator")
    sak.start("controller")
    sk = MsgSocket(name="1")
    sk.connect("localhost", 1235)
    time.sleep(2)
    sk.send(DoReadLayoutMsg("../../runSoftware/Layout.xml"))
    process = TestBlinkLightsViaController(sk)
    time.sleep(5)
    process.start()
    while True:
        try:
            sk.receive()
        except:
            break
    sk.close()
    print("Leaving function testTalkingToController\n")
Exemplo n.º 2
0
def testReceive():
    """
    Start RailroadBig and connect to it at (local host, 1234).
    Start a separate thread to send messages to the railroad.
        Register train 1111 and assume response is physical slot 1
        Tell train to blink lights and change direction 5 times.
    Should see messages sent and messages received.
    """
    sak = StartAndKill()
    print("Entering function testReceive\n")
    sak.setPath("../../runSoftware")
    sak.start("simulator")
    sk = MsgSocket(name="1")
    sk.connect("localhost", 1234)
    process = TestBlinkLightsDirectly(sk)
    process.start()
    while True:
        try:
            sk.receive()
        except:
            break
    sk.close()
    print("Leaving function testReceive\n")
Exemplo n.º 3
0
def testSend():
    """
    Start RailroadBig and connect to it at (local host, 1234)
    Register train 1111 and assume response is physical slot 1
    Tell train to blink its lights 5 times
    Will see only the messages sent.
    """
    sak = StartAndKill()
    print("Entering function testSend")
    sak.setPath("../../runSoftware")
    sak.start("simulator")
    time.sleep(3)
    sk = MsgSocket(name="1")  # sk is the socket to the simulator
    sk.connect("localhost", 1234)
    sk.send(LocoAdrMsg(address=1111))  # find slot for loco 1111 and assume response is slot 1
    time.sleep(1)
    sk.send(MoveSlotsMsg(slot1=1, slot2=1))  # register slot 1
    time.sleep(1)
    for i in range(1, 6):
        # send to slot 1 messages to turn the lights on and off
        sk.send(LocoDirfMsg(slot=1, direction=kBackward, lights=kOn, horn=kOff, bell=kOn))
        time.sleep(0.2)
        sk.send(LocoDirfMsg(slot=1, direction=kForward, lights=kOff, horn=kOff, bell=kOff))
        time.sleep(0.2)
    raw_input("Press enter to kill RailroadBig and leave function testSend")
    sk.close()
    sak.kill("simulator")
    print("Leaving function testSend")