Update 'REST/I2C_Function.py'

main
Orell-Pieter Schwarzbach 2023-06-09 15:30:11 +02:00
parent 33a7e1bd7d
commit 9cf70dc3a5
1 changed files with 169 additions and 161 deletions

View File

@ -16,6 +16,7 @@ def read_data(num_numbers, bits_per_number):
# Define the filename
filename = f'{num_numbers}numbers_{bits_per_number}bits.bin'
try:
with open(filename, 'wb') as file:
bytes_received = 0
while bytes_received < total_bytes:
@ -27,6 +28,9 @@ def read_data(num_numbers, bits_per_number):
return filename
except IOError as e:
return False
def convert_to_hex(binary_filename, num_numbers, bits_per_number):
with open(binary_filename, 'r') as f:
# Read the contents of the file
@ -110,6 +114,8 @@ def analyze_data(num_numbers, bits_per_number, startup):
if startup:
filename = read_data(10, 80000)
if not filename:
return False
binary_filename = convert_to_binary(filename, 10, 80000)
perform_startup_tests(binary_filename)
perform_tot_online_tests(binary_filename)
@ -118,6 +124,8 @@ def analyze_data(num_numbers, bits_per_number, startup):
return True
else:
filename = read_data(10, 20000)
if not filename:
return False
binary_filename = convert_to_binary(filename, 10, 20000)
result = perform_tot_online_tests(binary_filename)
os.unlink(filename)
@ -150,7 +158,7 @@ def analyze_data(num_numbers, bits_per_number, startup):
os.unlink(filename)
os.unlink(binary_filename)
os.unlink(hex_filename)
return False
return 400
# Teste den Code
#result = analyze_data(8, 8, startup=True)