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,64 @@
#include <stdio.h>
#include "trace/trace.h"
#include "statemachine01.h"
/**
* Constructor
*
* \param repeatInterval Interval in milliseconds used in state machine.
* \param text Text to display by the state machine.
*/
StateMachine01::StateMachine01(int repeatInterval, string text)
: repeatInterval_(repeatInterval),
text_(text)
{
currentState_ = STATE_INITIAL;
}
StateMachine01::~StateMachine01()
{
}
XFEventStatus StateMachine01::processEvent()
{
eEventStatus eventStatus = XFEventStatus::Unknown;
switch (currentState_)
{
case STATE_INITIAL:
{
if (getCurrentEvent()->getEventType() == XFEvent::Initial)
{
GEN(XFDefaultTransition());
currentState_ = STATE_SAY_HELLO;
eventStatus = XFEventStatus::Consumed;
}
}
break;
case STATE_SAY_HELLO:
{
if (getCurrentEvent()->getEventType() == XFEvent::DefaultTransition ||
(getCurrentEvent()->getEventType() == XFEvent::Timeout &&
getCurrentTimeout()->getId() == Timeout_SAY_HELLO_id))
{
{
Trace::out(getText());
}
scheduleTimeout(Timeout_SAY_HELLO_id, getRepeatInterval());
currentState_ = STATE_SAY_HELLO;
eventStatus = XFEventStatus::Consumed;
}
}
break;
default:
break;
}
return eventStatus;
}

View File

@ -0,0 +1,56 @@
#ifndef STATEMACHINE01_H
#define STATEMACHINE01_H
#include "xf/behavior.h"
#include <string>
using namespace std;
/**
* \ingroup test01
*
* Task implementing a little state machine saying something
* in a predefined time interval.
*
* Following you will find the state machine implemented by StateMachine01:
* \image html state-machine01.png "State Machine implemented by StateMachine01"
*/
class StateMachine01 : public XFBehavior
{
public:
StateMachine01(int repeatInterval, string text);
~StateMachine01() override;
protected:
XFEventStatus processEvent() override; ///< Remplementation from XFBehavior
inline int getRepeatInterval() const { return repeatInterval_; } ///< Returns repeat interval. Accessor for #_repeatInterval.
inline string getText() const { return text_; } ///< Returns text. Accessor for #_text.
protected:
/**
* Timeout identifier(s) for this state machine
*/
typedef enum
{
Timeout_SAY_HELLO_id = 1 ///< Timeout id for WAIT
} eTimeoutId;
/**
* Enumeration used to have a unique identifier for every
* state in the state machine.
*/
typedef enum
{
STATE_UNKNOWN = 0, ///< Unknown state
STATE_INITIAL = 1, ///< Initial state
STATE_SAY_HELLO = 2 ///< Say hello state
} eMainState;
eMainState currentState_; ///< Attribute indicating currently active state
int repeatInterval_; ///< Interval in milliseconds to repeat text in state machine
string text_; ///< Text to display in state machine state
};
#endif // STATEMACHINE01_H

View File

@ -0,0 +1,36 @@
#include "xf/xf.h"
#include "trace/trace.h"
#include "testfactory01.h"
void Factory_initialize()
{
TestFactory01::initialize();
}
void Factory_build()
{
TestFactory01::build();
}
StateMachine01 TestFactory01::task01_(1000, "Say Hello");
StateMachine01 TestFactory01::task02_(500, "Echo");
TestFactory01::TestFactory01()
{
}
// static
void TestFactory01::initialize()
{
}
// static
void TestFactory01::build()
{
Trace::out("Starting test1...");
Trace::out("---------------------");
// Start state machine
task01_.startBehavior();
task02_.startBehavior();
}

View File

@ -0,0 +1,45 @@
#ifndef TESTFACTORY01_H
#define TESTFACTORY01_H
//
// What is seen only by the C++ compiler
//
#ifdef __cplusplus
#include "statemachine01.h"
/**
* \ingroup test01
*
* Factory creating all objects used in test1.
*
*/
class TestFactory01
{
public:
TestFactory01(); ///< Constructor
static void initialize(); ///< Initializes the factory
static void build(); ///< Creates components and initializes relations
protected:
static StateMachine01 task01_; ///< First instance of StateMachine01
static StateMachine01 task02_; ///< Second instance of StateMachine01
};
#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 // TESTFACTORY01_H

View File

@ -0,0 +1,14 @@
#include "xf/xf.h"
#include "app/testfactory01.h"
int main(int argc, char *argv[])
{
XF::initialize(20, argc, argv);
TestFactory01 factory;
factory.initialize();
factory.build();
return XF::exec();
}