Update ports
This commit is contained in:
74
run_test.py
74
run_test.py
@@ -1,48 +1,56 @@
|
||||
import csv
|
||||
import time
|
||||
from hil_lib import HILController
|
||||
from hil_lib import SCD30_HIL_Lib
|
||||
|
||||
# --- SET YOUR PORTS HERE ---
|
||||
EMULATOR_PORT = 'COM4' # The Bridge
|
||||
TARGET_PORT = 'COM5' # The App
|
||||
FILENAME = 'hil_test_results.csv'
|
||||
# Device paths from your environment
|
||||
EMULATOR = '/dev/i2c_emulator'
|
||||
TARGET = '/dev/esp_sensor_test'
|
||||
LOG_FILE = 'hil_validation_results.csv'
|
||||
|
||||
hil = HILController(EMULATOR_PORT, TARGET_PORT)
|
||||
# Initialize HIL
|
||||
hil = SCD30_HIL_Lib(EMULATOR, TARGET)
|
||||
|
||||
print(f"Starting HIL Test... Saving to {FILENAME}")
|
||||
print(f"--- SCD30 HIL Test Started ---")
|
||||
print(f"Logging to: {LOG_FILE}")
|
||||
|
||||
with open(FILENAME, mode='w', newline='') as file:
|
||||
writer = csv.writer(file)
|
||||
writer.writerow(["Simulated_CO2", "Target_Read_Output", "Timestamp"])
|
||||
with open(LOG_FILE, mode='w', newline='') as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(["Timestamp", "Simulated_CO2", "Target_Received_Msg", "Status"])
|
||||
|
||||
# Test cases: varying CO2 levels
|
||||
test_points = [400.0, 850.5, 1200.0, 2500.0, 5000.0]
|
||||
|
||||
try:
|
||||
# Test values to cycle through
|
||||
test_values = [400.0, 600.5, 850.0, 1200.0, 2500.0]
|
||||
|
||||
for val in test_values:
|
||||
print(f"\nTesting CO2: {val} ppm")
|
||||
for co2 in test_points:
|
||||
print(f"\n[PHASE] Setting Simulated CO2 to {co2} ppm")
|
||||
|
||||
# 1. Put data on the bus (Wait for emulator to request it)
|
||||
start_time = time.time()
|
||||
success = False
|
||||
while time.time() - start_tick < 5: # 5 second timeout per sample
|
||||
if hil.set_emulator_data(co2=val, temp=25.0, hum=50.0):
|
||||
success = True
|
||||
# 1. Feed the bridge until the Target performs a successful Read
|
||||
# We loop briefly to wait for the Target's polling interval
|
||||
timeout = time.time() + 10
|
||||
data_served = False
|
||||
while time.time() < timeout:
|
||||
if hil.process_bridge(co2, 24.0, 50.0):
|
||||
data_served = True
|
||||
break
|
||||
|
||||
# 2. Read what the Target ESP32 saw on its Serial Monitor
|
||||
time.sleep(1) # Give the Target a moment to process and print
|
||||
target_data = hil.read_target_output()
|
||||
if not data_served:
|
||||
print("Error: Target didn't request data within 10s.")
|
||||
continue
|
||||
|
||||
# 2. Capture what the Target actually saw
|
||||
# Wait for Target to print the result to Serial
|
||||
time.sleep(0.5)
|
||||
target_msg = hil.get_target_reading()
|
||||
|
||||
if target_data:
|
||||
print(f"Target Received: {target_data}")
|
||||
# 3. Store in CSV
|
||||
writer.writerow([val, target_data, time.ctime()])
|
||||
file.flush() # Ensure data is written to disk
|
||||
else:
|
||||
print("Warning: Target did not report data in time.")
|
||||
# 3. Simple Validation
|
||||
status = "PASS" if str(int(co2)) in target_msg else "CHECK"
|
||||
|
||||
print(f"[RESULT] Target Output: {target_msg}")
|
||||
writer.writerow([time.strftime("%H:%M:%S"), co2, target_msg, status])
|
||||
f.flush()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("Test stopped by user.")
|
||||
print("\nTest Aborted.")
|
||||
finally:
|
||||
hil.close()
|
||||
hil.close()
|
||||
print("--- HIL Terminated ---")
|
||||
Reference in New Issue
Block a user