Browse Source

Script output modified to get it much more userfriendly.

klaute 2 years ago
parent
commit
d470dd9d91
1 changed files with 42 additions and 18 deletions
  1. 42
    18
      tools/meas.py

+ 42
- 18
tools/meas.py View File

@@ -8,7 +8,7 @@ import serial
8 8
 import copy
9 9
 import binascii
10 10
 import matplotlib.pyplot as plt
11
-import math
11
+import sys
12 12
 import operator
13 13
 
14 14
 ###############################################################################
@@ -352,6 +352,23 @@ def user_friendly_freq(f):
352 352
 
353 353
 ###############################################################################
354 354
 
355
+def gen_progress_bar(n, sf, ef, fs):
356
+  steps = 1 + ((end_freq - start_freq) / step_freq)
357
+  m = 40.0 / steps
358
+  ret = "[ "
359
+
360
+  for i in range(0, int(m * (steps - n))):
361
+    ret += "#"
362
+
363
+  for i in range(0, int(m * n)):
364
+    ret += " "
365
+
366
+  ret += " ] %0.2f %% " % ( (100.0 * (steps - n)/ steps) )
367
+
368
+  return ret
369
+
370
+###############################################################################
371
+
355 372
 if __name__ == "__main__":
356 373
 
357 374
   start_freq = 0
@@ -374,6 +391,8 @@ if __name__ == "__main__":
374 391
   if args.device != None:
375 392
     device = args.device
376 393
 
394
+  print "SWR meter measurement software v0.1 by Kai Lauterbach (me@klaute.de)\n---\n"
395
+
377 396
   openSerialDevice(device)
378 397
 
379 398
   # 2. start thread to poll cc_dataReceiverThread()
@@ -388,7 +407,7 @@ if __name__ == "__main__":
388 407
   #  dataSend = dataSend + 1
389 408
 
390 409
   if args.start_freq != None:
391
-    print "sent: SET_START_FREQ"
410
+    print "Set start frequency to: " + user_friendly_freq(args.start_freq)
392 411
     sendSerialData([CC_CMD_SET_START_FREQ,
393 412
                     (args.start_freq & 0xff000000) >> 24,
394 413
                     (args.start_freq & 0x00ff0000) >> 16,
@@ -397,7 +416,7 @@ if __name__ == "__main__":
397 416
     dataSend = dataSend + 1
398 417
 
399 418
   if args.end_freq != None:
400
-    print "sent: SET_END_FREQ"
419
+    print "Set the end frequency to: " + user_friendly_freq(args.end_freq)
401 420
     sendSerialData([CC_CMD_SET_END_FREQ,
402 421
                     (args.end_freq & 0xff000000) >> 24,
403 422
                     (args.end_freq & 0x00ff0000) >> 16,
@@ -406,7 +425,7 @@ if __name__ == "__main__":
406 425
     dataSend = dataSend + 1
407 426
 
408 427
   if args.step_freq != None:
409
-    print "sent: SET_FREQ_STEP"
428
+    print "Set the frequency step size to: " + user_friendly_freq(args.step_freq)
410 429
     sendSerialData([CC_CMD_SET_FREQ_STEP,
411 430
                     (args.step_freq & 0xff000000) >> 24,
412 431
                     (args.step_freq & 0x00ff0000) >> 16,
@@ -415,20 +434,20 @@ if __name__ == "__main__":
415 434
     dataSend = dataSend + 1
416 435
 
417 436
   if args.intervall != None:
418
-    print "sent: SET_INTERVALL"
437
+    print "Set the time intervall to %d milliseconds" % (args.intervall)
419 438
     sendSerialData([CC_CMD_SET_INTERVALL,
420 439
                     (args.intervall & 0x0000ff00) >>  8,
421 440
                     (args.intervall & 0x000000ff)])
422 441
     dataSend = dataSend + 1
423 442
 
424 443
   if args.drive_str != None:
425
-    print "sent: SET_DRIVE_STRENGTH"
444
+    print "Set the output drive strength to %d mA" % ((args.drive_str + 1) * 2)
426 445
     sendSerialData([CC_CMD_SET_DRIVE_STRENGTH,
427 446
                     args.drive_str])
428 447
     dataSend = dataSend + 1
429 448
 
430 449
   if args.start_meas == True:
431
-    print "sent: START_MEASUREMENT"
450
+    print "\nStarting the measurement process..."
432 451
     sendSerialData([CC_CMD_START_MEASUREMENT])
433 452
     dataSend = dataSend + 1
434 453
 
@@ -445,13 +464,14 @@ if __name__ == "__main__":
445 464
 
446 465
         # process it and set the data to read
447 466
         if e[1] == MSG_TYPE_ANSWER_OK:
448
-          print "recv: OK"
467
+          #print "recv: OK"
468
+          pass
449 469
 
450 470
         elif e[1] == MSG_TYPE_ANSWER_NOK:
451 471
           print "recv: NOT OK"
452 472
 
453 473
         elif e[1] == MSG_TYPE_MEAS_FREQ_INFO:
454
-          print "recv: FREQ INFO"
474
+          #print "recv: FREQ INFO"
455 475
           freq  = e[3][0] << 24
456 476
           freq += e[3][1] << 16
457 477
           freq += e[3][2] <<  8
@@ -460,14 +480,15 @@ if __name__ == "__main__":
460 480
           a0   += e[3][5]
461 481
           a1    = e[3][6] << 8
462 482
           a1   += e[3][7]
463
-          print "freq: " + user_friendly_freq(freq)
464
-          print "a0: " + str(a0)
465
-          print "a1: " + str(a1)
466
-
483
+          #print "freq: " + user_friendly_freq(freq)
484
+          #print "a0: " + str(a0)
485
+          #print "a1: " + str(a1)
486
+          sys.stdout.write("\r" + gen_progress_bar(dataSend, start_freq, end_freq, step_freq))
467 487
           meas_data.append([ freq, a0, a1 ])
468 488
 
469 489
         elif e[1] == MSG_TYPE_CONFIG:
470
-          print "recv: CONFIG"
490
+          #print "recv: CONFIG"
491
+          print "\nConfiguration used for measurement:"
471 492
           start_freq  = e[3][0] << 24
472 493
           start_freq += e[3][1] << 16
473 494
           start_freq += e[3][2] <<  8
@@ -489,13 +510,16 @@ if __name__ == "__main__":
489 510
           print "step_freq  = " + user_friendly_freq(step_freq)
490 511
           print "intervall  = " + str(intervall) + " ms"
491 512
           print "drive_str  = " + str((drive_str + 1) * 2) + " mA"
513
+          print ""
492 514
 
493 515
           if args.start_meas == True and config_read == False:
494 516
             dataSend = dataSend + 1 + ((end_freq - start_freq) / step_freq)
495 517
             config_read = True
496 518
 
497 519
         elif e[1] == MSG_TYPE_MEAS_END_INFO:
498
-          print "recv: END INFO"
520
+          #print "recv: END INFO"
521
+          sys.stdout.write("\r100.00 % done                                       \n")
522
+          print ""
499 523
 
500 524
           meas_freq = []
501 525
           meas_ratio = []
@@ -552,7 +576,7 @@ if __name__ == "__main__":
552 576
             FILE.close()
553 577
             print "Output file " + args.output_file + " written."
554 578
 
555
-          print "First minimum VSWR " + str(min_vswr[0]) + " found at freqency " + user_friendly_freq(min_vswr[1])
579
+          print "First minimum VSWR %0.6f found at freqency %s" % (min_vswr[0], user_friendly_freq(min_vswr[1]))
556 580
 
557 581
           #####
558 582
           if args.show_graph == True:
@@ -574,8 +598,8 @@ if __name__ == "__main__":
574 598
               if i == 5:
575 599
                 break
576 600
 
577
-            lv, = axarr[0].plot(meas_freq, meas_ratio, label='VSWR', markevery=vswr_marker, markersize=5, marker="o", markerfacecolor="g")
578
-            lr, = axarr[1].plot(meas_freq, meas_r, label='impedance')
601
+            lv, = axarr[0].plot(meas_freq, meas_ratio, label='VSWR', markevery=vswr_marker, markersize=4, marker="o", markerfacecolor="r")
602
+            lr, = axarr[1].plot(meas_freq, meas_r, label='impedance', markevery=[vswr_marker[0]], markersize=4, marker="o", markerfacecolor="r")
579 603
             la0, = axarr[2].plot(meas_freq, meas_a0, label='a0')
580 604
             la1, = axarr[2].plot(meas_freq, meas_a1, label='a1')
581 605