XCP协议标定和测量代码流程
XCP ON CAN
通过PCAN的XCP代码使用过程来记录XCP标定和测量的具体流程来作为以后使用的参考。
初始化CAN设备
这里主要是指的PCAN初始化和初始化XCP的连接
# 初始化CAN连接
def can_init(self, USBChannle, baud):
'''
USBChannle:PCAN_USBBUS1(in PCANBASIC)
baud:PCAN_BAUD_500K(in PCANBASIC)
'''
# 初始化XCP连接
def xcp_connect(self,BroadcastID, MasterID, SlaveID, IncrementIdUsed):
初始化CAN的XCP连接时主要是设置一些参数,并且添加XCP的Slave。
XCP上的数据测量过程
Memory Management
# ------------------------------
# Memory Management
# ------------------------------
#
# Command SET_MTA: initializes a pointer (32Bit address + 8Bit extension)
# for following memory transfer commands: BUILD_CHECKSUM, UPLOAD, DOWNLOAD,
# DOWNLOAD_NEXT, DOWNLOAD_MAX, MODIFY_BITS, PROGRAM_CLEAR, PROGRAM, PROGRAM_NEXT and PROGRAM_MAX.
#
def SetMemoryTransferAddress(
self,
XcpHandle, # TXCPHandle
AddrExtension, # BYTE c_ubyte
Addr): # DWORD c_ulong
"""
Command SET_MTA: initializes a pointer (32Bit address + 8Bit extension)
for following memory transfer commands: BUILD_CHECKSUM, UPLOAD, DOWNLOAD,
DOWNLOAD_NEXT, DOWNLOAD_MAX, MODIFY_BITS, PROGRAM_CLEAR, PROGRAM, PROGRAM_NEXT and PROGRAM_MAX.
Parameters:
XcpHandle : The handle of a XCP session
AddrExtension : Address extension
Addr : Address
Returns:
[0]: TXCPResult : A TXCPResult result code
[1]: c_ubyte*8 : Buffer for the slave responce (CTO package)
"""
SHORT_UPLOAD
#
# Command SHORT_UPLOAD: Upload a data block, of a maximum size of [1..MAX_CTO/AG], from slave to master.
#
def ShortUpload(
self,
XcpHandle, # TXCPHandle
numberOfElements, # BYTE c_ubyte
AddrExtension, # BYTE c_ubyte
Addr): # DWORD c_ulong
"""
Command SHORT_UPLOAD: Upload a data block, of a maximum size of [1..MAX_CTO/AG], from slave to master.
Parameters:
XcpHandle : The handle of a XCP session
numberOfElements : The amount of elements to retrieve
AddrExtension : Address extension to set the MTA pointer
Addr : Address to set the MTA pointer
Returns:
[0]: TXCPResult : A TXCPResult result code
[1]: c_ubyte*8 : Buffer for the slave responce (CTO package)
"""
XCP上的数据标定过程
setCalibrationPage
#
# Command SET_CAL_PAGE: sets the access mode for a calibration data segment.
#
def SetCalibrationPage(
self,
XcpHandle, # TXCPHandle
Mode, # BYTE c_ubyte
Page): # TXCPCalibrationPage
"""
Command SET_CAL_PAGE: sets the access mode for a calibration data segment.
Parameters:
XcpHandle : The handle of a XCP session
Mode : Access mode
Page : Represents a calibration data page (segment and page number)
Returns:
[0]: TXCPResult : A TXCPResult result code
[1]: c_ubyte*8 : Buffer for the slave responce (CTO package)
"""
Memory Management
# ------------------------------
# Memory Management
# ------------------------------
#
# Command SET_MTA: initializes a pointer (32Bit address + 8Bit extension)
# for following memory transfer commands: BUILD_CHECKSUM, UPLOAD, DOWNLOAD,
# DOWNLOAD_NEXT, DOWNLOAD_MAX, MODIFY_BITS, PROGRAM_CLEAR, PROGRAM, PROGRAM_NEXT and PROGRAM_MAX.
#
def SetMemoryTransferAddress(
self,
XcpHandle, # TXCPHandle
AddrExtension, # BYTE c_ubyte
Addr): # DWORD c_ulong
"""
Command SET_MTA: initializes a pointer (32Bit address + 8Bit extension)
for following memory transfer commands: BUILD_CHECKSUM, UPLOAD, DOWNLOAD,
DOWNLOAD_NEXT, DOWNLOAD_MAX, MODIFY_BITS, PROGRAM_CLEAR, PROGRAM, PROGRAM_NEXT and PROGRAM_MAX.
Parameters:
XcpHandle : The handle of a XCP session
AddrExtension : Address extension
Addr : Address
Returns:
[0]: TXCPResult : A TXCPResult result code
[1]: c_ubyte*8 : Buffer for the slave responce (CTO package)
"""
Download
#
# Command DOWNLOAD: Download a data block from master to slave, starting at the
# current MTA. The MTA will be post-incremented by the number of data elements.
#
def Download(
self,
XcpHandle, # TXCPHandle
numberOfElements, # BYTE c_ubyte
dataBuffer, # BYTE* c_ubyte*
dataBufferLength): # BYTE c_ubyte
"""
Command DOWNLOAD: Download a data block from master to slave, starting at the
current MTA. The MTA will be post-incremented by the number of data elements.
Parameters:
XcpHandle : The handle of a XCP session
numberOfElements : The amount of elements to be transfered
dataBuffer : Data buffer with the elements to transfer
dataBufferLength : Length of the data buffe
Returns:
[0]: TXCPResult : A TXCPResult result code
[1]: c_ubyte*8 : Buffer for the slave responce (CTO package)
"""
ShortUpload
#
# Command SHORT_UPLOAD: Upload a data block, of a maximum size of [1..MAX_CTO/AG], from slave to master.
#
def ShortUpload(
self,
XcpHandle, # TXCPHandle
numberOfElements, # BYTE c_ubyte
AddrExtension, # BYTE c_ubyte
Addr): # DWORD c_ulong
"""
Command SHORT_UPLOAD: Upload a data block, of a maximum size of [1..MAX_CTO/AG], from slave to master.
Parameters:
XcpHandle : The handle of a XCP session
numberOfElements : The amount of elements to retrieve
AddrExtension : Address extension to set the MTA pointer
Addr : Address to set the MTA pointer
Returns:
[0]: TXCPResult : A TXCPResult result code
[1]: c_ubyte*8 : Buffer for the slave responce (CTO package)
"""
总结
以上是根据PCAN 的XCP来理解的XCP的标定和观测流程。后期希望使用xcp包来配合can盒来做实现标定和观测功能。