SmartBox-Sortic
SmartFactory
BoxCtrl.h
Go to the documentation of this file.
1 
14 #ifndef BOXCTRL_H__
15 #define BOXCTRL_H__
16 
17 #include <Arduino.h>
18 
19 // own files:
20 #include "MainConfiguration.h"
21 
22 #include "BoxLevelCtrl.h"
23 #include "MQTTCommunication.h"
24 
30 class BoxCtrl {
31  //=====PUBLIC====================================================================================
32  public:
37  enum class Sector {
45  Parking,
51  error
52  };
53 
58  struct Box {
59  String id = DEFAULT_HOSTNAME;
60  // Sector actualSector = Sector::TransferHandover; ///< actual sector initialise with Sortic handover
63  String cargo = "";
64  String status = "null";
65  String ack = "null";
66  String req = "null";
67  } box;
68 
73  enum class Event { SBReadyForTransport,
74  SBReady,
75  CalcOptVal,
78  Error,
79  Reset,
80  Resume,
81  NoEvent
82  };
83 
88  BoxCtrl();
93  void loop();
94 
100  void loop(Event currentEvent);
101 
102  //=====PRIVATE====================================================================================
103  private:
109  void process(Event e);
110 
116  enum class State { readSensorVal,
120  waitForAck,
122  resetState,
123  errorState
124  };
125 
129 
135  Event (BoxCtrl::*doActionFPtr)(void) = nullptr;
136 
138  Communication pComm = Communication(DEFAULT_HOSTNAME);
139 
140  unsigned long currentMillis = 0;
141  unsigned long previousMillis = 0;
142  unsigned long previousMillisPublish = 0;
143 
144  //=====StateFunctions===============================================================
145  //==readSensorVal==========================================================
151  void
153 
165 
171 
172  //==waitForVehicle==========================================================
182 
194 
201 
202  //==calculateOptVehicle==========================================================
209 
223 
229 
230  //==publishOptVehicle==========================================================
238 
248 
254 
255  //==waitForAck==========================================================
260  void entryAction_waitForAck();
261 
274 
281  void exitAction_waitForAck();
282 
283  //==waitForTransport==========================================================
291 
300 
307 
308  //==errorState==========================================================
313  void entryAction_errorState();
314 
321 
326  void exitAction_errorState();
327 
328  //==resetState==========================================================
333  void entryAction_resetState();
334 
341 
346  void exitAction_resetState();
347  //============================================================================
348  //==Aux-Function==============================================================
355  String decodeState(State state);
356 
363  String decodeEvent(Event event);
364 
371  String decodeSector(Sector sector);
372 
379  BoxCtrl::Sector decodeSector(String sector);
380 
385  void publishPosition();
386 
392  void publishState(State state);
393 
400  bool checkForError();
401 
406  void clearGui();
407 };
408 #endif
BoxCtrl::Event doAction_waitForTransport()
main action of the waitForTransport
Definition: BoxCtrl.cpp:439
BoxCtrl::Event doAction_resetState()
main action of the resetState
Definition: BoxCtrl.cpp:514
Box class contains all relevant information about the box and its actual state.
Definition: BoxCtrl.h:58
BoxCtrl::Event doAction_readSensorVal()
main action of the readSensorVal
Definition: BoxCtrl.cpp:165
The BoxLevel Controll class contains the FSM for the BoxLevel.
Definition: BoxLevelCtrl.h:28
void entryAction_waitForVehicle()
entry action of the waitForVehicle
Definition: BoxCtrl.cpp:215
void entryAction_publishOptVehicle()
entry action of the publishOptVehicle
Definition: BoxCtrl.cpp:322
String decodeState(State state)
Decodes the State-Enum and returns a description.
Definition: BoxCtrl.cpp:538
void entryAction_waitForAck()
entry action of the waitForAck publish state to "Box/box.id/status"
Definition: BoxCtrl.cpp:379
State lastStateBevorError
holds the last state of the FSM so it's possible to resume after error
Definition: BoxCtrl.h:126
unsigned long currentMillis
store current time
Definition: BoxCtrl.h:140
String req
req for handshake vehicle
Definition: BoxCtrl.h:66
Sector
Sector class holds all possible position on the gametable.
Definition: BoxCtrl.h:37
Error occured.
wait for available vehicle
The Box Controll class contains the FSM for the complete Box.
Definition: BoxCtrl.h:30
unsigned long previousMillisPublish
store last publish time
Definition: BoxCtrl.h:142
BoxLevelCtrl pBoxlevelctrl
instance ot BoxLevelCtrl
Definition: BoxCtrl.h:137
Sector actualSector
actual sector initialise with Sortic handover
Definition: BoxCtrl.h:61
void exitAction_calculateOptVehicle()
exit action of the calculateOptVehicle
Definition: BoxCtrl.cpp:316
BoxCtrl::Event doAction_publishOptVehicle()
main action of the publishOptVehicle
Definition: BoxCtrl.cpp:334
State currentState
holds the current state of the FSM
Definition: BoxCtrl.h:127
BoxCtrl::Event doAction_calculateOptVehicle()
main action of the calculateOptVehicle
Definition: BoxCtrl.cpp:275
String ack
ack for handshake vehicle
Definition: BoxCtrl.h:65
Event
Enum holds all possible events.
Definition: BoxCtrl.h:73
Transit - Wait for Gateway Transfer.
void publishState(State state)
Publish actual state via communication.
Definition: BoxCtrl.cpp:696
bool checkForError()
Check if the last message was an error.
Definition: BoxCtrl.cpp:683
void entryAction_readSensorVal()
entry action of the readSensorVal
Definition: BoxCtrl.cpp:150
State
Enum holds all possible state's.
Definition: BoxCtrl.h:116
void process(Event e)
changes the state of the FSM based on the event
Definition: BoxCtrl.cpp:41
BoxCtrl()
Construct a new Box Ctrl object.
Definition: BoxCtrl.cpp:15
void exitAction_readSensorVal()
exit action of the readSensorVal
Definition: BoxCtrl.cpp:209
void exitAction_waitForVehicle()
exit action of the waitForVehicle
Definition: BoxCtrl.cpp:262
Error - Used to throw parseerror.
struct BoxCtrl::Box box
Sortic - Wait for Gateway.
Wait for Transport from vehicle.
Transfer - wait for Gateway.
void exitAction_waitForTransport()
exit action of the waitForTransport
Definition: BoxCtrl.cpp:462
Reset after Error occured.
Transit - Wait for Gateway Sortic.
void entryAction_errorState()
entry action of the errorState
Definition: BoxCtrl.cpp:469
Calculate desired vehicle.
void exitAction_errorState()
exit action of the errorState
Definition: BoxCtrl.cpp:498
Calculated Optimum Value.
String decodeEvent(Event event)
Decodes the Event-Enum and returns a description.
Definition: BoxCtrl.cpp:570
Resume after Error occured.
String cargo
cargo;
Definition: BoxCtrl.h:63
String status
status of the Box FSM
Definition: BoxCtrl.h:64
contains the default configuration for the smartbox
void exitAction_resetState()
exit action of the resetState
Definition: BoxCtrl.cpp:529
String decodeSector(Sector sector)
Decodes the Sector-Enum and returns a description.
Definition: BoxCtrl.cpp:605
BoxCtrl::Event doAction_errorState()
main action of the errorState
Definition: BoxCtrl.cpp:478
Communication pComm
instance of Communication with Box.id/hostname
Definition: BoxCtrl.h:138
#define DEFAULT_HOSTNAME
Hostname used for identification of SV.
The BoxLevel Controll class contains the FSM for the BoxLevel.
void entryAction_calculateOptVehicle()
entry action of the calculateOptVehicle
Definition: BoxCtrl.cpp:268
Parking (not used atm)
Wait for ack. from vehicle.
void entryAction_resetState()
entry action of the resetState
Definition: BoxCtrl.cpp:504
BoxCtrl::Event doAction_waitForAck()
main action of the waitForAck
Definition: BoxCtrl.cpp:389
SB is ready for transport.
No event generated.
int actualLine
actual line
Definition: BoxCtrl.h:62
void publishPosition()
publish actual position via communication
Definition: BoxCtrl.cpp:701
void entryAction_waitForTransport()
entry action of the waitForTransport
Definition: BoxCtrl.cpp:430
unsigned long previousMillis
store last time
Definition: BoxCtrl.h:141
void loop()
Calls the do-function of the active state and hence generates Events.
Definition: BoxCtrl.cpp:29
const int DEFAUL_HOSTNAME_NUMBER
Number of the Vehicle. Used to dermine startline and for GUI.
BoxCtrl::Event doAction_waitForVehicle()
main action of the waitForVehicle
Definition: BoxCtrl.cpp:235
void exitAction_publishOptVehicle()
exit action of the publishOptVehicle
Definition: BoxCtrl.cpp:374
Publishe desired vehicle.
void exitAction_waitForAck()
exit action of the waitForAck
Definition: BoxCtrl.cpp:423
void clearGui()
clear all box related gui entrys
Definition: BoxCtrl.cpp:705
Event(BoxCtrl::* doActionFPtr)(void)
Functionpointer to call the current states do-function.
Definition: BoxCtrl.h:135
Event currentEvent
holds the current event of the FSM
Definition: BoxCtrl.h:128