# CarTwin--Development of a Digital Twin for a Real-World In-Vehicle CAN Network
## 2 Background and Related Work
### Background of the CAN Bus  
Due to its cost efficiency and reliability under harsh conditions, the Controller Area Network (CAN) has been widely used since the 1990s in road vehicles as a data distribution interface between Electronic Control Units (ECUs), sensors and actuators. More recently, the CAN specifications were extended by Bosch to support higher payload and data rates as CAN-FD. The CAN protocol and its extension, CAN-FD, have been standardized by ISO (International Organization for Standardization) under the ISO-11898 standard [13,14]. A newer generation called CAN-XL, which will support even higher payloads and bit-rates that allow tunneling of Ethernet packets, will arrive soon. This proves that the CAN bus will survive in its newer embodiment, CAN-FD or CAN-XL, in future in-vehicle networks.  
CAN is an asynchronous serial communication protocol that requires information to be transmitted using dominant, i.e., logical '0', or recessive, i.e., logical '1', bits. A twisted pair of wires denoted as CANH (CAN High) and CANL (CAN Low) with a termination of 120 \(\Omega\) on both sides defines the CAN bus physical layer. The physical network supports the connection of multiple nodes that can transmit or receive frames with a pre-defined structure following the specifications defined by the CAN standard included in ISO-11898-1 [13]. The CAN nodes communicate on the physical bus using a CAN controller, usually embedded as part of a microcontroller, and a CAN transceiver. The CAN controller has two lines for communicating with the transceiver, called TX and RX. The RX line reflects the state of the physical bus converted by the transceiver from a differential voltage between CANH and CANL to a logical state, while the TX interface is used by nodes to transmit bits via the CAN transceiver on the physical bus. Each node can start communicating whenever the bus is idle, and if more than one node is trying to transmit data, all transmitters have to follow the arbitration procedure for the CAN bus, during which the node sending the frame with the highest priority wins.  
There are four specific types of frames defined on the CAN bus: data frames used to transfer data, remote frames used to request a data frame, overload frames signaling an overload condition and error frames signaling an error was detected.  
The CAN data frame is structured in different bit fields, which are defined according to the ISO-11898-1 [13] standard. Each frame transmission starts with the SOF (start of frame) bit, which is always dominant because the bus state is recessive when the bus is idle. It is followed by the arbitration field, which contains the frame identifier, i.e., ID, and will determine the node that wins the arbitration part. The ID is followed by the RTR (remote transmit request) bit, which, if recessive, it requests frame transmission from the genuine sender (remote frame), and if dominant, it means the data frame is transmitted by the sender (normal frame). The node that wins arbitration continues sending the control field, which starts with the IDE bit that is dominant for standard identifiers and recessive for extended identifiers. For standard frames, the control field contains a reserved bit that is always dominant and the number of data bytes carried by the frame, followed by the data field with the actual frame content called DLC. After the data field, the CRC field follows, and it is used by receivers to check the integrity of the received header and frame data. Then, the ACK field follows, which is used by the receivers to confirm the correct reception of the frame by transmitting a dominant bit over the recessive bit sent by the frame transmitter. Both CRC and ACK fields have a bit delimiter, i.e., DEL, that is always recessive. The frame ends with an EOF (end of frame) field of seven recessive bits. The remote frame has a similar structure with the data frame, except that it does not transmit data bytes, so it has an empty data field. The frame structure for a CAN data frame is depicted in Figure 2.