Skip to content

Commit

Permalink
Fix scripts/tx_bench.py for python3 for Linux & Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bvernoux committed Mar 24, 2023
1 parent 1780a9d commit 73a9457
Showing 1 changed file with 52 additions and 51 deletions.
103 changes: 52 additions & 51 deletions scripts/tx_bench.py
Original file line number Diff line number Diff line change
@@ -1,78 +1,79 @@
#!/usr/bin/env python
#!/usr/bin/env python3

############################### tx_bench.py ###############################
"""
Before to launch this test start HydraBus with latest HydraFW and open a console then type
debug test-rx
Then close the console and launch following example benchmark.
Before to launch this test just reset HydraBus board(to be sure it is in a clean state)
Examples
tx_bench.py 64 1000 >> bench.txt
tx_bench.py 128 500 >> bench.txt
tx_bench.py 256 500 >> bench.txt
tx_bench.py 500 500 >> bench.txt
tx_bench.py 512 500 >> bench.txt
tx_bench.py 1000 500 >> bench.txt
tx_bench.py 1008 500 >> bench.txt
tx_bench.py 1024 500 >> bench.txt
tx_bench.py 1280 400 >> bench.txt
tx_bench.py 2000 400 >> bench.txt
tx_bench.py 2048 400 >> bench.txt
tx_bench.py 3000 400 >> bench.txt
Examples Windows with HydraBus on COM4 (for Linux use /dev/ttyACM0 ...)
python tx_bench.py COM4 1 10000 >> bench_1B.txt
python tx_bench.py COM4 4 10000 >> bench_4B.txt
python tx_bench.py COM4 8 10000 >> bench_8B.txt
python tx_bench.py COM4 16 10000 >> bench_16B.txt
python tx_bench.py COM4 64 5000 >> bench_64B.txt
python tx_bench.py COM4 128 2000 >> bench_128B.txt
python tx_bench.py COM4 256 2000 >> bench_256B.txt
python tx_bench.py COM4 500 2000 >> bench_500B.txt
python tx_bench.py COM4 512 2000 >> bench_512B.txt
python tx_bench.py COM4 1000 1000 >> bench_1000B.txt
python tx_bench.py COM4 1008 1000 >> bench_1008B.txt
python tx_bench.py COM4 1024 1000 >> bench_1024B.txt
python tx_bench.py COM4 1280 800 >> bench_1280B.txt
python tx_bench.py COM4 2000 500 >> bench_2000B.txt
python tx_bench.py COM4 2048 500 >> bench_2048B.txt
python tx_bench.py COM4 3000 400 >> bench_3000B.txt
python tx_bench.py COM4 4096 300 >> bench_4096B.txt
"""

import serial;
import time;
import sys;
import serial
import time
import sys

def main():

port = sys.argv[1]
try:
serialPort = serial.Serial('COM3',\
115200,
serial.EIGHTBITS,\
serial.PARITY_NONE,
serial.STOPBITS_ONE);
serialPort = serial.Serial(port, 115200, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE)
except:
print("Couldn't open serial port");
exit();

size = int(sys.argv[1]);
num_Packets = int(sys.argv[2]);
print("Couldn't open serial port %s" % port)
exit()

txData=[];
size = int(sys.argv[2])
num_Packets = int(sys.argv[3])

# Enter special debug test-rx mode
txData = "debug test-rx\n"
text = txData.encode('utf-8')
serialPort.write(text)
# Wait 0.1s to be sure Hydrabus is entered in debug test-rx mode
time.sleep(0.1)
serialPort.flushInput()

txData = ""
for i in range(size):
txData.append('a');
txData += 'a'

packet_Length = len(txData);
text = txData;
packet_Length = len(txData)
text = txData.encode('utf-8')

print('packet_Length: %d num_Packets: %d' % (packet_Length, num_Packets));
print('COM port: %s packet_Length: %d num_Packets: %d' % (port, packet_Length, num_Packets))

byteSent = 0;
byteSent = 0
# First time slice
t1 = time.time()

for i in range(num_Packets):
byteSent += serialPort.write(text);
byteSent += serialPort.write(text)

# Second time slice
t2 = time.time()
throughPut = (num_Packets * packet_Length)/(t2-t1);
throughPut = (num_Packets * packet_Length)/(t2-t1)

time_s = t2-t1;
throughPut_kb = throughPut/1024;
kbyteSent = byteSent/1024;
print("TX Time: %.5f s " % time_s);
print('TX Bytes/s: %d TX KBytes/s: %.2f' % (throughPut, throughPut_kb));
print;
"""
print;
print('Bytes Sent: %d ' % byteSent);
print('KBytes Sent: %.2f ' % kbyteSent);
"""
time_s = t2-t1
throughPut_kb = throughPut/1024
kbyteSent = byteSent/1024
print("TX Time: %.5f s " % time_s)
print('TX Bytes/s: %d TX KBytes/s: %.2f' % (throughPut, throughPut_kb))

if __name__ == '__main__':
main()

#!/usr/bin/env python

0 comments on commit 73a9457

Please sign in to comment.