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.
53
mipi_test.py
53
mipi_test.py
@@ -13,11 +13,13 @@ import sys
|
|||||||
import requests
|
import requests
|
||||||
import threading
|
import threading
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import ai_mgmt
|
||||||
|
|
||||||
# --- Configuration ---
|
# --- Configuration ---
|
||||||
URL = "http://192.168.45.8:5000/display"
|
URL = "http://192.168.45.8:5000/display"
|
||||||
SCOPE_IP = "192.168.45.4"
|
SCOPE_IP = "192.168.45.4"
|
||||||
PSU_IP = "192.168.45.3"
|
PSU_IP = "192.168.45.3"
|
||||||
|
MGMT_INTERVAL = 60 # seconds between management runs (set to 3600 for hourly)
|
||||||
|
|
||||||
# --- Capture settings ---
|
# --- Capture settings ---
|
||||||
# Pass 1 — signal quality: resolves individual bits at 140 Mbit/s (7.1 ns/bit)
|
# 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
|
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 ---
|
# --- Instrument Connection ---
|
||||||
try:
|
try:
|
||||||
@@ -218,6 +222,7 @@ def dual_capture(iteration):
|
|||||||
Pass 2 — frame structure (PROTO_SCALE / PROTO_POINTS)
|
Pass 2 — frame structure (PROTO_SCALE / PROTO_POINTS)
|
||||||
Restores the original 5 ns/div timebase when done.
|
Restores the original 5 ns/div timebase when done.
|
||||||
"""
|
"""
|
||||||
|
capture_done.clear()
|
||||||
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
print(f"DUAL CAPTURE #{iteration:04d} [{ts}]")
|
print(f"DUAL CAPTURE #{iteration:04d} [{ts}]")
|
||||||
|
|
||||||
@@ -240,11 +245,41 @@ def dual_capture(iteration):
|
|||||||
# ── Restore original timebase ─────────────────────────────────────────
|
# ── Restore original timebase ─────────────────────────────────────────
|
||||||
_set_timebase(5e-9, 500_000)
|
_set_timebase(5e-9, 500_000)
|
||||||
scope.write(":RUN")
|
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():
|
def test_worker():
|
||||||
"""
|
"""
|
||||||
Background loop:
|
Background loop:
|
||||||
|
- Waits if mgmt_worker has paused via resume_event
|
||||||
- Turns display ON, waits DISPLAY_SETTLE_S for it to stabilise
|
- Turns display ON, waits DISPLAY_SETTLE_S for it to stabilise
|
||||||
- Runs dual_capture (signal quality + frame structure)
|
- Runs dual_capture (signal quality + frame structure)
|
||||||
- Turns display OFF for 1 second
|
- Turns display OFF for 1 second
|
||||||
@@ -254,6 +289,9 @@ def test_worker():
|
|||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
while test_running:
|
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)
|
requests.put(URL, json={"state": "on"}, timeout=2)
|
||||||
time.sleep(DISPLAY_SETTLE_S)
|
time.sleep(DISPLAY_SETTLE_S)
|
||||||
dual_capture(count)
|
dual_capture(count)
|
||||||
@@ -300,9 +338,10 @@ def main_menu():
|
|||||||
elif choice == '5':
|
elif choice == '5':
|
||||||
if not test_running:
|
if not test_running:
|
||||||
test_running = True
|
test_running = True
|
||||||
t = threading.Thread(target=test_worker, daemon=True)
|
resume_event.set()
|
||||||
t.start()
|
threading.Thread(target=test_worker, daemon=True).start()
|
||||||
print("TEST STARTED.")
|
threading.Thread(target=mgmt_worker, daemon=True).start()
|
||||||
|
print(f"TEST STARTED. MANAGEMENT INTERVAL: {MGMT_INTERVAL}s.")
|
||||||
else:
|
else:
|
||||||
print("TEST IS ALREADY RUNNING!")
|
print("TEST IS ALREADY RUNNING!")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user