Skip to content

Instantly share code, notes, and snippets.

@seongyooncho
Last active May 8, 2025 13:59
Show Gist options
  • Select an option

  • Save seongyooncho/e1863b902993e26929e1696d1aff39a3 to your computer and use it in GitHub Desktop.

Select an option

Save seongyooncho/e1863b902993e26929e1696d1aff39a3 to your computer and use it in GitHub Desktop.

MotionScore HTTP 트래픽 캡처 및 분석 가이드

이 문서는 MotionScore 실행 중 발생하는 HTTP 트래픽을 Wireshark(tshark)를 사용하여 캡처하고, HTTP 응답 바디를 JSON 형식으로 추출 및 검토하는 방법을 설명합니다.

1. Wireshark 설치

$ brew install wireshark

2. Loopback 인터페이스 캡처

$ sudo tshark -i lo0 -f "tcp port 8080" -w capture.pcap

3. MotionScore 실행 및 운동 수행

  1. MotionScore를 실행합니다.
  2. 운동을 모두 수행합니다.

4. 캡처 종료

  • Ctrl+C를 눌러 캡처를 종료합니다.

5. 캡처 파일 리뷰

$ sudo tshark -r capture.pcap \
  -o http.desegment_body:TRUE \
  -Y "http.response.code == 200" \
  -T json
  • -o http.desegment_body:TRUE: HTTP body 재조립
  • -Y "http.response.code == 200": HTTP 응답 코드 200 필터링
  • -T json: JSON 형식 출력

MotionScoreServer Documentation

MotionScoreServer는 C++로 작성된 간단한 HTTP 서버로, 오버레이 제어와 운동 시작/종료 요청을 처리합니다.

서버 실행

빌드된 실행 파일인 MotionScoreServer를 실행하면 서버가 자동으로 포트 8080에서 시작됩니다.

./MotionScoreServer

API 엔드포인트

1. Overlay On

  • Endpoint: /overlay_on
  • Method: POST
  • Request Body (JSON):
{
    "x": 100,
    "y": 100,
    "width": 100,
    "height": 100
}
  • Response: 요청이 성공하면 "성공", 오류 발생 시 "실패: ..." 문자열이 반환됩니다.

  • cURL 예제:

curl -X POST http://localhost:8080/overlay_on -H "Content-Type: application/json" -d '{"x":100,"y":100,"width":100,"height":100}'

2. Overlay Off

  • Endpoint: /overlay_off

  • Method: GET

  • Response: 정상 처리 시 "성공" 문자열이 반환됩니다.

  • cURL 예제:

curl http://localhost:8080/overlay_off

3. Exercise Start

  • Endpoint: /exercise_start
  • Method: POST
  • Request Body (JSON):
{
    "exercise_code": 427
}
  • Response: 운동 시작에 성공하면 "성공", 오류 발생 시 적절한 오류 메시지가 반환됩니다.

  • cURL 예제:

curl -X POST http://localhost:8080/exercise_start -H "Content-Type: application/json" -d '{"exercise_code":427}'

4. Exercise End

  • Endpoint: /exercise_end
  • Method: GET
  • Response: 운동 종료가 성공하면 아래와 같은 JSON 형식의 결과가 반환됩니다.
{
    "exercise_code": 427,
    "score": 4.5,
    "features": {
        "vertical_arm": 2.3,
        "horizontal_arm": 3.4
    }
}
  • cURL 예제:
curl http://localhost:8080/exercise_end

5. Session Start

  • Endpoint: /session_start
  • Method: POST
  • Request Body (JSON):
{
    // Session can be 'advanced' or 'simple'
    "type": "advanced" 
}
  • Response: 세션 시작에 성공하면 "성공", 오류 발생 시 적절한 오류 메시지가 반환됩니다.

  • cURL 예제:

curl -X POST http://localhost:8080/session_start -H "Content-Type: application/json" -d '{"type":"advanced"}'

6. Session End

  • Endpoint: /session_end
  • Method: GET
  • Response: 세션 종료가 성공하면 아래와 같은 JSON 형식의 결과가 반환됩니다.
[
{
  "exercise_code": 427,
  "timestamp": 1744469659318,
  "features": {
    "LeftShoulderForwardAngle": 0.356337,
    "LeftShoulderUpperAngle": 0.162778,
    "LeftShoulderSideAngle": 0.923694,
    "RightShoulderForwardAngle": 0.908989,
    "RightShoulderUpperAngle": 0.133905,
    "RightShoulderSideAngle": 0.78038,
  },
  "score": 3,
  "score by AI": 3.00376,
},
{
  "exercise_code": 428,
  "timestamp": 1744469676088,
  "features": {
    "LeftRaise": 0.590652,
    "RightRaise": 0.582238,
  },
  "score": 9,
  "score by AI": 8.71698,
},
{
  "exercise_code": 429,
  "timestamp": 1744469687062,
  "features": {
    "LeftStand": 0,
    "RightStand": 0.00776667,
  },
  "score": 0,
  "score by AI": -0.103938,
},
{
  "exercise_code": 430,
  "timestamp": 1744469701259,
  "features": {
    "AverageLeftKnee": nan,
    "AverageRightKnee": nan,
    "AverageLeftAnkle": nan,
    "AverageRightAnkle": nan,
    "StdevLeftKnee": nan,
    "StdevRightKnee": nan,
    "StdevLeftAnkle": nan,
    "StdevRightAnkle": nan,
  },
  "score": 0,
  "score by AI": nan,
},
{
  "exercise_code": 431,
  "timestamp": 1744469728759,
  "features": {
    "StraightStand": 0.897061,
    "BentStand": -0.0316793,
    "BentSit": -0.131609,
  },
  "score": 2,
  "score by AI": 1.67412,
},
{
  "exercise_code": 432,
  "timestamp": 1744469728759,
  "features": {
    "LeftThighRaise": 0.2,
    "RightThighRaise": 0.2,
    "LeftCalfRaise": 0.2,
    "RightCalfRaise": 0.2,
  },
  "score": 2,
  "score by AI": 0,
},
{
  "exercise_code": 433,
  "timestamp": 1744469728759,
  "features": {
    "LeftArmHorizontal": 0.2,
    "RightArmHorizontal": 0.2,
    "LeftLegHorizontal": 0.2,
    "RightLegHorizontal": 0.2,
    "LeftArmVertical": 0.2,
    "RightArmVertical": 0.2,
    "LeftLegVertical": 0.2,
    "RightLegVertical": 0.2,
  },
  "score": 2,
  "score by AI": 0,
},
{
  "exercise_code": 434,
  "timestamp": 1744469728759,
  "features": {
    "LeftArm": 0.2,
    "RightArm": 0.2,
    "LeftLeg": 0.2,
    "RightLeg": 0.2,
  },
  "score": 2,
  "score by AI": 0,
},
]
  • cURL 예제:
curl http://localhost:8080/session_end

V2.1 Communication Flow

아래 다이어그램은 Kiosk와 MotionScore 간의 통신 흐름을 나타냅니다.

  • Advanced 버전:

    • Kiosk는 session_start {"type":"advanced"}를 MotionScore에 전송하면 MotionScore는 응답으로 {"성공"}을 반환합니다.
    • 이후, 427부터 434까지 8개의 운동에 대한 동작은 V2와 동일합니다. 각각 exercise_start {"exercise_code": 427}exercise_end를 전송하며, MotionScore는 각각 "성공"{"exercise_code": 427, "score": 4.5, "features": {"vertical_arm": 2.3, "horizontal_arm": 3.4, ...}}를 응답합니다.
    • 마지막으로, Kiosk가 session_end를 전송하면 MotionScore는 지금까지의 운동 결과들을 모두 포함한 응답(리스트)을 반환합니다.
  • Simple 버전:

    • Kiosk는 session_start {"type":"simple"}를 전송하고, MotionScore는 {"성공"}을 응답합니다.
    • 5개의 운동에 대해 exercise_start {"exercise_id": <ID>}exercise_end를 전송하며, 각각 MotionScore는 {"성공"}와 결과를 응답합니다.
    • 마지막으로, Kiosk가 session_end를 전송하면 MotionScore는 Advanced 버전과 동일하게 8개의 결과를 포함한 응답을 반환합니다.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment