// Generated by STruC++ - IEC 61131-3 Structured Text to C++ Compiler
// Do not edit this file manually.

#include "generated.hpp"

namespace strucpp {

FB_PUMP::FB_PUMP()
    : SCAN_S(0.1), VIB_ALARM(7.1), VIB_TRIP(11.0), NOFLOW_KPA(150.0)
{
    // Initialize variables
}

void FB_PUMP::operator()() {
    if (RESETTRIP) {
        TRIPPED = false;
    }
    if (!THERMALOK) {
        TRIPPED = true;
    }
    if (VIBRATION > VIB_TRIP) {
        TRIPPED = true;
    }
    NOFLOWTMR.IN = RUNCMD;
    NOFLOWTMR.PT = 20000000000LL;
    NOFLOWTMR();
    NOFLOWTMR.ENO = true;
    if ((NOFLOWTMR.Q) & ((DISCHPRESSURE < NOFLOW_KPA))) {
        TRIPPED = true;
    }
    VIBALARM = VIBRATION > VIB_ALARM;
    SEALALARM = SEALLEAK;
    AVAILABLE = ((THERMALOK) & (!TRIPPED)) & (!LOCKOUT);
    MINRUNTMR.IN = RUNCMD;
    MINRUNTMR.PT = 300000000000LL;
    MINRUNTMR();
    MINRUNTMR.ENO = true;
    MINOFFTMR.IN = ((!RUNCMD)) & (HASRUN);
    MINOFFTMR.PT = 300000000000LL;
    MINOFFTMR();
    MINOFFTMR.ENO = true;
    STARTOK = (((!HASRUN)) | (MINOFFTMR.Q)) | (MINOFFBYPASS);
    if (((TRIPPED) | (LOCKOUT)) | (!THERMALOK)) {
        RUNCMD = false;
    } else if (RUNCMD) {
        if (((!RUNREQUEST)) & (MINRUNTMR.Q)) {
            RUNCMD = false;
        }
    } else {
        if ((RUNREQUEST) & (STARTOK)) {
            RUNCMD = true;
            HASRUN = true;
        }
    }
    RUNNING = RUNCMD;
    if (RESETHOURS) {
        RUNHOURS = 0.0;
    }
    if (RUNNING) {
        RUNHOURS = RUNHOURS + SCAN_S / 3600.0;
    }
    SERVICEDUE = RUNHOURS >= SERVICEINTERVAL;
    if (TRIPPED) {
        STATE = 6;
    } else if (LOCKOUT) {
        STATE = 7;
    } else if (!THERMALOK) {
        STATE = 0;
    } else if ((RUNNING) & (!RUNREQUEST)) {
        STATE = 4;
    } else if ((RUNCMD) & (!NOFLOWTMR.Q)) {
        STATE = 2;
    } else if (RUNNING) {
        STATE = 3;
    } else if ((HASRUN) & (!MINOFFTMR.Q)) {
        STATE = 5;
    } else {
        STATE = 1;
    }
}

}  // namespace strucpp