Created
February 5, 2020 05:52
-
-
Save redneck-f25/f7a2ef2fa925d3ad7163facb727f1431 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off & setlocal enableextensions enabledelayedexpansion | |
rem wrapper around samconfig to address a single slot in a cfg-block | |
rem | |
rem samconfig host port | |
rem get device-id cfg-block-id:slot-num [value] | |
rem samconfig host port | |
rem set device-id cfg-block-id:slot-num value | |
rem | |
rem if slot-num is missing command line is passed to samconfig | |
set "__HEXDIGITS=0123456789abcdef" | |
if not "%~3" == "get" if not "%~3" == "set" ( samconfig %* & exit /b ) | |
for /f "usebackq tokens=1,2 delims=:" %%a in ( '%~5' ) do ( | |
if "%%b" == "" ( samconfig %* & exit /b ) | |
set "__raw_block_id=%%a" | |
set "__raw_slot_num=%%b" | |
) | |
set /a "__block_id=%__raw_block_id%" || ( samconfig %* & exit /b ) | |
if %__block_id% equ 0 if not "%__raw_block_id:~0,1%" == "0" ( samconfig %* & exit /b ) | |
set /a "__slot_num=%__raw_slot_num%" || ( samconfig %* & exit /b ) | |
if %__slot_num% equ 0 if not "%__raw_slot_num:~0,1%" == "0" ( samconfig %* & exit /b ) | |
set /a "__hi=__slot_num / 16" | |
set /a "__lo=__slot_num %% 16" | |
set "__slot_num_hex=!__HEXDIGITS:~%__hi%,1!!__HEXDIGITS:~%__lo%,1!" | |
set "__value=" | |
set "__raw_value=%~6" | |
if "%__raw_value%" == "" ( set "__value=" & goto _lbl_skip_value ) | |
set /a "__value=%__raw_value%" || ( samconfig & exit /b ) | |
if %__value% equ 0 if not "%__raw_value:~0,1%" == "0" ( samconfig & exit /b ) | |
set /a "__hi=__value / 16" | |
set /a "__lo=__value %% 16" | |
set "__value_hex=!__HEXDIGITS:~%__hi%,1!!__HEXDIGITS:~%__lo%,1!" | |
:_lbl_skip_value | |
if "%~3" == "set" if not defined __value ( samconfig & exit /b ) | |
set "__data=" | |
for /f "usebackq tokens=*" %%a in ( `samconfig %1 %2 get %4 %__block_id%` ) do ( | |
if "%%~a" == "usage:" ( | |
samconfig | |
exit /b 1 | |
) | |
if "%%~a" == "cfg block empty or invalid" ( | |
echo %%a | |
exit /b 0 | |
) | |
for /f "usebackq tokens=1-17" %%b in ( '%%~a' ) do ( | |
if "%%b" == "error" ( | |
echo %%a | |
exit /b 1 | |
) | |
if "%%b %%c %%d %%e" == "could not establish connection" ( | |
echo %%a | |
exit /b 2 | |
) | |
set "__data=!__data!%%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o %%p" | |
if not "%%~q" == "" set "__data=!__data! %%q %%r " | |
) | |
) | |
set /a "__p1=__slot_num * 3 + __slot_num / 8" | |
set /a "__p2=__p1+3" | |
set "__data_value_hex=!__data:~%__p1%,2!" | |
set /a "__data_value=0x%__data_value_hex%" | |
if "%~3" == "get" ( | |
echo [%__slot_num_hex%] %__data_value_hex% ^( %__data_value% ^) | |
if defined __value if not "%__value%" == "%__data_value%" ( | |
echo. | |
echo error | |
echo. | |
exit /b 1 | |
) | |
exit /b 0 | |
) | |
if "%__value%" == "%__data_value%" ( | |
echo success | |
echo. | |
exit /b 0 | |
) | |
for /f "usebackq tokens=*" %%a in ( `samconfig %1 %2 set %4 %__block_id% "hex !__data:~0,%__p1%!%__value_hex% !__data:~%__p2%!"` ) do ( | |
if "%%~a" == "success" ( | |
echo %%a ^( old value was 0x%__data_value_hex% = %__data_value% ^) | |
echo. | |
exit /b 0 | |
) | |
echo %%a | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off & setlocal enableextensions enabledelayedexpansion | |
if "%~3" == "" ( | |
for /f "usebackq tokens=*" %%a in ( `samconfig_slot %1 %2 get 1 4:10` ) do ( | |
for /f "usebackq tokens=1-9" %%b in ( '%%a' ) do ( | |
if "%%b %%c %%d %%e" == "could not establish connection" ( | |
echo %%a | |
exit /b 2 | |
) | |
if /i "%%b" == "[0a]" ( | |
if "%%c" == "ff" ( | |
echo disabled ^( 0xff ^) | |
) else ( | |
echo %%e minutes | |
) | |
exit /b 0 | |
) | |
echo %%a | |
exit /b 1 | |
) | |
) | |
) | |
set "__success=" | |
set "__has_changed=" | |
for /f "usebackq tokens=*" %%a in ( `samconfig_slot %1 %2 set 1 4:10 %3` ) do ( | |
echo %%a | |
for /f "usebackq tokens=1,6,8" %%b in ( '%%a' ) do ( | |
if "%%b %%c %%d %%e" == "could not establish connection" ( | |
exit /b 2 | |
) | |
if "%%b" == "success" ( | |
set __success=1 | |
if not "%%c" == "" set __has_changed=1 | |
) | |
) | |
) | |
if not defined __success exit /b 1 | |
if defined __has_changed ( | |
echo value has changed. need power cycle. | |
exit /b 7 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment