def run(self): print("Starting thread TestBlinkLightsViaController\n") sak = StartAndKill() self.sk.send(DoLocoInitMsg(address=1111, sensors=[5, 1])) time.sleep(1) for i in range(1, 6): self.sk.send(LocoDirfMsg(slot=5, direction=kBackward, lights=kOn, horn=kOff, bell=kOn)) time.sleep(0.2) self.sk.send(LocoDirfMsg(slot=5, direction=kForward, lights=kOff, horn=kOff, bell=kOff)) time.sleep(0.2) raw_input("\nPress enter to kill RailroadBig and Controller and stop thread BlinkLightsViaController \n") sak.kill("simulator") sak.kill("controller") print("Ending thread TestBlinkLightsViaController\n")
def run(self): print("Starting thread BlinkLightsDirectly\n") sak = StartAndKill() self.sk.send(LocoAdrMsg(address=1111)) time.sleep(1) self.sk.send(MoveSlotsMsg(slot1=1, slot2=1)) time.sleep(1) for i in range(1, 6): self.sk.send(LocoDirfMsg(slot=1, direction=kBackward, lights=kOn, horn=kOff, bell=kOn)) time.sleep(0.2) self.sk.send(LocoDirfMsg(slot=1, direction=kForward, lights=kOff, horn=kOff, bell=kOff)) time.sleep(0.2) raw_input("\nPress enter to kill RailroadBig and stop thread TestBlinkLightsDirectly \n") sak.kill("simulator") print("Ending thread TestBlinkLightsDirectly\n")
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")
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")
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")
######################################################################################### ########################### Unit Testing ################################################ ######################################################################################### from Log import gLog from StartAndKill import StartAndKill def raw_input(st): return input(st) if __name__ == "__main__": gLog.open('1', 5) sak = StartAndKill(mode='testing') sak.start("simulator") sak.start("controller", ip = "127.0.0.1", port = "1234", trace = "yes") sak.start("ut4", ip = "127.0.0.1", port = "1234") sak.start("RBLDisplay", ip = "127.0.0.1", port = "1235") sak.start("adminthrottle", ip = "127.0.0.1", port = "1235", layoutFile = "layout.xml", logs = "no") print("\n") sak.start("controller", trace = "no") sak.start("ut4", port = "1236") sak.start("RBLDisplay", ip = "127.1.1.1") sak.start("adminthrottle", ip = "127.0.0.1", port = "1234", logs = "yes") print("\n") sak.kill("sim") sak.kill("cont") sak.kill("ut4") sak.kill("RBL") sak.kill("admin")
from Throttle import Throttle from time import sleep def raw_input(st): return input(st) ################################################### if __name__ == "__main__": gLog.open() name = "Bill" # Start the simulator and controller sak = StartAndKill() sak.start("simulator") sak.start("controller") # Create the communication resources for 5 users comRes = CommunicationResources(name = 'gui thr test', host = 'localhost', port = 1235, numberOfPackages = 5) # Create a throttle to read the layout file throttle = Throttle(name = name, comPkg = comRes.getNextPackage()) gLog.print("Main: read layout file") msg = throttle.readLayout("../../runSoftware/Layout.xml") sleep(2) responseFlag, code = (msg.responseFlag, msg.code) gLog.print("Main: finished reading layout file: responseFlag = {0} and code ={1}".format(responseFlag, code)) if responseFlag != 1: print("ABEND")