test_srv.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python2
  2. #
  3. # Copyright 2015-2019 Autoware Foundation
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. import sys
  17. import SocketServer
  18. import struct
  19. class Hdr(SocketServer.BaseRequestHandler):
  20. def handle(self):
  21. while True:
  22. data = self.request.recv(1024)
  23. if len(data) == 0:
  24. break;
  25. tp = struct.unpack('=5i', data)
  26. print(tp)
  27. (steer, accel, brake, gear, prog_manu) = tp
  28. #gear = 2 if gear is 1 else gear # for debug, R -> N , { 'b':0 , 'r':1 , 'n':2 , 'd':3 }
  29. #steer = 90 if steer > 90 else steer # for debug, limit 90
  30. data = struct.pack('=5i', steer, accel, brake, gear, prog_manu)
  31. self.request.send(data)
  32. self.request.close()
  33. if __name__ == "__main__":
  34. port = sys.argv[1] if len(sys.argv) > 1 else 12345
  35. srv = SocketServer.TCPServer(('', port), Hdr)
  36. srv.serve_forever()
  37. # EOF