SmartBox-Sortic
SmartFactory
BoxLevelCtrl.cpp
Go to the documentation of this file.
1 
14 #include "BoxLevelCtrl.h"
15 //=====PUBLIC====================================================================================
16 BoxLevelCtrl::BoxLevelCtrl() : currentState(State::emptyState), doActionFPtr(&BoxLevelCtrl::doAction_emptyState) {
17 }
18 
20  DBFUNCCALLln("BoxLevelCtrl::loop()");
21  process((this->*doActionFPtr)()); //do actions
22 }
23 
24 void BoxLevelCtrl::loop(Event currentEvent) {
25  DBFUNCCALLln("BoxLevelCtrl::loop(Event)");
27  process((this->*doActionFPtr)()); //do actions
28 }
29 
31  return currentState;
32 }
33 //=====PRIVATE====================================================================================
35  DBFUNCCALL("BoxLevelCtrl::process ")
36  DBEVENTln(String("DriveCtrl ") + String(decodeEvent(e)));
37  switch (currentState) {
38  case State::emptyState:
39  if (Event::CheckForPackage == e) {
40  exitAction_emptyState(); // Exit-action current state
41  entryAction_checking(); // Entry-actions next state
42  } else if (Event::Error == e) {
43  exitAction_emptyState(); // Exit-action current state
44  entryAction_errorState(); // Entry-actions next state
45  }
46  break;
47  case State::checking:
48  if (Event::PackageDetected == e) {
49  exitAction_checking(); // Exit-action current state
50  entryAction_fullState(); // Entry-actions next state
51  } else if (Event::NoPackageDetected == e) {
52  exitAction_checking(); // Exit-action current state
53  entryAction_emptyState(); // Entry-actions next state
54  } else if (Event::Error == e) {
55  exitAction_checking(); // Exit-action current state
56  entryAction_errorState(); // Entry-actions next state
57  }
58  break;
59  case State::fullState:
60  if (Event::CheckForPackage == e) {
61  exitAction_fullState(); // Exit-action current state
62  entryAction_checking(); // Entry-actions next state
63  } else if (Event::Error == e) {
64  exitAction_fullState(); // Exit-action current state
65  entryAction_errorState(); // Entry-actions next state
66  }
67  break;
68  case State::errorState:
69  if (Event::Resume == e) {
70  exitAction_errorState(); // Exit-action current state
71  switch (lastStateBevorError) {
72  case State::emptyState:
73  entryAction_emptyState(); // Entry-actions next state
74  break;
75  case State::checking:
76  entryAction_checking(); // Entry-actions next state
77  break;
78  case State::fullState:
79  entryAction_fullState(); // Entry-actions next state
80  break;
81  default:
82  break;
83  }
84  }
85  default:
86  break;
87  }
88 }
89 //==emptyState==========================================================
91  // DBSTATUSln("BL Entering State: emptyState");
92  currentState = State::emptyState; // state transition
94  digitalWrite(LOADINDICATOR_LED, LOW);
95 }
96 
98  // DBINFO1ln("BL State: emptyState");
99  //Generate the Event
100  return Event::NoEvent;
101 }
102 
104  // DBSTATUSln("BL Leaving State: emptyState");
105 }
106 
107 //==checking==========================================================
109  // DBSTATUSln("BL Entering State: checking");
110  currentState = State::checking; // state transition
112 }
113 
115  // DBINFO1ln("BL State: checking");
116  if (pSensorArray.getSensorData()) {
117  return Event::PackageDetected;
118  } else {
120  };
121  return Event::NoEvent;
122 }
123 
125  // DBSTATUSln("BL Leaving State: checking");
126 }
127 
128 //==fullState==========================================================
130  // DBSTATUSln("BL Entering State: fullState");
131  currentState = State::fullState; // state transition
133  digitalWrite(LOADINDICATOR_LED, HIGH);
134 }
135 
137  // DBINFO1ln("BL State: fullState");
138  //Generate the Event
139 
140  return Event::NoEvent;
141 }
142 
144  // DBSTATUSln("BL Leaving State: fullState");
145 }
146 
147 //==errorState========================================================
149  DBERROR("BL Entering State: errorState");
151  currentState = State::errorState; // state transition
153 }
154 
156  DBINFO1ln("BL State: errorState");
157  //Generate the Event
158 
159  return Event::NoEvent;
160 }
161 
163  DBSTATUSln("BL Leaving State: errorState");
164 }
165 
166 //============================================================================
167 //==Aux-Function==============================================================
169  switch (state) {
170  case State::emptyState:
171  return "State::emptyState";
172  break;
173  case State::fullState:
174  return "State::fullState";
175  break;
176  case State::checking:
177  return "State::checking";
178  break;
179  case State::errorState:
180  return "State::errorState";
181  break;
182  default:
183  return "ERROR: No matching state";
184  break;
185  }
186 }
187 
189  switch (event) {
191  return "Event::PackageDetected";
192  break;
194  return "Event::NoPackageDetected";
195  break;
197  return "Event::CheckForPackage";
198  break;
199  case Event::Error:
200  return "Event::Error";
201  break;
202  case Event::Resume:
203  return "Event::Resume";
204  break;
205  case Event::NoEvent:
206  return "Event::NoEvent";
207  break;
208  default:
209  return "ERROR: No matching event";
210  break;
211  }
212 }
#define DBEVENTln(x)
State lastStateBevorError
holds the last state of the FSM so it's possible to resume after error
Definition: BoxLevelCtrl.h:89
The BoxLevel Controll class contains the FSM for the BoxLevel.
Definition: BoxLevelCtrl.h:28
void exitAction_emptyState()
executes the exit action of the emptyState
String decodeEvent(Event event)
Decodes the Event-Enum and returns a description.
#define DBINFO1ln(x)
void exitAction_errorState()
exit action of the errorState
Event
Enum holds all possible events.
Definition: BoxLevelCtrl.h:35
String decodeState(State state)
Decodes the State-Enum and returns a description.
const int LOADINDICATOR_LED
PIn for Loadindicator LED.
void entryAction_fullState()
executes the entry action of the fullState
BoxLevelCtrl::Event doAction_checking()
executes the main action of the checking
BoxLevelCtrl()
Construct a new Box Level Ctrl object and initailize the currentState with emptyState.
bool getSensorData()
Read the Sensor Values.
Definition: SensorArray.cpp:34
void process(Event e)
changes the state of the FSM based on the event
BoxLevelCtrl::Event doAction_errorState()
main action of the errorState
void loop()
Calls the do-function of the active state and hence generates Events.
void entryAction_emptyState()
executes the entry action of the emptyState
void exitAction_checking()
executes the exit action of the checking
Ext.: Check for package.
The BoxLevel Controll class contains the FSM for the BoxLevel.
#define DBERROR(x)
Ext.:Resume after Error occured.
State
Enum holds all possible states.
Definition: BoxLevelCtrl.h:47
BoxLevelCtrl::Event doAction_emptyState()
executes the main action of the emptyState
BoxLevelCtrl::Event doAction_fullState()
executes the main action of the fullState
void entryAction_errorState()
entry action of the errorState
#define DBFUNCCALLln(x)
#define DBSTATUSln(x)
const State getcurrentState()
Get the current State.
Event currentEvent
holds the current event of the FSM
Definition: BoxLevelCtrl.h:91
SensorArray pSensorArray
SensorArray Object.
Definition: BoxLevelCtrl.h:100
#define DBFUNCCALL(x)
State currentState
holds the current state of the FSM
Definition: BoxLevelCtrl.h:90
void entryAction_checking()
executes the entry action of the checking
void exitAction_fullState()
executes the exit action of the fullState
Event(BoxLevelCtrl::* doActionFPtr)(void)
Functionpointer to call the current states do-function.
Definition: BoxLevelCtrl.h:98
No event generated.