From 8a56cbb111bb56d16c03016020479e6556d8a6f2 Mon Sep 17 00:00:00 2001 From: klaute Date: Tue, 20 Sep 2016 20:23:55 +0200 Subject: [PATCH] Plot view added. --- tools/meas.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/tools/meas.py b/tools/meas.py index 938d1b2..ad5d3be 100644 --- a/tools/meas.py +++ b/tools/meas.py @@ -7,6 +7,7 @@ import time import serial import copy import binascii +import matplotlib.pyplot as plt ############################################################################### @@ -154,11 +155,8 @@ def cc_dataReceiverThread(): incoming = [] bytesToRead = ser.inWaiting() if bytesToRead > 0: - #print bytesToRead # TODO incoming = list(ser.read(64)) - #print incoming # TODO - # 2. process the received data for c in incoming: c = int(binascii.hexlify(c), 16) @@ -348,6 +346,8 @@ if __name__ == "__main__": config_read = False + meas_data = [] + cc_init() # parse the commandline arguments @@ -450,6 +450,8 @@ if __name__ == "__main__": print "a0: " + str(a0) print "a1: " + str(a1) + meas_data.append([ freq, a0, a1 ]) + elif e[1] == MSG_TYPE_CONFIG: print "recv: CONFIG" start_freq = e[3][0] << 24 @@ -484,7 +486,36 @@ if __name__ == "__main__": if args.output_file != None: pass # TODO impl if args.show_graph == True: - pass # TODO impl + meas_freq = [] + meas_ratio = [] + meas_r = [] + meas_p = [] + + for m in meas_data: + + meas_freq.append(m[0]) + + if m[1] > m[2]: + meas_ratio.append(m[1] / m[2]) + elif m[1] < m[2]: + meas_ratio.append(m[1] / m[2]) + else: + meas_ratio.append(1) + + # R = meas_data[0] * 5V / 1023 + r = (m[1] * 5 / 1023) + meas_r.append(r) + + # P = meas_data[0] * 5V ^ 2 / r + if r > 0: + meas_p.append((m[1] * 5)**2 / r) + else: + meas_p.append(0) + + plt.plot(meas_freq, meas_ratio) + plt.plot(meas_freq, meas_r) + plt.plot(meas_freq, meas_p) + plt.show() else: print "err: unknown type 0x%02x" % (e[1])