Skip to content

Commit

Permalink
Merge pull request #231 from es-ude/230-update-hw-test_webserverpy-to…
Browse files Browse the repository at this point in the history
…-refelct-updated-url

230 update hw test webserverpy to refelct updated url
  • Loading branch information
DavidFederl authored Jul 2, 2024
2 parents 53be023 + fd234ef commit 271b495
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 61 deletions.
4 changes: 1 addition & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 37 additions & 52 deletions bitfile_scripts/HW-Test_Webserver.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,37 @@
import os
from pathlib import Path
from io import BytesIO
from flask import Flask, send_file
from flask import Flask, send_file, request

bytes_per_request = 512 # should be matching with the page size of the flash

app = Flask(__name__)
app: Flask = Flask(__name__)
bin_file_source_dir: Path = Path(__file__).resolve().parent


def print_bytearray(arr: bytes):
print("0x" + " 0x".join("%02X" % b for b in arr))


def read_slice(position: int, filename: str) -> bytes:
def read_slice(position: int, filename: Path, max_length: int = 512) -> bytes:
with open(filename, "rb") as file:
file.seek(position * bytes_per_request, 0)
chunk: bytes = file.read(bytes_per_request)
# print(f"Chunk {position}:")
# print_bytearray(chunk)
file.seek(position * max_length, 0)
chunk: bytes = file.read(max_length)
return chunk


@app.route("/getfast/<position>")
def get_file_fast(position: str):
"""
Using positional arguments as parameter did not work!
"""
buffer = BytesIO()
buffer.write(
read_slice(
int(position), "bitfiles/env5_bitfiles/blink/blink_fast/led_test.bin"
)
)
buffer.seek(0)
return send_file(
buffer,
as_attachment=True,
download_name="bitfile.bin",
mimetype="application/octet-stream",
)
@app.route("/getfast")
def get_file_fast():
chunk_size = request.args.get("chunkMaxSize", type=int)
chunk_number = request.args.get("chunkNumber", type=int)

print(f"chunk_size: {chunk_size}, chunk_number: {chunk_number}")

@app.route("/getslow/<position>")
def get_file_slow(position: str):
"""
Using positional arguments as parameter did not work!
"""
buffer = BytesIO()
buffer.write(
read_slice(
int(position), "bitfiles/env5_bitfiles/blink/blink_slow/led_test.bin"
chunk_number,
bin_file_source_dir.joinpath(
"bitfiles/env5_bitfiles/blink/blink_fast/led_test.bin"
),
chunk_size,
)
)
buffer.seek(0)
Expand All @@ -60,15 +43,19 @@ def get_file_slow(position: str):
)


@app.route("/getecho/<position>")
def get_file_echo(position: str):
"""
Using positional arguments as parameter did not work!
"""
@app.route("/getslow")
def get_file_slow():
chunk_size = request.args.get("chunkMaxSize", type=int)
chunk_number = request.args.get("chunkNumber", type=int)

buffer = BytesIO()
buffer.write(
read_slice(
int(position), "bitfiles/env5_bitfiles/echo_server/env5_top_reconfig.bin"
chunk_number,
bin_file_source_dir.joinpath(
"bitfiles/env5_bitfiles/blink/blink_slow/led_test.bin"
),
chunk_size,
)
)
buffer.seek(0)
Expand All @@ -80,15 +67,19 @@ def get_file_echo(position: str):
)


@app.route("/getconfig/<position>")
def get_bin_file(position: str):
"""
Using positional arguments as parameter did not work!
"""
@app.route("/getecho")
def get_file_echo():
chunk_size = request.args.get("chunkMaxSize", type=int)
chunk_number = request.args.get("chunkNumber", type=int)

buffer = BytesIO()
buffer.write(
read_slice(
int(position), "./../config.bin"
chunk_number,
bin_file_source_dir.joinpath(
"bitfiles/env5_bitfiles/echo_server/env5_top_reconfig.bin"
),
chunk_size,
)
)
buffer.seek(0)
Expand All @@ -100,12 +91,6 @@ def get_bin_file(position: str):
)


@app.route("/length")
def get_bin_file_length():
size = os.path.getsize("./../config.bin")
return str(size)


@app.route("/check")
def check_server_available():
return "AVAILABLE\0"
Expand Down
12 changes: 6 additions & 6 deletions helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ function(create_enV5_executable target)
pico_enable_stdio_uart(${target} 0)
# create map/bin/hex/uf2 file etc.
pico_add_uf2_output(${target})
# copy u2f files after build to out directory
file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_LIST_DIR})
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/${relative_path}/${target}.uf2
${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}/${relative_path}/${target}.uf2)
# # copy u2f files after build to out directory
# file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_LIST_DIR})
# add_custom_command(TARGET ${target} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy
# ${CMAKE_BINARY_DIR}/${relative_path}/${target}.uf2
# ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}-Rev${REVISION}/${relative_path}/${target}.uf2)
endfunction()

function(add_dependency_graph)
Expand Down

0 comments on commit 271b495

Please sign in to comment.