SmartBox-Sortic
SmartFactory
BoxCtrl.cpp
Go to the documentation of this file.
1 
13 #include "BoxCtrl.h"
14 //=====PUBLIC====================================================================================
15 BoxCtrl::BoxCtrl() : currentState(State::readSensorVal), doActionFPtr(&BoxCtrl::doAction_readSensorVal) {
16  DBFUNCCALLln("BoxCtrl::BoxCtrl()");
17  delay(100);
18  clearGui();
20  pComm.unsubscribe("#");
21  pComm.subscribe("Box/" + String(box.id) + "/error");
22  pComm.subscribe("Box/error");
23  pComm.subscribe("error");
24  delay(100);
27 }
28 
29 void BoxCtrl::loop() {
30  DBFUNCCALLln("BoxCtrl::loop()");
31  process((this->*doActionFPtr)()); //do actions
32 }
33 
34 void BoxCtrl::loop(Event currentEvent) {
35  DBFUNCCALLln("BoxCtrl::loop(Event)");
37  process((this->*doActionFPtr)()); //do actions
38 }
39 
40 //=====PRIVATE====================================================================================
42  DBFUNCCALL("BoxCtrl::process ")
43  DBEVENTln(String("BoxCtrl ") + decodeEvent(e));
44  switch (currentState) {
46  if (Event::SBReadyForTransport == e) {
47  exitAction_readSensorVal(); // Exit-action current state
48  entryAction_waitForVehicle(); // Entry-actions next state
49  } else if (Event::Error == e) {
50  exitAction_readSensorVal(); // Exit-action current state
51  entryAction_errorState(); // Entry-actions next state
52  }
53  break;
55  if (Event::AnswerReceived == e) {
56  exitAction_waitForVehicle(); // Exit-action current state
57  entryAction_calculateOptVehicle(); // Entry-actions next state
58  } else if (Event::Error == e) {
59  exitAction_waitForVehicle(); // Exit-action current state
60  entryAction_errorState(); // Entry-actions next state
61  }
62  break;
64  if (Event::CalcOptVal == e) {
65  exitAction_calculateOptVehicle(); // Exit-action current state
66  entryAction_publishOptVehicle(); // Entry-actions next state
67  } else if (Event::NoAnswerReceived == e) {
68  exitAction_calculateOptVehicle(); // Exit-action current state
69  entryAction_waitForVehicle(); // Entry-actions next state
70  } else if (Event::Error == e) {
71  exitAction_calculateOptVehicle(); // Exit-action current state
72  entryAction_errorState(); // Entry-actions next state
73  }
74  break;
76  if (Event::AnswerReceived == e) {
77  exitAction_publishOptVehicle(); // Exit-action current state
78  entryAction_waitForAck(); // Entry-actions next state
79  } else if (Event::NoAnswerReceived == e) {
80  exitAction_publishOptVehicle(); // Exit-action current state
81  entryAction_waitForVehicle(); // Entry-actions next state
82  } else if (Event::Error == e) {
83  exitAction_publishOptVehicle(); // Exit-action current state
84  entryAction_errorState(); // Entry-actions next state
85  }
86  break;
87  case State::waitForAck:
88  if (Event::AnswerReceived == e) {
89  exitAction_waitForAck(); // Exit-action current state
90  entryAction_waitForTransport(); // Entry-actions next state
91  } else if (Event::NoAnswerReceived == e) {
92  exitAction_waitForAck(); // Exit-action current state
93  entryAction_waitForVehicle(); // Entry-actions next state
94  } else if (Event::Error == e) {
95  exitAction_waitForAck(); // Exit-action current state
96  entryAction_errorState(); // Entry-actions next state
97  }
98  break;
100  if (Event::SBReady == e) {
101  exitAction_waitForTransport(); // Exit-action current state
102  entryAction_readSensorVal(); // Entry-actions next state
103  } else if (Event::Error == e) {
104  exitAction_waitForTransport(); // Exit-action current state
105  entryAction_errorState(); // Entry-actions next state
106  }
107  break;
108  case State::errorState:
109  if (Event::Resume == e) {
110  exitAction_errorState(); // Exit-action current state
111  switch (lastStateBevorError) {
113  entryAction_readSensorVal(); // Entry-actions next state
114  break;
116  entryAction_waitForVehicle(); // Entry-actions next state
117  break;
119  entryAction_calculateOptVehicle(); // Entry-actions next state
120  break;
122  entryAction_publishOptVehicle(); // Entry-actions next state
123  break;
124  case State::waitForAck:
125  entryAction_waitForAck(); // Entry-actions next state
126  break;
128  entryAction_waitForTransport(); // Entry-actions next state
129  break;
130  default:
131  break;
132  }
133  }
134  if (Event::Reset == e) {
135  exitAction_errorState(); // Exit-action current state
136  entryAction_resetState(); // Entry-actions next state
137  }
138  break;
139  case State::resetState:
140  if (Event::Resume == e) {
141  exitAction_resetState(); // Exit-action current state
142  entryAction_readSensorVal(); // Entry-actions next state
143  }
144  break;
145  default:
146  break;
147  }
148 }
149 //==readSensorVal========================================================
151  DBSTATUSln("Entering State: emptyState");
152  currentState = State::readSensorVal; // state transition
154  publishState(currentState); //Update Current State and Publish
155  publishPosition();
156  pComm.clear();
158  pComm.subscribe("Sortic/Handover");
159  }
160  previousMillis = millis();
163 }
164 
166  DBINFO1ln("State: emptyState");
167  //Generate the Event
168  pComm.loop(); //Check for new Messages
169  if (checkForError()) {
170  return Event::Error;
171  }
172 
173  currentMillis = millis();
174  // Publish/Block HandoverPosition
176  //only publish all xx seconds
177  previousMillisPublish = millis();
179  pComm.publishMessage("Sortic/Handover", "{\"id\":\"" + String(box.id) + "\",\"sector\":\"" + decodeSector(box.actualSector) + "\",\"line\":" + String(box.actualLine) + "}");
180  } else if (box.actualSector == Sector::TransferHandover) {
181  pComm.publishMessage("Transfer/Handover", "{\"id\":\"" + String(box.id) + "\",\"sector\":\"" + decodeSector(box.actualSector) + "\",\"line\":" + String(box.actualLine) + "}");
182  }
183  }
184 
188  if (!pComm.isEmpty()) {
189  myJSONStr temp = pComm.pop();
190  //Check if message is from req vehicle and if vehicle does req the correct box
191  if ((temp.line == box.actualLine) && (temp.id = String("Sortic")) && (temp.cargo.length() != 0) && (temp.cargo != String("null"))) {
192  box.cargo = temp.cargo;
193  pComm.publishMessage("Box/" + String(box.id) + "/cargo", "{\"cargo\":\"" + String(box.cargo) + "\"}");
195  }
196  }
197 
200  box.cargo = String("Empty");
201  pComm.publishMessage("Box/" + String(box.id) + "/cargo", "{\"cargo\":\"Empty\"}");
202  //Update BoxPosition
204  }
205 
206  return Event::NoEvent;
207 }
208 
210  DBSTATUSln("Leaving State: emptyState");
211  pComm.unsubscribe("Sortic/Handover");
212 }
213 
214 //==waitForVehicle========================================================
216  DBSTATUSln("Entering State: waitForVehicle");
217  currentState = State::waitForVehicle; // state transition
219  publishState(currentState); //Update Current State and Publish
220 
221  previousMillis = millis();
224  //Subscribe to Topics
225  pComm.subscribe("Vehicle/+/available");
226  // pComm.unsubscribe("Vehicle/+/handshake");
227  // pComm.unsubscribe("Vehicle/V1/handshake");
228  pComm.unsubscribe("Vehicle/" + String(box.req) + "/handshake");
229  pComm.clear();
230  //Update Box Infos
231  box.ack = "null";
232  box.req = "null";
233 }
234 
236  DBINFO1ln("State: waitForVehicle");
237  pComm.loop(); //Check for new Messages
238  if (checkForError()) {
239  return Event::Error;
240  }
241 
242  currentMillis = millis();
243  // Publish/Block HandoverPosition
244  if ((currentMillis - previousMillisPublish) > TIME_BETWEEN_PUBLISH) { //only publish all xx seconds
245  previousMillisPublish = millis();
247  pComm.publishMessage("Sortic/Handover", "{\"id\":\"" + String(box.id) + "\",\"sector\":\"" + decodeSector(box.actualSector) + "\",\"line\":" + String(box.actualLine) + "}");
248  } else if (box.actualSector == Sector::TransferHandover) {
249  pComm.publishMessage("Transfer/Handover", "{\"id\":\"" + String(box.id) + "\",\"sector\":\"" + decodeSector(box.actualSector) + "\",\"line\":" + String(box.actualLine) + "}");
250  }
251  }
252 
253  //wait time or max response
254  currentMillis = millis();
255  if ((NUM_OF_MAXVALUES_VEHICLES_STORE + 1 < pComm.size()) ||
256  (((currentMillis - previousMillis) > SMARTBOX_WAITFOR_VEHICLES_SECONDS * 1000) && 0 < pComm.size())) {
257  return Event::AnswerReceived;
258  }
259  return Event::NoEvent;
260 }
261 
263  DBSTATUSln("Leaving State: waitForVehicle");
264  pComm.unsubscribe("Vehicle/+/available");
265 }
266 
267 //==calculateOptVehicle========================================================
269  DBSTATUSln("Entering State: calculateOptVehicle");
270  currentState = State::calculateOptVehicle; // state transition
272  publishState(currentState); //Update Current State and Publish
273 }
274 
276  DBINFO1ln("State: calculateOptVehicle");
277  //Check all saved Messages and save the best Vehicles to an Array
278  //Generate the Event
279  // pComm.loop(); //Check for new Messages
280  // if (checkForError()) {
281  // return Event::Error;
282  // }
283 
284  DBINFO3ln(String("BuffSize: ") + String(pComm.size()));
285  int size = pComm.size();
286  // myJSONStr nearestVehicleStr = pComm.getElement(0);
287  myJSONStr nearestVehicleStr = pComm.pop();
288  myJSONStr temp;
289 
290  for (int i = 0; i < size; i++) {
291  // temp = pComm.getElement(i);
292  if (!pComm.isEmpty()) {
293  temp = pComm.pop();
294  DBINFO3ln(decodeSector(box.actualSector) + String("==") + temp.sector);
295  //Check if actual sector same as sector from vehicle
296  if (decodeSector(box.actualSector) == temp.sector) {
297  DBINFO3ln(String(abs(temp.line - box.actualLine)) + String(" < ") + String(abs(nearestVehicleStr.line - box.actualLine)));
298  //Check if this vehicle is nearer than the actual near vehicle
299  if (abs(temp.line - box.actualLine) < abs(nearestVehicleStr.line - box.actualLine)) {
300  //load nearestVehcile with actual vehicle if necessary
301  nearestVehicleStr = temp;
302  }
303  }
304  }
305  }
306 
307  if (nearestVehicleStr.line != 0 && decodeSector(nearestVehicleStr.sector) != BoxCtrl::Sector::error && decodeSector(nearestVehicleStr.sector) == box.actualSector) {
308  box.req = nearestVehicleStr.id;
309  return Event::CalcOptVal;
310  }
311 
313  // return
314 }
315 
317  DBSTATUSln("Leaving State: calculateOptVehicle");
318  // pComm.clear();
319 }
320 
321 //==publishOptVehicle========================================================
323  DBSTATUSln("Entering State: publishOptVehicle");
324  currentState = State::publishOptVehicle; // state transition
326  publishState(currentState); //Update Current State and Publish
327  //Subscribe to Topics
328  pComm.subscribe("Vehicle/" + String(box.req) + "/handshake");
329  previousMillis = millis();
332 }
333 
335  DBINFO1ln("State: publishOptVehicle");
336 
337  pComm.loop(); //Check for new Messages
338  if (checkForError()) {
339  return Event::Error;
340  }
341 
342  currentMillis = millis();
343 
344  //Publish decision
345  currentMillis = millis();
346  if ((currentMillis - previousMillisPublish) > TIME_BETWEEN_PUBLISH) { //only publish all xx seconds
347  previousMillisPublish = millis();
348  pComm.publishMessage("Box/" + String(box.id) + "/handshake", "{\"id\":\"" + String(box.id) + "\",\"req\":\"" + String(box.req) + "\"}");
349  if (box.actualSector == Sector::SorticHandover) { // Publish/Block HandoverPosition
350  pComm.publishMessage("Sortic/Handover", "{\"id\":\"" + String(box.id) + "\",\"sector\":\"" + decodeSector(box.actualSector) + "\",\"line\":" + String(box.actualLine) + "}");
351  } else if (box.actualSector == Sector::TransferHandover) {
352  pComm.publishMessage("Transfer/Handover", "{\"id\":\"" + String(box.id) + "\",\"sector\":\"" + decodeSector(box.actualSector) + "\",\"line\":" + String(box.actualLine) + "}");
353  }
354  }
355 
356  //Wait for response
358  if (!pComm.isEmpty()) {
359  myJSONStr temp = pComm.pop();
360  //Check if message is from req vehicle and if vehicle does req the correct box
361  if (temp.req == box.id && temp.id == box.req) {
362  box.ack = temp.id;
363  return Event::AnswerReceived;
364  }
365  }
366  } else {
368  }
369 
370  //Generate the Event
371  return Event::NoEvent;
372 }
373 
375  DBSTATUSln("Leaving State: publishOptVehicle");
376 }
377 
378 //==waitForAck========================================================
380  DBSTATUSln("Entering State: waitForAck");
381  currentState = State::waitForAck; // state transition
383  publishState(currentState); //Update Current State and Publish
384  previousMillis = millis();
387 }
388 
390  DBINFO1ln("State: waitForAck");
391  currentMillis = millis();
392  //read responses
393  //check for ack from vehicle
394  //Generate the Event
395  pComm.loop(); //Check for new Messages
396  if (checkForError()) {
397  return Event::Error;
398  }
399 
400  if ((currentMillis - previousMillisPublish) > TIME_BETWEEN_PUBLISH) { //only publish all xx seconds
401  previousMillisPublish = millis();
402  // pComm.publishMessage("Box/" + String(box.id) + "/handshake", "{\"id\":\"" + String(box.id) + "\",\"ack\":\"" + String(box.ack) + "\"}");
403  pComm.publishMessage("Box/" + String(box.id) + "/handshake", "{\"id\":\"" + String(box.id) + "\",\"ack\":\"" + String(box.ack) + "\",\"sector\":\"" + decodeSector(box.actualSector) + "\",\"line\":" + String(box.actualLine) + ",\"cargo\":\"" + String(box.cargo) + "\"}");
404  }
405 
406  //Wait for response
408  DBINFO2ln("Wait for response");
409  if (!pComm.isEmpty()) {
410  myJSONStr temp = pComm.pop();
411  DBINFO2ln(String("temp.ack: ") + String(temp.ack) + String("==") + String("box.id: ") + String(box.id));
412  DBINFO2ln(String("temp.id: ") + String(temp.id) + String("==") + String("box.ack: ") + String(box.ack));
413  if ((temp.ack == box.id) && (temp.id == box.ack)) {
414  return Event::AnswerReceived;
415  }
416  }
417  } else {
419  }
420  return Event::NoEvent;
421 }
422 
424  DBSTATUSln("Leaving State: waitForAck");
425  // pComm.unsubscribe("Vehicle/+/handshake");
426  pComm.unsubscribe("Vehicle/" + String(box.req) + "/handshake");
427 }
428 
429 //==waitForTransport===================================================
431  DBSTATUSln("Entering State: waitForTransport");
432  currentState = State::waitForTransport; // state transition
434  publishState(currentState); //Update Current State and Publish
435  pComm.publishMessage("Box/" + String(box.id) + "/position", "{\"id\":\"" + String(box.id) + "\",\"sector\":\"" + String(box.ack) + "\",\"line\":\"" + String(box.ack) + "\"}");
436  pComm.subscribe("Box/" + String(box.id) + "/position");
437 }
438 
440  DBINFO1ln("State: waitForTransport");
441  //Generate the Event
442  //check message for transportconfirmation
443  pComm.loop(); //Check for new Messages
444  if (checkForError()) {
445  return Event::Error;
446  }
447  if (!pComm.isEmpty()) {
448  myJSONStr temp = pComm.pop();
449  DBINFO2ln(String("temp.id: ") + String(temp.id) + String("==") + String("box.ack: ") + String(box.ack));
450  DBINFO2ln(String("temp.sector: ") + String(temp.sector) + String("/") + String("temp.line: ") + String(temp.line));
451  Sector tempsector = decodeSector(temp.sector);
452  //Check for valid message form ack vehicle
453  if ((temp.id == box.ack) && (tempsector != BoxCtrl::Sector::error) && (temp.line != 0)) {
454  box.actualLine = temp.line;
455  box.actualSector = tempsector;
456  return Event::SBReady;
457  }
458  }
459  return Event::NoEvent;
460 }
461 
463  DBSTATUSln("Leaving State: waitForTransport");
464  //unsubscribe
465  pComm.unsubscribe("Box/" + String(box.id) + "/position");
466 }
467 
468 //==errorState========================================================
470  DBERROR("Entering State: errorState");
472  currentState = State::errorState; // state transition
474  publishState(currentState); //Update Current State and Publish
475  pComm.clear();
476 }
477 
479  DBINFO1ln("State: errorState");
480  //Generate the Event
481  pComm.loop(); //Check for new Messages
482  while (!pComm.isEmpty()) {
483  // if (!pComm.first().error) {
484  myJSONStr temp = pComm.pop();
485  if (temp.topic.endsWith("error")) { //check if message from an error-topic
486  if (!temp.error && !temp.token) {
487  // pComm.shift();
488  return Event::Resume;
489  } else if (temp.error && temp.token) {
490  // pComm.shift();
491  return Event::Reset;
492  }
493  }
494  }
495  return Event::NoEvent;
496 }
497 
499  DBSTATUSln("Leaving State: errorState");
500  pComm.clear();
501 }
502 
503 //==resetState========================================================
505  DBERROR("Entering State: resetState");
507  currentState = State::resetState; // state transition
509  clearGui();
510  publishState(currentState); //Update Current State and Publish
511  pComm.clear();
512 }
513 
515  DBINFO1ln("State: resetState");
516  //Generate the Event
517  pComm.loop(); //Check for new Messages
518  while (!pComm.isEmpty()) {
519  myJSONStr temp = pComm.pop();
520  if (temp.topic.endsWith("error")) { //check if message from an error-topic
521  if (!temp.error && !temp.token) {
522  return Event::Resume;
523  }
524  }
525  }
526  return Event::NoEvent;
527 }
528 
530  DBSTATUSln("Leaving State: resetState");
531  pComm.clear();
532  clearGui();
533  box = {}; //reset struct
534 }
535 
536 //============================================================================
537 //==Aux-Function==============================================================
539  switch (state) {
541  return "readSensorVal";
542  break;
544  return "waitForVehicle";
545  break;
547  return "calculateOptVehicle";
548  break;
550  return "publishOptVehicle";
551  break;
552  case State::waitForAck:
553  return "waitForAck";
554  break;
556  return "waitForTransport";
557  break;
558  case State::errorState:
559  return "errorState";
560  break;
561  case State::resetState:
562  return "resetState";
563  break;
564  default:
565  return "ERROR: No matching state";
566  break;
567  }
568 }
569 
571  switch (event) {
573  return "Event::SBReadyForTransport";
574  break;
575  case Event::SBReady:
576  return "Event::SBReady";
577  break;
578  case Event::CalcOptVal:
579  return "Event::CalcOptVal";
580  break;
582  return "Event::AnswerReceived";
583  break;
585  return "Event::NoAnswerReceived";
586  break;
587  case Event::Error:
588  return "Event::Error";
589  break;
590  case Event::Resume:
591  return "Event::Resume";
592  break;
593  case Event::Reset:
594  return "Event::Reset";
595  break;
596  case Event::NoEvent:
597  return "Event::NoEvent";
598  break;
599  default:
600  return "ERROR: No matching event";
601  break;
602  }
603 }
604 
606  switch (sector) {
608  return "SorticHandover";
609  break;
611  return "SorticToHandover";
612  break;
614  return "SorticWaitForGateway";
615  break;
617  return "SorticGateway";
618  break;
620  return "TransitWaitForGatewaySortic";
621  break;
623  return "TransitToSortic";
624  break;
626  return "TransitToTransfer";
627  break;
628  case Sector::Parking:
629  return "Parking";
630  break;
632  return "TransitWaitForGatewayTransfer";
633  break;
635  return "TransferGateway";
636  break;
638  return "TransferWaitForGateway";
639  break;
641  return "TransferToHandover";
642  break;
644  return "TransferHandover";
645  break;
646 
647  default:
648  return "ERROR: No matching sector";
649  break;
650  }
651 }
652 
654  if (String("SorticHandover") == sector) {
655  return Sector::SorticHandover;
656  } else if (String("SorticToHandover") == sector) {
658  } else if (String("SorticWaitForGateway") == sector) {
660  } else if (String("TransitWaitForGatewaySortic") == sector) {
662  } else if (String("TransitToSortic") == sector) {
664  } else if (String("TransitToTransfer") == sector) {
666  } else if (String("Parking") == sector) {
667  return Sector::Parking;
668  } else if (String("TransitWaitForGatewayTransfer") == sector) {
670  } else if (String("TransferGateway") == sector) {
672  } else if (String("TransferWaitForGateway") == sector) {
674  } else if (String("TransferToHandover") == sector) {
676  } else if (String("TransferHandover") == sector) {
678  } else {
679  return Sector::error;
680  }
681 }
682 
684  DBFUNCCALLln("BoxCtrl::checkForError()");
685  if (!pComm.isEmpty()) {
686  DBINFO3ln(pComm.size());
687  DBINFO3ln(pComm.last().error);
688  if (pComm.first().error) {
689  pComm.shift();
690  return true;
691  }
692  }
693  return false;
694 }
695 
697  box.status = decodeState(state);
698  pComm.publishMessage("Box/" + String(box.id) + "/status", "{\"status\":\"" + String(box.status) + "\"}");
699 }
700 
702  pComm.publishMessage("Box/" + String(box.id) + "/position", "{\"sector\":\"" + decodeSector(box.actualSector) + "\",\"line\":" + String(box.actualLine) + "}");
703 }
704 
706  pComm.publishMessage("Box/" + String(box.id) + "/status", "{\"status\":\"\"}");
707  pComm.publishMessage("Box/" + String(box.id) + "/position", "{\"sector\":\"\",\"line\":\"\"}");
708  pComm.publishMessage("Box/" + String(box.id) + "/cargo", "{\"cargo\":\"\"}");
709  pComm.publishMessage("Box/" + String(box.id) + "/handshake", "{\"ack\":\"\",\"req\":\"\"}");
710 }
#define DBEVENTln(x)
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
BoxCtrl::Event doAction_readSensorVal()
main action of the readSensorVal
Definition: BoxCtrl.cpp:165
void entryAction_waitForVehicle()
entry action of the waitForVehicle
Definition: BoxCtrl.cpp:215
The Box Controll class contains the FSM for the BoxLevel.
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
#define DBINFO1ln(x)
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
String id
Boxname / Hostname of the Box.
Definition: BoxCtrl.h:59
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
#define DBINFO2ln(x)
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
Error - Used to throw parseerror.
void exitAction_waitForVehicle()
exit action of the waitForVehicle
Definition: BoxCtrl.cpp:262
struct BoxCtrl::Box box
Sortic - Wait for Gateway.
Wait for Transport from vehicle.
const unsigned int SMARTBOX_WAITFOR_VEHICLES_SECONDS
SB waits this amount of seconds for vehicles to respond.
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 loop()
Calls the do-function of the active state and hence generates Events.
const unsigned int NUM_OF_MAXVALUES_VEHICLES_STORE
how many best values can be stored!
void exitAction_errorState()
exit action of the errorState
Definition: BoxCtrl.cpp:498
const unsigned int TIME_BETWEEN_PUBLISH
Time between MQTT-Message publish.
Calculated Optimum Value.
String decodeEvent(Event event)
Decodes the Event-Enum and returns a description.
Definition: BoxCtrl.cpp:570
#define DBINFO3ln(x)
Resume after Error occured.
String cargo
cargo;
Definition: BoxCtrl.h:63
String status
status of the Box FSM
Definition: BoxCtrl.h:64
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
Ext.: Check for package.
#define DBERROR(x)
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
const unsigned int SMARTBOX_ITERATION_VACKS_SECONDS
SB waits this amound of secnods for vehicles to send their acknoledgement to transport SB.
#define DBFUNCCALLln(x)
SB is ready for transport.
#define DBSTATUSln(x)
const State getcurrentState()
Get the current State.
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
#define DBFUNCCALL(x)
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
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