USB-to-CAN device and transmission rate adjusting method

By monitoring the CAN bus load and USB characteristic parameters, and using a rate optimization prediction model to dynamically adjust the transmission rate of the USB-to-CAN device, the problem that traditional converters cannot make adaptive adjustments is solved, achieving more efficient and stable data transmission.

CN120675948AActive Publication Date: 2025-09-19SHENYANG GUANGCHENG TECH CO LTD

Patent Information

Application Number
CN202511035173.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-25
Publication Date
2025-09-19
Estimated Expiration
2045-07-25

AI Technical Summary

Technical Problem

Existing USB-to-CAN converters cannot adaptively adjust data transmission rates, resulting in low communication efficiency, data loss, or network congestion in dynamic network environments, and are unable to respond to changes in network load or device status in real time.

Method used

By monitoring the CAN bus load and standard bit error rate, combined with USB characteristic parameters, a rate optimization prediction model is used to dynamically adjust the transmission rate, including load monitoring, bit error rate acquisition, USB bandwidth utilization and delay rate calculation, to generate a transmission pressure factor and achieve adaptive rate regulation.

Benefits of technology

It significantly improves the stability and efficiency of data transmission, reduces the bit error rate and link conflict risk, and is suitable for high-speed, high-load CAN bus communication systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120675948A_ABST
    Figure CN120675948A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of communication interface conversion, in particular to a USB (Universal Serial Bus) to CAN (Controller Area Network) device and a transmission rate adjusting method, and the method comprises the following steps: acquiring a CAN bus load by monitoring a frame time interval of a sending frame and data traffic on a bus; the standard bit error rate is obtained by monitoring the proportion between the error frame and the data frame; generating an initial adjustment transmission rate value through weighted summation operation based on the CAN bus load and the standard bit error rate; according to the method, the CAN bus load condition, the bit error rate, the USB link characteristic parameters and the data communication characteristics are comprehensively considered, and the multi-dimensional input vector is established and input into the rate optimization prediction model, so that the dynamic optimization adjustment of the data transmission rate is realized, and the data transmission efficiency is improved. According to the scheme, the transmission pressure can be evaluated in real time according to the actual communication link state and the system performance, the rate is reasonably adjusted, the stability and efficiency of data transmission are remarkably improved, and the error rate and the link conflict risk are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of communication interface conversion, in particular to a USB to CAN device and a transmission rate adjustment method. Background Art

[0002] USB (Universal Serial Bus) to CAN (Controller Area Network) converters are common communication bridges in industrial automation, automotive electronics, and numerous embedded systems. Traditional USB-to-CAN converters typically support fixed data transfer rates, such as standard CAN bus rates of 125Kbps, 250Kbps, and 500Kbps. However, as application scenarios diversify, the demand for data transfer rates is also becoming increasingly flexible and dynamic.

[0003] Patent application number CN221010145U discloses a CAN signal conversion device, comprising 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 to the first isolation circuit, the second isolation circuit, and the USB interface; the DB9 interface is electrically connected to the CAN bus circuit and the LIN bus circuit; the CAN bus circuit is electrically connected to the first isolation circuit; and the LIN bus circuit is electrically connected to the second isolation circuit. In this technical solution, CAN and LIN signals are analyzed after entering the main control circuit. After analysis, the CAN signal can be converted into a USB signal and a CAN signal, and the LIN signal can be converted into a USB signal and a LIN signal, thereby achieving mutual conversion among CAN, LIN, and USB signals.

[0004] As mentioned in the above application, in the existing technical solutions, USB to CAN converters usually support a fixed data transmission rate, and there is no adaptive adjustment method for the data transmission rate. The adjustment of the data rate usually requires the user to manually set it or configure it through specific software tools. Not only is the operation cumbersome, but it also cannot respond to changes in network load or device status in real time. Especially in a dynamically changing network environment, a fixed data rate may lead to problems such as low communication efficiency, data loss or network congestion. Summary of the Invention

[0005] In order to solve the above problems, the present invention provides a USB to CAN device and a transmission rate adjustment method.

[0006] The present invention adopts the following technical solution, a method for adjusting the transmission rate of a USB to CAN device, comprising:

[0007] Obtain the CAN bus load by monitoring the frame time interval of the sent frame and the data flow on the bus;

[0008] By monitoring the ratio between error frames and data frames, the standard bit error rate is obtained;

[0009] Generate an initial adjusted transmission rate value based on the CAN bus load and the standard bit error rate through weighted summation operation;

[0010] collecting USB characteristic parameters, wherein the USB characteristic parameters include a standard USB bandwidth utilization and a USB delay rate, and generating a transmission stress factor based on the standard USB bandwidth utilization and the USB delay rate;

[0011] The initial adjusted transmission rate value, transmission pressure factor and data characteristic parameters are obtained and input into a pre-built rate optimization prediction model, 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 includes:

[0013] Step 1: Based on the CAN bus rate and data frame size, calculate the maximum frame transmission capacity of the CAN bus;

[0014] Step 2: Obtain the actual number of frames transmitted per second on the CAN bus based on the monitored frame time interval of the sent frames;

[0015] Step 3: Calculate the CAN bus load based on the known maximum frame transmission capacity and the actual number of frames transmitted per second.

[0016] As a further description of the above technical solution: the method for obtaining the standard USB bandwidth utilization includes:

[0017] Connect the USB to CAN device to the monitor channel of the analyzer, start the packet capture software, select the analysis channel and start capturing USB bus data in real time;

[0018] Set the time window, capture the total size of data packets, and calculate the first utilization rate;

[0019] In the USB Host controller, register the SOF interrupt handler and record the current timestamp every time SOF arrives;

[0020] The period 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 frame transmission bytes in a frame window is counted.

[0021] For the frame window, obtain the transmission time record of each data packet, accumulate the gaps between each data packet as the gap duration, and calculate the frame duration, where the frame duration is equal to the transmission time of each data packet plus the gap duration;

[0022] Calculate the utilization of each frame in turn, and sum and average the utilization of consecutive i frames to obtain the USB width utilization, i ≥ 10; record it as the second utilization Dlw;

[0023] A weighted sum is performed on the first utilization and the second utilization to obtain a standard USB bandwidth utilization.

[0024] As a further description of the above technical solution: the method for obtaining the USB delay rate includes:

[0025] Use a USB protocol analyzer or built-in debugging firmware to connect the USB to CAN device to the monitoring channel and start packet capture;

[0026] Configure the data collection granularity to the transaction level to ensure that every complete transaction including IN / OUT / SETUP Token packet + DATA packet + ACK is captured;

[0027] For each complete USB transaction, record the transaction initiation time and transaction response time, 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 receives the 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 cycle is calculated based on the USB frame cycle and the transmission delay of each transaction;

[0030] Continuously sample M frame periods, average the delay rate of each frame, and obtain the USB delay rate.

[0031] As a further description of the above technical solution: the method for obtaining the standard bit error rate includes:

[0032] Step S01: Preset the number of frame windows as a monitoring period;

[0033] Step S02: in the CAN bus protocol analyzer, classifying and marking the i-frames, wherein the types of classification markings include valid data frames, error frames, and control frames;

[0034] Step S03: within a monitoring period, count the number of valid data frames and error frames in real time, and record the length of the data area of ​​each valid data frame and error frame to obtain the number of bytes of each frame;

[0035] Step S04: obtaining the original bit error rate based on the basic frame error rate calculation formula;

[0036] Step S05: Preset a raw bit error rate threshold. When 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. Conversely, when the obtained raw bit error rate is greater than the preset raw bit error rate threshold, proceed to step S06.

[0037] Step S06: estimating the total number of bits based on the number of bytes in each frame;

[0038] Step S07: Calculate and obtain a standard bit error rate 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 types include control frames, remote frames and Data frames; the data characteristic parameters are dynamically collected through 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: generating the transmission pressure factor by performing a weighted sum operation on the standard USB bandwidth utilization 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] Collecting historical operating data of the USB-to-CAN device, wherein the historical operating data is collected when the numerical transmission rate meets a preset threshold and there is no data loss. The historical operating data includes a transmission pressure factor, an initial adjusted transmission rate value, a data characteristic parameter, and a corresponding final adjusted rate. The final adjusted rate is recorded as the optimized adjustment rate to form a data set;

[0044] The transmission pressure factor, the initial adjusted transmission rate value, and the data characteristic parameters are selected as input features, the predicted optimized adjustment rate is used as the output target, and the data set is randomly divided into a training set and a test set according to a preset ratio.

[0045] Construct an SVR model, select the radial basis function as the kernel function of the SVR model, introduce slack variables, construct the optimization target of the SVR model, use the training set data, solve the dual problem of the SVR model, obtain the optimal Lagrange multiplier and the model parameters of the SVR model, and continuously adjust the model parameters during the solution process;

[0046] Use the test set data to evaluate the trained SVR model, calculate the error between the predicted value and the true value, and use the mean square error, mean absolute error, and coefficient of determination to evaluate the model's prediction performance. Based on the model evaluation results, adjust the hyperparameters of the SVR model, including the penalty coefficient, the parameters of the loss function, and the bandwidth parameter of the kernel function.

[0047] Use the grid search optimization method to search for the optimal hyperparameter combination in the hyperparameter space, repeat the model training and evaluation steps, and continuously adjust the hyperparameters until the expected prediction performance is obtained, and the output rate optimizes the prediction model.

[0048] A USB to CAN device, used to implement the transmission rate adjustment method of the USB to CAN device, comprises: a USB connector, a single-chip microcomputer, and multiple CAN transceivers, wherein the multiple CAN transceivers respectively communicate with the single-chip microcomputer, the single-chip microcomputer is externally connected to the USB connector, the single-chip microcomputer receives USB signals input by the USB connector, and the single-chip microcomputer outputs the received USB signals to the CAN transceiver to implement CAN bus communication, and further comprises:

[0049] A transmission rate control system, for adjusting the data transmission rate, comprising:

[0050] The load monitoring unit is used to monitor the frame time interval of the sent frames and the data flow on the bus to obtain the CAN bus load;

[0051] A bit error rate acquisition unit, which acquires a standard bit error rate by monitoring the ratio between error frames and data frames;

[0052] An initial rate generation unit generates an initial adjusted transmission rate value through a weighted sum operation based on the CAN bus load and the standard bit error rate;

[0053] a data acquisition unit for acquiring USB characteristic parameters, wherein the USB characteristic parameters include a standard USB bandwidth utilization and a USB delay rate, and generating a transmission pressure factor based on the standard USB bandwidth utilization and the USB delay rate;

[0054] The rate generation unit obtains 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.

[0055] Beneficial effects:

[0056] The USB-to-CAN device and transmission rate adjustment method provided by the present invention comprehensively consider the CAN bus load, bit error rate, USB link characteristic parameters, and data communication characteristics to establish a multi-dimensional input vector, which is input into a rate optimization prediction model, thereby achieving dynamic optimization and adjustment of the data transmission rate. This solution can evaluate the transmission pressure in real time according to the actual communication link status and system performance, and reasonably adjust the rate, significantly improving the stability and efficiency of data transmission, and reducing the bit error rate and link conflict risk.

[0057] Furthermore, the USB bandwidth utilization is obtained by weighted summing the first utilization and the second utilization. The first utilization is based on the packet capture tool of the USB protocol analyzer. By monitoring USB bus data, it observes the bandwidth usage at a macro level of the entire communication process from the host to the device, which can reflect the actual load rate of the protocol. The second utilization comes from the SOF-level real-time statistics in the USB Host controller. It has higher time resolution and can analyze details such as transaction density and gap time at a micro level, which is closer to the actual bandwidth usage behavior. The two methods complement each other and effectively avoid measurement blind spots or errors caused by a single source.

[0058] By dividing the SOF frame window, the bus transmission every millisecond (USB2.0) or every 125μs (USB3.0) can be fine-grained into time segments, and the effective transaction time and gap time within each frame window are accumulated, which truly simulates the degree to which USB data "fills" the link. Compared with rough statistics based only on the total data volume, this approach can capture protocol layer idleness, retransmissions, time slot waste, and other situations, and more realistically reflect utilization. In addition, averaging consecutive i-frames can eliminate deviations caused by sudden jitter, such as occasional SOF missing, interruptions, and protocol timeouts, ensuring that the results have good time stability and fluctuation buffering capabilities, making them suitable as input sources for dynamic bandwidth adjustment strategies. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] The present invention will be further explained below in conjunction with the accompanying drawings and examples:

[0060] Figure 1 A flow chart of a method for adjusting the transmission rate of a USB-to-CAN device provided in Example 1 of the present invention;

[0061] Figure 2 A flowchart of a method for obtaining a standard bit error rate provided in Example 2 of the present invention;

[0062] Figure 3 Module connection diagram of the USB to CAN device provided in Example 3 of the present invention;

[0063] Figure 4This is a timing diagram of the transmission rate adjustment method of the USB to CAN device provided in Example 1 of the present invention. DETAILED DESCRIPTION

[0064] In order to make the technical means, creative features, objectives and effects of the present invention easier to understand, the present invention is further described below with reference to specific diagrams. It should be noted that the embodiments and features in the embodiments of this application can be combined with each other unless they conflict.

[0065] Example 1

[0066] See also Figure 1 and Figure 4 The embodiment of the present invention provides a technical solution: a method for adjusting the transmission rate of a USB to CAN device, comprising:

[0067] Obtain the CAN bus load by monitoring the frame time interval of the sent frame and the data flow on the bus;

[0068] It should be noted that the tool for monitoring the time interval and data flow of sent frames is a CAN analyzer. A CAN analyzer is a hardware tool specifically used to monitor and analyze CAN bus communications. It can capture and analyze CAN data frames in real time and obtain detailed information on key parameters such as the time interval and flow of sent frames.

[0069] Methods for obtaining CAN bus load include:

[0070] Step 1: Based on the CAN bus rate and data frame size, calculate the maximum frame transmission capacity of the CAN bus;

[0071] The calculation formula of the maximum frame transmission capability is: ; Where Bmax is the maximum frame transmission capacity of the CAN bus; Scan is the rate of the CAN bus;

[0072] Example: For a 500Kbps CAN bus, each frame size is 64 bits:

[0073] ; That is, the CAN bus rate is 500 Kbps, and theoretically it can transmit a maximum of 7812 frames per second;

[0074] Step 2: Obtain the actual number of frames transmitted per second on the CAN bus based on the monitored frame time interval of the sent frames;

[0075] The calculation formula for the number of frames actually transmitted per second by the CAN bus is: , where Bc is the number of frames actually transmitted per second by the CAN bus. The frame time interval for sending frames, where the frame time interval refers to the time interval between two consecutive frames;

[0076] Step 3: Calculate the CAN bus load based on the known maximum frame transmission capacity and the actual number of frames transmitted per second;

[0077] The calculation formula of CAN bus load Bfz is: ;

[0078] It should be noted that the CAN bus load indicates the current degree of bus usage and reflects the efficiency of system data transmission. A higher load indicates that the system is closer to saturation, which may cause congestion, delays or data loss. In other words, if the CAN bus load exceeds a preset threshold (for example, 80%), the data transmission rate should be reduced, and vice versa, the data transmission efficiency should be increased.

[0079] By monitoring the ratio between error frames and data frames, the standard bit error rate is obtained;

[0080] Generate an initial adjusted transmission rate value based on the CAN bus load and the standard bit error rate through weighted summation operation;

[0081] The calculation method for the initial adjusted transmission rate value includes:

[0082] ;in, is the current transmission rate, To initially adjust the transmission rate value, is the weight coefficient, which indicates the sensitivity of rate adjustment. =0.1; is the bit error rate;

[0083] It should be noted that and The ratio will affect the rate adjustment. The higher the load or the greater the error rate, the greater the rate reduction.

[0084] Collecting USB characteristic parameters and data characteristic parameters, wherein the USB characteristic parameters include standard USB bandwidth utilization and USB latency rate;

[0085] The method for obtaining the standard USB bandwidth utilization includes:

[0086] Connect the USB to CAN device to the monitor channel of the analyzer, start the packet capture software, select the analysis channel and start capturing USB bus data in real time;

[0087] Set a time window (e.g., 1 second), capture the total size of data packets, and calculate the first utilization Dln;

[0088] Example: The data captured by the analyzer is as follows:

[0089] Total data transfer rate in 1 second: 3,000,000 bytes; USB type: USB2.0 (480Mbps);

[0090] The calculated result is 5%, which means that only 5% of the USB bandwidth is used, indicating 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 SOF arrives;

[0092] The period between each SOF and the next SOF is a frame window. Each USB transaction (IN, OUT, CTRL, INT) is recorded according to the frame window, and the total number of frame transmission bytes in a frame window is counted Dzjs.

[0093] For this frame window, obtain the transmission time record of each data packet, accumulate the gaps between each data packet as the gap duration, and calculate the frame duration Tf. The frame duration Tf is equal to the transmission time of each data packet plus the gap duration.

[0094] The utilization rate of each frame is calculated in sequence. The calculation formula of the utilization rate of each frame is: ; In the formula, lyz is the frame utilization rate, Rusb is the actual theoretical width of USB;

[0095] The USB width utilization is obtained by summing and averaging the utilization of consecutive i frames, i ≥ 10; recorded as the second utilization Dlw;

[0096] Performing a weighted summation on the first utilization and the second utilization to obtain a standard USB bandwidth utilization;

[0097] Preferably, the calculation formula of the standard USB bandwidth utilization is:

[0098] Where, is the standard USB bandwidth utilization, β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 a specific value obtained by quantifying each data to facilitate subsequent comparison. The size of the weight coefficient depends on the number of comprehensive parameters and the initial setting of the corresponding weight coefficient for each set of comprehensive parameters by those skilled in the art.

[0100] It should be noted that standard USB bandwidth utilization refers to the ratio of the actual USB bandwidth used per unit time to its theoretical maximum bandwidth. If the standard USB bandwidth utilization exceeds a preset threshold (such as 80%), it indicates that the USB interface has become a bottleneck and the data transfer 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. By monitoring USB bus data, it observes the bandwidth usage at a macro level during the entire communication process from the host to the device, reflecting the actual load rate of the protocol. The second utilization rate is derived from SOF-level real-time statistics within the USB host controller. It has higher time resolution and can analyze details such as transaction density and intermittent time at a micro level, which is closer to the actual bandwidth usage behavior. The two methods complement each other and effectively avoid measurement blind spots or errors caused by a single source.

[0102] SOF frame windowing allows for fine-grained time segmentation of bus transmissions per millisecond (USB 2.0) or every 125 μs (USB 3.0). The effective transaction time and idle time within each frame window are accumulated, realistically simulating the extent to which USB data "fills" the link. Compared to crude statistics based solely on total data volume, this approach can capture protocol layer idleness, retransmissions, and time slot waste, providing a more realistic reflection of utilization. Furthermore, averaging consecutive i-frames eliminates deviations caused by sudden jitter, such as occasional SOF loss, interruptions, and protocol timeouts. This ensures the results have excellent temporal stability and fluctuation buffering capabilities, making them suitable as input sources for dynamic bandwidth adjustment strategies.

[0103] This application overcomes the problems of traditional methods that mostly rely solely on external packet capture tools (such as Wireshark, USB analyzers) or internal driver logs to obtain a single indicator, which has problems such as measurement delay, coarse packet capture time granularity, inability to cover all USB transactions, and inability to observe protocol idle intervals.

[0104] The method for obtaining the USB delay rate includes:

[0105] Use a USB protocol analyzer (such as LeCroy, TotalPhase Beagle USB) or built-in debugging firmware to connect the USB-to-CAN device to the monitoring channel and start packet capture;

[0106] Configure the data collection granularity to the transaction level to ensure that every complete transaction including IN / OUT / SETUP Token packet + DATA packet + ACK is captured;

[0107] For each complete USB transaction, record the transaction initiation time and transaction response time, 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 receives the 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 USB frame period and the transmission delay of each data;

[0110] The calculation formula of the delay rate is: ;

[0111] Continuously sample M frame periods (10≤M≤50), average the delay rate of each frame, and obtain the USB delay rate;

[0112] It should be noted that the USB latency rate is the USB data transmission delay. By measuring the USB data transmission delay, we can evaluate whether there is a delay problem in the USB system. A high latency rate indicates that the system is busy or the communication is abnormal, so the transmission rate should be reduced. A low latency rate indicates that the system is idle and the transmission batch size or frequency can be increased.

[0113] In this embodiment, by capturing USB frame-level transaction data in real time, accurately calculating the time delay between the host scheduling a transaction and the device responding, and performing normalization processing based on the USB frame period, a representative delay rate parameter is obtained. This parameter can accurately reflect the response delay between the USB host and the device during data transmission, providing a basis for locating performance bottlenecks. By monitoring the changing trend of the delay rate, potential anomalies (such as device ACK delays and frequent NAKs) can be predicted and adjusted before they occur in the communication system, thereby ensuring the stable operation of the real-time system. In addition, the delay rate indicator can be used in conjunction with parameters such as USB bandwidth utilization and CAN bus load rate to form a multi-dimensional feedback control mechanism to optimize the collaborative efficiency of the overall communication path.

[0114] Generates a transfer stress factor based on standard USB bandwidth utilization and USB latency;

[0115] The transmission pressure factor is generated by performing a weighted sum operation on the standard USB bandwidth utilization and the USB delay rate to generate the transmission pressure factor;

[0116] The calculation formula of the transmission pressure factor is: ;

[0117] Where, is the transmission pressure factor, is the standard USB bandwidth utilization, is the USB latency rate, The maximum USB latency threshold preset by the system, and is the weight coefficient, which reflects the influence of each indicator on system performance.

[0118] In the formula, the two key indicators are normalized, mapped to the same numerical space, and then weighted combined to eliminate the dimension effect and construct a unified pressure measurement value. Reflects the USB bus bandwidth usage pressure, Reflecting the delay tension of USB data transmission, TPI is used to measure the comprehensive transmission pressure of the current USB to CAN device. A larger value indicates that the system is more saturated or faces the risk of blocking, thus providing a reference for rate adaptive adjustment.

[0119] It should be noted that the formulas involved in the above are all calculated by removing the dimensions and taking their numerical values. They are a formula that is closest to the actual situation obtained by collecting a large amount of data and performing software simulation. The weight coefficients in the formulas and the various preset thresholds in the analysis process are set by technical personnel in this field according to actual conditions or obtained by simulating a large amount of data; the size of the weight coefficient is to quantify each parameter to obtain a specific numerical value, which is convenient for subsequent comparison. The size of the weight coefficient depends on the amount of sample data and the corresponding processing coefficient preliminarily set by technical personnel in this field for each group of sample data; as long as it does not affect the proportional relationship between the parameter and the quantized value.

[0120] Obtaining the transmission pressure factor, the initial adjusted transmission rate value, and the data characteristic parameters and inputting them into a pre-built rate optimization prediction model, outputting the predicted optimized adjustment rate, and dynamically adjusting the data transmission rate based on the predicted optimized adjustment rate;

[0121] The training method of the rate optimization prediction model includes:

[0122] Collecting historical operating data of the USB-to-CAN device, wherein the historical operating data is collected when the numerical transmission rate meets a preset threshold and there is no data loss. The historical operating data includes a transmission pressure factor, an initial adjusted transmission rate value, a data characteristic parameter, and a corresponding final adjusted rate. The final adjusted rate is recorded as the optimized adjustment rate to form a data set;

[0123] Select the transmission pressure factor, the initial adjusted transmission rate value, and the data characteristic parameters as input features, and predict the optimized adjustment rate as the output target. Randomly divide the data set into training and test sets according to a preset ratio (e.g., 7:3);

[0124] A support vector regression (SVR) model was constructed, and the radial basis function (RBF) was selected as the kernel function for the SVR model due to its excellent nonlinear mapping capabilities and its ability to effectively handle complex rate optimization prediction problems. Slack variables were introduced to address possible outliers or noisy data, and the optimization objective of the SVR model was established. This optimization objective aims to minimize prediction error while controlling model complexity.

[0125] Using the training set data, the dual problem of the SVR model is solved to obtain the optimal Lagrange multiplier and model parameters of the SVR model. During the solution process, the model parameters are continuously adjusted so that the model can better fit the training data and capture the relationship between input features and output targets.

[0126] The trained SVR model was evaluated using the test set data, calculating the error between the predicted value and the true value. The model's predictive performance was assessed using metrics such as mean squared error (MSE), mean absolute error (MAE), and coefficient of determination (R²). The mean squared error measures the average of the squares of the errors between the predicted value and the true value, reflecting the overall error level of the model. The mean absolute error, the average of the absolute errors between the predicted value and the true value, more intuitively reflects the magnitude of the prediction error. The coefficient of determination indicates how well the model fits the data; a value closer to 1 indicates a better fit.

[0127] Based on the model evaluation results, adjust the hyperparameters of the SVR model, 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 penalty for error. A larger penalty coefficient will make the model focus more on reducing error, but may lead to overfitting. The parameters of the loss function affect the model's tolerance for error. The bandwidth parameter of the kernel function determines the range of the kernel function and has a significant impact on the model's generalization ability.

[0128] Use the grid search optimization method to search for the optimal hyperparameter combination in the hyperparameter space. Grid search traverses the predefined range of hyperparameter values, trying all possible combinations to find the hyperparameter combination that performs best on the test set.

[0129] Repeat the model training and evaluation steps, continuously adjusting hyperparameters until the desired predictive performance is achieved. During this process, continuously monitor the model's performance metrics to ensure that the model maintains stable and good predictive results across different datasets, effectively avoiding bus overloads, data loss, and latency issues, and optimizing system transmission efficiency.

[0130] The optimization problem is transformed into a dual problem and Lagrange multipliers are introduced to solve it. This method can transform the original problem into a more solvable form and facilitate the subsequent determination of support vectors and model parameters.

[0131] The data characteristic parameters include data frame type, average frame length and node communication frequency, and the data frame types include 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 encoded and input;

[0132] It should be noted that the frame type reflects the type of frame currently being transmitted. A high ratio of error frames and control frames will reduce transmission efficiency. The longer the frame length, the greater the amount of data transmitted per unit time and the higher the load. The node communication frequency reflects the network activity. A high frequency may cause conflicts or bandwidth competition.

[0133] In this embodiment, a multi-dimensional input vector is established by comprehensively considering CAN bus load, bit error rate (BER), USB link parameters, and data communication characteristics. This input is fed into a rate optimization prediction model, enabling dynamic optimization and adjustment of the data transmission rate. This solution assesses transmission pressure in real time based on the actual communication link status and system performance, and adjusts the rate appropriately, significantly improving data transmission stability and efficiency while reducing bit error rates and the risk of link conflicts.

[0134] Compared with the traditional method of adjusting the rate by relying only on a fixed rate or a single indicator, this method can achieve more refined and adaptive transmission rate control. It is particularly suitable for high-speed, high-load, error-sensitive CAN bus communication systems, and is suitable for promotion to high-reliability application fields such as industrial control and in-vehicle communications.

[0135] Example 2

[0136] See also Figure 1 and Figure 2 , an embodiment of the present invention provides a technical solution:

[0137] Methods for obtaining a standard bit error rate include:

[0138] Step S01: Preset a frame window number as a monitoring period, optionally, such as 100 frames or 500 frames;

[0139] Step S02: in the CAN bus protocol analyzer, classifying and marking the i-frames, wherein the types of classification markings include valid data frames, error frames, and control frames;

[0140] It should be noted that valid data frames are Data Frames, error frames are Error Frames, including bit errors, stuffing errors, frame format errors, etc. Control frames include Remote Frames, ACK Frames, and Overload Frames, which are not included in the bit error analysis.

[0141] Step S03: In one monitoring cycle, count the number of valid data frames and error frames in real time, and record the length of the data area (DLC field) of each valid data frame and error frame to obtain the number of bytes of each frame L. i ;

[0142] Step S04: Obtain the original bit error rate based on the basic frame error rate calculation formula; the basic frame error rate calculation formula is: Where, is the original bit error rate, is the number of error frames, is the number of valid data frames;

[0143] Step S05: Preset the raw bit error rate threshold Byz. When 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. Conversely, when the obtained raw bit error rate is greater than the preset raw bit error rate threshold, proceed to step S06.

[0144] Step S06: estimating the total number of bits using a formula based on the number of bytes in each frame;

[0145] The calculation formula of the total number of bits is: i =L i ×8+H i , where B i is the total number of bits, H i The length of the protocol header + CRC + ACK field is averaged, such as 47-135 bits. It should be noted that 1 byte = 8 bits + protocol overhead (approximately 47 to 135 bits per frame).

[0146] Step S07: Calculate and obtain the standard bit error rate based on the total number of bits. The calculation formula is:

[0147] ;

[0148] Where, is the bit error rate, B j is the total number of bits in the jth error frame, B i is the total number of bits in the i-th frame (valid frame or error frame).

[0149] In this embodiment, it should be noted that, in the prior art, the method for obtaining the bit error rate is to calculate by monitoring the ratio between error frames and data frames, and the error frames are obtained through the diagnostic function of the USB to CAN device. In this method, the original bit error rate is calculated without involving complex bit statistics and weighting processes. Therefore, it can be obtained in real time with high frequency and low overhead during system operation, thereby realizing rapid monitoring of the CAN bus communication status. When the original bit error rate increases abnormally, it serves as a pre-signal to trigger in-depth error analysis, thereby improving the response agility of the system. Since the bit-level bit error rate calculation involves bit-level estimation such as the DLC field and the protocol header, its calculation is relatively complex. The original bit error rate can be used as a first-layer coarse-grained screening indicator. Only when the original bit error rate exceeds the preset threshold, the bit-level accuracy estimation process is entered to reduce resource usage.

[0150] Furthermore, based on the method of obtaining weighted bit-level bit error rate, a frame-level bit statistics method is adopted to estimate the bit error rate by monitoring the actual bit ratio between error frames and data frames. This is more accurate than the traditional estimation method based on the number of frames. The error frames are identified through the diagnostic function of the USB-CAN device, and weighted processing is performed in combination with the bit length of each frame to reflect the actual proportion of error bits in the total transmission bits in each statistical window, thereby being closer to the error transmission characteristics of the physical layer. It is particularly suitable for bit error rate monitoring of USB to CAN, and solves the defects of low accuracy of traditional bit error rate estimation, inability to reflect frame bit differences, and unsuitability for dynamic load scenarios. In high-interference environments or industrial scenarios with high requirements on communication quality, this solution can more realistically feedback link quality, providing a reliable basis for the adaptive rate adjustment, anti-interference strategy and fault-tolerant control of USB-CAN devices.

[0151] Example 3

[0152] See also Figure 3 , an embodiment of the present invention provides a technical solution:

[0153] The USB to CAN device includes a USB connector, a single-chip microcomputer, and several CAN transceivers. The several CAN transceivers communicate with the single-chip microcomputer respectively. The single-chip microcomputer is externally connected to the USB connector. The single-chip microcomputer receives USB signals input from the USB connector and outputs the received USB signals to the CAN transceivers to realize CAN bus communication. The device also includes:

[0154] A transmission rate control system, for adjusting the data transmission rate, comprising:

[0155] The load monitoring unit is used to monitor the frame time interval of the sent frames and the data flow on the bus to obtain the CAN bus load;

[0156] A bit error rate acquisition unit, which acquires a standard bit error rate by monitoring the ratio between error frames and data frames;

[0157] An initial rate generation unit generates an initial adjusted transmission rate value through a weighted sum operation based on the CAN bus load and the standard bit error rate;

[0158] a data acquisition unit for acquiring USB characteristic parameters, wherein the USB characteristic parameters include a standard USB bandwidth utilization and a USB delay rate, and generating a transmission pressure factor based on the standard USB bandwidth utilization and the USB delay rate;

[0159] The rate generation unit obtains 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.

[0160] The basic principles, main features, and advantages of the present invention are shown and described above. Those skilled in the art should understand that the present invention is not limited to the above-described embodiments. The above-described embodiments and descriptions are merely illustrative of the principles of the present invention. Various changes and modifications may be made to the present invention without departing from the spirit and scope of the present invention. Such changes and modifications are intended to fall within the scope of the present invention. The scope of protection claimed in the present invention 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: Obtain the CAN bus load by monitoring the frame time interval of the sent frame and the data flow on the bus; By monitoring the ratio between error frames and data frames, the standard bit error rate is obtained; Generate an initial adjusted transmission rate value based on the CAN bus load and the standard bit error rate through weighted summation operation; Collecting USB characteristic parameters, wherein the USB characteristic parameters include standard USB bandwidth utilization and USB latency rate; Generates a transfer stress factor based on standard USB bandwidth utilization and USB latency; The initial adjusted transmission rate value, transmission pressure factor and data characteristic parameters are obtained and input into a pre-built rate optimization prediction model, the predicted optimized adjustment rate is output, and the data transmission rate is dynamically adjusted based on the predicted optimized adjustment rate.

2. The transmission rate adjustment method of the USB to CAN device according to claim 1, characterized in that: The method for obtaining the CAN bus load includes: Step 1: Based on the CAN bus rate and data frame size, calculate the maximum frame transmission capacity of the CAN bus; Step 2: Obtain the actual number of frames transmitted per second on the CAN bus based on the monitored frame time interval of the sent 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 transmission rate adjustment method of the USB to CAN device according to claim 1, characterized in that: The method for obtaining the standard USB bandwidth utilization includes: Connect the USB to CAN device to the monitor channel of the analyzer, start the packet capture software, select the analysis channel and start capturing USB bus data in real time; Set the time window, capture the total size of data packets, and calculate the first utilization rate; In the USB Host controller, register the SOF interrupt handler and record the current timestamp every time SOF arrives; The period 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 frame transmission bytes in a frame window is counted. For the frame window, obtain the transmission time record of each data packet, accumulate the gaps between each data packet as the gap duration, and calculate the frame duration, where the frame duration is equal to the transmission time of each data packet plus the gap duration; Calculate the utilization of each frame in turn, and sum and average the utilization of consecutive i frames to obtain the USB width utilization, i ≥ 10; record it as the second utilization; A weighted sum is performed on the first utilization and the second utilization to obtain a standard USB bandwidth utilization.

4. The transmission rate adjustment method of the USB to CAN device according to claim 1, characterized in that: The method for obtaining the USB delay rate includes: Use a USB protocol analyzer or built-in debugging firmware to connect the USB to CAN device to the monitoring channel and start packet capture; Configure the data collection granularity to the transaction level to ensure that every complete transaction including IN / OUT / SETUP Token packet + DATA packet + ACK is captured; For each complete USB transaction, record the transaction initiation time and transaction response time, 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 receives the ACK, NAK, or DATA packet. The transaction transmission delay is calculated by subtracting the transaction initiation time from the transaction response time; The delay rate of each frame cycle is calculated based on the USB frame cycle and the transmission delay of each transaction; Continuously sample M frame periods, average the delay rate of each frame, and obtain the USB delay rate.

5. The transmission rate adjustment method 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 number of frame windows as a monitoring period; Step S02: in the CAN bus protocol analyzer, classifying and marking the i-frames, wherein the types of classification markings include valid data frames, error frames, and control frames; Step S03: within a monitoring period, count the number of valid data frames and error frames in real time, and record the length of the data area of ​​each valid data frame and error frame to obtain the number of bytes of each frame; Step S04: obtaining the original bit error rate based on the basic frame error rate calculation formula; Step S05: Preset a raw bit error rate threshold. When 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. Conversely, when the obtained raw bit error rate is greater than the preset raw bit error rate threshold, proceed to step S06. Step S06: estimating the total number of bits based on the number of bytes in each frame; Step S07: Calculate and obtain a standard bit error rate based on the total number of bits.

6. The transmission rate adjustment method 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.

7. The transmission rate adjustment method of the USB to CAN device according to claim 6, characterized in that: The data frame types include control frames, remote frames and Data frames; the data characteristic parameters are dynamically collected through a CAN protocol analyzer and a USB link layer capture module, and are encoded and input.

8. The method for adjusting the transmission rate of a USB to CAN device according to claim 1, wherein: The acquisition of the transmission pressure factor includes: performing a weighted sum operation on the standard USB bandwidth utilization and the USB delay rate to generate the transmission pressure factor.

9. The transmission rate adjustment method of the USB to CAN device according to claim 8, characterized in that: The training method of the rate optimization prediction model includes: Collecting historical operating data of the USB-to-CAN device, wherein the historical operating data is collected when the numerical transmission rate meets a preset threshold and there is no data loss. The historical operating data includes a transmission pressure factor, an initial adjusted transmission rate value, a data characteristic parameter, and a corresponding final adjusted rate. The final adjusted rate is recorded as the optimized adjustment rate to form a data set; The transmission pressure factor, the initial adjusted transmission rate value, and the data characteristic parameters are selected as input features, the predicted optimized adjustment rate is used as the output target, and the data set is randomly divided into a training set and a test set according to a preset ratio. Construct an SVR model, select the radial basis function as the kernel function of the SVR model, introduce slack variables, construct the optimization target of the SVR model, use the training set data, solve the dual problem of the SVR model, obtain the optimal Lagrange multiplier and the model parameters of the SVR model, and continuously adjust the model parameters during the solution process; Use the test set data to evaluate the trained SVR model, calculate the error between the predicted value and the true value, and use the mean square error, mean absolute error, and coefficient of determination to evaluate the model's prediction performance. Based on the model evaluation results, adjust the hyperparameters of the SVR model, including the penalty coefficient, the parameters of the loss function, and the bandwidth parameter of the kernel function. Use the grid search optimization method to search for the optimal hyperparameter combination in the hyperparameter space, repeat the model training and evaluation steps, and continuously adjust the hyperparameters until the expected prediction performance is obtained, and the output rate optimizes the prediction model.

10. A USB-to-CAN device, configured to implement the transmission rate adjustment method of a USB-to-CAN device according to any one of claims 1 to 9, comprising: A USB connector, a single-chip microcomputer, and multiple CAN transceivers, wherein the multiple CAN transceivers communicate with the single-chip microcomputer respectively, the single-chip microcomputer is externally connected to the USB connector, the single-chip microcomputer receives USB signals input by the USB connector, and the single-chip microcomputer outputs the received USB signals to the CAN transceiver to realize CAN bus communication, characterized in that it also includes: A transmission rate control system, for adjusting the data transmission rate, comprising: The load monitoring unit is used to monitor the frame time interval of the sent frames and the data flow on the bus to obtain the CAN bus load; A bit error rate acquisition unit, which acquires a standard bit error rate by monitoring the ratio between error frames and data frames; An initial rate generation unit generates an initial adjusted transmission rate value through a weighted sum operation based on the CAN bus load and the standard bit error rate; a data acquisition unit for acquiring USB characteristic parameters, wherein the USB characteristic parameters include a standard USB bandwidth utilization and a USB delay rate, and generating a transmission pressure factor based on the standard USB bandwidth utilization and the USB delay rate; The rate generation unit obtains 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

  • PCIE-to-SATA polymorphic low-delay adaptive circuit

    CN114528238A

  • Dual-mode network communication method and system based on HPLC + HRF

    CN119603174A

  • Adapter for converting USB interface into CAN bus interface

    CN213814658U

  • System and method for link adaptation for variable link conditions

    US20100124887A1

  • Frame collision rate calculation method for frame on can bus, and can bus resource minimization method

    US20250088465A1

Cited By

  • Image transmission method and system for expressway unmanned aerial vehicle inspection

    CN122093532A