//$file${.::CTDepthSensor.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//
// Model: CPF.qm
// File:  ${.::CTDepthSensor.c}
//
// This code has been generated by QM 4.5.1 (https://www.state-machine.com/qm).
// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
//
// This program is open source software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
//$endhead${.::CTDepthSensor.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#include "qpcpp.hpp"
#include <iostream>
#include <stdlib.h> // for exit()

using namespace std;
using namespace QP;

enum { BSP_TICKS_PER_SEC = 100 };

extern "C" void Q_onAssert(char const * const module, int loc) {
    cout << "Assertion failed in " << module << ':' << loc << endl;
    exit(-1);
}
void QF::onStartup(void) {}
void QF::onCleanup(void) {}
void QP::QF_onClockTick(void) {
    QF::TICK_X(0U, (void *)0);  // perform the QF clock tick processing
}

enum CTDDepthSensorSignals {
    TIMEOUT_SIG = Q_USER_SIG,
    MAX_SIG
};

//=============== ask QM to declare the CTDepthSensor class ==================
//$declare${AOs::CTDepthSensor} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//${AOs::CTDepthSensor} ......................................................
class CTDepthSensor : public QP::QActive {
protected:
    Q_STATE_DECL(initial);
    Q_STATE_DECL(initCTDepthSensor);
    Q_STATE_DECL(sendReceiveCommand);
    Q_STATE_DECL(SendCommand);
    Q_STATE_DECL(CheckForResponse);
    Q_STATE_DECL(PowerUp);
    Q_STATE_DECL(PowerDown);
    Q_STATE_DECL(doDepthCalculations);
};
//$enddecl${AOs::CTDepthSensor} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

static CTDepthSensor l_ctDepthSensor;
QActive * const AO_CTDepthSensor = &l_ctDepthSensor;

int main() {
    // statically allocate event queue buffer for the CTDepthSensor AO
    static QEvt const *ctDepthSensor_queueSto[10];

    QF::init(); // initialize the framework
    AO_CTDepthSensor->start(1U, // priority
                     ctDepthSensor_queueSto, Q_DIM(ctDepthSensor_queueSto),
                     (void *)0, 0U); // no stack
    return QF::run(); // run the QF application
}

//================ ask QM to define the CTDepthSensor class ==================
//$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// Check for the minimum required QP version
#if (QP_VERSION < 650U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
#error qpcpp version 6.5.0 or higher required
#endif
//$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//$define${AOs::CTDepthSensor} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//${AOs::CTDepthSensor} ......................................................
//${AOs::CTDepthSensor::SM} ..................................................
//${AOs::CTDepthSensor::SM::initCTDepthSensor} ...............................
Q_STATE_DEF(CTDepthSensor, initCTDepthSensor) {
    QP::QState status_;
    switch (e->sig) {
        default: {
            status_ = super(&top);
            break;
        }
    }
    return status_;
}
//${AOs::CTDepthSensor::SM::sendReceiveCommand} ..............................
Q_STATE_DEF(CTDepthSensor, sendReceiveCommand) {
    QP::QState status_;
    switch (e->sig) {
        default: {
            status_ = super(&top);
            break;
        }
    }
    return status_;
}
//${AOs::CTDepthSensor::SM::sendReceiveComma~::SendCommand} ..................
Q_STATE_DEF(CTDepthSensor, SendCommand) {
    QP::QState status_;
    switch (e->sig) {
        //${AOs::CTDepthSensor::SM::sendReceiveComma~::SendCommand::TRIG1}
        case TRIG1_SIG: {
            status_ = tran(&CheckForResponse);
            break;
        }
        //${AOs::CTDepthSensor::SM::sendReceiveComma~::SendCommand::Timeout}
        case Timeout_SIG: {
            status_ = tran(&SendCommand);
            break;
        }
        default: {
            status_ = super(&sendReceiveCommand);
            break;
        }
    }
    return status_;
}
//${AOs::CTDepthSensor::SM::sendReceiveComma~::CheckForResponse} .............
Q_STATE_DEF(CTDepthSensor, CheckForResponse) {
    QP::QState status_;
    switch (e->sig) {
        default: {
            status_ = super(&sendReceiveCommand);
            break;
        }
    }
    return status_;
}
//${AOs::CTDepthSensor::SM::PowerUp} .........................................
Q_STATE_DEF(CTDepthSensor, PowerUp) {
    QP::QState status_;
    switch (e->sig) {
        default: {
            status_ = super(&top);
            break;
        }
    }
    return status_;
}
//${AOs::CTDepthSensor::SM::PowerDown} .......................................
Q_STATE_DEF(CTDepthSensor, PowerDown) {
    QP::QState status_;
    switch (e->sig) {
        default: {
            status_ = super(&top);
            break;
        }
    }
    return status_;
}
//${AOs::CTDepthSensor::SM::doDepthCalculations} .............................
Q_STATE_DEF(CTDepthSensor, doDepthCalculations) {
    QP::QState status_;
    switch (e->sig) {
        default: {
            status_ = super(&top);
            break;
        }
    }
    return status_;
}
//$enddef${AOs::CTDepthSensor} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
