#include "ovenbar.h"
//-----------------QT的头文件一定放在QP的上面
#include "qp_app.h"
#include "oven.h"
#include "bsp.h"
#include "qp_port.h"
class Oven_idle: public QP::QHsm {
protected:
static QP::QState initial (Oven_idle * const me, QP::QEvt const * const e);
static QP::QState active (Oven_idle * const me, QP::QEvt const * const e);
static QP::QState active_off (Oven_idle * const me, QP::QEvt const * const e);
static QP::QState active_prepare (Oven_idle * const me, QP::QEvt const * const e);
static QP::QState active_door_on (Oven_idle * const me, QP::QEvt const * const e);
static QP::QState active_door_off (Oven_idle * const me, QP::QEvt const * const e);
public:
Oven_idle():QHsm(Q_STATE_CAST(&Oven_idle::initial)){}
};
//QHsm是QActive的父类,可以用来辅助Oven对象
class Oven : public QP::QActive {
public:
QP::QTimeEvt m_timeout; //计时
public:
Oven_idle m_Oven_idle;
Oven();
protected: //定义微波炉的各状态
static QP::QState initial (Oven * const me, QP::QEvt const * const e);
static QP::QState active (Oven * const me, QP::QEvt const * const e); // idle
static QP::QState active_working (Oven * const me, QP::QEvt const * const e);
static QP::QState active_idle (Oven * const me, QP::QEvt const * const e);
};
static Oven l_oven;
QP::QActive * const AO_Oven = &l_oven;
/**************** Oven_idle **********************/
QP::QState Oven_idle::initial(Oven_idle * const me, QP::QEvt const * const e)
{
return Q_TRAN(&Oven_idle::active_prepare);
}
QP::QState Oven_idle::active (Oven_idle * const me, QP::QEvt const * const e)
{
QP::QState status;
switch (e->sig) {
case Q_ENTRY_SIG: {
qDebug("Oven_idle::active");
status = Q_HANDLED();
break;
}
case TERMINATE_SIG:{
BSP_terminate(0);
status = Q_HANDLED();
break;
}
default:{
status = Q_SUPER(&QHsm::top); break;
}
}
return status;
}
QP::QState Oven_idle::active_prepare(Oven_idle * const me, QP::QEvt const * const e)
{
QP::QState status;
switch (e->sig) {
case Q_ENTRY_SIG: {
qDebug("Oven_idle::active_prepare");
status = Q_HANDLED();
break;
}
case OPEN_SIG: {
status = Q_TRAN(&Oven_idle::active_door_on);
break;
}
case CLOSE_SIG: {
status = Q_TRAN(&Oven_idle::active_door_off);
break;
}
case ADD_SIG:{
BSP_SETTIME(true);
status = Q_HANDLED();
break;
}
case MINUS_SIG:{
BSP_SETTIME(false);
status = Q_HANDLED();
break;
}
case START_SIG:{
if(Ovenbar::instance()->dstatus())
{
qDebug("The door is open, please close the door");
status = Q_HANDLED();
}
else
{
AO_Oven->postFIFO(Q_NEW(QP::QEvt,Oven_idle_Start_SIG));
status = Q_TRAN(&Oven_idle::active_off);
}
break;
}
default:{
status = Q_SUPER(&Oven_idle::active); break;
}
}
return status;
}
QP::QState Oven_idle::active_off (Oven_idle * const me, QP::QEvt const * const e)
{
QP::QState status;
switch (e->sig) {
case Q_ENTRY_SIG: {
qDebug("Oven_idle::active_off");
status = Q_HANDLED();
break;
}
case STOP_SIG:{
status = Q_TRAN(&Oven_idle::active_prepare);
break;
}
case OPEN_SIG:{
status = Q_TRAN(&Oven_idle::active_door_on);
break;
}
case TIMEOUT_m_timeout_SIG:{
status = Q_TRAN(&Oven_idle::active_prepare);
}
default:{
status = Q_SUPER(&Oven_idle::active); break;
}
}
return status;
}
QP::QState Oven_idle::active_door_on (Oven_idle * const me, QP::QEvt const * const e)
{
QP::QState status;
switch (e->sig) {
case Q_ENTRY_SIG: {
qDebug("Oven_idle::idle_door_on");
BSP_DOOR(true);
status = Q_HANDLED();
break;
}
case CHICKIN_SIG:{
BSP_CHICK(true);
status = Q_HANDLED();
break;
}
case CHICKOUT_SIG:{
BSP_CHICK(false);
status = Q_HANDLED();
break;
}
case CLOSE_SIG:{
BSP_DOOR(false);
status = Q_TRAN(&Oven_idle::active_door_off);
break;
}
case START_SIG:{
qDebug("The door is open, please close the door");
status = Q_HANDLED();
break;
}
default: {
status = Q_SUPER(&Oven_idle::active); break;
}
}
return status;
}
QP::QState Oven_idle::active_door_off (Oven_idle * const me, QP::QEvt const * const e)
{
QP::QState status;
switch (e->sig) {
case Q_ENTRY_SIG: {
qDebug("Oven_idle::idle_door_off");
BSP_DOOR(false);
status = Q_HANDLED();
break;
}
case ADD_SIG:{
BSP_SETTIME(true);
status = Q_HANDLED();
break;
}
case MINUS_SIG:{
BSP_SETTIME(false);
status = Q_HANDLED();
break;
}
case START_SIG:{
AO_Oven->postFIFO(Q_NEW(QP::QEvt,Oven_idle_Start_SIG));
status = Q_TRAN(&Oven_idle::active_off);
break;
}
case OPEN_SIG:{
BSP_DOOR(true);
status = Q_TRAN(&Oven_idle::active_door_on);
break;
}
default:{
status = Q_SUPER(&Oven_idle::active); break;
}
}
return status;
}
/**************** Oven_idle **********************/
/**************** Oven **********************/
Oven::Oven()
: QActive(Q_STATE_CAST(&Oven::initial)),
m_timeout(TIMEOUT_m_timeout_SIG)
{
}
QP::QState Oven::initial(Oven * const me, QP::QEvt const * const e)
{
me->m_Oven_idle.init(); //初始化Oven_idle的状态
return Q_TRAN(&Oven::active_idle);
}
QP::QState Oven::active(Oven * const me, QP::QEvt const * const e)
{
QP::QState status;
switch (e->sig) {
case Q_ENTRY_SIG: {
qDebug("Oven::active");
status = Q_HANDLED();
break;
}
case TERMINATE_SIG:{
BSP_terminate(0);
status = Q_HANDLED();
break;
}
default: {
status = Q_SUPER(&QHsm::top); break;
}
}
return status;
}
QP::QState Oven::active_working (Oven * const me, QP::QEvt const * const e)
{
QP::QState status;
switch (e->sig) {
case Q_ENTRY_SIG:{
qDebug("Oven::active_working");
me->m_timeout.postEvery(me, BSP_TICKS_PER_SEC);
BSP_OVEN(true);
status = Q_HANDLED();
break;
}
case Q_EXIT_SIG:{
qDebug("Oven::active_working out");
me->m_timeout.disarm();
status = Q_HANDLED();
BSP_OVEN(false);
break;
}
case TIMEOUT_m_timeout_SIG:
if(BSP_SHOWTIME())
{
status = Q_HANDLED();
}
else
{
me->m_Oven_idle.dispatch(e);
status = Q_TRAN(&Oven::active_idle);
}
break;
case STOP_SIG:{
me->m_timeout.disarm();
me->m_Oven_idle.dispatch(e);
status = Q_HANDLED();
break;
}
case OPEN_SIG:{
me->m_Oven_idle.dispatch(e);
status = Q_TRAN(&Oven::active_idle);
break;
}
case START_SIG:{
me->m_Oven_idle.dispatch(e);
status = Q_HANDLED();
break;
}
case Oven_idle_Start_SIG:{
if(!me->m_timeout.ctr())
{
me->m_timeout.postEvery(me, BSP_TICKS_PER_SEC);
}
else
{
me->m_timeout.rearm(BSP_TICKS_PER_SEC);
}
BSP_OVEN(true);
status = Q_HANDL