update message

This commit is contained in:
2026-02-11 23:03:59 +01:00
parent fbae73828f
commit 8ee934cb70
3 changed files with 42 additions and 18 deletions

View File

@@ -3,7 +3,7 @@ import time
from hil_lib import SCD30_HIL_Lib
# Device paths from your environment
Device = 'HIL'
Device = 'PC'
if Device == 'PC':
EMULATOR = 'COM11'#'/dev/i2c_emulator'
@@ -30,23 +30,47 @@ with open(LOG_FILE, mode='w', newline='') as f:
for co2 in test_points:
print(f"\n[PHASE] Setting Simulated CO2 to {co2} ppm")
# 1. Feed the bridge until the Target performs a successful Read
# We loop briefly to wait for the Target's polling interval
# Flush buffers to ensure we don't read old data
hil.emulator.reset_input_buffer()
hil.target.reset_input_buffer()
# 1. Feed the bridge AND listen for Target output simultaneously
# The Master might retry multiple times, so we must keep the bridge alive
# until we see a final result from the Target.
timeout = time.time() + 10
data_served = False
target_msg = ""
while time.time() < timeout:
# Service the Bridge
if hil.process_bridge(co2, 24.0, 50.0):
data_served = True
break
#time.sleep(4)
if not data_served:
print("Error: Target didn't request data within 10s.")
# Check for Target Output
if hil.target.in_waiting:
line = hil.get_target_reading()
if line:
# We are looking for either a successful reading or a final failure message
# Success example: "CO2: 400.00 ppm..."
# Warning example: "W (123) SCD30: CRC failed..." (We might want to keep going if it's just a warning)
# Error example: "E (123) SCD30: ..."
# Ideally, we wait for the formatted output
if "CO2:" in line or "Read data failed" in line:
target_msg = line
break
else:
# It might be a warning retry log, let's capture it but keep going
# If we overwrite target_msg, we might miss the final success
# But for debugging, let's print it
print(f"[LOG] {line}")
if not target_msg:
if not data_served:
print("Error: Target didn't request data within 10s.")
else:
print("Error: Target requested data but yielded no final result.")
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()
# 3. Simple Validation
status = "PASS" if str(int(co2)) in target_msg else "CHECK"