Index: firmware/App/Services/DDInterface.c =================================================================== diff -u -r3b23149bcfa736ff20f32346d609245c50f40643 -r12c4f28723f9af89ae693df771039da1bc7ffc80 --- firmware/App/Services/DDInterface.c (.../DDInterface.c) (revision 3b23149bcfa736ff20f32346d609245c50f40643) +++ firmware/App/Services/DDInterface.c (.../DDInterface.c) (revision 12c4f28723f9af89ae693df771039da1bc7ffc80) @@ -15,12 +15,14 @@ * ***************************************************************************/ + #include "ROPump.h" #include "DDInterface.h" #include "Messaging.h" #include "MessagePayloads.h" -#include "ModeGenPermeate.h" #include "ModeStandby.h" +#include "ModeWaterGen.h" +#include "ModeWaterPreGen.h" #include "OperationModes.h" #include "PersistentAlarm.h" #include "SystemCommRO.h" @@ -42,8 +44,9 @@ // ********** private function prototypes ********** -static void setDDOpMode( U32 opMode, U32 subMode ); static void setDDPermeateFlowRate( F32 flowRate ); +static BOOL handlePreGenCmd( BOOL start, F32 roRate ); +static BOOL handleGenWaterCmd( BOOL start, F32 roRate ); /*********************************************************************//** * @brief @@ -127,51 +130,118 @@ /*********************************************************************//** * @brief - * The handleGeneratePermeateRequestMsg function handles a RO permeate + * The handleGenerateWaterRequestMsg function handles a RO permeate * request from DD and updates permeate flow rate. * @details Inputs: none * @details Outputs: message handled * @param message a pointer to the message to handle * @return TRUE if message is sucessfully parsed, FALSE if not. *************************************************************************/ -BOOL handleGeneratePermeateRequestMsg( MESSAGE_T *message ) +BOOL handleGenerateWaterRequestMsg( MESSAGE_T *message ) { BOOL result = FALSE; if ( message->hdr.payloadLen == sizeof( RO_WATER_REQ_PAYLOAD_T ) ) { - RO_WATER_REQ_PAYLOAD_T startRORequest; - RO_OP_MODE_T roMode = getCurrentOperationMode(); + RO_WATER_REQ_PAYLOAD_T cmd; + memcpy( &cmd, message->payload, sizeof( RO_WATER_REQ_PAYLOAD_T ) ); - memcpy( &startRORequest, message->payload, sizeof( RO_WATER_REQ_PAYLOAD_T ) ); + switch ( cmd.cmdID ) + { + case RO_PRE_GEN: + result = handlePreGenCmd( cmd.start, cmd.roRate ); + break; + case RO_GEN_WATER: + result = handleGenWaterCmd( cmd.start, cmd.roRate ); + break; + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_RO_SOFTWARE_FAULT, SW_FAULT_ID_RO_INVALID_RO_CMD, cmd.cmdID ) + break; + } + } - if ( ( RO_MODE_STAN == roMode ) && ( TRUE == startRORequest.start ) ) + return result; +} + +/*********************************************************************//** + * @brief + * The handlePreGenCmd function handles a RO pre generate water + * request from DD and updates permeate flow rate. + * @details Inputs: none + * @details Outputs: message handled + * @param start the TRUE FALSE bool to determine start or stop + * @param roRate the flow rate from the dd to set the ro pump + * @return TRUE if message is sucessfully parsed, FALSE if not. + *************************************************************************/ +static BOOL handlePreGenCmd( BOOL start, F32 roRate ) +{ + BOOL result = FALSE; + RO_OP_MODE_T roMode = getCurrentOperationMode(); + + if ( ( RO_MODE_STAN == roMode ) && ( TRUE == start ) ) + { + setDDPermeateFlowRate( roRate ); + setBoostPumpPWMDutyCycle( P12_PUMP, roRate ); + result = requestPreGenStart(); + } + else if ( RO_MODE_PGEN == roMode ) + { + if ( FALSE == start ) { - setDDPermeateFlowRate( startRORequest.roRate ); - setBoostPumpPWMDutyCycle( P12_PUMP,startRORequest.roRate ); - result = requestROStart(); + signalROPumpStop( P12_PUMP ); + result = requestPreGenStop(); } - else if ( RO_MODE_GENP == roMode ) + else { - if ( FALSE == startRORequest.start ) - { - // stop Permeate Generation by transitioning to standby mode - signalROPumpStop( P12_PUMP ); - requestNewOperationMode( RO_MODE_STAN ); - } - else - { - // Set flow rate and delivery. - setDDPermeateFlowRate( startRORequest.roRate ); - } + // Set flow rate and delivery. + setDDPermeateFlowRate( roRate ); result = TRUE; } } return result; } +/*********************************************************************//** + * @brief + * The handleGenWaterCmd function handles a generate water + * request from DD and updates permeate flow rate. + * @details Inputs: none + * @details Outputs: message handled + * @param start the TRUE FALSE bool to determine start or stop + * @param roRate the flow rate from the dd to set the ro pump + * @return TRUE if message is sucessfully parsed, FALSE if not. + *************************************************************************/ +static BOOL handleGenWaterCmd( BOOL start, F32 roRate ) +{ + BOOL result = FALSE; + RO_OP_MODE_T roMode = getCurrentOperationMode(); + if ( ( RO_MODE_PGEN == roMode ) && ( TRUE == start ) ) + { + setDDPermeateFlowRate( roRate ); + setBoostPumpPWMDutyCycle( P12_PUMP,roRate ); + result = requestGenWaterStart(); + } + else if ( RO_MODE_GENW == roMode ) + { + if ( FALSE == start ) + { + signalROPumpStop( P12_PUMP ); + result = requestGenWaterStop(); + } + else + { + // Set flow rate and delivery. + setDDPermeateFlowRate( roRate ); + result = TRUE; + } + } + + return result; +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/