diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 7a8c886..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/Dockerfile b/Dockerfile index 5ef5c4d..a6d8cb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ RUN mkdir /docker_persistent VOLUME /docker_persistent +# setup docker RUN ./install.sh docker \ && touch /docker_persistent/mbconfig.cfg \ && touch /docker_persistent/persistent.file \ diff --git a/background_installer.sh b/background_installer.sh index 9db0d1a..dae1784 100755 --- a/background_installer.sh +++ b/background_installer.sh @@ -1,7 +1,7 @@ #!/bin/bash OPENPLC_DIR="$PWD" SWAP_FILE="$OPENPLC_DIR/swapfile" -WIRINGPI_VERSION="3.4" +WIRINGPI_VERSION="3.14" # Support RPi 1..5, CM5, CM5(L), Pi500, GCLK (Generic Clock) for RPi5 is not supported. VENV_DIR="$OPENPLC_DIR/.venv" function print_help_and_exit { @@ -73,24 +73,6 @@ function install_wiringpi { ) || fail "Failed to install wiringpi." } -function install_pigpio { - echo "[PIGPIO]" - echo "Trying distribution package..." - sudo apt-get install -y pigpio && return 0 - - echo "Falling back to direct download..." - local URL="https://github.com/joan2937/pigpio/archive/master.zip" - ( - set -e - wget -c "$URL" - unzip master.zip - cd pigpio-master - make - sudo make install - rm -f master.zip - ) -} - function install_wiringop { echo "[WIRINGOP]" local URL="https://github.com/orangepi-xunlong/wiringOP/archive/master.zip" @@ -369,7 +351,7 @@ elif [ "$1" == "docker" ]; then elif [ "$1" == "rpi" ]; then echo "Installing OpenPLC on Raspberry Pi" linux_install_deps sudo - install_pigpio + install_wiringpi install_py_deps install_all_libs sudo install_systemd_service sudo diff --git a/webserver/core/hardware_layers/raspberrypi.cpp b/webserver/core/hardware_layers/raspberrypi.cpp index 2c25eab..73c8fb2 100755 --- a/webserver/core/hardware_layers/raspberrypi.cpp +++ b/webserver/core/hardware_layers/raspberrypi.cpp @@ -28,7 +28,8 @@ #include #include #include -#include +#include +#include #include #include "ladder.h" @@ -39,7 +40,7 @@ #define MAX_INPUT 14 #define MAX_OUTPUT 11 -#define MAX_ANALOG_OUT 1 +#define MAX_ANALOG_OUT 1 /********************I/O PINS CONFIGURATION********************* * A good source for RaspberryPi I/O pins information is: @@ -50,15 +51,15 @@ ****************************************************************/ //inBufferPinMask: pin mask for each input, which //means what pin is mapped to that OpenPLC input -int inBufferPinMask[MAX_INPUT] = { 2, 3, 4, 17, 27, 22, 10, 9, 11, 5, 6, 13, 19, 26 }; +int inBufferPinMask[MAX_INPUT] = { 8, 9, 7, 0, 2, 3, 12, 13, 14, 21, 22, 23, 24, 25 }; //outBufferPinMask: pin mask for each output, which //means what pin is mapped to that OpenPLC output -int outBufferPinMask[MAX_OUTPUT] = { 14, 15, 23, 24, 25, 8, 7, 12, 16, 20, 21 }; +int outBufferPinMask[MAX_OUTPUT] = { 15, 16, 4, 5, 6, 10, 11, 26, 27, 28, 29 }; //analogOutBufferPinMask: pin mask for the analog PWM //output of the RaspberryPi -int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 18 }; +int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 1 }; //----------------------------------------------------------------------------- // This function is called by the main OpenPLC routine when it is initializing. @@ -66,30 +67,29 @@ int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 18 }; //----------------------------------------------------------------------------- void initializeHardware() { - gpioInitialise(); + wiringPiSetup(); //piHiPri(99); //set pins as input for (int i = 0; i < MAX_INPUT; i++) { - gpioSetMode(inBufferPinMask[i], PI_INPUT); + pinMode(inBufferPinMask[i], INPUT); if (i != 0 && i != 1) //pull down can't be enabled on the first two pins { - gpioSetPullUpDown(inBufferPinMask[i], PI_PUD_DOWN); //pull down enabled + pullUpDnControl(inBufferPinMask[i], PUD_DOWN); //pull down enabled } } //set pins as output for (int i = 0; i < MAX_OUTPUT; i++) { - gpioSetMode(outBufferPinMask[i], PI_OUTPUT); + pinMode(outBufferPinMask[i], OUTPUT); } //set PWM pins as output for (int i = 0; i < MAX_ANALOG_OUT; i++) { - gpioSetMode(analogOutBufferPinMask[i], PI_ALT5); - gpioSetPWMrange(analogOutBufferPinMask[i], 1024); + pinMode(analogOutBufferPinMask[i], PWM_OUTPUT); } } @@ -99,7 +99,6 @@ void initializeHardware() //----------------------------------------------------------------------------- void finalizeHardware() { - gpioTerminate(); } //----------------------------------------------------------------------------- @@ -114,7 +113,7 @@ void updateBuffersIn() //INPUT for (int i = 0; i < MAX_INPUT; i++) { - if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = gpioRead(inBufferPinMask[i]); + if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = digitalRead(inBufferPinMask[i]); } pthread_mutex_unlock(&bufferLock); //unlock mutex @@ -132,13 +131,13 @@ void updateBuffersOut() //OUTPUT for (int i = 0; i < MAX_OUTPUT; i++) { - if (bool_output[i/8][i%8] != NULL) gpioWrite(outBufferPinMask[i], *bool_output[i/8][i%8]); + if (bool_output[i/8][i%8] != NULL) digitalWrite(outBufferPinMask[i], *bool_output[i/8][i%8]); } //ANALOG OUT (PWM) for (int i = 0; i < MAX_ANALOG_OUT; i++) { - if (int_output[i] != NULL) gpioPWM(analogOutBufferPinMask[i], (*int_output[i] / 64)); + if (int_output[i] != NULL) pwmWrite(analogOutBufferPinMask[i], (*int_output[i] / 64)); } pthread_mutex_unlock(&bufferLock); //unlock mutex diff --git a/webserver/scripts/compile_program.sh b/webserver/scripts/compile_program.sh index c5f8379..63fc7fa 100755 --- a/webserver/scripts/compile_program.sh +++ b/webserver/scripts/compile_program.sh @@ -143,9 +143,9 @@ elif [ "$OPENPLC_PLATFORM" = "rpi" ]; then ./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` -lsnap7 -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` -lsnap7 -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w + g++ -DSEQUENT -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lwiringPi -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lsnap7 -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w + else + g++ -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lwiringPi -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lsnap7 -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w fi if [ $? -ne 0 ]; then echo "Error compiling C files"