Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -rd91a24c730aeb5cd7e3eba9ef4eca78e442911f8 -r1fb58baf6e7e3d1f054b2a3634e233da7609dad9 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision d91a24c730aeb5cd7e3eba9ef4eca78e442911f8) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 1fb58baf6e7e3d1f054b2a3634e233da7609dad9) @@ -33,7 +33,8 @@ #include "SafetyShutdown.h" #include "SystemComm.h" #include "SystemCommMessages.h" -#include "Utilities.h" +#include "Utilities.h" +#include "Valves.h" #include "WatchdogMgmt.h" #include "RTC.h" @@ -1127,6 +1128,54 @@ result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_BROADCAST, ACK_NOT_REQUIRED ); return result; +} + +/***********************************************************************//** + * @brief + * The broadcastHDValves function constructs an HD valves msg to \n + * be broadcast and queues the msg for transmit on the appropriate CAN channel. + * @details + * Inputs : none + * Outputs : HD valves msg constructed and queued + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastHDValves( HD_VALVE_DATA_T *valveData ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_VALVES_DATA; + msg.hdr.payloadLen = sizeof( HD_VALVE_DATA_T ); + + memcpy( payloadPtr, valveData, sizeof( HD_VALVE_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_HD_BROADCAST, ACK_NOT_REQUIRED ); + + return result; +} + +// TODO remove this function +BOOL broadcastFastTempHDValves( HD_VALVE_FAST_DATA_T *fastDataRemoveLater ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_TEMP_FAST_HD_VALVES_REMOVE_LATER; + msg.hdr.payloadLen = sizeof( HD_VALVE_FAST_DATA_T ); + + memcpy( payloadPtr, fastDataRemoveLater, sizeof( HD_VALVE_FAST_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_HD_BROADCAST, ACK_NOT_REQUIRED ); + + return result; } #ifdef EMC_TEST_BUILD @@ -3364,8 +3413,159 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } +/************************************************************************* + * @brief + * The handleHomeHDValve function handles a request to home an HD valve + * @details + * Inputs: none + * Outputs: message handled + * @param message: a pointer to the message to handle + * @return none + *************************************************************************/ +void handleHomeHDValve( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + U32 valve; + + memcpy( &valve, message->payload, sizeof(U32) ); + homeValve( (VALVE_T)valve ); + + result = TRUE; + } + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + /*********************************************************************//** * @brief + * The handleTestHDValvesBroadcastIntervalOverrideRequest function handles \n + * a request to override the broadcast interval for HD valves data. + * @details + * Inputs: none + * Outputs: message handled + * @param message: a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestHDValvesBroadcastIntervalOverrideRequest( MESSAGE_T *message ) +{ + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + + BOOL result = FALSE; + // verify payload length + if ( sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) ); + if ( FALSE == payload.reset ) + { + result = testSetValvesDataPublishInterval( (BOOL)(payload.state.u32) ); + } + else + { + result = testResetValvesDataPublishInterval(); + } + } + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief + * The handleSetBloodValve function handles a request to set the HD air + * (blood) trap valve to open or close + * @details + * Inputs: none + * Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetAirTrapValve( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + U32 valveState; + + memcpy( &valveState, message->payload, sizeof(U32) ); + setValveAirTrap( (OPN_CLS_STATE_T)valveState ); + + result = TRUE; + } + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/************************************************************************* + * @brief + * The handleSetHDValvePositionOverrideRequest function handles a request to + * override the position of a valve + * @details + * Inputs: none + * Outputs: message handled + * @param message: a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetHDValvePositionOverrideRequest( MESSAGE_T *message ) +{ + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + + BOOL result = FALSE; + // verify payload length + if ( sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) ); + if ( FALSE == payload.reset ) + { + result = testSetValvesPositionOverride( payload.index, (BOOL)(payload.state.u32) ); + } + else + { + result = testResetValvesPositionOverride( payload.index ); + } + } + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +#ifdef DEBUG_ENABLED +/************************************************************************* + * @brief + * The handleSetHDValvePWMOverrideRequest function handles a request to + * override the PWM of a valve + * @details + * Inputs: none + * Outputs: message handled + * @param message: a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetHDValvePWMOverrideRequest( MESSAGE_T *message ) +{ + OVERRIDE_VALVES_PWM_DIR_SET_PAYLOAD_T payload; + + BOOL result = FALSE; + // verify payload length + if ( sizeof(OVERRIDE_VALVES_PWM_DIR_SET_PAYLOAD_T) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof(OVERRIDE_VALVES_PWM_DIR_SET_PAYLOAD_T) ); + if ( FALSE == payload.reset ) + { + result = testSetValvePWMOverride( payload.valve, payload.pwm, payload.direction ); + } + else + { + result = testResetValvePWMOverride( payload.valve ); + } + } + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} +#endif + +/*********************************************************************//** + * @brief * The handleSetDialysateFlowCalibration function handles a request to set * dialysate flow calibration factors. * @details