Index: firmware/App/DGCommon.h =================================================================== diff -u -r7e577bd98ab711d4f7e6ca5125968905ac411f1d -r25aab138cab85b53eef7d37f48d2a06985e93fbc --- firmware/App/DGCommon.h (.../DGCommon.h) (revision 7e577bd98ab711d4f7e6ca5125968905ac411f1d) +++ firmware/App/DGCommon.h (.../DGCommon.h) (revision 25aab138cab85b53eef7d37f48d2a06985e93fbc) @@ -21,9 +21,9 @@ // ********** version ********** -#define DG_VERSION_MAJOR 0 -#define DG_VERSION_MINOR 3 -#define DG_VERSION_BUILD 0 +#define DG_VERSION_MAJOR 0 +#define DG_VERSION_MINOR 3 +#define DG_VERSION_BUILD 0 // ********** build switches ********** #ifndef _RELEASE_ Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r8638b207699a3a48e3657e838e24ae838369c867 -r25aab138cab85b53eef7d37f48d2a06985e93fbc --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 8638b207699a3a48e3657e838e24ae838369c867) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 25aab138cab85b53eef7d37f48d2a06985e93fbc) @@ -978,6 +978,34 @@ // handle any messages from other sub-systems switch ( msgID ) { + case MSG_ID_POWER_OFF_WARNING: + handlePowerOffWarning( message ); + break; + + case MSG_ID_SET_DG_DIALYSATE_TEMP_TARGETS: + handleSetDialysateTemperatureCmd( message ); + break; + + case MSG_ID_REQUEST_FW_VERSIONS: + handleFWVersionCmd( message ); + break; + + case MSG_ID_DG_SWITCH_RESERVOIR: + handleSwitchReservoirCmd( message ); + break; + + case MSG_ID_DG_FILL: + handleFillCmd( message ); + break; + + case MSG_ID_DG_DRAIN: + handleDrainCmd( message ); + break; + + case MSG_ID_STARTING_STOPPING_TREATMENT: + handleStartStopTreatmentMsg( message ); + break; + case MSG_ID_DG_TESTER_LOGIN_REQUEST: handleTesterLogInRequest( message ); break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -rdd3356035996866e5db7678d352f933fc22ad789 -r25aab138cab85b53eef7d37f48d2a06985e93fbc --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision dd3356035996866e5db7678d352f933fc22ad789) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 25aab138cab85b53eef7d37f48d2a06985e93fbc) @@ -18,13 +18,17 @@ #include // for memcpy() +#include "DrainPump.h" +#include "LoadCell.h" #include "MsgQueues.h" +#include "OperationModes.h" +#include "Reservoirs.h" +#include "ROPump.h" +#include "RTC.h" +#include "SystemComm.h" +#include "Utilities.h" #include "WatchdogMgmt.h" #include "SystemCommMessages.h" -#include "Utilities.h" -#include "SystemComm.h" -#include "RTC.h" -#include "LoadCell.h" // ********** private definitions ********** @@ -57,6 +61,34 @@ F32 loadCellB2inGram; } LOAD_CELL_DATA_T; +typedef struct +{ + U32 setROPumpPressure; + F32 measROFlowRate; + F32 roPumpPWM; +} RO_PUMP_DATA_T; + +typedef struct +{ + U32 setDrainPumpSpeed; + F32 drainPumpPWM; +} DRAIN_PUMP_DATA_T; + +typedef struct +{ + F32 roPumpInletPressure; + F32 roPumpOutletPressure; + F32 drainPumpInletPressure; + F32 drainPumpOutletPressure; +} PRESSURES_DATA_T; + +typedef struct +{ + U32 activeReservoir; + U32 fillToVolumeMl; + U32 drainToVolumeMl; +} RESERVOIR_DATA_T; + #pragma pack(pop) // ********** private data ********** @@ -68,6 +100,7 @@ static U32 serializeMessage( MESSAGE_T msg, COMM_BUFFER_T buffer, BOOL ackReq ); static BOOL sendTestAckResponseMsg( MSG_ID_T msgID, BOOL ack ); +static BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ); /************************************************************************* * @brief serializeMessage @@ -182,8 +215,38 @@ return result; } +/************************************************************************* + * @brief sendTestAckResponseMsg + * The sendTestAckResponseMsg function constructs a simple response \n + * message for a handled test message and queues it for transmit on the \n + * appropriate UART channel. + * @details + * Inputs : none + * Outputs : response message constructed and queued for transmit. + * @param msgID : ID of handled message that we are responding to + * @param buffer : outgoing buffer that message should be queued in + * @param ack : TRUE if test message was handled successfully, FALSE if not + * @return TRUE if response message successfully queued for transmit, FALSE if not + *************************************************************************/ +static BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ) +{ + BOOL result; + MESSAGE_T msg; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = msgID; + msg.hdr.payloadLen = sizeof( U08 ); + msg.payload[ 0 ] = (U08)ack; + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, buffer, ACK_NOT_REQUIRED ); + + return result; +} + // *********************************************************************** -// ********************* MSG_ID_OFF_BUTTON_PRESS ************************* +// ***************** Message Sending Helper Functions ******************** // *********************************************************************** /************************************************************************* @@ -281,34 +344,26 @@ /************************************************************************* * @brief - * The broadcastTreatmentTime function constructs a treatment time msg to \n - * be broadcast and queues the msg for transmit on the appropriate CAN channel. + * The broadcastDGHDOperationMode function constructs a DG operation mode \n + * broadcast message and queues the msg for transmit on the appropriate CAN channel. * @details * Inputs : none - * Outputs : treatment time data msg constructed and queued - * @param secsTotTreatment : Total treatment time prescribed (in seconds). - * @param secsElapsed : Treatment time elapsed (in seconds). - * @param secsRemaining : Treatment time remaining (in seconds). + * Outputs : DG operation mode msg constructed and queued * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -BOOL broadcastTreatmentTime( U32 secsTotTreatment, U32 secsElapsed, U32 secsRemaining ) +BOOL broadcastDGOperationMode( U32 mode ) { BOOL result; MESSAGE_T msg; U08 *payloadPtr = msg.payload; - TREATMENT_TIME_DATA_T payload; // create a message record blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_TREATMENT_TIME; - msg.hdr.payloadLen = sizeof( TREATMENT_TIME_DATA_T ); + msg.hdr.msgID = MSG_ID_DG_OP_MODE; + msg.hdr.payloadLen = sizeof( U32 ); - payload.treatmentTimePrescribedinSec = secsTotTreatment; - payload.treatmentTimeElapsedinSec = secsElapsed; - payload.treatmentTimeRemaininginSec = secsRemaining; + memcpy( payloadPtr, &mode, sizeof( U32 ) ); - memcpy( payloadPtr, &payload, sizeof( TREATMENT_TIME_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 ); @@ -319,7 +374,7 @@ * @brief * The broadcastLoadCellData function sends out load cell data. * @details - * Inputs : load cell data + * Inputs : none * Outputs : load cell data msg constructed and queued * @param loadCellA1 : load cell A 1 data in grams. * @param loadCellA2 : load cell A 2 data in grams. @@ -352,8 +407,324 @@ return result; } +/************************************************************************* + * @brief + * The broadcastROPumpData function sends out RO pump data. + * @details + * Inputs : none + * Outputs : RO pump data msg constructed and queued + * @param tgtPressure : target pressure for RO pump in PSI. + * @param measFlow : measure RO flow rate in LPM. + * @param setPWM : set PWM duty cycle in %. + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastROPumpData( U32 tgtPressure, F32 measFlow, F32 setPWM ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + RO_PUMP_DATA_T payload; + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_RO_PUMP_DATA; + msg.hdr.payloadLen = sizeof( RO_PUMP_DATA_T ); + + payload.setROPumpPressure = tgtPressure; + payload.measROFlowRate = measFlow; + payload.roPumpPWM = setPWM; + + memcpy( payloadPtr, &payload, sizeof( RO_PUMP_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 broadcastDrainPumpData function sends out RO pump data. + * @details + * Inputs : none + * Outputs : Drain pump data msg constructed and queued + * @param tgtSpeed : target speed for drain pump in RPM. + * @param setPWM : set PWM duty cycle in %. + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastDrainPumpData( U32 tgtSpeed, F32 setPWM ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + DRAIN_PUMP_DATA_T payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DRAIN_PUMP_DATA; + msg.hdr.payloadLen = sizeof( DRAIN_PUMP_DATA_T ); + + payload.setDrainPumpSpeed = tgtSpeed; + payload.drainPumpPWM = setPWM; + + memcpy( payloadPtr, &payload, sizeof( DRAIN_PUMP_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 broadcastPressureSensorsData function sends out DG pressure data. + * @details + * Inputs : none + * Outputs : Pressure data msg constructed and queued + * @param measROIn : measured RO pump inlet pressure in PSI. + * @param measROOut : measured RO pump outlet pressure in PSI. + * @param measDrainIn : measured Drain pump inlet pressure in PSI. + * @param measDrainOut : measured Drain pump outlet pressure in PSI. + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastPressureSensorsData( F32 measROIn, F32 measROOut, F32 measDrainIn, F32 measDrainOut ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + PRESSURES_DATA_T payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_PRESSURES_DATA; + msg.hdr.payloadLen = sizeof( PRESSURES_DATA_T ); + + payload.roPumpInletPressure = measROIn; + payload.roPumpOutletPressure = measROOut; + payload.drainPumpInletPressure = measDrainIn; + payload.drainPumpOutletPressure = measDrainOut; + + memcpy( payloadPtr, &payload, sizeof( PRESSURES_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 broadcastReservoirData function broadcasts the DG reservoir data. + * @details + * Inputs : none + * Outputs : Reservoir data msg constructed and queued + * @param resID : ID of currently active reservoir. + * @param fillToVol : Current target fill to volume for inactive reservoir. + * @param drainToVol : Current target drain to volume for inactive reservoir. + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +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; +} + +// *********************************************************************** +// **************** Message Handling Helper Functions ******************** +// *********************************************************************** + +/************************************************************************* + * @brief + * The handlePowerOffWarning function handles a power off warning message \n + * from the HD. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handlePowerOffWarning( MESSAGE_T *message ) +{ + // TODO - signal modules that require a warning +} + +/************************************************************************* + * @brief + * The handleSetDialysateTemperatureCmd function handles a dialysate temperature \n + * set points message from the HD. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetDialysateTemperatureCmd( MESSAGE_T *message ) +{ + // TODO - parse and send temp targets to heaters module +} + +/************************************************************************* + * @brief + * The handleFWVersionCmd function handles a FW version request message. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleFWVersionCmd( MESSAGE_T *message ) +{ + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + 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 ); + + 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 ); +} + +/************************************************************************* + * @brief + * The handleSwitchReservoirCmd function handles a switch reservoirs command \n + * from the HD. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSwitchReservoirCmd( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + U32 reservoirID; + + result = TRUE; + memcpy( &reservoirID, message->payload, sizeof(U32) ); + setActiveReservoir( (RESERVOIR_ID_T)reservoirID ); + } + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_DG_2_HD, result ); +} + +/************************************************************************* + * @brief + * The handleFillCmd function handles a fill command from the HD. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleFillCmd( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + U32 fillToVolumeMl; + + result = TRUE; + memcpy( &fillToVolumeMl, message->payload, sizeof(U32) ); + startFill( fillToVolumeMl ); + } + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_DG_2_HD, result ); +} + +/************************************************************************* + * @brief + * The handleDrainCmd function handles a drain command from the HD. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleDrainCmd( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + U32 drainToVolMl; + + result = TRUE; + memcpy( &drainToVolMl, message->payload, sizeof(U32) ); + + startDrain( drainToVolMl ); + } + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_DG_2_HD, result ); +} + +/************************************************************************* + * @brief + * The handleStartStopTreatmentMsg function handles a treatment start/stop \n + * message from the HD. + * @details + * Inputs : none + * Outputs : message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleStartStopTreatmentMsg( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + BOOL startingTreatment; + + result = TRUE; + memcpy( &startingTreatment, message->payload, sizeof(U32) ); + + if ( MODE_STAN == getCurrentOperationMode() && TRUE == startingTreatment ) + { + requestNewOperationMode( MODE_CIRC ); + } + else if ( MODE_CIRC == getCurrentOperationMode() && FALSE == startingTreatment ) + { + requestNewOperationMode( MODE_STAN ); + } + else + { + result = FALSE; + } + } + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_DG_2_HD, result ); +} + +/************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/