Refactor packetizer and depacketizer components; update test scripts and images

- Modified the graph structure in pak_depak.bda to correct node and edge connections.
- Adjusted testbench for packetizer (tb_packetizer.vhd) to fix data values and packet sizes.
- Enhanced packetizer.vhd to manage footer sending based on last signal.
- Removed obsolete executable file LAB2-Test_new.exe.
- Updated Python test script (test.py) to include new test case for depack > pack functionality and improved image handling.
- Altered Vivado project files to reflect changes in simulation and synthesis settings.
- Deleted unnecessary test executable and added new image for depack > pack testing.
This commit is contained in:
2025-04-24 17:23:56 +02:00
parent a5b23940de
commit 5cabb20fdd
10 changed files with 496 additions and 267 deletions

View File

@@ -1,4 +1,4 @@
""" import sys
import sys
import subprocess
def install_and_import(package, package_name=None):
@@ -16,7 +16,7 @@ install_and_import("serial", "pyserial")
install_and_import("PIL", "pillow")
install_and_import("tqdm")
install_and_import("numpy")
install_and_import("scipy") """
install_and_import("scipy")
from serial import Serial
import serial.tools.list_ports
@@ -30,6 +30,7 @@ IMAGE_UF = r'C:\DESD\LAB2\test\test_uf.png'
IMAGE_NAME3 = r'C:\DESD\LAB2\test\test3.png'
IMAGE_NAME2 = r'C:\DESD\LAB2\test\test2.png'
IMAGE_NAME1 = r'C:\DESD\LAB2\test\test1.png'
IMAGE_DEPACK_PACK = r'C:\DESD\LAB2\test\test_depack_pack.png'
BASYS3_PID = 0x6010
BASYS3_VID = 0x0403
@@ -45,17 +46,22 @@ for port in serial.tools.list_ports.comports():
if not dev:
raise RuntimeError("Basys 3 Not Found!")
test_n = int(input("Insert test number (1, 2, 3, overflow (4) or underflow (5)): ").strip())
test_n = int(input("Insert test number (1, 2, 3, 4 (overflow), 5 (underflow) or 6 (depack > pack only)): ").strip())
if test_n not in [1, 2, 3, 4, 5]:
raise RuntimeError("Test number must be 1, 2, 3, 4 (overflow) or 5 (underflow)")
if test_n not in [1, 2, 3, 4, 5, 6]:
raise RuntimeError("Test number must be 1, 2, 3, 4 (overflow), 5 (underflow) or 6 (depack > pack only)")
dev = Serial(dev, 115200)
img = Image.open(IMAGE_NAME1 if test_n == 1 else IMAGE_NAME2 if test_n == 2 else IMAGE_NAME3 if test_n == 3 else IMAGE_UF if test_n == 5 else IMAGE_OF)
img = Image.open(IMAGE_NAME1 if test_n == 1 else IMAGE_NAME2 if test_n == 2 else IMAGE_NAME3 if test_n == 3 else IMAGE_OF if test_n == 4 else IMAGE_UF if test_n == 5 else IMAGE_DEPACK_PACK)
if img.mode != "RGB":
img = img.convert("RGB")
if test_n == 4:
print("Check for overflow (LED U16)")
elif test_n == 5:
print("Check for underflow (LED U19)")
IMG_WIDTH, IMG_HEIGHT = img.size # Get dimensions from the image
mat = np.asarray(img, dtype=np.uint8)
@@ -64,39 +70,59 @@ mat = mat[:, :, :3]
if mat.max() > 127:
mat = mat // 2
buff = mat.tobytes()
res = b''
mat_gray = np.sum(mat, axis=2) // 3
if test_n == 6:
print("Check for depack > pack")
sim_img = convolve2d(mat_gray, [[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]], mode="same")
total_bytes = IMG_HEIGHT * IMG_WIDTH * 3
for idx in tqdm(range(total_bytes)):
i = idx // (IMG_WIDTH * 3)
j = (idx // 3) % IMG_WIDTH
k = idx % 3
sim_img[sim_img < 0] = 0
sim_img[sim_img > 127] = 127
sim_img = sim_img.astype(np.uint8)
dev.write(b'\xff')
dev.write(bytes([mat[i, j, k]]))
dev.write(b'\xf1')
dev.flush()
dev.write(b'\xff')
for i in tqdm(range(IMG_HEIGHT)):
dev.write(buff[i * IMG_WIDTH * 3:(i + 1) * IMG_WIDTH * 3])
# Read 3 bytes: header, data, footer
resp = dev.read(3)
res += resp[1:2] # Only keep the data byte
dev.write(b'\xf1')
dev.flush()
res_img = np.frombuffer(res, dtype=np.uint8)
res_img = res_img.reshape((IMG_HEIGHT, IMG_WIDTH, 3))
if test_n == 4:
print("Check for overflow (LED U16)")
exit()
elif test_n == 5:
print("Check for underflow (LED U19)")
exit()
else:
buff = mat.tobytes()
res = dev.read(IMG_HEIGHT * IMG_WIDTH + 2)
mat_gray = np.sum(mat, axis=2) // 3
res_img = np.frombuffer(res[1:-1], dtype=np.uint8)
res_img = res_img.reshape((IMG_HEIGHT, IMG_WIDTH))
sim_img = convolve2d(mat_gray, [[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]], mode="same")
sim_img[sim_img < 0] = 0
sim_img[sim_img > 127] = 127
sim_img = sim_img.astype(np.uint8)
dev.write(b'\xff')
for i in tqdm(range(IMG_HEIGHT)):
dev.write(buff[i * IMG_WIDTH * 3:(i + 1) * IMG_WIDTH * 3])
dev.write(b'\xf1')
dev.flush()
if test_n == 4 or test_n == 5:
exit()
else:
res = dev.read(IMG_HEIGHT * IMG_WIDTH + 2)
res_img = np.frombuffer(res[1:-1], dtype=np.uint8)
res_img = res_img.reshape((IMG_HEIGHT, IMG_WIDTH))
if (test_n == 6 and (res_img == mat).all()) or (res_img == sim_img).all():
print("Image Match!")
else:
print("Image Mismatch!")
im = Image.fromarray(res_img)
im.show()
if np.all(res_img != sim_img):
print("Image Mismatch!")
dev.close()