19 pComm.unsubscribe(
"#");
21 pComm.subscribe(
"Vehicle/error");
22 pComm.subscribe(
"error");
137 pComm.publishMessage(
"Vehicle/" + String(
vehicle.
id) +
"/handshake",
"{\"ack\":\"\",\"req\":\"\"}");
138 pComm.subscribe(
"Box/+/handshake");
158 if (!
pComm.isEmpty()) {
159 myJSONStr temp =
pComm.pop();
160 DBINFO2ln(String(
"temp.req: ") + String(temp.req) + String(
"==") + String(
"vehicle.id: ") + String(
vehicle.
id));
177 pComm.unsubscribe(
"Box/+/handshake");
178 pComm.publishMessage(
"Vehicle/" + String(
vehicle.
id) +
"/available",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"sector\":\"\",\"line\":\"\"}");
208 if (!
pComm.isEmpty()) {
209 myJSONStr temp =
pComm.pop();
210 DBINFO2ln(String(
"temp.ack: ") + String(temp.ack) + String(
"==") + String(
"vehicle.id: ") + String(
vehicle.
id));
304 pComm.subscribe(
"Sortic/Gateway");
308 pComm.subscribe(
"Transfer/Gateway");
314 DBINFO2ln(
"if gateway is free for some time take token");
316 while (!
pComm.isEmpty()) {
317 myJSONStr temp =
pComm.pop();
318 DBINFO2ln(String(
"vehicle.id: ") + String(
vehicle.
id) + String(
": ") + String(
"temp.token: ") + String(temp.token));
319 if (temp.token && (temp.topic.endsWith(
"Gateway"))) {
335 pComm.publishMessage(
"Sortic/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":true}");
337 pComm.publishMessage(
"Transfer/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":true}");
342 while (!
pComm.isEmpty()) {
344 myJSONStr temp =
pComm.pop();
345 DBINFO2ln(String(
"vehicle.id: ") + String(
vehicle.
id) + String(
": ") + String(
"temp.token: ") + String(temp.token));
346 if (temp.token && (temp.topic.endsWith(
"Gateway")) && (
vehicle.
id != temp.id)) {
357 pComm.unsubscribe(
"Sortic/Gateway");
358 pComm.publishMessage(
"Sortic/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":true}");
360 pComm.unsubscribe(
"Transfer/Gateway");
361 pComm.publishMessage(
"Transfer/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":true}");
380 pComm.publishMessage(
"Sortic/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":true}");
382 pComm.publishMessage(
"Sortic/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":false}");
391 pComm.publishMessage(
"Transfer/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":true}");
393 pComm.publishMessage(
"Transfer/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":false}");
404 if (
pHoistCtrl.getcurrentState() != HoistCtrl::State::high) {
455 pComm.subscribe(
"Transfer/Handover");
463 pComm.subscribe(
"Sortic/Handover");
474 DBINFO2ln(
"Substate 10: listen for matching cargo in Transfer and free place");
479 if (!
pComm.isEmpty()) {
480 myJSONStr temp =
pComm.pop();
482 if ((temp.id == String(
"Transfer")) && (temp.cargo ==
vehicle.
cargo)) {
485 DBINFO2ln(String(
"Line with same Cargo: ") + String(temp.line));
490 DBINFO2ln(String(
"Line occupied: ") + String(temp.line));
530 DBINFO2ln(
"Substate 11: publish taget and listen if not occupied");
532 while (!
pComm.isEmpty()) {
533 myJSONStr temp =
pComm.pop();
547 pComm.unsubscribe(
"Transfer/Handover");
552 DBINFO2ln(
"Substate 20: listen for empty place in Sortic");
556 if (!
pComm.isEmpty()) {
557 myJSONStr temp =
pComm.pop();
558 DBINFO2ln(String(
"Sector: ") + String(temp.sector) + String(
" line: ") + String(temp.line));
563 DBINFO2ln(String(
"Line occupied: ") + String(temp.line));
598 DBINFO2ln(
"Substate 21: publish taget and listen if not occupied");
600 while (!
pComm.isEmpty()) {
601 myJSONStr temp =
pComm.pop();
615 pComm.unsubscribe(
"Sortic/Handover");
632 pComm.subscribe(
"Sortic/Gateway");
638 pComm.subscribe(
"Transfer/Gateway");
644 DBINFO2ln(
"if gateway is free for some time take token");
646 while (!
pComm.isEmpty()) {
647 myJSONStr temp =
pComm.pop();
648 DBINFO2ln(String(
"vehicle.id: ") + String(
vehicle.
id) + String(
": ") + String(
"temp.token: ") + String(temp.token));
649 if (temp.token && (temp.topic.endsWith(
"Gateway")) && (
vehicle.
id != temp.id)) {
666 pComm.publishMessage(
"Sortic/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":true}");
669 pComm.publishMessage(
"Transfer/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":true}");
674 while (!
pComm.isEmpty()) {
675 myJSONStr temp =
pComm.pop();
676 DBINFO2ln(String(
"vehicle.id: ") + String(
vehicle.
id) + String(
": ") + String(
"temp.token: ") + String(temp.token));
677 if (temp.token && (temp.topic.endsWith(
"Gateway")) && (
vehicle.
id != temp.id)) {
689 pComm.unsubscribe(
"Sortic/Gateway");
690 pComm.publishMessage(
"Sortic/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":true}");
693 pComm.unsubscribe(
"Transfer/Gateway");
694 pComm.publishMessage(
"Transfer/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":true}");
713 pComm.publishMessage(
"Sortic/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":true}");
715 pComm.publishMessage(
"Sortic/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":false}");
721 DBINFO2ln(
"Vehicle-Substate 32: Token Transfer");
725 pComm.publishMessage(
"Transfer/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":true}");
727 pComm.publishMessage(
"Transfer/Gateway",
"{\"id\":\"" + String(
vehicle.
id) +
"\",\"token\":false}");
733 DBINFO2ln(
"Vehicle-Substate 400: Check if in Position");
735 pComm.subscribe(
"Sortic/Gateway");
739 pComm.subscribe(
"Transfer/Gateway");
751 if (
pHoistCtrl.getcurrentState() != HoistCtrl::State::low) {
759 DBINFO2ln(
"Vehicle-Substate 60: Publish Position to Box");
789 DBERROR(
"Entering State: errorState");
804 while (!
pComm.isEmpty()) {
806 myJSONStr temp =
pComm.pop();
807 if (temp.topic.endsWith(
"error")) {
808 if (!temp.error && !temp.token) {
813 }
else if (temp.error && temp.token) {
829 DBERROR(
"Entering State: resetState");
836 pComm.unsubscribe(
"Box/+/handshake");
838 pComm.unsubscribe(
"Sortic/Gateway");
839 pComm.unsubscribe(
"Sortic/Handover");
840 pComm.unsubscribe(
"Transfer/Gateway");
841 pComm.unsubscribe(
"Transfer/Handover");
848 while (!
pComm.isEmpty()) {
849 myJSONStr temp =
pComm.pop();
850 if (temp.topic.endsWith(
"error")) {
851 if (!temp.error && !temp.token) {
882 return "loadVehicle";
885 return "unloadVehicle";
894 return "ERROR: No matching state";
902 return "Event::PosReached";
905 return "Event::HSsucessful";
908 return "Event::AnswerReceived";
911 return "Event::NoAnswerReceived";
914 return "Event::Error";
917 return "Event::Resume";
920 return "Event::Reset";
923 return "Event::NoEvent";
926 return "ERROR: No matching event";
963 if (!
pComm.isEmpty()) {
966 if (
pComm.first().error) {
1021 pComm.publishMessage(
"Vehicle/" + String(
vehicle.
id) +
"/status",
"{\"status\":\"\"}");
1022 pComm.publishMessage(
"Vehicle/" + String(
vehicle.
id) +
"/position",
"{\"sector\":\"\",\"line\":\"\"}");
1023 pComm.publishMessage(
"Vehicle/" + String(
vehicle.
id) +
"/available",
"{\"sector\":\"\",\"line\":\"\"}");
1024 pComm.publishMessage(
"Vehicle/" + String(
vehicle.
id) +
"/handshake",
"{\"ack\":\"\",\"req\":\"\"}");
unsigned int pRandomDelayFactor
some sort of ALOHA stuff
const Sector getcurrentSector()
Get the current Sector.
Event currentEvent
holds the current event of the FSM
int actualLine
actual line initialised with 1
VehicleCtrl::Event doAction_resetState()
main action of the resetState
Ext.: Reset after Error occured.
void publishTargetPosition()
Update position and Publish actual position.
VehicleCtrl::Event doAction_unloadVehicle()
main action of the unloadVehicle
VehicleCtrl::Event doAction_waitForBox()
main action of the waitForBox
Sortic - Wait for Gateway.
void giveToken()
give Token to access the Gateway
NavigationCtrl::Sector targetSector
actual sector initialise with Sortic handover
void publishTargetPositionBlockLine()
Ext: Resume after Error occured.
bool checkForError()
Check if a new message with a error is received.
Resume after Error occured.
unsigned long previousMillisPublishToken
will store last time token published
Ext: Start MoveToTargetPosition.
String ack
ack for handshake vehicle
Transfer - wait for Gateway.
const unsigned int TIMEOUT_VACKS
How long the vehicle waits for acknoledgment from box.
Event
Enum holds all possible events.
String req
req for handshake vehicle
VehicleCtrl::Event doAction_errorState()
main action of the errorState
void entryAction_loadVehicle()
entry action of the loadVehicle
void setTargetPosition(Sector sector, const int line)
Set the Target Position object.
Transit - Wait for Gateway Transfer.
VehicleCtrl()
Construct a new Vehicle Ctrl object.
wait for box to transport
unsigned long previousMillis
will store last time published
const unsigned int TIME_BETWEEN_PUBLISH_TOKEN
Time in ms between publish token.
Event(VehicleCtrl::* doActionFPtr)(void)
Functionpointer to call the current states do-function.
void exitAction_handshake()
exit action of the handshake
HoistCtrl pHoistCtrl
Hoist Controll object.
void loop()
Calls the do-function of the active state and hence generates Events.
void process(Event e)
changes the state of the FSM based on the event
The Vehicle Controll class contains the FSM for the complete Vehicle.
NavigationCtrl::Sector actualSector
actual sector initialise with Sortic handover
NavigationCtrl pNavCtrl
Navigation Controll object.
int pTransferPark[SORTIC_MAX_LINE]
Sortic with 10 diffrent lines.
State
Enum holds all possible state's.
int pSorticPark[SORTIC_MAX_LINE]
Sortic with 10 diffrent lines.
void clearGui()
clear node Red gui
The Vehicle Controll class contains the FSM for the Vehicle.
String cargo
cargo; not used atm
VehicleCtrl::Event doAction_loadVehicle()
main action of the loadVehicle
VehicleCtrl::Event doAction_handshake()
main action of the handshake
void exitAction_waitForBox()
exit action of the waitForBox
const unsigned int TIME_BETWEEN_PUBLISH
Time in ms between publishs.
unsigned long previousMillisPublish
will store last publish time
Communication pComm
Communication object.
unsigned long currentMillis
will store current time
void exitAction_unloadVehicle()
exit action of the unloadVehicle
void exitAction_errorState()
exit action of the errorState
State currentState
holds the current state of the FSM
String status
status of the Vehicle FSM
void entryAction_waitForBox()
entry action of the waitForBox
String decodeState(State state)
Decodes the State-Enum and returns a description.
void entryAction_errorState()
entry action of the errorState
const unsigned int SORTIC_MAX_LINE
How many lines are available. Needed atm to choose a free line without handshake with sortic.
void loop()
Calls the do-function of the active state and hence generates Events.
int targetLine
tartget line initialised with 1
struct VehicleCtrl::Vehicle vehicle
String decodeSector(Sector sector)
Decodes the Sector-Enum and returns a description.
void exitAction_resetState()
exit action of the resetState
void entryAction_resetState()
entry action of the resetState
Transit - Wait for Gateway Sortic.
const int getcurrentLine()
Get the current Line.
void publishState(State state)
Update State and Publish actual state.
unsigned long previousMillisPublishPos
will store last publish position time
void setActualPosition(Sector sector, const int line)
Set the actual Position object.
void entryAction_handshake()
entry action of the handshake
int substate
actual Substate of FSM
String decodeEvent(Event event)
Decodes the Event-Enum and returns a description.
void entryAction_unloadVehicle()
entry action of the unloadVehicle
void exitAction_loadVehicle()
exit action of the loadVehicle
void publishPosition()
Update position and Publish actual position.
State lastStateBevorError
holds the last state of the FSM so it's possible to resume after error
Reset after Error occured.