CCP协议学习《一》
CCP:CAN Calibration Protocol是基于CAN总线应用层协议。
在学习CCP之前,先了解一下CAN总线。
1 CAN是什么?
CAN 是Controller Area Network****(控制器局域网) 的缩写(以下称为CAN),是ISO*1 国际标准化的串行通信协议。
CAN总线的作用就是将整车中各种不同的控制器连接起来,实现信息的可靠共享,并减少整车线束数量。
1.1 CAN总线的工作原理
CAN总线的通信是通过一种类似于“会议”的机制实现的,每一个会议参加人员都可以*的提出会议议题(多主通信模式)。
1.2 CAN收发器
按照BOSCH CAN总线标准将0或1逻辑信号转换为标准中规定的电平,同时有反馈功能。
CAN2.0A/B标准规定:总线空闲时,CAN_H和CAN_L上的电压为2.5V
在数据传输时,
显性电平(逻辑0):CAN_H 3.5V CAN_L 1.5V
隐性电平(逻辑1):CAN_H 2.5V CAN_L 2.5V
1.3何为CAN控制器?
CAN控制器主要实现了两部分的功能
- 数据链路层的全部功能;
- 物理层的位定时功能
1.4 帧的种类
通信是通过以下5种类型的帧进行的。
数据帧、遥控帧、错误帧、过载帧、帧间隔。
另外,数据帧和遥控帧有标准格式和扩展格式两种格式。标准格式有11 个位的标识符(Identifier: 以下称ID),扩展格式有29 个位的ID。
帧 | 帧用途 |
---|---|
数据帧 | 用于发送单元向接收单元传送数据的帧。 |
遥控帧 | 用于接收单元向具有相同ID的发送单元请求数据的帧。 |
错误帧 | 用于当检测出错误时向其它单元通知错误的帧。 |
过载帧 | 用于接收单元通知其尚未做好接收准备的帧。 |
帧间隔 | 用于将数据帧及遥控帧与前面的帧分离开来的帧。 |
2 CCP协议
2.1 基本概念
-
ECU
Electronic Control Unit(电子控制单元):一种具有*处理单元的电子装置,其外围电路可执行编程功能。
-
CRM
Command Return Message(命令返回消息) : 从从设备发送到主设备的一种消息,包含命令/错误代码和命令计数器。
-
CRO
Command Receive Object(命令接收对象) :从主设备发送到从设备的消息。
-
DTO
Data Thansmission Object (数据传输对象):从设备发送到主设备的消息(命令返回消息或事件消息或数据采集消息)。
-
DAQ
Data Acquisition:从从设备向主设备发送的用于从ECU快速数据采集的过程和消息的定义。
-
ODT
Obiect Descriptor Table: 元素(变量)列表,用于组织数据采集。
2.2 CCP的应用范围和领域
- 任何基于CAN的分布式电控系统ECU开发
- 对ECU进行功能和环境测试的系统
- 被控设备的测试系统和测试台架(发动机、变速箱、悬挂系统、空调控制系统、车身控制系统、刹车防抱死系统)
- 预研车系的测试和测量系统
2.3 报文对象描述
DTO:Data Transmit Object ——从Slave到Master 根据PID(Packet ID)的不同,DTO可分为:
?
- PID=255:Command Return Message(CRM-DTO )
主要是从设备反馈给主设备的响应 ?
- PID=254:Event Message
当从设备检测到内部发生错误机制时,由从设备自行向主设备发送, 报告其当前的运行状态,并请求主设备暂停当前工作进程以处理发生 的错误。 ?
- 0≤PID ≤253:Data Acquisition Message(DAQ-DTO)
用在DAQ模式中,由从设备组织,周期性向主设备发送。
2.4 11个基本命令
Command | Code | TimeOut to ACK[ms] | Remark |
---|---|---|---|
CONNECT | 0x01 | 25 | |
GET_CCP_VERSION | 0x1B | 25 | |
EXCHANG_ID | 0x17 | 25 | |
SET_MTA | 0x02 | 25 | |
DNLOAD | 0x03 | 25 | |
UPLOAD | 0x04 | 25 | |
GET_DAQ_SIZE | 0x14 | 25 | |
SET_DAQ_PTR | 0x15 | 25 | |
WRITE_DAQ | 0x16 | 25 | |
START_STOP | 0x06 | 25 | |
DISCONNECT | 0x07 | 25 |
2.5 17个可选命令
Command | Code | TimeOut to ACK[ms] | Remark |
---|---|---|---|
GET_SEED | 0X12 | 25 | |
UNLOCK | 0X13 | 25 | |
DNLOAD_6 | 0X23 | 25 | |
SHORT_UP | 0X0F | 25 | |
SELECT_CAL_PAGE | 0X11 | 25 | |
GET_ACTIVE_CAL_PAGE | 0X09 | 25 | |
SET_S_STATUS | 0X0C | 25 | |
GET_S_STATUS | 0X0D | 25 | |
BUILD_CHKSUM | 0X0E | 30000 | |
CLEAR_MEMORY | 0X10 | 30000 | |
PROGRAM | 0X18 | 100 | |
PROGRAM_6 | 0X22 | 100 | |
MOVE | 0X19 | 30000 | |
TEST | 0X05 | 25 | |
DIAG_SERVICE | 0X20 | 500 | |
ACTION_SERVICE | 0X21 | 5000 | |
START_STOP_ALL | 0X08 | 25 |
2.6 命令返回码和错误类别
2.7 基本命令描述
2.7.1 CONNECT——建立连接(0x01)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = CONNECT 0x01 |
1 | byte | Command Counter = CTR |
2 | word | station address (Intel format) |
4…7 | byte | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3…7 | bytes | don’t care |
2.7.2 GET_CCP_VERSION ——获得CCP版本(0X1B)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = GET_CCP_VERSION 0x1B |
1 | Byte | Command Counter = CTR |
2 | Byte | Main Protocol version (desired) |
3 | Byte | Release within version (desired) |
4 …7 | Bytes | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID: 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 | Byte | Main Protocol version as implemented |
4 | Byte | Release within version as implemented |
5 … 7 | Bytes | don’t care |
2.7.3 EXCHANGE_ID—加粗样式—交换ID(0x17)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = EXCHANGE_ID 0x17 |
1 | byte | Command Counter = CTR |
2… | bytes | CCP master device ID information (optional and implementation specific) |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3 | byte | length of slave device ID in bytes |
4 | byte | data type qualifier of slave device ID (optional and implementation specific) |
5 | byte | Resource Availability Mask |
6 | byte | Resource Protection Mask |
7 | byte | Don’t care |
2.7. 4. SET_MTA——设置内存传输地址(0X02)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command |
1 | byte | Command |
2 | byte | Memory transfer address MTA number (0,1) |
3 | byte | Address extension |
4…7 | unsigned | long Address |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3…7 | bytes | don’t care |
2.7. 5. DNLOAD——数据下载(0x03)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = DNLOAD 0x03 |
1 | byte | Command Counter = CTR |
2 | byte | size of data block to follow in bytes |
3…7 | bytes | data to be transferred (up to 5 bytes) |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3 | byte | MTA0 extension (after post-increment) |
4…7 | unsigned long | MTA0 address (after post-increment) |
2.7.6. UPLOAD——数据上载(0x04)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = UPLOAD 0x04 |
1 | byte | Command Counter = CTR |
2 | byte | Size of data block to be uploaded in bytes |
3…7 | bytes | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3 … 7 | bytes | requested data bytes |
2.7. 7. GET_DAQ_SIZE ——获得DAQlist大小(0X14)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = GET_DAQ_SIZE 0x14 |
1 | byte | Command Counter = CTR |
2 | byte | DAQ list number (0,1,…) |
3 | byte | don’t care |
4…7 | unsigned long | CAN Identifier of DTO dedicated to list number |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3 | byte | DAQ list size (= number of ODTs in this list) |
4 | byte | First PID of DAQ list |
5 … 7 | bytes | don’t care |
2.7.8. SET_DAQ_PTR ——设置DAQlist指针(0X15)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = SET_DAQ_PTR 0x15 |
1 | byte | Command Counter = CTR |
2 | byte | DAQ list number (0,1,…) |
3 | byte | Object Descriptor Table ODT number (0,1,…) |
4 | byte | Element number within ODT (0,1,…) |
5…7 | bytes | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3 … 7 | bytes | don’t care |
2.7. 9. WRITE_DAQ ——写DAQlist入口(0X16)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = WRITE_DAQ 0x16 |
1 | byte | Command Counter = CTR |
2 | byte | Size of DAQ element in bytes { 1, 2, 4 } |
3 | byte | Address extension of DAQ element |
4…7 | unsigned long | Address of DAQ element |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3 … 7 | bytes | don’t care |
2.7.10 DISCONNECT ——断开连接(0X07)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = DISCONNECT 0x07 |
1 | byte | Command Counter = CTR |
2 | byte | 0x00 temporary, 0x01 end of session |
3 | byte | don’t care |
4,5 | word | Station address (Intel format) |
6…7 | bytes | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3 … 7 | bytes | don’t care |
2.7.11. STOP_START ——开始/停止数据传输(0X06)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = START_STOP 0x06 |
1 | byte | Command Counter = CTR |
2 | byte | Mode : start / stop / prepare data tranmission |
3 | byte | DAQ list number |
4 | byte | Last ODT number |
5 | byte | Event Channel No. |
6, 7 | word | Transmission rate prescaler |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3 … 7 | bytes | don’t care |
2.8 可选命令描述
2.8.1. GET_SEED——获取被请求资源的种子(0x12)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = GET_SEED 0x12 |
1 | byte | Command Counter = CTR |
2 | byte | Requested slave resource or function (Resource Mask) |
3…7 | bytes | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3 | byte | Protection status (TRUE or FALSE) |
4…7 | bytes | ‘seed’ data |
2.8.2. UNLOCK——解锁保护(0x13)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = UNLOCK 0x13 |
1 | byte | Command Counter = CTR |
2… | bytes | ‘key’ |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3 | byte | Current Privilege Status (Resource Mask) |
4…7 | bytes | don’t care |
2.8.3 DNLOAD_6 ——数据下载6个字节(0X23)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = DNLOAD_6 0x23 |
1 | byte | Command Counter = CTR |
2…7 | bytes | 6 bytes of data to be transferred |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code |
2 | byte | Command Counter = CTR |
3 | byte | MTA0 extension (after post-increment) |
4…7 | unsigned long | MTA0 address (after post-increment) |
2.8.4 SHORT_UP ——上传数据最多为5个字节(0X0F)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = SHORT_UP 0x0F |
1 | Byte | Command Counter = CTR |
2 | Byte | Size of data block to be uploaded in bytes (1…5) |
3 | Byte | Address extension |
4 | unsigned long | Address |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID: 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 … 7 | bytes | requested data bytes |
2.8.5 SET_S_STATUS ——设置Session状态(0X0C)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = SET_S_STATUS 0x0C |
1 | Byte | Command Counter = CTR |
2 | Byte | Session status bits (see table below) |
3…7 | Byte | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID: 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 … 7 | bytes | don’t care |
2.8.6 GET_S_STATUS ——获得Session状态(0X0D)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = GET_S_STATUS 0x0D |
1 | Byte | Command Counter = CTR |
2…7 | bytes | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID = 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 | Byte | Session status |
4 | Byte | additional status information qualifier |
5 | bytes | additional status information (optional) |
2.8.7 BUILD_CHESUM ——计算校验和(0X0E)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = BUILD_CHKSUM 0x0E |
1 | Byte | Command Counter = CTR |
2…5 | unsigned long | block size in bytes |
6, 7 | bytes | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID: 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 | Byte | size of checksum data |
4 … 7 | bytes | checksum data (implementation specific) |
2.8.8 CLEAR_MEMORY ——清除某内存范围(0X10)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = CLEAR_MEMORY 0x10 |
1 | Byte | Command Counter = CTR |
2…5 | long | Memory size |
3…7 | bytes | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID: 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 … 7 | bytes | don’t care |
2.8.9 PROGRAM ——下载最多5个编程字节(0X18)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = PROGRAM 0x18 |
1 | Byte | Command Counter = CTR |
2 | Byte | Size of data block to follow (bytes) |
3…7 | bytes | Data to be programmed (max. 5 bytes) |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID: 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 | Byte | MTA0 extension (after post-increment) |
4 | unsigned long | MTA0 address (after post-increment) |
2.8.10 PROGRAM_6 ——下载6个编程字节(0X22)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = PROGRAM_6 0x22 |
1 | Byte | Command Counter = CTR |
2…7 | bytes | Data to be programmed (6 bytes) |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID: 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 | Byte | MTA0 extension (after post-increment) |
4 | unsigned long | MTA0 address (after post-increment) |
2.8.11 MOVE ——移动某内存块(0X19)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = MOVE 0x19 |
1 | Byte | Command Counter = CTR |
2…5 | long Size | (number of bytes) of data block to be moved |
6,7 | bytes | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID: 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 … 7 | bytes | don’t care |
2.8.12 DIAG_SERVICE ——诊断服务(0X20)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = DIAG_SERVICE 0x20 |
1 | Byte | Command Counter = CTR |
2,3 | word | Diagnostic service number |
4…7 | bytes | Parameters, if applicable |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID = 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 | Byte | length of return information in bytes |
4 | Byte | data type qualifier of return information (to bedefined) |
5…7 | bytes | don’t care |
2.8.13 ACTION_SERVICE ——行为服务(0X21)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = ACTION_SERVICE 0x21 |
1 | Byte | Command Counter = CTR |
2,3 | word | Action service number |
4…7 | bytes | Parameters, if applicable |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID = 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 | Byte | length of return information in bytes |
4 | Byte | data type qualifier of return information (to bedefined) |
5…7 | bytes | don’t care |
2.8.14 TEST ——测试可用性(0X05)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = TEST 0x05 |
1 | Byte | Command Counter = CTR |
2,3 | little-endian word | station address (Intel format) |
4… | bytes | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID: 0xFF |
1 | Byte | Command Return Code = ACK 0x00 |
2 | Byte | Command Counter = CTR |
3 …7 | bytes | don’t care |
2.8.15 START_STOP_ALL ——开始/停止同步数据传输(0X08)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = START_STOP 0x08 |
1 | Byte | Command Counter = CTR |
2 | Byte | 0x00 stops, 0x01 starts data transmission |
3 … 7 | bytes | don´t care |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID: 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 … 7 | bytes | don’t care |
2.8.16 SELECT_CAL_PAGE ——选择标定数据页(0X11)
CRO:
Position | Type | Description |
---|---|---|
0 | byte | Command Code = SELECT_CAL_PAGE 0x11 |
1 | byte | Command Counter = CTR |
2…7 | bytes | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | byte | Packet ID: 0xFF |
1 | byte | Command Return Code = ACKNOWLEDGE 0x00 |
2 | byte | Command Counter = CTR |
3 … 7 | bytes | don’t care |
2.8.17 GET_ACTIVE_CAL_PAGE —获得当前**的标定页(0X09)
CRO:
Position | Type | Description |
---|---|---|
0 | Byte | Command Code = GET_ACTIVE_CAL_PAGE 0x09 |
1 | Byte | Command Counter = CTR |
2…7 | Bytes | don’t care |
DTO:
Position | Type | Description |
---|---|---|
0 | Byte | Packet ID: 0xFF |
1 | Byte | Command Return Code |
2 | Byte | Command Counter = CTR |
3 | Byte | Address extension |
4 … 7 | unsigned long | Address |
上一篇: Python周立功CAN接口卡接口库函数
下一篇: STM32F1笔记(二)GPIO输入