Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r085476747d1b466802f94f5926fc53a8ec463ec5 -r491bddb51ce331490567666795549c17f78a0e68 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 085476747d1b466802f94f5926fc53a8ec463ec5) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 491bddb51ce331490567666795549c17f78a0e68) @@ -7,8 +7,8 @@ * * @file BloodLeak.c * -* @author (last) Darren Cox -* @date (last) 10-Mar-2022 +* @author (last) Dara Navaei +* @date (last) 23-May-2022 * * @author (original) Peman Montazemi * @date (original) 18-Mar-2021 @@ -101,17 +101,17 @@ enum EmbCommands { - NU = 0, ///< Null command. - CS, ///< Control S command to switch to embedded mode. - SP, ///< Set point command to set the set point. - T, ///< Self test command. - G, ///< Get self test command. - I, ///< Intensity command. - V, ///< Blood detection level command. - Z, ///< Zero sensor command. - Q, ///< Zero sensor confirm command. - D, ///< Display blood detection command. - C, ///< Calibration sensor command. + NU_EMB_MODE_CMD = 0, ///< Null command. + CS_EMB_MODE_CMD, ///< Control S command to switch to embedded mode. + SP_EMB_MODE_CMD, ///< Set point command to set the set point. + T_EMB_MODE_CMD, ///< Self test command. + G_EMB_MODE_CMD, ///< Get self test command. + I_EMB_MODE_CMD, ///< Intensity command. + V_EMB_MODE_CMD, ///< Blood detection level command. + Z_EMB_MODE_CMD, ///< Zero sensor command. + Q_EMB_MODE_CMD, ///< Zero sensor confirm command. + D_EMB_MODE_CMD, ///< Display blood detection command. + C_EMB_MODE_CMD, ///< Calibration sensor command. NUM_OF_EMB_CMDS, ///< Number of embedded mode commands. }; @@ -225,7 +225,7 @@ bloodLeakPrevFPGARegisterCount = 0; bloodLeakPersistenceCtr = 0; bloodLeakSignalEmbModeReq = FALSE; - bloodLeakEmbModeRqstedCmd = NU; + bloodLeakEmbModeRqstedCmd = NU_EMB_MODE_CMD; bloodLeakEmbModeSubstate = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE; bloodLeakEmbModeOpsStartTime = 0; bloodLeakEmbModeRespIndex = 0; @@ -240,7 +240,7 @@ // Initialize the blood leak calibration command sequence array. // The first index is the command character so it can be changed upon request. - // The reset of the commands are never changing. + // The rest of the commands are never changing. bloodLeakEmbModeCmdSquence[ 0 ] = 0; bloodLeakEmbModeCmdSquence[ 1 ] = BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND; bloodLeakEmbModeCmdSquence[ 2 ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_HIGH; @@ -361,13 +361,16 @@ * @brief * The exitBloodLeakNormalState requests that the blood leak sensor to exit * its normal state. - * @details Inputs: none + * @details Inputs: bloodLeakState * @details Outputs: bloodLeakExitNormalRequested * @return none *************************************************************************/ void exitBloodLeakNormalState( void ) { - bloodLeakExitNormalRequested = TRUE; + if ( BLOOD_LEAK_NORMAL_STATE == bloodLeakState ) + { + bloodLeakExitNormalRequested = TRUE; + } } /*********************************************************************//** @@ -763,7 +766,7 @@ { state = BLOOD_LEAK_INIT_STATE; bloodLeakZeroRequested = FALSE; - bloodLeakExitNormalRequested = TRUE; + bloodLeakExitNormalRequested = FALSE; } return state; @@ -856,19 +859,19 @@ switch( bloodLeakEmbModeRqstedCmd ) { - case NU: + case NU_EMB_MODE_CMD: // Null command do nothing break; - case CS: - case T: - case G: - case I: - case V: - case Z: - case Q: - case D: - case C: + case CS_EMB_MODE_CMD: + case T_EMB_MODE_CMD: + case G_EMB_MODE_CMD: + case I_EMB_MODE_CMD: + case V_EMB_MODE_CMD: + case Z_EMB_MODE_CMD: + case Q_EMB_MODE_CMD: + case D_EMB_MODE_CMD: + case C_EMB_MODE_CMD: // The requested command is not set point and so update the command sequence buffer. // The first index of calibration command sequence is the requested command in ASCII. bloodLeakEmbModeCmdSquence[ 0 ] = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].commandASCII; @@ -877,7 +880,7 @@ state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; break; - case SP: + case SP_EMB_MODE_CMD: prepareSetPointSeq( bloodLeakEmbModeSetPoint ); bloodLeakEmbModeNumOfCmdTries = 0; @@ -907,23 +910,23 @@ switch ( bloodLeakEmbModeRqstedCmd ) { - case CS: - case T: - case G: - case I: - case V: - case Z: - case Q: - case D: - case C: + case CS_EMB_MODE_CMD: + case T_EMB_MODE_CMD: + case G_EMB_MODE_CMD: + case I_EMB_MODE_CMD: + case V_EMB_MODE_CMD: + case Z_EMB_MODE_CMD: + case Q_EMB_MODE_CMD: + case D_EMB_MODE_CMD: + case C_EMB_MODE_CMD: command = bloodLeakEmbModeCmdSquence[ bloodLeakUARTCmdIndex ]; isUARTTxDone = ( bloodLeakUARTCmdIndex <= BLOOD_LEAK_EMB_MODE_STOP_INDEX ? FALSE : TRUE ); isUARTCtrlDone = ( bloodLeakUARTCmdIndex > ( BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH - 1 ) ? TRUE : FALSE ); bloodLeakUARTCmdIndex++; break; - case SP: + case SP_EMB_MODE_CMD: // Check if the current buffer index is less than the buffer length if( bloodLeakUARTCmdIndex < bloodLeakSetPointSeqLength ) { @@ -996,7 +999,7 @@ U08 expChar2 = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].expChar2; U08 command = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].commandASCII; - if ( ( expChar1 != NU ) && ( NU == expChar2 ) ) + if ( ( expChar1 != NU_EMB_MODE_CMD ) && ( NU_EMB_MODE_CMD == expChar2 ) ) { // This is the case that there is a start character. If current character buffer index is less than the // length of the expected response of the command. @@ -1020,7 +1023,7 @@ } } } - else if ( ( expChar1 != NU ) && ( expChar2 != NU ) ) + else if ( ( expChar1 != NU_EMB_MODE_CMD ) && ( expChar2 != NU_EMB_MODE_CMD ) ) { // This is the case that both expected chars are not null. Either of the chars are accepted like P or F if ( bloodLeakEmbModeRespIndex < length ) @@ -1059,7 +1062,7 @@ } } } - else if ( ( NU == expChar1 ) && ( NU == expChar2 ) ) + else if ( ( NU_EMB_MODE_CMD == expChar1 ) && ( NU_EMB_MODE_CMD == expChar2 ) ) { // This is the case that there are no expected characters and the received value are numbers if ( bloodLeakEmbModeRespIndex < length ) @@ -1080,7 +1083,7 @@ { // Check if the first element of the response buffer is null and the number of tries has not exceeded. When the response buffer is // null but it is the end of the receive buffer it means no response has been received back - if ( ( NU == bloodLeakEmbModeRespBuffer[ 0 ] ) && ( ++bloodLeakEmbModeNumOfCmdTries < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) ) + if ( ( NU_EMB_MODE_CMD == bloodLeakEmbModeRespBuffer[ 0 ] ) && ( ++bloodLeakEmbModeNumOfCmdTries < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) ) { state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; } @@ -1094,20 +1097,20 @@ { // Loop through the elements of the buffer and make sure none of the elements are not NULL. // The elements are checked until the specified length that is expected for a command - isNull |= ( bloodLeakEmbModeRespBuffer[ i ] != NU ? FALSE : TRUE ); + isNull |= ( bloodLeakEmbModeRespBuffer[ i ] != NU_EMB_MODE_CMD ? FALSE : TRUE ); } // Check if the failed command is Control S which is switch to embedded mode and if // it failed set the embedded mode request to false so the other commands cannot be sent again - bloodLeakSignalEmbModeReq = ( ( CS == bloodLeakEmbModeRqstedCmd ) && ( NU == bloodLeakEmbModeRespBuffer[ 0 ] ) ? FALSE : TRUE ); + bloodLeakSignalEmbModeReq = ( ( CS_EMB_MODE_CMD == bloodLeakEmbModeRqstedCmd ) && ( NU_EMB_MODE_CMD == bloodLeakEmbModeRespBuffer[ 0 ] ) ? FALSE : TRUE ); if ( ( TRUE == isNull ) && ( ++bloodLeakEmbModeNumOfCmdTries < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) ) { state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; } else { - bloodLeakEmbModeRqstedCmd = NU; + bloodLeakEmbModeRqstedCmd = NU_EMB_MODE_CMD; state = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE; handleSendBloodLeakEmbeddedModeCommandResponse( length, bloodLeakEmbModeRespBuffer ); @@ -1220,70 +1223,70 @@ static void initEmbModeSpecs( void ) { // Null command - bloodLeakEmbModeCmd[ NU ].commandASCII = NU; - bloodLeakEmbModeCmd[ NU ].expChar1 = NU; - bloodLeakEmbModeCmd[ NU ].expChar2 = NU; - bloodLeakEmbModeCmd[ NU ].length = 0; + bloodLeakEmbModeCmd[ NU_EMB_MODE_CMD ].commandASCII = NU_EMB_MODE_CMD; + bloodLeakEmbModeCmd[ NU_EMB_MODE_CMD ].expChar1 = NU_EMB_MODE_CMD; + bloodLeakEmbModeCmd[ NU_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; + bloodLeakEmbModeCmd[ NU_EMB_MODE_CMD ].length = 0; // Control S command - bloodLeakEmbModeCmd[ CS ].commandASCII = 19; // ASCII for Control S - bloodLeakEmbModeCmd[ CS ].expChar1 = 69; // ASCII for E (Embedded ...) - bloodLeakEmbModeCmd[ CS ].expChar2 = NU; - bloodLeakEmbModeCmd[ CS ].length = 5; + bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].commandASCII = 19; // ASCII for Control S + bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].expChar1 = 69; // ASCII for E (Embedded ...) + bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; + bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].length = 5; // Set point command - bloodLeakEmbModeCmd[ SP ].commandASCII = 83; // ASCII for S - bloodLeakEmbModeCmd[ SP ].expChar1 = 88; // ASCII for X (Timeout) - bloodLeakEmbModeCmd[ SP ].expChar2 = 70; // ASCII for F (Fail) - bloodLeakEmbModeCmd[ SP ].length = 1; + bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].commandASCII = 83; // ASCII for S + bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].expChar1 = 88; // ASCII for X (Timeout) + bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].expChar2 = 70; // ASCII for F (Fail) + bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].length = 1; // Self test command - bloodLeakEmbModeCmd[ T ].commandASCII = 84; // ASCII for T - bloodLeakEmbModeCmd[ T ].expChar1 = 80; // ASCII for P - bloodLeakEmbModeCmd[ T ].expChar2 = 70; // ASCII for F - bloodLeakEmbModeCmd[ T ].length = 1; + bloodLeakEmbModeCmd[ T_EMB_MODE_CMD ].commandASCII = 84; // ASCII for T + bloodLeakEmbModeCmd[ T_EMB_MODE_CMD ].expChar1 = 80; // ASCII for P + bloodLeakEmbModeCmd[ T_EMB_MODE_CMD ].expChar2 = 70; // ASCII for F + bloodLeakEmbModeCmd[ T_EMB_MODE_CMD ].length = 1; // Get self test command - bloodLeakEmbModeCmd[ G ].commandASCII = 71; // ASCII for G - bloodLeakEmbModeCmd[ G ].expChar1 = 71; - bloodLeakEmbModeCmd[ G ].expChar2 = NU; - bloodLeakEmbModeCmd[ G ].length = 5; + bloodLeakEmbModeCmd[ G_EMB_MODE_CMD ].commandASCII = 71; // ASCII for G + bloodLeakEmbModeCmd[ G_EMB_MODE_CMD ].expChar1 = 71; + bloodLeakEmbModeCmd[ G_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; + bloodLeakEmbModeCmd[ G_EMB_MODE_CMD ].length = 5; // Intensity command - bloodLeakEmbModeCmd[ I ].commandASCII = 73; // ASCII for I - bloodLeakEmbModeCmd[ I ].expChar1 = 73; - bloodLeakEmbModeCmd[ I ].expChar2 = NU; - bloodLeakEmbModeCmd[ I ].length = 5; + bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].commandASCII = 73; // ASCII for I + bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].expChar1 = 73; + bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; + bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].length = 5; // Blood detection command - bloodLeakEmbModeCmd[ V ].commandASCII = 86; // ASCII for V - bloodLeakEmbModeCmd[ V ].expChar1 = 86; - bloodLeakEmbModeCmd[ V ].expChar2 = NU; - bloodLeakEmbModeCmd[ V ].length = 5; + bloodLeakEmbModeCmd[ V_EMB_MODE_CMD ].commandASCII = 86; // ASCII for V + bloodLeakEmbModeCmd[ V_EMB_MODE_CMD ].expChar1 = 86; + bloodLeakEmbModeCmd[ V_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; + bloodLeakEmbModeCmd[ V_EMB_MODE_CMD ].length = 5; // Zero sensor command - bloodLeakEmbModeCmd[ Z ].commandASCII = 90; // ASCII for Z - bloodLeakEmbModeCmd[ Z ].expChar1 = 89; // ASCII for Y - bloodLeakEmbModeCmd[ Z ].expChar2 = NU; - bloodLeakEmbModeCmd[ Z ].length = 1; + bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].commandASCII = 90; // ASCII for Z + bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].expChar1 = 89; // ASCII for Y + bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; + bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].length = 1; // Zero confirm command - bloodLeakEmbModeCmd[ Q ].commandASCII = 81; // ASCII for Q - bloodLeakEmbModeCmd[ Q ].expChar1 = 80; // ASCII for P - bloodLeakEmbModeCmd[ Q ].expChar2 = 70; // ASCII for F - bloodLeakEmbModeCmd[ Q ].length = 1; + bloodLeakEmbModeCmd[ Q_EMB_MODE_CMD ].commandASCII = 81; // ASCII for Q + bloodLeakEmbModeCmd[ Q_EMB_MODE_CMD ].expChar1 = 80; // ASCII for P + bloodLeakEmbModeCmd[ Q_EMB_MODE_CMD ].expChar2 = 70; // ASCII for F + bloodLeakEmbModeCmd[ Q_EMB_MODE_CMD ].length = 1; // Display blood detection command - bloodLeakEmbModeCmd[ D ].commandASCII = 68; - bloodLeakEmbModeCmd[ D ].expChar1 = 68; // ASCII for D - bloodLeakEmbModeCmd[ D ].expChar2 = NU; - bloodLeakEmbModeCmd[ D ].length = 5; + bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].commandASCII = 68; + bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].expChar1 = 68; // ASCII for D + bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; + bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].length = 5; // Calibrate command - bloodLeakEmbModeCmd[ C ].commandASCII = 67; - bloodLeakEmbModeCmd[ C ].expChar1 = 67; // ASCII for C - bloodLeakEmbModeCmd[ C ].expChar2 = NU; - bloodLeakEmbModeCmd[ C ].length = 4; + bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].commandASCII = 67; + bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].expChar1 = 67; // ASCII for C + bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; + bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].length = 4; } @@ -1410,7 +1413,7 @@ if ( ( MODE_FAUL == mode ) || ( MODE_SERV == mode ) || ( MODE_STAN == mode ) ) { bloodLeakSignalEmbModeReq = TRUE; - bloodLeakEmbModeRqstedCmd = CS; + bloodLeakEmbModeRqstedCmd = CS_EMB_MODE_CMD; result = TRUE; } }