Index: firmware/App/Services/DDInterface.c =================================================================== diff -u -r8cbddbe34a4ffed5a4d9fac07a065799c5862611 -rd595ea4a23b0b2371e31838c24990059653c1871 --- firmware/App/Services/DDInterface.c (.../DDInterface.c) (revision 8cbddbe34a4ffed5a4d9fac07a065799c5862611) +++ firmware/App/Services/DDInterface.c (.../DDInterface.c) (revision d595ea4a23b0b2371e31838c24990059653c1871) @@ -16,6 +16,7 @@ ***************************************************************************/ #include "DDInterface.h" +#include "MessagePayloads.h" #include "Messaging.h" #include "ModeInitPOST.h" #include "OperationModes.h" @@ -38,10 +39,12 @@ // DG status static DD_OP_MODE_T ddCurrentOpMode; ///< Current DD operation mode. static U32 ddSubMode; ///< Current state (sub-mode) of current DD operation mode. +static F32 dialysatePressure; ///< Current dialysate pressure reported by DD. static BOOL ddStartCommandSent; ///< Flag indicates command to start DD has been sent. static BOOL ddStarted; ///< Flag indicates whether we have commanded the DD to start or stop. -static BOOL ddOpModeDataFreshFlag = FALSE; ///< Flag to signal the handleDDOpMode() to process fresh dd op mode data +static BOOL ddOpModeDataFreshFlag; ///< Flag to signal the handleDDOpMode() to process fresh dd op mode data +static BOOL ddDialysatePressureFreshFlag; ///< Flag to signal // DG command response static DD_CMD_RESPONSE_T ddCmdResp[ NUM_OF_DD_COMMANDS ]; ///< Keep the latest DD command response for each command. @@ -66,8 +69,12 @@ ddStarted = FALSE; ddCurrentOpMode = DD_MODE_INIT; ddSubMode = 0; + dialysatePressure = 0.0F; ddStartCommandSent = FALSE; + ddOpModeDataFreshFlag = FALSE; + ddDialysatePressureFreshFlag = FALSE; + // initialize DD command response for ( i = 0; i < NUM_OF_DD_COMMANDS; i++ ) { @@ -123,7 +130,7 @@ void execDDInterfaceMonitor( void ) { // if ( getCPLDACPowerLossDetected() != TRUE ) - { +// { // Trigger alarm if not receiving new DD op mode message in timely manner // checkDDDataFreshness( ALARM_ID_TD_DD_NEW_OPERATION_MODE_MESSAGE_NOT_RECEIVE, &ddOpModeDataFreshFlag ); // if ( TRUE == isAlarmActive( ALARM_ID_TD_DD_NEW_OPERATION_MODE_MESSAGE_NOT_RECEIVE ) ) @@ -133,8 +140,8 @@ // } // Check to see if DD has restarted - checkDDRestart(); - } +// checkDDRestart(); +// } } /*********************************************************************//** @@ -168,33 +175,171 @@ * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if reported DD mode is invalid. * @details \b Inputs: none * @details \b Outputs: ddCurrentOpMode, ddSubMode, ddOpModeDataFreshFlag - * @param opMode The operating mode reported by DD - * @param subMode The sub-mode of operating mode reported by DD - * @return none + * @param message Pointer to the DD operation mode broadcast message + * @return TRUE if message handled successfully, FALSE if not *************************************************************************/ -void setDDOpMode( U32 opMode, U32 subMode ) +BOOL setDDOpMode( MESSAGE_T *message ) { - if ( opMode < NUM_OF_DD_MODES ) + BOOL result = FALSE; + U32 opMode, subMode; + + // parse message payload + memcpy( &opMode, &message->payload[ 0 ], sizeof( U32 ) ); + memcpy( &subMode, &message->payload[ sizeof( U32 ) ], sizeof( U32 ) ); + + if ( ( message->hdr.payloadLen == sizeof( OP_MODE_PAYLOAD_T ) ) && ( opMode < NUM_OF_DD_MODES ) ) { - // reset POST passed flag if DG restarted or faulted or went to service mode + // reset POST passed flag if DD restarted or faulted or went to service mode if ( ( opMode < DD_MODE_STAN ) && ( ddCurrentOpMode >= DD_MODE_STAN ) ) { signalDDPOSTFinalResult( FALSE ); } - // update DG op mode and sub-mode + // update DD op mode and sub-mode ddCurrentOpMode = (DD_OP_MODE_T)opMode; ddSubMode = subMode; + result = TRUE; } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_DD_OPERATING_MODE, opMode ); } ddOpModeDataFreshFlag = TRUE; + + return result; } /*********************************************************************//** * @brief + * The getDialysatePressure function gets the latest reported dialysate + * pressure. + * @details \b Inputs: dialysatePressure + * @details \b Outputs: none + * @return Latest reported dialysate pressure. + *************************************************************************/ +F32 getDialysatePressure( void ) +{ + return dialysatePressure; +} + +/*********************************************************************//** + * @brief + * The setDialysatePressure function sets the latest dialysate pressure + * reported by the DD sub-system. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if message invalid. + * @details \b Inputs: none + * @details \b Outputs: dialysatePressure, ddDialysatePressureFreshFlag + * @param message Pointer to the DD pressure data broadcast message + * @return TRUE if message handled successfully, FALSE if not + *************************************************************************/ +BOOL setDialysatePressure( MESSAGE_T *message ) +{ + BOOL result = FALSE; + DD_PRESSURE_TEMP_DATA_T payload; + + // parse message payload + memcpy( &payload, &message->payload[ 0 ], sizeof( DD_PRESSURE_TEMP_DATA_T ) ); + + if ( message->hdr.payloadLen == sizeof( DD_PRESSURE_TEMP_DATA_T ) ) + { + // update dialysate pressure + dialysatePressure = payload.d41Pressure; + result = TRUE; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_DD_PRESSURE_DATA, (U32)message->hdr.payloadLen ); + } + + ddDialysatePressureFreshFlag = TRUE; + + return result; +} + +/*********************************************************************//** + * @brief + * The cmdStartGenerateDialysate function sends a generate dialysate command + * to the DD with a given set of details. DG will transition to generate + * dialysate mode if it hasn't already. + * @details \b Inputs: none + * @details \b Outputs: none + * @details \b Message \b Sent: Start/continue generate dialysate command. + * @param qd Target dialysate flow rate (Qd). + * @param quf Target ultrafiltration rate (Quf). + * @param dialTemp Target dialysate temperature in deg C. + * @param bypass Flag indicating whether dialyzer should be bypassed. + * @param acid Type of acid concentrate used. + * @param bicarb Type of bicarbonate concentrate used. + * @return none + *************************************************************************/ +void cmdStartGenerateDialysate( F32 qd, F32 quf, F32 dialTemp, BOOL bypass, ACID_CONCENTRATE_TYPE_T acid, BICARB_CONCENTRATE_TYPE_T bicarb ) +{ + DIALYSATE_DELIVERY_REQ_PAYLOAD_T payload; + + payload.start = TRUE; + payload.dialRate = qd; + payload.ufRate = quf; + payload.dialTemp = dialTemp; + payload.bypassDialyzer = bypass; + payload.acidType = (U32)acid; + payload.bicarbType = (U32)bicarb; + + sendMessage( MSG_ID_DD_GEN_DIALYSATE_REQUEST_DATA, COMM_BUFFER_OUT_CAN_TD_2_DD, (U08*)(&payload), sizeof( DIALYSATE_DELIVERY_REQ_PAYLOAD_T ) ); +} + +/*********************************************************************//** + * @brief + * The cmdStopGenerateDialysate function sends a stop generate dialysate command + * to the DD. DD will transition back to standby mode. + * @details \b Inputs: none + * @details \b Outputs: none + * @details \b Message \b Sent: Stop generate dialysate command. + * @return none + *************************************************************************/ +void cmdStopGenerateDialysate( void ) +{ + DIALYSATE_DELIVERY_REQ_PAYLOAD_T payload; + + memset( &payload, 0, sizeof( DIALYSATE_DELIVERY_REQ_PAYLOAD_T ) ); + payload.start = FALSE; + + sendMessage( MSG_ID_DD_GEN_DIALYSATE_REQUEST_DATA, COMM_BUFFER_OUT_CAN_TD_2_DD, (U08*)(&payload), sizeof( DIALYSATE_DELIVERY_REQ_PAYLOAD_T ) ); +} + +/**********************************************************************//** + * @brief + * The checkDDDataFreshness function checks to verify that needed data from + * the DD sub-system is coming regularly to keep the data fresh. + * @details Alarm: Data freshness alarm triggered if fresh data not received + * within 2 seconds of last data broadcast. + * @details Inputs: none + * @details Outputs: ddFreshDataFlag set to FALSE + * @param alarm ID of alarm to check + * @param ddFreshDataFlag flag indicating whether data is fresh + * @return None + *************************************************************************/ +static void checkDDDataFreshness( ALARM_ID_T alarmID, BOOL *ddFreshDataFlag ) +{ + if ( TRUE == *ddFreshDataFlag ) + { + *ddFreshDataFlag = FALSE; + checkPersistentAlarm( alarmID, FALSE, 0.0, 0.0 ); + } + else + { // Alarm if not receiving DG fresh data message in timely manner + if ( TRUE == isDDCommunicating() ) + { + checkPersistentAlarm( alarmID, TRUE, 0.0, 0.0 ); + } + else + { + checkPersistentAlarm( alarmID, FALSE, 0.0, 0.0 ); + } + } +} + +/*********************************************************************//** + * @brief * The handleDDCommandResponse function processes the latest DD command response. * @details \b Alarm: ALARM_ID_TD_DD_COMMAND_INVALID_PARAMETER_FAULT if reported * response indicates DD rejected command due to invalid parameter.