SmartBox-Sortic
SmartFactory
BoxCtrl Class Reference

The Box Controll class contains the FSM for the complete Box. More...

#include <BoxCtrl.h>

Collaboration diagram for BoxCtrl:

Classes

struct  Box
 Box class contains all relevant information about the box and its actual state. More...
 

Public Types

enum  Sector {
  Sector::SorticHandover, Sector::SorticToHandover, Sector::SorticWaitForGateway, Sector::SorticGateway,
  Sector::TransitWaitForGatewaySortic, Sector::TransitToSortic, Sector::TransitToTransfer, Sector::Parking,
  Sector::TransitWaitForGatewayTransfer, Sector::TransferGateway, Sector::TransferWaitForGateway, Sector::TransferToHandover,
  Sector::TransferHandover, Sector::error
}
 Sector class holds all possible position on the gametable. More...
 
enum  Event {
  Event::SBReadyForTransport, Event::SBReady, Event::CalcOptVal, Event::AnswerReceived,
  Event::NoAnswerReceived, Event::Error, Event::Reset, Event::Resume,
  Event::NoEvent
}
 Enum holds all possible events. More...
 

Public Member Functions

 BoxCtrl ()
 Construct a new Box Ctrl object. More...
 
void loop ()
 Calls the do-function of the active state and hence generates Events. More...
 
void loop (Event currentEvent)
 procceses the current Event and calls the do-function of the active state More...
 

Public Attributes

struct BoxCtrl::Box box
 

Private Types

enum  State {
  State::readSensorVal, State::waitForVehicle, State::calculateOptVehicle, State::publishOptVehicle,
  State::waitForAck, State::waitForTransport, State::resetState, State::errorState
}
 Enum holds all possible state's. More...
 

Private Member Functions

void process (Event e)
 changes the state of the FSM based on the event More...
 
void entryAction_readSensorVal ()
 entry action of the readSensorVal More...
 
BoxCtrl::Event doAction_readSensorVal ()
 main action of the readSensorVal More...
 
void exitAction_readSensorVal ()
 exit action of the readSensorVal More...
 
void entryAction_waitForVehicle ()
 entry action of the waitForVehicle More...
 
BoxCtrl::Event doAction_waitForVehicle ()
 main action of the waitForVehicle More...
 
void exitAction_waitForVehicle ()
 exit action of the waitForVehicle More...
 
void entryAction_calculateOptVehicle ()
 entry action of the calculateOptVehicle More...
 
BoxCtrl::Event doAction_calculateOptVehicle ()
 main action of the calculateOptVehicle More...
 
void exitAction_calculateOptVehicle ()
 exit action of the calculateOptVehicle More...
 
void entryAction_publishOptVehicle ()
 entry action of the publishOptVehicle More...
 
BoxCtrl::Event doAction_publishOptVehicle ()
 main action of the publishOptVehicle More...
 
void exitAction_publishOptVehicle ()
 exit action of the publishOptVehicle More...
 
void entryAction_waitForAck ()
 entry action of the waitForAck publish state to "Box/box.id/status" More...
 
BoxCtrl::Event doAction_waitForAck ()
 main action of the waitForAck More...
 
void exitAction_waitForAck ()
 exit action of the waitForAck More...
 
void entryAction_waitForTransport ()
 entry action of the waitForTransport More...
 
BoxCtrl::Event doAction_waitForTransport ()
 main action of the waitForTransport More...
 
void exitAction_waitForTransport ()
 exit action of the waitForTransport More...
 
void entryAction_errorState ()
 entry action of the errorState More...
 
BoxCtrl::Event doAction_errorState ()
 main action of the errorState More...
 
void exitAction_errorState ()
 exit action of the errorState More...
 
void entryAction_resetState ()
 entry action of the resetState More...
 
BoxCtrl::Event doAction_resetState ()
 main action of the resetState More...
 
void exitAction_resetState ()
 exit action of the resetState More...
 
String decodeState (State state)
 Decodes the State-Enum and returns a description. More...
 
String decodeEvent (Event event)
 Decodes the Event-Enum and returns a description. More...
 
String decodeSector (Sector sector)
 Decodes the Sector-Enum and returns a description. More...
 
BoxCtrl::Sector decodeSector (String sector)
 Decodes the Sector-Enum and returns a description. More...
 
void publishPosition ()
 publish actual position via communication More...
 
void publishState (State state)
 Publish actual state via communication. More...
 
bool checkForError ()
 Check if the last message was an error. More...
 
void clearGui ()
 clear all box related gui entrys More...
 

Private Attributes

State lastStateBevorError
 holds the last state of the FSM so it's possible to resume after error More...
 
State currentState
 holds the current state of the FSM More...
 
Event currentEvent
 holds the current event of the FSM More...
 
Event(BoxCtrl::* doActionFPtr )(void) = nullptr
 Functionpointer to call the current states do-function. More...
 
BoxLevelCtrl pBoxlevelctrl
 instance ot BoxLevelCtrl More...
 
Communication pComm = Communication(DEFAULT_HOSTNAME)
 instance of Communication with Box.id/hostname More...
 
unsigned long currentMillis = 0
 store current time More...
 
unsigned long previousMillis = 0
 store last time More...
 
unsigned long previousMillisPublish = 0
 store last publish time More...
 

Detailed Description

The Box Controll class contains the FSM for the complete Box.

BoxCtrl.png

Definition at line 30 of file BoxCtrl.h.

Member Enumeration Documentation

◆ Sector

enum BoxCtrl::Sector
strong

Sector class holds all possible position on the gametable.

Enumerator
SorticHandover 

Sortic - Handover.

SorticToHandover 

Sortic - to Handover.

SorticWaitForGateway 

Sortic - Wait for Gateway.

SorticGateway 

Sortic - Gateway.

TransitWaitForGatewaySortic 

Transit - Wait for Gateway Sortic.

TransitToSortic 

Transit - to Sortic.

TransitToTransfer 

Transit - to Transfer.

Parking 

Parking (not used atm)

TransitWaitForGatewayTransfer 

Transit - Wait for Gateway Transfer.

TransferGateway 

Transfer - Gateway.

TransferWaitForGateway 

Transfer - wait for Gateway.

TransferToHandover 

Transfer - to Handover.

TransferHandover 

Transfer - Handover.

error 

Error - Used to throw parseerror.

Definition at line 37 of file BoxCtrl.h.

◆ Event

enum BoxCtrl::Event
strong

Enum holds all possible events.

Enumerator
SBReadyForTransport 

SB is ready for transport.

SBReady 

SB is Ready.

CalcOptVal 

Calculated Optimum Value.

AnswerReceived 

Answer received.

NoAnswerReceived 

No Answer received.

Error 

Error occured.

Reset 

Reset after Error occured.

Resume 

Resume after Error occured.

NoEvent 

No event generated.

Definition at line 73 of file BoxCtrl.h.

◆ State

enum BoxCtrl::State
strongprivate

Enum holds all possible state's.

https://stackoverflow.com/questions/18335861/why-is-enum-class-preferred-over-plain-enum

Enumerator
readSensorVal 

read fill level

waitForVehicle 

wait for available vehicle

calculateOptVehicle 

Calculate desired vehicle.

publishOptVehicle 

Publishe desired vehicle.

waitForAck 

Wait for ack. from vehicle.

waitForTransport 

Wait for Transport from vehicle.

resetState 

Reset state.

errorState 

Error state.

Definition at line 116 of file BoxCtrl.h.

Constructor & Destructor Documentation

◆ BoxCtrl()

BoxCtrl::BoxCtrl ( )

Construct a new Box Ctrl object.

Definition at line 15 of file BoxCtrl.cpp.

Member Function Documentation

◆ loop() [1/2]

void BoxCtrl::loop ( )

Calls the do-function of the active state and hence generates Events.

Definition at line 29 of file BoxCtrl.cpp.

◆ loop() [2/2]

void BoxCtrl::loop ( Event  currentEvent)

procceses the current Event and calls the do-function of the active state

Parameters
currentEvent- Event

Definition at line 34 of file BoxCtrl.cpp.

◆ process()

void BoxCtrl::process ( Event  e)
private

changes the state of the FSM based on the event

Parameters
e- Event

Definition at line 41 of file BoxCtrl.cpp.

◆ entryAction_readSensorVal()

void BoxCtrl::entryAction_readSensorVal ( )
private

entry action of the readSensorVal

publish actual state to "Box/box.id/status"

Definition at line 150 of file BoxCtrl.cpp.

◆ doAction_readSensorVal()

BoxCtrl::Event BoxCtrl::doAction_readSensorVal ( )
private

main action of the readSensorVal

  • call Comm.loop and check for incoming Error-Message
  • call BoxLevelCtrl with Event::CheckForPackage
  • if BoxLvl is in FullState and at HandoverSortic or in EmptyState and at HandOverTransfer
    • return Event SBReadyForTransport
Returns
BoxCtrl::Event - generated Event

Definition at line 165 of file BoxCtrl.cpp.

◆ exitAction_readSensorVal()

void BoxCtrl::exitAction_readSensorVal ( )
private

exit action of the readSensorVal

Definition at line 209 of file BoxCtrl.cpp.

◆ entryAction_waitForVehicle()

void BoxCtrl::entryAction_waitForVehicle ( )
private

entry action of the waitForVehicle

  • publish state to "Box/box.id/status".
  • subscribe to "Vehicle/+/available".
  • unsubscribe from "Vehicle/box.req/handshake".
  • reset box.ack and box.req.

Definition at line 215 of file BoxCtrl.cpp.

◆ doAction_waitForVehicle()

BoxCtrl::Event BoxCtrl::doAction_waitForVehicle ( )
private

main action of the waitForVehicle

  • call Comm.loop and check for incoming Error-Message.
  • wait for SMARTBOX_WAITFOR_VEHICLES_SECONDS seconds

    • if a message is received or more than NUM_OF_MAXVALUES_VEHICLES_STORE messages are recived
    Returns
    BoxCtrl::Event - generated Event

Definition at line 235 of file BoxCtrl.cpp.

◆ exitAction_waitForVehicle()

void BoxCtrl::exitAction_waitForVehicle ( )
private

exit action of the waitForVehicle

unsubscribe from "Vehicle/+/available"

Definition at line 262 of file BoxCtrl.cpp.

◆ entryAction_calculateOptVehicle()

void BoxCtrl::entryAction_calculateOptVehicle ( )
private

entry action of the calculateOptVehicle

publish state to "Box/box.id/status"

Definition at line 268 of file BoxCtrl.cpp.

◆ doAction_calculateOptVehicle()

BoxCtrl::Event BoxCtrl::doAction_calculateOptVehicle ( )
private

main action of the calculateOptVehicle

Definition at line 275 of file BoxCtrl.cpp.

◆ exitAction_calculateOptVehicle()

void BoxCtrl::exitAction_calculateOptVehicle ( )
private

exit action of the calculateOptVehicle

Definition at line 316 of file BoxCtrl.cpp.

◆ entryAction_publishOptVehicle()

void BoxCtrl::entryAction_publishOptVehicle ( )
private

entry action of the publishOptVehicle

  • publish state to "Box/box.id/status"
  • subscribe to "Vehicle/box.req/handshake"

Definition at line 322 of file BoxCtrl.cpp.

◆ doAction_publishOptVehicle()

BoxCtrl::Event BoxCtrl::doAction_publishOptVehicle ( )
private

main action of the publishOptVehicle

  • call Comm.loop and check for incoming Error-Message.
  • publish box.id and id of req vehicle to "Box/box.id/handshake" all TIME_BETWEEN_PUBLISH seconds.
  • if requested vehicle also req box in time return Event::AnswerReceived.
    Returns
    BoxLevelCtrl::Event - generated Event

Definition at line 334 of file BoxCtrl.cpp.

◆ exitAction_publishOptVehicle()

void BoxCtrl::exitAction_publishOptVehicle ( )
private

exit action of the publishOptVehicle

Definition at line 374 of file BoxCtrl.cpp.

◆ entryAction_waitForAck()

void BoxCtrl::entryAction_waitForAck ( )
private

entry action of the waitForAck publish state to "Box/box.id/status"

Definition at line 379 of file BoxCtrl.cpp.

◆ doAction_waitForAck()

BoxCtrl::Event BoxCtrl::doAction_waitForAck ( )
private

main action of the waitForAck

  • call Comm.loop and check for incoming Error-Message.
  • publish box.id and id of ack vehicle to "Box/box.id/handshake".
  • wait SMARTBOX_ITERATION_VACKS_SECONDS for responde.
  • if acknoledge vehicle also ack box in time

    Returns
    BoxLevelCtrl::Event - generated Event

Definition at line 389 of file BoxCtrl.cpp.

◆ exitAction_waitForAck()

void BoxCtrl::exitAction_waitForAck ( )
private

exit action of the waitForAck

unsubscribe from "Vehicle/box.req/handshake"

Definition at line 423 of file BoxCtrl.cpp.

◆ entryAction_waitForTransport()

void BoxCtrl::entryAction_waitForTransport ( )
private

entry action of the waitForTransport

  • publish state to "Box/box.id/status".
  • subscribe to "Box/box.id/position".

Definition at line 430 of file BoxCtrl.cpp.

◆ doAction_waitForTransport()

BoxCtrl::Event BoxCtrl::doAction_waitForTransport ( )
private

main action of the waitForTransport

  • call Comm.loop and check for incoming Error-Message.
  • check incoming message if ack. vehicle updated box-position
    Returns
    BoxLevelCtrl::Event - generated Event

Definition at line 439 of file BoxCtrl.cpp.

◆ exitAction_waitForTransport()

void BoxCtrl::exitAction_waitForTransport ( )
private

exit action of the waitForTransport

unsubscribe from "Box/box.id/position"

Definition at line 462 of file BoxCtrl.cpp.

◆ entryAction_errorState()

void BoxCtrl::entryAction_errorState ( )
private

entry action of the errorState

Definition at line 469 of file BoxCtrl.cpp.

◆ doAction_errorState()

BoxCtrl::Event BoxCtrl::doAction_errorState ( )
private

main action of the errorState

Returns
BoxLevelCtrl::Event - generated Event

Definition at line 478 of file BoxCtrl.cpp.

◆ exitAction_errorState()

void BoxCtrl::exitAction_errorState ( )
private

exit action of the errorState

Definition at line 498 of file BoxCtrl.cpp.

◆ entryAction_resetState()

void BoxCtrl::entryAction_resetState ( )
private

entry action of the resetState

Definition at line 504 of file BoxCtrl.cpp.

◆ doAction_resetState()

BoxCtrl::Event BoxCtrl::doAction_resetState ( )
private

main action of the resetState

Returns
BoxCtrl::Event - generated Event

Definition at line 514 of file BoxCtrl.cpp.

◆ exitAction_resetState()

void BoxCtrl::exitAction_resetState ( )
private

exit action of the resetState

Definition at line 529 of file BoxCtrl.cpp.

◆ decodeState()

String BoxCtrl::decodeState ( State  state)
private

Decodes the State-Enum and returns a description.

Parameters
state- enum State
Returns
String - State as String

Definition at line 538 of file BoxCtrl.cpp.

◆ decodeEvent()

String BoxCtrl::decodeEvent ( Event  event)
private

Decodes the Event-Enum and returns a description.

Parameters
event- enum Event
Returns
String - Event as String

Definition at line 570 of file BoxCtrl.cpp.

◆ decodeSector() [1/2]

String BoxCtrl::decodeSector ( Sector  sector)
private

Decodes the Sector-Enum and returns a description.

Parameters
sector- Sector to decode
Returns
String - Sector as String

Definition at line 605 of file BoxCtrl.cpp.

◆ decodeSector() [2/2]

BoxCtrl::Sector BoxCtrl::decodeSector ( String  sector)
private

Decodes the Sector-Enum and returns a description.

Parameters
sector- String to decode
Returns
BoxCtrl::Sector - Sector as Sector

Definition at line 653 of file BoxCtrl.cpp.

◆ publishPosition()

void BoxCtrl::publishPosition ( )
private

publish actual position via communication

Definition at line 701 of file BoxCtrl.cpp.

◆ publishState()

void BoxCtrl::publishState ( State  state)
private

Publish actual state via communication.

Parameters
state- State of type enum State

Definition at line 696 of file BoxCtrl.cpp.

◆ checkForError()

bool BoxCtrl::checkForError ( )
private

Check if the last message was an error.

Returns
true - if the last message was an error
false - if the last message wasn't an error

Definition at line 683 of file BoxCtrl.cpp.

◆ clearGui()

void BoxCtrl::clearGui ( )
private

clear all box related gui entrys

Definition at line 705 of file BoxCtrl.cpp.

Member Data Documentation

◆ box

struct BoxCtrl::Box BoxCtrl::box

◆ lastStateBevorError

State BoxCtrl::lastStateBevorError
private

holds the last state of the FSM so it's possible to resume after error

Definition at line 126 of file BoxCtrl.h.

◆ currentState

State BoxCtrl::currentState
private

holds the current state of the FSM

Definition at line 127 of file BoxCtrl.h.

◆ currentEvent

Event BoxCtrl::currentEvent
private

holds the current event of the FSM

Definition at line 128 of file BoxCtrl.h.

◆ doActionFPtr

Event(BoxCtrl::* BoxCtrl::doActionFPtr) (void) = nullptr
private

Functionpointer to call the current states do-function.

https://stackoverflow.com/questions/1485983/calling-c-class-methods-via-a-function-pointer

Definition at line 135 of file BoxCtrl.h.

◆ pBoxlevelctrl

BoxLevelCtrl BoxCtrl::pBoxlevelctrl
private

instance ot BoxLevelCtrl

Definition at line 137 of file BoxCtrl.h.

◆ pComm

Communication BoxCtrl::pComm = Communication(DEFAULT_HOSTNAME)
private

instance of Communication with Box.id/hostname

Definition at line 138 of file BoxCtrl.h.

◆ currentMillis

unsigned long BoxCtrl::currentMillis = 0
private

store current time

Definition at line 140 of file BoxCtrl.h.

◆ previousMillis

unsigned long BoxCtrl::previousMillis = 0
private

store last time

Definition at line 141 of file BoxCtrl.h.

◆ previousMillisPublish

unsigned long BoxCtrl::previousMillisPublish = 0
private

store last publish time

Definition at line 142 of file BoxCtrl.h.


The documentation for this class was generated from the following files: