Movatterモバイル変換


[0]ホーム

URL:


CN115617725A - A data transmission method, a first terminal, a second terminal and a storage medium - Google Patents

A data transmission method, a first terminal, a second terminal and a storage medium
Download PDF

Info

Publication number
CN115617725A
CN115617725ACN202110797654.1ACN202110797654ACN115617725ACN 115617725 ACN115617725 ACN 115617725ACN 202110797654 ACN202110797654 ACN 202110797654ACN 115617725 ACN115617725 ACN 115617725A
Authority
CN
China
Prior art keywords
sending
terminal
receiving
endpoint
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110797654.1A
Other languages
Chinese (zh)
Inventor
马迎斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Oppo Mobile Telecommunications Corp Ltd
Original Assignee
Guangdong Oppo Mobile Telecommunications Corp Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangdong Oppo Mobile Telecommunications Corp LtdfiledCriticalGuangdong Oppo Mobile Telecommunications Corp Ltd
Priority to CN202110797654.1ApriorityCriticalpatent/CN115617725A/en
Publication of CN115617725ApublicationCriticalpatent/CN115617725A/en
Pendinglegal-statusCriticalCurrent

Links

Images

Classifications

Landscapes

Abstract

The embodiment of the application discloses a data transmission method, a first terminal, a second terminal and a storage medium, wherein the method applied to the first terminal comprises the following steps: establishing a data transmission interface based on a Universal Serial Bus (USB) protocol; the data transmission interface comprises a sending endpoint used for transmitting data; under the condition that target data to be transmitted are obtained, a sending thread configured for a sending end point is obtained, a storage function is called by the sending thread, and the target data are stored in a first preset buffer area; calling a write-in function by using a sending thread, and writing target data in a first preset buffer area into a sending endpoint; and transmitting the target data to the second terminal in real time by utilizing the sending end point.

Description

Translated fromChinese
一种数据传输方法、第一终端、第二终端及存储介质A data transmission method, a first terminal, a second terminal and a storage medium

技术领域technical field

本申请实施例涉及通信技术领域,尤其涉及一种数据传输方法、第一终端、第二终端及存储介质。The embodiments of the present application relate to the field of communication technologies, and in particular, to a data transmission method, a first terminal, a second terminal, and a storage medium.

背景技术Background technique

目前,手机与计算机间的数据传输方案,主要分为两种:有线传输和无线传输。At present, data transmission schemes between mobile phones and computers are mainly divided into two types: wired transmission and wireless transmission.

有线传输,具体可以使用通用串行总线(Universal Serial Bus,USB)接口,手机基本都包含USB接口,计算机只需安装USB设备驱动,两端即可通信,该传输方式数据传输比较稳定。For wired transmission, you can specifically use a Universal Serial Bus (USB) interface. Mobile phones basically include a USB interface. The computer only needs to install the USB device driver, and the two ends can communicate. This transmission method is relatively stable in data transmission.

对于USB连接的调试桥传输方式,是以文件为单位的传输,通过命令改变文件路径从而进行文件传输,在需要实时传输数据并解析的场景下无法满足需求,且传输接收端进行文件接收的速率有限。For the debug bridge transmission mode connected by USB, the transmission is based on the file as the unit, and the file path is changed through the command to perform file transmission. In the scene where real-time data transmission and analysis are required, it cannot meet the demand, and the transmission receiving end can receive the file. The rate limited.

发明内容Contents of the invention

本申请实施例提供一种数据传输方法、第一终端、第二终端及存储介质,提高了USB数据传输的速率,且支持数据实时传输,具备实时性。Embodiments of the present application provide a data transmission method, a first terminal, a second terminal, and a storage medium, which improve the rate of USB data transmission, and support real-time data transmission with real-time performance.

本申请实施例的技术方案是这样实现的:The technical scheme of the embodiment of the application is realized in this way:

本申请实施例提供了一种数据传输方法,应用于第一终端,包括:An embodiment of the present application provides a data transmission method applied to a first terminal, including:

创建基于通用串行总线USB协议的数据传输接口;所述数据传输接口包括用于传输数据的发送端点;Create a data transmission interface based on the Universal Serial Bus USB protocol; the data transmission interface includes a sending endpoint for transmitting data;

在获取到待传输的目标数据的情况下,获取为所述发送端点配置的发送线程,并利用所述发送线程调用存储函数,将所述目标数据存储到第一预设缓冲区;When the target data to be transmitted is obtained, obtain a sending thread configured for the sending endpoint, and use the sending thread to call a storage function to store the target data in a first preset buffer;

利用所述发送线程调用写入函数,将所述第一预设缓冲区中所述目标数据写入所述发送端点;Using the sending thread to call a write function to write the target data in the first preset buffer into the sending endpoint;

利用所述发送端点,将所述目标数据实时传输至第二终端。Using the sending endpoint, the target data is transmitted to the second terminal in real time.

在上述方法中,所述数据传输接口还包括:用于传输控制信息的收发端点,以及用于接收数据的接收端点,所述创建基于通用串行总线USB协议的数据传输接口,包括:In the above method, the data transmission interface further includes: a sending and receiving endpoint for transmitting control information, and a receiving endpoint for receiving data, and the creation of a data transmission interface based on the Universal Serial Bus USB protocol includes:

创建收发端点,并获取为所述收发端点配置的收发线程;Create a sending and receiving endpoint, and obtain the sending and receiving thread configured for the sending and receiving endpoint;

利用所述收发线程将USB描述符写入所述收发端点;Write the USB descriptor into the transceiver endpoint by using the transceiver thread;

在所述收发端点写入所述USB描述符的情况下,自动生成所述发送端点,以及用于接收数据的接收端点。When the sending and receiving endpoint writes the USB descriptor, the sending endpoint and the receiving endpoint for receiving data are automatically generated.

在上述方法中,所述利用所述发送线程调用写入函数,将所述第一预设缓冲区中所述目标数据写入所述发送端点之前,所述方法还包括:In the above method, before using the sending thread to call the writing function and writing the target data in the first preset buffer to the sending endpoint, the method further includes:

向发送队列中插入所述目标数据的发送请求;所述发送请求中包括所述第一预设缓冲区的地址信息;inserting a sending request of the target data into the sending queue; the sending request includes address information of the first preset buffer;

相应的,所述利用所述发送线程调用写入函数,将所述第一预设缓冲区中所述目标数据写入所述发送端点,包括:Correspondingly, using the sending thread to call the write function to write the target data in the first preset buffer into the sending endpoint includes:

在依次循环处理到所述发送队列中的所述发送请求的情况下,利用所述发送线程,从所述发送请求中获取所述第一预设缓冲区的地址信息;In the case of sequentially processing the sending requests in the sending queue in turn, using the sending thread to obtain address information of the first preset buffer from the sending requests;

利用所述发送线程,根据所述第一预设缓冲区的地址信息查询到所述第一预设缓冲区,并将所述第一预设缓冲区中所述目标数据写入所述发送端点。Using the sending thread to query the first preset buffer according to the address information of the first preset buffer, and write the target data in the first preset buffer into the sending endpoint .

在上述方法中,还包括:In the above method, also include:

在所述接收端点接收到所述第二终端传输的配置命令的情况下,获取为所述接收线程配置的接收线程,并利用所述接收线程调用读取函数,将所述接收端点中所述配置命令读取到第二预设缓冲区;When the receiving end point receives the configuration command transmitted by the second terminal, obtain the receiving thread configured for the receiving thread, and use the receiving thread to call the read function, and the receiving end point in the The configuration command is read into the second preset buffer;

利用所述接收线程调用解析函数,从所述第二预设缓冲区中解析出所述配置命令进行响应。Using the receiving thread to invoke a parsing function to parse out the configuration command from the second preset buffer to respond.

在上述方法中,所述利用所述接收线程调用解析函数,从所述第二预设缓冲区中解析出所述配置命令进行响应之前,所述方法还包括:In the above method, before using the receiving thread to call the parsing function, parsing the configuration command from the second preset buffer to respond, the method further includes:

向接收队列中插入所述配置命令的接收请求;所述接收请求中包括所述第二预设缓冲区的地址信息;Inserting a receiving request of the configuration command into the receiving queue; the receiving request includes address information of the second preset buffer;

相应的,所述利用所述接收线程调用解析函数,从所述第二预设缓冲区中解析出所述配置命令进行响应,包括:Correspondingly, using the receiving thread to call the parsing function, parsing the configuration command from the second preset buffer to respond, includes:

在依次循环处理到所述接收队列中的所述接收请求的情况下,利用所述接收线程,从所述接收请求中获取所述第二预设缓冲区的地址信息;In the case of sequentially processing the receiving requests in the receiving queue in a loop, using the receiving thread to obtain address information of the second preset buffer from the receiving requests;

利用所述接收线程调用所述解析函数,根据所述第二预设缓冲区的地址信息查询到所述第二预设缓冲区,并从所述第一预设缓冲区解析出所述配置命令进行响应。Use the receiving thread to call the parsing function, query the second preset buffer according to the address information of the second preset buffer, and parse the configuration command from the first preset buffer to respond.

在上述方法中,还包括:In the above method, also include:

在每次与所述第二终端进行数据传输之前,向所述第二终端发起身份校验;Initiating identity verification to the second terminal before each data transmission with the second terminal;

在对所述第二终端的身份校验通过的情况下,与所述第二终端进行数据传输。If the identity verification of the second terminal is passed, data transmission is performed with the second terminal.

本申请实施例提供了一种数据传输方法,应用于第二终端,包括:An embodiment of the present application provides a data transmission method applied to a second terminal, including:

在第一终端向所述第二终端发起数据传输的情况下,采用异步传输方式,接收所述第一终端利用数据传输接口的发送端点传输的目标数据。When the first terminal initiates data transmission to the second terminal, an asynchronous transmission mode is used to receive the target data transmitted by the first terminal using the sending endpoint of the data transmission interface.

在上述方法中,所述采用所述异步传输方式,接收所述第一终端利用数据传输接口的发送端点传输的目标数据,包括:In the above method, using the asynchronous transmission method to receive the target data transmitted by the first terminal using the sending endpoint of the data transmission interface includes:

创建多个传输任务;Create multiple transfer tasks;

执行所述多个传输任务,进行所述目标数据的接收;Executing the multiple transmission tasks to receive the target data;

针对所述多个传输任务中的每个传输任务,在任务结束时,重新激活并再次承接数据接收工作,直至完成所述目标数据的接收。For each transmission task in the plurality of transmission tasks, when the task ends, reactivate and undertake the data receiving work again until the receiving of the target data is completed.

本申请实施例提供了一种第一终端,包括:The embodiment of this application provides a first terminal, including:

接口创建模块,用于创建基于通用串行总线USB协议的数据传输接口;所述数据传输接口包括用于传输数据的发送端点;An interface creation module is used to create a data transmission interface based on the Universal Serial Bus USB protocol; the data transmission interface includes a sending endpoint for transmitting data;

第一通信模块,用于在获取到待传输的目标数据的情况下,获取为所述发送端点配置的发送线程,并利用所述发送线程调用存储函数,将所述目标数据存储到第一预设缓冲区;利用所述发送线程调用写入函数,将所述第一预设缓冲区中所述目标数据写入所述发送端点;利用所述发送端点,将所述目标数据实时传输至第二终端。The first communication module is configured to obtain the sending thread configured for the sending endpoint when the target data to be transmitted is obtained, and use the sending thread to call a storage function to store the target data in the first preset Set up a buffer; use the sending thread to call a write function, write the target data in the first preset buffer into the sending endpoint; use the sending endpoint to transmit the target data to the first preset buffer in real time Two terminals.

本申请实施例提供了一种第二终端,包括:The embodiment of this application provides a second terminal, including:

第二通信模块,用于在第一终端向所述第二终端发起数据传输的情况下,采用异步传输方式,接收所述第一终端利用数据传输接口的发送端点传输的目标数据。The second communication module is configured to receive the target data transmitted by the first terminal using the sending endpoint of the data transmission interface in an asynchronous transmission mode when the first terminal initiates data transmission to the second terminal.

本申请实施例提供了一种第一终端,包括:第一处理器、第一存储器和第一通信总线;An embodiment of the present application provides a first terminal, including: a first processor, a first memory, and a first communication bus;

所述第一通信总线,用于实现所述第一处理器和所述第一存储器之间的通信连接;The first communication bus is used to realize the communication connection between the first processor and the first memory;

所述第一处理器,用于执行所述第一存储器存储的一个或多个程序,以实现上述应用于第一终端的数据传输方法。The first processor is configured to execute one or more programs stored in the first memory, so as to implement the above data transmission method applied to the first terminal.

本申请实施例提供了一种第二终端,包括:第二处理器、第二存储器和第二通信总线;An embodiment of the present application provides a second terminal, including: a second processor, a second memory, and a second communication bus;

所述第二通信总线,用于实现所述第二处理器和所述第二存储器之间的通信连接;The second communication bus is used to realize the communication connection between the second processor and the second memory;

所述第二处理器,用于执行所述第二存储器存储的一个或多个程序,以实现上述应用于第二终端的数据传输方法。The second processor is configured to execute one or more programs stored in the second memory, so as to implement the above data transmission method applied to the second terminal.

本申请实施例提供了一种计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现上述数据传输方法。An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the foregoing data transmission method is implemented.

本申请实施例提供了一种数据传输方法、第一终端、第二终端及存储介质,应用于第一终端的方法包括:创建基于通用串行总线USB协议的数据传输接口;数据传输接口包括用于传输数据的发送端点;在获取到待传输的目标数据的情况下,获取为发送端点配置的发送线程,并利用发送线程调用存储函数,将目标数据存储到第一预设缓冲区;利用发送线程调用写入函数,将第一预设缓冲区中目标数据写入发送端点;利用发送端点,将目标数据实时传输至第二终端。本申请实施例提供的技术方案,提高了USB数据传输的速率,且支持数据实时传输,具备实时性。An embodiment of the present application provides a data transmission method, a first terminal, a second terminal, and a storage medium. The method applied to the first terminal includes: creating a data transmission interface based on the Universal Serial Bus (USB) protocol; the data transmission interface includes The sending endpoint of the transmitted data; in the case of obtaining the target data to be transmitted, obtain the sending thread configured for the sending endpoint, and use the sending thread to call the storage function to store the target data in the first preset buffer; use the sending The thread calls the writing function to write the target data in the first preset buffer into the sending endpoint; the sending endpoint is used to transmit the target data to the second terminal in real time. The technical solution provided by the embodiment of the present application improves the rate of USB data transmission, and supports real-time data transmission, and has real-time performance.

附图说明Description of drawings

图1为本申请实施例提供的一种数据传输方法的流程示意图一;FIG. 1 is a first schematic flow diagram of a data transmission method provided by an embodiment of the present application;

图2为本申请实施例提供的一种数据传输方法的流程示意图二;FIG. 2 is a second schematic flow diagram of a data transmission method provided by an embodiment of the present application;

图3为本申请实施例提供的一种示例性的线程执行示意图;FIG. 3 is a schematic diagram of an exemplary thread execution provided by an embodiment of the present application;

图4为本申请实施例提供的一种数据传输方法的流程示意图三;FIG. 4 is a third schematic flow diagram of a data transmission method provided by an embodiment of the present application;

图5为本申请实施例提供的一种示例性的传输任务实现示意图;FIG. 5 is a schematic diagram of an exemplary implementation of a transmission task provided by an embodiment of the present application;

图6为本申请实施例提供的一种第一终端的结构示意图一;FIG. 6 is a first structural schematic diagram of a first terminal provided by an embodiment of the present application;

图7为本申请实施例提供的一种第一终端的结构示意图二;FIG. 7 is a second structural schematic diagram of a first terminal provided in an embodiment of the present application;

图8为本申请实施例提供的一种第二终端的结构示意图一;FIG. 8 is a first structural schematic diagram of a second terminal provided by an embodiment of the present application;

图9为本申请实施例提供的一种第二终端的结构示意图二。FIG. 9 is a second structural schematic diagram of a second terminal provided in an embodiment of the present application.

具体实施方式detailed description

为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。In order to make the purpose, technical solution and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain the present application, and are not intended to limit the present application.

下面将通过实施例并结合附图具体地对本申请的技术方案以及本申请的技术方案如何解决上述技术问题进行详细说明。下面的实施例可以相互结合,对于相同或相似的概念或过程可能在某些实施例中不再赘述。The technical solution of the present application and how the technical solution of the present application solves the above technical problems will be described in detail below through embodiments and in conjunction with the accompanying drawings. The following embodiments may be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.

另外,本申请实施例所记载的技术方案之间,在不冲突的情况下,可以任意组合。In addition, the technical solutions described in the embodiments of the present application may be combined arbitrarily if there is no conflict.

本申请实施例提供了一种数据传输方法,应用于第一终端和第二终端之间的数据传输。其中,第一终端具体可以是Android系统的手机,其作为USB从设备,第二终端具体可以是Windows系统或Linux系统的计算机,其作为USB主设备。An embodiment of the present application provides a data transmission method, which is applied to data transmission between a first terminal and a second terminal. Wherein, the first terminal may specifically be a mobile phone with an Android system, which acts as a USB slave device, and the second terminal may specifically be a computer with a Windows system or a Linux system, which acts as a USB master device.

需要说明的是,USB主设备对USB系统进行管理、每毫秒产生一帧数据、发送配置请求对USB从设备进行配置、管理和恢复总线上的错误。通用串行总线集线器(UniversalSerialBus Hub,USB HUB)用于设备扩展连接,所有USB从设备都连接在USB HUB的端口上,USB从设备接收USB总线上的所有数据包,通过数据包的地址域来判断是不是发给自己的数据包,若地址不符,则丢弃该数据包,若地址相符,则通过响应USB主设备的数据包与USB主设备进行数据传输。It should be noted that the USB master device manages the USB system, generates a frame of data every millisecond, sends configuration requests to configure the USB slave device, manages and recovers errors on the bus. The universal serial bus hub (UniversalSerialBus Hub, USB HUB) is used for device expansion connection. All USB slave devices are connected to the port of USB HUB. Judging whether it is a data packet sent to oneself, if the address does not match, the data packet is discarded, and if the address matches, data transmission is performed with the USB master device by responding to the data packet of the USB master device.

需要说明的是,USB主设备和USB从设备之间遵循主从通信的原理,每一次的数据传输都是USB主设备发起。如果USB主设备要输出数据,则先发一个握手包,通知USB从设备,然后发送数据,USB从设备接收到数据后,再发送一个确认包。如果USB主设备要输入数据,也是先发一个握手包,通知USB从设备,USB从设备然后将准备好的数据发送给USB主设备,USB主设备再给USB从设备一个确认包。It should be noted that the principle of master-slave communication is followed between the USB master device and the USB slave device, and each data transmission is initiated by the USB master device. If the USB master device wants to output data, it first sends a handshake packet to notify the USB slave device, and then sends data. After the USB slave device receives the data, it sends a confirmation packet. If the USB master device wants to input data, it also sends a handshake packet first to notify the USB slave device, and the USB slave device then sends the prepared data to the USB master device, and the USB master device sends a confirmation packet to the USB slave device.

以下将分别对第一终端和第二终端执行的数据传输方法进行详述。The data transmission methods performed by the first terminal and the second terminal will be described in detail below respectively.

图1为本申请实施例提供的一种数据传输方法的流程示意图一。如图1所示,应用于第一终端的数据传输方法主要包括以下步骤:FIG. 1 is a first schematic flowchart of a data transmission method provided by an embodiment of the present application. As shown in Figure 1, the data transmission method applied to the first terminal mainly includes the following steps:

S101、创建基于通用串行总线USB协议的数据传输接口;数据传输接口包括用于传输数据的发送端点。S101. Create a data transmission interface based on the Universal Serial Bus (USB) protocol; the data transmission interface includes a sending endpoint for transmitting data.

在本申请的实施例中,第一终端可以先创建基于USB协议的数据传输接口,在该数据传输接口中,包括用于传输数据的发送端点。In the embodiment of the present application, the first terminal may first create a data transmission interface based on the USB protocol, and the data transmission interface includes a sending endpoint for transmitting data.

需要说明的是,在本申请的实施例中,第一终端可以创建基于USB协议的用于数据传输的数据传输接口,在该数据传输接口中,不仅包括上述发送端点,可以实现将数据传输至第二终端,还包括用于传输控制信息的收发端点,以及用于接收数据的接收端点。It should be noted that, in the embodiment of the present application, the first terminal can create a data transmission interface for data transmission based on the USB protocol. In this data transmission interface, not only the above-mentioned sending endpoints are included, but data can be transmitted to The second terminal also includes a sending and receiving endpoint for transmitting control information, and a receiving endpoint for receiving data.

具体的,在本申请的实施例中,第一终端创建基于USB协议的数据传输接口,包括:创建收发端点,并利用收发线程将USB描述符写入所述收发端点;在所述收发端点写入所述USB描述符的情况下,自动生成所述发送端点,以及用于接收数据的接收端点。Specifically, in an embodiment of the present application, the first terminal creates a data transmission interface based on the USB protocol, including: creating a sending and receiving endpoint, and using a sending and receiving thread to write a USB descriptor into the sending and receiving endpoint; In the case of entering the USB descriptor, the sending endpoint and the receiving endpoint for receiving data are automatically generated.

需要说明的是,在本申请的实施例中,收发端点对应的数据传输方向为双向,即通过收发端点,既可以实现第一终端向第二终端发送数据,也可以实现第一终端接收第二终端发送的数据,具体的,收发端点主要用于传输控制信息。接收端点,对应的数据传输方向为第二终端向第一终端,即用于实现第一终端接收第二终端发送的数据,具体的,接收端点主要用于传输第二终端的配置命令,配置命令如可以开始或停止数据传输。发送端点,对应的数据传输方向为第一终端向第二终端,即用于实现第一终端向第二终端发送数据,具体的,发送端点主要用于传输第一终端的实时数据。It should be noted that, in the embodiment of this application, the data transmission direction corresponding to the sending and receiving endpoints is bidirectional, that is, through the sending and receiving endpoints, the first terminal can send data to the second terminal, and the first terminal can receive the second terminal. The data sent by the terminal, specifically, the sending and receiving endpoints are mainly used to transmit control information. The receiving end point, the corresponding data transmission direction is from the second terminal to the first terminal, which is used to realize the first terminal receiving the data sent by the second terminal. Specifically, the receiving end point is mainly used to transmit the configuration command of the second terminal, the configuration command Such as data transmission can be started or stopped. The sending endpoint corresponds to the data transmission direction from the first terminal to the second terminal, that is, it is used to realize the sending of data from the first terminal to the second terminal. Specifically, the sending endpoint is mainly used to transmit real-time data of the first terminal.

需要说明的是,Gadget文件系统在Linux内核被引入支持,可以在用户空间操作gadget驱动。USB gdbget基于内存的文件系统configFs也被Linux内核引入,其支持用户空间级别的应用程序编程接口来创建USB复合设备中任意函数或配置的创建。以文件系统的接口来操作gadget。调试桥都是常见的使用gadget configFS的例子。It should be noted that the Gadget file system is introduced and supported in the Linux kernel, and the gadget driver can be operated in the user space. USB gdbget's memory-based file system configFs is also introduced by the Linux kernel, which supports user-space-level application programming interfaces to create arbitrary functions or configurations in USB composite devices. Use the interface of the file system to operate the gadget. Debug bridges are common examples of using gadget configFS.

需要说明的是,在本申请的实施例中,第一终端可以使用USB gadget configFs来创建数据传输接口需要的函数。在第一终端中已有的gadget实例1中新增数据传输接口,配置数据传输接口。It should be noted that, in the embodiment of the present application, the first terminal may use the USB gadget configFs to create functions required by the data transmission interface. A new data transmission interface is added in the existing gadget instance 1 in the first terminal, and the data transmission interface is configured.

具体的,在本申请的实施例中,第一终端可以在可配置的初始化文件:Init.rc文件中指定开机启动即创建数据传输接口,然后通过设置系统属性sys.usb.transfer为1,来配置新增的数据传输接口,配置工作在传输服务虚拟光驱tansfer_server daemon程序中实现。此外,第一终端也可支持删除数据传输接口的配置,通过设置系统属性sys.usb.transfer为0来删除。Specifically, in the embodiment of the present application, the first terminal can specify in the configurable initialization file: Init. Configure the newly added data transmission interface, and the configuration work is implemented in the transfer service virtual CD-ROM drive tansfer_server daemon program. In addition, the first terminal may also support the deletion of the configuration of the data transfer interface, which is deleted by setting the system property sys.usb.transfer to 0.

需要说明的是,在本申请的实施例中,第一终端进行数据传输接口的创建,主要使用收发线程向收发端点写入USB描述符,包含描述符、端点、传输方式信息等,之后,第一终端将在数据传输接口下自动生成发送端点和接收端点,完成数据传输接口的创建。It should be noted that, in the embodiment of the present application, the first terminal creates the data transmission interface, mainly uses the sending and receiving thread to write the USB descriptor to the sending and receiving endpoint, including the descriptor, endpoint, transmission mode information, etc. After that, the second A terminal will automatically generate a sending endpoint and a receiving endpoint under the data transmission interface to complete the creation of the data transmission interface.

需要说明的是,在本申请的实施例中,上述创建数据传输接口的方式仅为提供的一种可选的方式,当然,第一终端还可以根据自身应用的具体系统类型,或者,其它信息和方式,完成数据传输接口的创建,本申请实施例不作限定。It should be noted that, in the embodiment of this application, the above-mentioned method of creating a data transmission interface is only an optional method provided. Of course, the first terminal can also use the specific system type of its own application, or other information and methods to complete the creation of the data transmission interface, which is not limited in this embodiment of the application.

S102、在获取到待传输的目标数据的情况下,获取为发送端点配置的发送线程,并利用发送线程调用存储函数,将目标数据存储到第一预设缓冲区。S102. When the target data to be transmitted is acquired, acquire a sending thread configured for the sending endpoint, and use the sending thread to call a storage function to store the target data in the first preset buffer.

在本申请的实施例中,第一终端在获取到待传输的目标数据的情况下,可以先利用发送线程调用存储函数,将目标数据存储到第一预设缓冲区。In the embodiment of the present application, when the first terminal acquires the target data to be transmitted, it may first use the sending thread to call the storage function to store the target data in the first preset buffer.

需要说明的是,在本申请的实施例中,在第一终端中,维护有发送线程和接收线程,其中,发送线程是在创建发送端点时为发送端点配置的,接收线程是在创建接收端点时为接收端点配置的。此外,如步骤S101所述,数据传输接口还包括收发端点,相应的,第一终端还为收发端点配置有相应的收发线程。不同端点的线程的配置,实际上是在端点创建时配置的,端点的创建也包括为端点配置相应的线程。通过不同的端点可以维护不同的线程。It should be noted that, in the embodiment of the present application, in the first terminal, a sending thread and a receiving thread are maintained, wherein the sending thread is configured for the sending endpoint when the sending endpoint is created, and the receiving thread is configured when the receiving endpoint is created. configured for the receiving endpoint. In addition, as described in step S101, the data transmission interface further includes a sending and receiving endpoint, and correspondingly, the first terminal is also configured with a corresponding sending and receiving thread for the sending and receiving endpoint. The configuration of threads for different endpoints is actually configured when the endpoint is created, and the creation of the endpoint also includes configuring the corresponding threads for the endpoint. Different threads can be maintained through different endpoints.

需要说明的是,在本申请的实施例中,待传输的目标数据可以是第一终端当前需要传输至第二终端的任意数据,具体的目标数据可以根据实际需求和应用场景确定,本申请实施例不作限定。It should be noted that, in the embodiments of this application, the target data to be transmitted can be any data that the first terminal currently needs to transmit to the second terminal, and the specific target data can be determined according to actual needs and application scenarios. Examples are not limited.

需要说明的是,在本申请的实施例中,发送线程的结构体定义为一个输入(in)指针和一个输出(out)指针,该in指针指向存储函数,具体的存储函数可以为full_in_buf函数,即向缓冲区中填入数据,该out指针指向写入函数,即向发送端点写入数据。It should be noted that, in the embodiment of the present application, the structure of the sending thread is defined as an input (in) pointer and an output (out) pointer, the in pointer points to a storage function, and the specific storage function can be the full_in_buf function, That is, fill data into the buffer, and the out pointer points to the write function, that is, write data to the sending endpoint.

需要说明的是,在本申请的实施例中,第一终端实际上可以维护一个发送缓冲池,在需要传输目标数据时,可以从发送缓冲池中为目标数据分配一个缓冲区,该缓冲区即可确定为第一预设缓冲区。第一终端利用发送线程调用存储函数,即可将目标数据存储到第一预设缓冲区中,等待后续进行数据传输。It should be noted that, in the embodiment of the present application, the first terminal may actually maintain a sending buffer pool, and when it is necessary to transmit target data, it may allocate a buffer for the target data from the sending buffer pool, and the buffer is Can be determined as the first preset buffer. The first terminal uses the sending thread to call the storage function, so as to store the target data in the first preset buffer and wait for subsequent data transmission.

S103、利用发送线程调用写入函数,将第一预设缓冲区中目标数据写入发送端点。S103. Use the sending thread to call the write function, and write the target data in the first preset buffer to the sending endpoint.

在本申请的实施例中,第一终端在将目标数据存储到第一预设缓冲区之后,进一步的,利用发送线程调用写入函数,将第一预设缓冲区中目标数据写入发送端点。In the embodiment of this application, after the first terminal stores the target data in the first preset buffer, it further uses the sending thread to call the write function to write the target data in the first preset buffer to the sending endpoint .

需要说明的是,在本申请的实施例中,发送线程中不仅包括上述存储函数,还包括写入函数,发送线程的out指针指向写入函数,第一终端利用发送线程的out指针就可以实现写入函数的调用。It should be noted that, in the embodiment of the present application, the sending thread not only includes the above-mentioned storage function, but also includes the writing function, and the out pointer of the sending thread points to the writing function, and the first terminal can use the out pointer of the sending thread to realize Write function calls.

需要说明的是,在本申请的实施例中,利用发送线程调用写入函数,将第一预设缓冲区中目标数据写入发送端点之前,还可以执行以下步骤:向发送队列中插入目标数据的发送请求;发送请求中包括第一预设缓冲区的地址信息;相应的,第一终端利用发送线程调用写入函数,将第一预设缓冲区中目标数据写入发送端点,包括:在依次循环处理到发送队列中的发送请求的情况下,利用发送线程,从发送请求中获取第一预设缓冲区的地址信息;利用发送线程,根据第一预设缓冲区的地址信息查询到第一预设缓冲区,并将第一预设缓冲区中目标数据写入发送端点。It should be noted that, in the embodiment of the present application, before writing the target data in the first preset buffer into the sending endpoint by using the sending thread to call the write function, the following steps can also be performed: Insert the target data into the sending queue The sending request; the sending request includes the address information of the first preset buffer; correspondingly, the first terminal uses the sending thread to call the write function, and writes the target data in the first preset buffer into the sending endpoint, including: In the case of sequentially processing the sending requests in the sending queue, use the sending thread to obtain the address information of the first preset buffer from the sending request; use the sending thread to query the first buffer according to the address information of the first preset buffer. A preset buffer, and write the target data in the first preset buffer into the sending endpoint.

可以理解的是,在本申请的实施例中,对于发送线程而言,数据生产者是第一终端的应用,数据消费者为发送线程,为了防止存储当前缓冲区未使用完,开始下次传输时,覆盖缓冲区的内容,引入发送消息队列机制。It can be understood that, in the embodiment of this application, for the sending thread, the data producer is the application of the first terminal, and the data consumer is the sending thread. In order to prevent the storage of the current buffer from being used up, start the next transmission When , overwrite the content of the buffer and introduce the sending message queue mechanism.

需要说明的是,在本申请的实施例中,第一终端需要维护一个发送缓冲池和发送队列。第一终端在启动一次数据发送时,将从发送缓冲池中申请一个缓冲区,然后填充内容,再向发送队列中入队一个发送请求,该发送请求包含申请的缓冲区的地址。发送线程可以从该发送队列中取出当前的发送请求,即得到申请的缓冲区,然后再调用写入函数向发送端点写数据。It should be noted that, in the embodiment of the present application, the first terminal needs to maintain a sending buffer pool and a sending queue. When the first terminal starts a data transmission, it will apply for a buffer from the transmission buffer pool, then fill it with content, and then enqueue a transmission request into the transmission queue, and the transmission request includes the address of the applied buffer. The sending thread can take out the current sending request from the sending queue, that is, get the requested buffer, and then call the write function to write data to the sending endpoint.

需要说明的是,在本申请的实施例中,第一终端当将目标数据写入发送端点之后,可以释放第一预设缓冲区归还给缓冲池。It should be noted that, in the embodiment of the present application, after the first terminal writes the target data into the sending endpoint, it may release the first preset buffer and return it to the buffer pool.

S104、利用发送端点,将目标数据实时传输至第二终端。S104. Using the sending endpoint, transmit the target data to the second terminal in real time.

在本申请的实施例中,第一终端在利用发送线程将目标数据写入发送端点之后,即可利用发送端点,将目标数据实时传输至第二终端。In the embodiment of the present application, after the first terminal uses the sending thread to write the target data into the sending endpoint, it can use the sending endpoint to transmit the target data to the second terminal in real time.

可以理解的是,在本申请的实施例中,第一终端将目标数据写入发送端点,发送端点可以进行数据的发送,因此,可以直接将目标数据实时传输给第二终端,第二终端即可接收到目标数据。It can be understood that, in the embodiment of the present application, the first terminal writes the target data into the sending endpoint, and the sending endpoint can send the data. Therefore, the target data can be directly transmitted to the second terminal in real time, and the second terminal is Target data can be received.

图2为本申请实施例提供的一种数据传输方法的流程示意图二。如图2所示,在本申请的实施例中,第一终端还可以执行以下步骤:FIG. 2 is a second schematic flow diagram of a data transmission method provided by an embodiment of the present application. As shown in Figure 2, in the embodiment of the present application, the first terminal may also perform the following steps:

S201、在接收端点接收到第二终端传输的配置命令的情况下,获取为接收线程配置的接收线程,并利用接收线程调用读取函数,将接收端点中配置命令读取到第二预设缓冲区。S201. When the receiving endpoint receives the configuration command transmitted by the second terminal, obtain the receiving thread configured for the receiving thread, and use the receiving thread to call the read function to read the configuration command in the receiving endpoint to the second preset buffer Area.

在本申请的实施例中,第一终端中数据传输接口的接收端点可以接收第二终端传输的配置命令,从而可以利用接收线程调用读取函数,将配置命令读取到第二预设缓冲区。In the embodiment of this application, the receiving endpoint of the data transmission interface in the first terminal can receive the configuration command transmitted by the second terminal, so that the receiving thread can be used to call the read function to read the configuration command to the second preset buffer .

需要说明的是,在本申请的实施例中,第一终端不仅可以维护一个发送缓冲池,还可以维护一个接收缓冲池,在接收端点接收到第二终端传输的配置命令的情况下,第一终端可以从接收缓冲池中分配一个缓冲区,即第二预设缓冲区,作为读取配置命令的空间。具体的第二预设缓冲区本申请实施例不作限定。It should be noted that, in the embodiment of this application, the first terminal can not only maintain a sending buffer pool, but also maintain a receiving buffer pool. When the receiving end point receives the configuration command transmitted by the second terminal, the first terminal The terminal may allocate a buffer from the receiving buffer pool, that is, the second preset buffer, as a space for reading configuration commands. The specific second preset buffer zone is not limited in this embodiment of the present application.

可以理解的是,在本申请的实施例中,与上述发送线程类似,接收线程的结构体定义为一个in指针和一个out指针,该in指针指向读取函数,具体的读取函数可以为read_wrap函数,即从接收端点读取配置命令,将配置命令读取到缓冲区,该out指针指向解析函数,即解析缓冲区中的配置命令从而进行响应。It can be understood that, in the embodiment of the present application, similar to the above-mentioned sending thread, the structure of the receiving thread is defined as an in pointer and an out pointer, the in pointer points to a read function, and the specific read function can be read_wrap The function reads the configuration command from the receiving endpoint, reads the configuration command into the buffer, and the out pointer points to the parsing function, that is, parses the configuration command in the buffer to respond.

S202、利用接收线程调用解析函数,从第二预设缓冲区中解析出配置命令进行响应。S202. Use the receiving thread to call the parsing function, and parse the configuration command from the second preset buffer to respond.

在本申请的实施例中,第一终端在将接收端点中配置命令读取到第二预设缓冲区之后,即可利用接收线程调用解析函数,从第二预设缓冲区中解析出配置命令进行响应。In the embodiment of this application, after the first terminal reads the configuration command in the receiving endpoint into the second preset buffer, it can use the receiving thread to call the parsing function to parse out the configuration command from the second preset buffer to respond.

需要说明的是,在本申请的实施例中,第一终端利用接收线程调用解析函数,从第二预设缓冲区中解析出配置命令进行响应之前,还可以执行以下步骤:向接收队列中插入配置命令的接收请求;接收请求中包括第二预设缓冲区的地址信息;相应的,第一终端利用接收线程调用解析函数,从第二预设缓冲区中解析出配置命令进行响应,包括:在依次循环处理到接收队列中的接收请求的情况下,利用接收线程,从接收请求中获取第二预设缓冲区的地址信息;利用接收线程调用解析函数,根据第二预设缓冲区的地址信息查询到第二预设缓冲区,并从第一预设缓冲区解析出配置命令进行响应。It should be noted that, in the embodiment of this application, the first terminal uses the receiving thread to call the parsing function, and before parsing the configuration command from the second preset buffer to respond, the following steps can also be performed: Insert the The receiving request of the configuration command; the receiving request includes the address information of the second preset buffer; correspondingly, the first terminal uses the receiving thread to call the parsing function, and parses the configuration command from the second preset buffer to respond, including: In the case of sequentially cyclically processing the receiving requests in the receiving queue, use the receiving thread to obtain the address information of the second preset buffer from the receiving request; use the receiving thread to call the analysis function, according to the address of the second preset buffer The information is queried to the second preset buffer, and the configuration command is parsed from the first preset buffer to respond.

可以理解的是,在本申请的实施例中,对于接收线程而言,数据生产者是接收线程,数据消费者为第一终端上的应用,为了防止当前缓冲区未使用完,开始下次接收时,覆盖之前缓冲区的内容,引入接收消息队列机制。It can be understood that, in the embodiment of this application, for the receiving thread, the data producer is the receiving thread, and the data consumer is the application on the first terminal. In order to prevent the current buffer from being used up, start the next reception When , overwrite the contents of the previous buffer and introduce the receiving message queue mechanism.

需要说明的是,在本申请的实施例中,第一终端需要维护一个接收缓冲池和接收队列。第一终端在启动一次接收时,将从接收缓冲池中申请一个缓冲区,然后拷贝第二终端传输来的配置命令,再向接收队列中入队一个接收请求,该接收请求包含申请缓冲区的地址。接收线程可以从发送队列中取出当前的接收请求,即得到申请的缓冲区,然后再根据缓冲区中的内容进行对应的配置命令处理。It should be noted that, in the embodiment of the present application, the first terminal needs to maintain a receiving buffer pool and a receiving queue. When the first terminal starts a reception, it will apply for a buffer from the receiving buffer pool, then copy the configuration command transmitted by the second terminal, and then enqueue a receiving request to the receiving queue, which includes the request buffer address. The receiving thread can take out the current receiving request from the sending queue, that is, obtain the applied buffer, and then process the corresponding configuration command according to the content in the buffer.

需要说明的是,在本申请的实施例中,第一终端当处理完毕后,可以释放申请的第二预设缓冲区归还给接收缓冲池,即此次接收完毕。It should be noted that, in the embodiment of the present application, after the first terminal finishes processing, it can release the second preset buffer of the application and return it to the receiving buffer pool, that is, the receiving is completed.

需要说明的是,在本申请的实施例中,对于上述数据传输过程,其中涉及到的接收线程和发送线程,都是先使用in指针处理,然后再使用out指针处理。It should be noted that, in the embodiment of the present application, for the above-mentioned data transmission process, the receiving thread and the sending thread involved are first processed using the in pointer, and then processed using the out pointer.

图3为本申请实施例提供的一种示例性的线程执行示意图。如图3所示,目标线程可以为上述接收线程,也可以为上述发送线程,目标线程包括in指针和out指针,在启动目标线程之后,首先目标线程中先使用in指针进行函数处理,之后,再使用out指针进行函数处理。FIG. 3 is a schematic diagram of an exemplary thread execution provided by an embodiment of the present application. As shown in Figure 3, the target thread can be the above-mentioned receiving thread or the above-mentioned sending thread. The target thread includes an in pointer and an out pointer. After starting the target thread, first use the in pointer to perform function processing in the target thread, and then, Then use the out pointer for function processing.

需要说明的是,在本申请的实施例中,第一终端还可以执行以下步骤:在每次与第二终端进行数据传输之前,向第二终端发起身份校验;在对第二终端的身份校验通过的情况下,与第二终端进行数据传输。It should be noted that, in the embodiment of the present application, the first terminal may also perform the following steps: before each data transmission with the second terminal, initiate an identity verification to the second terminal; If the verification is passed, data transmission is performed with the second terminal.

可以理解的是,在本申请的实施例中,对于第一终端与第二终端进行数据传输而言,如果传输的信息是有关用户的隐私数据或者第一终端的控制信息,黑客很容易伪造第二终端获取该数据。所以需要在传输前需要加验证流程,双方进行握手确认身份后再进行传输,每次传输需要进行循环冗余校验,以此来保证传输的安全性。It can be understood that, in the embodiment of the present application, for data transmission between the first terminal and the second terminal, if the transmitted information is private data about the user or control information of the first terminal, it is easy for hackers to forge the second terminal. The second terminal obtains the data. Therefore, it is necessary to add a verification process before the transmission. The two parties shake hands to confirm the identity before the transmission. Each transmission needs to perform a cyclic redundancy check to ensure the security of the transmission.

需要说明的是,在本申请的实施例中,如果由第一终端的第三方应用有实时传输数据至第二终端的需求,传输服务程序可以释放出软件开发工具包接口,使第三方应用接入该接口,即可采用本申请的方案传输数据至第二终端。It should be noted that, in the embodiment of the present application, if the third-party application of the first terminal needs to transmit data to the second terminal in real time, the transmission service program can release the software development kit interface, so that the third-party application can access By entering the interface, the solution of this application can be used to transmit data to the second terminal.

本申请实施例提供了一种数据传输方法,应用于第一终端,包括:创建基于通用串行总线USB协议的数据传输接口;数据传输接口包括用于传输数据的发送端点;在获取到待传输的目标数据的情况下,获取为发送端点配置的发送线程,并利用发送线程调用存储函数,将目标数据存储到第一预设缓冲区;利用发送线程调用写入函数,将第一预设缓冲区中目标数据写入发送端点;利用发送端点,将目标数据实时传输至第二终端。本申请实施例提供的数据传输方法,提高了USB数据传输的速率,且支持数据实时传输,具备实时性。The embodiment of the present application provides a data transmission method, which is applied to the first terminal, including: creating a data transmission interface based on the Universal Serial Bus USB protocol; the data transmission interface includes a sending endpoint for transmitting data; In the case of the target data, obtain the sending thread configured for the sending endpoint, and use the sending thread to call the storage function to store the target data in the first preset buffer; use the sending thread to call the write function to store the first preset buffer The target data in the area is written into the sending endpoint; the sending endpoint is used to transmit the target data to the second terminal in real time. The data transmission method provided by the embodiment of the present application improves the rate of USB data transmission, supports real-time data transmission, and has real-time performance.

图4为本申请实施例提供的一种数据传输方法的流程示意图三。如图4所示,应用于第二终端的数据传输方法主要包括以下步骤:FIG. 4 is a third schematic flowchart of a data transmission method provided by an embodiment of the present application. As shown in Figure 4, the data transmission method applied to the second terminal mainly includes the following steps:

S401、在第一终端向第二终端发起数据传输的情况下,采用异步传输方式,接收第一终端利用数据传输接口的发送端点传输的目标数据。S401. When the first terminal initiates data transmission to the second terminal, use an asynchronous transmission mode to receive target data transmitted by the first terminal using a sending endpoint of a data transmission interface.

在本申请的实施例中,第二终端在第一终端向其发起数据传输的情况下,采用异步传输方式,接收第一终端利用数据传输接口的发送端点传输的目标数据。In the embodiment of the present application, when the first terminal initiates data transmission to it, the second terminal adopts an asynchronous transmission method to receive the target data transmitted by the first terminal using the sending endpoint of the data transmission interface.

需要说明的是,在本申请的实施例中,第二终端可以运行Windows或Linux操作系统,而且第二终端的USB程序可以运行在用户空间,即无需修改内核驱动。内核可以将USB消息转发到用户空间,Libusb为一套完成的USB配置库,可以使用该库根据需求进行定制配置,其提供了基于内核应用程序编程接口的抽象层。It should be noted that, in the embodiment of the present application, the second terminal can run Windows or Linux operating system, and the USB program of the second terminal can run in user space, that is, there is no need to modify the kernel driver. The kernel can forward USB messages to the user space. Libusb is a complete set of USB configuration library, which can be used to customize the configuration according to requirements, and it provides an abstraction layer based on the kernel application programming interface.

需要说明的是,在本申请的实施例中,第二终端基于Libusb支持同步传输方式和异步传输方式,在使用同步传输方式的时候,第二终端基于每次传输等待当前的传输任务完毕后才能重新创建,第一终端发送数据只有在第二终端请求时才进行发送,第二终端只有在传输任务激活时才请求发送数据。如此,当一个传输任务结束后,下一个传输任务未创建和提交前,第一终端无法进行发送数据,即使处于循环中,软件循环处理的耗时,传输任务是没有激活的。因此,简单的对时间要求不是很高的数据传输推荐使用同步传输方式,但是为满足高速率传输,就需要使用异步传输方式。It should be noted that, in the embodiment of the present application, the second terminal supports synchronous transmission mode and asynchronous transmission mode based on Libusb. When using the synchronous transmission mode, the second terminal waits for the completion of the current transmission task based on each transmission. To recreate, the first terminal sends data only when the second terminal requests it, and the second terminal only requests to send data when the transmission task is activated. In this way, when a transmission task ends, the first terminal cannot send data before the next transmission task is created and submitted. Even if it is in a loop, the transmission task is not activated due to the time-consuming software cycle processing. Therefore, it is recommended to use the synchronous transmission method for simple data transmission that is not very demanding on time, but to meet the high-speed transmission, it is necessary to use the asynchronous transmission method.

具体的,在本申请的实施例中,第二终端采用异步传输方式,接收第一终端利用数据传输接口的发送端点传输的目标数据,包括:创建多个传输任务;执行多个传输任务,进行目标数据的接收;针对多个传输任务中的每个传输任务,在任务结束时,重新激活并再次承接数据接收工作,直至完成目标数据的接收。Specifically, in the embodiment of the present application, the second terminal adopts the asynchronous transmission method, and receives the target data transmitted by the first terminal using the sending endpoint of the data transmission interface, including: creating multiple transmission tasks; executing multiple transmission tasks, performing Receiving the target data: For each transmission task in the multiple transmission tasks, when the task ends, reactivate and undertake the data receiving work again until the target data reception is completed.

可以理解的是,在本申请的实施例中,如图5所示,对于第二终端而言,每个传输任务结束,即第一终端向第二终端传输完一次数据。传输任务是用来承载传输数据工作的,传输任务可复用,即初始化时批量创建一批,等待每次传输任务传输数据完毕后,重新激活传输任务即又可承载接收第一终端发送过来的数据工作,从而支持并行传输数据,减少软件处理的延时,提高USB传输的速率。It can be understood that, in the embodiment of the present application, as shown in FIG. 5 , for the second terminal, each transmission task ends, that is, the first terminal completes one data transmission to the second terminal. The transmission task is used to carry the work of transmitting data. The transmission task can be reused, that is, a batch is created in batches during initialization, and after each transmission task completes the data transmission, the transmission task can be reactivated to carry and receive the data sent by the first terminal. Data work, so as to support parallel data transmission, reduce the delay of software processing, and increase the speed of USB transmission.

本申请实施例提供了一种数据传输方法,应用于第二终端,包括:在第一终端向第二终端发起数据传输的情况下,采用异步传输方式,接收第一终端利用数据传输接口的发送端点传输的目标数据。本申请实施例提供的数据传输方法,提高了USB数据传输的速率,且支持数据实时传输,具备实时性。The embodiment of the present application provides a data transmission method, which is applied to the second terminal, including: when the first terminal initiates data transmission to the second terminal, adopting an asynchronous transmission method, and receiving the data sent by the first terminal through the data transmission interface Destination data transmitted by the endpoint. The data transmission method provided by the embodiment of the present application improves the rate of USB data transmission, supports real-time data transmission, and has real-time performance.

本申请实施例提供了一种第一终端。图6为本申请实施例提供的一种第一终端的结构示意图一。如图6所示,在本申请的实施例中,第一终端包括:The embodiment of this application provides a first terminal. FIG. 6 is a first structural schematic diagram of a first terminal provided in an embodiment of the present application. As shown in Figure 6, in the embodiment of the present application, the first terminal includes:

接口创建模块601,用于创建基于通用串行总线USB协议的数据传输接口;所述数据传输接口包括用于传输数据的发送端点;Theinterface creation module 601 is used to create a data transmission interface based on the Universal Serial Bus USB protocol; the data transmission interface includes a sending endpoint for transmitting data;

第一通信模块602,用于在获取到待传输的目标数据的情况下,获取为所述发送端点配置的发送线程,并利用所述发送线程调用存储函数,将所述目标数据存储到第一预设缓冲区;利用所述发送线程调用写入函数,将所述第一预设缓冲区中所述目标数据写入所述发送端点;利用所述发送端点,将所述目标数据实时传输至第二终端。Thefirst communication module 602 is configured to obtain the sending thread configured for the sending endpoint when the target data to be transmitted is obtained, and use the sending thread to call a storage function to store the target data in the first A preset buffer; using the sending thread to call a write function to write the target data in the first preset buffer into the sending endpoint; using the sending endpoint to transmit the target data in real time to second terminal.

在本申请一实施例中,所述数据传输接口还包括:用于传输控制信息的收发端点,以及用于接收数据的接收端点,所述接口创建模块601,具体用于创建收发端点,并获取为所述收发端点配置的收发线程;利用所述收发线程将USB描述符写入所述收发端点;在所述收发端点写入所述USB描述符的情况下,自动生成所述发送端点,以及用于接收数据的接收端点。In an embodiment of the present application, the data transmission interface further includes: a sending and receiving endpoint for transmitting control information, and a receiving endpoint for receiving data, and theinterface creation module 601 is specifically used to create a sending and receiving endpoint, and obtain A sending and receiving thread configured for the sending and receiving endpoint; using the sending and receiving thread to write the USB descriptor into the sending and receiving endpoint; when the sending and receiving endpoint writes the USB descriptor, automatically generating the sending endpoint, and Receive endpoint for receiving data.

在本申请一实施例中,所述第一通信模块602,还用于向发送队列中插入所述目标数据的发送请求;所述发送请求中包括所述第一预设缓冲区的地址信息;In an embodiment of the present application, thefirst communication module 602 is further configured to insert a sending request of the target data into the sending queue; the sending request includes address information of the first preset buffer;

相应的,所述第一通信模块602,具体用于在依次循环处理到所述发送队列中的所述发送请求的情况下,利用所述发送线程,从所述发送请求中获取所述第一预设缓冲区的地址信息;利用所述发送线程,根据所述第一预设缓冲区的地址信息查询到所述第一预设缓冲区,并将所述第一预设缓冲区中所述目标数据写入所述发送端点。Correspondingly, thefirst communication module 602 is specifically configured to use the sending thread to acquire the first The address information of the preset buffer; using the sending thread to query the first preset buffer according to the address information of the first preset buffer, and send the Target data is written to the sending endpoint.

在本申请一实施例中,所述第一通信模块602,还用于在所述接收端点接收到所述第二终端传输的配置命令的情况下,获取为所述接收线程配置的接收线程,并利用所述接收线程调用读取函数,将所述接收端点中所述配置命令读取到第二预设缓冲区;利用所述接收线程调用解析函数,从所述第二预设缓冲区中解析出所述配置命令进行响应。In an embodiment of the present application, thefirst communication module 602 is further configured to acquire a receiving thread configured for the receiving thread when the receiving endpoint receives the configuration command transmitted by the second terminal, And use the receiving thread to call the read function to read the configuration command in the receiving endpoint to the second preset buffer; use the receiving thread to call the parsing function to read the configuration command from the second preset buffer Parse out the configuration command to respond.

在本申请一实施例中,所述第一通信模块602,还用于向接收队列中插入所述配置命令的接收请求;所述接收请求中包括所述第二预设缓冲区的地址信息;In an embodiment of the present application, thefirst communication module 602 is further configured to insert a receiving request of the configuration command into the receiving queue; the receiving request includes address information of the second preset buffer;

相应的,所述第一通信模块602,具体用于在依次循环处理到所述接收队列中的所述接收请求的情况下,利用所述接收线程,从所述接收请求中获取所述第二预设缓冲区的地址信息;利用所述接收线程调用所述解析函数,根据所述第二预设缓冲区的地址信息查询到所述第二预设缓冲区,并从所述第一预设缓冲区解析出所述配置命令进行响应。Correspondingly, thefirst communication module 602 is specifically configured to use the receiving thread to acquire the second The address information of the preset buffer; use the receiving thread to call the parsing function, query the second preset buffer according to the address information of the second preset buffer, and obtain the second preset buffer from the first preset The buffer parses out the configuration command in response.

在本申请一实施例中,所述第一通信模块602,还用于在每次与所述第二终端进行数据传输之前,向所述第二终端发起身份校验;在对所述第二终端的身份校验通过的情况下,与所述第二终端进行数据传输。In an embodiment of the present application, thefirst communication module 602 is further configured to initiate identity verification to the second terminal before each data transmission with the second terminal; When the identity verification of the terminal passes, data transmission is performed with the second terminal.

图7为本申请实施例提供的一种第一终端的结构示意图二。如图7所示,在本申请的实施例中,第一终端包括:第一处理器701、第一存储器702和第一通信总线703;FIG. 7 is a second structural schematic diagram of a first terminal provided in an embodiment of the present application. As shown in FIG. 7, in the embodiment of the present application, the first terminal includes: afirst processor 701, afirst memory 702, and a first communication bus 703;

所述第一通信总线703,用于实现所述第一处理器701和所述第一存储器702之间的通信连接;The first communication bus 703 is configured to realize the communication connection between thefirst processor 701 and thefirst memory 702;

所述第一处理器701,用于执行所述第一存储器702存储的一个或多个程序,以实现上述应用于第一终端的数据传输方法。Thefirst processor 701 is configured to execute one or more programs stored in thefirst memory 702, so as to implement the above data transmission method applied to the first terminal.

本申请实施例还提供了一种第二终端。图8为本申请实施例提供的一种第二终端的结构示意图一。如图8所示,第二终端包括:The embodiment of the present application also provides a second terminal. FIG. 8 is a first structural schematic diagram of a second terminal provided by an embodiment of the present application. As shown in Figure 8, the second terminal includes:

第二通信模块801,用于在第一终端向所述第二终端发起数据传输的情况下,采用异步传输方式,接收所述第一终端利用数据传输接口的发送端点传输的目标数据。Thesecond communication module 801 is configured to receive the target data transmitted by the first terminal using the sending endpoint of the data transmission interface in an asynchronous transmission mode when the first terminal initiates data transmission to the second terminal.

在本申请一实施例中,所述第二通信模块801,具体用于创建多个传输任务;执行所述多个传输任务,进行所述目标数据的接收;针对所述多个传输任务中的每个传输任务,在任务结束时,重新激活并再次承接数据接收工作,直至完成所述目标数据的接收。In an embodiment of the present application, thesecond communication module 801 is specifically configured to create multiple transmission tasks; execute the multiple transmission tasks to receive the target data; Each transmission task is reactivated at the end of the task and undertakes the data receiving work again until the receiving of the target data is completed.

图9为本申请实施例提供的一种第二终端的结构示意图二。如图9所示,第二终端包括:第二处理器901、第二存储器902和第二通信总线903;FIG. 9 is a second structural schematic diagram of a second terminal provided in an embodiment of the present application. As shown in FIG. 9, the second terminal includes: asecond processor 901, asecond memory 902, and a second communication bus 903;

所述第二通信总线903,用于实现所述第二处理器901和所述第二存储器902之间的通信连接;The second communication bus 903 is configured to realize the communication connection between thesecond processor 901 and thesecond memory 902;

所述第二处理器901,用于执行所述第二存储器902存储的一个或多个程序,以实现上述应用于第二终端的数据传输方法。Thesecond processor 901 is configured to execute one or more programs stored in thesecond memory 902, so as to implement the above data transmission method applied to the second terminal.

本申请实施例提供了一种计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现上述数据传输方法。计算机可读存储介质可以是易失性存储器(volatile memory),例如随机存取存储器(Random-Access Memory,RAM);或者非易失性存储器(non-volatile memory),例如只读存储器(Read-Only Memory,ROM),快闪存储器(flash memory),硬盘(Hard Disk Drive,HDD)或固态硬盘(Solid-State Drive,SSD);也可以是包括上述存储器之一或任意组合的各自设备,如移动电话、计算机、平板设备、个人数字助理等。An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the foregoing data transmission method is implemented. The computer-readable storage medium can be a volatile memory (volatile memory), such as a random access memory (Random-Access Memory, RAM); or a non-volatile memory (non-volatile memory), such as a read-only memory (Read-Only Memory). Only Memory, ROM), flash memory (flash memory), hard disk (Hard Disk Drive, HDD) or solid-state drive (Solid-State Drive, SSD); also can be the respective equipment that comprises one of above-mentioned memories or any combination, such as Mobile phones, computers, tablet devices, personal digital assistants, and more.

本领域内的技术人员应明白,本申请的实施例可提供为方法、系统、或计算机程序产品。因此,本申请可采用硬件实施例、软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器和光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art should understand that the embodiments of the present application may be provided as methods, systems, or computer program products. Accordingly, the present application may take the form of a hardware embodiment, a software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) having computer-usable program code embodied therein.

本申请是参照根据本申请实施例的方法、设备(系统)、和计算机程序产品的实现流程示意图和/或方框图来描述的。应理解可由计算机程序指令实现流程示意图和/或方框图中的每一流程和/或方框、以及实现流程示意图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在实现流程示意图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present application is described with reference to the implementation flow diagrams and/or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and/or block in the schematic flowchart and/or block diagram, and a combination of processes and/or blocks in the schematic flowchart and/or block diagram can be realized by computer program instructions. These computer program instructions may be provided to a general purpose computer, special purpose computer, embedded processor, or processor of other programmable data processing equipment to produce a machine such that the instructions executed by the processor of the computer or other programmable data processing equipment produce a Means for realizing the functions specified in one or more steps of the flowchart and/or one or more blocks of the block diagram.

这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在实现流程示意图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture comprising instruction means, the instructions The device realizes the function specified in implementing one or more procedures of the flowchart and/or one or more blocks of the block diagram.

这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在实现流程示意图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded onto a computer or other programmable data processing device, causing a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby The instructions provide steps for implementing the functions specified in implementing the process flow or processes of the flowchart diagrams and/or the block or blocks of the block diagrams.

以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本实用申请揭露的技术范围内,可轻易想到的变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。The above is only the specific implementation of the application, but the scope of protection of the application is not limited thereto, any changes or substitutions that can be easily imagined by any person familiar with the technical field within the technical scope disclosed in this application , should be covered within the protection scope of this application. Therefore, the protection scope of the present application should be determined by the protection scope of the claims.

Claims (13)

CN202110797654.1A2021-07-142021-07-14 A data transmission method, a first terminal, a second terminal and a storage mediumPendingCN115617725A (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202110797654.1ACN115617725A (en)2021-07-142021-07-14 A data transmission method, a first terminal, a second terminal and a storage medium

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202110797654.1ACN115617725A (en)2021-07-142021-07-14 A data transmission method, a first terminal, a second terminal and a storage medium

Publications (1)

Publication NumberPublication Date
CN115617725Atrue CN115617725A (en)2023-01-17

Family

ID=84854487

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202110797654.1APendingCN115617725A (en)2021-07-142021-07-14 A data transmission method, a first terminal, a second terminal and a storage medium

Country Status (1)

CountryLink
CN (1)CN115617725A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN118585345A (en)*2024-08-062024-09-03牛芯半导体(深圳)有限公司 Data interaction method, device, storage medium and electronic device
CN119917338A (en)*2023-10-232025-05-02荣耀终端股份有限公司 Data transmission method, device and storage medium

Cited By (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN119917338A (en)*2023-10-232025-05-02荣耀终端股份有限公司 Data transmission method, device and storage medium
CN118585345A (en)*2024-08-062024-09-03牛芯半导体(深圳)有限公司 Data interaction method, device, storage medium and electronic device
CN118585345B (en)*2024-08-062024-10-22牛芯半导体(深圳)有限公司Data interaction method and device, storage medium and electronic equipment

Similar Documents

PublicationPublication DateTitle
CN106797388B (en)Cross-system multimedia data encoding and decoding method and device, electronic equipment and computer program product
CN111813584A (en) Memory sharing method, device, electronic device and storage medium
CN107783818A (en)Deep learning task processing method, device, equipment and storage medium
CN102053869B (en)Resource allocation method and device for multi-operation system
WO2022193953A1 (en)Memory sharing method and apparatus
CN109033328B (en)Access request processing method, device, equipment and readable storage medium
WO2014071804A1 (en)Data transmission method and device of terminal equipment with android platform
CN106034120B (en)method and system for multi-process access to trusted application
CN109324874B (en) A method, system and device for importing a virtual machine memory snapshot into a block device
CN115617725A (en) A data transmission method, a first terminal, a second terminal and a storage medium
WO2023115852A1 (en)Pcie-based communication method and apparatus, and computer device and readable storage medium
CN116860391A (en)GPU computing power resource scheduling method, device, equipment and medium
CN106850554B (en) Method and device for directional connection of dual systems
CN106569874B (en) Operation method of storage device and physical server
CN107025146B (en) A file generation method, device and system
WO2024093542A1 (en)Usb drive-free communication method and apparatus, and electronic device and storage medium
CN117076409A (en)File sharing method, device, system, electronic equipment and storage medium
CN104714821B (en)Operation system example creation method and device
CN105677456A (en)Process information writing method and user device
CN115617537A (en) A data transmission method and device, storage medium
CN110968383B (en) Display method and device, terminal and storage medium of a message box
WO2015184902A1 (en)Concurrent processing method for intelligent split-screen and corresponding intelligent terminal
CN117311729A (en)System deployment method, device, equipment and machine-readable storage medium
CN113347115B (en)Message processing method and device, electronic equipment and medium
CN111258715B (en)Multi-operating system rendering processing method and device

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination

[8]ページ先頭

©2009-2025 Movatter.jp