Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -rc137d3c7cb17b0364d745e10ff6dbd1901eb1baa -rce247681f11b5e164e00992fb73ba5c595d349aa --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision c137d3c7cb17b0364d745e10ff6dbd1901eb1baa) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision ce247681f11b5e164e00992fb73ba5c595d349aa) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-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 OperationModes.c * -* @author (last) Sean Nash -* @date (last) 13-Aug-2021 +* @author (last) Darren Cox +* @date (last) 25-Aug-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -26,9 +26,12 @@ #include "ModePreTreat.h" #include "ModeTreatment.h" #include "ModePostTreat.h" +#include "NVDataMgmt.h" #include "OperationModes.h" +#include "RTC.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" +#include "Timers.h" /** * @addtogroup HDOperationModes @@ -37,16 +40,16 @@ // ********** private data ********** -/// HD operation mode broadcast interval (in task interval/sec). -#define BROADCAST_HD_OP_MODE_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) +#define BROADCAST_HD_OP_MODE_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< HD operation mode broadcast interval (in task interval/sec). +#define DATA_PUBLISH_COUNTER_START_COUNT 11 ///< Data publish counter start count. // ********** private data ********** static volatile BOOL modeRequest[ NUM_OF_MODES - 1 ]; ///< Pending operation mode change requests. static HD_OP_MODE_T lastMode = MODE_INIT; ///< Last operation mode prior to current mode. static HD_OP_MODE_T currentMode = MODE_INIT; ///< Current operation mode. static U32 currentSubMode = 0; ///< The currently active state of the active mode. -static U32 broadcastModeIntervalCtr = 11; ///< Interval counter used to determine when to broadcast operation mode. Initialize to 11 to stagger broadcast. +static U32 broadcastModeIntervalCtr; ///< Interval counter used to determine when to broadcast operation mode. Initialize to 11 to stagger broadcast. /// Interval (in task intervals) at which to publish operation mode data to CAN bus. static OVERRIDE_U32_T opModePublishInterval = { BROADCAST_HD_OP_MODE_INTERVAL, BROADCAST_HD_OP_MODE_INTERVAL, BROADCAST_HD_OP_MODE_INTERVAL, 0 }; static U32 priorSubMode = 0; ///< The prior submode state. @@ -87,9 +90,11 @@ } // Start in init mode - currentMode = MODE_INIT; - currentSubMode = 0; - priorSubMode = 0; + currentMode = MODE_INIT; + currentSubMode = 0; + priorSubMode = 0; + broadcastModeIntervalCtr = DATA_PUBLISH_COUNTER_START_COUNT; + transitionToNewOperationMode( MODE_INIT ); // Call initializers for the individual modes @@ -134,6 +139,16 @@ lastMode = currentMode; transitionToNewOperationMode( newMode ); currentMode = newMode; + + if ( MODE_TREA == lastMode ) + { + // If the current mode is treatment but transitioning to another mode has been requested (including transitioning to fault mode) + // it means the treatment is done. Get the elapsed time since the beginning of the treatment and convert it to hours to be written + U32 txElapsedTimeMS = calcTimeSince( getTreatmentStartTimeStamp() ); + F32 txElapsedTimeHrs = (F32)txElapsedTimeMS / ( MIN_PER_HOUR * SEC_PER_MIN * MS_PER_SECOND ); + // Write the treatment hours and set the service to be false so the treatment hours is not reset + setTxTimeHours( txElapsedTimeHrs, FALSE ); + } } // Mode specific processing to be done continuously