예제 #1
0
 static extern int VCI_Transmit(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd, ref VCI_CAN_OBJ pSend, UInt32 Len);
예제 #2
0
        /*---------------------------------------------------------------------------------------------------*/
        unsafe public void udsProcess(ref VCI_CAN_OBJ canObj)
        {
            int  size, d;
            byte tpType = (byte)(canObj.Data[0] >> 4);

            if (tpType == FIRSTFRAME) //首帧
            {
                if (expectedReturnIsFirstFrame == false)
                {
                    return;
                }

                //回应流量控制帧
                usbCAN.arrSendBuf[0].ID         = udsCaller.address;
                usbCAN.arrSendBuf[0].ExternFlag = udsCaller.format;
                usbCAN.arrSendBuf[0].RemoteFlag = 0;
                usbCAN.arrSendBuf[0].SendType   = 1;

                usbCAN.arrSendBuf[0].DataLen = 3;
                usbCAN.arrSendBuf[0].Data[0] = 0x30;
                usbCAN.arrSendBuf[0].Data[1] = 0x00;
                usbCAN.arrSendBuf[0].Data[2] = 0x7f;
                usbCAN.sendFame(1);

                //
                responseListForMultiFrameExpected.respAddress = canObj.ID;
                size = canObj.Data[0] & 0x0f;
                size = (size << 8) + canObj.Data[1];

                for (d = 2; d < 8; d++)
                {
                    responseListForMultiFrameExpected.responseList.Add(canObj.Data[d]);
                }
                responseListForMultiFrameExpected.remainingReceivingLength = size - 6;

                responseListForMultiFrameExpected.expectedIndex = 1;
                expectedReturnIsFirstFrame       = false;
                expectedReturnIsConsecutiveFrame = true;
            }
            else if (tpType == CONSECUTIVEFRAME)
            {
                if (expectedReturnIsConsecutiveFrame == false)
                {
                    return;
                }

                int seq = canObj.Data[0] & 0x0f;
                if (seq != responseListForMultiFrameExpected.expectedIndex)
                {
                    responseListForMultiFrameExpected.errorCode = UDSResponseList.ERRORCODE.EXPECTEDINDEX;
                    return;
                }

                size = responseListForMultiFrameExpected.remainingReceivingLength;
                for (d = 1; d < 8 && size > 0; d++, size--)
                {
                    responseListForMultiFrameExpected.responseList.Add(canObj.Data[d]);
                }

                responseListForMultiFrameExpected.remainingReceivingLength = size;
                if (size == 0)
                {
                    expectedReturnIsConsecutiveFrame = false;
                }
                else
                {
                    responseListForMultiFrameExpected.expectedIndex = (responseListForMultiFrameExpected.expectedIndex + 1) % 16;
                }
            }
            else if (tpType == SINGLEFRAME)
            {
                if (expectedReturnIsSingleFrame == false)
                {
                    return;
                }

                responseListForSingleFrameExpected.respAddress = canObj.ID;

                size = canObj.Data[0] & 0x0f;
                for (d = 1; size > 0 && d < 8; size--, d++)
                {
                    responseListForSingleFrameExpected.responseList.Add(canObj.Data[d]);
                }

                expectedReturnIsSingleFrame = false;
            }
        }
예제 #3
0
 static extern int VCI_Receive(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd, ref VCI_CAN_OBJ pReceive, UInt32 Len, Int32 WaitTime);