Skip to content

Commit 14ce087

Browse files
committed
FTP upload option during factory calibration
1 parent 5d1a30c commit 14ce087

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/Results/
22
/.idea/
3+
ftp.json
4+

Software/Scripts/FactoryCoefficients/createFactoryCoefficients.py

+27
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from datetime import datetime
1010
import os
1111
import shutil
12+
from ftplib import FTP
1213
#import VNA
1314
#from VNA_Example_LibreVNA import VNA
1415
from VNA_Example_SNA5000A import VNA
@@ -27,9 +28,13 @@ def SCPICommand(ser, cmd: str) -> str:
2728
parser.add_argument('-f', '--flash', help='Flash the firmware file first', metavar="firmware")
2829
parser.add_argument('-l', '--limits', help='Enables limit checking on coefficients with limits from json file', metavar="json_limit_file")
2930
parser.add_argument('-d', '--directory', help='Save measured touchstone files to this path', metavar="touchstone_path")
31+
parser.add_argument('--ftp', help='Save measured touchstone files to a FTP server (requires --directory)', metavar="ftp_json_file")
3032

3133
args = parser.parse_args()
3234

35+
if args.ftp and not args.directory:
36+
raise Exception("ftp option is only valid when directory option is also specified")
37+
3338
if args.flash is not None:
3439
# Check if picotool is available
3540
if subprocess.call(['picotool', 'help'], stdout=subprocess.DEVNULL) != 0:
@@ -385,6 +390,28 @@ def takeMeasurements(portmapping : dict):
385390
# this limit failed
386391
raise Exception("Limit check failed for type "+str(i)+" in measurement "+str(key)+" at frequency "+str(sample[0])+": limit is "+str(limval)+", measured value is "+str(yval))
387392

393+
# Limits are valid, upload to FTP server at this point
394+
if args.ftp:
395+
print("Uploading to FTP server...")
396+
jftp = None
397+
try:
398+
f = open(args.ftp)
399+
jftp = json.load(f)
400+
except Exception as e:
401+
raise Exception("Failed to parse FTP config file: "+str(e))
402+
403+
try:
404+
ftp = FTP(host=jftp["host"], user=jftp["user"], passwd=jftp["password"])
405+
# Open the previously created zip file
406+
zipname = libreCAL_serial + '.zip'
407+
zippath = args.directory + "/" + zipname
408+
zipfile = open(zippath, 'rb')
409+
ftp.storbinary("STOR "+zipname, zipfile)
410+
zipfile.close()
411+
ftp.quit()
412+
except Exception as e:
413+
raise Exception("FTP transfer failed: "+str(e))
414+
388415
# Enable writing of the factory partition
389416
SCPICommand(ser, ":FACT:ENABLEWRITE I_AM_SURE")
390417

0 commit comments

Comments
 (0)