embedded_raumsenor_lorawan/setup_framework.bat
xlemmingx de28645511 Fix Windows batch script - remove PowerShell dependency
- Replace PowerShell Set-Content with native batch commands
- Use type, findstr, echo and move for file processing
- Should work on all Windows systems without PowerShell restrictions
2025-10-07 18:55:13 +02:00

128 lines
3.9 KiB
Batchfile

@echo off
REM Script to setup framework modifications for STM32WL LoRaWAN project
REM Usage: setup_framework.bat
echo Setting up framework modifications for STM32WL LoRaWAN build...
REM Find PlatformIO packages directory
set PIO_PACKAGES=%USERPROFILE%\.platformio\packages
set FRAMEWORK_ZEPHYR=%PIO_PACKAGES%\framework-zephyr
set LORAMAC_NODE=%FRAMEWORK_ZEPHYR%\_pio\modules\lib\loramac-node
echo PlatformIO packages: %PIO_PACKAGES%
echo Framework Zephyr: %FRAMEWORK_ZEPHYR%
REM Check if framework exists
if not exist "%FRAMEWORK_ZEPHYR%" (
echo Error: Zephyr framework not found at %FRAMEWORK_ZEPHYR%
echo Please run 'pio run' first to download the framework
pause
exit /b 1
)
if not exist "%LORAMAC_NODE%" (
echo LoRaMAC-Node not found, need to fix PlatformIO packages first...
echo Cleaning and reinstalling PlatformIO packages...
echo Removing corrupted packages...
rmdir /s /q "%PIO_PACKAGES%" 2>nul
echo Updating PlatformIO core...
pio update
echo Running initial build to download fresh packages...
pio run
if %errorlevel% neq 0 (
echo [31mError: Build failed after package cleanup[0m
echo [33mTry running: pio platform install ststm32[0m
pause
exit /b 1
)
echo [32m✓ Framework modules initialized[0m
)
REM Double-check after potential build
if not exist "%LORAMAC_NODE%" (
echo Error: LoRaMAC-Node still not found at %LORAMAC_NODE%
echo Please check PlatformIO installation and project configuration
pause
exit /b 1
)
echo [32m✓ Framework directories found[0m
REM 1. Remove conflicting sx126x.c from LoRaMAC-Node
set CONFLICTING_FILE=%LORAMAC_NODE%\src\radio\sx126x\sx126x.c
if exist "%CONFLICTING_FILE%" (
echo Removing conflicting sx126x.c...
del "%CONFLICTING_FILE%"
echo [32m✓ Removed %CONFLICTING_FILE%[0m
) else (
echo [32m✓ sx126x.c already removed[0m
)
REM 2. Create radio_sx126x.c from original sx126x.c
set RADIO_SX126X=%LORAMAC_NODE%\src\radio\sx126x\radio_sx126x.c
if not exist "%RADIO_SX126X%" (
echo Creating radio_sx126x.c from git repository...
cd /d "%LORAMAC_NODE%"
git show HEAD:src/radio/sx126x/sx126x.c > src\radio\sx126x\radio_sx126x.c
if %errorlevel% neq 0 (
echo [31mError: Failed to create radio_sx126x.c from git[0m
echo Please ensure git is available and LoRaMAC-Node is a git repository
pause
exit /b 1
)
echo [32m✓ Created radio_sx126x.c[0m
) else (
echo [32m✓ radio_sx126x.c already exists[0m
)
REM 3. Update CMakeLists.txt
set CMAKE_FILE=%FRAMEWORK_ZEPHYR%\modules\loramac-node\CMakeLists.txt
echo Updating CMakeLists.txt...
REM Create backup
copy "%CMAKE_FILE%" "%CMAKE_FILE%.backup" >nul
REM Simple replacement - add the two lines after the zephyr_library_sources_ifdef line
set TEMP_FILE=%CMAKE_FILE%.tmp
type nul > "%TEMP_FILE%"
REM Use findstr to process the file line by line
for /f "delims=" %%i in ('type "%CMAKE_FILE%"') do (
echo %%i >> "%TEMP_FILE%"
echo %%i | findstr /c:"zephyr_library_sources_ifdef(CONFIG_HAS_SEMTECH_SX126X" >nul
if not errorlevel 1 (
echo ${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/radio/sx126x/radio.c >> "%TEMP_FILE%"
echo ${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/radio/sx126x/radio_sx126x.c >> "%TEMP_FILE%"
)
)
REM Replace original file with modified version
move "%TEMP_FILE%" "%CMAKE_FILE%"
if %errorlevel% neq 0 (
echo [31mError: Failed to update CMakeLists.txt[0m
pause
exit /b 1
)
echo [32m✓ Updated %CMAKE_FILE%[0m
echo.
echo [32m🎉 Framework setup complete![0m
echo.
echo Summary of changes:
echo - Removed: %CONFLICTING_FILE%
echo - Created: %RADIO_SX126X%
echo - Updated: %CMAKE_FILE%
echo.
echo You can now run 'pio run' to build the project.
echo.
echo To restore original framework:
echo git restore "%CONFLICTING_FILE%"
echo del "%RADIO_SX126X%"
echo move "%CMAKE_FILE%.backup" "%CMAKE_FILE%"
pause