Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r16dfbeeca1bcf1d2115c2f7549999fdaae0700e9 -r5a61bccd959265c00e5276ba23391198ca82b6dd --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 16dfbeeca1bcf1d2115c2f7549999fdaae0700e9) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 5a61bccd959265c00e5276ba23391198ca82b6dd) @@ -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 ********** @@ -66,6 +70,12 @@ typedef struct { + U32 setDrainPumpSpeed; + F32 drainPumpPWM; +} DRAIN_PUMP_DATA_T; + +typedef struct +{ F32 roPumpInletPressure; F32 roPumpOutletPressure; F32 drainPumpInletPressure; @@ -83,6 +93,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 @@ -197,6 +208,36 @@ 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 ************************* // *********************************************************************** @@ -368,6 +409,39 @@ /************************************************************************* * @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 @@ -404,6 +478,177 @@ } /************************************************************************* + * @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; + U16 buildNum = (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 ) ); + + // 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 *************************************************************************/