public DCPRetCodes AnswerToDCPMessage(DataBuffer a_data, MessageTypes a_msgType, CommandSet a_cmdSet, DCPFrame a_txMsg, DCPFrame a_rxMsg) { DataBuffer buffer = new DataBuffer(a_data.NumItems + 4); byte num = (byte) a_msgType; buffer = a_data; switch (num) { case 0x40: case 0x80: a_txMsg.CmdSet = (byte) a_cmdSet; a_txMsg.SeqNum = a_rxMsg.SeqNum; break; } int num2 = 0; while (num2 < _DCPMsgRepeatNr) { DCPRetCodes codes; if (_dcpVersion == DCPVersion.DCP) { codes = a_txMsg.ConstructDCPmsg(buffer, a_cmdSet, a_msgType); } else { codes = a_txMsg.ConstructDCP2msg(buffer, a_cmdSet, a_msgType); } codes = doExchangeDCP_TX(a_txMsg, a_rxMsg); switch (codes) { case DCPRetCodes.DCP_RESP_SENT: return codes; case DCPRetCodes.DCP_FATAL: return codes; } return DCPRetCodes.DCP_FATAL; } return DCPRetCodes.DCP_FATAL; }
public DCPRetCodes exchangeDCPMessage(DataBuffer a_data, MessageTypes a_msgType, CommandSet a_cmdSet, DCPFrame a_txMsg, DCPFrame a_rxMsg) { MessageTypes synchReqOrIndication; DataBuffer buffer = new DataBuffer(a_data.NumItems + 4); MessageTypes types = synchReqOrIndication = a_msgType; buffer = a_data; TaskState writingCommand = TaskState.WritingCommand; switch (synchReqOrIndication) { case MessageTypes.ACK: case MessageTypes.Nack: return DCPRetCodes.DCP_FATAL; } for (int i = 0; i < _DCPMsgRepeatNr; i++) { DCPRetCodes codes; switch (_dcpVersion) { case DCPVersion.DCP2: codes = a_txMsg.ConstructDCP2msg(buffer, a_cmdSet, synchReqOrIndication); break; default: codes = a_txMsg.ConstructDCPmsg(buffer, a_cmdSet, synchReqOrIndication); break; } codes = doExchangeDCP_TX(a_txMsg, a_rxMsg); switch (codes) { case DCPRetCodes.DCP_RESP_SENT: return codes; case DCPRetCodes.DCP_FATAL: return codes; case DCPRetCodes.DCP_ERR_TIMEOUT: case DCPRetCodes.DCP_ERR_EDC: break; default: if (codes != DCPRetCodes.DCP_OK) return DCPRetCodes.DCP_FATAL; if (a_rxMsg.SeqNum == a_txMsg.SeqNum) { if ((a_rxMsg.MsgType != 0) && (a_rxMsg.MsgType != 0xc0)) { if (a_rxMsg.MsgType != 0x80) { if (a_rxMsg.MsgType != 0x40) return DCPRetCodes.DCP_FATAL; if (writingCommand != TaskState.SynchReq) { if (a_rxMsg.Len > 2) return DCPRetCodes.DCP_OK_ACK; return DCPRetCodes.DCP_OK; } synchReqOrIndication = types; buffer = a_data; writingCommand = TaskState.WritingCommand; } else { if (a_rxMsg.CmdSet != 0) return DCPRetCodes.DCP_OK_NACK; if (a_rxMsg.Data[0] != 0) return DCPRetCodes.DCP_OK_NACK; } } } else { writingCommand = TaskState.SynchReq; synchReqOrIndication = MessageTypes.SynchReqOrIndication; buffer.NumItems = 0; } break; } } return DCPRetCodes.DCP_FATAL; }