Method and system for reducing data transmission packet loss rate of USB (Universal Serial Bus) virtual serial port and related equipment
By setting a ring receiving buffer for the USB virtual serial port and dynamically adjusting its capacity, the common packet loss problem in USB virtual serial port data transmission is solved, the stability and reliability of data transmission is improved, and the effective management of buffer capacity is realized.
Patent Information
- Application Number
- CN202510043846.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-10
- Publication Date
- 2025-05-09
AI Technical Summary
Data packet loss problems are often encountered in the data transmission of existing USB virtual serial ports, which are mainly caused by factors such as data processing delay, buffer overflow or interference, which seriously affects the stability and reliability of communication.
Set a ring receiving buffer for the USB virtual serial port and monitor its remaining capacity in real time. When the remaining capacity is less than the preset unit capacity value, the expanded capacity is dynamically increased from the redundant capacity of the ring receiving buffer, and it is determined whether the total capacity value is greater than the critical value. If it exceeds it, an alarm information will be generated.
By dynamically adjusting the capacity of the ring receiving buffer, the packet loss rate of data transmission is effectively reduced, the stability and reliability of communication is improved, and users are promptly reminded to adjust the buffer parameters to avoid problems caused by excessive capacity.
Smart Images

Figure CN119961200A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of USB data transmission, and in particular to a method, system and related equipment for reducing the packet loss rate of USB virtual serial port data transmission. Background Art
[0002] With the advancement of USB technology, USB CDC (Communication Device Class) virtual serial ports are widely used for data transmission between microcontrollers and hosts. However, in practical applications, microcontrollers often encounter data packet loss problems when processing USB CDC communications. These problems may be caused by factors such as data processing delays, buffer overflows or interference, which seriously affect the stability and reliability of communication.
[0003] In the prior art, the solution for dealing with the single-chip USB CDC packet loss problem has the following main disadvantages:
[0004] 1. Buffer overflow, Disadvantages: Many existing technologies rely on only a single buffer to store received data. When the data flow exceeds the buffer processing capacity, it will cause the buffer to overflow, resulting in data packet loss. Problem manifestation: When the data receiving speed exceeds the data processing speed, the buffer cannot accommodate all the data, resulting in partial data loss.
[0005] 2. Insufficient buffer. Disadvantages: In some solutions, the size of the buffer is not designed enough to effectively cope with peak data traffic. This design deficiency will limit the system's ability to handle large amounts of data. Problem manifestation: Insufficient buffer will lead to data packet loss, especially when data traffic surges, and it is impossible to effectively cache and process all received data, thus affecting the stability and reliability of the system.
[0006] Therefore, the prior art still needs to be improved and developed. Summary of the invention
[0007] The main purpose of the present invention is to solve the technical problems mentioned in the above background technology existing in the existing USB virtual serial port data transmission.
[0008] A first aspect of the present invention provides a method for reducing a packet loss rate of USB virtual serial port data transmission, comprising:
[0009] Set up a circular receive buffer for the USB virtual serial port;
[0010] The annular receiving buffer receives initial data with a default capacity value;
[0011] Real-time monitoring of the remaining capacity of the annular receiving buffer under the default capacity value state;
[0012] When the remaining capacity is less than a preset unit capacity value, dynamically increasing the expansion capacity of the ring receiving buffer by a number of the unit capacity values from the redundant capacity of the ring receiving buffer;
[0013] In response to each expansion of the capacity of the annular receiving buffer, determining whether a current total capacity value of the annular receiving buffer is greater than a critical value;
[0014] When the current total capacity value of the annular receiving buffer is greater than the critical value, an alarm message is generated to prompt the user to modify the parameters of the annular receiving buffer by using macro definition through the alarm message.
[0015] In an optional implementation of the first aspect of the present invention, setting a circular receiving buffer for the USB virtual serial port includes:
[0016] Allocate a circular receiving buffer for the USB virtual serial port through a kernel parameter configuration command, and configure a default capacity value and a maximum capacity value of the circular receiving buffer, wherein the circular receiving buffer is composed of a plurality of unit capacity spaces of equal sectors;
[0017] A dynamic capacity matching rule of the annular receiving buffer is set, and a parameter adjustment mode of the annular receiving buffer is configured as a macro definition.
[0018] In an optional implementation manner of the first aspect of the present invention, the initial data reception of the annular receiving buffer with a default capacity value includes:
[0019] Setting a head pointer and a tail pointer in the default capacity value interval of the annular receiving buffer, and specifying the tail pointer to guide the writing position of data each time;
[0020] Each time the data is written into the circular receive buffer based on the tail pointer, the tail pointer moves toward the head pointer by a distance of the unit capacity value.
[0021] In an optional implementation of the first aspect of the present invention, the real-time monitoring of the remaining capacity of the annular receiving buffer in the default capacity value state includes:
[0022] In response to each writing of the data, obtaining a current first data address of the head pointer and a current second data address of the tail pointer;
[0023] Perform pointer distance calculation on the first data address and the second data address to obtain the remaining capacity of the ring receiving buffer.
[0024] In an optional implementation of the first aspect of the present invention, when the remaining capacity is less than a preset unit capacity value, dynamically increasing the expansion capacity of the ring receiving buffer by a number of the unit capacity values from the redundant capacity of the ring receiving buffer includes:
[0025] When the remaining capacity is less than a preset unit capacity value, obtaining a first difference between a data writing speed and a data fetching speed of the annular receiving buffer;
[0026] Based on the comparison between the first difference and the unit capacity value, a target amount for expanding the unit capacity value is obtained;
[0027] Obtaining a moving distance of the head pointer based on the target quantity;
[0028] The address of the head pointer in the ring receive buffer is adjusted based on the moving distance.
[0029] In an optional implementation of the first aspect of the present invention, in response to each expansion of the capacity of the annular receive buffer, determining whether the current total capacity value of the annular receive buffer is greater than a critical value includes:
[0030] Acquire the third data address of the head pointer after capacity expansion;
[0031] Performing pointer distance calculation on the third data address and the initial data address of the tail pointer to obtain a current total capacity value of the annular receiving buffer;
[0032] Obtain a critical value based on multiplying the maximum capacity value of the annular receiving buffer by a preset safety index;
[0033] The current total capacity value of the annular receiving buffer is compared with the critical value to determine whether the current total capacity value of the annular receiving buffer is greater than the critical value.
[0034] In an optional implementation manner of the first aspect of the present invention, when the current total capacity value of the ring receiving buffer is greater than the critical value, generating the alarm information further includes:
[0035] In response to the generation of the alarm information, enabling a preset USB interrupt thread;
[0036] The USB interrupt thread is used to determine the preset interrupt condition of the annular receiving buffer;
[0037] When the annular receiving buffer satisfies the interrupt condition, the annular receiving buffer is controlled to stop data transmission.
[0038] A second aspect of the present invention provides a data transmission system for reducing a packet loss rate of USB virtual serial port data transmission, the data transmission system comprising:
[0039] The buffer setting module is used to set a circular receiving buffer for the USB virtual serial port;
[0040] An initial receiving module, used for receiving initial data in the annular receiving buffer with a default capacity value;
[0041] A capacity monitoring module, used for monitoring the remaining capacity of the annular receiving buffer in real time under the default capacity value state;
[0042] A capacity expansion module, configured to dynamically increase the expansion capacity of the ring receiving buffer by a number of the unit capacity values from the redundant capacity of the ring receiving buffer when the remaining capacity is less than a preset unit capacity value;
[0043] A critical judgment module, configured to judge whether a current total capacity value of the annular receiving buffer is greater than a critical value in response to each expansion of the capacity of the annular receiving buffer;
[0044] The reminder module is used to generate an alarm message when the current total capacity value of the annular receiving buffer is greater than the critical value, so as to prompt the user to modify the parameters of the annular receiving buffer by using the macro definition through the alarm message.
[0045] A third aspect of the present invention provides a data transmission device for reducing a packet loss rate of data transmission through a USB virtual serial port, the data transmission device for reducing a packet loss rate of data transmission through a USB virtual serial port comprising: a memory and at least one processor, the memory storing instructions, the memory and the at least one processor being interconnected via a line;
[0046] The at least one processor calls the instruction in the memory to enable the data transmission device for reducing the USB virtual serial port data transmission packet loss rate to perform the method for reducing the USB virtual serial port data transmission packet loss rate as described in any one of the first aspects above.
[0047] A fourth aspect of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method for reducing the packet loss rate of USB virtual serial port data transmission as described in any one of the above-mentioned first aspects is implemented.
[0048] Beneficial effects: The present invention discloses a method, system and related equipment for reducing the packet loss rate of USB virtual serial port data transmission. The method includes setting a circular receiving buffer for the USB virtual serial port; receiving initial data in the circular receiving buffer with a default capacity value; real-time monitoring of the remaining capacity of the circular receiving buffer under the default capacity value state; when the remaining capacity is less than the preset unit capacity value, dynamically increasing the expansion capacity of a number of unit capacity values from the redundant capacity of the circular receiving buffer; in response to each expansion capacity, determining whether the current total capacity value of the circular receiving buffer is greater than a critical value; if the current total capacity value is greater than the critical value, generating an alarm message to prompt the user to modify the parameters of the circular receiving buffer using macro definitions. The present invention uses a circular receiving buffer to manage data flow. The circular receiving buffer can dynamically adjust the capacity size based on the received data, and can also provide timely reminders when the capacity is insufficient, thereby reducing the packet loss rate of data transmission. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 The present invention is an exemplary flowchart of a method for reducing the packet loss rate of USB virtual serial port data transmission.
[0050] Figure 2 The figure is a schematic diagram of a ring receiving buffer in a default state according to an exemplary embodiment of the present invention.
[0051] Figure 3 The figure is a schematic diagram of a ring receiving buffer in an exemplary expanded state according to the present invention.
[0052] Figure 4 A schematic diagram of a circular receiving buffer in an exemplary critical state of the present invention.
[0053] Figure 5 The present invention is an exemplary schematic diagram of the module composition of a data transmission system for reducing the packet loss rate of USB virtual serial port data transmission.
[0054] Figure 6 The present invention is an exemplary schematic diagram of the device composition of a data transmission device for reducing the packet loss rate of USB virtual serial port data transmission. DETAILED DESCRIPTION
[0055] The embodiments disclosed in the present invention are described in more detail below with reference to the accompanying drawings. Although certain embodiments disclosed in the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments disclosed in the present invention are only for exemplary purposes and are not intended to limit the scope of protection disclosed in the present invention.
[0056] In the description of the embodiments disclosed in the present invention, if there are terms, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc. can refer to different or the same objects. Other explicit and implicit definitions may also be included below.
[0057] See also Figure 1 The first aspect of the present invention provides a method for reducing the packet loss rate of USB virtual serial port data transmission, comprising:
[0058] S100, setting a circular receiving buffer for the USB virtual serial port; in the present invention, the design of the circular receiving buffer data structure can be: composed of an array and two pointers (head pointer and tail pointer). The head pointer points to the earliest data in the buffer, and the tail pointer points to the location where the next data will be written. When the tail pointer catches up with the head pointer, the buffer is full; when the head pointer catches up with the tail pointer, the buffer is empty.
[0059] In an optional implementation of step S100 of the present invention, setting a circular receive buffer for the USB virtual serial port includes: allocating a circular receive buffer for the USB virtual serial port through a kernel parameter configuration command, and configuring a default capacity value and a maximum capacity value of the circular receive buffer, wherein the maximum capacity value is equal to the default capacity value+a redundant capacity value, wherein the circular receive buffer is composed of a number of unit capacity spaces of equal sectors; setting a dynamic capacity matching rule for the circular receive buffer, and configuring a parameter adjustment method of the circular receive buffer as a macro definition.
[0060] Specifically, in the present invention, increasing the buffer is to modify the size of the kernel parameters. Establish a ring buffer area, and according to actual business needs, open the size of the ring buffer area through commands. For example: in the Linux system, the kernel parameters can be modified through the sysctl command, such as setting the receiving buffer size to 10MB, and the following commands can be used: sudosysctl-wnet.core.rmem_max=10485760; sudosysctl-wnet.core.rmem_default=5242880; Set the maximum value and default value of the receiving buffer to 10MB and 5MB respectively. In this way, it is set as a macro definition, and the size of the buffer can be flexibly adjusted. Matching rules: According to actual business needs, if the amount of data is too large and the remaining size of the buffer area is less than 1MB, the ring area automatically opens a temporary 1MB buffer area. If a peak data traffic impact is encountered, in order to avoid packet loss, all areas of the ring buffer are opened to 10MB. When the data traffic is reduced to less than the default buffer area, it is restored to the default buffer area size of 5MB.
[0061] S200, the annular receiving buffer is used for initial data reception with a default capacity value; during the initialization process of the USB virtual serial port, a memory space is allocated for the annular receiving buffer, and its head pointer and tail pointer are initialized to 0. At the same time, the default capacity value of the buffer is set, and this value can be determined according to the data receiving rate and processing power in the actual application. For example, the annular buffer is set to 10MB (macro definition can be performed to set macros with different values), half of the buffer size is enabled by default, and the default is 5MB. Figure 2 as shown.
[0062] In an optional implementation of step S200 of the present invention, the initial data reception of the annular receiving buffer with a default capacity value includes: setting a head pointer and a tail pointer in the default capacity value interval of the annular receiving buffer, and specifying the tail pointer to guide the writing position of the data each time; each time the data is written into the annular receiving buffer based on the tail pointer, the tail pointer moves toward the head pointer by the distance of the unit capacity value. In the present invention, the head pointer and the tail pointer are used to indicate the data position in the annular buffer. The head pointer points to the earliest written data position in the buffer, and the tail pointer points to the next position in the buffer where the data will be written. They move in the buffer to track the reading and writing of data. When the data is written into the buffer according to the position of the tail pointer, the tail pointer moves forward by a unit capacity value. This unit capacity value is usually the size of a data element, such as a byte or a data packet. The direction of the tail pointer's movement is toward the direction of the head pointer, that is, it moves forward in the annular buffer. Through the setting and movement rules of the head pointer and the tail pointer, the annular buffer can efficiently manage the reading and writing operations of data, avoiding the problems of data overflow and data loss. It is widely used in many applications, such as audio processing, network communication, etc., for temporary storage and transmission of data.
[0063] S300, real-time monitoring of the remaining capacity of the annular receiving buffer under the default capacity value state; after the USB virtual serial port starts working, data will be continuously written into the tail pointer position of the annular receiving buffer. Every time a data is written, the tail pointer moves forward by one position. If the tail pointer reaches the end of the buffer, it returns to the starting position to form a ring. In the present invention, the current used capacity of the annular receiving buffer can be obtained by calculating the distance between the head pointer and the tail pointer. The remaining capacity of the buffer is equal to its total capacity minus the used capacity.
[0064] In an optional implementation of step S300 of the present invention, the real-time monitoring of the remaining capacity of the annular receiving buffer under the default capacity value state includes: in response to each writing of the data, obtaining the current first data address of the head pointer and the current second data address of the tail pointer; performing pointer distance calculation on the first data address and the second data address to obtain the remaining capacity of the annular receiving buffer. Specifically, in the present invention, each time new data is written into the annular buffer, a remaining capacity calculation process is triggered. Pointer distance calculation is to calculate the difference in data addresses between the head pointer and the tail pointer. This distance can be obtained by a simple subtraction operation, that is, the second data address (tail pointer address) minus the first data address (head pointer address), and the remaining capacity of the annular receiving buffer can be calculated by the proportional relationship between the current data address difference between the head pointer and the tail pointer and the maximum data address difference in combination with the default capacity value corresponding to the maximum data address difference.
[0065] S400. When the remaining capacity is less than the preset unit capacity value, dynamically increase the expansion capacity of the ring-shaped receiving buffer by a number of the unit capacity values from the redundant capacity of the ring-shaped receiving buffer; in the present invention, when it is monitored that the remaining capacity of the ring-shaped receiving buffer is less than the preset unit capacity value, it means that the buffer is about to be full and the capacity needs to be expanded. The process of expanding the capacity is to allocate a portion of space from the redundant capacity of the buffer and add it to the total capacity of the buffer. For example, if the default capacity of the buffer is 1024 bytes and the unit capacity value is 256 bytes, when the remaining capacity is less than 256 bytes, 256 bytes of expanded buffer can be allocated from the redundant capacity. Specifically, Figure 3 shown.
[0066] In an optional implementation of the first aspect of the present invention, when the remaining capacity is less than the preset unit capacity value, dynamically increasing the expansion capacity of the ring receiving buffer by a number of the unit capacity values from the redundant capacity of the ring receiving buffer includes: when the remaining capacity is less than the preset unit capacity value, obtaining the first difference between the data writing speed and the data taking speed of the ring receiving buffer; comparing the first difference with the unit capacity value to obtain the target number of expanding the unit capacity value; obtaining the moving distance of the head pointer based on the target number; and adjusting the address of the head pointer in the ring receiving buffer based on the moving distance. In the present invention, when the remaining capacity of the buffer is lower than the unit capacity value, it means that the space of the buffer is very tight and may not be able to meet the subsequent data writing requirements. At this time, measures need to be taken to expand the capacity of the buffer. By comparing the first difference with the unit capacity value, it can be determined how many unit capacity values need to be expanded to meet the current data writing requirements. The target number refers to the number of unit capacity values that need to be increased, which is proportional to the size of the first difference. If the first difference is large, it means that the data writing speed is much faster than the data retrieval speed, and more capacity needs to be expanded; otherwise, less capacity needs to be expanded. After determining the target number of capacity expansion, it is necessary to calculate the distance the head pointer should move. The moving distance of the head pointer is related to the target number. Usually, the moving distance is equal to the target number multiplied by the unit capacity value. By moving the head pointer, more space can be released to expand the capacity of the buffer. Finally, according to the calculated moving distance, the address of the head pointer in the ring buffer is adjusted. Moving the head pointer forward by a corresponding distance releases space of a corresponding size.
[0067] S500, in response to each expansion of the capacity of the annular receiving buffer, determine whether the current total capacity value of the annular receiving buffer is greater than a critical value; in the present invention, after each expansion of the capacity, it is necessary to determine whether the current total capacity value of the annular receiving buffer is greater than a preset critical value. The critical value is an upper limit of the buffer capacity, and exceeding this value may cause system performance degradation or data loss. If the current total capacity is greater than the critical value, it means that the buffer has been expanded to an unsafe level.
[0068] In an optional implementation of the first aspect of the present invention, in response to each capacity expansion of the circular receive buffer, determining whether the current total capacity value of the circular receive buffer is greater than a critical value includes: obtaining a third data address of the head pointer after the capacity expansion; performing pointer distance calculation on the third data address and the initial data address of the tail pointer to obtain the current total capacity value of the circular receive buffer; obtaining a critical value based on multiplying the maximum capacity value of the circular receive buffer by a preset safety index; comparing the current total capacity value of the circular receive buffer with the critical value to determine whether the current total capacity value of the circular receive buffer is greater than the critical value. In the present invention, the total capacity of the current circular receiving buffer can be obtained by calculating the difference between the third data address of the head pointer and the initial data address of the tail pointer after the capacity is expanded. Generally speaking, the circular receiving buffer will not alarm after the data is completely full, but will alarm a period of time in advance. That is to say, the circular receiving buffer will have a critical value, and this critical value is related to the safety index set in different data transmission scenarios. For data transmission scenarios with larger traffic, the safety index will be relatively small, that is, the critical value will be smaller, and the alarm will be earlier. For data transmission scenarios with smaller traffic, the safety index will be relatively large, that is, the critical value will be larger, and the alarm will be later.
[0069] S600, when the current total capacity value of the annular receiving buffer is greater than the critical value, an alarm message is generated to prompt the user to modify the parameters of the annular receiving buffer using the macro definition through the alarm message. In the present invention, when the buffer has expanded to an unsafe level, an alarm message needs to be generated. The alarm message can notify the user through log records, interface prompts, etc., prompting the user to modify the attribute parameters of the annular receiving buffer using the macro definition, such as increasing the initial capacity of the buffer, adjusting the unit capacity value, etc., to avoid the problems caused by frequent expansion of the buffer and excessive capacity. In the macro definition of the annular receiving buffer, a series of data operation functions are used for data management of the buffer, including initialization, appending, reading, deleting and clearing operations. The use of macro definitions: macros for defining buffer size and other related parameters, and how to flexibly adjust these parameters in different application scenarios. For example, in the exemplary application scenario of the present invention, under normal conditions, if the default capacity buffer size can meet the requirements, and when the peak data flow arrives, when the default buffer area does not meet the requirements, the annular buffer area will be opened to a critical value of 9MB at most to cope with the peak data flow. If 9MB still does not meet the requirement, an alarm message will be issued to remind the user to modify the maximum size of the ring buffer area through macro definition, such as Figure 4 shown.
[0070] In an optional implementation of the first aspect of the present invention, when the current total capacity value of the annular receiving buffer is greater than the critical value, after generating the alarm information, it also includes: in response to the generation of the alarm information, enabling a preset USB interrupt thread; judging the preset interrupt condition of the annular receiving buffer by the USB interrupt thread; when the annular receiving buffer satisfies the interrupt condition, controlling the annular receiving buffer to stop data transmission. In the present invention, when initializing USB data reception, the conditions for USB interrupt reception are set, and it is defined under which conditions USB data reception will generate an interrupt, such as when the received data exceeds the maximum capacity of the buffer, when data transmission is completed, etc., and the corresponding interrupt service program is configured to enable these interrupt conditions. More specifically, the process of initializing USB interrupt can be as follows: configuring the interrupt controller to initialize the relevant registers of the interrupt controller, such as the interrupt control register (INTCON) and the interrupt mode register (INTMOD), to enable USB interrupts. configuring the interrupt vector table, and associating the address of the USB interrupt service program (ISR) with the corresponding interrupt vector. setting the external interrupt pin if the USB controller is connected to the microcontroller via the external interrupt pin, the pin needs to be configured as the interrupt input mode. Set the external interrupt register and specify the interrupt triggering method (such as edge trigger or level trigger). Install the USB interrupt service program and write the USB interrupt service program, which is responsible for handling the interrupt events generated by the USB controller. Install the interrupt service program to the corresponding position in the interrupt vector table. Start the USB interrupt and enable the USB interrupt by setting the main control register or other related registers.
[0071] In general, the main features of the present invention are: 1) Optimized configuration of the ring buffer: Ring buffer structure: A ring buffer is used to manage data flow, with key attributes such as a write pointer (i.e., tail pointer), a read pointer (i.e., head pointer), size, and data cache address. Dynamic adjustment of buffer size: A large-capacity buffer is defined (to adapt to different data transmission requirements, thereby improving data processing capabilities. 2) Macro definition and buffer management: Macro definition: Use macro definition to flexibly configure the buffer size to adapt to different communication interfaces and data volumes. Buffer operation function: A set of functions is provided to initialize, manage, append, read, and delete data in the ring buffer, thereby effectively processing data flows. 3) Improved data transmission stability and performance: Reduced data packet loss: Reduced data packet loss and improved data transmission reliability by increasing the buffer capacity.
[0072] See also Figure 5 A second aspect of the present invention provides a data transmission system that reduces the packet loss rate of USB virtual serial port data transmission, the data transmission system comprising:
[0073] The buffer setting module 10 is used to set a circular receiving buffer for the USB virtual serial port;
[0074] An initial receiving module 20 is used to receive initial data in the annular receiving buffer with a default capacity value;
[0075] A capacity monitoring module 30, used for real-time monitoring of the remaining capacity of the annular receiving buffer under the default capacity value state;
[0076] The capacity expansion module 40 is used to dynamically increase the expansion capacity of the ring receiving buffer by a number of the unit capacity values from the redundant capacity of the ring receiving buffer when the remaining capacity is less than the preset unit capacity value;
[0077] A critical judgment module 50 is used to judge whether the current total capacity value of the annular receiving buffer is greater than a critical value in response to each expansion of the capacity of the annular receiving buffer;
[0078] The reminder module 60 is used to generate an alarm message when the current total capacity value of the annular receiving buffer is greater than the critical value, so as to prompt the user to modify the parameters of the annular receiving buffer by using the macro definition through the alarm message.
[0079] In an optional implementation of the second aspect of the present invention, the buffer setting module includes:
[0080] A buffer allocation unit, used to allocate a circular receiving buffer for the USB virtual serial port through a kernel parameter configuration command, and configure a default capacity value and a maximum capacity value of the circular receiving buffer, wherein the circular receiving buffer is composed of a plurality of unit capacity spaces of equal sectors;
[0081] The rule definition unit is used to set the dynamic capacity matching rule of the annular receiving buffer and configure the parameter adjustment mode of the annular receiving buffer as a macro definition.
[0082] In an optional implementation manner of the second aspect of the present invention, the initial receiving module includes:
[0083] A pointer setting module, used for setting a head pointer and a tail pointer in the default capacity value interval of the ring receiving buffer, and specifying the tail pointer to guide the writing position of data each time;
[0084] The pointer moving module is used for each time the data is written into the circular receiving buffer based on the tail pointer, the tail pointer moves the distance of the unit capacity value toward the head pointer.
[0085] In an optional implementation of the second aspect of the present invention, the capacity monitoring module includes:
[0086] a pointer address acquisition unit, configured to acquire a current first data address of the head pointer and a current second data address of the tail pointer in response to each writing of the data;
[0087] The first address distance calculation unit is used to perform pointer distance calculation on the first data address and the second data address to obtain the remaining capacity of the ring receiving buffer.
[0088] In an optional implementation of the second aspect of the present invention, the capacity expansion module includes:
[0089] A first difference calculation unit, configured to obtain a first difference between a data writing speed and a data fetching speed of the annular receiving buffer when the remaining capacity is less than a preset unit capacity value;
[0090] an expansion quantity acquisition unit, configured to obtain a target quantity for expanding the unit capacity value based on a comparison between the first difference and the unit capacity value;
[0091] a moving distance obtaining unit, configured to obtain a moving distance of the head pointer based on the target quantity;
[0092] The address moving unit adjusts the address of the head pointer in the ring receiving buffer based on the moving distance.
[0093] In an optional implementation of the second aspect of the present invention, the critical judgment module includes:
[0094] an expanded address acquisition unit, used to acquire a third data address of the head pointer after capacity expansion;
[0095] A second address distance calculation unit, configured to perform pointer distance calculation on the third data address and the initial data address of the tail pointer to obtain a current total capacity value of the ring receiving buffer;
[0096] A critical value acquisition unit, configured to obtain a critical value based on multiplying the maximum capacity value of the annular receiving buffer by a preset safety index;
[0097] The comparing unit is used to compare the current total capacity value of the annular receiving buffer with the critical value to determine whether the current total capacity value of the annular receiving buffer is greater than the critical value.
[0098] In an optional implementation of the second aspect of the present invention, the data transmission system further includes:
[0099] An interrupt thread wake-up module, used for enabling a preset USB interrupt thread in response to the generation of the alarm information;
[0100] A condition judgment module, used for judging the preset interrupt condition of the ring receiving buffer through the USB interrupt thread;
[0101] The transmission closing module is used to control the annular receiving buffer to stop data transmission when the annular receiving buffer meets the interrupt condition.
[0102] Figure 6 1 is a schematic diagram of the structure of a data transmission device for reducing the packet loss rate of data transmission of a USB virtual serial port provided by an embodiment of the present invention. The data transmission device for reducing the packet loss rate of data transmission of a USB virtual serial port may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 70 (for example, one or more processors) and a memory 80, and one or more storage media 100 for storing application programs 90 or data (for example, one or more mass storage devices). Among them, the memory and the storage medium may be short-term storage or permanent storage. The program stored in the storage medium may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the data transmission device for reducing the packet loss rate of data transmission of a USB virtual serial port. Furthermore, the processor may be configured to communicate with the storage medium and execute a series of instruction operations in the storage medium on the data transmission device for reducing the packet loss rate of data transmission of a USB virtual serial port.
[0103] The data transmission device for reducing the packet loss rate of USB virtual serial port data transmission of the present invention may also include one or more power supplies 110, one or more wired or wireless network interfaces 120, one or more input and output interfaces 130, and / or one or more operating systems 140, such as Windows Serve, Mac OS X, Unix, Linux, FreeBSD, etc. It can be understood by those skilled in the art that Figure 6 The data transmission device structure for reducing the USB virtual serial port data transmission packet loss rate shown does not constitute a limitation on the data transmission device based on reducing the USB virtual serial port data transmission packet loss rate, and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.
[0104] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the method for reducing the packet loss rate of USB virtual serial port data transmission.
[0105] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0106] In addition, although each operation is described in a specific order, this should be understood as requiring such operation to be performed in the specific order shown or in a sequential order, or requiring that all illustrated operations should be performed to obtain desired results. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single implementation in combination. On the contrary, the various features described in the context of a single implementation can also be implemented in multiple implementations individually or in any suitable sub-combination mode.
[0107] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A method for reducing the packet loss rate of USB virtual serial port data transmission, characterized in that: include: Set up a circular receive buffer for the USB virtual serial port; The annular receiving buffer receives initial data with a default capacity value; Real-time monitoring of the remaining capacity of the annular receiving buffer under the default capacity value state; When the remaining capacity is less than a preset unit capacity value, dynamically increasing the expansion capacity of the ring receiving buffer by a number of the unit capacity values from the redundant capacity of the ring receiving buffer; In response to each expansion of the capacity of the annular receiving buffer, determining whether a current total capacity value of the annular receiving buffer is greater than a critical value; When the current total capacity value of the annular receiving buffer is greater than the critical value, an alarm message is generated to prompt the user to modify the parameters of the annular receiving buffer by using macro definition through the alarm message.
2. The method for reducing the packet loss rate of USB virtual serial port data transmission according to claim 1, characterized in that: The setting of a ring receiving buffer for the USB virtual serial port includes: Allocate a circular receiving buffer for the USB virtual serial port through a kernel parameter configuration command, and configure a default capacity value and a maximum capacity value of the circular receiving buffer, wherein the circular receiving buffer is composed of a plurality of unit capacity spaces of equal sectors; A dynamic capacity matching rule of the annular receiving buffer is set, and a parameter adjustment mode of the annular receiving buffer is configured as a macro definition.
3. The method for reducing the packet loss rate of USB virtual serial port data transmission according to claim 1, characterized in that: The initial data reception of the annular receiving buffer with a default capacity value comprises: Setting a head pointer and a tail pointer in the default capacity value interval of the annular receiving buffer, and specifying the tail pointer to guide the writing position of data each time; Each time the data is written into the circular receive buffer based on the tail pointer, the tail pointer moves toward the head pointer by a distance of the unit capacity value.
4. The method for reducing the packet loss rate of USB virtual serial port data transmission according to claim 3, characterized in that: The real-time monitoring of the remaining capacity of the annular receiving buffer under the default capacity value state includes: In response to each writing of the data, obtaining a current first data address of the head pointer and a current second data address of the tail pointer; Perform pointer distance calculation on the first data address and the second data address to obtain the remaining capacity of the ring receiving buffer.
5. The method for reducing the packet loss rate of USB virtual serial port data transmission according to claim 4, characterized in that: When the remaining capacity is less than the preset unit capacity value, dynamically increasing the expansion capacity of the ring receiving buffer by a number of the unit capacity values from the redundant capacity of the ring receiving buffer includes: When the remaining capacity is less than a preset unit capacity value, obtaining a first difference between a data writing speed and a data fetching speed of the annular receiving buffer; Based on the comparison between the first difference and the unit capacity value, a target amount for expanding the unit capacity value is obtained; Obtaining a moving distance of the head pointer based on the target quantity; The address of the head pointer in the ring receive buffer is adjusted based on the moving distance.
6. The method for reducing the packet loss rate of USB virtual serial port data transmission according to claim 5, characterized in that: In response to each expansion of the capacity of the annular receiving buffer, determining whether the current total capacity value of the annular receiving buffer is greater than a critical value comprises: Acquire the third data address of the head pointer after capacity expansion; Performing pointer distance calculation on the third data address and the initial data address of the tail pointer to obtain a current total capacity value of the annular receiving buffer; Obtain a critical value based on multiplying the maximum capacity value of the annular receiving buffer by a preset safety index; The current total capacity value of the annular receiving buffer is compared with the critical value to determine whether the current total capacity value of the annular receiving buffer is greater than the critical value.
7. The method for reducing the packet loss rate of USB virtual serial port data transmission according to claim 1, characterized in that: When the current total capacity value of the annular receiving buffer is greater than the critical value, generating the alarm information further includes: In response to the generation of the alarm information, enabling a preset USB interrupt thread; The USB interrupt thread is used to determine the preset interrupt condition of the annular receiving buffer; When the annular receiving buffer satisfies the interrupt condition, the annular receiving buffer is controlled to stop data transmission.
8. A data transmission system for reducing the packet loss rate of USB virtual serial port data transmission, characterized in that: The data transmission system comprises: The buffer setting module is used to set a circular receiving buffer for the USB virtual serial port; An initial receiving module, used for receiving initial data in the annular receiving buffer with a default capacity value; A capacity monitoring module, used for real-time monitoring of the remaining capacity of the annular receiving buffer under the default capacity value state; A capacity expansion module, configured to dynamically increase the expansion capacity of the ring receiving buffer by a number of the unit capacity values from the redundant capacity of the ring receiving buffer when the remaining capacity is less than a preset unit capacity value; A critical judgment module, configured to judge whether a current total capacity value of the annular receiving buffer is greater than a critical value in response to each expansion of the capacity of the annular receiving buffer; The reminder module is used to generate an alarm message when the current total capacity value of the annular receiving buffer is greater than the critical value, so as to prompt the user to modify the parameters of the annular receiving buffer by using the macro definition through the alarm message.
9. A data transmission device for reducing the packet loss rate of USB virtual serial port data transmission, characterized in that: The data transmission device for reducing the packet loss rate of USB virtual serial port data transmission comprises: a memory and at least one processor, the memory stores instructions, and the memory and the at least one processor are interconnected via a line; The at least one processor calls the instruction in the memory to enable the data transmission device for reducing the packet loss rate of USB virtual serial port data transmission to execute the method for reducing the packet loss rate of USB virtual serial port data transmission according to any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for reducing the packet loss rate of USB virtual serial port data transmission according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Parallel redundancy Ethernet receiving and processing method based on annular sliding window algorithm and related equipment
CN121644016A
Event ring adaptive pre-extension method and device, electronic equipment and storage medium
CN122387695A