Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r5e99007b56b14a0656fabb7145fe86ac17900f93 -r88f28230d288947ba84840b967e95b32e3deffaa --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 5e99007b56b14a0656fabb7145fe86ac17900f93) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 88f28230d288947ba84840b967e95b32e3deffaa) @@ -40,7 +40,9 @@ #include "SafetyShutdown.h" #include "SystemCommMessages.h" #include "TemperatureSensors.h" +#include "Thermistors.h" #include "Utilities.h" +#include "Utilities.h" #include "Valves.h" #include "WatchdogMgmt.h" #include "UVReactors.h" @@ -58,102 +60,102 @@ #ifdef DEBUG_ENABLED #define DEBUG_EVENT_MAX_TEXT_LEN 40 #endif - -// ********** private data ********** - -static BOOL testerLoggedIn = FALSE; ///< Flag indicates whether tester logged in or not. + +// ********** private data ********** + +static BOOL testerLoggedIn = FALSE; ///< Flag indicates whether tester logged in or not. static volatile U16 nextSeqNo = 1; ///< Next sequence number. + +// ********** private function prototypes ********** + +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 + * The serializeMessage function serializes a given message into a given + * array of bytes. A sequence # is added to the message here and the ACK + * bit of the sequence # is set if ACK is required per parameter. A sync byte + * is inserted at the beginning of the message and an 8-bit CRC is appended to + * the end of the message. The message is queued for transmission in the given buffer. + * @details Inputs: none + * @details Outputs: given data array populated with serialized message data and queued for transmit. + * @param msg message to serialize + * @param buffer outgoing buffer that message should be queued in + * @param ackReq is an acknowledgement from receiver required? + * @return size (in bytes) of serialized message populated in given data array. + *************************************************************************/ +static U32 serializeMessage( MESSAGE_T msg, COMM_BUFFER_T buffer, BOOL ackReq ) +{ + BOOL result = FALSE; + BOOL error = FALSE; + U32 msgSize = 0; + U32 sizeMod, sizePad; + U32 i; + U08 crc; + U08 data[ MAX_ACK_MSG_SIZE ]; // byte array to populate with message data + + // prefix data with message sync byte + data[ msgSize++ ] = MESSAGE_SYNC_BYTE; + + // set sequence # and ACK bit (unless this is an ACK to a received message) + if ( msg.hdr.msgID != MSG_ID_ACK ) + { + // thread protect next sequence # access & increment + _disable_IRQ(); + msg.hdr.seqNo = nextSeqNo; + nextSeqNo = INC_WRAP( nextSeqNo, MIN_MSG_SEQ_NO, MAX_MSG_SEQ_NO ); + _enable_IRQ(); + if ( TRUE == ackReq ) + { + msg.hdr.seqNo *= -1; + } + } + + // calculate message CRC + crc = crc8( (U08*)(&msg), sizeof( MESSAGE_HEADER_T ) + msg.hdr.payloadLen ); + + // serialize message header data + memcpy( &data[ msgSize ], &( msg.hdr ), sizeof( MESSAGE_HEADER_T ) ); + msgSize += sizeof( MESSAGE_HEADER_T ); + + // serialize message payload (only used bytes per payloadLen field) + memcpy( &data[ msgSize ], &( msg.payload ), msg.hdr.payloadLen ); + msgSize += msg.hdr.payloadLen; + + // add 8-bit CRC + data[ msgSize++ ] = crc; + + // pad with zero bytes to get length a multiple of CAN_MESSAGE_PAYLOAD_SIZE (8) + sizeMod = msgSize % CAN_MESSAGE_PAYLOAD_SIZE; + sizePad = ( sizeMod == 0 ? 0 : CAN_MESSAGE_PAYLOAD_SIZE - sizeMod ); + for ( i = 0; i < sizePad; i++ ) + { + data[ msgSize++ ] = 0; + } + + // if ACK required, add to pending ACK list + if ( TRUE == ackReq ) + { + if ( FALSE == addMsgToPendingACKList( &msg, buffer, data, msgSize ) ) + { + error = TRUE; + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_MSG_PENDING_ACK_LIST_FULL ) + } + } + + if ( FALSE == error ) + { + // add serialized message data to appropriate out-going comm buffer + result = addToCommBuffer( buffer, data, msgSize ); + } + + return result; +} -// ********** private function prototypes ********** - -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 - * The serializeMessage function serializes a given message into a given - * array of bytes. A sequence # is added to the message here and the ACK - * bit of the sequence # is set if ACK is required per parameter. A sync byte - * is inserted at the beginning of the message and an 8-bit CRC is appended to - * the end of the message. The message is queued for transmission in the given buffer. - * @details Inputs: none - * @details Outputs: given data array populated with serialized message data and queued for transmit. - * @param msg message to serialize - * @param buffer outgoing buffer that message should be queued in - * @param ackReq is an acknowledgement from receiver required? - * @return size (in bytes) of serialized message populated in given data array. - *************************************************************************/ -static U32 serializeMessage( MESSAGE_T msg, COMM_BUFFER_T buffer, BOOL ackReq ) -{ - BOOL result = FALSE; - BOOL error = FALSE; - U32 msgSize = 0; - U32 sizeMod, sizePad; - U32 i; - U08 crc; - U08 data[ MAX_ACK_MSG_SIZE ]; // byte array to populate with message data - - // prefix data with message sync byte - data[ msgSize++ ] = MESSAGE_SYNC_BYTE; - - // set sequence # and ACK bit (unless this is an ACK to a received message) - if ( msg.hdr.msgID != MSG_ID_ACK ) - { - // thread protect next sequence # access & increment - _disable_IRQ(); - msg.hdr.seqNo = nextSeqNo; - nextSeqNo = INC_WRAP( nextSeqNo, MIN_MSG_SEQ_NO, MAX_MSG_SEQ_NO ); - _enable_IRQ(); - if ( TRUE == ackReq ) - { - msg.hdr.seqNo *= -1; - } - } - - // calculate message CRC - crc = crc8( (U08*)(&msg), sizeof( MESSAGE_HEADER_T ) + msg.hdr.payloadLen ); - - // serialize message header data - memcpy( &data[ msgSize ], &( msg.hdr ), sizeof( MESSAGE_HEADER_T ) ); - msgSize += sizeof( MESSAGE_HEADER_T ); - - // serialize message payload (only used bytes per payloadLen field) - memcpy( &data[ msgSize ], &( msg.payload ), msg.hdr.payloadLen ); - msgSize += msg.hdr.payloadLen; - - // add 8-bit CRC - data[ msgSize++ ] = crc; - - // pad with zero bytes to get length a multiple of CAN_MESSAGE_PAYLOAD_SIZE (8) - sizeMod = msgSize % CAN_MESSAGE_PAYLOAD_SIZE; - sizePad = ( sizeMod == 0 ? 0 : CAN_MESSAGE_PAYLOAD_SIZE - sizeMod ); - for ( i = 0; i < sizePad; i++ ) - { - data[ msgSize++ ] = 0; - } - - // if ACK required, add to pending ACK list - if ( TRUE == ackReq ) - { - if ( FALSE == addMsgToPendingACKList( &msg, buffer, data, msgSize ) ) - { - error = TRUE; - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_MSG_PENDING_ACK_LIST_FULL ) - } - } - - if ( FALSE == error ) - { - // add serialized message data to appropriate out-going comm buffer - result = addToCommBuffer( buffer, data, msgSize ); - } - - return result; -} - -/*********************************************************************//** - * @brief * The sendACKMsg function constructs and queues for transmit an ACK message * for a given received message. * @details Inputs: none @@ -325,24 +327,149 @@ /*********************************************************************//** * @brief * The broadcastRTCEpoch function constructs an epoch msg to be broadcast - * and queues the msg for transmit on the appropriate CAN channel. + * and queues the msg for transmit on the appropriate CAN channel. + * @details Inputs: none + * @details Outputs: RTC time and date in epoch + * @param epoch Current time and date in epoch + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastRTCEpoch( U32 epoch ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_RTC_EPOCH; + msg.hdr.payloadLen = sizeof( U32 ); + + memcpy( payloadPtr, &epoch, 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 + * The broadcastLoadCellData function sends out load cell data. + * @details Inputs: none + * @details 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 + * @param loadCellB1 load cell B 1 data in grams + * @param loadCellB2 load cell B 2 data in grams + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastLoadCellData( F32 loadCellA1, F32 loadCellA2, F32 loadCellB1, F32 loadCellB2 ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + LOAD_CELL_DATA_T payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_LOAD_CELL_READINGS; + msg.hdr.payloadLen = sizeof( LOAD_CELL_DATA_T ); + + payload.loadCellA1inGram = loadCellA1; + payload.loadCellA2inGram = loadCellA2; + payload.loadCellB1inGram = loadCellB1; + payload.loadCellB2inGram = loadCellB2; + + memcpy( payloadPtr, &payload, sizeof( LOAD_CELL_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 broadcastValvesStates function sends out DG valves states. + * @details Inputs: none + * @details Outputs: Valves states msg constructed and queued + * @param valvesStates valves states + * refer to setFPGAValveStates function in FPGA.c for details + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastValvesStates( U16 valvesStates ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_VALVES_STATES; + msg.hdr.payloadLen = sizeof( U16 ); + + memcpy( payloadPtr, &valvesStates, sizeof( U16 ) ); + + // 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 broadcastHeatersData function sends out DG heaters data + * @details Inputs: heaters data + * @details Outputs: heatears data msg constructed and queued + * @param mainPrimaryDC main primary heater duty cycle + * @param smallPrimaryDC small primary heater duty cycle + * @param trimmerDC trimmer heater duty cycle + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastHeatersData ( U32 mainPrimaryDC, U32 smallPrimaryDC, U32 trimmerDC ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + HEATERS_DATA_T payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_HEATERS_DATA; + msg.hdr.payloadLen = sizeof( HEATERS_DATA_T ); + + payload.mainPrimayHeaterDC = mainPrimaryDC; + payload.smallPrimaryHeaterDC = smallPrimaryDC; + payload.trimmerHeaterDC = trimmerDC; + + memcpy( payloadPtr, &payload, sizeof( HEATERS_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 the drain pump data. * @details Inputs: none - * @details Outputs: RTC time and date in epoch - * @param epoch Current time and date in epoch + * @details Outputs: Drain pump data msg constructed and queued + * @param drainPumpData which is the drain pump data structure pointer * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -BOOL broadcastRTCEpoch( U32 epoch ) +BOOL broadcastDrainPumpData( DRAIN_PUMP_DATA_T *drainPumpData ) { BOOL result; MESSAGE_T msg; U08 *payloadPtr = msg.payload; // create a message record blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_RTC_EPOCH; - msg.hdr.payloadLen = sizeof( U32 ); + msg.hdr.msgID = MSG_ID_DRAIN_PUMP_DATA; + msg.hdr.payloadLen = sizeof( DRAIN_PUMP_DATA_T ); - memcpy( payloadPtr, &epoch, sizeof( U32 ) ); + memcpy( payloadPtr, drainPumpData, 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 ); @@ -383,104 +510,6 @@ /*********************************************************************//** * @brief - * The broadcastLoadCellData function sends out load cell data. - * @details Inputs: none - * @details 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 - * @param loadCellB1 load cell B 1 data in grams - * @param loadCellB2 load cell B 2 data in grams - * @return TRUE if msg successfully queued for transmit, FALSE if not - *************************************************************************/ -BOOL broadcastLoadCellData( F32 loadCellA1, F32 loadCellA2, F32 loadCellB1, F32 loadCellB2 ) -{ - BOOL result; - MESSAGE_T msg; - U08 *payloadPtr = msg.payload; - LOAD_CELL_DATA_T payload; - - // create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_LOAD_CELL_READINGS; - msg.hdr.payloadLen = sizeof( LOAD_CELL_DATA_T ); - - payload.loadCellA1inGram = loadCellA1; - payload.loadCellA2inGram = loadCellA2; - payload.loadCellB1inGram = loadCellB1; - payload.loadCellB2inGram = loadCellB2; - - memcpy( payloadPtr, &payload, sizeof( LOAD_CELL_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 broadcastValvesStates function sends out DG valves states. - * @details Inputs: none - * @details Outputs: Valves states msg constructed and queued - * @param valvesStates valves states - * refer to setFPGAValveStates function in FPGA.c for details - * @return TRUE if msg successfully queued for transmit, FALSE if not - *************************************************************************/ -BOOL broadcastValvesStates( U16 valvesStates ) -{ - BOOL result; - MESSAGE_T msg; - U08 *payloadPtr = msg.payload; - - // create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_DG_VALVES_STATES; - msg.hdr.payloadLen = sizeof( U16 ); - - memcpy( payloadPtr, &valvesStates, sizeof( U16 ) ); - - // 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 broadcastHeatersData function sends out DG heaters data - * @details Inputs: heaters data - * @details Outputs: heatears data msg constructed and queued - * @param mainPrimaryDC main primary heater duty cycle - * @param smallPrimaryDC small primary heater duty cycle - * @param trimmerDC trimmer heater duty cycle - * @return TRUE if msg successfully queued for transmit, FALSE if not - *************************************************************************/ -BOOL broadcastHeatersData ( U32 mainPrimaryDC, U32 smallPrimaryDC, U32 trimmerDC ) -{ - BOOL result; - MESSAGE_T msg; - U08 *payloadPtr = msg.payload; - HEATERS_DATA_T payload; - - // create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_DG_HEATERS_DATA; - msg.hdr.payloadLen = sizeof( HEATERS_DATA_T ); - - payload.mainPrimayHeaterDC = mainPrimaryDC; - payload.smallPrimaryHeaterDC = smallPrimaryDC; - payload.trimmerHeaterDC = trimmerDC; - - memcpy( payloadPtr, &payload, sizeof( HEATERS_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 broadcastROPumpData function sends out RO pump data. * @details Inputs: none * @details Outputs: RO pump data msg constructed and queued @@ -489,24 +518,19 @@ * @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 broadcastROPumpData( RO_PUMP_DATA_T *pumpData ) { 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, pumpData, sizeof( RO_PUMP_DATA_T ) ); - 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 ); @@ -515,38 +539,6 @@ /*********************************************************************//** * @brief - * The broadcastDrainPumpData function sends out drain pump data. - * @details Inputs: none - * @details Outputs: Drain pump data msg constructed and queued - * @param tgtSpeed target speed for drain pump in RPM - * @param dac set DAC value - * @return TRUE if msg successfully queued for transmit, FALSE if not - *************************************************************************/ -BOOL broadcastDrainPumpData( U32 tgtSpeed, U32 dac ) -{ - 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.dacValue = dac; - - 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 broadcastConcentratePumpData function sends out concentrate pumps' data. * @details Inputs: none * @details Outputs: concentrate pump data msg constructed and queued @@ -675,25 +667,25 @@ /*********************************************************************//** * @brief - * The broadcastConductivityData function sends out conductivity data. + * The broadcastThermistorsData function sends out the thermistors data. + * @details * @details Inputs: none - * @details Outputs: conductivity data message constructed and queued - * @param roRejectionRatio RO rejection ratio - * @param cpi water inlet conductivity data - * @param cpo water outlet conductivity data + * @details Outputs: thermistors data msg constructed and queued + * @param thermistorsData which is constructed and queued * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -BOOL broadcastConductivityData( void * conductivityDataPtr ) +BOOL broadcastThermistorsData( THERMISTORS_DATA_T *thermistorsData ) { BOOL result; MESSAGE_T msg; + U08 *payloadPtr = msg.payload; // create a message record blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_DG_CONDUCTIVITY_DATA; - msg.hdr.payloadLen = sizeof( CONDUCTIVITY_DATA_T ); + msg.hdr.msgID = MSG_ID_DG_THERMISTORS_DATA; + msg.hdr.payloadLen = sizeof( THERMISTORS_DATA_T ); - memcpy( &msg.payload, conductivityDataPtr, sizeof( CONDUCTIVITY_DATA_T ) ); + memcpy( payloadPtr, thermistorsData, sizeof( THERMISTORS_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 ); @@ -703,24 +695,24 @@ /*********************************************************************//** * @brief - * The broadcastUVReactorsData function sends out the UV reactors data. + * The broadcastFansData function sends out the fans data. * @details Inputs: none - * @details Outputs: UV reactors data msg constructed and queued - * @param UV reactors msg constructed and queued + * @details Outputs: fans data msg constructed and queued + * @param fansData which is constructed and queued * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -BOOL broadcastUVReactorsData( UV_REACTORS_DATA_T *uvReactorsData ) +BOOL broadcastFansData( FANS_DATA_T *fansData ) { BOOL result; MESSAGE_T msg; U08 *payloadPtr = msg.payload; // create a message record blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_DG_UV_REACTORS_DATA; - msg.hdr.payloadLen = sizeof( UV_REACTORS_DATA_T ); + msg.hdr.msgID = MSG_ID_DG_FANS_DATA; + msg.hdr.payloadLen = sizeof( FANS_DATA_T ); - memcpy( payloadPtr, uvReactorsData, sizeof( UV_REACTORS_DATA_T ) ); + memcpy( payloadPtr, fansData, sizeof( FANS_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 ); @@ -810,6 +802,65 @@ /*********************************************************************//** * @brief + * The broadcastConductivityData function sends out conductivity data. + * @details Inputs: none + * @details Outputs: conductivity data message constructed and queued + * @param roRejectionRatio RO rejection ratio + * @param cpi water inlet conductivity data + * @param cpo water outlet conductivity data + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastConductivityData( void * conductivityDataPtr ) +{ + BOOL result; + MESSAGE_T msg; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_CONDUCTIVITY_DATA; + msg.hdr.payloadLen = sizeof( CONDUCTIVITY_DATA_T ); + + memcpy( &msg.payload, conductivityDataPtr, sizeof( CONDUCTIVITY_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 broadcastUVReactorsData function sends out the UV reactors data. + * @details Inputs: none + * @details Outputs: UV reactors data msg constructed and queued + * @param UV reactors msg constructed and queued + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastUVReactorsData( UV_REACTORS_DATA_T *uvReactorsData ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_DG_UV_REACTORS_DATA; + msg.hdr.payloadLen = sizeof( UV_REACTORS_DATA_T ); + + memcpy( payloadPtr, uvReactorsData, sizeof( UV_REACTORS_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 handleSwitchReservoirCmd function handles a switch reservoirs command * from the HD. * @details Inputs: none @@ -1037,6 +1088,9 @@ * TEST SUPPORT FUNCTIONS *************************************************************************/ +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ #ifdef DEBUG_ENABLED /*********************************************************************//** @@ -1441,47 +1495,16 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } -/*********************************************************************//** - * @brief - * The handleTestROPumpSetPointOverrideRequest function handles a request to - * override the RO pump pressure set point (in PSI). - * @details Inputs: none - * @details Outputs: message handled - * @param message a pointer to the message to handle - * @return none - *************************************************************************/ -void handleTestROPumpSetPointOverrideRequest( MESSAGE_T *message ) -{ - TEST_OVERRIDE_PAYLOAD_T payload; - BOOL result = FALSE; - // verify payload length - if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) - { - memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); - if ( FALSE == payload.reset ) - { - result = testSetTargetROPumpPressureOverride( payload.state.u32 ); - } - else - { - result = testResetTargetROPumpPressureOverride(); - } - } - - // respond to request - sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); -} - -/*********************************************************************//** - * @brief - * The handleTestROMeasuredFlowOverrideRequest function handles a request to - * override the RO flow rate. - * @details Inputs: none - * @details Outputs: message handled - * @param message a pointer to the message to handle - * @return none - *************************************************************************/ +/*********************************************************************//** + * @brief + * The handleTestROMeasuredFlowOverrideRequest function handles a request to + * override the RO flow rate. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ void handleTestROMeasuredFlowOverrideRequest( MESSAGE_T *message ) { TEST_OVERRIDE_PAYLOAD_T payload; @@ -1546,23 +1569,18 @@ * @param message a pointer to the message to handle * @return none *************************************************************************/ -void handleTestDrainPumpSetPointOverrideRequest( MESSAGE_T *message ) +void handleTestDrainPumpRPMOverrideRequest( MESSAGE_T *message ) { - TEST_OVERRIDE_PAYLOAD_T payload; BOOL result = FALSE; // verify payload length - if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) + if ( sizeof( U32 ) == message->hdr.payloadLen ) { - memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); - if ( FALSE == payload.reset ) - { - result = testSetTargetDrainPumpSpeedOverride( payload.state.u32 ); - } - else - { - result = testResetTargetDrainPumpSpeedOverride(); - } + U32 payLoad; + + memcpy( &payLoad, message->payload, sizeof( U32 ) ); + + result = testSetTargetDrainPumpRPM( payLoad ); } // respond to request @@ -1584,9 +1602,9 @@ BOOL result = FALSE; // verify payload length - if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) + if ( sizeof(TEST_OVERRIDE_PAYLOAD_T) == message->hdr.payloadLen ) { - memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); + memcpy( &payload, message->payload, sizeof(TEST_OVERRIDE_PAYLOAD_T) ); if ( FALSE == payload.reset ) { result = testSetDrainPumpDataPublishIntervalOverride( payload.state.u32 ); @@ -1697,6 +1715,32 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } +/************************************************************************* + * @brief + * The handleSetDrainPumpDeltaPressureOverrideRequest function handles a + * request to override the delta pressure for the drain pump. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetDrainPumpDeltaPressureOverrideRequest( MESSAGE_T *message ) +{ + BOOL result = 0; + + /* verify payload length */ + if ( sizeof( F32 ) == message->hdr.payloadLen ) + { + F32 payLoad; + + memcpy( &payLoad, message->payload, sizeof( F32 ) ); + + result = testSetTargetDrainPumpDeltaPressure( payLoad ); + } + /* respond to request */ + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + /*********************************************************************//** * @brief * The handleTestDGAccelOverrideRequest function handles a request to @@ -2134,4 +2178,197 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } +/*********************************************************************//** +* @brief +* The handleTestThermistorsDataPublishIntervalOverride function handles a +* request to override the publish interval of the thermistors data. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*************************************************************************/ +void handleTestThermistorsDataPublishIntervalOverride( MESSAGE_T *message ) +{ + TEST_OVERRIDE_PAYLOAD_T payload; + BOOL result = FALSE; + + // verify payload length + if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) + { + result = testSetThermistorPublishIntervalOverride( payload.state.u32 ); + } + else + { + result = testResetThermistorPublishIntervalOverride(); + } + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** +* @brief +* The handleTestROPumpDutyCycleOverride function handles a request to override +* the RO pumps duty cycle. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*************************************************************************/ +void handleTestROPumpDutyCycleOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // verify payload length + if ( sizeof( F32 ) == message->hdr.payloadLen ) + { + F32 payLoad; + + memcpy( &payLoad, message->payload, sizeof( F32 ) ); + + result = testSetTargetDutyCycle( payLoad ); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** +* @brief +* The handleTestROFlowRateOverride function handles a request to override +* the RO flow rate. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*******************************************************************/ +void handleTestMeasuredROFlowRateOverride( 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 = testSetMeasuredROFlowRateOverride( payload.state.f32 ); + } + else + { + result = testResetMeasuredROFlowRateOverride(); + } + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** +* @brief +* The handleTestThermistorsValueOverride function handles a request to +* override a thermistor's value. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*************************************************************************/ +void handleTestThermistorsValueOverride( 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 = testSetMeasuredThermistorOverride( payload.index, payload.state.f32 ); + } + else + { + result = testResetMeasuredThermistorOverride( payload.index ); + } + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +//*******************************************************************/ +void handleTestROPumpTargetFlowOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // verify payload length + if ( sizeof( F32 ) == message->hdr.payloadLen ) + { + F32 payload; + + memcpy( &payload, message->payload, sizeof( F32 ) ); + result = testSetTargetROPumpFlow( payload ); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** +* @brief +* The handleTestFansDataPublishIntervalOverride function handles a request +* to override the publish interval of the fans data +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*************************************************************************/ +void handleTestFansDataPublishIntervalOverride( MESSAGE_T * message ) +{ + TEST_OVERRIDE_PAYLOAD_T payload; + BOOL result = FALSE; + + // verify payload length + if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) + { + result = testSetFanPublishIntervalOverride( payload.state.u32 ); + } + else + { + result = testResetFanPublishIntervalOverride(); + } + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +//*******************************************************************/ +void handleROPumpTargetPressureOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // verify payload length + if ( sizeof( U32 ) == message->hdr.payloadLen ) + { + U32 payload; + + memcpy( &payload, message->payload, sizeof( U32 ) ); + + result = testSetTargetROPumpPressure( payload ); + + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + /**@}*/