Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r138efd92a8645e0d2fe422409ef5a33dd2929a25 -r5ff39fd6948ae3656b4035c85325bd8fca0a37f3 --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 138efd92a8645e0d2fe422409ef5a33dd2929a25) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 5ff39fd6948ae3656b4035c85325bd8fca0a37f3) @@ -16,6 +16,7 @@ #include "gio.h" +#include "TaskGeneral.h" #include "OperationModes.h" #include "ModeChemicalDisinfect.h" #include "ModeDisinfect.h" @@ -34,6 +35,10 @@ * @{ */ +// ********** private definitions ********** + +#define DG_OP_MODE_BROADCAST_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the op mode is published on the CAN bus. + // ********** private data ********** static volatile BOOL modeRequest[NUM_OF_MODES - 1]; ///< Array of mode request flags. @@ -56,6 +61,8 @@ /* CHEM */{ MODE_FAUL, MODE_NLEG, MODE_NLEG, MODE_STAN, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_CHEM } }; +static U32 dgOpModePublicationTimerCounter = 0; + // ********** private function prototypes ********** static OP_MODE arbitrateModeRequest( void ); @@ -96,6 +103,9 @@ initFlushMode(); initDisinfectMode(); initChemicalDisinfectMode(); + + // initialize broadcast timer counter + dgOpModePublicationTimerCounter = 0; } /*********************************************************************//** @@ -182,6 +192,13 @@ // TODO - trigger s/w fault break; } // end switch + + // publish op mode on interval + if ( ++dgOpModePublicationTimerCounter >= DG_OP_MODE_BROADCAST_INTERVAL ) + { + broadcastDGOpMode( (U32)currentMode ); + dgOpModePublicationTimerCounter = 0; + } } /*********************************************************************//**** Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r5a61bccd959265c00e5276ba23391198ca82b6dd -r5ff39fd6948ae3656b4035c85325bd8fca0a37f3 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 5a61bccd959265c00e5276ba23391198ca82b6dd) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 5ff39fd6948ae3656b4035c85325bd8fca0a37f3) @@ -17,6 +17,7 @@ #include // for memcpy() +#include "TaskGeneral.h" #include "OperationModes.h" #include "SystemCommMessages.h" #include "Reservoirs.h" @@ -37,8 +38,12 @@ #define MAX_DRAIN_VOLUME_ML MAX_RESERVOIR_VOLUME_ML ///> Maximum drain volume in mL. #define MIN_DRAIN_VOLUME_ML 20 ///> Minimum drain volume in mL. +#define RESERVOIR_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the reservoir data is published on the CAN bus. + // ********** private data ********** +static U32 reservoirDataPublicationTimerCounter = 0; ///< used to schedule reservoir data publication to CAN bus. + static OVERRIDE_U32_T activeReservoir = { 0, 0, 0, 0 }; ///< The active reservoir that the DG is filling/draining/etc. static OVERRIDE_U32_T fillVolumeTargetMl = { 0, 0, 0, 0 }; ///< The target reservoir fill volume (in mL). static OVERRIDE_U32_T drainVolumeTargetMl = { 0, 0, 0, 0 }; ///< The target reservoir drain volume (in mL). @@ -61,17 +66,35 @@ drainVolumeTargetMl.data = DEFAULT_DRAIN_VOLUME_ML; } +void execReservoirs( void ) +{ + // TODO - publish active reservoir, fill/drain volume targets at 1 Hz. + if ( ++reservoirDataPublicationTimerCounter >= RESERVOIR_DATA_PUB_INTERVAL ) + { + U32 actRes = getActiveReservoir(); + U32 filVol = getReservoirFillVolumeTargetMl(); + U32 drnVol = getReservoirDrainVolumeTargetMl(); + broadcastReservoirData( actRes, filVol, drnVol ); + reservoirDataPublicationTimerCounter = 0; + } +} + BOOL setActiveReservoir( RESERVOIR_ID_T resID ) { + BOOL result = FALSE; + // switch reservoir command only valid in re-circulate mode if ( MODE_CIRC == getCurrentOperationMode() ) { // validate parameters if ( resID < NUM_OF_RESERVOIRS ) { activeReservoir.data = (U32)resID; + result = TRUE; } } + + return result; } /*********************************************************************//** Index: firmware/App/Services/Reservoirs.h =================================================================== diff -u -r5a61bccd959265c00e5276ba23391198ca82b6dd -r5ff39fd6948ae3656b4035c85325bd8fca0a37f3 --- firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 5a61bccd959265c00e5276ba23391198ca82b6dd) +++ firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 5ff39fd6948ae3656b4035c85325bd8fca0a37f3) @@ -41,6 +41,7 @@ // ********** public function prototypes ********** void initReservoirs( void ); +void execReservoirs( void ); BOOL setActiveReservoir( RESERVOIR_ID_T resID ); // handle switch reservoirs command from HD BOOL startFill( U32 fillToVolMl ); // handle fill command from HD Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r5a61bccd959265c00e5276ba23391198ca82b6dd -r5ff39fd6948ae3656b4035c85325bd8fca0a37f3 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 5a61bccd959265c00e5276ba23391198ca82b6dd) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 5ff39fd6948ae3656b4035c85325bd8fca0a37f3) @@ -82,6 +82,13 @@ F32 drainPumpOutletPressure; } PRESSURES_DATA_T; +typedef struct +{ + U32 activeReservoir; + U32 fillToVolumeMl; + U32 drainToVolumeMl; +} RESERVOIR_DATA_T; + #pragma pack(pop) // ********** private data ********** @@ -307,6 +314,35 @@ } /************************************************************************* + * @brief + * The broadcastDGOpMode function constructs an operation mode msg to be \n + * broadcast and queues the msg for transmit on the appropriate CAN channel. + * @details + * Inputs : none + * Outputs : DG op mode msg constructed and queued. + * @param mode : ID of current DG op mode + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastDGOpMode( U32 mode ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_OP_MODE; + msg.hdr.payloadLen = sizeof( U32 ); + + memcpy( payloadPtr, &mode, sizeof( U32 ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_DG_BROADCAST, ACK_NOT_REQUIRED ); + + return result; +} + +/************************************************************************* * @brief broadcastRTCEpoch * The broadcastRTCEpoch function constructs an epoch msg to \n * be broadcast and queues the msg for transmit on the appropriate CAN channel. @@ -477,6 +513,31 @@ return result; } +// MSG_ID_DG_RESERVOIR_DATA +BOOL broadcastReservoirData( U32 resID, U32 fillToVol, U32 drainToVol ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + RESERVOIR_DATA_T payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_PRESSURES_DATA; + msg.hdr.payloadLen = sizeof( RESERVOIR_DATA_T ); + + payload.activeReservoir = resID; + payload.fillToVolumeMl = fillToVol; + payload.drainToVolumeMl = drainToVol; + + memcpy( payloadPtr, &payload, sizeof( RESERVOIR_DATA_T ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_DG_BROADCAST, ACK_NOT_REQUIRED ); + + return result; +} + /************************************************************************* * @brief * The handlePowerOffWarning function handles a power off warning message \n @@ -520,18 +581,20 @@ { MESSAGE_T msg; U08 *payloadPtr = msg.payload; - U16 buildNum = (U16)DG_VERSION_BUILD; + U08 major = (U08)DG_VERSION_MAJOR; + U08 minor = (U08)DG_VERSION_MINOR; + U16 build = (U16)DG_VERSION_BUILD; // create a message record blankMessage( &msg ); msg.hdr.msgID = MSG_ID_DG_VERSION; msg.hdr.payloadLen = sizeof( U08 ) + sizeof( U08 ) + sizeof( U16 ); - *payloadPtr = (U08)DG_VERSION_MAJOR; - payloadPtr++; - *payloadPtr = (U08)DG_VERSION_MINOR; - payloadPtr++; - memcpy( payloadPtr, &buildNum, sizeof( U16 ) ); + memcpy( payloadPtr, &major, sizeof( U08 ) ); + payloadPtr += sizeof( U08 ); + memcpy( payloadPtr, &minor, sizeof( U08 ) ); + payloadPtr += sizeof( U08 ); + memcpy( payloadPtr, &build, sizeof( U16 ) ); // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer serializeMessage( msg, COMM_BUFFER_OUT_CAN_DG_BROADCAST, ACK_NOT_REQUIRED ); Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r5a61bccd959265c00e5276ba23391198ca82b6dd -r5ff39fd6948ae3656b4035c85325bd8fca0a37f3 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 5a61bccd959265c00e5276ba23391198ca82b6dd) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 5ff39fd6948ae3656b4035c85325bd8fca0a37f3) @@ -32,6 +32,9 @@ // MSG_ID_ALARM_CLEARED BOOL broadcastAlarmCleared( U16 alarm ); +// MSG_ID_DG_OP_MODE +BOOL broadcastDGOpMode( U32 mode ); + // MSG_ID_RTC_EPOCH BOOL broadcastRTCEpoch( U32 epoch ); // TODO - probably don't want DG to broadcast these @@ -47,6 +50,9 @@ // MSG_ID_DG_PRESSURES_DATA BOOL broadcastPressureSensorsData( F32 measROIn, F32 measROOut, F32 measDrainIn, F32 measDrainOut ); +// MSG_ID_DG_RESERVOIR_DATA +BOOL broadcastReservoirData( U32 resID, U32 fillToVol, U32 drainToVol ); + // MSG_ID_POWER_OFF_WARNING void handlePowerOffWarning( MESSAGE_T *message ); Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -r68fc03b5a22f14190146fc9069f022c109682b63 -r5ff39fd6948ae3656b4035c85325bd8fca0a37f3 --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 68fc03b5a22f14190146fc9069f022c109682b63) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 5ff39fd6948ae3656b4035c85325bd8fca0a37f3) @@ -18,6 +18,7 @@ #include "lin.h" #include "OperationModes.h" +#include "Reservoirs.h" #include "ROPump.h" #include "SystemComm.h" #include "SystemCommMessages.h" @@ -46,6 +47,9 @@ // manage RO pump execROPumpController(); + // manage time-based reservoir tasks + execReservoirs(); + // run operation mode state machine execOperationModes();