USB-to-CAN device and transmission rate adjustment method
By monitoring the CAN bus load and USB link characteristic parameters, and using a rate optimization prediction model to dynamically adjust the data transmission rate of the USB to CAN converter, the problem of traditional converters being unable to adaptively adjust is solved, achieving more efficient data transmission.
Patent Information
- Application Number
- CN202511035173.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-25
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2045-07-25
AI Technical Summary
Existing USB to CAN converters cannot adaptively adjust the data transmission rate, resulting in low communication efficiency, data loss, or network congestion in dynamic network environments, and an inability to respond in real time to changes in network load or device status.
By monitoring CAN bus load, standard bit error rate, and USB link characteristic parameters, the data transmission rate is dynamically adjusted using a rate optimization prediction model, and real-time evaluation and adjustment are performed in conjunction with multi-dimensional input vectors.
It significantly improves the stability and efficiency of data transmission, reduces the error rate and link conflict risk, and is suitable for high-speed, high-load CAN bus communication systems.
Smart Images

Figure CN120675948B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of communication interface conversion, in particular to a USB-to-CAN device and a transmission rate adjusting method. BACKGROUND
[0002] A USB (Universal Serial Bus)-to-CAN (Controller Area Network) converter is a common communication bridge in industrial automation, automotive electronics, and many embedded systems. Traditional USB-to-CAN converters usually support fixed data transmission rates, such as standard CAN bus rates of 125 Kbps, 250 Kbps, 500 Kbps, etc. However, with the diversification of application scenarios, the demand for data transmission rates has become increasingly flexible and varied.
[0003] A patent application with the authorization announcement number CN221010145U discloses a CAN signal conversion device, which includes a main control circuit, a CAN bus circuit, a LIN bus circuit, a first isolation circuit, a second isolation circuit, a DB9 interface, and a USB interface. The main control circuit is electrically connected with the first isolation circuit, the second isolation circuit, and the USB interface. The DB9 interface is electrically connected with the CAN bus circuit and the LIN bus circuit. The CAN bus circuit is electrically connected with the first isolation circuit. The LIN bus circuit is electrically connected with the second isolation circuit. In this technical solution, CAN signals and LIN signals enter the main control circuit for analysis. After CAN signal analysis, the CAN signal can be converted into a USB signal and a CAN signal. After LIN signal analysis, the LIN signal can be converted into a USB signal and a LIN signal, realizing the mutual conversion of CAN signals, LIN signals, and USB signals.
[0004] As in the above-mentioned application, in the prior art, USB-to-CAN converters usually support fixed data transmission rates. There is no adaptive adjustment method for data transmission rates. The adjustment of data rates usually requires manual setting by the user or configuration through specific software tools. This is not only cumbersome to operate, but also cannot respond to changes in network load or device status in real time. Especially in a dynamically changing network environment, fixed data rates may lead to low communication efficiency, data loss, or network congestion. SUMMARY
[0005] To solve the above problems, the present application provides a USB-to-CAN device and a transmission rate adjusting method.
[0006] The present application adopts the following technical solution, a transmission rate adjusting method for a USB-to-CAN device, which includes:
[0007] The CAN bus load is obtained by monitoring the frame time interval of the sent frame and the data flow on the bus.
[0008] The standard bit error rate is obtained by monitoring the proportion between error frames and data frames;
[0009] The initial adjustment transmission rate value is generated by weighted summation operation based on CAN bus load and standard bit error rate;
[0010] The USB characteristic parameters including standard USB bandwidth utilization and USB delay rate are collected, and the transmission pressure factor is generated based on the standard USB bandwidth utilization and USB delay rate;
[0011] The initial adjustment transmission rate value, the transmission pressure factor and the data characteristic parameters are input into the pre-constructed rate optimization prediction model, and the predicted optimized adjustment rate is output, and the data transmission rate is dynamically adjusted based on the predicted optimized adjustment rate.
[0012] As a further description of the above technical solution: the method for obtaining the CAN bus load comprises:
[0013] Step 1: based on the rate of the CAN bus and the size of the data frame, the maximum frame transmission capacity of the CAN bus is calculated and obtained;
[0014] Step 2: based on the monitored frame time interval of the sent frame, the actual frame number transmitted per second of the CAN bus is obtained;
[0015] Step 3: based on the known maximum frame transmission capacity and the actual frame number transmitted per second, the CAN bus load is calculated and obtained.
[0016] As a further description of the above technical solution: the method for obtaining the standard USB bandwidth utilization comprises:
[0017] The USB-to-CAN device is connected to the monitoring channel of the analyzer, the packet capture software is started, the analysis channel is selected and the USB bus data is captured in real time;
[0018] The time window is set, the total size of the data packet is captured, and the first utilization rate is calculated and obtained;
[0019] In the USB Host controller, the SOF interrupt handler is registered, and the current timestamp is recorded each time the SOF arrives;
[0020] The period between each SOF and the next SOF is a frame window, and each USB transaction is recorded according to the frame window, and the total frame transmission bytes of a frame window are counted;
[0021] For the frame window, the transmission time record of each data packet is obtained, the gap between each data packet is accumulated as the gap duration, and the frame duration is calculated and obtained, wherein the frame duration is equal to the transmission duration of each data packet plus the gap duration;
[0022] The utilization rate of each frame is calculated in sequence, the utilization rates of consecutive i frames are summed and averaged to obtain the width utilization rate of the USB, i≥10; denoted as a second utilization rate Dlw;
[0023] The first utilization rate and the second utilization rate are weighted and summed to obtain the standard USB bandwidth utilization rate.
[0024] As a further description of the above technical solution: the USB delay rate acquisition method comprises:
[0025] The USB-CAN conversion device is connected to a monitoring channel using a USB protocol analyzer or built-in debugging firmware, and packet capture is started;
[0026] The data acquisition granularity is configured as a transaction level to ensure that each IN / OUT / SETUP Token packet+DATA packet+ACK complete transaction is captured;
[0027] For each complete USB transaction, the transaction initiation time and the transaction response time are recorded, wherein the transaction initiation time is the timestamp of the host sending the IN / OUT / SETUP Token, and the transaction response time is the timestamp of receiving the device return ACK, NAK or DATA packet;
[0028] The transaction transmission delay is calculated by subtracting the transaction initiation time from the transaction response time;
[0029] The delay rate of each frame period is calculated based on the frame period of the USB and the transmission delay of each transaction;
[0030] M frame periods are continuously sampled, and the delay rate of each frame is averaged to obtain the USB delay rate.
[0031] As a further description of the above technical solution: the method for obtaining the standard bit error rate comprises:
[0032] Step S01: presetting a frame number window number as a monitoring period;
[0033] Step S02: in the CAN bus protocol analyzer, i frames are classified and labeled, and the classification labels include valid data frames, error frames and control frames;
[0034] Step S03: in a monitoring period, the number of valid data frames and error frames is counted in real time, and the data area length of each valid data frame and error frame is recorded to obtain the byte number of each frame;
[0035] Step S04: obtaining the original bit error rate based on the basic frame error rate calculation formula;
[0036] Step S05: a preset original error rate threshold is set, when the obtained original error rate is less than or equal to the preset original error rate threshold, the original error rate is recorded as a standard bit error rate; otherwise, when the obtained original error rate is greater than the preset original error rate threshold, step S06 is entered;
[0037] Step S06: the total number of bits is estimated based on the number of bytes of each frame;
[0038] Step S07: the standard bit error rate is calculated based on the total number of bits.
[0039] As a further description of the above technical solution: the data characteristic parameters include data frame type, average frame length and node communication frequency.
[0040] As a further description of the above technical solution: the data frame type includes control frame, remote frame and Data frame; the data characteristic parameters are dynamically collected by a CAN protocol analyzer and a USB link layer capture module, and are encoded and input.
[0041] As a further description of the above technical solution: the acquisition of the transmission pressure factor includes: the transmission pressure factor is generated by weighted sum operation on the standard USB bandwidth utilization rate and the USB delay rate.
[0042] As a further description of the above technical solution: the training method of the rate optimization prediction model includes:
[0043] The historical working data of the USB-to-CAN device is collected, the historical working data is collected under the condition that the numerical transmission rate meets a preset threshold and there is no data loss, the historical working data includes the transmission pressure factor, the initial adjustment transmission rate value, the data characteristic parameters and the corresponding last adjustment rate, the last adjustment rate is recorded as the optimized adjustment rate, and a data set is formed;
[0044] The transmission pressure factor, the initial adjustment transmission rate value and the data characteristic parameters are selected as input features, the optimized adjustment rate is predicted as an output target, and the data set is randomly divided into a training set and a test set according to a preset proportion;
[0045] The SVR model is constructed, the radial basis function is selected as the kernel function of the SVR model, the slack variable is introduced, the optimization target of the SVR model is constructed, the training set data is used, the dual problem of the SVR model is solved, the optimal Lagrange multiplier and the model parameter of the SVR model are obtained, and the model parameter is adjusted constantly in the solving process;
[0046] The trained SVR model is evaluated using the test set data, the error between the predicted value and the true value is calculated, the mean square error, the mean absolute error and the determination coefficient are used to evaluate the prediction performance of the model, and the super parameters of the SVR model are adjusted according to the model evaluation results, including the penalty coefficient, the parameters of the loss function and the bandwidth parameters of the kernel function;
[0047] The optimal combination of super parameters in the super parameter space is searched using the grid search optimization method, the model training and evaluation steps are repeated, and the super parameters are adjusted until the expected prediction performance is obtained, and the rate optimization prediction model is output.
[0048] The USB-to-CAN device is used to realize the transmission rate adjustment method of the USB-to-CAN device, which comprises a USB connector, a single-chip microcomputer and a plurality of CAN transceivers, the plurality of CAN transceivers are in communication with the single-chip microcomputer, the single-chip microcomputer is connected to the USB connector, the single-chip microcomputer receives the USB signal input by the USB connector, and the single-chip microcomputer outputs the received USB signal to the CAN transceiver to realize CAN bus communication, and further comprising:
[0049] The transmission rate control system is used to adjust the data transmission rate, and the transmission rate control system comprises:
[0050] The load monitoring unit is used to monitor the frame time interval of the sending frame and the data flow on the bus to obtain the CAN bus load;
[0051] The bit error rate acquisition unit obtains the standard bit error rate by monitoring the proportion between the error frame and the data frame;
[0052] The initial rate generation unit generates an initial adjusted transmission rate value based on the weighted summation operation of the CAN bus load and the standard bit error rate;
[0053] The data acquisition unit acquires USB characteristic parameters, the USB characteristic parameters include standard USB bandwidth utilization and USB delay rate, and generates a transmission pressure factor based on the standard USB bandwidth utilization and the USB delay rate;
[0054] The rate generation unit acquires the initial adjusted transmission rate value, the transmission pressure factor and the data characteristic parameters, inputs them into the pre-constructed rate optimization prediction model, and outputs a predicted optimized adjustment rate, and dynamically adjusts the data transmission rate based on the predicted optimized adjustment rate.
[0055] Advantages:
[0056] The USB-to-CAN device and the transmission rate adjusting method provided by the application can evaluate the transmission pressure in real time according to the actual communication link state and system performance, and reasonably adjust the rate, thereby significantly improving the stability and efficiency of data transmission, and reducing the error rate and link conflict risk.
[0057] Further, the width utilization rate of the USB is obtained by weighted summation of the first utilization rate and the second utilization rate, the first utilization rate is based on the packet capture tool of the USB protocol analyzer, and the bandwidth usage condition is observed from the macroscopic level of the whole communication process from the host to the device by listening to the USB bus data, which can reflect the actual load rate of the protocol, and the second utilization rate is from the SOF level real-time statistics in the USB Host controller, which has higher time resolution and can analyze the transaction density, gap time and other details from the microscopic level, and is closer to the real bandwidth usage behavior, the two ways are complementary, and the measurement blind area or error caused by a single source is effectively avoided.
[0058] By SOF frame window division, the bus transmission per millisecond (USB2.0) or per 125us (USB3.0) can be finely time-divided, the effective transaction time and gap time in each frame window are accumulated, the degree of "filling" of the USB data in the link is truly simulated, compared with the rough statistics based on the total data volume, this method can capture the protocol layer idle, retransmission, time slot waste and other conditions, more truly reflect the utilization rate, and the average value of the continuous i frame can eliminate the deviation caused by the burst jitter, such as occasional SOF loss, interruption interruption, protocol timeout and the like, and ensure that the result has good time stability and fluctuation buffering capacity, and is suitable for input source of bandwidth dynamic adjustment strategy. BRIEF DESCRIPTION OF DRAWINGS
[0059] The application will be further explained in combination with the drawings and embodiments:
[0060] Figure 1 The flowchart of the transmission rate adjusting method of the USB-to-CAN device provided for the embodiment 1 of the application is shown;
[0061] Figure 2 The flowchart of the method for obtaining the standard bit error rate provided for the embodiment 2 of the application is shown;
[0062] Figure 3 The module connection diagram of the USB-to-CAN device provided for the embodiment 3 of the application is shown;
[0063] Figure 4The timing diagram of the transmission rate adjustment method of the USB-to-CAN device provided for Embodiment 1 of the present application. DETAILED DESCRIPTION
[0064] In order to make the technical means, creative features, purposes and effects achieved by the present application easy to understand, the present application is further described below in combination with specific drawings. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.
[0065] Embodiment 1
[0066] Please refer to Figure 1 and Figure 4 The present application provides a technical solution: a transmission rate adjustment method of a USB-to-CAN device, comprising:
[0067] The CAN bus load is obtained by monitoring the frame time interval of the sending frame and the data flow on the bus.
[0068] It should be noted that the tool for monitoring the time interval of the sending frame and the data flow is a CAN analyzer, which is a hardware tool specially used for monitoring and analyzing CAN bus communication. It can capture and analyze CAN data frames in real time and obtain detailed information of key parameters such as the time interval and flow of the sending frame.
[0069] The method for obtaining the CAN bus load comprises:
[0070] Step 1: based on the rate of the CAN bus and the size of the data frame, the maximum frame transmission capacity of the CAN bus is calculated and obtained;
[0071] The calculation formula of the maximum frame transmission capacity is: ; wherein Bmax is the maximum frame transmission capacity of the CAN bus; Scan is the rate of the CAN bus.
[0072] Example: for a CAN bus with a rate of 500 Kbps and a frame size of 64 bits:
[0073] ; that is, the rate of the CAN bus is 500 Kbps, and theoretically, a maximum of 7812 frames can be transmitted per second;
[0074] Step 2: based on the monitored frame time interval of the sending frame, the actual number of frames transmitted per second by the CAN bus is obtained;
[0075] The calculation formula of the actual number of frames transmitted per second by the CAN bus is: ; wherein Bc is the actual number of frames transmitted per second by the CAN bus, A frame time interval for transmitting a frame, wherein the frame time interval refers to a time interval between two consecutive frames;
[0076] Step 3: Calculate the CAN bus load according to the known maximum frame transmission capacity and the actual number of frames transmitted per second;
[0077] The formula for calculating the CAN bus load Bfz is: ;
[0078] It should be noted that the CAN bus load represents the degree to which the bus is currently being used, reflecting the efficiency of system data transmission. A higher load indicates that the system is closer to saturation, which can cause congestion, delay or data loss. Therefore, if the CAN bus load exceeds a preset threshold (e.g. 80%), the data transmission rate should be reduced, and vice versa to increase data transmission efficiency;
[0079] By monitoring the ratio between error frames and data frames, the standard bit error rate is obtained;
[0080] Based on the CAN bus load and the standard bit error rate, an initial adjustment transmission rate value is generated through a weighted summation operation;
[0081] The calculation method of the initial adjustment transmission rate value includes:
[0082] ; wherein, is the current transmission rate, is the initial adjustment transmission rate value, is a weight coefficient, representing the sensitivity of rate adjustment, and the priority = 0.1; is the bit error rate;
[0083] It should be noted that, and The ratio of the load and the error rate will affect the adjustment of the rate. The higher the load or the larger the error rate, the greater the rate reduction;
[0084] Collect USB feature parameters and data feature parameters, wherein the USB feature parameters include standard USB bandwidth utilization and USB delay rate;
[0085] The method for obtaining the standard USB bandwidth utilization includes:
[0086] Connect the USB-to-CAN device to the monitoring channel of the analyzer, start the packet capture software, select the analysis channel and start real-time capture of USB bus data;
[0087] Set a time window (e.g. 1 second), capture the total size of the data packet, and calculate the first utilization rate Dln;
[0088] Example: The data captured by the analyzer is as follows:
[0089] Total data transmission in 1 second: 3,000,000 bytes; USB type: USB2.0 (480 Mbps);
[0090] The calculation result is 5%, indicating that the USB bandwidth is only used by 5%, which means that there is still a lot of room for improvement.
[0091] In the USB Host controller, register the SOF interrupt handler, and record the current timestamp every time the SOF arrives;
[0092] The period between each SOF and the next SOF is a frame window, and each USB transaction (IN, OUT, CTRL, INT) is recorded according to the frame window, and the total byte number Dzjs of a frame window is counted;
[0093] For this frame window, the transmission time record of each data packet is obtained, the gap between each data packet is accumulated as the gap length, and the frame length Tf is calculated and obtained, which is equal to the transmission length of each data packet plus the gap length;
[0094] The utilization rate of each frame is calculated in turn, and the calculation formula of the utilization rate of each frame is: ; In the formula, lyz is the frame utilization rate, and Rusb is the actual theoretical width of USB;
[0095] The utilization rates of consecutive i frames are summed and averaged to obtain the width utilization rate of USB, i≥10; denoted as the second utilization rate Dlw;
[0096] The first utilization rate and the second utilization rate are weighted and summed to obtain the standard USB bandwidth utilization rate;
[0097] Preferably, the calculation formula of the standard USB bandwidth utilization rate is:
[0098] ; In the formula, is the standard USB bandwidth utilization rate, β1 and β2 are weight factors, β1+β2=1, preferably β1=0.4; β2=0.6;
[0099] It should be noted that the size of the weight coefficient is to obtain a specific value by quantifying each data, which is convenient for subsequent comparison. The size of the weight coefficient depends on the number of comprehensive parameters and the corresponding weight coefficient initially set by the person skilled in the art for each group of comprehensive parameters;
[0100] It should be noted that the standard USB bandwidth utilization refers to the proportion of the actual bandwidth used by the USB to the theoretical maximum bandwidth per unit time; the standard USB bandwidth utilization exceeds a preset threshold (such as 80%), indicating that the USB interface becomes a bottleneck, and the data transmission rate needs to be reduced;
[0101] In this embodiment, the first utilization rate is based on the packet capture tool of the USB protocol analyzer, which observes the bandwidth usage from the macroscopic level of the entire communication process from the host to the device by listening to the USB bus data, can reflect the actual load rate of the protocol, and the second utilization rate comes from the SOF level real-time statistics in the USB Host controller, has higher time resolution, can analyze the transaction density, gap time and other details from the microscopic level, is closer to the real bandwidth usage behavior, the two ways complement each other, and effectively avoid the measurement blind area or error brought by a single source;
[0102] Through SOF frame window division, the bus transmission per millisecond (USB2.0) or per 125us (USB3.0) can be finely time-sliced, the effective transaction time and gap time in each frame window are accumulated, the degree of "filling" of USB data in the link is truly simulated, compared with the rough statistics based on the total data volume, this method can capture the protocol layer idle, retransmission, time slot waste and other situations, more truly reflects the utilization rate, and the mean value of continuous i frames can eliminate the deviation brought by burst jitter, such as occasional SOF missing, interruption interruption, protocol timeout and the like, ensures that the result has good time stability and fluctuation buffering capacity, and is suitable for input source of bandwidth dynamic adjustment strategy;
[0103] The present application overcomes the problems in the prior art that most of the conventional methods only rely on external packet capture tools (such as Wireshark, USB analyzer) or internal driver logs to obtain a single index, and have measurement delay, coarse packet capture time granularity, cannot cover all USB transactions, cannot observe the protocol idle interval and the like.
[0104] The method for obtaining the USB delay rate comprises:
[0105] Use a USB protocol analyzer (such as LeCroy, TotalPhase Beagle USB) or a built-in debugging firmware to connect the USB-to-CAN device to a listening channel, and start packet capture;
[0106] Configure the data acquisition granularity to be transaction level, to ensure that each IN / OUT / SETUP Token packet + DATA packet + ACK complete transaction is captured;
[0107] For each complete USB transaction, record the transaction initiation time, i.e. the timestamp of the host issuing an IN / OUT / SETUP Token, and the transaction response time, i.e. the timestamp of receiving the device's return ACK, NAK or DATA packet;
[0108] The transaction transmission delay is calculated by subtracting the transaction initiation time from the transaction response time;
[0109] The delay rate of each frame period is calculated based on the frame period of USB and the transmission delay of each data;
[0110] The calculation formula of the delay rate is: ;
[0111] The USB delay rate is obtained by averaging the delay rate of each frame by continuously sampling M frame periods (10≤M≤50);
[0112] It should be noted that the USB delay rate is the USB data transmission delay. By measuring the USB data transmission delay, it is evaluated whether the USB system has a delay problem. High delay rate → system busy or communication abnormal, should reduce the sending rate; low delay rate → system idle good, can improve the sending batch or frequency;
[0113] In this embodiment, by capturing USB frame-level transaction data in real time, the time delay between the host scheduling transaction and the device response is accurately calculated, and the representative delay rate parameter is obtained by normalizing with the USB frame period, which can accurately reflect the response time delay between the USB host and the device in the data transmission process, and provide a basis for performance bottleneck positioning. By monitoring the trend of the delay rate, potential abnormalities (such as device ACK delay, frequent NAK) in the communication system can be predicted and adjusted in advance to ensure the stable operation of the real-time system. In addition, the delay rate index can be used in combination with USB bandwidth utilization, CAN bus load rate and other parameters to form a multi-dimensional feedback control mechanism to optimize the collaborative efficiency of the overall communication path.
[0114] Generate a transmission pressure factor based on the standard USB bandwidth utilization and the USB delay rate;
[0115] The transmission pressure factor is generated by performing a weighted summation operation on the standard USB bandwidth utilization and the USB delay rate;
[0116] The calculation formula of the transmission pressure factor is: ;
[0117] In the formula, is the transmission pressure factor, is the standard USB bandwidth utilization, a USB delay rate, a maximum USB delay threshold value preset for the system, and is a weight coefficient, reflecting the influence degree of each index on the system performance.
[0118] In the formula, the two key indexes are normalized and mapped to the same numerical space, and then combined by weighting, so as to eliminate the dimension influence and construct a unified pressure measurement value, reflecting the USB bus bandwidth use pressure, reflecting the time delay tension degree of USB data transmission, and the TPI is used to measure the comprehensive transmission pressure of the current USB-to-CAN device, and the larger the value is, the more the system tends to be saturated or faces the risk of congestion, thereby providing a reference for rate adaptive adjustment.
[0119] It should be noted that the formula involved in the above is to remove the dimension and take the numerical calculation, and is obtained by software simulation of a large amount of data to obtain a formula closest to the actual situation. The weight coefficient in the formula and each preset threshold value in the analysis process are set by the person skilled in the art according to the actual situation or obtained by a large amount of data simulation. The size of the weight coefficient is to obtain a specific numerical value by quantizing each parameter, so as to facilitate subsequent comparison. The size of the weight coefficient depends on the number of sample data and the corresponding processing coefficient preliminarily set by the person skilled in the art for each group of sample data. As long as it does not affect the proportional relationship between the parameter and the quantized numerical value.
[0120] The transmission pressure factor, the initial adjustment transmission rate value and the data characteristic parameter are input into the pre-constructed rate optimization prediction model, and the predicted optimization adjustment rate is output. The data transmission rate is dynamically adjusted based on the predicted optimization adjustment rate;
[0121] The training method of the rate optimization prediction model comprises:
[0122] The historical working data of the USB-to-CAN device is collected, the historical working data is collected under the condition that the numerical transmission rate meets the preset threshold value and there is no data loss, and the historical working data comprises a transmission pressure factor, an initial adjustment transmission rate value, a data characteristic parameter and a corresponding last adjustment rate. The last adjustment rate is recorded as an optimization adjustment rate, and a data set is formed;
[0123] The transmission pressure factor, the initial adjustment transmission rate value and the data characteristic parameter are selected as input features, and the predicted optimization adjustment rate is selected as an output target. The data set is randomly divided into a training set and a test set according to a preset proportion (such as 7:3);
[0124] A support vector regression (SVR) model is constructed, and a radial basis function (RBF) is selected as the kernel function of the SVR model because it has good non-linear mapping ability and can better handle complex rate optimization prediction problems. A relaxation variable is introduced to handle possible outliers or noisy data, and an optimization objective for the SVR model is constructed. The optimization objective aims to minimize the prediction error while controlling the complexity of the model.
[0125] Using the training set data, the optimal Lagrange multipliers and model parameters of the SVR model are obtained by solving the dual problem of the SVR model. During the solving process, the model parameters are constantly adjusted to enable the model to better fit the training data and capture the relationship between the input features and the output target.
[0126] The trained SVR model is evaluated using test set data, and the error between the predicted value and the true value is calculated. The mean squared error (MSE), mean absolute error (MAE), and determination coefficient (R2) are used to evaluate the prediction performance of the model. The mean squared error measures the average of the squares of the errors between the predicted value and the true value, which can reflect the overall error level of the model. The mean absolute error is the average of the absolute errors between the predicted value and the true value, which more directly reflects the size of the prediction error. The determination coefficient represents the goodness of fit of the model to the data, and the closer it is to 1, the better the model fitting effect.
[0127] According to the model evaluation results, the hyperparameters of the SVR model are adjusted, including the penalty coefficient, the parameters of the loss function, and the bandwidth parameter of the kernel function. The penalty coefficient controls the degree of punishment for errors, and a larger penalty coefficient will make the model pay more attention to reducing errors, but may lead to overfitting. The parameters of the loss function affect the tolerance of the model to errors. The bandwidth parameter of the kernel function determines the range of action of the kernel function, which has an important influence on the generalization ability of the model.
[0128] The grid search optimization method is used to search for the optimal combination of hyperparameters in the hyperparameter space. Grid search will traverse the predefined value range of hyperparameters, try all possible combinations, and find the best combination of hyperparameters on the test set.
[0129] The model training and evaluation steps are repeated, and the hyperparameters are constantly adjusted until the desired prediction performance is obtained. In this process, the performance indicators of the model are continuously monitored to ensure that the model maintains stable and good prediction effects on different data sets, thereby effectively avoiding bus overload, data loss, and delay problems, and optimizing the transmission efficiency of the system.
[0130] The optimization problem is converted into a dual problem, and Lagrange multipliers are introduced for solving. In this way, the original problem can be converted into a form that is easier to solve, and it is convenient to determine the support vectors and model parameters later.
[0131] The data characteristic parameters include a data frame type, an average frame length and a node communication frequency, the data frame type includes a control frame, a remote frame and a Data frame, the data characteristic parameters are dynamically collected through a CAN protocol analyzer and a USB link layer capture module, and are encoded and input;
[0132] It should be noted that the frame type reflects the current transmission frame type, and a high proportion of error frames and control frames can reduce transmission efficiency, the longer the frame length, the more the transmission data amount in a unit of time, and the higher the load, and the node communication frequency reflects network activity, and a high frequency can cause a conflict or bandwidth competition.
[0133] In the embodiment, by comprehensively considering the CAN bus load condition, a bit error rate (BER), USB link characteristic parameters and data communication characteristics, a multi-dimensional input vector is established and input into a rate optimization prediction model, so that dynamic optimization and adjustment of the data transmission rate are realized. According to the actual communication link state and system performance, the transmission pressure can be evaluated in real time, and the rate can be reasonably adjusted, so that the stability and efficiency of data transmission are significantly improved, and the bit error rate and link conflict risk are reduced.
[0134] Compared with the traditional method of only relying on fixed rate or single index to adjust the rate, the method can realize more refined and adaptive transmission rate control, and is especially suitable for a high-speed, high-load and bit error sensitive CAN bus communication system, and is suitable for popularization to high-reliability application fields such as industrial control and vehicle-mounted communication.
[0135] Embodiment 2
[0136] Please refer to Figure 1 and Figure 2 The embodiment of the application provides a technical scheme:
[0137] The method for obtaining the standard bit error rate comprises the following steps:
[0138] Step S01: presetting a frame number window number as a monitoring period, and optionally, for example, 100 frames, 500 frames;
[0139] Step S02: in the CAN bus protocol analyzer, classifying and marking i frames, and the classification and marking types include valid data frames, error frames and control frames;
[0140] It should be noted that the valid data frame is a Data Frame, the error frame is an Error Frame, including bit errors, padding errors, frame format errors and the like, and the control frame includes a remote frame, an ACK frame and an Overload frame, which are not counted in the error code analysis.
[0141] Step S03: In a monitoring period, the number of valid data frames and error frames is counted in real time, and the length of data area (DLC field) of each valid data frame and error frame is recorded to obtain the byte number L of each frame i ;
[0142] Step S04: The original bit error rate is obtained based on a basic frame error rate calculation formula; the basic frame error rate calculation formula is ; in the formula, the original bit error rate is , the number of error frames is , and the number of valid data frames is
[0143] Step S05: A preset original bit error rate threshold Byz is set, when the obtained original bit error rate is less than or equal to the preset original bit error rate threshold, the original bit error rate is recorded as a standard bit error rate; otherwise, when the obtained original bit error rate is greater than the preset original bit error rate threshold, step S06 is entered;
[0144] Step S06: The total bit number is estimated by a formula based on the byte number of each frame;
[0145] The calculation formula of the total bit number is: B i =L i ×8+H i , wherein B i is the total bit number, H i is the length of protocol header+CRC+ACK field, and the average value is 47-135 bits; it should be noted that 1 byte=8 bits+protocol overhead (about 47-135 bits / frame);
[0146] Step S07: The standard bit error rate is obtained based on the total bit number, and the calculation formula is:
[0147] ;
[0148] in the formula, the bit error rate is j , the total bit number of the jth error frame is B i , and the total bit number of the ith frame (valid frame or error frame) is B .
[0149] It needs to be explained in this embodiment that the method for obtaining the bit error rate in the prior art is to calculate the proportion between the error frame and the data frame, and the error frame is obtained through the diagnostic function of the USB-to-CAN device. In this method, the calculation method of the original bit error rate does not involve complex bit statistics and weighting process, so the original bit error rate can be obtained in real time with high frequency and low cost during the system operation, thereby realizing the rapid monitoring of the CAN bus communication state. When the original bit error rate abnormally increases, it serves as a pre-confidence signal for triggering in-depth bit error analysis, and improves the response agility of the system. Since the bit-level bit error rate calculation involves DLC field and protocol header estimation, the calculation is relatively complex. The original bit error rate can be used as a first layer of coarse screening index. Only when the original bit error rate exceeds the preset threshold, the bit-level precision estimation process is entered, so as to reduce the resource occupation.
[0150] Further, based on the acquisition method of the weighted bit error rate, the frame-level bit statistics method is adopted, the actual bit quantity proportion between the error frame and the data frame is monitored to estimate the bit error rate, which is more accurate than the traditional estimation method based on the number of frames. The error frame is identified through the diagnostic function of the USB-to-CAN device, and is weighted by combining the bit length of each frame, so as to reflect the actual proportion of the error bits in the total transmission bits in each statistical window, thereby being more close to the bit error transmission characteristics of the physical layer. Especially suitable for bit error rate monitoring of USB-to-CAN, solves the defects of low accuracy of traditional bit error rate estimation, cannot reflect the frame bit difference and is not suitable for dynamic load scene. In high interference environment or industrial scene with high communication quality requirement, the scheme can more truly feedback the link quality, and provide reliable basis for adaptive rate adjustment, anti-interference strategy and fault tolerance control of USB-CAN device.
[0151] Embodiment 3
[0152] Please refer to Figure 3 The embodiment of the application provides a technical scheme:
[0153] The USB-to-CAN device comprises a USB connector, a single-chip microcomputer and a plurality of CAN transceivers, the plurality of CAN transceivers are in communication with the single-chip microcomputer respectively, the single-chip microcomputer is connected with the USB connector externally, the single-chip microcomputer receives the USB signal input by the USB connector, and the single-chip microcomputer outputs the received USB signal to the CAN transceivers, so as to realize CAN bus communication, and the USB-to-CAN device further comprises:
[0154] The transmission rate control system is used for adjusting the data transmission rate, and comprises:
[0155] The load monitoring unit is used for monitoring the frame time interval of the sending frame and the data flow on the bus to obtain the CAN bus load.
[0156] The bit error rate acquisition unit acquires the standard bit error rate by monitoring the proportion between error frames and data frames.
[0157] The initial rate generation unit generates an initial adjusted transmission rate value by a weighted summation operation based on the CAN bus load and the standard bit error rate.
[0158] The data acquisition unit acquires USB characteristic parameters, including the standard USB bandwidth utilization rate and the USB delay rate, and generates a transmission pressure factor based on the standard USB bandwidth utilization rate and the USB delay rate.
[0159] The rate generation unit acquires the initial adjusted transmission rate value, the transmission pressure factor, and the data characteristic parameters, inputs them into a pre-constructed rate optimization prediction model, outputs a predicted optimized adjusted rate, and dynamically adjusts the data transmission rate based on the predicted optimized adjusted rate.
[0160] The above shows and describes the basic principles, main features, and advantages of the present application. Those skilled in the art should understand that the present application is not limited to the above-mentioned embodiments, and the above-mentioned embodiments and descriptions in the specification are only to illustrate the principles of the present application. Without departing from the spirit and scope of the present application, various changes and improvements can be made to the present application, and these changes and improvements all fall within the scope of the claimed present application. The scope of protection of the present application is defined by the appended claims and their equivalents.
Claims
1. A method for adjusting the transmission rate of a USB-to-CAN device, characterized in that, include: The CAN bus load is obtained by monitoring the frame interval of the transmitted frames and the data flow on the bus; The standard bit error rate is obtained by monitoring the ratio between error frames and data frames; The initial adjustment transmission rate value is generated by weighted summation based on CAN bus load and standard bit error rate; Collect USB characteristic parameters, including standard USB bandwidth utilization and USB latency. The method for obtaining the standard USB bandwidth utilization includes: Connect the USB to CAN converter to the analyzer's monitoring channel, start the packet capture software, select the analysis channel, and begin capturing USB bus data in real time. Set a time window, capture the total size of data packets, and calculate the first utilization rate; In the USB Host controller, register an SOF interrupt handler to record the current timestamp each time an SOF occurs; The time interval between each SOF and the next SOF is a frame window. Each USB transaction is recorded according to the frame window, and the total number of bytes transmitted in a frame window is counted. For this frame window, the transmission time record of each data packet is obtained, the gap between each data packet is accumulated as the gap duration, and the frame duration is calculated. The frame duration is equal to the transmission time of each data packet plus the gap duration. The utilization rate of each frame is calculated sequentially, and the average of the utilization rates of i consecutive frames is summed to obtain the USB width utilization rate, i≥10; this is denoted as the second utilization rate. The first and second utilization rates are weighted and summed to obtain the standard USB bandwidth utilization rate. A transmission pressure factor is generated based on standard USB bandwidth utilization and USB latency. The initial adjustment transmission rate value, transmission pressure factor, and data characteristic parameters are obtained and input into the pre-built rate optimization prediction model. The predicted optimization adjustment rate is output, and the data transmission rate is dynamically adjusted based on the predicted optimization adjustment rate.
2. The method for adjusting the transmission rate of the USB-to-CAN device according to claim 1, characterized in that, The method for obtaining the CAN bus load includes: Step 1: Calculate the maximum frame transmission capacity of the CAN bus based on the CAN bus speed and data frame size; Step 2: Obtain the actual number of frames transmitted per second on the CAN bus based on the frame interval of the monitored transmitted frames; Step 3: Calculate the CAN bus load based on the known maximum frame transmission capacity and the actual number of frames transmitted per second.
3. The method for adjusting the transmission rate of the USB to CAN device according to claim 1, characterized in that, The method for obtaining the USB latency rate includes: Connect the USB to CAN device to the listening channel using a USB protocol analyzer or built-in debugging firmware, and start packet capture. Configure data collection granularity to transaction level to ensure that every complete transaction of IN / OUT / SETUP Token packet + DATA packet + ACK is captured; For each complete USB transaction, the transaction initiation time and transaction response time are recorded, where the transaction initiation time is the timestamp when the host sends the IN / OUT / SETUP Token, and the transaction response time is the timestamp when the device returns an ACK, NAK, or DATA packet. The transaction transmission delay is calculated by subtracting the transaction initiation time from the transaction response time. The latency rate for each frame period is calculated based on the USB frame period and the transmission delay of each transaction. The USB latency rate is obtained by averaging the latency of each frame after sampling M consecutive frame periods.
4. The method for adjusting the transmission rate of the USB-to-CAN device according to claim 1, characterized in that, The method for obtaining the standard bit error rate includes: Step S01: Preset the frame window number as the monitoring period; Step S02: In the CAN bus protocol analyzer, the i-frames are classified and marked. The types of classification and marking include valid data frames, error frames, and control frames. Step S03: Within a monitoring cycle, count the number of valid data frames and error frames in real time, and record the data area length of each valid data frame and error frame to obtain the number of bytes in each frame; Step S04: Obtain the raw bit error rate based on the basic frame error rate calculation formula; Step S05: Preset the raw bit error rate threshold. If the obtained raw bit error rate is less than or equal to the preset raw bit error rate threshold, the raw bit error rate is recorded as the standard bit error rate; otherwise, if the obtained raw bit error rate is greater than the preset raw bit error rate threshold, proceed to step S06. Step S06: Estimate the total number of bits based on the number of bytes per frame; Step S07: Calculate the standard bit error rate based on the total number of bits.
5. The method for adjusting the transmission rate of the USB to CAN device according to claim 1, characterized in that, The data characteristic parameters include data frame type, average frame length, and node communication frequency.
6. The method for adjusting the transmission rate of the USB-to-CAN device according to claim 5, characterized in that, The data frame types include control frames, remote frames, and data frames; the data feature parameters are dynamically acquired through a CAN protocol analyzer and a USB link layer capture module, and then encoded and input.
7. The method for adjusting the transmission rate of the USB-to-CAN device according to claim 1, characterized in that, The transmission pressure factor is obtained by performing a weighted summation operation on the standard USB bandwidth utilization and USB latency to generate the transmission pressure factor.
8. The method for adjusting the transmission rate of the USB to CAN device according to claim 7, characterized in that, The training method for the rate optimization prediction model includes: Collect historical working data of the USB to CAN device. The historical working data is collected when the numerical transmission rate meets the preset threshold and there is no data loss. The historical working data includes the transmission pressure factor, the initial adjusted transmission rate value, data characteristic parameters and the corresponding final adjustment rate. The final adjustment rate is recorded as the optimized adjustment rate to form a dataset. The transmission pressure factor, the initial adjusted transmission rate value, and the data feature parameters are selected as input features, and the predicted and optimized adjustment rate is used as the output target. The dataset is randomly divided into training set and test set according to a preset ratio. An SVR model is constructed, and the radial basis function is selected as the kernel function of the SVR model. Relaxation variables are introduced to construct the optimization objective of the SVR model. Using the training set data, the optimal Lagrange multipliers and the model parameters of the SVR model are obtained by solving the dual problem of the SVR model. The model parameters are continuously adjusted during the solution process. The trained SVR model is evaluated using test set data. The error between the predicted and actual values is calculated. The predictive performance of the model is evaluated using mean squared error, mean absolute error, and coefficient of determination. Based on the model evaluation results, the hyperparameters of the SVR model are adjusted, including the penalty coefficient, the parameters of the loss function, and the bandwidth parameters of the kernel function. The optimization method of grid search is used to search for the optimal combination of hyperparameters in the hyperparameter space. The model training and evaluation steps are repeated, and the hyperparameters are continuously adjusted until the expected predictive performance is obtained. The output rate is then optimized to improve the prediction model.
9. A USB-to-CAN device, used to implement the transmission rate adjustment method of the USB-to-CAN device according to any one of claims 1-8, comprising: The system comprises a USB connector, a microcontroller, and multiple CAN transceivers. Each CAN transceiver communicates with the microcontroller. The microcontroller connects to the USB connector, receives USB signals from the USB connector, and outputs the received USB signals to the CAN transceivers, thus achieving CAN bus communication. The system further includes: A transmission rate control system for adjusting the data transmission rate, the transmission rate control system comprising: The load monitoring unit is used to monitor the frame interval of transmitted frames and the data flow on the bus to obtain the CAN bus load; The bit error rate acquisition unit obtains the standard bit error rate by monitoring the ratio between error frames and data frames; The initial rate generation unit generates an initial adjusted transmission rate value based on the CAN bus load and the standard bit error rate through a weighted summation operation. The data acquisition unit acquires USB characteristic parameters, including standard USB bandwidth utilization and USB latency, and generates a transmission pressure factor based on standard USB bandwidth utilization and USB latency. The rate generation unit acquires the initial adjusted transmission rate value, transmission pressure factor, and data characteristic parameters, inputs them into the pre-built rate optimization prediction model, outputs the predicted optimized adjustment rate, and dynamically adjusts the data transmission rate based on the predicted optimized adjustment rate.
Citation Information
Patent Citations
A CAN signal conversion device
CN221010145U
PCIE-to-SATA polymorphic low-delay adaptive circuit
CN114528238A
Adapter for converting USB interface into CAN bus interface
CN213814658U