@echo on

:: enter path to stm32cubeide installation folder
set stm_ide_location_path="C:/ST/STM32CubeIDE_1.9.0/STM32CubeIDE/stm32cubeidec"
echo off
echo "\n\n************************************** #### BUILDING OBC SOFTWARE... #### ************************************\n\n"
echo on



%stm_ide_location_path% --launcher.suppressErrors -nosplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data ..\..\..\exo_ws -import ..\..\..\exo_sat_bus_ctrl  || exit \b 1

%stm_ide_location_path% --launcher.suppressErrors -nosplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data ..\..\..\exo_ws -build Modified_CB_forTesting || exit \b 1
echo off
echo "\n\n*************************************OBC_BUILD_COMPLETED*****************************************\n\n"
echo on
copy ..\..\antaris_exo_core.elf > nul

echo off
if %errorlevel% equ 0 (
    echo "antaris_exo_core.elf copied success"
) else (
    echo "antaris_exo_core.elf not present in obc"
    pause
    exit \b 1
)
echo on

python3.10 binMaker.py 


python3.10 binMerger_lutMaker.py debug
echo off
if %ERRORLEVEL% EQU 0 (
    echo "*************OBC_MAKEFILE_BOOTLOADER_CONFIGURATION_PASS**************************"
) else (
    echo "*************BOOTLOADER NOT ENABLED IN OBC BUILD, PLS UPDATE MAKEFILE *************************"
    pause
    exit \b 1
)
echo on

del *.hex antaris_exo_core_final.bin antaris_exo_core.elf *.bak header* size_info.txt boot_table.bin antaris_exo_core_boot_table.bin


python3.10 vfb_merge_with_btlr.py debug 
echo off
if %ERRORLEVEL% EQU 0 (
    echo "*************### Success!!! Copied exo_sat_bus_ctlr binary to exo_sat_bus_btlr ###**************************"
) else (
    echo "*************### Success!!! Erased exo_sat_bus_ctlr binary from exo_sat_bus_btlr ###*************************"
    pause
    exit \b 1
)
echo on


echo off
echo "\n\n************************************** #### BUILDING BOOTLOADER SOFTWARE... #### ************************************\n\n"
echo on



%stm_ide_location_path% --launcher.suppressErrors -nosplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data ..\..\..\exo_ws -import ..\..\..\exo_sat_bus_btlr || exit \b1

%stm_ide_location_path% --launcher.suppressErrors -nosplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data ..\..\..\exo_ws -build exo_sat_bus_btlr || exit \b1

echo off
echo "*************### BUILD PROCESS SUCCESSFULLY COMPLETED !!! #####*******************************************************\n\n"
echo on
pause