|
4 | 4 | import time |
5 | 5 | from werkzeug.utils import secure_filename |
6 | 6 | import os |
| 7 | +import subprocess |
| 8 | +import mmap |
| 9 | + |
7 | 10 |
|
8 | 11 | job_status = {"running": False, "result": "", "thread": None} |
9 | 12 |
|
|
13 | 16 | #port = '/dev/ttyUSB2' |
14 | 17 | baudrate = '921600' |
15 | 18 | #baudrate = '115200' |
16 | | -exe_path = "/usr/bin/tsi/v0.1.1.tsv31_06_06_2025/bin/" |
| 19 | +#exe_path = "/usr/bin/tsi/v0.1.1.tsv31_06_06_2025/bin/" |
| 20 | +exe_path = "/usr/bin/tsi/v0.1.1*/bin/" |
17 | 21 |
|
18 | 22 | DEFAULT_REPEAT_PENALTY = 1.5 |
19 | 23 | DEFAULT_BATCH_SIZE = 1024 |
@@ -106,6 +110,50 @@ def upload_serial_command(): |
106 | 110 | # except subprocess.CalledProcessError as e: |
107 | 111 | # return f"Error executing script: {e.stderr}", 500 |
108 | 112 |
|
| 113 | +@app.route('/uploadtofpga-file', methods=['GET', 'POST']) |
| 114 | +def uploadtofpga_file(): |
| 115 | + setupprints = "Before:Copy2fpga-setup.sh" |
| 116 | + print(setupprints) |
| 117 | + |
| 118 | + if request.method == 'POST': |
| 119 | + # Check if a file was submitted |
| 120 | + if 'file' not in request.files: |
| 121 | + return "No file part" |
| 122 | + file = request.files['file'] |
| 123 | + |
| 124 | + # Check if the file is empty |
| 125 | + if file.filename == '': |
| 126 | + return "No file selected" |
| 127 | + |
| 128 | + # Save the file if it exists |
| 129 | + if file: |
| 130 | + filename = secure_filename(file.filename) |
| 131 | + process = subprocess.Popen(["./copy2fpga-x86.sh", filename], text=True) |
| 132 | + copy2fpgax86prints = "Starting copy2fpga-x86 sending file..." |
| 133 | + print (copy2fpgax86prints) |
| 134 | + file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) |
| 135 | + |
| 136 | + script_path = "./recvFromHost " |
| 137 | + command = f"cd {exe_path}; {script_path} {filename}" |
| 138 | + def scriptRecvFromHost(): |
| 139 | + try: |
| 140 | + result = subprocess.run(['python3', 'serial_script.py', port, baudrate, command], capture_output=True, text=True, check=True) |
| 141 | + job_status["result"] = result.stdout |
| 142 | + print("FPGA Target ready to receive file: recvFromHost started..\n") |
| 143 | + print(result.stdout) |
| 144 | + recv_output = result.stdout |
| 145 | + except subprocess.CalledProcessError as e: |
| 146 | + job_status["result"] = f"Error: {e.stderr}" |
| 147 | + finally: |
| 148 | + job_status["running"] = False |
| 149 | + thread = threading.Thread(target=scriptRecvFromHost) |
| 150 | + job_status = {"running": True, "result": "", "thread": thread} |
| 151 | + thread.start() |
| 152 | + |
| 153 | + stdout, stderr = process.communicate() |
| 154 | + return render_template('uploadtofpga.html', apple = process, recvoutput=f"On FPGA Target, recvFromHost completed ; transf ered file:{filename} received") |
| 155 | + return render_template('upload.html') # Display the upload form |
| 156 | + |
109 | 157 | @app.route('/upload-file', methods=['GET', 'POST']) |
110 | 158 | def upload_file(): |
111 | 159 | if request.method == 'POST': |
|
0 commit comments