/
tisit
/
OpenPLC_v3
Обзор
Документация
Войти
/
tisit
/
OpenPLC_v3
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
webserver/scripts/compile_program.sh
186 строк
7 KB
Kostadin Popov
Adding Orange Pi as a platform in the compiling script
10 сен 2024, 18:12
Не верифицирован
10 сен 2024, 18:12
cfaf508
Код
Авторство
О чём код?
#!/bin/bash if [ $# -eq 0 ]; then echo "Error: You must provide a file to be compiled as argument" exit 1 fi #move into the scripts folder if you're not there already cd scripts &>/dev/null OPENPLC_PLATFORM=$(cat openplc_platform) ETHERCAT_OPT=$(cat ethercat) OPENPLC_DRIVER=$(cat openplc_driver) #store the active program filename echo "$1" > ../active_program #compiling the ST file into C cd .. echo "Generating C files..." ./iec2c -f -l -p -r -R -a ./st_files/"$1" if [ $? -ne 0 ]; then echo "Error generating C files" echo "Compilation finished with errors!" exit 1 fi # stick reference to ethercat_src in there for CoE access etc functionality that needs to be accessed from PLC if [ "$ETHERCAT_OPT" = "ethercat" ]; then sed -i '7s/^/#include "ethercat_src.h" /' Res0.c fi echo "Moving Files..." mv -f POUS.c POUS.h LOCATED_VARIABLES.h VARIABLES.csv Config0.c Config0.h Res0.c ./core/ if [ $? -ne 0 ]; then echo "Error moving files" echo "Compilation finished with errors!" exit 1 fi if [ "$ETHERCAT_OPT" = "ethercat" ]; then echo "Including EtherCAT" ETHERCAT_INC="-L../../utils/ethercat_src/build/lib -lethercat_src -I../../utils/ethercat_src/src -D _ethercat_src" else ETHERCAT_INC="" fi #compiling for each platform cd core if [ "$OPENPLC_PLATFORM" = "win" ]; then echo "Compiling for Windows" echo "Generating object files..." g++ -I ./lib -c Config0.c -w if [ $? -ne 0 ]; then echo "Error compiling C files" echo "Compilation finished with errors!" exit 1 fi g++ -I ./lib -c Res0.c -w if [ $? -ne 0 ]; then echo "Error compiling C files" echo "Compilation finished with errors!" exit 1 fi echo "Generating glueVars..." ./glue_generator echo "Compiling main program..." g++ *.cpp *.o -o openplc -I ./lib -pthread -fpermissive -I /usr/local/include/modbus -L /usr/local/lib -lmodbus -w if [ $? -ne 0 ]; then echo "Error compiling C files" echo "Compilation finished with errors!" exit 1 fi echo "Compilation finished successfully!" exit 0 elif [ "$OPENPLC_PLATFORM" = "linux" ]; then echo "Compiling for Linux" echo "Generating object files..." if [ "$OPENPLC_DRIVER" = "sl_rp4" ]; then g++ -std=gnu++11 -I ./lib -c Config0.c -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w -DSL_RP4 else g++ -std=gnu++11 -I ./lib -c Config0.c -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w fi if [ $? -ne 0 ]; then echo "Error compiling C files" echo "Compilation finished with errors!" exit 1 fi if [ "$OPENPLC_DRIVER" = "sl_rp4" ]; then g++ -std=gnu++11 -I ./lib -c Res0.c -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w $ETHERCAT_INC -DSL_RP4 else g++ -std=gnu++11 -I ./lib -c Res0.c -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w $ETHERCAT_INC fi if [ $? -ne 0 ]; then echo "Error compiling C files" echo "Compilation finished with errors!" exit 1 fi echo "Generating glueVars..." ./glue_generator echo "Compiling main program..." if [ "$OPENPLC_DRIVER" = "sl_rp4" ]; then g++ -std=gnu++11 *.cpp *.o -o openplc -I ./lib -pthread -fpermissive `pkg-config --cflags --libs libmodbus` -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w $ETHERCAT_INC -DSL_RP4 else g++ -std=gnu++11 *.cpp *.o -o openplc -I ./lib -pthread -fpermissive `pkg-config --cflags --libs libmodbus` -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w $ETHERCAT_INC fi if [ $? -ne 0 ]; then echo "Error compiling C files" echo "Compilation finished with errors!" exit 1 fi echo "Compilation finished successfully!" exit 0 elif [ "$OPENPLC_PLATFORM" = "rpi" ]; then echo "Compiling for Raspberry Pi" echo "Generating object files..." if [ "$OPENPLC_DRIVER" = "sequent" ]; then g++ -std=gnu++11 -I ./lib -c Config0.c -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w -DSEQUENT else g++ -std=gnu++11 -I ./lib -c Config0.c -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w fi if [ $? -ne 0 ]; then echo "Error compiling C files" echo "Compilation finished with errors!" exit 1 fi if [ "$OPENPLC_DRIVER" = "sequent" ]; then g++ -std=gnu++11 -I ./lib -c Res0.c -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w -DSEQUENT else g++ -std=gnu++11 -I ./lib -c Res0.c -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w fi if [ $? -ne 0 ]; then echo "Error compiling C files" echo "Compilation finished with errors!" exit 1 fi echo "Generating glueVars..." ./glue_generator echo "Compiling main program..." if [ "$OPENPLC_DRIVER" = "sequent" ]; then g++ -DSEQUENT -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lpigpio -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w else g++ -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lpigpio -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w fi if [ $? -ne 0 ]; then echo "Error compiling C files" echo "Compilation finished with errors!" exit 1 fi echo "Compilation finished successfully!" exit 0 elif [ "$OPENPLC_PLATFORM" = "opi" ]; then WIRINGOP_INC="-I/usr/local/include -L/usr/local/lib -lwiringPi -lwiringPiDev" echo "Compiling for Orange Pi" echo "Generating object files..." g++ -std=gnu++11 -I ./lib -c Config0.c -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w $WIRINGOP_INC if [ $? -ne 0 ]; then echo "Error compiling C files" echo "Compilation finished with errors!" exit 1 fi g++ -std=gnu++11 -I ./lib -c Res0.c -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w $WIRINGOP_INC if [ $? -ne 0 ]; then echo "Error compiling C files" echo "Compilation finished with errors!" exit 1 fi echo "Generating glueVars..." ./glue_generator echo "Compiling main program..." g++ -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w $WIRINGOP_INC if [ $? -ne 0 ]; then echo "Error compiling C files" echo "Compilation finished with errors!" exit 1 fi echo "Compilation finished successfully!" exit 0 else echo "Error: Undefined platform! OpenPLC can only compile for Windows, Linux and Raspberry Pi environments" echo "Compilation finished with errors!" exit 1 fi