Skip to content

Instantly share code, notes, and snippets.

@yoojaehong92
Created December 27, 2025 01:11
Show Gist options
  • Select an option

  • Save yoojaehong92/18380bb392e1869ebb6bdaa91a720bec to your computer and use it in GitHub Desktop.

Select an option

Save yoojaehong92/18380bb392e1869ebb6bdaa91a720bec to your computer and use it in GitHub Desktop.
1) 폴더 구조 + FastAPI 라우트 설계 (MVP)
폴더 구조(최소)
코드 복사
mport-scope-dashboard/
app/
main.py # FastAPI 엔트리
config.py # 스코프 IP/포트 등 설정
drivers/
base.py # 공통 인터페이스(어댑터)
scpi_socket.py # TCP SCPI 기본 드라이버
keysight.py # (옵션) 벤더별 캡처/명령 차이 흡수
tektronix.py # (옵션)
services/
capture_service.py # 캡처 + 메타 저장
bus_service.py # CSV 로드/파싱
session_service.py # 세션 저장/불러오기
timebase.py # global cursor/time align
models/
schemas.py # Pydantic request/response
static/
index.html
app.js
styles.css
data/
sessions/
2025-12-26_230501/
scopeA.png
scopeA.json
scopeB.png
scopeB.json
bus.csv
bus.json
session.json
requirements.txt
핵심 API 라우트(순서대로 구현)
(1) 연결/상태
POST /api/scope/connect
body: { "scope": "A"|"B", "ip": "...", "port": 5025, "vendor": "generic|keysight|tek|lecroy" }
GET /api/scope/status
→ A/B 연결상태, 최근 캡처 시각, time/div, pos
(2) 캡처
POST /api/capture
body: { "target": "A"|"B"|"AB" }
→ PNG 저장 + 메타(JSON) 저장 + 세션 갱신
GET /api/capture/latest?scope=A
→ 최신 캡처 파일 경로(또는 base64/바이너리)
(3) 디지털 버스 로드
POST /api/bus/load (multipart file upload)
→ time,value CSV 업로드/파싱 → downsample 생성 → 저장
GET /api/bus/data
query: t_min,t_max,decimation → 그래프용 구간 데이터 반환
(4) 세션
POST /api/session/new
GET /api/session/current
POST /api/session/save
POST /api/session/load
(5) Global cursor
POST /api/cursor
body: { "t": 123.456789 }
→ 현재 커서 값 저장(프론트가 3개 뷰 동기 렌더)
2) SCPI “캡처 버튼” 구현 템플릿 (드라이버 구조)
드라이버 공통 인터페이스(개념)
get_timebase() → time/div, position, (가능하면) trigger 정보
capture_screenshot_png() → PNG bytes 반환
우선순위(단순성 기준)
TCP 소켓 SCPI (port 5025가 흔함)
안되면 pyvisa
현실 팁(삽질 방지)
스크린샷은 벤더마다 명령이 다르니까
drivers/base.py는 공통
drivers/keysight.py, drivers/tektronix.py에서 캡처 명령만 override
time/div, pos는 대체로 표준 비슷하지만 그래도 벤더 차이 대비
캡처 시 “반드시 같이 저장할 메타”
scopeA.json 예시
코드 복사
Json
{
"captured_at": "2025-12-26T23:05:01+09:00",
"ip": "10.0.0.21",
"vendor": "keysight",
"time_scale_s_per_div": 2e-11,
"time_position_s": 1.2e-6,
"trigger": { "source": "CH1", "slope": "RISE", "level_v": 0.2 }
}
이 메타가 있어야 “같은 시간축으로 비교했다”가 성립함.
3) 9:16 UI(세로) + Global cursor 동기 로직
화면 레이아웃(위→아래)
Top bar(세션/저장/로드/캡처)
Scope A 카드(이미지 + 메타 라인)
Scope B 카드(이미지 + 메타 라인)
Digital Bus 그래프(Canvas)
Global Cursor Bar(슬라이더/숫자 입력/좌우 이동 버튼)
UI 동작(최소)
Capture A/B/AB 누르면
캡처 이미지 갱신
메타(time/div, pos) 표시 갱신
CSV Load 하면
Bus 그래프 렌더
Global cursor 이동하면
Scope A 이미지 위에 수직선(overlay) 표시
Scope B 이미지 위에 수직선(overlay) 표시
Bus 그래프도 동일 t에 수직선 표시
(옵션) 커서 주변 구간만 bus data 재요청해서 성능 유지
버스 그래프 포맷(간단)
X: time (s 또는 us)
Y: value (0/1, 또는 byte/word 값)
처음엔 0/1 한 채널만 해도 MVP 됨
(추후 멀티채널/버스 디코드 확장)
원하면 다음 메시지에서 바로 (1) FastAPI main.py 뼈대 + (2) scpi_socket 캡처 함수 + (3) 9:16 index.html/app.js 최소 동작 코드까지 한 번에 뽑아줄게.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment