Data transmission methods and electronic devices
By breaking down data transmission tasks into atomic tasks and executing them serially within a single transmission thread in electronic devices, the problems of data transmission congestion and high power consumption in resource-constrained devices are solved, achieving more efficient data transmission.
Patent Information
- Application Number
- CN202411999500.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2044-12-31
AI Technical Summary
How to improve the data transmission performance of electronic devices under limited resources, especially for devices with tight memory and CPU resources, and avoid congestion and high power consumption during data transmission.
The method of serial task execution is adopted. By splitting the data transmission process into atomic tasks, each task corresponds to a timer structure, and these tasks are executed sequentially in a single transmission thread. This avoids congestion caused by data concurrency and reduces the number of threads to save system resources.
It effectively reduces the power consumption of electronic devices, reduces the resource consumption of CPU and memory, avoids data transmission congestion, and improves data transmission efficiency.
Smart Images

Figure CN120428815B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminals, and more particularly to a data transmission method and an electronic device. Background Technology
[0002] Electronic devices can transfer data to each other. For example, watches and mobile phones can synchronize sports and health information, calendar information, etc.
[0003] Some electronic devices, such as watches, are constrained by hardware limitations, with limited resources such as memory and central processing unit (CPU). Improving the data transmission performance of these devices under these resource constraints is a problem that needs to be addressed. Summary of the Invention
[0004] This application provides a data transmission method and an electronic device that can reduce resource consumption during data transmission and improve the performance of the electronic device when transmitting data.
[0005] To achieve the above objectives, the embodiments of this application adopt the following technical solutions:
[0006] In a first aspect, a data transmission method is provided, comprising: a transmission module acquiring a timer list; when the timer list includes at least one timer structure, acquiring the timer structure with the shortest timer duration in the timer list, i.e., a first timer structure; wherein, the timer structure includes a timer duration and an operation function, the operation function being used to instruct the electronic device to perform an operation; the transmission module executing the operation corresponding to the operation function in the first timer structure at the time indicated by the timer duration in the first timer structure; the transmission module deleting the first timer structure from the timer list and acquiring an updated timer list; when the updated timer list includes at least one timer structure, acquiring the timer structure with the shortest timer duration in the updated timer list, i.e., a second timer structure; the transmission module executing the operation corresponding to the operation function in the second timer structure at the time indicated by the timer duration in the second timer structure.
[0007] In this method, the transmission module executes tasks serially within a single transmission thread, avoiding data congestion caused by concurrent data transmission of large amounts of data. Furthermore, it reduces the number of threads running on the electronic device, saving system resources and reducing power consumption.
[0008] In conjunction with the first aspect, in one possible implementation, before the transmission module obtains the timer list, the service module creates a first timer structure and adds the first timer structure to the timer list; or, the connection networking module creates a first timer structure and adds the first timer structure to the timer list; or, the transmission module creates a first timer structure and adds the first timer structure to the timer list.
[0009] In this method, the tasks of the business module, the connection networking module, or the transmission module are all broken down into atomic tasks. Each atomic task takes a very short time and can be completed within a single transmission thread.
[0010] In conjunction with the first aspect, in one possible implementation, if the timer list does not exist or the timer list does not contain a timer structure before the first timer structure is added, the electronic device starts the transmission thread of the transmission module. When the updated timer list does not include a timer structure, the transmission thread of the transmission module is shut down.
[0011] In this method, after each execution of the operation function in the timer structure, the transmission module removes the timer structure from the timer list. The transmission module checks the number of timer structures in the timer list; if it determines that no timer structure exists in the list, it shuts down the transmission thread. Compared to the transmission thread going to sleep, shutting down the transmission thread removes it from memory, further conserving CPU, memory, and other resources of the electronic device. If a timer structure exists in the timer list, it retrieves the next timer structure with the shortest duration.
[0012] In conjunction with the first aspect, in one possible implementation, when the first timer structure is created by the service module, the operation corresponding to the operation function in the first timer structure performed by the transmission module includes: the transmission module sending a message or data to the connection networking module; when the first timer structure is created by the connection networking module, the operation corresponding to the operation function in the first timer structure performed by the transmission module includes: the transmission module sending a message or data to the service module.
[0013] In conjunction with the first aspect, in one possible implementation, the transmission module executes the operation corresponding to the operation function in the first timer structure at the time indicated by the timer duration in the first timer structure, including: when the timer duration in the first timer structure is a preset value, the transmission module immediately executes the operation corresponding to the operation function in the first timer structure; when the timer duration in the first timer structure is not a preset value, the transmission module starts a waiting timer, the waiting timer duration being the timer duration in the first timer structure; the transmission module executes the operation function in the first timer structure after the waiting timer times out.
[0014] In conjunction with the first aspect, in one possible implementation, after the transmission module starts a waiting timer, the electronic device causes the transmission thread of the transmission module to sleep.
[0015] When a transmission thread is in sleep mode, it does not consume CPU resources, thus reducing CPU power consumption. While in sleep mode, the transmission thread is in a waiting state; once awakened, it can continue executing its task.
[0016] Secondly, an electronic device is provided, which has the function of implementing the method described in the first aspect. This function can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-described function.
[0017] Thirdly, an electronic device is provided, comprising: a processor, a memory, and a communication interface; the communication interface is used for the electronic device to communicate with other devices, the memory is used to store computer-executed instructions, and when the electronic device is running, the processor executes the computer-executed instructions stored in the memory to cause the electronic device to perform the method as described in any one of the first aspects above.
[0018] Fourthly, a computer-readable storage medium is provided that stores instructions which, when executed on a computer, cause the computer to perform the method described in any one of the first aspects.
[0019] Fifthly, a computer program product containing instructions is provided, which, when run on a computer, enables the computer to perform the method described in any one of the first aspects.
[0020] The technical effects of any of the design methods in aspects two through five can be found in the technical effects of different design methods in aspect one, and will not be repeated here. Attached Figure Description
[0021] Figure 1 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application;
[0022] Figure 2 A schematic diagram of a system architecture for an electronic device provided in an embodiment of this application;
[0023] Figure 3 A schematic flowchart of a data transmission method provided in an embodiment of this application;
[0024] Figure 4 A schematic diagram of module interaction for a data transmission method provided in an embodiment of this application;
[0025] Figure 5This is a schematic diagram of the structural composition of an electronic device provided in an embodiment of this application. Detailed Implementation
[0026] In the description of the embodiments of this application, the terminology used in the following embodiments is for the purpose of describing specific embodiments only and is not intended to be a limitation of this application. As used in the specification and appended claims of this application, the singular expressions "a," "the," "the," "the," and "this" are intended to also include expressions such as "one or more," unless the context clearly indicates otherwise. It should also be understood that in the following embodiments of this application, "at least one" and "one or more" refer to one or more (including two). The term "and / or" is used to describe the relationship between related objects, indicating that three relationships can exist; for example, A and / or B can indicate: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship.
[0027] References to "one embodiment" or "some embodiments" in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized. The term "connection" includes direct connections and indirect connections, unless otherwise stated. "First" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated.
[0028] In the embodiments of this application, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or design that is described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the terms "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0029] The data transmission method provided in this application can be applied to data transmission between electronic devices. These electronic devices may include watches, mobile phones, tablets, laptops, personal computers (PCs), ultra-mobile personal computers (UMPCs), handheld computers, netbooks, smart home devices (e.g., smart TVs, smart screens, large screens, smart speakers, smart air conditioners, etc.), personal digital assistants (PDAs), wearable devices (e.g., smartwatches, smart bracelets, etc.), in-vehicle devices, virtual reality devices, etc. This application does not impose any limitations on these.
[0030] For example, Figure 1 A schematic diagram of a hardware structure of an electronic device 100 is shown.
[0031] like Figure 1 As shown, the electronic device 100 may include a processor 110, a memory 120, a power module 130, an antenna 1, an antenna 2, a mobile communication module 140, a wireless communication module 150, a display screen 160, an audio module 170, etc.
[0032] It is understood that the structures illustrated in the embodiments of the present invention do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0033] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0034] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.
[0035] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0036] The memory 120 can be used to store computer executable program code, which includes instructions. The processor 110 executes various functional applications and data processing of the device 100 by running the instructions stored in the memory 120. The memory 120 may include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function, etc. The data storage area may store data created during the use of the device 100, etc. Furthermore, the memory 120 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.
[0037] The power module 130 can be used to supply power to the various components included in the electronic device 100. In some embodiments, the power module 130 can be a battery, such as a rechargeable battery.
[0038] The wireless communication function of electronic device 100 can be implemented through antenna 1, antenna 2, mobile communication module 140, wireless communication module 150, modem processor, and baseband processor.
[0039] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover one or more communication frequency bands. Different antennas can also be multiplexed to improve antenna utilization. For example, antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with tuning switches.
[0040] The mobile communication module 140 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the electronic device 100. The mobile communication module 140 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 140 can receive electromagnetic waves via antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to a modem processor for demodulation. The mobile communication module 140 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via antenna 1. In some embodiments, at least some functional modules of the mobile communication module 140 may be housed in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 140 and at least some modules of the processor 110 may be housed in the same device.
[0041] The wireless communication module 150 can provide solutions for wireless communication applications on the electronic device 100, including wireless local area networks (WLAN) (such as Wi-Fi), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR). The wireless communication module 150 can be one or more devices integrating at least one communication processing module. The wireless communication module 150 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signal, and sends the processed signal to processor 110. The wireless communication module 150 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.
[0042] Electronic device 100 implements display functions through a GPU, a display screen 160, and an application processor. The GPU is a microprocessor for image processing, connecting the display screen 160 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0043] The audio module 170 is used to convert digital audio information into analog audio signals for output, and also to convert analog audio input into digital audio signals. The audio module 170 can also be used for encoding and decoding audio signals. In some embodiments, the audio module 170 may be located in the processor 110, or some functional modules of the audio module 170 may be located in the processor 110.
[0044] It is understandable that electronic devices require multiple modules to work together to complete the data transmission process.
[0045] For example, Figure 2 A schematic diagram of a system architecture for an electronic device is shown.
[0046] like Figure 2 As shown, electronic devices may include service modules, transmission modules, connection and networking modules, etc.
[0047] The business modules can include various services provided by the application and system services, such as the sports and health services of a sports and health app, the audio playback services of an audio and video playback application, and the chat services and file sharing services of a chat application. Each service in the business module can generate business data; for example, the sports service generates sports data, and the audio playback service generates audio data and / or image data.
[0048] The transmission module is used to manage data transmission. This includes managing the establishment, modification, and deletion of sessions; allocating transmission channels for data; matching data sent by business modules with corresponding transmission protocols; encapsulating and parsing various transmission protocols; and applying various transmission algorithms.
[0049] The connectivity and networking module is used to provide a transmission channel for the electronic device to send data to or receive data from other devices. This transmission channel may include Bluetooth channel, Wi-Fi Direct, etc.
[0050] refer to Figure 2 After the business module generates data, it sends the data to the transmission module. The transmission module can encapsulate the data, allocate appropriate transmission channels, and perform congestion management. Then, the transmission module sends the encapsulated data packets to the connection networking module. The connection networking module sends the data packets to other devices through the corresponding transmission channels.
[0051] After receiving data packets from other devices, the connection module sends the data packets to the transmission module; the transmission module processes the data packets by parsing, sorting, etc., and then sends the data to the service module.
[0052] During the process of the electronic device sending or receiving data, the service module, transmission module, and connection networking module each execute their respective processes.
[0053] Understandably, the various modules of an electronic device need to access system resources during operation, such as CPU resources, memory resources, and lock resources. Generally, electronic devices use processes as the unit of resource allocation and execution. A process is a program with independent functionality running on a specific set of data; it can request and own system resources. A process can include multiple threads. A thread is the smallest unit of computation that the operating system can schedule; it is contained within a process and is the actual unit of operation within the process. A thread refers to a single sequential flow of control within a process. Multiple threads can run concurrently within a process, each executing different tasks in parallel.
[0054] In some embodiments, for resource-constrained electronic devices such as watches, the various processes and modules of the electronic device share a single process, and a module may occupy one or more threads.
[0055] For example, a thread used to run related tasks in a business module is called a business thread, a thread used to run related tasks in a transmission module is called a transmission thread, and a thread used to run related tasks in a connection networking module is called a connection networking thread.
[0056] In one implementation, the service module allocates a service thread for each service, the transmission module allocates a transmission thread for each service, and the connection and networking module allocates a connection and networking thread for each service.
[0057] When various services transmit data concurrently, such as when a watch and a phone are syncing running information, the watch receives calendar information from the phone, and multiple threads run on the electronic device. Because watches have limited system resources, the operation of multiple threads can easily lead to insufficient memory and other resources, causing crashes. Furthermore, the more threads running, the greater the power consumption and battery drain. Moreover, with each service running on its own independent thread, data transmission between multiple services may cause data congestion.
[0058] This application provides a data transmission method in which an electronic device shares a single transmission thread for sending and receiving data; that is, the transmission module completes data transmission and reception within a single transmission thread. When multiple services transmit data concurrently, compared to running multiple transmission threads, completing the data transmission of each service within a single transmission thread avoids the excessive consumption of resources such as memory and locks by running multiple threads, thus reducing the power consumption of the electronic device. Furthermore, since the data transmission of multiple services is completed within a single transmission thread, the transmission thread can uniformly manage the sending or receiving process of each service's data, avoiding data transmission or reception congestion.
[0059] In some embodiments, the processes requiring processing by the transmission module in an electronic device are broken down into independent atomic tasks. Each atomic task is an operation performed by the transmission module, and there is no delay within the atomic task. In one implementation, one atomic task corresponds to one timer structure. Each timer structure includes a timer duration, an operation function, function parameters, and a loop count. The transmission module executes the corresponding atomic task based on the information in the timer structure. The timer duration indicates the moment when the transmission module executes the atomic task (calls the operation function), the operation function indicates the operation to be performed, the function parameters are the parameters of the operation function, and the loop count is the number of times the operation function runs. The process of the electronic device sending or receiving data may create multiple timer structures. The transmission module executes the atomic tasks of each timer structure sequentially within a single transmission thread, thus avoiding data congestion caused by concurrent data transmission of a large number of data.
[0060] For example, Figure 3 A schematic flowchart of a data transmission method provided in an embodiment of this application is shown.
[0061] The business module creates a timer structure:
[0062] After the business module generates signaling or data, it can call the send function for processing.
[0063] A service module can run one or more service threads for sending signaling or data. In one implementation, data transmission for one service is processed within one service thread, and multiple services correspond to multiple service threads.
[0064] In one implementation, on the business thread, a single call to the send function by the business module is broken down into one or more atomic tasks, each corresponding to a timer structure. For example, sending a message corresponds to a timer structure, sending a file corresponds to a timer structure, and sending a data packet from a data stream corresponds to a timer structure, etc.
[0065] In one implementation, each timer structure is created, it is added to the timer list. Optionally, timer structures are added to the timer list sequentially according to the order in which they were created. Optionally, timer structures are added to the timer list in ascending order of their timer durations.
[0066] Connecting the network module creates a timer structure:
[0067] After receiving signaling or data from other devices, the connection networking module can call the receive function to process it.
[0068] The connectivity module can run one or more connectivity threads to process received signaling or data. In one implementation, data reception for each service is processed within its corresponding connectivity thread, with multiple services corresponding to multiple connectivity threads. In another implementation, data reception for each transmission port is processed within its corresponding connectivity thread, with multiple transmission ports corresponding to multiple connectivity threads.
[0069] In one implementation, a single call to the receive function by the network module is broken down into one or more atomic tasks, each corresponding to a timer structure. For example, receiving a message corresponds to a timer structure, receiving a file corresponds to a timer structure, and receiving a data packet from a data stream corresponds to a timer structure, etc.
[0070] In one implementation, each timer structure is created, it is added to the timer list. Optionally, timer structures are added to the timer list in the order they were created. Optionally, timer structures are added to the timer list in ascending order of timer duration; when timer durations are the same in timer structures, they are added to the timer list in the order they were created.
[0071] The transmission module executes the atomic task corresponding to the timer structure:
[0072] The transmission module runs a transmission thread. Within this transmission thread, atomic tasks corresponding to the timer structures in the timer list are executed serially.
[0073] Optionally, the timer structures in the timer list are stored in the order they were created. The transmission module iterates through the timer list and retrieves the timer structure with the shortest duration. Alternatively, the timer structures in the timer list are stored in ascending order of duration. The transmission module retrieves the first timer structure in the timer list, which is the timer structure with the shortest duration.
[0074] After obtaining the timer structure with the shortest duration, the transmission module can execute the atomic task corresponding to that timer structure. In one implementation, executing the atomic task corresponding to the timer structure involves calling the operation function within the timer structure.
[0075] In one example, the timer structure with the shortest timer duration has a preset timer duration, such as 0. The transmission module immediately calls the operation function in this timer structure. Optionally, the transmission module can call the operation function according to the number of loops in the timer structure.
[0076] In another example, the timer duration in the shortest timer structure is not a preset value, such as a timer duration greater than 0. The transmission module can start a timer based on the timer duration in the timer structure and call the operation function in the timer structure after the timer expires. Optionally, the transmission module can call the operation function according to the number of loops in the timer structure. In one implementation, after the transmission module starts the timer, the transmission thread sleeps; when the timer expires, the transmission thread is awakened. The transmission thread does not occupy CPU resources while sleeping, which can reduce CPU power consumption. The transmission thread is in a waiting state while sleeping, and can continue to execute atomic tasks once awakened. Optionally, if a new timer structure is created while the transmission thread is sleeping, and the execution time of the atomic task corresponding to the new timer structure is earlier than the timeout time of the previous timer, the transmission thread is awakened at the execution time of the atomic task corresponding to the new timer structure.
[0077] After the transmission thread completes the atomic task corresponding to the timer structure, it removes the timer structure from the timer list. After the timer list is updated, if the timer list is not empty, the transmission thread retrieves the timer structure with the shortest timer duration from the timer list again and executes the atomic task corresponding to that timer structure.
[0078] Optionally, during the execution of an atomic task by the transmission module, this atomic task can generate new atomic tasks; that is, a new timer structure can be created in the operation function. The transmission module can also delete an existing atomic task during the execution of an atomic task; that is, a timer structure can be deleted in the operation function. For example, the transmission thread executes operation function 1 in timer structure 1, which is used to send a signaling message. Operation function 1 can create a timer structure 2, whose corresponding atomic task is waiting for the acknowledgment message of the signaling message; for example, operation function 2 in timer structure 2 is used to create a waiting-for-acknowledgment timer. After operation function 1 completes its execution, timer structure 1 is deleted from the timer list. Then, after the connection networking module receives the acknowledgment message of the signaling message, it creates timer structure 3, in which operation function 3 is used to process the acknowledgment message. Calling operation function 3 can delete the waiting-for-acknowledgment timer and delete timer structure 2. After operation function 3 completes its execution, timer structure 3 is deleted from the timer list.
[0079] In one implementation, the transmission module starts the transmission thread when the number of timer structures in the timer list changes from 0 to 1; and shuts down the transmission thread when the number of timer structures in the timer list changes from 1 to 0. After shutting down the transmission thread, the CPU, memory, and lock resources it occupied are released. In other words, the transmission thread starts when there is an atomic task to be processed (i.e., when the timer list contains at least one timer structure), and shuts down when there is no atomic task to be processed (i.e., when the timer list does not contain any timer structures). Compared to the transmission thread going to sleep, shutting down the transmission thread removes it from memory, further conserving the CPU and memory resources of the electronic device.
[0080] The data transmission method provided in this application breaks down complex tasks into atomic tasks, each with a very short processing time, which can be completed within a single transmission thread. The transmission module executes atomic tasks serially within a single transmission thread, avoiding data congestion caused by concurrent data transmission. Furthermore, it reduces the number of threads running on the electronic device, saving system resources and reducing power consumption. In some embodiments, when there are no atomic tasks to process, the transmission thread is closed, saving system resources such as CPU and memory of the electronic device.
[0081] The following section uses the transmission of data from a sports and health app as an example to detail the data transmission method provided in this application.
[0082] For example, Figure 4 This illustration shows a module interaction diagram of the data transmission method provided in an embodiment of this application.
[0083] like Figure 4 As shown, the method includes:
[0084] S401. After the Sports and Health App starts, the business module creates session-related listeners in the business thread.
[0085] Once launched, the Health & Fitness app can transfer data with other Health & Fitness apps on other devices.
[0086] In one implementation, the business module creates a session-related listener. For example, callback functions are registered in both the transport module and the connection networking module. When the listening reporting conditions are met, either the transport module or the connection networking module can call the corresponding callback function. In one example, the input parameter of the callback function includes a session identifier, thus distinguishing the session corresponding to the callback function.
[0087] For example, session-related listeners may include:
[0088] Session creation listener (session creation callback function); the session creation callback function is called when a new session is successfully created.
[0089] Session creation failure listener (session creation failure callback function); when creating a new session fails, the session creation failure function is called.
[0090] Data reception listener (data reception callback function); when data is received from other devices, the data reception callback function is called.
[0091] Listen for data transmission results (data transmission result callback function); when the data transmission result is received, call the data transmission result callback function.
[0092] In one implementation, the business module detects whether the transmission module is initialized. If it is determined that the transmission module is not initialized, it initiates the initialization of the transmission module.
[0093] In one implementation, the business module stores the listeners (callback functions) registered by the sports and health app into the listener list of the transmission module.
[0094] S402. In the business thread, the business module initiates a session creation to the transmission module.
[0095] The fitness and health app generates data that is sent to another device.
[0096] In some embodiments, if the Health & Fitness App is sending data for the first time after startup, the App initiates a session creation request to the transmission module. In one implementation, the business module decomposes the session creation task into one or more atomic tasks, each encapsulated as a timer structure. The business module also stores the timer structures generated based on the session creation tasks into the transmission module's timer list.
[0097] The business module checks whether the transmission thread has been started. If it determines that the transmission thread has not been started, it starts the transmission thread. Understandably, in one possible scenario, the transmission thread is not started before the transmission module sends or receives a message for the first time; in another possible scenario, the transmission thread is not started after it has been closed.
[0098] S403. In the transmission thread, the transmission module serially executes the atomic tasks corresponding to each timer structure in the timer list.
[0099] In one scenario, after the transmission thread starts, the transmission module checks the timer list within that thread. If the timer list is not empty, meaning it contains at least one timer structure, the transmission module retrieves the timer structure with the shortest timer duration from the list.
[0100] In another scenario, each time a timer structure is added to the timer list, the transmission module checks the timer list within the transmission thread. If the timer list is not empty (i.e., it contains at least one timer structure), the transmission module retrieves the timer structure with the shortest timer duration from the list.
[0101] If the timer duration of the timer structure with the shortest timer duration is a preset value, such as 0, the transmission module immediately calls the operation function in that timer structure.
[0102] If the timer duration of the shortest timer structure is not a preset value, such as a timer duration greater than 0, the transmission module starts a waiting timer, and the timer duration of this waiting timer is the timer duration of the timer structure.
[0103] In one implementation, the transmission process goes to sleep after the wait timer is started.
[0104] In one possible scenario, when the wait timer expires, the transmission process is woken up, and the operation function in the timer structure is immediately invoked. In another possible scenario, while the transmission process is sleeping, another timer structure is added to the timer list; for example, a business module creates a new timer structure, or an operation function creates a new timer structure. If the execution time of the atomic task corresponding to the newly added timer structure is earlier than the timeout time of the wait timer, the wait timer is stopped, and the transmission thread is woken up according to the timer duration of the newly added timer structure. For example, if the timer duration of the newly added timer structure is 0, the transmission thread is woken up immediately, and the operation function in the newly added timer structure is invoked; if the timer duration of the newly added timer structure is greater than 0, a wait timer is started, and the timer duration of the wait timer is the timer duration of the newly added timer structure. When the wait timer expires, the transmission process is woken up, and the operation function in the timer structure is immediately invoked.
[0105] After each execution of the operation function within a timer structure, the transmission module removes that timer structure from the timer list. The transmission module checks the number of timer structures in the timer list; if it determines that no timer structure exists, it closes the transmission thread. Compared to the transmission thread going to sleep, closing the transmission thread removes it from memory, further conserving CPU and memory resources of the electronic device. If a timer structure exists in the timer list, it retrieves the next timer structure with the shortest duration.
[0106] S404. In the transmission thread, the transmission module sends a connection request to the connection networking module.
[0107] For example, if the operation function corresponding to creating a session task is to request to open a connection to another device, then the transmission module sends a connection request to the connection networking module.
[0108] S405. In the connection networking thread, the connection networking module sends a connection request to another device.
[0109] S406. In the connection networking thread, the connection networking module receives a connection response from another device.
[0110] In one implementation, the connection networking module checks if a fitness app is listening. If no fitness app is listening, the message is discarded. If a fitness app is listening, the connection networking module breaks down the connection response task into one or more atomic tasks, each of which is encapsulated as a timer structure. The connection networking module also stores the timer structures generated based on the connection response tasks into the timer list of the transmission module.
[0111] The connection networking module checks whether the transmission thread has been started. If it determines that the transmission thread has not been started, it starts the transmission thread. In one possible scenario, the transmission thread is not started before the transmission module sends or receives a message for the first time; in another possible scenario, the transmission thread is not started after it has been closed.
[0112] S407. In the transmission thread, the transmission module serially executes the atomic tasks corresponding to each timer structure in the timer list.
[0113] The specific implementation of S407 can be referenced from S403.
[0114] S408. In the transmission thread, the transmission module sends a session creation response to the service module.
[0115] For example, if the operation function corresponding to the connection response task is to send a session creation response to the business module, then the transport module sends a session creation response to the business module.
[0116] S409. In the business thread, the business module sends data from the sports and health app to the transmission module.
[0117] In some embodiments, after the business module receives the session creation response, the session is successfully created. After the session is successfully created, the business module can send data from the sports and health app to the transmission module.
[0118] In one implementation, the business module decomposes the data sending task into one or more atomic tasks, and each atomic task is encapsulated as a timer structure.
[0119] In some embodiments, the number of timer structures in the health app can be checked. If the number of timer structures created within a preset duration (e.g., 1 second) is greater than or equal to a preset threshold (e.g., 100), the health app session is closed. In one implementation, the business module creates the timer structure corresponding to the session closure task. The business module stops creating timer structures based on atomic tasks other than the session closure task and clears the timer structures related to the health app.
[0120] The business module stores the timer structure created based on the data transmission task into the timer list of the transmission module. In one implementation, if the business module determines that a timer list does not exist, it can notify the transmission module to create one.
[0121] The business module checks whether the transmission thread has started. If it determines that the transmission thread has not started, it starts the transmission thread. Understandably, in one possible scenario, the transmission thread might not start after being closed. In one implementation, if the business module determines that the timer list does not exist or is empty before adding the timer structure to the timer list, it then determines that the transmission thread has not started.
[0122] S410. In the transmission thread, the transmission module serially executes the atomic tasks corresponding to each timer structure in the timer list.
[0123] The specific implementation of S410 can be found in S403.
[0124] S411. In the transmission thread, the transmission module sends data to the connection networking module.
[0125] For example, if the operation function corresponding to the data sending task is to send data to another device, then the transmission module sends data to the connection networking module.
[0126] S412. In the connection networking thread, the connection networking module sends data to another device.
[0127] S413. In the connection networking thread, the connection networking module receives data from another device.
[0128] In one example, the connectivity module receives data from a fitness and health app from another device.
[0129] In one implementation, the connection networking module checks if a fitness app is listening. If no fitness app is listening, the data is discarded. If a fitness app is listening, the connection networking module breaks down the data receiving task into one or more atomic tasks, each of which is encapsulated as a timer structure.
[0130] In some embodiments, the number of timer structures in the fitness app can be checked. If the number of timer structures created within a preset duration (e.g., 1 second) is greater than or equal to a preset threshold (e.g., 100), the fitness app session is closed. In one implementation, the connection networking module creates the timer structure corresponding to the session closure task. The business module stops creating timer structures based on atomic tasks other than the session closure task and clears the timer structures related to the fitness app.
[0131] The connection networking module also stores the timer structure generated based on the data reception task into the timer list of the transmission module. In one implementation, if the connection networking module determines that a timer list does not exist, it can notify the transmission module to create one.
[0132] The connection networking module checks whether the transmission thread has started. If it determines that the transmission thread has not started, it starts the transmission thread. In one possible scenario, the transmission thread is not started before the transmission module sends or receives a message for the first time; in another possible scenario, the transmission thread is not started after it has been closed. In one implementation, if the connection networking module determines that a timer list does not exist or is empty before adding the timer structure to the timer list, it determines that the transmission thread has not started.
[0133] S414. In the transmission thread, the transmission module executes the atomic tasks corresponding to each timer structure in the timer list serially.
[0134] The specific implementation of S414 can be found in S403.
[0135] S415. In the transmission thread, the transmission module sends the received data to the service module.
[0136] For example, if the operation function corresponding to the data sending task is to send data to the business module, then the transmission module sends data to the business module.
[0137] The data transmission method provided in this application breaks down tasks such as session creation, data sending, and data receiving into atomic tasks. Each atomic task is very short and can be completed serially within a single transmission thread. The transmission module executes atomic tasks serially within a single transmission thread, avoiding data congestion caused by concurrent data transmission. Furthermore, it reduces the number of threads running on the electronic device, saving system resources and reducing power consumption. When there are no atomic tasks to process, the transmission thread is closed, conserving system resources such as CPU and memory of the electronic device.
[0138] It is understood that, in order to achieve the aforementioned functions, the electronic device includes corresponding hardware structures and / or software modules for performing each function. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein, the embodiments of this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed by hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of this application.
[0139] This application embodiment can divide the above-described electronic device into functional modules based on the method example described above. For example, each function can be divided into its own functional modules, or two or more functions can be integrated into one processing module. The integrated modules can be implemented in hardware or as software functional modules. It should be noted that the module division in this application embodiment is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.
[0140] Figure 5 A possible structural diagram of the electronic device involved in the above embodiments is shown. The electronic device 500 includes: a processing unit 501, a communication unit 502, and a storage unit 503. The processing unit 501 is used to control and manage the operation of the electronic device 500; the communication unit 502 is used to support communication between the electronic device 500 and other network entities; and the storage unit 503 stores the instructions and data of the electronic device 500.
[0141] Of course, the unit modules in the above-mentioned electronic device 500 include, but are not limited to, the processing unit 501, the communication unit 502, and the storage unit 503. For example, the electronic device 500 may also include a power supply unit, which is used to supply power to the electronic device 500.
[0142] The processing unit 501 can be a processor or controller, such as a central processing unit (CPU), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. The communication unit 502 can be a transceiver, transceiver circuit, etc. The storage unit 503 can be a memory.
[0143] For example, processing unit 501 is a processor (such as...) Figure 1 The processor 110 shown, and the communication unit 502 include a mobile communication module (such as...). Figure 1 The mobile communication module 140 shown) and / or wireless communication module (such as Figure 1 The wireless communication module 150 shown can be a memory (such as a storage unit 503). Figure 1 The memory 120 shown is an example of an electronic device 500 provided in this application embodiment. Figure 1 The electronic device 100 shown above. The processor, memory, communication interface, etc., can be connected together, for example, via a bus. The processor calls the program code stored in the memory to execute the various steps in the above method embodiments.
[0144] This application also provides a computer-readable storage medium storing computer program code. When the processor executes the computer program code, the electronic device performs the method described in the above embodiments.
[0145] This application also provides a computer program product that, when run on a computer, causes the computer to perform the methods described in the above embodiments.
[0146] In this application, the electronic device 500, computer-readable storage medium, or computer program product provided in the embodiments are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
[0147] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0148] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0149] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit described above can be implemented in hardware or as a software functional unit.
[0150] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially, or the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROMs, magnetic disks, or optical disks.
[0151] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A data transmission method, characterized by, The method is applied to an electronic device, and the electronic device comprises a transmission module, and the method comprises the following steps: The transmission module acquires a timer list; When the timer list comprises at least one timer structure, a first timer structure is acquired; the first timer structure is a timer structure with the shortest timer duration in the timer list, the timer structure comprises a timer duration and an operation function, and the operation function is used for indicating an operation performed by the electronic device; The transmission module performs an operation corresponding to the operation function in the first timer structure at a time indicated by the timer duration in the first timer structure; The transmission module deletes the first timer structure from the timer list and acquires an updated timer list; When the updated timer list comprises at least one timer structure, a second timer structure is acquired; the second timer structure is a timer structure with the shortest timer duration in the updated timer list; The transmission module performs an operation corresponding to the operation function in the second timer structure at a time indicated by the timer duration in the second timer structure.
2. The method of claim 1, wherein, The electronic device further comprises a service module and a connection networking module, and before the transmission module acquires the timer list, the method further comprises the following steps: The service module creates the first timer structure and adds the first timer structure to the timer list; or The connection networking module creates the first timer structure and adds the first timer structure to the timer list; or The transmission module creates the first timer structure and adds the first timer structure to the timer list.
3. The method of claim 2, wherein, If the timer list does not exist or no timer structure exists in the timer list before the first timer structure is added to the timer list, the method further comprises the following steps: The electronic device starts a transmission thread of the transmission module.
4. The method according to any one of claims 1 to 3, characterized in that, The method further comprises the following steps: When the updated timer list does not comprise a timer structure, the transmission thread of the transmission module is closed.
5. The method of claim 2, wherein When the first timer structure is created by the service module, the transmission module performing the operation corresponding to the operation function in the first timer structure comprises the following steps: The transmission module sends a message or data to the connection networking module; When the first timer structure is created by the connection networking module, the transmission module performing the operation corresponding to the operation function in the first timer structure comprises the following steps: The transmission module sends a message or data to the service module.
6. The method according to any one of claims 1 to 5, characterized in that, The transmission module performing the operation corresponding to the operation function in the first timer structure at the time indicated by the timer duration in the first timer structure comprises the following steps: When the timer duration in the first timer structure is a preset value, the transmission module immediately performs the operation corresponding to the operation function in the first timer structure; When the timer duration in the first timer structure is not the preset value, the transmission module starts a waiting timer, and a duration of the waiting timer is the timer duration in the first timer structure; The transmission module executes the operation function in the first timer structure after the waiting timer expires.
7. The method of claim 6, wherein, The method further comprises: The electronic device causes the transmission thread of the transmission module to sleep.
8. An electronic device, comprising: Comprise: A communication interface, a processor and a memory; the communication interface, the processor and the memory are coupled; the communication interface is used for the electronic device to communicate with other devices, the memory is used for storing computer program code, the computer program code comprises computer instructions, when the processor executes the computer instructions, causes the electronic device to execute the method as claimed in any one of claims 1-7.
9. A computer readable storage medium having stored thereon computer instructions, wherein, When the computer instructions run on the electronic device, cause the electronic device to execute the method as claimed in any one of claims 1-7.
10. A computer program product comprising computer instructions, characterized in that, When the computer program product runs on the computer, cause the computer to execute the method as claimed in any one of claims 1-7.
Citation Information
Patent Citations
Data transmission method, device and equipment and computer readable storage medium
CN111148159A
Software timer operation method and device based on thread driving, equipment and medium
CN116401067A