From 8ee934cb70664b5ace9dc77218919c772c5c8d29 Mon Sep 17 00:00:00 2001 From: mahmamdouh Date: Wed, 11 Feb 2026 23:03:59 +0100 Subject: [PATCH] update message --- I2C/components/scd30_driver/scd30.c | 2 +- hil_validation_results.csv | 10 +++--- run_test.py | 48 +++++++++++++++++++++-------- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/I2C/components/scd30_driver/scd30.c b/I2C/components/scd30_driver/scd30.c index 0c046e9..5a12df3 100644 --- a/I2C/components/scd30_driver/scd30.c +++ b/I2C/components/scd30_driver/scd30.c @@ -176,7 +176,7 @@ int scd30_read_data(scd30_handle_t *handle, scd30_data_t *data) { } // 2. Wait for Slave to consult Python - vTaskDelay(pdMS_TO_TICKS(50)); // Give ample time for UART bridge + vTaskDelay(pdMS_TO_TICKS(100)); // Give ample time for UART bridge // 3. Read Data cmd = i2c_cmd_link_create(); diff --git a/hil_validation_results.csv b/hil_validation_results.csv index 60276a3..39c114b 100644 --- a/hil_validation_results.csv +++ b/hil_validation_results.csv @@ -1,6 +1,6 @@ Timestamp,Simulated_CO2,Target_Received_Msg,Status -19:43:59,400.0,"W (4783) SCD30: Command Write Failed, retrying... (0)",CHECK -19:43:59,850.5,"W (4883) SCD30: CRC failed or Read error, retrying... (1)",CHECK -19:44:02,1200.0,"CO2: 400.00 ppm, Temp: 24.00 °C, Humidity: 50.00 %",CHECK -19:44:03,2500.0,"W (8393) SCD30: CRC failed or Read error, retrying... (0)",CHECK -19:44:06,5000.0,"CO2: 1200.00 ppm, Temp: 24.00 °C, Humidity: 50.00 %",CHECK +23:02:18,400.0,"CO2: 400.00 ppm, Temp: 24.00 °C, Humidity: 50.00 %",PASS +23:02:21,850.5,"CO2: 850.50 ppm, Temp: 24.00 °C, Humidity: 50.00 %",PASS +23:02:23,1200.0,"CO2: 1200.00 ppm, Temp: 24.00 °C, Humidity: 50.00 %",PASS +23:02:25,2500.0,"CO2: 2500.00 ppm, Temp: 24.00 °C, Humidity: 50.00 %",PASS +23:02:27,5000.0,"CO2: 5000.00 ppm, Temp: 24.00 °C, Humidity: 50.00 %",PASS diff --git a/run_test.py b/run_test.py index 0f4f10c..dc01850 100644 --- a/run_test.py +++ b/run_test.py @@ -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"