CAN-Sniffer Protokoll V1

Aus iSysBus Doku

Wechseln zu: Navigation, Suche

Allgemein / CAN-Sniffer / CAN-Sniffer_Protokoll_V1

Diese Seite beschreibt die Version 1 des CAN-Sniffer-Protokolls.

Dieses Protokoll ist gültig seit dem 28.04.2009

Zusätze werden grün markiert, geänderte Stellen orange und wegfallende Einträge rot

Inhaltsverzeichnis

Paketaufbau

Die einzelnen Datenpakete besitzen folgenden Aufbau:

SOF CTRL Daten CRC
1 Byte 1 Byte variabel 2 Bytes

Das SOF (Start Of Frame) Feld besteht aus dem Startbyte 0x01 Das CTRL (Control) Feld enthält den TOF (Type Of Frame) und je nach Typ erweiterte Informationen

SOF und CTRL bestimmen den Paketaufbau, gemäß folgender Tabelle. Dabei steht jede Zeile für einen Header, bestehend aus SOF, TOF und eventuell einem Subtyp (bei Befehlen und Fehlern).

SOF CTRL Typ-Info Subtyp-Info
1 Byte 1 Byte
0x01 000 00000 Befehl Reset
00001 Modus
00010 RX Fehlercounter
00011 TX Fehlercounter
00100 Initialisierung
00101 Taktrate
00110 Version
00111 Bufsize
01001 Time-Sync
010 xxxxx Standard Frame -
011 xxxxx Extended Frame -
110
/
111
/
100
00000 Standard Frame Error
/
Extended Frame Error
/
Error Frame
Error Frame
00001 Overload Frame
00010 CRC Error
00011 Acknowledge Error
00100 Form Error
00101 Bit Error
00110 Stuff Error
00111 RX Buffer Overflow
01000 Bus-Off
01001 TX Error
01010 RX Error
01011 TX Warn
01100 RX Warn


Befehl

Der Befehl-Typ wird zum Steuern des Adapters vom PC aus verwendet. Das Feld CTRL setzt sich zusammen aus dem Type Of Frame (die höchstwertigen 3 Bits) sowie dem Befehltyp (die restlichen 5 Bits).


Reset

Löst einen Neustart des Adapters aus

SOF CTRL CRC
0x01 TOF RES [CRC]
0b000 0b00000
1 Byte 1 Byte 2 Byte
4 Bytes


Feld Breite Werte Info
[CRC] 2 Byte 0x00-0xFF (2x) Prüfsumme (siehe CRC)



Modus

Stellt verschiedene Modi ein

SOF CTRL Daten CRC
0x01 TOF MOD [VAL] [CRC]
0b000 0b00001
1 Byte 1 Byte 1 Byte 2 Byte
5 Bytes


Feld Breite Werte Info
[VAL] 1 Byte 0x00 = Abfrage, 0x01 = OFF, 0x02 = Monitor, 0x03 = Listen-Only, 0x04 = Loopback Schaltet die verschiedenen Modi um



RX Fehlercounter

Liefert die Anzahl der Emfpangsfehler

SOF CTRL Daten CRC
0x01 TOF RXERR [VAL] [CRC]
0b000 0b00010
1 Byte 1 Byte 1 Byte 2 Byte
5 Bytes


Feld Breite Werte Info
[VAL] 1 Byte 0x00-0xFF Anzahl der Empfangsfehler (zur Abfrage auf 0x00 setzen)



TX Fehlercounter

Liefert die Anzahl der Sendefehler

SOF CTRL Daten CRC
0x01 TOF TXERR [VAL] [CRC]
0b000 0b00011
1 Byte 1 Byte 1 Byte 2 Byte
5 Bytes


Feld Breite Werte Info
[VAL] 1 Byte 0x00-0xFF Anzahl der Sendefehler (zur Abfrage auf 0x00 setzen)



Initialisierung

Stellt Prescaler, TQ PropSeg, TQ PhSeg1, TQ PhSeg2, TQ Jump Width und die Anzahl der Samples ein

SOF CTRL Daten CRC
0x01 TOF INIT [BRP] [PSEG] [PHSEG1] [PHSEG2] [JPW] [SAM] [CRC]
0b000 0b00100
1 Byte 1 Byte 6 Bytes 2 Byte
10 Bytes


Feld Breite Werte Info
[BRP] 1 Byte 0x00-0xFF Prescaler-Wert
[PSEG] 1 Byte 0x00-0x08 TQ PropSeg
[PHSEG1] 1 Byte 0x01-0x08 TQ PhSeg1
[PHSEG2] 1 Byte 0x02-0x08 TQ PhSeg2 (Wert muss kleiner als [PHSEG1] sein)
[JPW] 1 Byte 0x00-0x04 TQ Jump Width
[SAM] 1 Byte 0x01 / 0x03 Anzahl der Samples (1 bzw. 3)



Taktrate

Liest die Taktrate des CAN-Controllers aus

SOF CTRL Daten CRC
0x01 TOF XTAL [OSC1] [OSC2] [OSC3] [OSC4] [CRC]
0b000 0b00101
1 Byte 1 Byte 4 Byte 2 Byte
8 Bytes


Feld Breite Werte Info
[OSC1] 1 Byte 0x00-0xFF Taktfrequenz, Byte 1
[OSC2] 1 Byte 0x00-0xFF Taktfrequenz, Byte 2
[OSC3] 1 Byte 0x00-0xFF Taktfrequenz, Byte 3
[OSC4] 1 Byte 0x00-0xFF Taktfrequenz, Byte 4


Der Wert wird wie folgt berechnet: Taktrate = [OSC1] + [OSC2] * 2^8 + [OSC3] * 2^16 + [OSC4] * 2^24
Zur Abfrage des aktuellen Wertes sind alle [OSCx]-Bytes auf 0x00 zu setzen

Version

Liefert die Adapterkennung, die verwendete Protokollversion sowie die Firmware-Version des Adapters

SOF CTRL Daten CRC
0x01 TOF VER [ADI] [PV] [VER1] [VER2] [VER3] [CRC]
0b000 0b00110
1 Byte 1 Byte 5 Bytes 2 Byte
9 Bytes


Feld Breite Werte Info
[ADI] 1 Byte 0x00-0xFF Adapter Identification (Hardwaretyp)
[PV] 1 Byte 0x00-0xFF Verwendete Protokollversion
[VER1] 1 Byte 0x00-0xFF Adapterversion, Byte 1
[VER2] 1 Byte 0x00-0xFF Adapterversion, Byte 2
[VER3] 1 Byte 0x00-0xFF Adapterversion, Byte 3


Die Adapterversion setzt sich wie folgt zusammen: x.y.zz = [VER3].[VER2].[VER1]
Die Versionsnummer für das Protokoll ist eine fortlaufende Nummer

Bufsize

Liest die Größe des Sende- und Empfangspuffers (vom Adapter in Richtung PC aus gesehen) aus.

SOF CTRL Daten CRC
0x01 TOF BUFSIZE [BUF_TX] [BUF_RX] [CRC]
0b000 0b00111
1 Byte 1 Byte 2 Byte 2 Byte 2 Byte
8 Bytes


Feld Breite Werte Info
[BUF_RX] 2 Byte 0-65535 Puffergröße PC->Adapter in Byte
[BUF_TX] 2 Byte 0-65535 Puffergröße Adapter->PC in Byte



Time-Sync

Kommando, um den internen 16-Bit Zähler auf 0 zu setzen und anfangen, jede Milisekunde um 1 nach oben zu zählen. Jedes dafür vorgesehene Paket erhält damit einen Zeitstempel um die Sende- und Empfangsreihenfolge feststellen zu können. Das Paket sollte vom Adapter möglichst zeitnah ausgewertet werden.

SOF CTRL CRC
0x01 TOF TSYN [CRC]
0b000 0b01001
1 Byte 1 Byte 2 Byte
4 Bytes



Standard Frame

Enthält die Daten eines CAN-Standard-Frames sowie einen Timestamp, wann das Paket vom Adapter gesendet bzw. empfangen wurde


SOF CTRL Daten CRC
0x01 TOF [RTR] [DLC] [TSP] [DIR] [RES] [CAN_ID] [CAN_DATA] [CRC]
0b010 1 Bit 4 Bit 1 Bit 4 Bit 11 Bit
1 Byte 1 Byte 2 Byte 2 Byte 0-8 Byte 2 Byte
8-16 Bytes


Feld Breite Werte Info
[RTR] 1 Bit 0 / 1 CAN Remote Request
[DLC] 4 Bit 0-8 CAN Data Length
[RES] 4 Bit - reserviert
[DIR] 1 Bit 0 / 1 Richtungsbit, 0: Nachricht kommt vom CAN-Bus / 1: Nachricht wird auf den Bus gelegt
[CAN_ID] 11 Bit 0x0000-0x3FF CAN ID
[CAN_DATA] 0-8 Byte 0x00-0xFF CAN Daten (Anzahl der Bytes wird durch [DLC] bestimmt)
[TSP] 2 Byte 0x00-0xFF (2x) Timestamp
[CRC] 2 Byte 0x00-0xFF (2x) Prüfsumme (siehe CRC)

Hinweis: Die Anzahl der Datenbytes in [DATA] wird durch [DLC] bestimmt

Extended Frame

Enthält die Daten eines CAN-Extended-Frames sowie einen Timestamp, wann das Paket vom Adapter gesendet bzw. empfangen wurde


SOF CTRL Daten CRC
0x01 TOF [RTR] [DLC] [TSP] [DIR] [RES] [CAN_ID] [CAN_DATA] [CRC]
0b011 1 Bit 4 Bit 1 Bit 2 Bit 29 Bit
1 Byte 1 Byte 2 Byte 4 Byte 0-8 Byte 2 Byte
10-18 Bytes


Feld Breite Werte Info
[RTR] 1 Bit 0 / 1 CAN Remote Request
[DLC] 4 Bit 0-8 CAN Data Length
[CAN_ID] 4 Byte 0-2^29 CAN Extended ID (29 Bit)
[CAN_DATA] 0-8 Byte 0x00-0xFF CAN Daten (Anzahl der Bytes wird durch [DLC] bestimmt)
[TSP] 2 Byte 0x00-0xFF (2x) Timestamp
[CRC] 0x00-0xFF 0x00-0xFF (2x) Prüfsumme (siehe CRC)

Hinweis: Die Anzahl der Datenbytes in [DATA] wird durch [DLC] bestimmt

Standard Frame Error

Enthält die Daten eines CAN-Standard-Frames, einen Fehlercode sowie einen Timestamp, wann das Paket vom Adapter gesendet / empfangen wurde bzw. der Fehler aufgetreten ist

SOF CTRL Daten CRC
0x01 TOF [RTR] [DLC] [TSP] [RES] [ERR] [DIR] [RES] [CAN_ID] [CAN_DATA] [CRC]
0b110 1 Bit 4 Bit 3 Bit 5 Bit 1 Bit 4 Bit 11 Bit
1 Byte 1 Byte 2 Byte 1 Byte 2 Byte 0-8 Byte 2 Byte
9-17 Bytes


Feld Breite Werte Info
[RES] - - Reserviert für Erweiterungen
[ERR] 5 Bit 0-32 Fehler-ID (siehe Fehlertypen)
[RTR] 1 Bit 0 / 1 CAN Remote Request
[DLC] 4 Bit 0-8 CAN Data Length
[DIR] 1 Bit 0 / 1 Richtungsbit, 0: Nachricht kommt vom CAN-Bus / 1: Nachricht wird auf den Bus gelegt
[CAN_ID] 4 Byte 0-2^29 CAN Extended ID (29 Bit)
[CAN_DATA] 0-8 Byte 0x00-0xFF CAN Daten (Anzahl der Bytes wird durch [DLC] bestimmt)
[TSP] 2 Byte 0x00-0xFF (2x) Timestamp
[CRC] 0x00-0xFF 0x00-0xFF (2x) Prüfsumme (siehe CRC)



Extended Frame Error

Enthält die Daten eines CAN-Extended-Frames sowie einen Timestamp, wann das Paket vom Adapter gesendet bzw. empfangen wurde


SOF CTRL Daten CRC
0x01 TOF [RTR] [DLC] [TSP] [RES] [ERR] [DIR] [RES] [CAN_ID] [CAN_DATA] [CRC]
0b111 1 Bit 4 Bit 3 Bit 5 Bit 1 Bit 2 Bit 29 Bit
1 Byte 1 Byte 2 Byte 1 Byte 4 Byte 0-8 Byte 2 Byte
11-19 Bytes


Feld Breite Werte Info
[RES] 3 Bit - Reserviert für Erweiterungen
[ERR] 5 Bit 0-32 Fehler-ID (siehe Fehlertypen)
[RTR] 1 Bit 0 / 1 CAN Remote Request
[DLC] 4 Bit 0-8 CAN Data Length
[DIR] 1 Bit 0 / 1 Richtungsbit, 0: Nachricht kommt vom CAN-Bus / 1: Nachricht wird auf den Bus gelegt
[CAN_ID] 4 Byte 0-2^29 CAN Extended ID (29 Bit)
[CAN_DATA] 0-8 Byte 0x00-0xFF CAN Daten (Anzahl der Bytes wird durch [DLC] bestimmt)
[TSP] 2 Byte 0x00-0xFF (2x) Timestamp
[CRC] 0x00-0xFF 0x00-0xFF (2x) Prüfsumme (siehe CRC)



Error Frame

SOF CTRL Daten CRC
0x01 TOF [ERR] [TSP] [CRC]
0b100 5 Bit
1 Byte 1 Byte 2 Byte 2 Byte
6 Bytes


Feld Breite Werte Info
[ERR] 5 Bit 0-32 Fehler-ID (siehe Fehlertypen)



Fehlertypen

ID Fehler
0x00 Error Frame
0x01 Overload Frame
0x02 CRC Error
0x03 Acknowledge Error
0x04 Form Error
0x05 Bit Error
0x06 Stuff Error
0x07 RX Buffer Overflow
0x08 Bus-Off
0x09 TX Error
0x0A RX Error
0x0B TX Warn
0x0C RX Warn



CRC

Die Prüfsumme der Pakete wird nach folgendem Algorithmus gebildet:

uint16_t calc_crc(void *data, uint16_t len) {
  uint32_t sum = 0;
  for (;;) {
    if (len < 2) break;
    sum += *((uint16_t *)data);
    data += 2;
    len -= 2;
  }
  if (len) sum += *(uint8_t *) data;
  while ((len = (uint16_t) (sum >> 16)) != 0) sum = (uint16_t) sum + len;
  return (uint16_t) sum ^ 0xFFFF;
}

Dabei zählen alle Bytes bis auf das Startbyte und die CRC-Bytes

Meine Werkzeuge