mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

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