void CUDSMainWnd::PrepareFlowControl() { Counter_BSize = BSize; // BSize and SSTMin depends of the value put in the settingsWnd. //FWaitLongRespBSize = Counter_BSize; // Not used psTxCanMsgUds->m_psTxMsg->m_ucDataLen= SizeFC; //The DLC of the FCmessage depends of the value put in the settingsWnd. memset(psTxCanMsgUds->m_psTxMsg->m_ucData, 0, SizeFC); // ################## Casian #############################// switch(fInterface) { case INTERFACE_NORMAL_11 : { psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte-1] = TargetAddress; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte] = 0x30; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte+1] = BSize; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte+2] = SSTMin; ////// SendSimpleDiagnosticMessage(); }; break; case INTERFACE_EXTENDED_11 : { psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte-1] = TargetAddress; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte] = 0x30; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte+1] = BSize; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte+2] = SSTMin; SendSimpleDiagnosticMessage(); }; break; case INTERFACE_NORMAL_ISO_29 : { psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte-1] = TargetAddress; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte] = 0x30; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte+1] = BSize; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte+2] = SSTMin; SendSimpleDiagnosticMessage(); }; break; case INTERFACE_NORMAL_J1939_29 : { psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte] = 0x30; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte+1] = BSize; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte+2] = SSTMin; SendSimpleDiagnosticMessage(); }; break; } // ################## Casian #############################// }
void CUDSMainWnd::OnTimer(UINT_PTR nIDEvent){ //Envía TeserPresent if(nIDEvent ==ID_TIMER_TP && psTxCanMsgUds->m_psTxMsg != NULL) { //Prepare the message if(fInterface == INTERFACE_NORMAL_ISO_29 || fInterface ==INTERFACE_NORMAL_J1939_29){ psTxCanMsgUds->m_psTxMsg->m_ucEXTENDED= TRUE; // Initial Config }else{ psTxCanMsgUds->m_psTxMsg->m_ucEXTENDED= FALSE; // Initial Config } psTxCanMsgUds->m_psTxMsg->m_ucRTR = FALSE; psTxCanMsgUds->m_psTxMsg->m_ucChannel = (UCHAR)m_omComboChannelUDS.GetCurSel()+1; psTxCanMsgUds->m_psTxMsg->m_unMsgID = (int)m_omCanID.lGetValue(); memset(psTxCanMsgUds->m_psTxMsg->m_ucData, 0, 8); // Initialize the bytes to 0 if(fInterface == INTERFACE_EXTENDED_11 ) psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte-1]= TargetAddress; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte]= 0x02; //The tester Present will always have 2 bytes 0x3E y 0x00 psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte+1]= 0x3E; if(fMsgSize){ // how many bytes has the flow Control? psTxCanMsgUds->m_psTxMsg->m_ucDataLen = 8; } else { psTxCanMsgUds->m_psTxMsg->m_ucDataLen = aux_Finterface + 3; } if(FCRespReq) psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte+2]= 0x80; // if NoResponse Required is activated SendSimpleDiagnosticMessage(); } if ( nIDEvent == ID_TIMER_SEND_BUTTON){ m_omSendButton.EnableWindow(TRUE); KillTimer(ID_TIMER_SEND_BUTTON); } }
void CUDSMainWnd::PrepareFlowControl(){ Counter_BSize = BSize; // BSize and SSTMin depends of the value put in the settingsWnd. //FWaitLongRespBSize = Counter_BSize; // Not used psTxCanMsgUds->m_psTxMsg->m_ucDataLen= SizeFC; //The DLC of the FCmessage depends of the value put in the settingsWnd. memset(psTxCanMsgUds->m_psTxMsg->m_ucData, 0, SizeFC); if(fInterface == INTERFACE_EXTENDED_11 ) psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte-1] = TargetAddress; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte] = 0x30; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte+1] = BSize; psTxCanMsgUds->m_psTxMsg->m_ucData[initialByte+2] = SSTMin; SendSimpleDiagnosticMessage(); }
void CUDSMainWnd::SendContinuosFrames( unsigned char abByteArr[],mPSTXSELMSGDATA psTxCanMsgUds, UDS_INTERFACE FInterface) { CString Length; CString omTempByte; CString omByteStrTemp; int numberofFrames =0; // It will indicate how many multiples frames have been sent int c_numberOfTaken = numberOfTaken+2; // The consecutive Messages will contain one byte more that the FirstFrame int i = aux_Finterface + c_numberOfTaken/2; // aux_Finterface it's used to indicate that i must be bigger if we're in extended Addressing if (TotalLength*2<c_numberOfTaken){ // It only enters here once, at the end when the last message of the multiple frames has to be sent when i = TotalLength+aux_Finterface; // the number of frames that has to be sent is less than c_numberOfTaken } while (DatatoSend.GetLength()){ // While there is remaining data that has to be sent omByteStrTemp = DatatoSend.Left(c_numberOfTaken); //I take the part of the message that is going to be sent in the current Frame while(FWait_SendingFrame){} // Wait if something is being sent in this moment while (omByteStrTemp.GetLength()){ omTempByte = omByteStrTemp.Right(NO_OF_CHAR_IN_BYTE); abByteArr[i--] = (BYTE)_tcstol(omTempByte, L'\0', 16); //Llena el arreglo con el msg actual a enviar omByteStrTemp = omByteStrTemp.Left(omByteStrTemp.GetLength() - NO_OF_CHAR_IN_BYTE); } psTxCanMsgUds->m_psTxMsg->m_ucDataLen = 8; // Consecutive Frames can always have 8 bytes abByteArr[initialByte]= ConsecutiveFrame; // Put the initial Byte of the consecutive frames in a long request SendSimpleDiagnosticMessage(); // Send the current Message DatatoSend = DatatoSend.Right(((UINT)TotalLength*2)-c_numberOfTaken); // DatatoSend will contain the rest of the bytes that hasn't been sent yet. TotalLength = (((UINT)TotalLength*2)-c_numberOfTaken)/2; ConsecutiveFrame++; if (ConsecutiveFrame == 0x30) ConsecutiveFrame=0x20; // Requirement from the ISO TP numberofFrames++; if (numberofFrames == BSizE) { // It enters here when I've reached the quantity of Blocks settled by the ECU in the flow Control FWaitFlow = TRUE; // Now it has to wait for the Flow control again numberofFrames = 0; c_dDiffTime =0; return ; // Now it has to wait for another FlowControl }else { for(c_dDiffTime =0,c_unPreviousTime =-1 ;c_dDiffTime <=STMin; CalculateDiffTime()){} // Wait for the STMin Time settled by the ECU in the flow Control } c_unPreviousTime = -1; //ReStart the variables for the timmings c_dDiffTime = 0; i = aux_Finterface + c_numberOfTaken/2; // i must be a bigger numeber in the case of extended addressing-> aux_Finterface to control this. if (TotalLength*2<c_numberOfTaken){ // It only enters here once, at the end when the last message of the multiple frames has to be sent when i = TotalLength+aux_Finterface; // the number of frames that has to be sent is less than c_numberOfTaken } } m_omSendButton.EnableWindow(TRUE); // It only enters here when it has sent all the msg // In the case that this function cannot be completed there is a timer as default to activate the SEND button }
int CUDSMainWnd::SendFirstFrame(CString omByteStr, unsigned char abByteArr[], mPSTXSELMSGDATA psTxCanMsgUds, UDS_INTERFACE FInterface) { bool FirstFrame= TRUE; CString Length; CString omTempByte; CString omByteStrTemp; //int numberofFrames =-1 ; int c_numberOfTaken= numberOfTaken; // It contains the number of Data bytes that can be sent in the current message Length.Format("%.3x\n",TotalLength); //Prepare the first 2 bytes of a first frame of a long request Length = "1" + Length; omTempByte = Length.Left(2); abByteArr[initialByte]= (BYTE)_tcstol(omTempByte, L'\0', 16); omTempByte = Length.Right(3); abByteArr[initialByte+1]= (BYTE)_tcstol(omTempByte,L'\0', 16); int i=7; omByteStrTemp = omByteStr.Left(c_numberOfTaken); //I take the part of omByteStr that is going to be sent in the first Frame //while(FWait_SendingFrame){} // Wait if something is being sent in this moment while (omByteStrTemp.GetLength()) { omTempByte = omByteStrTemp.Right(NO_OF_CHAR_IN_BYTE); abByteArr[i--] = (BYTE)_tcstol(omTempByte, L'\0', 16); // Fill the array to sent with the current data omByteStrTemp = omByteStrTemp.Left(omByteStrTemp.GetLength() - NO_OF_CHAR_IN_BYTE); } psTxCanMsgUds->m_psTxMsg->m_ucDataLen = 8; // The FirstFrame always has 8 butes SendSimpleDiagnosticMessage(); //Send the message omByteStr = omByteStr.Right(((UINT)TotalLength*2)-c_numberOfTaken); // The bytes that were sent are deleted DatatoSend = omByteStr.Right(((UINT)TotalLength*2)-c_numberOfTaken); // DatatoSend will contain the rest of the bytes that hasn't been sent yet. TotalLength = (((UINT)TotalLength*2)-c_numberOfTaken)/2; FirstFrame = FALSE; FWaitFlow =TRUE; // No Wait for the Flow Control comming from the ECU ConsecutiveFrame = 0x21; //Initialize this -> because a long frame will be sent return 0; }
void CUDSMainWnd::PrepareDiagnosticMessage(CString omByteStr,mPSTXSELMSGDATA psTxCanMsgUds, unsigned char abByteArr[], UINT ByteArrLen) { memset(abByteArr, 0, ByteArrLen); // Initialize the array to zero omByteStr.Replace(" ",""); int i_counter =0; UINT LengthStr = omByteStr.GetLength(); UINT Result; if ( LengthStr%2 != 0){ CString LastString = "0" + omByteStr.Right(1); omByteStr= omByteStr.Left(omByteStr.GetLength() - 1); omByteStr = omByteStr+ LastString; } Result = LengthStr / 2 + LengthStr % 2; // Result posee la cantidad de bytes que desean ser enviados TotalLength = Result; m_omSendButton.EnableWindow(FALSE); //I have to disable the sendButton everytime that I press SEND // If it's a long request I need it // If it's a long response I've to restart it and receive all the bytes // If it's a simple response: the response could take more time or it could be a 0x78 resp m_nTimer = SetTimer(ID_TIMER_SEND_BUTTON,P2_Time , NULL); // Time to wait to enable the send button again switch (fInterface){ case INTERFACE_NORMAL_11: { psTxCanMsgUds->m_psTxMsg->m_ucEXTENDED= FALSE; ByteArrLen = ByteArrLen-1; if (Result>7) // Long Request { int f =SendFirstFrame(omByteStr,abByteArr,psTxCanMsgUds,fInterface ); } else { // Short request i_counter = (int) Result; abByteArr[0] = Result; Result++; // Result must be increased to make the size array bigger CString omTempByte; while (omByteStr.GetLength()) { omTempByte = omByteStr.Right(NO_OF_CHAR_IN_BYTE); abByteArr[i_counter--] = (BYTE)_tcstol(omTempByte, L'\0', 16); omByteStr = omByteStr.Left(omByteStr.GetLength() - NO_OF_CHAR_IN_BYTE); } if(fMsgSize){ psTxCanMsgUds->m_psTxMsg->m_ucDataLen = 8; } else { psTxCanMsgUds->m_psTxMsg->m_ucDataLen = Result; } SendSimpleDiagnosticMessage(); } } break; case INTERFACE_EXTENDED_11: { psTxCanMsgUds->m_psTxMsg->m_ucEXTENDED= FALSE; ByteArrLen = ByteArrLen-2; abByteArr[0] = TargetAddress; if (Result>6){ // Long Request - The limit of a simple request for extended is 6 because the byte that contains the TA. m_omSendButton.EnableWindow(FALSE); m_nTimer = SetTimer(ID_TIMER_SEND_BUTTON, P2_Time , NULL); // Start Timer to wait to enable by default the send button again int f =SendFirstFrame(omByteStr,abByteArr,psTxCanMsgUds,fInterface); } else { // Short request i_counter = Result+1; abByteArr[1] = Result; Result = Result+2; CString omTempByte; while (omByteStr.GetLength()) // Take all the bytes that will be parte of the simple message { omTempByte = omByteStr.Right(NO_OF_CHAR_IN_BYTE); abByteArr[i_counter--] = (BYTE)_tcstol(omTempByte, L'\0', 16); omByteStr = omByteStr.Left(omByteStr.GetLength() - NO_OF_CHAR_IN_BYTE); } if(fMsgSize){ psTxCanMsgUds->m_psTxMsg->m_ucDataLen = 8; } else { psTxCanMsgUds->m_psTxMsg->m_ucDataLen = Result; } SendSimpleDiagnosticMessage(); } } break; case INTERFACE_NORMAL_ISO_29: { psTxCanMsgUds->m_psTxMsg->m_ucEXTENDED= TRUE; ByteArrLen = ByteArrLen-1; if (Result>7) // Long Request { int f =SendFirstFrame(omByteStr,abByteArr,psTxCanMsgUds,fInterface ); } else { // Short request i_counter = (int) Result; abByteArr[0] = Result; Result++; // Result must be increased to make the size array bigger CString omTempByte; while (omByteStr.GetLength()) { omTempByte = omByteStr.Right(NO_OF_CHAR_IN_BYTE); abByteArr[i_counter--] = (BYTE)_tcstol(omTempByte, L'\0', 16); omByteStr = omByteStr.Left(omByteStr.GetLength() - NO_OF_CHAR_IN_BYTE); } if(fMsgSize){ psTxCanMsgUds->m_psTxMsg->m_ucDataLen = 8; } else { psTxCanMsgUds->m_psTxMsg->m_ucDataLen = Result; } SendSimpleDiagnosticMessage(); } } break; case INTERFACE_NORMAL_J1939_29: { psTxCanMsgUds->m_psTxMsg->m_ucEXTENDED= TRUE; ByteArrLen = ByteArrLen-1; if (Result>7) // Long Request { int f =SendFirstFrame(omByteStr,abByteArr,psTxCanMsgUds,fInterface ); } else { // Short request i_counter = (int) Result; abByteArr[0] = Result; Result++; // Result must be increased to make the size array bigger CString omTempByte; while (omByteStr.GetLength()) { omTempByte = omByteStr.Right(NO_OF_CHAR_IN_BYTE); abByteArr[i_counter--] = (BYTE)_tcstol(omTempByte, L'\0', 16); omByteStr = omByteStr.Left(omByteStr.GetLength() - NO_OF_CHAR_IN_BYTE); } if(fMsgSize){ psTxCanMsgUds->m_psTxMsg->m_ucDataLen = 8; } else { psTxCanMsgUds->m_psTxMsg->m_ucDataLen = Result; } SendSimpleDiagnosticMessage(); } } break; } }