// ====================================================================== // \title ActiveExternalStateMachinesComponentAc.cpp // \author Generated by fpp-to-cpp // \brief cpp file for ActiveExternalStateMachines component base class // ====================================================================== #include "Fw/Types/Assert.hpp" #include "Fw/Types/ExternalString.hpp" #if FW_ENABLE_TEXT_LOGGING #include "Fw/Types/String.hpp" #endif #include "base/ActiveExternalStateMachinesComponentAc.hpp" namespace ExternalSm { namespace { enum MsgTypeEnum { ACTIVEEXTERNALSTATEMACHINES_COMPONENT_EXIT = Fw::ActiveComponentBase::ACTIVE_COMPONENT_EXIT, EXTERNAL_STATE_MACHINE_SIGNAL, }; // Get the max size by constructing a union of the async input, command, and // internal port serialization sizes union BuffUnion { // Size of buffer for external state machine signals // The external SmSignalBuffer stores the signal data BYTE externalSmBufferSize[ 2 * sizeof(FwEnumStoreType) + Fw::SmSignalBuffer::SERIALIZED_SIZE ]; }; // Define a message buffer class large enough to handle all the // asynchronous inputs to the component class ComponentIpcSerializableBuffer : public Fw::LinearBufferBase { public: enum { // Offset into data in buffer: Size of message ID and port number DATA_OFFSET = sizeof(FwEnumStoreType) + sizeof(FwIndexType), // Max data size MAX_DATA_SIZE = sizeof(BuffUnion), // Max message size: Size of message id + size of port + max data size SERIALIZATION_SIZE = DATA_OFFSET + MAX_DATA_SIZE }; Fw::Serializable::SizeType getCapacity() const { return sizeof(m_buff); } U8* getBuffAddr() { return m_buff; } const U8* getBuffAddr() const { return m_buff; } private: // Should be the max of all the input ports serialized sizes... U8 m_buff[SERIALIZATION_SIZE]; }; } // ---------------------------------------------------------------------- // Component initialization // ---------------------------------------------------------------------- void ActiveExternalStateMachinesComponentBase :: init( FwSizeType queueDepth, FwEnumStoreType instance ) { // Initialize base class Fw::ActiveComponentBase::init(instance); // Initialize state machine instances this->m_stateMachine_sm1.init(static_cast(SmId::sm1)); this->m_stateMachine_sm2.init(static_cast(SmId::sm2)); this->m_stateMachine_sm3.init(static_cast(SmId::sm3)); this->m_stateMachine_sm4.init(static_cast(SmId::sm4)); this->m_stateMachine_sm5.init(static_cast(SmId::sm5)); this->m_stateMachine_sm6.init(static_cast(SmId::sm6)); // Create the queue Os::Queue::Status qStat = this->createQueue( queueDepth, static_cast(ComponentIpcSerializableBuffer::SERIALIZATION_SIZE) ); FW_ASSERT( Os::Queue::Status::OP_OK == qStat, static_cast(qStat) ); } // ---------------------------------------------------------------------- // Component construction and destruction // ---------------------------------------------------------------------- ActiveExternalStateMachinesComponentBase :: ActiveExternalStateMachinesComponentBase(const char* compName) : Fw::ActiveComponentBase(compName), m_stateMachine_sm1(this), m_stateMachine_sm2(this), m_stateMachine_sm3(this), m_stateMachine_sm4(this), m_stateMachine_sm5(this), m_stateMachine_sm6(this) { } ActiveExternalStateMachinesComponentBase :: ~ActiveExternalStateMachinesComponentBase() { } // ---------------------------------------------------------------------- // State getter functions // ---------------------------------------------------------------------- ExternalSm::ActiveExternalStateMachines_S1::ActiveExternalStateMachines_S1_States ActiveExternalStateMachinesComponentBase :: sm1_getState() const { return this->m_stateMachine_sm1.state; } ExternalSm::ActiveExternalStateMachines_S1::ActiveExternalStateMachines_S1_States ActiveExternalStateMachinesComponentBase :: sm2_getState() const { return this->m_stateMachine_sm2.state; } ExternalSm::ActiveExternalStateMachines_S2::ActiveExternalStateMachines_S2_States ActiveExternalStateMachinesComponentBase :: sm3_getState() const { return this->m_stateMachine_sm3.state; } ExternalSm::ActiveExternalStateMachines_S2::ActiveExternalStateMachines_S2_States ActiveExternalStateMachinesComponentBase :: sm4_getState() const { return this->m_stateMachine_sm4.state; } ExternalSm::ActiveExternalStateMachines_S2::ActiveExternalStateMachines_S2_States ActiveExternalStateMachinesComponentBase :: sm5_getState() const { return this->m_stateMachine_sm5.state; } ExternalSm::ActiveExternalStateMachines_S2::ActiveExternalStateMachines_S2_States ActiveExternalStateMachinesComponentBase :: sm6_getState() const { return this->m_stateMachine_sm6.state; } // ---------------------------------------------------------------------- // Functions for sending signals to external state machines // ---------------------------------------------------------------------- void ActiveExternalStateMachinesComponentBase :: sm1_stateMachineInvoke( const ExternalSm::ActiveExternalStateMachines_S1_Interface::ActiveExternalStateMachines_S1_Signals signal, const Fw::SmSignalBuffer& data ) { ComponentIpcSerializableBuffer _msg; Fw::SerializeStatus _status = Fw::FW_SERIALIZE_OK; // Serialize the message ID _status = _msg.serializeFrom(static_cast(EXTERNAL_STATE_MACHINE_SIGNAL)); FW_ASSERT ( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); // Fake port number to make message dequeue work _status = _msg.serializeFrom(static_cast(0)); FW_ASSERT ( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(static_cast(SmId::sm1)); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(static_cast(signal)); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(data); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); // Send message Os::Queue::BlockingType _block = Os::Queue::BLOCKING; Os::Queue::Status qStatus = this->m_queue.send(_msg, 1, _block); FW_ASSERT( qStatus == Os::Queue::OP_OK, static_cast(qStatus) ); } void ActiveExternalStateMachinesComponentBase :: sm2_stateMachineInvoke( const ExternalSm::ActiveExternalStateMachines_S1_Interface::ActiveExternalStateMachines_S1_Signals signal, const Fw::SmSignalBuffer& data ) { ComponentIpcSerializableBuffer _msg; Fw::SerializeStatus _status = Fw::FW_SERIALIZE_OK; // Serialize the message ID _status = _msg.serializeFrom(static_cast(EXTERNAL_STATE_MACHINE_SIGNAL)); FW_ASSERT ( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); // Fake port number to make message dequeue work _status = _msg.serializeFrom(static_cast(0)); FW_ASSERT ( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(static_cast(SmId::sm2)); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(static_cast(signal)); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(data); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); // Send message Os::Queue::BlockingType _block = Os::Queue::NONBLOCKING; Os::Queue::Status qStatus = this->m_queue.send(_msg, 2, _block); FW_ASSERT( qStatus == Os::Queue::OP_OK, static_cast(qStatus) ); } void ActiveExternalStateMachinesComponentBase :: sm3_stateMachineInvoke( const ExternalSm::ActiveExternalStateMachines_S2_Interface::ActiveExternalStateMachines_S2_Signals signal, const Fw::SmSignalBuffer& data ) { ComponentIpcSerializableBuffer _msg; Fw::SerializeStatus _status = Fw::FW_SERIALIZE_OK; // Serialize the message ID _status = _msg.serializeFrom(static_cast(EXTERNAL_STATE_MACHINE_SIGNAL)); FW_ASSERT ( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); // Fake port number to make message dequeue work _status = _msg.serializeFrom(static_cast(0)); FW_ASSERT ( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(static_cast(SmId::sm3)); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(static_cast(signal)); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(data); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); // Send message Os::Queue::BlockingType _block = Os::Queue::NONBLOCKING; Os::Queue::Status qStatus = this->m_queue.send(_msg, 3, _block); if (qStatus == Os::Queue::Status::FULL) { this->incNumMsgDropped(); return; } FW_ASSERT( qStatus == Os::Queue::OP_OK, static_cast(qStatus) ); } void ActiveExternalStateMachinesComponentBase :: sm4_stateMachineInvoke( const ExternalSm::ActiveExternalStateMachines_S2_Interface::ActiveExternalStateMachines_S2_Signals signal, const Fw::SmSignalBuffer& data ) { ComponentIpcSerializableBuffer _msg; Fw::SerializeStatus _status = Fw::FW_SERIALIZE_OK; // Serialize the message ID _status = _msg.serializeFrom(static_cast(EXTERNAL_STATE_MACHINE_SIGNAL)); FW_ASSERT ( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); // Fake port number to make message dequeue work _status = _msg.serializeFrom(static_cast(0)); FW_ASSERT ( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(static_cast(SmId::sm4)); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(static_cast(signal)); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(data); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); // Send message Os::Queue::BlockingType _block = Os::Queue::NONBLOCKING; Os::Queue::Status qStatus = this->m_queue.send(_msg, 4, _block); FW_ASSERT( qStatus == Os::Queue::OP_OK, static_cast(qStatus) ); } void ActiveExternalStateMachinesComponentBase :: sm5_stateMachineInvoke( const ExternalSm::ActiveExternalStateMachines_S2_Interface::ActiveExternalStateMachines_S2_Signals signal, const Fw::SmSignalBuffer& data ) { ComponentIpcSerializableBuffer _msg; Fw::SerializeStatus _status = Fw::FW_SERIALIZE_OK; // Serialize the message ID _status = _msg.serializeFrom(static_cast(EXTERNAL_STATE_MACHINE_SIGNAL)); FW_ASSERT ( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); // Fake port number to make message dequeue work _status = _msg.serializeFrom(static_cast(0)); FW_ASSERT ( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(static_cast(SmId::sm5)); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(static_cast(signal)); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(data); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); // Send message Os::Queue::BlockingType _block = Os::Queue::NONBLOCKING; Os::Queue::Status qStatus = this->m_queue.send(_msg, 0, _block); if (qStatus == Os::Queue::Status::FULL) { this->sm5_stateMachineOverflowHook(signal, data); return; } FW_ASSERT( qStatus == Os::Queue::OP_OK, static_cast(qStatus) ); } void ActiveExternalStateMachinesComponentBase :: sm6_stateMachineInvoke( const ExternalSm::ActiveExternalStateMachines_S2_Interface::ActiveExternalStateMachines_S2_Signals signal, const Fw::SmSignalBuffer& data ) { ComponentIpcSerializableBuffer _msg; Fw::SerializeStatus _status = Fw::FW_SERIALIZE_OK; // Serialize the message ID _status = _msg.serializeFrom(static_cast(EXTERNAL_STATE_MACHINE_SIGNAL)); FW_ASSERT ( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); // Fake port number to make message dequeue work _status = _msg.serializeFrom(static_cast(0)); FW_ASSERT ( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(static_cast(SmId::sm6)); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(static_cast(signal)); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); _status = _msg.serializeFrom(data); FW_ASSERT( _status == Fw::FW_SERIALIZE_OK, static_cast(_status) ); // Send message Os::Queue::BlockingType _block = Os::Queue::NONBLOCKING; Os::Queue::Status qStatus = this->m_queue.send(_msg, 0, _block); FW_ASSERT( qStatus == Os::Queue::OP_OK, static_cast(qStatus) ); } // ---------------------------------------------------------------------- // Message dispatch functions // ---------------------------------------------------------------------- Fw::QueuedComponentBase::MsgDispatchStatus ActiveExternalStateMachinesComponentBase :: doDispatch() { ComponentIpcSerializableBuffer _msg; FwQueuePriorityType _priority = 0; Os::Queue::Status _msgStatus = this->m_queue.receive( _msg, Os::Queue::BLOCKING, _priority ); FW_ASSERT( _msgStatus == Os::Queue::OP_OK, static_cast(_msgStatus) ); // Reset to beginning of buffer _msg.resetDeser(); FwEnumStoreType _desMsg = 0; Fw::SerializeStatus _deserStatus = _msg.deserializeTo(_desMsg); FW_ASSERT( _deserStatus == Fw::FW_SERIALIZE_OK, static_cast(_deserStatus) ); MsgTypeEnum _msgType = static_cast(_desMsg); if (_msgType == ACTIVEEXTERNALSTATEMACHINES_COMPONENT_EXIT) { return MSG_DISPATCH_EXIT; } FwIndexType portNum = 0; _deserStatus = _msg.deserializeTo(portNum); FW_ASSERT( _deserStatus == Fw::FW_SERIALIZE_OK, static_cast(_deserStatus) ); switch (_msgType) { // Handle signals to external state machines case EXTERNAL_STATE_MACHINE_SIGNAL: { // Deserialize the state machine ID to an FwEnumStoreType FwEnumStoreType enumStoreSmId = 0; _deserStatus = _msg.deserializeTo(enumStoreSmId); FW_ASSERT( _deserStatus == Fw::FW_SERIALIZE_OK, static_cast(_deserStatus) ); // Cast it to the correct type SmId stateMachineId = static_cast(enumStoreSmId); // Deserialize the state machine signal to an FwEnumStoreType. // This value will be cast to the correct type in the // switch statement that calls the state machine update function. FwEnumStoreType enumStoreSmSignal = 0; _deserStatus = _msg.deserializeTo(enumStoreSmSignal); FW_ASSERT( _deserStatus == Fw::FW_SERIALIZE_OK, static_cast(_deserStatus) ); // Deserialize the state machine data Fw::SmSignalBuffer data; _deserStatus = _msg.deserializeTo(data); FW_ASSERT( Fw::FW_SERIALIZE_OK == _deserStatus, static_cast(_deserStatus) ); // Make sure there was no data left over. // That means the buffer size was incorrect. FW_ASSERT( _msg.getDeserializeSizeLeft() == 0, static_cast(_msg.getDeserializeSizeLeft()) ); // Call the state machine update function switch (stateMachineId) { case SmId::sm1: { ExternalSm::ActiveExternalStateMachines_S1_Interface::ActiveExternalStateMachines_S1_Signals signal = static_cast(enumStoreSmSignal); this->m_stateMachine_sm1.update(static_cast(stateMachineId), signal, data); break; } case SmId::sm2: { ExternalSm::ActiveExternalStateMachines_S1_Interface::ActiveExternalStateMachines_S1_Signals signal = static_cast(enumStoreSmSignal); this->m_stateMachine_sm2.update(static_cast(stateMachineId), signal, data); break; } case SmId::sm3: { ExternalSm::ActiveExternalStateMachines_S2_Interface::ActiveExternalStateMachines_S2_Signals signal = static_cast(enumStoreSmSignal); this->m_stateMachine_sm3.update(static_cast(stateMachineId), signal, data); break; } case SmId::sm4: { ExternalSm::ActiveExternalStateMachines_S2_Interface::ActiveExternalStateMachines_S2_Signals signal = static_cast(enumStoreSmSignal); this->m_stateMachine_sm4.update(static_cast(stateMachineId), signal, data); break; } case SmId::sm5: { ExternalSm::ActiveExternalStateMachines_S2_Interface::ActiveExternalStateMachines_S2_Signals signal = static_cast(enumStoreSmSignal); this->m_stateMachine_sm5.update(static_cast(stateMachineId), signal, data); break; } case SmId::sm6: { ExternalSm::ActiveExternalStateMachines_S2_Interface::ActiveExternalStateMachines_S2_Signals signal = static_cast(enumStoreSmSignal); this->m_stateMachine_sm6.update(static_cast(stateMachineId), signal, data); break; } default: return MSG_DISPATCH_ERROR; } break; } default: return MSG_DISPATCH_ERROR; } return MSG_DISPATCH_OK; } }