Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. from TCP_connection import Client
  4. from command import Train
  5. from time import sleep
  6. import os
  7.  
  8. TCP_IP = '192.168.210.200'
  9. TCP_PORT = 5550
  10.  
  11.  
  12. def cls():
  13. # TODO Sprawdzić działanie w konsoli - czyszczenie ekranu w obsłudze menu
  14. os.system('cls' if os.name == 'nt' else 'clear')
  15.  
  16.  
  17. def main():
  18. direction = {"Forward": 1, "Backward": 0}
  19. client = Client()
  20. client.connect(TCP_IP, TCP_PORT)
  21. # TODO Rozbudowa menu do testów
  22. while True:
  23. numer = input("Podaj numer pociągu[1-7]: ")
  24. if not numer in range(1, 8):
  25. # cls()
  26. print("Nieprawidlowy numer pociagu.\n")
  27. continue
  28. train = Train(numer)
  29. while True:
  30. key = input(train.menu())
  31. if key == 1:
  32. msg = train.move(127, direction["Forward"]) # do przodu z prędkością max
  33. elif key == 2:
  34. msg = train.move(127, direction["Backward"]) # do tylu z prędkością max
  35. elif key == 3:
  36. vel = input("Zakres[0-127]: ")
  37. msg = train.move(vel, direction["Forward"]) # do przodu z określoną prędkością
  38. elif key == 4:
  39. vel = input("Zakres[0-127]: ")
  40. msg = train.move(vel, direction["Backward"]) # do tylu z określoną prędkością
  41. elif key == 5:
  42. msg = train.move(0) # Stop
  43. elif key == 6:
  44. msg = train.stop_all_locomotives()
  45. elif key == 0:
  46. msg = train.move(0) # Zakończ
  47. client.send(msg)
  48. sleep(1)
  49. break
  50. else:
  51. # cls()
  52. print("Podano nieprawidłowy klawisz. Cofam na poczatek.")
  53. continue
  54. print client.send(msg)
  55. sleep(1) # Czekaj 1s
  56. key1 = raw_input(menu())
  57. print key1
  58. if key1 == 'q' or key1 == 'Q':
  59. break
  60. else:
  61. continue
  62. client.disconnect()
  63.  
  64.  
  65. def menu():
  66. print("Aby zakończyć program naciśnij klawisz q.")
  67.  
  68.  
  69. if __name__ == "__main__":
  70. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement