@echo off


if not exist %USERPROFILE%\desktop\RtkBtTraces md %USERPROFILE%\desktop\RtkBtTraces
set LOGMAINDIR="%USERPROFILE%\desktop\RtkBtTraces"

if not exist "C:\Program Files\REALTEK\Realtek Bluetooth" md "C:\Program Files\REALTEK\Realtek Bluetooth" 
set CFADIR="C:\Program Files\REALTEK\Realtek Bluetooth"

rem set log path
if "%date:~4,1%" == "/" set CDATE=%date:~0,4%%date:~5,2%%date:~8,2%
if "%date:~2,1%" == "/" set CDATE=%date:~6,4%%date:~0,2%%date:~3,2%
if "%date:~-5,1%" == "/" set CDATE=%date:~-4,4%%date:~-10,2%%date:~-7,2%
if "%date:~-3,1%" == "/" set CDATE=%date:~-10,4%%date:~-5,2%%date:~-2,2%
echo %CDATE%

if "%time:~0,1%" == " " (
	set CTIME=%time:~1,1%-%time:~3,2%-%time:~6,2%
) else (
	set CTIME=%time:~0,2%-%time:~3,2%-%time:~6,2%
)
echo %CTIME%
echo %CDATE%_%CTIME%

if not exist %LOGMAINDIR%\%CDATE%_%CTIME% md %LOGMAINDIR%\%CDATE%_%CTIME%
set LOGDIR=%LOGMAINDIR%\%CDATE%_%CTIME%

echo Getting System information
Systeminfo > "%LOGDIR%\SystemInfo.txt"
call:GetBtFileVersion  "%LOGDIR%\SystemInfo.txt"

echo.
echo ####################################################################
echo Log file is put in the Dir:
echo %LOGDIR%
echo ####################################################################
echo.


rem rtkuart
logman create trace -n rtkuarttrace -o %LOGDIR%\rtkuart_trace_%CTIME%.etl -nb 128 640 -bs 128
logman update trace -n rtkuarttrace -p {52939353-f219-4281-af9a-5283379bfc96} 0xffffffff 9
logman start -n rtkuarttrace

rem BTDevMgr
logman create trace -n BTDevMgrtrace -o %LOGDIR%\BTDevMgr_trace_%CTIME%.etl -nb 128 640 -bs 128
logman update trace -n BTDevMgrtrace -p {4ed1fccd-EA57-433d-8C92-0A841BAA3B5C} 0xffffffff 9
logman start -n BTDevMgrtrace

echo.
echo RtkUart trace started, please repro the issue.
echo run logmanUartTraceDisable.bat after the repro.
echo.

:end
pause
@echo on
goto:eof



:GetBtFileVersion

set OLDPATH=%PATH%
set PATH=%PATH%;%~dp0%
set OLDCD=%cd%

if %PROCESSOR_ARCHITECTURE%==AMD64 (
    set BTDIR="%programfiles(x86)%\\REALTEK\\Realtek Bluetooth"
)
if %PROCESSOR_ARCHITECTURE%==x86 (
    set BTDIR="%programfiles%\\REALTEK\\Realtek Bluetooth"
)
cd /d %BTDIR%


rem get driver version information
GetFileVer.exe ".\Version\RTLBTVersion.dll" >>%~1
GetFileVer.exe "%windir%\system32\drivers\RtkUart.sys" >>%~1
GetFileVer.exe "%windir%\system32\drivers\RtkA2dp.sys" >>%~1
GetFileVer.exe /fwver >>%~1
GetFileVer.exe "BTDevMgr.exe">>%~1
rem read wifi reported antenna policy in registry.
REG QUERY HKLM\SYSTEM\CurrentControlSet\services\RtlWlans\Parameters /v BtAntennaInHw >>%~1
rem read BtIsConfig antenna policy in registry
REG QUERY HKLM\SYSTEM\CurrentControlSet\services\RtkUart\Parameters /v BtIsConfigAntenna >>%~1
 

echo ======================IsConfig.ini========================== >>%~1
type IsConfig.ini >>%~1

GetFileVer.exe /e

set PATH=%OLDPATH%
cd /d %OLDCD%

goto:eof
