Chnages
This commit is contained in:
BIN
__pycache__/ai_mgmt.cpython-312.pyc
Normal file
BIN
__pycache__/ai_mgmt.cpython-312.pyc
Normal file
Binary file not shown.
47
mipi_test.py
47
mipi_test.py
@@ -13,11 +13,13 @@ import sys
|
||||
import requests
|
||||
import threading
|
||||
from datetime import datetime
|
||||
import ai_mgmt
|
||||
|
||||
# --- Configuration ---
|
||||
URL = "http://192.168.45.8:5000/display"
|
||||
SCOPE_IP = "192.168.45.4"
|
||||
PSU_IP = "192.168.45.3"
|
||||
MGMT_INTERVAL = 60 # seconds between management runs (set to 3600 for hourly)
|
||||
|
||||
# --- Capture settings ---
|
||||
# Pass 1 — signal quality: resolves individual bits at 140 Mbit/s (7.1 ns/bit)
|
||||
@@ -30,7 +32,9 @@ PROTO_POINTS = 500_000 # 500 k pts → 50 MSa/s (enough to see burst structure)
|
||||
|
||||
DISPLAY_SETTLE_S = 1.0 # seconds to wait after display ON before arming scope
|
||||
|
||||
test_running = False # Global flag to control the background thread
|
||||
test_running = False # controls both worker threads
|
||||
resume_event = threading.Event() # cleared to pause test_worker, set to resume
|
||||
capture_done = threading.Event() # set when a full dual_capture (all 4 files) completes
|
||||
|
||||
# --- Instrument Connection ---
|
||||
try:
|
||||
@@ -218,6 +222,7 @@ def dual_capture(iteration):
|
||||
Pass 2 — frame structure (PROTO_SCALE / PROTO_POINTS)
|
||||
Restores the original 5 ns/div timebase when done.
|
||||
"""
|
||||
capture_done.clear()
|
||||
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
print(f"DUAL CAPTURE #{iteration:04d} [{ts}]")
|
||||
|
||||
@@ -240,11 +245,41 @@ def dual_capture(iteration):
|
||||
# ── Restore original timebase ─────────────────────────────────────────
|
||||
_set_timebase(5e-9, 500_000)
|
||||
scope.write(":RUN")
|
||||
capture_done.set()
|
||||
|
||||
|
||||
def mgmt_worker():
|
||||
"""
|
||||
Fires every MGMT_INTERVAL seconds while a test is running:
|
||||
- Pauses test_worker via resume_event
|
||||
- Runs ai_mgmt CSV scan
|
||||
- Resumes test_worker
|
||||
"""
|
||||
while test_running:
|
||||
time.sleep(MGMT_INTERVAL)
|
||||
if not test_running:
|
||||
break
|
||||
|
||||
print("\n[MGMT] WAITING FOR CURRENT CAPTURE TO COMPLETE...")
|
||||
capture_done.wait()
|
||||
print("[MGMT] PAUSING TEST — RUNNING MANAGEMENT TASKS...")
|
||||
resume_event.clear()
|
||||
try:
|
||||
files = ai_mgmt.list_csv_files(ai_mgmt.SERVER, ai_mgmt.SHARE)
|
||||
print(f"[MGMT] FOUND {len(files)} CSV FILE(S) ON SCOPE DRIVE.")
|
||||
for f in files:
|
||||
print(f" {f}")
|
||||
except Exception as e:
|
||||
print(f"[MGMT] ERROR: {e}")
|
||||
finally:
|
||||
resume_event.set()
|
||||
print("[MGMT] RESUMING TEST.\n")
|
||||
|
||||
|
||||
def test_worker():
|
||||
"""
|
||||
Background loop:
|
||||
- Waits if mgmt_worker has paused via resume_event
|
||||
- Turns display ON, waits DISPLAY_SETTLE_S for it to stabilise
|
||||
- Runs dual_capture (signal quality + frame structure)
|
||||
- Turns display OFF for 1 second
|
||||
@@ -254,6 +289,9 @@ def test_worker():
|
||||
count = 1
|
||||
|
||||
while test_running:
|
||||
resume_event.wait() # block here while mgmt_worker is running
|
||||
if not test_running:
|
||||
break
|
||||
requests.put(URL, json={"state": "on"}, timeout=2)
|
||||
time.sleep(DISPLAY_SETTLE_S)
|
||||
dual_capture(count)
|
||||
@@ -300,9 +338,10 @@ def main_menu():
|
||||
elif choice == '5':
|
||||
if not test_running:
|
||||
test_running = True
|
||||
t = threading.Thread(target=test_worker, daemon=True)
|
||||
t.start()
|
||||
print("TEST STARTED.")
|
||||
resume_event.set()
|
||||
threading.Thread(target=test_worker, daemon=True).start()
|
||||
threading.Thread(target=mgmt_worker, daemon=True).start()
|
||||
print(f"TEST STARTED. MANAGEMENT INTERVAL: {MGMT_INTERVAL}s.")
|
||||
else:
|
||||
print("TEST IS ALREADY RUNNING!")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user