Skip to content

Commit 981d570

Browse files
committed
Added Error State
1 parent 58de6d8 commit 981d570

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed

lib/ConvoyLeader/src/App.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "StartupState.h"
4545
#include "IdleState.h"
4646
#include "DrivingState.h"
47+
#include "ErrorState.h"
4748

4849
/******************************************************************************
4950
* Compiler Switches
@@ -227,6 +228,11 @@ void App::setLatestVehicleData(const Waypoint& waypoint)
227228
m_latestVehicleData = waypoint;
228229
}
229230

231+
void App::setErrorState()
232+
{
233+
m_systemStateMachine.setState(&ErrorState::getInstance());
234+
}
235+
230236
/******************************************************************************
231237
* Protected Methods
232238
*****************************************************************************/
@@ -373,6 +379,7 @@ void App_cmdRspChannelCallback(const uint8_t* payload, const uint8_t payloadSize
373379
if (RemoteControl::RSP_ID_ERROR == cmdRsp->responseId)
374380
{
375381
/* Go to error state. */
382+
application->setErrorState();
376383
}
377384
else if (RemoteControl::CMD_ID_GET_MAX_SPEED == cmdRsp->commandId)
378385
{

lib/ConvoyLeader/src/App.h

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ class App
100100
*/
101101
void setLatestVehicleData(const Waypoint& waypoint);
102102

103+
/**
104+
* Set error state.
105+
*/
106+
void setErrorState();
107+
103108
private:
104109
/** Minimum battery level in percent. */
105110
static const uint8_t MIN_BATTERY_LEVEL = 10U;

lib/ConvoyLeader/src/ErrorState.cpp

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* MIT License
2+
*
3+
* Copyright (c) 2023 - 2024 Andreas Merkle <web@blue-andi.de>
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
/*******************************************************************************
25+
DESCRIPTION
26+
*******************************************************************************/
27+
/**
28+
* @brief Error State.
29+
* @author Gabryel Reyes <gabryelrdiaz@gmail.com>
30+
*/
31+
32+
/******************************************************************************
33+
* Includes
34+
*****************************************************************************/
35+
36+
#include "ErrorState.h"
37+
#include <Util.h>
38+
39+
/******************************************************************************
40+
* Compiler Switches
41+
*****************************************************************************/
42+
43+
/******************************************************************************
44+
* Macros
45+
*****************************************************************************/
46+
47+
/******************************************************************************
48+
* Types and classes
49+
*****************************************************************************/
50+
51+
/******************************************************************************
52+
* Prototypes
53+
*****************************************************************************/
54+
55+
/******************************************************************************
56+
* Local Variables
57+
*****************************************************************************/
58+
59+
/******************************************************************************
60+
* Public Methods
61+
*****************************************************************************/
62+
63+
void ErrorState::entry()
64+
{
65+
m_isActive = true;
66+
m_releaseRequested = false;
67+
}
68+
69+
void ErrorState::process(StateMachine& sm)
70+
{
71+
UTIL_NOT_USED(sm);
72+
}
73+
74+
void ErrorState::exit()
75+
{
76+
m_isActive = false;
77+
}
78+
79+
/******************************************************************************
80+
* Protected Methods
81+
*****************************************************************************/
82+
83+
/******************************************************************************
84+
* Private Methods
85+
*****************************************************************************/
86+
87+
/******************************************************************************
88+
* External Functions
89+
*****************************************************************************/
90+
91+
/******************************************************************************
92+
* Local Functions
93+
*****************************************************************************/

lib/ConvoyLeader/src/ErrorState.h

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/* MIT License
2+
*
3+
* Copyright (c) 2023 - 2024 Andreas Merkle <web@blue-andi.de>
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
/*******************************************************************************
25+
DESCRIPTION
26+
*******************************************************************************/
27+
/**
28+
* @brief Error State.
29+
* @author Gabryel Reyes <gabryelrdiaz@gmail.com>
30+
*
31+
* @addtogroup Application
32+
*
33+
* @{
34+
*/
35+
#ifndef ERROR_STATE_H
36+
#define ERROR_STATE_H
37+
38+
/******************************************************************************
39+
* Compile Switches
40+
*****************************************************************************/
41+
42+
/******************************************************************************
43+
* Includes
44+
*****************************************************************************/
45+
46+
#include <IState.h>
47+
#include <StateMachine.h>
48+
49+
/******************************************************************************
50+
* Macros
51+
*****************************************************************************/
52+
53+
/******************************************************************************
54+
* Types and Classes
55+
*****************************************************************************/
56+
57+
/** The system error state. */
58+
class ErrorState : public IState
59+
{
60+
public:
61+
/**
62+
* Get state instance.
63+
*
64+
* @return State instance
65+
*/
66+
static ErrorState& getInstance()
67+
{
68+
static ErrorState instance; /* singleton idiom to force initialization in the first usage. */
69+
70+
return instance;
71+
}
72+
73+
/**
74+
* If the state is entered, this method will called once.
75+
*/
76+
void entry() final;
77+
78+
/**
79+
* Processing the state.
80+
*
81+
* @param[in] sm State machine, which is calling this state.
82+
*/
83+
void process(StateMachine& sm) final;
84+
85+
/**
86+
* If the state is left, this method will be called once.
87+
*/
88+
void exit() final;
89+
90+
protected:
91+
private:
92+
/** Flag: State is active. */
93+
bool m_isActive;
94+
95+
/** Flag: Release is requested. */
96+
bool m_releaseRequested;
97+
98+
/**
99+
* Default constructor.
100+
*/
101+
ErrorState() : IState(), m_isActive(false)
102+
{
103+
}
104+
105+
/**
106+
* Default destructor.
107+
*/
108+
virtual ~ErrorState()
109+
{
110+
}
111+
112+
/* Not allowed. */
113+
ErrorState(const ErrorState& state); /**< Copy construction of an instance. */
114+
ErrorState& operator=(const ErrorState& state); /**< Assignment of an instance. */
115+
};
116+
117+
/******************************************************************************
118+
* Functions
119+
*****************************************************************************/
120+
121+
#endif /* ERROR_STATE_H */
122+
/** @} */

0 commit comments

Comments
 (0)