Index: firmware/App/Services/Messaging.c =================================================================== diff -u -rc85d9f0a8023fabdf1cd557965958d225e2b9085 -r5e92cbb2c29854fb60a91dc4abafeb9b08d3272c --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision c85d9f0a8023fabdf1cd557965958d225e2b9085) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 5e92cbb2c29854fb60a91dc4abafeb9b08d3272c) @@ -18,19 +18,26 @@ #include // for memcpy() #include "reg_system.h" - +#include "BalancingChamber.h" #include "Conductivity.h" #include "Compatible.h" #include "ConcentratePumps.h" #include "DialysatePumps.h" #include "Heaters.h" #include "Level.h" #include "Messaging.h" +#include "MessagePayloads.h" +#include "ModeStandby.h" +#include "ModeGenDialysate.h" #include "OperationModes.h" #include "PAL.h" +#ifdef __PUMPTEST__ +#include "PistonPumpControl.h" +#endif #include "Pressure.h" #include "SystemCommDD.h" #include "Temperature.h" +#include "TDInterface.h" #include "Utilities.h" #include "Valves.h" @@ -78,7 +85,7 @@ /// Message handling function lookup table static const U16 MSG_FUNCTION_HANDLER_LOOKUP[] = { - MSG_ID_TESTER_LOGIN_REQUEST, + MSG_ID_DD_TESTER_LOGIN_REQUEST, MSG_ID_DD_SOFTWARE_RESET_REQUEST, MSG_ID_TD_OP_MODE_DATA, MSG_ID_DD_VALVE_PUBLISH_INTERVAL_OVERRIDE_REQUEST, @@ -117,6 +124,33 @@ MSG_ID_DD_HEATERS_DUTY_CYCLE_OVERRIDE_REQUEST, MSG_ID_DD_LEVELS_PUBLISH_INTERVAL_OVERRIDE_REQUEST, MSG_ID_DD_LEVELS_STATUS_OVERRIDE_REQUEST, + MSD_ID_DD_TD_COMMUNICATION_STATUS_OVERRIDE_REQUEST, //40 + MSG_ID_DD_OP_MODE_STATUS_OVERRIDE_REQUEST, + MSG_ID_DD_SET_OPERATION_MODE_OVERRIDE_REQUEST, + MSG_ID_DD_START_GEN_DIALYSATE_MODE_OVERRIDE_REQUEST, + MSG_ID_DD_DIALYSATE_PUMPS_START_STOP_OVERRIDE_REQUEST, + MSG_ID_DD_GEND_MODE_DATA_PUBLISH_OVERRIDE_REQUEST, //45 + MSG_ID_DD_CONCENTRATE_PUMPS_START_STOP_OVERRIDE_REQUEST, + MSG_ID_DD_HEATERS_START_STOP_OVERRIDE_REQUEST, + MSG_ID_DD_VALVES_OPEN_CLOSE_STATE_OVERRIDE_REQUEST, + MSG_ID_DD_GEN_DIALYSATE_REQUEST_DATA, + MSD_ID_DD_RO_COMMUNICATION_STATUS_OVERRIDE_REQUEST, //50 + MSG_ID_DD_BAL_CHAMBER_DATA_PUBLISH_OVERRIDE_REQUEST, + MSG_ID_DD_BAL_CHAMBER_SWITCH_FREQ_OVERRIDE_REQUEST, + MSG_ID_DD_DIAL_DELIVERY_IN_PROGRESS_OVERRIDE_REQUEST, + MSG_ID_DD_DIAL_DELIVERY_GOOD_TO_DELIVER_OVERRIDE_REQUEST, + MSG_ID_DD_HEATERS_TARGET_TEMPERATURE_OVERRIDE_REQUEST, //55 + MSG_ID_DD_BC_VALVE_STATES_OVERRIDE_REQUEST, + MSG_ID_DD_BC_SWITCH_ONLY_START_STOP_OVERRIDE_REQUEST, + MSG_ID_DD_HYD_CHAMBER_TARGET_TEMP_OVERRIDE_REQUEST, + MSG_ID_DD_ACID_DOSING_VOLUME_OVERRIDE_REQUEST, + MSG_ID_DD_BICARB_DOSING_VOLUME_OVERRIDE_REQUEST, //60 + MSG_ID_DD_GEND_EXEC_STATE_OVERRIDE_REQUEST, +#ifdef __PUMPTEST__ + MSG_ID_DD_PISTON_PUMP_DATA_PUBLISH_OVERRIDE_REQUEST, + MSG_ID_DD_PISTON_PUMP_START_STOP_OVERRIDE_REQUEST, + MSG_ID_DD_PISTON_PUMP_FILL_AFTER_DISPENSE_OVERRIDE_REQUEST, +#endif }; /// Message handling function table @@ -160,6 +194,33 @@ &testHeaterDutyCycleOverride, &testLevelsDataPublishIntervalOverride, &testLevelStatusOverride, + &testTDCommunicationStatusOverride, //40 + &testDDOpModePublishIntervalOverride, + &testSetOperationMode, + &testDDstartGenDialysateOverride, + &testDialysatePumpStartStopOverride, + &testDDGenDialysateDataPublishIntervalOverride, //45 + &testConcentratePumpStartStopOverride, + &testHeaterStartStopOverride, + &testValveOpenCloseStateOverride, + &handleDialysateDeliveryRequestMsg, + &testROCommunicationStatusOverride, //50 + &testDDBalChamberDataPublishIntervalOverride, + &testBalChamberSwFreqOverride, + &testDialDeliveryInProgressOverride, + &testDialGoodToDeliverStatusOverride, + &testHeaterTargetTemperatureOverride, //55 + &testBCValveStatesOverride, + &testBCSwitchOnlyStartStopOverride, + &testGenDHydChamberFluidTempOverride, + &testAcidDoseVolumeOverride, + &testBicarbDoseVolumeOverride, //60 + &testGenDExecStateOverride, +#ifdef __PUMPTEST__ + &testDDPistonPumpControlDataPublishIntervalOverride, + &testDDPistonPumpStartStopOverride, + &testDDPistonPumpFillAfterDispenseOverride, +#endif }; #define NUM_OF_FUNCTION_HANDLERS (sizeof(MSG_FUNCTION_HANDLERS) / sizeof(MsgFuncPtr)) @@ -171,96 +232,95 @@ static volatile U16 nextSeqNo = 1; ///< Next sequence number. /// List of message IDs that are requested not to be transmitted. //static BLOCKED_MSGS_DATA_T blockedMessagesForXmit = { 0, 0, 0, 0, 0, 0, 0, 0 }; - -// ********** private function prototypes ********** - -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 \b Inputs: none + +// ********** private function prototypes ********** + +static BOOL sendTestAckResponseMsg( MSG_ID_T msgID, 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 \b Inputs: none * @details \b Outputs: given data array populated with serialized message data and * queued for transmit. - * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when pending ACK list is full. - * @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. - *************************************************************************/ -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_MESSAGE_THAT_REQUIRES_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_FRAME_PAYLOAD_SIZE (8) - sizeMod = msgSize % CAN_FRAME_PAYLOAD_SIZE; - sizePad = ( sizeMod == 0 ? 0 : CAN_FRAME_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_DD_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; -} + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when pending ACK list is full. + * @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. + *************************************************************************/ +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_MESSAGE_THAT_REQUIRES_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_FRAME_PAYLOAD_SIZE (8) + sizeMod = msgSize % CAN_FRAME_PAYLOAD_SIZE; + sizePad = ( sizeMod == 0 ? 0 : CAN_FRAME_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_DD_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 @@ -301,7 +361,7 @@ * @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 sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ) { BOOL result; MESSAGE_T msg; @@ -359,7 +419,8 @@ COMM_BUFFER_T respBuffer = tdResponseBuffers[ message->in_buffer ]; // if Dialin message, ensure Dialin is logged in before processing it - if ( ( message->hdr.msgID <= MSG_ID_FIRST_DD_TESTER_MESSAGE ) || + if ( ( message->hdr.msgID < MSG_ID_FIRST_TD_TESTER_MESSAGE ) || + ( MSG_ID_FIRST_DD_TESTER_MESSAGE == message->hdr.msgID ) || ( TRUE == isTestingActivated() ) ) { MsgFuncPtr msgFuncPtr; @@ -373,7 +434,7 @@ } } // ACK/NAK request - if ( message->hdr.msgID < MSG_ID_FIRST_DD_TESTER_MESSAGE ) + if ( message->hdr.msgID < MSG_ID_FIRST_TD_TESTER_MESSAGE ) { if ( respBuffer != COMM_BUFFER_NOT_USED ) { @@ -392,10 +453,10 @@ /*********************************************************************//** * @brief - * The sendEvent function constructs an DG event message to the UI and + * The sendEvent function constructs an DD event message to the UI and * queues the msg for transmit on the appropriate CAN channel. * @details \b Inputs: none - * @details \b Outputs: DG event msg constructed and queued. + * @details \b Outputs: DD event msg constructed and queued. * @param event Enumeration of event type that occurred * @param dat1 First data associated with event * @param dat2 Second data associated with event @@ -463,7 +524,7 @@ payloadPtr += sizeof( U32 ); data = almData2.data.uInt.data; memcpy( payloadPtr, &data, sizeof( U32 ) ); - // Pad with space for 3 U32s - set to zero - unused for DG + // Pad with space for 3 U32s - set to zero - unused for DD payloadPtr += ( sizeof( U32) * 3 ); memset( payloadPtr, 0, sizeof( U32) * 3 ); @@ -565,6 +626,7 @@ return status; } + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -645,8 +707,6 @@ { testerLoggedIn = FALSE; } - // respond to would be tester - sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, testerLoggedIn ); return testerLoggedIn; }