20 pComm.unsubscribe(
"#");
21 pComm.subscribe(
"Box/" + String(
box.
id) +
"/error");
22 pComm.subscribe(
"Box/error");
23 pComm.subscribe(
"error");
158 pComm.subscribe(
"Sortic/Handover");
188 if (!
pComm.isEmpty()) {
189 myJSONStr temp =
pComm.pop();
191 if ((temp.line ==
box.
actualLine) && (temp.id = String(
"Sortic")) && (temp.cargo.length() != 0) && (temp.cargo != String(
"null"))) {
193 pComm.publishMessage(
"Box/" + String(
box.
id) +
"/cargo",
"{\"cargo\":\"" + String(
box.
cargo) +
"\"}");
201 pComm.publishMessage(
"Box/" + String(
box.
id) +
"/cargo",
"{\"cargo\":\"Empty\"}");
211 pComm.unsubscribe(
"Sortic/Handover");
225 pComm.subscribe(
"Vehicle/+/available");
228 pComm.unsubscribe(
"Vehicle/" + String(
box.
req) +
"/handshake");
264 pComm.unsubscribe(
"Vehicle/+/available");
269 DBSTATUSln(
"Entering State: calculateOptVehicle");
285 int size =
pComm.size();
287 myJSONStr nearestVehicleStr =
pComm.pop();
290 for (
int i = 0; i < size; i++) {
292 if (!
pComm.isEmpty()) {
301 nearestVehicleStr = temp;
308 box.
req = nearestVehicleStr.id;
317 DBSTATUSln(
"Leaving State: calculateOptVehicle");
323 DBSTATUSln(
"Entering State: publishOptVehicle");
328 pComm.subscribe(
"Vehicle/" + String(
box.
req) +
"/handshake");
348 pComm.publishMessage(
"Box/" + String(
box.
id) +
"/handshake",
"{\"id\":\"" + String(
box.
id) +
"\",\"req\":\"" + String(
box.
req) +
"\"}");
358 if (!
pComm.isEmpty()) {
359 myJSONStr temp =
pComm.pop();
375 DBSTATUSln(
"Leaving State: publishOptVehicle");
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)) {
426 pComm.unsubscribe(
"Vehicle/" + String(
box.
req) +
"/handshake");
431 DBSTATUSln(
"Entering State: waitForTransport");
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");
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));
463 DBSTATUSln(
"Leaving State: waitForTransport");
465 pComm.unsubscribe(
"Box/" + String(
box.
id) +
"/position");
470 DBERROR(
"Entering State: errorState");
482 while (!
pComm.isEmpty()) {
484 myJSONStr temp =
pComm.pop();
485 if (temp.topic.endsWith(
"error")) {
486 if (!temp.error && !temp.token) {
489 }
else if (temp.error && temp.token) {
505 DBERROR(
"Entering State: resetState");
518 while (!
pComm.isEmpty()) {
519 myJSONStr temp =
pComm.pop();
520 if (temp.topic.endsWith(
"error")) {
521 if (!temp.error && !temp.token) {
541 return "readSensorVal";
544 return "waitForVehicle";
547 return "calculateOptVehicle";
550 return "publishOptVehicle";
556 return "waitForTransport";
565 return "ERROR: No matching state";
573 return "Event::SBReadyForTransport";
576 return "Event::SBReady";
579 return "Event::CalcOptVal";
582 return "Event::AnswerReceived";
585 return "Event::NoAnswerReceived";
588 return "Event::Error";
591 return "Event::Resume";
594 return "Event::Reset";
597 return "Event::NoEvent";
600 return "ERROR: No matching event";
608 return "SorticHandover";
611 return "SorticToHandover";
614 return "SorticWaitForGateway";
617 return "SorticGateway";
620 return "TransitWaitForGatewaySortic";
623 return "TransitToSortic";
626 return "TransitToTransfer";
632 return "TransitWaitForGatewayTransfer";
635 return "TransferGateway";
638 return "TransferWaitForGateway";
641 return "TransferToHandover";
644 return "TransferHandover";
648 return "ERROR: No matching sector";
654 if (String(
"SorticHandover") == sector) {
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) {
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) {
685 if (!
pComm.isEmpty()) {
688 if (
pComm.first().error) {
698 pComm.publishMessage(
"Box/" + String(
box.
id) +
"/status",
"{\"status\":\"" + String(
box.
status) +
"\"}");
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\":\"\"}");
BoxCtrl::Event doAction_waitForTransport()
main action of the waitForTransport
BoxCtrl::Event doAction_resetState()
main action of the resetState
BoxCtrl::Event doAction_readSensorVal()
main action of the readSensorVal
void entryAction_waitForVehicle()
entry action of the waitForVehicle
The Box Controll class contains the FSM for the BoxLevel.
void entryAction_publishOptVehicle()
entry action of the publishOptVehicle
String decodeState(State state)
Decodes the State-Enum and returns a description.
void entryAction_waitForAck()
entry action of the waitForAck publish state to "Box/box.id/status"
State lastStateBevorError
holds the last state of the FSM so it's possible to resume after error
unsigned long currentMillis
store current time
String req
req for handshake vehicle
String id
Boxname / Hostname of the Box.
Sector
Sector class holds all possible position on the gametable.
wait for available vehicle
The Box Controll class contains the FSM for the complete Box.
unsigned long previousMillisPublish
store last publish time
BoxLevelCtrl pBoxlevelctrl
instance ot BoxLevelCtrl
Sector actualSector
actual sector initialise with Sortic handover
void exitAction_calculateOptVehicle()
exit action of the calculateOptVehicle
BoxCtrl::Event doAction_publishOptVehicle()
main action of the publishOptVehicle
State currentState
holds the current state of the FSM
BoxCtrl::Event doAction_calculateOptVehicle()
main action of the calculateOptVehicle
String ack
ack for handshake vehicle
Event
Enum holds all possible events.
Transit - Wait for Gateway Transfer.
void publishState(State state)
Publish actual state via communication.
bool checkForError()
Check if the last message was an error.
void entryAction_readSensorVal()
entry action of the readSensorVal
State
Enum holds all possible state's.
void process(Event e)
changes the state of the FSM based on the event
BoxCtrl()
Construct a new Box Ctrl object.
void exitAction_readSensorVal()
exit action of the readSensorVal
Error - Used to throw parseerror.
void exitAction_waitForVehicle()
exit action of the waitForVehicle
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
Reset after Error occured.
Transit - Wait for Gateway Sortic.
void entryAction_errorState()
entry action of the errorState
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
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.
Resume after Error occured.
String status
status of the Box FSM
void exitAction_resetState()
exit action of the resetState
String decodeSector(Sector sector)
Decodes the Sector-Enum and returns a description.
BoxCtrl::Event doAction_errorState()
main action of the errorState
Communication pComm
instance of Communication with Box.id/hostname
void entryAction_calculateOptVehicle()
entry action of the calculateOptVehicle
Wait for ack. from vehicle.
void entryAction_resetState()
entry action of the resetState
BoxCtrl::Event doAction_waitForAck()
main action of the waitForAck
const unsigned int SMARTBOX_ITERATION_VACKS_SECONDS
SB waits this amound of secnods for vehicles to send their acknoledgement to transport SB.
SB is ready for transport.
const State getcurrentState()
Get the current State.
int actualLine
actual line
void publishPosition()
publish actual position via communication
void entryAction_waitForTransport()
entry action of the waitForTransport
unsigned long previousMillis
store last time
void loop()
Calls the do-function of the active state and hence generates Events.
BoxCtrl::Event doAction_waitForVehicle()
main action of the waitForVehicle
void exitAction_publishOptVehicle()
exit action of the publishOptVehicle
Publishe desired vehicle.
void exitAction_waitForAck()
exit action of the waitForAck
void clearGui()
clear all box related gui entrys
Event(BoxCtrl::* doActionFPtr)(void)
Functionpointer to call the current states do-function.
Event currentEvent
holds the current event of the FSM