Added timestamps to project logging
This commit is contained in:
@@ -6,10 +6,12 @@ setlocal enabledelayedexpansion
|
||||
:: Reads baud rate from .anvil.toml. No Anvil binary required.
|
||||
::
|
||||
:: Usage:
|
||||
:: monitor.bat Open monitor (auto-detect port)
|
||||
:: monitor.bat -p COM3 Specify port
|
||||
:: monitor.bat -b 9600 Override baud rate
|
||||
:: monitor.bat --board mega Use baud from a named board
|
||||
:: monitor.bat Open monitor (auto-detect port)
|
||||
:: monitor.bat -p COM3 Specify port
|
||||
:: monitor.bat -b 9600 Override baud rate
|
||||
:: monitor.bat --board mega Use baud from a named board
|
||||
:: monitor.bat --timestamps Prepend [HH:MM:SS.mmm] to each line
|
||||
:: monitor.bat --log session.log Also write output to a file
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"
|
||||
@@ -60,6 +62,8 @@ if "%BAUD%"=="" set "BAUD=115200"
|
||||
:: -- Parse arguments ------------------------------------------------------
|
||||
set "PORT="
|
||||
set "BOARD_NAME="
|
||||
set "DO_TIMESTAMPS=0"
|
||||
set "LOG_FILE="
|
||||
|
||||
:parse_args
|
||||
if "%~1"=="" goto done_args
|
||||
@@ -68,6 +72,8 @@ if "%~1"=="--port" set "PORT=%~2" & shift & shift & goto parse_args
|
||||
if "%~1"=="-b" set "BAUD=%~2" & shift & shift & goto parse_args
|
||||
if "%~1"=="--baud" set "BAUD=%~2" & shift & shift & goto parse_args
|
||||
if "%~1"=="--board" set "BOARD_NAME=%~2" & shift & shift & goto parse_args
|
||||
if "%~1"=="--timestamps" set "DO_TIMESTAMPS=1" & shift & goto parse_args
|
||||
if "%~1"=="--log" set "LOG_FILE=%~2" & shift & shift & goto parse_args
|
||||
if "%~1"=="--help" goto show_help
|
||||
if "%~1"=="-h" goto show_help
|
||||
echo FAIL: Unknown option: %~1
|
||||
@@ -75,8 +81,11 @@ exit /b 1
|
||||
|
||||
:show_help
|
||||
echo Usage: monitor.bat [-p PORT] [-b BAUD] [--board NAME]
|
||||
echo [--timestamps] [--log FILE]
|
||||
echo Opens serial monitor. Baud rate from .anvil.toml.
|
||||
echo --board NAME selects a board from [boards.NAME].
|
||||
echo --board NAME selects a board from [boards.NAME].
|
||||
echo --timestamps prepend [HH:MM:SS.mmm] to each line.
|
||||
echo --log FILE also write output to a file.
|
||||
exit /b 0
|
||||
|
||||
:done_args
|
||||
@@ -164,6 +173,27 @@ if "%PORT%"=="" (
|
||||
|
||||
:: -- Monitor --------------------------------------------------------------
|
||||
echo Opening serial monitor on %PORT% at %BAUD% baud...
|
||||
if "%DO_TIMESTAMPS%"=="1" echo Timestamps enabled.
|
||||
if not "%LOG_FILE%"=="" echo Logging to: %LOG_FILE%
|
||||
echo Press Ctrl+C to exit.
|
||||
echo.
|
||||
|
||||
if "%DO_TIMESTAMPS%"=="1" if not "%LOG_FILE%"=="" goto monitor_ts_log
|
||||
if "%DO_TIMESTAMPS%"=="1" goto monitor_ts
|
||||
if not "%LOG_FILE%"=="" goto monitor_log
|
||||
goto monitor_plain
|
||||
|
||||
:monitor_ts_log
|
||||
powershell -NoProfile -File "%SCRIPT_DIR%\_monitor_filter.ps1" -Port "%PORT%" -Baud "%BAUD%" -Timestamps -LogFile "%LOG_FILE%"
|
||||
goto :eof
|
||||
|
||||
:monitor_ts
|
||||
powershell -NoProfile -File "%SCRIPT_DIR%\_monitor_filter.ps1" -Port "%PORT%" -Baud "%BAUD%" -Timestamps
|
||||
goto :eof
|
||||
|
||||
:monitor_log
|
||||
powershell -NoProfile -File "%SCRIPT_DIR%\_monitor_filter.ps1" -Port "%PORT%" -Baud "%BAUD%" -LogFile "%LOG_FILE%"
|
||||
goto :eof
|
||||
|
||||
:monitor_plain
|
||||
arduino-cli monitor -p %PORT% -c "baudrate=%BAUD%"
|
||||
Reference in New Issue
Block a user