Initial commit

This commit is contained in:
2023-09-19 15:59:49 +02:00
commit bef0bade14
1860 changed files with 582828 additions and 0 deletions

View File

@ -0,0 +1,92 @@
#include <cassert>
#include "trace/trace.h"
#include "events/evrestart.h"
#include "statemachine04a.h"
StateMachine04a::StateMachine04a()
: pNeighbour_(nullptr)
{
currentState_ = STATE_INITIAL;
}
StateMachine04a::~StateMachine04a()
{
}
/**
* Sets the association to the neighbour state machine.
* Call this method prior the start the state machine.
*/
void StateMachine04a::setNeighbour(XFBehavior * pNeighbour)
{
pNeighbour_ = pNeighbour;
}
/**
* Returns reference to neighbour state machine.
*/
XFBehavior * StateMachine04a::getNeighbour() const
{
assert(pNeighbour_);
return pNeighbour_;
}
/**
* Implements state machine behavior.
*/
XFEventStatus StateMachine04a::processEvent()
{
eEventStatus eventStatus = XFEventStatus::Unknown;
switch (currentState_)
{
case STATE_INITIAL:
{
if (getCurrentEvent()->getEventType() == XFEvent::Initial)
{
GEN(XFDefaultTransition());
currentState_ = STATE_WAIT;
eventStatus = XFEventStatus::Consumed;
}
}
break;
case STATE_WAIT:
{
if (getCurrentEvent()->getEventType() == XFEvent::DefaultTransition)
{
{
Trace::out("SM04a: Wait");
}
scheduleTimeout(Timeout_WAIT_id, 4500);
currentState_ = STATE_SEND_RESTART;
eventStatus = XFEventStatus::Consumed;
}
}
break;
case STATE_SEND_RESTART:
{
if (getCurrentEvent()->getEventType() == XFEvent::Timeout &&
getCurrentTimeout()->getId() == Timeout_WAIT_id)
{
{
Trace::out("SM04a: Send restart to SM04b");
getNeighbour()->GEN(evRestart());
}
GEN(XFDefaultTransition());
currentState_ = STATE_WAIT;
eventStatus = XFEventStatus::Consumed;
}
}
break;
default:
break;
}
return eventStatus;
}

View File

@ -0,0 +1,54 @@
#ifndef STATEMACHINE04A_H
#define STATEMACHINE04A_H
#include <string>
#include "xf/behavior.h"
/**
* \ingroup test04
*
* Implements a state machine sending its neighbour state machine
* an \a evRestart event every four seconds.
*
* Following you will find the state machine implemented by StateMachine04a:
* \image html state-machine04a.png "State Machine implemented by StateMachine04"
*/
class StateMachine04a : public XFBehavior
{
public:
StateMachine04a(); ///< Constructor
~StateMachine04a() override;
void setNeighbour(XFBehavior * pNeighbour);
XFBehavior * getNeighbour() const;
protected:
XFEventStatus processEvent() override;
protected:
/**
* Timeout identifier(s) for this state machine
*/
typedef enum
{
Timeout_WAIT_id = 1 ///< Timeout id for WAIT
} eTimeoutId;
/**
* Enumeration used to have a unique identifier for every
* state in the state machine.
*/
typedef enum
{
STATE_UNKOWN = 0, ///< Unknown state
STATE_INITIAL = 1, ///< Initial state
STATE_WAIT = 2, ///< Wait state
STATE_SEND_RESTART = 3 ///< State sending an restart event
} eMainState;
eMainState currentState_; ///< Attribute indicating currently active state
XFBehavior * pNeighbour_; ///< Association to the neigbour state machine
};
#endif // STATEMACHINE04A_H

View File

@ -0,0 +1,85 @@
#include <stdio.h>
#include "trace/trace.h"
#include "events/evrestart.h"
#include "statemachine04b.h"
StateMachine04b::StateMachine04b()
{
currentState_ = STATE_INITIAL;
}
StateMachine04b::~StateMachine04b()
{
}
/**
* Implements state machine behavior.
*/
XFEventStatus StateMachine04b::processEvent()
{
eEventStatus eventStatus = XFEventStatus::Unknown;
// Every time receiving an evRestart event, reset state machine
if (isRestartEvent())
{
// Remove any previous WAIT timeouts
unscheduleTimeout(Timeout_WAIT_id);
currentState_ = STATE_INITIAL;
}
switch (currentState_)
{
case STATE_INITIAL:
{
if (isRestartEvent() ||
getCurrentEvent()->getEventType() == XFEvent::Initial)
{
{
timeout_ = 0;
}
GEN(XFDefaultTransition());
currentState_ = STATE_WAIT;
eventStatus = XFEventStatus::Consumed;
}
}
break;
case STATE_WAIT:
{
if (getCurrentEvent()->getEventType() == XFEvent::DefaultTransition ||
isTimeoutEvent(Timeout_WAIT_id))
{
if (isTimeoutEvent(Timeout_WAIT_id))
{
Trace::out("SM04b: Timeout %d", ++timeout_);
}
scheduleTimeout(Timeout_WAIT_id, 1000);
currentState_ = STATE_WAIT;
eventStatus = XFEventStatus::Consumed;
}
}
break;
default:
break;
}
return eventStatus;
}
bool StateMachine04b::isTimeoutEvent(int timeoutId)
{
return (getCurrentEvent()->getEventType() == XFEvent::Timeout &&
getCurrentTimeout()->getId() == timeoutId);
}
bool StateMachine04b::isRestartEvent() const
{
return (getCurrentEvent()->getEventType() == XFEvent::Event &&
getCurrentEvent()->getId() == EventId::evRestart);
}

View File

@ -0,0 +1,53 @@
#ifndef STATEMACHINE04B_H
#define STATEMACHINE04B_H
#include <string>
#include "xf/behavior.h"
/**
* \ingroup test04
*
* Implements a state machine timeouting every second. It shows how many times
* the timeout has expired (using a #timeout_ attribute). The state machine can
* be reset by sending an \a evRestart event.
*
* Following you will find the state machine implemented by StateMachine04b:
* \image html state-machine04b.png "State Machine implemented by StateMachine04"
*/
class StateMachine04b : public XFBehavior
{
public:
StateMachine04b();
~StateMachine04b() override;
protected:
XFEventStatus processEvent() override;
bool isTimeoutEvent(int timeoutId); ///< Returns true in case state machine is currently processing a timeout.
bool isRestartEvent() const; ///< Returns true in case state machine is currently processing an \a evRestart event.
protected:
/**
* Timeout identifier(s) for this state machine
*/
typedef enum
{
Timeout_WAIT_id = 1 ///< Timeout id for WAIT
} eTimeoutId;
/**
* Enumeration used to have a unique identifier for every
* state in the state machine.
*/
typedef enum
{
STATE_UNKOWN = 0, ///< Unkown state
STATE_INITIAL = 1, ///< Initial state
STATE_WAIT = 2 ///< Wait for timeout state
} eMainState;
eMainState currentState_; ///< Attribute indicating currently active state
int timeout_; ///< Timeout attribute counting rised timeouts in state machine
};
#endif // STATEMACHINE04B_H

View File

@ -0,0 +1,39 @@
#include "xf/xf.h"
#include "trace/trace.h"
#include "testfactory04.h"
void Factory_initialize()
{
TestFactory04::initialize();
}
void Factory_build()
{
TestFactory04::build();
}
StateMachine04a TestFactory04::task01_;
StateMachine04b TestFactory04::task02_;
TestFactory04::TestFactory04()
{
}
// static
void TestFactory04::initialize()
{
}
// static
void TestFactory04::build()
{
Trace::out("Starting test4...");
Trace::out("---------------------");
// Set up association(s)
task01_.setNeighbour(&task02_);
// Start state machine(s)
task01_.startBehavior();
task02_.startBehavior();
}

View File

@ -0,0 +1,47 @@
#ifndef TESTFACTORY04_H
#define TESTFACTORY04_H
//
// What is seen only by the C++ compiler
//
#ifdef __cplusplus
#include "statemachine04a.h"
#include "statemachine04b.h"
/**
* \ingroup test04
*
* Factory creating all objects used in test4.
*
*/
class TestFactory04
{
public:
TestFactory04(); ///< Constructor
static void initialize(); ///< Initializes the factory
static void build(); ///< Creates components and initializes relations
protected:
static StateMachine04a task01_; ///< Instance of StateMachine04a
static StateMachine04b task02_; ///< Instance of StateMachine04b
};
#endif // __cplusplus
//
// What is seen by the C and C++ compiler
//
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void Factory_initialize();
void Factory_build();
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // TESTFACTORY03_H