rp_get_sayma_data: Prettify human-readable output

This commit is contained in:
Harry Ho 2021-10-06 14:37:53 +08:00
parent 8b397c0728
commit 1688ceecde
1 changed files with 12 additions and 0 deletions

View File

@ -114,13 +114,25 @@ def main():
print("Succesfully written y2 raw data from RP {}.".format(rp.name)) print("Succesfully written y2 raw data from RP {}.".format(rp.name))
if args.txt: if args.txt:
header = '''\
RedPitaya Oscilloscope Reading
RP Hostname: {} ({})
RP Channel: Input {} ({})
Date & Time: {}
------
'''
y1 = [float(i) for i in y1_raw.split(',')] y1 = [float(i) for i in y1_raw.split(',')]
y2 = [float(i) for i in y2_raw.split(',')] y2 = [float(i) for i in y2_raw.split(',')]
with open(os.path.join(args.dir, 'rp_{}_y1_raw.txt'.format(rp.name)), 'w') as f: with open(os.path.join(args.dir, 'rp_{}_y1_raw.txt'.format(rp.name)), 'w') as f:
f.write(''.join([l.lstrip(' ') for l in header.format(
RP_IP_ADDRS[rp.name], rp.name, 1, ch1_gain.upper(), now_iso).splitlines(True)]))
for i in y1: for i in y1:
f.write(str(i) + '\n') f.write(str(i) + '\n')
print("Succesfully written y1 human-readable data from {}.".format(rp.name)) print("Succesfully written y1 human-readable data from {}.".format(rp.name))
with open(os.path.join(args.dir, 'rp_{}_y2_raw.txt'.format(rp.name)), 'w') as f: with open(os.path.join(args.dir, 'rp_{}_y2_raw.txt'.format(rp.name)), 'w') as f:
f.write(''.join([l.lstrip(' ') for l in header.format(
RP_IP_ADDRS[rp.name], rp.name, 2, ch2_gain.upper(), now_iso).splitlines(True)]))
for i in y2: for i in y2:
f.write(str(i) + '\n') f.write(str(i) + '\n')
print("Succesfully written y2 human-readable data from {}.".format(rp.name)) print("Succesfully written y2 human-readable data from {}.".format(rp.name))