Response Time Analysis for Nonperiodic CAN Message Based on GI/G/1 Queue Model

Controller area network (CAN) has wide applications in modern industrial control systems. Automobile manufacturers use this communication protocol for vehicle control, which is subject to real-time and high-reliability performance. However, with the increasing actuators gathered in the vehicle, time delay will lead to a serious problem for the vehicle safety and performance control. *us, the information transmission stability of the CAN message needs to be investigated. In order to find out the delay response time of nonperiodic CAN message in the vehicle bus area, the response of the message transmitted in the CAN bus is modeled based on the GI/G/1 queue theory. *e test platform is developed to verify the methodology. In the experimental test, some conditions with different IDs, load ratios, and priorities are investigated. Experimental results are compared with the theoretical results, and the simulation results show that the method is valid and verify the real response delay time of nonperiodic CAN message.


Introduction
With the rapid development of the vehicle technology, vehicles are developed as a transportation facility and become more convenient for people. More and more functions are developed for comfort, accessibility, and practicality compared with the past. In order to meet the comfortable and reliability demands of passengers, modern technology has integrated entertainment equipment, personal communication electronic device, wireless connection, and other functions into one car. All these components connected to the network system achieve their function through the electronic control units (ECUs); with the increasing demand for cars, the number of ECUs is growing. ere may be more than 100 ECUs to provide all the electronic functions in high-end vehicles [1][2][3]. Since the information is exchanged through those ECUs with the interconnected data buses, it is necessary to optimize the communication network to reduce the cost and improve the performance.
Controller area network [4][5][6] is designed as a microcontroller in the automotive industry and has become a global standard. Now CAN has been well extensively used in other areas due to its high real-time properties and low cost, such as industrial automation, aircraft industry, industrial control, safety protection, and other fields. No matter in which field, the real-time analysis of CAN bus is still the research; see [7][8][9] and the references therein. In [2], Sato and Fukumoto analyzed the response time of CAN with randomly occurring messages based on M/G/1 queuing theory. Lim et al. [10] investigated the signal distortion in a controller area network with flexible data rate, and the presented model-based analysis can closely approximate the size and time response of ringing and the extent of bit time distortion. Mubeen et al. [11] analyzed periodic, sporadic, and mixed transmission of messages in CAN with implementation of priority queues and FIFO queues.
However, for the general CAN bus network communication, due to the message triggered randomly, the realtime property is also related to the random sending messages. In this paper, the nonperiodic CAN bus communication is investigated. Based on the queue theory GI/G/1 and the bit-stuffing mechanism, the delay time can be read clearly at different ratios. e rest of this paper is organized as follows. Section 2 mainly describes the basics of CAN bus and mathematical queue GI/G/1 model. Section 3 presents the delay model of nonperiodic CAN message which is composed of queue theory about the waiting time and bit-stuffing mechanism about the transmission time. e experimental platform is set up in Section 4. In Section 5, the analysis work about the data compared with the experimental theory is developed. Finally, Section 6 concludes the paper.

Theoretical Analysis
CAN is a multimaster serial communication bus, and it is designed not only with high bit rate and high antielectromagnetic interference but also detecting any occurring error. e CAN communication protocol mainly described the ways of information communication between different devices. With the CAN layer and the definition of the open systems interconnection (OSI), all devices can communicate with the same layer. Real communication can be implemented on every equipment between two layers, and information was only interconnected by physical media. Usually, the specification of CAN defines the bottom transmission via two layers: the data link layer and physical layer. CAN communication could use a variety of physical media, such as twisted-pair cable and optical fiber. e most commonly used is twisted-pair wiring. Signals using a differential voltage and two signal lines are referred to as CAN_H and CAN L, the static voltage is about 2.5 V, the state is expressed as logic 1, which can also be called a Recessive, and CAN H is higher than CAN L, which can be presented as logic 0, known as the "dominant"; thus, CAN H equals 3.5 V and CAN L becomes 1.5 V. e delay of CAN communication can be divided into four parts: generation delay, queuing delay, transmission delay, and delivery delay [12]. e generation delay refers to the time from receiving the request of sending message from the sending node processor to writing the message data into the cache queue; queuing delay refers to the time from the message frame entering the sending buffer queue to the time when the message frame occupies the bus; the transmission delay refers to the time from the message occupying the bus to leaving the bus; delivery delay refers to the time when a message departs from the bus to the receiving node receiving data and providing it to the target processor. Generally, the generation delay and the delivery delay are generally related to the characteristics of the hardware electrical equipment, and the delay time is small. erefore, once considering the CAN communication delay, the queuing delay and the transmission delay are considered. is paper mainly discusses these two parts of the CAN delay.

Transmission Mechanism of CAN Bus. Data in CAN bus
is divided into two types: one is the standard frame, and the other is extended frames. e main difference between these is the length of identifier ID. e schematic diagram of the standard frames is shown in Figure 1.
e main difference of two CAN types between standard frame and extended frame is the length of message. e standard frame has an 11-bit identifier and the extended one has 29-bit identifier. e identifier must be unique, which means that the message derived from different sources must have different identifiers.
Once the bus is at least 6 recessive bits, it is called idle, and all nodes join in the bus with pending messages ready to transmit from the identifier field. According to the arbitration mechanism, a node will not transmit a message if it sent a recessive bit, and the bus level is dominant. Only when the node level is the same as the bus level through whole ID field will the node be allowed to transmit messages. at means the message ID is used for the arbitration mechanism: the smaller the ID, the higher the priority. us, the identifier has two purposes: (1) the priority of the frame and (2) making the receivers able to filter frames. It should be noted that the data transmit in the bus will only have 0∼8 bytes and each byte of message occupies 8 bits in data field, and the data field has 0∼64 bits. For more details about other fields in the frame, the reader is referred to [2,9].
CAN uses NRZ (non-return-to-zero) encoding mode for bit synchronization. In CAN bus, it will be seen as an error flag when the bus has 6 consecutive same polarity bits (000000 or 111111). To avoid those special bit patterns, once a send node has successively transmitted 5 same polarity bits (00000 or 11111), it will additionally add one opposite polarity bit (as a stuff bit). When the receive node has detected 5 same polarity bits, it will remove the stuff bit. is process is called bit-stuffing mechanism.

Queue Mode Modeling.
Queuing is a normal phenomenon in daily life; for example, people queue to register in the hospital and line up in the store and cars on the highway queue to toll station.
e queue system [13][14][15] consists of two parts: one needs to be served and the other provides the services. ose people or things that need to be served are called customers and service for customers is called service counter. e queuing service system can be seen as the customers and the service counter. e GI/G/1 queue [16,17] model is usually described as follows: the customers arrived at time T 1 , T 2 , T 3 . . .; arrival time interval sequence τ n � T n − T n−1 , where (n � 1,2, . . ., τ 0 � 0) are independent from each other and follow the same distribution function A(t); t ≥ 0, and 0 < (1/λ) � ∞ 0 tdA(t); here λ > 0 is a constant. e service time sequence χ i, i > 1 of customers needed is independent and follows the general distribution B(t), and 0 < (1/μ) � ∞ 0 tdB(t) is taken as the average service time. e system follows the FIFO (first-infirst-out) mechanism and only has one service counter.
In GI/G/1 queue system, C n can be seen as the n th customer arriving in the system at time T n , and w n can be seen as the waiting time of customer C n . Customer C n+1 arriving in the system will meet two statuses: one is that the service counter is busy and the other is that the service counter is idle. e two statuses are shown in Figures 2(a) and 2(b). e process can be formulated as (1) Here, w n+1 � w n + χ n − τ n+1 is the (n + 1) th customer's waiting time when it arrives in the system, and thereby w n+1 could be greater than 0 or equal to 0. w n+1 could be shown as Let U n � χ n − τ n+1 , and equation (2) can be described as According to equation (3), we can know that According to [18], the upper boundary of the average waiting time for the mean waiting time of the GI/G/1 system is adopted. In this paper, when ρ < 1, there will be Here, D[χ i ] is the variance of service time, D[τ i ] is the variance of arrive interval time, and ρ � λ/μ indicates the load level or intensity of the system. ereby, the inequation can be deduced into two parts.
In equation (6), the first part on the right can be seen as the waiting time of customers in the queue when a new message arrived, and the second part is the average service time of the current customer served by service counter when a new message arrived. at means if E[W rs ] denotes the current customer-rest service time when a new customer arrives, we can get e average staying time of a message can be obtained by the total time of the average service time and average waiting time, and the expression is

Delay Analysis for Nonperiodic CAN Message
Based on the knowledge of queue theory, if messages occupy the bus and transmitted data was considered as service, then the nodes in the CAN bus need to occupy the bus in the messages transmission process which can be regarded as customer, and the CAN bus provides the physical media to transmit the messages by arbitration and managing the message transmission; the bus can be called service counter. Generally, the messages in the CAN bus system are sent continuously; the total number of customers is infinite, and let the arrival interval time of customer follow general independent distribution. e CAN bus employs the Carrier Sense Multiple Access (CSMA) protocol to arbitrate the messages. is means that if the low-priority message is sent, the higher-priority message needs to wait to be sent until the low-priority messages are sent completely, and if the higherpriority messages are sent, the priority message cannot be sent.
is process accords with the service protocol of nonpreemptive discrimination of priorities. e status of transmission finish for a message in CAN bus is only when all the bits were sent completely. us, we could consider the transmission time as the service time. Due to the fact that the CAN bus transmission time followed a probability distribution according to the difference of stuffing bit, the service time followed the general probability distribution. ere are many nodes in a CAN bus but only one node can send message transmitted on the bus at a moment, which means that there is only one service counter. On the basis of these features of the CAN bus transmission mechanism, we adopt the GI/G/1 queue theory [12,19,20] to model the delay of nonperiodic CAN messages. (1) N nodes in CAN bus represent n customer's arrival interval time sequence, and they share one bus. (2) e customers have priority; the range of the priority from high to low was 1, 2, . . ., n, respectively. Service mechanism employs the nonpreemptive discrimination of priorities. (3) e speeds of arrivals are λ 1 , λ 2 , . . ., λ n . (4) e customer's service time followed the general distribution, and, in different levels, the average service time is 1/μ 1 , 1/μ 2 , . . ., 1/μ n .
On the basis of the message priority from high to low, the first high-priority message is called class 1, the higher-priority message is class 2, and the lowest-priority message is class n. For the class 1 message, its average waiting time E[W q1 ] is expressed as below. When a class 1 message arrives, the remaining transmission time (the average rest service time) of the messages that are transmitting through the bus is E[W rs ], and the average waiting time is supposed to be From equation (7), the average rest service time is supposed to be Here, n represents the n kinds of messages, λ i represents the speed of class i message arrivals, D[χ i ] is the variance of transmission time, and D[τ i ] is the variance of arrive interval time. For the class 2 message, its average waiting time E[W q2 ] is expressed as follows: (1) E[W rs ] is the remaining transmission time (the average rest service time) of the messages that are transmitting through the bus.
(2) When class 2 message arrives, the total transmission time of remaining class 1 message in the queue E[W rt 2 ] is supposed to be (3) When class 2 message arrives and during its waiting period, a new class 1 message arrives, and the total transmission time of new higher-priority (class 1) message is supposed to be According to equations (9), (11), and (12), the average waiting time of class 2 message can be deduced: For the class i message, its average waiting time E[W qi ] is expressed as follows: (1) E[W rs ] is the remaining transmission time (the average rest service time) of the messages that are transmitting through the bus.  (2) When class i message arrives, the total transmission time of remaining higher priority than i messages in the queue E[W rt i ] is supposed to be (3) When class i message arrives and during its waiting period, a new higher-priority message arrives, and the total transmission time of new higher-priority messages is supposed to be According to equations (14) and (15), the message average waiting time of class i can be deduced:

Bit-Stuffing Mechanism and the Transmission Time.
e transmission time is regarded as service time, so we need to figure out the transmission time. As mentioned above for the bit-stuffing mechanism, it will make the real transmitted message bits be greater than original bits.
According to the CAN standard, before the bit-stuffing mechanism, the total number of bits in a CAN frame is Here, L i is the number of bits of the data in messages, 0 ≤ L i ≤ 8; g is the number of control bits in CAN frame, and, for standard frame, g � 34; and, for extended frame, g � 54.
e total number of bits exposed to bit-stuffing is 8L i + g; the remainder including Cyclic Redundancy Check (CRC) delimiter bit, ACK field, EOF, and Int, all 13 bits, are without bit-stuffing.
After bit-stuffing, the total number of bits of a message is where T is the total number of stuffed bits. In the worst situation, an opposite polarity bit every 4 bits will be inserted, as shown in Figure 4. Due to exposure to bit-stuffing only having 8L i + g bits, the maximum of T is e transmission time of a message in the worst situation will be where τ bit represents the time taken to transmit a bit on bus. In fact, the message's stuffing bits are always less than the worst-case scenario; the value of T is less than the maximum T max , and the real transmission time is less than the value as shown in equation (20); the relationship between transmission time C i and stuffing bits T satisfies the equation Due to the bits having different arrangements, the transmission time changes randomly. In [9], after bitstuffing, the real probabilities of having a certain frame length can be calculated. If we transmit a message with 7 bytes, before bit-stuffing, the length of a frame can be at most 103 bits and among them 90 bits are exposed to bit-stuffing. In this 90-bit probabilities model, the following will be assumed: (1) equal probability of bit values 0 and 1 and (2) no dependency among bits. According to the bit-stuffing probability distribution, the mean and variance of transmission time can be calculated by using equation (21). e mean and variance of transmission time for standard format messages with 7 bytes are 106.48104 τ bit t and 2.0078405 τ 2 bit , respectively.
As mentioned above, according to the waiting time and the transmission time, the online delay of nonperiodic CAN message can be derived from equations (8), (16), and (21).
where 1/μ i � C i � (8L i + g + 13 + T)τ bit represents the average service time and represents the average waiting time.

Experimental Test
Actually, the nonperiodic CAN messages transmission is a triggering process. In real condition, the CAN nodes get a send request which is random and then the message is sent. erefore, we use the random sequence as the messages arrival interval time in this experiment through the random interval sequence to send CAN messages in send nodes and use the oscilloscope to detect the received messages in the receiving node and save the datum. e experimental platform includes two parts: the hardware network nodes system and the data collecting system. e hardware devices adopt the Freescale MC9S12X series single chip which is built-in CAN module. is nodes system totally has five nodes, which are consistent with three built-in CAN modules and two CAN analyzer device named CANalyst as four send nodes and one receive node. In more detail, one built-in CAN module acts as a receiving node, the other built-in module acts as the sending node, and the test built-in CAN module and two CAN analyzer act as the interrupt nodes to change the bus load ratio and compete the bus with the sending node. e test and save system was the Mathematical Problems in Engineering digital oscilloscope; it could give intuitive level changes and could save the delay datum about the sending and receiving moment. e whole platform is shown in Figure 5. Numbers 1, 2, and 5 are the CAN module embedded in the Freescale 16-bit MC9S12X series single chip. Number 1 is the sending node in CAN bus, number 2 is the interrupting node in CAN bus, and number 5 is a receiving node in CAN bus; numbers 3 and 4 are the CAN analyzers as two interrupting nodes in the CAN bus; number 6 is a high-accuracy digital oscilloscope, as the delay time data save system; number 7 is the computer, mainly for the CANalyst sent data through a software interface on the computer.
In the experimental platform, the delay of nonperiodic CAN messages with different bus load ratios at different IDs and different priorities is tested and saved in an actual CAN communication process.

Nonperiodic CAN Test Results.
e experiment is implemented and the data are handled, respectively, in ID1, ID2, ID3, and ID4 with ratios of 9.84%, 12.208%, 15.168%, and 18.974%. In each test, 50 time intervals are set, 51 messages are sent at one time, and 10 times data are saved for the data of every ID with every bus load ratio. en, the time difference between receiving and sending is adopted to be the response time, and the value obtained is the average of 10 test data. e following are the detailed data for the nonperiodic CAN messages' response time.
In the first experiment, ID1 is set as the send node, and the nonperiodic CAN messages transmitted from the send node to receive node are tested. en, deal with the datum to get the difference between receiving moment and sending moment and the other operations. In the second experiment, ID1 is set as the send node and, like the first experiment, the third and fourth experiments are similar to the above; the response times of nonperiodic CAN messages are obtained in Table 1.

Comparative Analysis
As discussed above, we can calculate the theory value of the upper boundary of response time with different ratios and different priorities as shown in Table 2. According to the experiment, the ratios of 9.84%, 12.208%, 15.168%, and 18.974% are chosen. Due to the fact that the bus baud rate is 250 kb/s, the value of τ bit is 4 μs. It is worth mentioning that the ID also means the priority, and the lowest ID has the highest priority which is already mentioned in Section 3. Table 2 shows the response time trend with different priorities in ratios of 9.84%, 12.208%, 15.168%, and 18.974%, respectively. Figure 6(a) shows the priority increase in a certain bus load ratio, and the upper boundary of response time is increased. Figure 6(b) shows the bus load ratio increase in a certain priority; the upper boundary of response time is increased, and when the priority is the lowest, the trend of response time increases more quickly than the others, and the highest one is stable. e experimental data are processed in the same ways as in the theory part. From Table 2, the trend about the response time with different priorities in ratios of 9.84%, 12.208%, 15.168%, and 18.974% is obtained and it is shown in Figures 7(a) and 7(b).
From Figure 7(a), we can draw the conclusion that, with the priority decrease in a certain bus load ratio, the upper boundary of response time is increasing; and, from Figure 7(b), it is shown that, with the bus load ratio increase in a certain priority, the upper boundary of response time is increasing and when the priority is lower, the response time is higher than the higher priority.
Comparing the test and theory data, Figures 8(a)∼8(d) represent the relationship between the test delay time of nonperiodic CAN messages and the theory in different bus load ratios; the results show that the theory analysis about the experimental data of the nonperiodic CAN message delay time is under the upper boundary of theory response time in GI/G/1queue system; and the trend of experimental change curve is similar to the theory.

Conclusions
is paper adopts the GI/G/1 queue system model to analyze the nonperiodic CAN messages time delay performance with nonpreemptive discrimination of priorities, and the experimental data reflect the reliability of the upper boundary of waiting time and the service time obtained by the bit-stuffing mechanism. e similarity between mathematical theory and the experiment about the trends of delay time in different ratios with different priorities also shows that the mathematical theory of the GI/G/1 queue system is feasible. Using the upper boundary of response time, the new model for the worse scenario of response time to handle the case of messages transmit in CAN bus will be investigated in the future.

Data Availability
e research data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest
e authors declare that they have no conflicts of interest.