╔══════════════════════════════════════════════════════════════╗
║         VinfastDiag Bridge - Huong dan su dung               ║
║         Website: https://patskey.shop                        ║
╚══════════════════════════════════════════════════════════════╝

YEU CAU
  - PC Windows 7/8/10/11 (32-bit hoac 64-bit)
  - Adapter OBD2 J2534 (Mongoose, TOPDON, Autel, VXDIAG...)
  - Ket noi internet (lan dau cai dat)
  - Cap OBD2 cam vao xe, bat IGN ON

════════════════════════════════════════════════════════════════
PHAN 1 — CAI DAT (chi lam 1 LAN DUY NHAT)
════════════════════════════════════════════════════════════════

  [Cach A — Don gian nhat: Cai Node.js truoc]
  ─────────────────────────────────────────────
  1. Tai Node.js tai:  https://nodejs.org/en/download
     Chon: Windows Installer (.msi) — phien ban LTS
  2. Cai dat Node.js (next → next → finish)
  3. Double-click: install.bat
  4. Xong! Chuyen sang Phan 2.

  [Cach B — Khong can cai Node.js]
  ─────────────────────────────────────────────
  1. Tai file zip tai:
     https://nodejs.org/dist/v20.19.1/node-v20.19.1-win-x86.zip
  2. Giai nen file zip
  3. Doi ten thu muc "node-v20.19.1-win-x86" thanh "node32"
  4. Chuyen thu muc "node32" vao cung cho voi install.bat:
       bridge-setup\
         node32\          ← copy vao day
         install.bat
         server.js
  5. Mo PowerShell trong thu muc bridge-setup:
     (Shift + chuot phai → "Open PowerShell here")
  6. Chay 2 lenh nay:
       $env:PATH = "$PWD\node32;$env:PATH"
       .\node32\npm.cmd install
  7. Xong! Chuyen sang Phan 2.

════════════════════════════════════════════════════════════════
PHAN 2 — CAI DAT SSL (chi lam 1 LAN DUY NHAT)
════════════════════════════════════════════════════════════════

  Buoc nay giup ket noi tu trang HTTPS (patskey.shop)
  den bridge tren may tinh (wss://localhost:8443)

  1. Chay: start.bat
     → Bridge khoi dong, mo 2 tab trinh duyet tu dong

  2. O tab https://localhost:8443:
     → Chrome: bam "Advanced" → "Proceed to localhost (unsafe)"
     → Firefox: bam "Accept the Risk and Continue"
     → Edge: bam "Advanced" → "Continue to localhost (unsafe)"

     (Neu khong tu mo, tu mo tab va vao: https://localhost:8443)

  3. Thay "Cannot GET /" → SSL da duoc chap nhan!

  * Chi can lam 1 lan. Nhung neu doi may tinh / doi trinh duyet
    → phai lam lai buoc nay.

════════════════════════════════════════════════════════════════
PHAN 3 — TU DONG CHAY KHI BAT MAY (tuy chon)
════════════════════════════════════════════════════════════════

  Sau khi cai dat xong, muon bridge tu chay khi bat may:

  1. Double-click: add-to-startup.bat
  2. Khoi dong lai Windows
  3. Bridge se tu dong chay ngam, khong can mo thu gi them

  De go bo: xoa file "VinfastDiag Bridge.lnk" trong thu muc:
  C:\Users\[ten-user]\AppData\Roaming\Microsoft\Windows\
  Start Menu\Programs\Startup\

════════════════════════════════════════════════════════════════
PHAN 4 — SU DUNG HANG NGAY
════════════════════════════════════════════════════════════════

  NEU DA CAI AUTO-START (Phan 3):
    1. Bat may → bridge tu chay ngam
    2. Mo Chrome → vao: https://patskey.shop
    3. Trang tu dong ket noi bridge (cho ~3-5 giay)
    4. Cam adapter OBD2 → bam "Ket noi J2534" → chon DLL → Ket noi
    5. Chon xe (model VinFast) → Scan ECU → su dung

  NEU CHUA CAI AUTO-START:
    1. Mo thu muc bridge-setup
    2. Double-click: start.bat
    3. De cua so cmd CHAY SUOT (dong la bridge tat)
    4. Mo Chrome → vao: https://patskey.shop
    5. Trang tu dong ket noi bridge

════════════════════════════════════════════════════════════════
PHAN 5 — SU DUNG TU DIEN THOAI / THIET BI KHAC
════════════════════════════════════════════════════════════════

  Dung khi muon chan doan tu dien thoai hoac may tinh khac
  trong cung mang WiFi.

  Tren PC chay bridge:
    1. Mo CMD → nhap: ipconfig
    2. Tim dong "IPv4 Address" (vi du: 192.168.1.50)

  Tren dien thoai / may khac:
    1. Mo: https://patskey.shop
    2. Trong o "Bridge WebSocket URL" nhap:
       wss://192.168.1.50:8443   (thay IP cho dung)
    3. Bam "Ket noi Bridge"

  * Dien thoai cung phai chap nhan SSL:
    Mo trinh duyet → vao https://192.168.1.50:8443 → chap nhan

════════════════════════════════════════════════════════════════
PHAN 6 — TRUY CAP TU INTERNET (khong can mang LAN)
════════════════════════════════════════════════════════════════

  Dung Cloudflare Tunnel (mien phi, khong can SSL rieng):

  1. Double-click: cloudflared.bat
  2. Copy URL dang: https://xxxx.trycloudflare.com
  3. Doi "https" thanh "wss": wss://xxxx.trycloudflare.com
  4. Dan vao o Bridge URL tren website

  * URL nay thay doi moi lan chay cloudflared.bat

════════════════════════════════════════════════════════════════
XU LY SU CO
════════════════════════════════════════════════════════════════

  [X] install.bat: "npm not found" / loi cai dat
      → Dung Cach B o Phan 1, nho chay 2 lenh PowerShell

  [X] "Khong tim thay DLL" khi quet J2534
      → Cai driver J2534 cua adapter (Mongoose, TOPDON...)
      → Chuot phai vao .inf → Install → Quet Registry lai

  [X] Bridge URL: "WS Mat ket noi" tren trang Hostinger
      → Kiem tra start.bat (hoac start-bg.vbs) dang chay
      → Kiem tra da chap nhan SSL tai https://localhost:8443 chua
      → Thu doi sang ws://localhost:8080 (neu dung cung PC)

  [X] Trinh duyet bao "Not secure" / tu choi ket noi SSL
      → Vao https://localhost:8443 → chap nhan canh bao
      → Xem Phan 2 de lam lai

  [X] "PassThruOpen failed"
      → Cam adapter OBD2 truoc khi bam Ket noi J2534
      → Thu chon DLL khac trong danh sach

  [X] Muon dung bridge ma khong co internet
      → Truy cap: http://localhost:8080 (cung PC, HTTP)
      → Hoac dung LAN: ws://[IP-PC]:8080 (khong can SSL)

════════════════════════════════════════════════════════════════
TOM TAT FILE TRONG GOI
════════════════════════════════════════════════════════════════

  install.bat        → Cai dat thu vien (chay 1 lan dau)
  start.bat          → Khoi dong bridge (hien thi cua so)
  start-bg.vbs       → Khoi dong bridge an (khong cua so)
  add-to-startup.bat → Them vao Windows Startup tu dong
  setup-ssl.bat      → Tao SSL certificate (tu dong trong install)
  cloudflared.bat    → Tao tunnel truy cap Internet
  server.js          → File chinh cua bridge
  src\               → Thu vien ho tro (j2534, uds, vinfast...)

════════════════════════════════════════════════════════════════
