Index: firmware/App/Controllers/Switches.c =================================================================== diff -u -r025612ad77fe630889a364586de54bffe5262d56 -r04c5d5d9198c1fde05df66ec8f5e660f7f7174b1 --- firmware/App/Controllers/Switches.c (.../Switches.c) (revision 025612ad77fe630889a364586de54bffe5262d56) +++ firmware/App/Controllers/Switches.c (.../Switches.c) (revision 04c5d5d9198c1fde05df66ec8f5e660f7f7174b1) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2022 Diality Inc. - All Rights Reserved. +* Copyright (c) 2021-2022 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file Switches.c * * @author (last) Dara Navaei -* @date (last) 06-Nov-2021 +* @date (last) 22-Feb-2022 * * @author (original) Dara Navaei * @date (original) 24-Jul-2021 @@ -30,8 +30,9 @@ // ********** private definitions ********** -#define SWITCHES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the switches data is published on the CAN bus. -#define SWITCHES_DEBOUNCE_TIME_MS ( MS_PER_SECOND / 4 ) ///< Switches debounce time in milliseconds. +#define SWITCHES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the switches data is published on the CAN bus. +#define SWITCHES_DEBOUNCE_TIME_MS ( MS_PER_SECOND / 4 ) ///< Switches debounce time in milliseconds. +#define DATA_PUBLISH_COUNTER_START_COUNT 7 ///< Data publish counter start count. /// Switch status structure typedef struct @@ -45,11 +46,12 @@ static U32 switchesDataPublicationCounter; ///< Switches data publication counter. static OVERRIDE_U32_T switchesDataPublishInterval = { SWITCHES_DATA_PUB_INTERVAL, SWITCHES_DATA_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish switches data to CAN bus. -static SWITCH_STATUS_T switchesStatus[ NUM_OF_DOORS_AND_CAPS ]; ///< Switches status array. +static SWITCH_STATUS_T switchesStatus[ NUM_OF_CAPS ]; ///< Switches status array. // ********** private function prototypes ********** static void publishSwitchesData( void ); +static void publishSwitchChanged( SWITCH_T switchId, U32 current_state ); /*********************************************************************//** * @brief @@ -62,10 +64,10 @@ { U08 i; - switchesDataPublicationCounter = 0; + switchesDataPublicationCounter = DATA_PUBLISH_COUNTER_START_COUNT; // Initialize all the switches - for ( i = 0; i < NUM_OF_DOORS_AND_CAPS; i++ ) + for ( i = 0; i < NUM_OF_CAPS; i++ ) { switchesStatus[ i ].status.data = (U32)STATE_CLOSED; switchesStatus[ i ].status.ovData = (U32)STATE_CLOSED; @@ -88,7 +90,7 @@ U08 currentSwitchStatus = 0; - for ( i = 0; i < NUM_OF_DOORS_AND_CAPS; i++ ) + for ( i = 0; i < NUM_OF_CAPS; i++ ) { // Get the current switch status switch ( i ) @@ -101,13 +103,8 @@ currentSwitchStatus = ( getFPGADialysateCapStatus() != 0 ? STATE_OPEN : STATE_CLOSED ); break; - case FLUID_DOOR: - currentSwitchStatus = ( getFPGAGFluidDoorStatus() != 0 ? STATE_OPEN : STATE_CLOSED ); - break; - - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_DG_INVALID_SWITCH_ID, i ) - break; + // NOTE: the default case was removed since this switch case is executed using a for loop so the default + // case is never called. The default case is unreachable in development testing. } // Check if the current switch status is not the same as the recorded data @@ -121,6 +118,7 @@ // If the debounce time has been elapsed, update the switch status to the new status else if ( TRUE == didTimeout( switchesStatus[ i ].debounceStartTime, SWITCHES_DEBOUNCE_TIME_MS ) ) { + publishSwitchChanged( (SWITCH_T)i, (U32)currentSwitchStatus ); switchesStatus[ i ].debounceStartTime = 0; switchesStatus[ i ].status.data = currentSwitchStatus; } @@ -146,7 +144,7 @@ { U32 status = 0; - if ( switchId < NUM_OF_DOORS_AND_CAPS ) + if ( switchId < NUM_OF_CAPS ) { // Assume there is no override status = switchesStatus[ switchId ].status.data; @@ -182,15 +180,22 @@ data.concentrateCap = (U32)getSwitchStatus( CONCENTRATE_CAP ); data.dialysateCap = (U32)getSwitchStatus( DIALYSATE_CAP ); - data.fluidDoor = (U32)getSwitchStatus( FLUID_DOOR ); switchesDataPublicationCounter = 0; broadcastData( MSG_ID_DG_SWITCHES_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( SWITCHES_DATA_T ) ); } } +static void publishSwitchChanged( SWITCH_T switchId, U32 current_state ) +{ + SWITCH_CHANGED_DATA_T data; + data.SwitchId = (U32)switchId; + data.newstate = current_state; + + broadcastData( MSG_ID_DG_SWITCH_CHANGE, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( SWITCH_CHANGED_DATA_T ) ); +} /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -257,7 +262,7 @@ { BOOL result = FALSE; - if ( switchId < NUM_OF_DOORS_AND_CAPS ) + if ( switchId < NUM_OF_CAPS ) { if ( TRUE == isTestingActivated() ) { @@ -283,7 +288,7 @@ { BOOL result = FALSE; - if ( switchId < NUM_OF_DOORS_AND_CAPS ) + if ( switchId < NUM_OF_CAPS ) { if ( TRUE == isTestingActivated() ) {