Script output modified to get it much more userfriendly.

This commit is contained in:
klaute 2016-09-26 16:01:25 +02:00
parent 7f9a28061e
commit d470dd9d91

View file

@ -8,7 +8,7 @@ import serial
import copy import copy
import binascii import binascii
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import math import sys
import operator import operator
############################################################################### ###############################################################################
@ -352,6 +352,23 @@ def user_friendly_freq(f):
############################################################################### ###############################################################################
def gen_progress_bar(n, sf, ef, fs):
steps = 1 + ((end_freq - start_freq) / step_freq)
m = 40.0 / steps
ret = "[ "
for i in range(0, int(m * (steps - n))):
ret += "#"
for i in range(0, int(m * n)):
ret += " "
ret += " ] %0.2f %% " % ( (100.0 * (steps - n)/ steps) )
return ret
###############################################################################
if __name__ == "__main__": if __name__ == "__main__":
start_freq = 0 start_freq = 0
@ -374,6 +391,8 @@ if __name__ == "__main__":
if args.device != None: if args.device != None:
device = args.device device = args.device
print "SWR meter measurement software v0.1 by Kai Lauterbach (me@klaute.de)\n---\n"
openSerialDevice(device) openSerialDevice(device)
# 2. start thread to poll cc_dataReceiverThread() # 2. start thread to poll cc_dataReceiverThread()
@ -388,7 +407,7 @@ if __name__ == "__main__":
# dataSend = dataSend + 1 # dataSend = dataSend + 1
if args.start_freq != None: if args.start_freq != None:
print "sent: SET_START_FREQ" print "Set start frequency to: " + user_friendly_freq(args.start_freq)
sendSerialData([CC_CMD_SET_START_FREQ, sendSerialData([CC_CMD_SET_START_FREQ,
(args.start_freq & 0xff000000) >> 24, (args.start_freq & 0xff000000) >> 24,
(args.start_freq & 0x00ff0000) >> 16, (args.start_freq & 0x00ff0000) >> 16,
@ -397,7 +416,7 @@ if __name__ == "__main__":
dataSend = dataSend + 1 dataSend = dataSend + 1
if args.end_freq != None: if args.end_freq != None:
print "sent: SET_END_FREQ" print "Set the end frequency to: " + user_friendly_freq(args.end_freq)
sendSerialData([CC_CMD_SET_END_FREQ, sendSerialData([CC_CMD_SET_END_FREQ,
(args.end_freq & 0xff000000) >> 24, (args.end_freq & 0xff000000) >> 24,
(args.end_freq & 0x00ff0000) >> 16, (args.end_freq & 0x00ff0000) >> 16,
@ -406,7 +425,7 @@ if __name__ == "__main__":
dataSend = dataSend + 1 dataSend = dataSend + 1
if args.step_freq != None: if args.step_freq != None:
print "sent: SET_FREQ_STEP" print "Set the frequency step size to: " + user_friendly_freq(args.step_freq)
sendSerialData([CC_CMD_SET_FREQ_STEP, sendSerialData([CC_CMD_SET_FREQ_STEP,
(args.step_freq & 0xff000000) >> 24, (args.step_freq & 0xff000000) >> 24,
(args.step_freq & 0x00ff0000) >> 16, (args.step_freq & 0x00ff0000) >> 16,
@ -415,20 +434,20 @@ if __name__ == "__main__":
dataSend = dataSend + 1 dataSend = dataSend + 1
if args.intervall != None: if args.intervall != None:
print "sent: SET_INTERVALL" print "Set the time intervall to %d milliseconds" % (args.intervall)
sendSerialData([CC_CMD_SET_INTERVALL, sendSerialData([CC_CMD_SET_INTERVALL,
(args.intervall & 0x0000ff00) >> 8, (args.intervall & 0x0000ff00) >> 8,
(args.intervall & 0x000000ff)]) (args.intervall & 0x000000ff)])
dataSend = dataSend + 1 dataSend = dataSend + 1
if args.drive_str != None: if args.drive_str != None:
print "sent: SET_DRIVE_STRENGTH" print "Set the output drive strength to %d mA" % ((args.drive_str + 1) * 2)
sendSerialData([CC_CMD_SET_DRIVE_STRENGTH, sendSerialData([CC_CMD_SET_DRIVE_STRENGTH,
args.drive_str]) args.drive_str])
dataSend = dataSend + 1 dataSend = dataSend + 1
if args.start_meas == True: if args.start_meas == True:
print "sent: START_MEASUREMENT" print "\nStarting the measurement process..."
sendSerialData([CC_CMD_START_MEASUREMENT]) sendSerialData([CC_CMD_START_MEASUREMENT])
dataSend = dataSend + 1 dataSend = dataSend + 1
@ -445,13 +464,14 @@ if __name__ == "__main__":
# process it and set the data to read # process it and set the data to read
if e[1] == MSG_TYPE_ANSWER_OK: if e[1] == MSG_TYPE_ANSWER_OK:
print "recv: OK" #print "recv: OK"
pass
elif e[1] == MSG_TYPE_ANSWER_NOK: elif e[1] == MSG_TYPE_ANSWER_NOK:
print "recv: NOT OK" print "recv: NOT OK"
elif e[1] == MSG_TYPE_MEAS_FREQ_INFO: elif e[1] == MSG_TYPE_MEAS_FREQ_INFO:
print "recv: FREQ INFO" #print "recv: FREQ INFO"
freq = e[3][0] << 24 freq = e[3][0] << 24
freq += e[3][1] << 16 freq += e[3][1] << 16
freq += e[3][2] << 8 freq += e[3][2] << 8
@ -460,14 +480,15 @@ if __name__ == "__main__":
a0 += e[3][5] a0 += e[3][5]
a1 = e[3][6] << 8 a1 = e[3][6] << 8
a1 += e[3][7] a1 += e[3][7]
print "freq: " + user_friendly_freq(freq) #print "freq: " + user_friendly_freq(freq)
print "a0: " + str(a0) #print "a0: " + str(a0)
print "a1: " + str(a1) #print "a1: " + str(a1)
sys.stdout.write("\r" + gen_progress_bar(dataSend, start_freq, end_freq, step_freq))
meas_data.append([ freq, a0, a1 ]) meas_data.append([ freq, a0, a1 ])
elif e[1] == MSG_TYPE_CONFIG: elif e[1] == MSG_TYPE_CONFIG:
print "recv: CONFIG" #print "recv: CONFIG"
print "\nConfiguration used for measurement:"
start_freq = e[3][0] << 24 start_freq = e[3][0] << 24
start_freq += e[3][1] << 16 start_freq += e[3][1] << 16
start_freq += e[3][2] << 8 start_freq += e[3][2] << 8
@ -489,13 +510,16 @@ if __name__ == "__main__":
print "step_freq = " + user_friendly_freq(step_freq) print "step_freq = " + user_friendly_freq(step_freq)
print "intervall = " + str(intervall) + " ms" print "intervall = " + str(intervall) + " ms"
print "drive_str = " + str((drive_str + 1) * 2) + " mA" print "drive_str = " + str((drive_str + 1) * 2) + " mA"
print ""
if args.start_meas == True and config_read == False: if args.start_meas == True and config_read == False:
dataSend = dataSend + 1 + ((end_freq - start_freq) / step_freq) dataSend = dataSend + 1 + ((end_freq - start_freq) / step_freq)
config_read = True config_read = True
elif e[1] == MSG_TYPE_MEAS_END_INFO: elif e[1] == MSG_TYPE_MEAS_END_INFO:
print "recv: END INFO" #print "recv: END INFO"
sys.stdout.write("\r100.00 % done \n")
print ""
meas_freq = [] meas_freq = []
meas_ratio = [] meas_ratio = []
@ -552,7 +576,7 @@ if __name__ == "__main__":
FILE.close() FILE.close()
print "Output file " + args.output_file + " written." print "Output file " + args.output_file + " written."
print "First minimum VSWR " + str(min_vswr[0]) + " found at freqency " + user_friendly_freq(min_vswr[1]) print "First minimum VSWR %0.6f found at freqency %s" % (min_vswr[0], user_friendly_freq(min_vswr[1]))
##### #####
if args.show_graph == True: if args.show_graph == True:
@ -574,8 +598,8 @@ if __name__ == "__main__":
if i == 5: if i == 5:
break break
lv, = axarr[0].plot(meas_freq, meas_ratio, label='VSWR', markevery=vswr_marker, markersize=5, marker="o", markerfacecolor="g") lv, = axarr[0].plot(meas_freq, meas_ratio, label='VSWR', markevery=vswr_marker, markersize=4, marker="o", markerfacecolor="r")
lr, = axarr[1].plot(meas_freq, meas_r, label='impedance') lr, = axarr[1].plot(meas_freq, meas_r, label='impedance', markevery=[vswr_marker[0]], markersize=4, marker="o", markerfacecolor="r")
la0, = axarr[2].plot(meas_freq, meas_a0, label='a0') la0, = axarr[2].plot(meas_freq, meas_a0, label='a0')
la1, = axarr[2].plot(meas_freq, meas_a1, label='a1') la1, = axarr[2].plot(meas_freq, meas_a1, label='a1')