Index: firmware/App/Controllers/BPModule.c =================================================================== diff -u -r521a6440cea9f66e5c3ad9af1f0b79d30977e774 -r5ad0389d9abad0f0a523fc44ae6c00ca8b12f313 --- firmware/App/Controllers/BPModule.c (.../BPModule.c) (revision 521a6440cea9f66e5c3ad9af1f0b79d30977e774) +++ firmware/App/Controllers/BPModule.c (.../BPModule.c) (revision 5ad0389d9abad0f0a523fc44ae6c00ca8b12f313) @@ -20,6 +20,9 @@ #include "BPDriver.h" #include "BPModule.h" #include "FpgaTD.h" +#include "Messaging.h" +#include "OperationModes.h" +#include "TaskGeneral.h" /** * @addtogroup BPModule @@ -28,6 +31,8 @@ // ********** private definitions ********** +#define BP_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval at which vitals data is published to UI. + // TODO remove these when institutional settings are available #define BP_SYSTOLIC_LOW_LIMIT 90 ///< Low systolic blood pressure threshold in mmHg #define BP_SYSTOLIC_HIGH_LIMIT 180 ///< High systolic blood pressure threshold in mmHG @@ -51,13 +56,19 @@ static BOOL requestAdultBPReading; ///< Adult BP reading request static BOOL requestPedsBPReading; ///< Pediatric BP reading request static BOOL requestAbortBPReading; ///< Abort BP reading request +static BOOL pendingVitalsRequest; ///< Indicating UI requested BP measurement. +static BOOL isBloodPressureCuffConnected; ///< Indicating UI has requested Bp Cuff connected. +static U32 bpPublishTimerCtr; ///< Timer counter for vitals publish. +static BP_RESULTS_T bpResults; ///< Latest BP measurement results. // ********** private function prototypes ********** static void checkBloodPressureReading( BP_RESULTS_T *bpResults ); static BP_MODULE_STATE_T handleBPModuleIdleState( void ); static BP_MODULE_STATE_T handleBPModuleMeasureState( void ); static BP_MODULE_STATE_T handleBPModuleCheckState( void ); +static void resetBPModuleFlags( void ); +static void publishVitalsData( void ); /*********************************************************************//** * @brief @@ -71,9 +82,12 @@ initBPDriver(); bpModuleState = BP_MODULE_IDLE_STATE; lowSystolicCount = 0; + bpPublishTimerCtr = 0; + pendingVitalsRequest = FALSE; requestAdultBPReading = FALSE; requestPedsBPReading = FALSE; requestAbortBPReading = FALSE; + isBloodPressureCuffConnected = FALSE; } /*********************************************************************//** @@ -106,10 +120,24 @@ bpModuleState = BP_MODULE_IDLE_STATE; break; } + resetBPModuleFlags(); + publishVitalsData(); } /*********************************************************************//** * @brief +* The resetBPModuleFlags function resets BP module flags. +* @details \b Inputs: none +* @details \b Outputs: BP module flags reset. +* @return none +*************************************************************************/ +static void resetBPModuleFlags( void ) +{ + pendingVitalsRequest = FALSE; +} + +/*********************************************************************//** +* @brief * The initiateAdultBPReading function initiates an adult blood pressure * measurement. * @details \b Inputs: none @@ -267,5 +295,74 @@ return nextState; } +/*********************************************************************//** +* @brief +* The bpModuleHandleVitalsRequest function handles the UI blood +* pressure measurement request. +* @details \b Message \b Sent: MSG_ID_TD_BLOOD_PRESSURE_READING +* @details \b Inputs: message containing blood pressure reques +* @details \b Outputs: pendingVitalsRequest +* @return TRUE if request is accepted, FALSE if rejected. +*************************************************************************/ +BOOL bpModuleHandleVitalsRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + UI_RESPONSE_PAYLOAD_T response; + + if ( 0 == message->hdr.payloadLen ) + { + // Verify treatment mode + if ( MODE_TREA == getCurrentOperationMode() ) + { + // Verify cuff connection + if ( TRUE == isBloodPressureCuffConnected ) + { + pendingVitalsRequest = TRUE; + result = TRUE; + rejReason = REQUEST_REJECT_REASON_NONE; + } + else + { + rejReason = REQUEST_REJECT_REASON_INVALID_COMMAND; + } + } + else + { + rejReason = REQUEST_REJECT_REASON_INVALID_TREATMENT_STATE; + } + } + + // Respond to request + response.accepted = result; + response.rejectionReason = rejReason; + sendMessage( MSG_ID_TD_BLOOD_PRESSURE_READING, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08*)&response, sizeof( UI_RESPONSE_PAYLOAD_T ) ); + + return result; +} + +/*********************************************************************//** +* @brief +* The publishVitalsData function publishes blood pressure data. +* @details \b Message \b Sent: MSG_ID_TD_BLOOD_PRESSURE_DATA +* @details \b Inputs: bpResults +* @details \b Outputs: blood pressure data published to CAN bus. +* @return none +*************************************************************************/ +static void publishVitalsData( void ) +{ + if ( ++bpPublishTimerCtr >= BP_DATA_PUBLISH_INTERVAL ) + { + BP_RESULTS_T data; + + bpPublishTimerCtr = 0; + data.systolic = bpResults.systolic; + data.diastolic = bpResults.diastolic; + data.heartRate = bpResults.heartRate; + + broadcastData( MSG_ID_TD_BLOOD_PRESSURE_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( BP_RESULTS_T ) ); + } +} + /**@}*/