Keyboard firmwares for Atmel AVR and Cortex-M
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

udpecho_client.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """
  2. mbed SDK
  3. Copyright (c) 2011-2013 ARM Limited
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. """
  14. from socket import socket, AF_INET, SOCK_DGRAM
  15. import string, random
  16. from time import time
  17. from private_settings import CLIENT_ADDRESS
  18. ECHO_PORT = 7
  19. LEN_PACKET = 127
  20. N_PACKETS = 5000
  21. TOT_BITS = float(LEN_PACKET * N_PACKETS * 8) * 2
  22. MEGA = float(1024 * 1024)
  23. UPDATE_STEP = (N_PACKETS/10)
  24. class UDP_EchoClient:
  25. s = socket(AF_INET, SOCK_DGRAM)
  26. def __init__(self, host):
  27. self.host = host
  28. self.packet = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(LEN_PACKET))
  29. def __packet(self):
  30. # Comment out the checks when measuring the throughput
  31. # packet = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(LEN_PACKET))
  32. UDP_EchoClient.s.sendto(packet, (self.host, ECHO_PORT))
  33. data = UDP_EchoClient.s.recv(LEN_PACKET)
  34. # assert packet == data, "packet error:\n%s\n%s\n" % (packet, data)
  35. def test(self):
  36. start = time()
  37. for i in range(N_PACKETS):
  38. if (i % UPDATE_STEP) == 0: print '%.2f%%' % ((float(i)/float(N_PACKETS)) * 100.)
  39. self.__packet()
  40. t = time() - start
  41. print 'Throughput: (%.2f)Mbits/s' % ((TOT_BITS / t)/MEGA)
  42. while True:
  43. e = UDP_EchoClient(CLIENT_ADDRESS)
  44. e.test()