In this guide, we will walk through the implementation of the Platform State service and requires you to understand How to create a Component and How to add Services to a Component


Starting in v1.1.0-dev.1 of the org.openjaus.iop-v3.cpp package, the OjPlatformState class was introduced. This class partially implements the Platform State service to handle the management of the reported platform state (INITIALIZE, OPERATIONAL, etc). When using the OjPlatformState class the final implementer is still required to do the work to monitor and update the platform's sub-processes as needed.


Attached is some example code on how to integrate the OjPlatformState class into a component with additional design considerations for implementing the Platform State service provided here


We briefly highlight and discuss some snippets from the attached code.



Monitoring the Internal Platform State


The implementer is responsible for adding the code to monitor the internal state of the platform and triggering the necessary internal events, or additional actions. In the example code, this is done using internal timers that are triggered every second to check if the platform has been initialized or if an internal failure has occurred.


void PlatformStateExampleComponent::handleInitTimerTimeout(openjaus::system::Timer* timer)
{
    // OJINFO: TODO: Check if the platform's sub-processes (JAUS components, sensor network, etc) have all been initialized

    timer->stop();

    // If componentsInitialized AND other platform sub-processes are initialized
    //      initializationComplete(); // Fire the InitializationComplete Internal Event
    // Else
    //      timer->start(); // Restart the timer
}

The above code is triggered every second until the platform has successfully initialized. When the successful initialization has been been detected the InitializationComplete Internal Event is fired to update the PlatformState service's reported state.


void PlatformStateExampleComponent::handleFailureTimerTimeout(openjaus::system::Timer* timer)
{
    // OJINFO: TODO: Check if any of the platform's sub-processes have failed

    timer->stop();

    // If internal platform failure is detected
    //      internalFailure(); // Fire the InternalFalure Internal Event
    // Else
    //      timer->start(); // Restart the timer
}

The above code is triggered every second unless an internal platform failure (non-recoverable failure) has been detected. When the internal failure has been been detected the InternalFailure Internal Event is fired to update the PlatformState service's reported state.



Updating the Internal Platform State


The implementer is responsible for adding the code to update the internal state of the platform based on the defined protocol behavior. When a transition is required, one of the transitionPlatformState methods will be executed. The transition necessary is determined by the parameters to transitionPlatformState method.


bool PlatformStateExampleComponent::transitionPlatformState(openjaus::iop_v3::EmergencyEvent *emergencyEvent)
{
    // OJINFO: TODO: EmergencyEvent occurred. Transition to Emergency.

    return true;
}

The above code is triggered when a SetPlatformState(EMERGENCY) message is received. The implementer must add the code to transition the platform to an internal emergency state. The specific details on the platform's emergency state is vehicle specific, but must comply with the description outlined in the standard. The implemented code could include:

  • Sending JAUS messages to other JAUS components
  • Sending non-JAUS messages to other software processes (locally and remotely)
  • Directly commanding attached hardware