A command processing method, electronic device and storage medium based on iAP1 protocol
By creating a unique condition variable for each command, the inefficiency problem of multi-threaded command transmission in the iAP1 protocol is solved, multi-threaded parallel transmission is realized, and the command transmission efficiency is improved.
Patent Information
- Application Number
- CN202010086570.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-02-11
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2040-02-11
AI Technical Summary
In the iAP1 protocol, when multiple threads send commands at the same time, since all threads share the same condition variable, any reply received will trigger all threads, which is inefficient.
Create a uniquely associated condition variable for each command so that each command only completes its corresponding condition variable when receiving a reply to avoid multiple threads responding at the same time.
It realizes multiple threads parallel command transmission, improves command transmission efficiency and avoids multi-thread interference.
Smart Images

Figure CN113254367B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of electronic device control processing, and in particular to a command processing method, electronic device and storage medium based on the iAP1 protocol. Background Art
[0002] The iAP1 protocol is a protocol used by non-IOS system devices (hereinafter referred to as the first device) and IOS system devices (hereinafter referred to as the second device) to transmit commands. In the iAP1 protocol, each command sent by the first device requires the second device to reply to the command execution status. Therefore, when implementing the synchronous sending of a certain command, it is necessary to send the command first and then wait for the corresponding reply of the command.
[0003] In the prior art, each command sent uses the same condition variable. When multiple threads send commands at the same time, after the first device receives the reply from the second device, since the commands sent by all threads use the same condition variable, receiving any reply will trigger all threads waiting for the reply. To solve this problem, the prior art adopts the method of transmitting only one command at a time and waiting for the reply. Obviously, this method is inefficient. Summary of the invention
[0004] To solve the above problems, the present application provides a command processing method, electronic device and storage medium based on the iAP1 protocol, which can realize the transmission of commands in parallel by multiple threads.
[0005] A technical solution adopted in the present application is: to provide a command transmission method based on the iAP1 protocol, the method comprising: creating conditional variables uniquely associated with each of the multiple first commands based on the multiple first commands sent; when receiving a first reply for replying to each of the multiple commands, completing the conditional variables uniquely associated with each first command.
[0006] Another technical solution adopted by the present application is: to provide an electronic device based on the iAP1 protocol, the electronic device includes a processor and a memory connected to each other, the memory is used to store program data, and the processor is used to execute the program data to implement the above method.
[0007] Another technical solution adopted by the present application is: providing a computer-readable storage medium, in which program data is stored, and when the program data is executed by a processor, it is used to implement the above method.
[0008] The command processing method based on the iAP1 protocol provided by the present application includes: creating conditional variables uniquely associated with each of the multiple first commands based on the multiple first commands sent; when receiving the first reply for replying each of the multiple commands, completing the conditional variables uniquely associated with each first command. In the above manner, each command issued has a unique conditional variable. When multiple threads are used to send commands, the conditional variables of the multiple commands are different. Therefore, when a reply is received, multiple threads will not respond. Therefore, through this embodiment, multiple threads can transmit commands in parallel. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. Among them:
[0010] Figure 1 This is the iAP1 command class diagram provided by this application;
[0011] Figure 2 It is a flowchart of the first embodiment of the command processing method provided by the present application;
[0012] Figure 3 It is a flowchart of the second embodiment of the command processing method provided by the present application;
[0013] Figure 4 It is a flowchart of the third embodiment of the command processing method provided by the present application;
[0014] Figure 5 is a flowchart of a fourth embodiment of a command processing method provided by the present application;
[0015] Figure 6 is a flowchart of a fifth embodiment of a command processing method provided by the present application;
[0016] Figure 7 is a flowchart of a sixth embodiment of a command processing method provided by the present application;
[0017] Figure 8 It is a structural schematic diagram of an embodiment of an electronic device provided by the present application;
[0018] Fig. 9 It is a structural schematic diagram of an embodiment of a computer-readable storage medium provided by the present application. DETAILED DESCRIPTION
[0019] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It will be appreciated that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for ease of description, only some but not all structures related to the present application are shown in the drawings. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the art without making creative work are within the scope of protection of the present application.
[0020] The terms "first", "second", etc. in this application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
[0021] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0022] The iAP1 protocol contains two command / response mapping methods:
[0023] 1. Transaction ID mode: When sending a command, each command packet will carry a unique and dynamically generated 16-bit Transaction ID, and the corresponding reply command will also carry the same Transaction ID to indicate that the reply is for the command. The Transaction ID is generated by using a random number for the first iAP1 command sent by both parties, and each time a new command is sent, the Transaction ID is the value of the previous command plus 1.
[0024] 2. Fixed mode: When Transaction ID is not supported, only fixed commands and responses can be used. For example, sending a PlayControl command will only reply with iPodAck; sending GetShuffle will only reply with ReturnShuffle or iPodAck (Bad Parameter), that is, the fixed number of the command is directly used as the ID.
[0025] The difference between the two modes is that the mapping (one-to-one correspondence) between the command and reply ID in the fixed mode is preset, and the reply corresponding to the command is directly found by ID when calling; the command ID in the Transaction ID mode is set when sending, and after receiving the command, the command ID is assigned to the reply ID.
[0026] The iAP1 command class diagram designed by this application for the above situation is as follows Figure 1 shown.
[0027] iAP1AccRequest defines the interface and implementation for Accessory (non-IOS device) to send commands and respond to commands from Device (IOS device). That is, this class is used by Accessory to send iAP1 commands and provides synchronous sending function (send and wait for reply before returning).
[0028] iAP1AccResponse defines the interface and implementation used by Accessory to listen to commands from Device. That is, this class is used to receive commands from Device, but not to receive replies to commands sent by Accessory, which are handled by iAP1AccRequest.
[0029] iAP1AccRequest and iAP1AccResponse are both used for fixed command / reply mode, while iAP1CommandTID is used to support Transaction ID mode. iAP1CommandTID implements the interface defined by iAP1AccRequest and iAP1AccResponse, and matches the sent and received packets according to the requirements of Transaction ID.
[0030] iAP1Command is responsible for deciding which method to use to send commands. It is a proxy for iAP1AccRequest / iAP1AccResponse and iAP1CommandTID objects. This class can decide which method to use to send commands based on the commands sent and received, and switch the sending method internally, thus simplifying the upper-level command processing process.
[0031] Using this design, the upper-layer application only needs one iAP1Command object to use the corresponding command sending method according to the protocol without adding additional operations.
[0032] See also Figure 2 , Figure 2: is a flowchart of a first embodiment of a command processing method provided by the present application, the method comprising:
[0033] Step 21: creating condition variables uniquely associated with each of the plurality of first commands based on the plurality of first commands sent.
[0034] Condition variables are a mechanism for synchronization using global variables shared between threads. They mainly include two actions: one thread waits for the "condition of the condition variable to be met" and suspends; the other thread makes the "condition meet" (gives a signal that the condition is met).
[0035] It can be understood that the multiple first commands can be sent in chronological order or simultaneously, and there is no limitation here.
[0036] In an optional embodiment, the first command may be sent out first, and then a conditional variable uniquely associated with the first command may be created based on the sent first command; in another embodiment, a conditional variable uniquely associated with the first command may be created based on the first command to be sent, and then the first command may be sent out.
[0037] This embodiment is mainly applied to command transmission between a non-IOS device and an IOS device. In this step, the non-IOS device sends the command to the IOS device.
[0038] Step 22: When a first reply for replying to each first command in the plurality of commands is received, a condition variable uniquely associated with each first command is completed.
[0039] Specifically, when a first reply for replying to a first command is received, the condition variable uniquely associated with the first command is cancelled.
[0040] It can be understood that through the above method, when multiple commands are sent at the same time, conditional variables that are respectively associated with the multiple commands can be created based on the multiple commands sent; when a reply for replying to the first command among the multiple commands is received, the conditional variable uniquely associated with the first command is completed.
[0041] Different from the prior art, the command processing method based on the iAP1 protocol provided in this embodiment includes: creating conditional variables uniquely associated with each of the multiple first commands based on the multiple first commands sent; when receiving the first reply for replying to each of the multiple commands, completing the conditional variable uniquely associated with each first command. In the above manner, each command issued has a unique conditional variable. When multiple threads are used to send commands, the conditional variables of the multiple commands are different. Therefore, when a reply is received, multiple threads will not respond. Therefore, through this embodiment, multiple threads can transmit commands in parallel.
[0042] Further reading Figure 3 , Figure 3 : is a flowchart of a second embodiment of a command processing method provided by the present application, the method comprising:
[0043] Step 31: Get the first Lingo value and the first Command value of the first command.
[0044] The first command is a command to be sent or has been sent.
[0045] Lingo and Command are concepts in the iAP1 protocol. Lingo is a 1B number, and Command is a 1B or 2B number. These two numbers together determine an iAP1 command type.
[0046] Step 32: Combine the first Lingo value and the first Command value to obtain first identification information uniquely associated with the first command.
[0047] Optionally, a 32-bit ID (identification information) is formed using the Lingo and Command values of the command. For example, when a packet corresponding to a PlayControl command is sent through the interface, if the Lingo of the PlayControl command is 4 and the Command is 0x0029, the ID corresponding to the command is 0x00040029.
[0048] Step 33: Associating and storing the callback function for processing the first reply with the first identification information.
[0049] Step 34: Create a conditional variable uniquely associated with the first identification information based on the first identification information.
[0050] The conditional variables here generally use the synchronization mechanism provided by the operating system. The general process is to create the conditional variable first, then one thread (thread A) waits for the completion of the conditional variable, and another thread (thread B) is used to detect whether the condition is completed. If completed, thread B actively triggers the conditional variable. At this time, thread A will exit from waiting and continue with subsequent operations.
[0051] After step 34, the condition variable waits for the condition to be completed, and after the condition variable is completed, the corresponding condition variable and callback function are deleted.
[0052] Combination Figure 4 , Figure 4 : is a flowchart of a third embodiment of a command processing method provided by the present application, the method comprising:
[0053] Step 41: When receiving a command to be processed, obtain a second Lingo value and a second Command value of the command to be processed.
[0054] Step 42: Combine the second Lingo value and the second Command value to obtain second identification information uniquely associated with the command to be processed.
[0055] Step 43: Search for an associated callback function according to the second identification information, and use the associated callback function to process the first reply.
[0056] Step 44: When a first reply for replying to the first command is received, the condition variable uniquely associated with the first command is completed.
[0057] Understandably, the above Figure 2-Figure 4 The embodiment can be applied to the iAP1AccRequest command class.
[0058] Combination Figure 3 and Figure 4 , the whole process can include:
[0059] 1) When the first device sends an iAP1packet (packet is an actual data packet used to transmit an iAP1 command) through the send interface of iAP1AccRequest, the send interface will create a unique ID (identification information) for each iAP1packet to be sent.
[0060] 2) Pair and store the callback function used to process the reply of the command with the ID obtained in 1).
[0061] 3) Send the command.
[0062] 4) Create a unique condition variable based on the ID obtained in 1) and wait for the completion of the condition variable.
[0063] 5) When receiving the iAP1 packet from the second device, find the ID of the corresponding command according to its Lingo and Command.
[0064] 6) Find the callback function corresponding to the ID obtained in 5), and call the function to process the returned command.
[0065] 7) Find the condition variable corresponding to the ID obtained in 5), complete the condition, and delete the callback function and condition variable corresponding to the ID.
[0066] 8) At this time, the sender who was waiting for the condition in 5) has completed the sending process.
[0067] See also Figure 5 , Figure 5 : is a flowchart of a fourth embodiment of a command processing method provided by the present application, the method comprising:
[0068] Step 51: Create third identification information uniquely associated with the second command based on the second command to be monitored.
[0069] Optionally, in this step, a third Lingo value and a third Command value of the second command to be monitored may be obtained; and the third Lingo value and the third Command value may be combined to obtain third identification information uniquely associated with the second command.
[0070] Step 52: Associating and storing the callback function for processing the second command with the third identification information.
[0071] Step 53: When the second command is received, the second command is processed using the callback function associated with the third identification information.
[0072] Optionally, in one embodiment, step 53 may specifically include:
[0073] Step 531: When receiving a command to be processed, obtain the fourth Lingo value and the fourth Command value of the command to be processed.
[0074] Step 532: Combine the fourth Lingo value and the fourth Command value to obtain fourth identification information uniquely associated with the command to be processed.
[0075] Step 533: When the fourth identification signal is identical to the third identification information, the second command is processed using the callback function associated with the third identification information.
[0076] Combination Figure 5 , the whole process can include:
[0077] 1) Before starting to listen to commands from the second device, register the commands to be listened to through the addListener interface, which needs to pass the callback function and the Lingo and Command of the command to be listened to.
[0078] 2) The addListener interface creates a unique ID based on Lingo and Command and saves it together with the callback function.
[0079] 3) When receiving a command from the second device, create an ID based on the Lingo and Command of the received packet, and match the saved ID and callback function to find the corresponding callback function.
[0080] 4) Call the callback function found in 3), and after the callback function is executed, delete the callback function and the corresponding ID.
[0081] Understandably, the above Figure 5 The embodiment can be applied to the iAP1AccResponse command class.
[0082] See also Figure 6 , Figure 6 : is a flowchart of a fifth embodiment of a command processing method provided by the present application, the method comprising:
[0083] Step 61: When the first command is sent for the first time, a preset Transaction ID is used as the Transaction ID of the first command, and is used as the first identification information uniquely associated with the first command; or when the first command is not sent for the first time, the last used Transaction ID is incremented by 1 and is used as the Transaction ID of the first command, and is used as the first identification information uniquely associated with the first command; or when the first command is used to reply to a received target command, the Transaction ID of the target command is used as the Transaction ID of the first command, and is used as the first identification information uniquely associated with the first command.
[0084] The first command is a command to be sent or has been sent.
[0085] Step 62: Associating and storing the callback function for processing the first reply with the first identification information.
[0086] Step 63: Create a conditional variable uniquely associated with the first identification information based on the first identification information.
[0087] After step 63, the condition variable waits for the condition to be completed, and after the condition variable is completed, the corresponding condition variable and callback function are deleted.
[0088] Specifically, when a pending reply is received, the Transaction ID of the pending reply is obtained as the second identification information of the pending reply; when the second identification signal is the same as the first identification information, the conditional variable uniquely associated with the first command is completed.
[0089] Combination Figure 6 , the whole process can include:
[0090] 1) When the sender sends an iAP1packet through the send interface of iAP1CommandTID, if the packet is a command packet sent by Accessory, the last Accessory Transaction ID+1 is used as the command ID; if it is a reply command to Device, the Transaction ID used by the corresponding Device packet is used as the command ID.
[0091] 2) Pair and store the callback function used to process the reply of the command with the ID obtained in 1).
[0092] 3) Send the command.
[0093] 4) Create a unique condition variable based on the ID obtained in 1) and wait for the completion of the condition variable.
[0094] 5) When receiving the iAP1 packet from the Device, parse out its Transaction ID from the packet.
[0095] 6) Find the callback function corresponding to the ID obtained in 5), and call the function to process the returned command.
[0096] 7) Find the condition variable corresponding to the ID obtained in 5) and complete the condition.
[0097] 8) At this time, the sender who was waiting for the condition in 5) has completed the sending process.
[0098] See also Figure 7 , Figure 7 : is a flowchart of a sixth embodiment of a command processing method provided by the present application, the method comprising:
[0099] Step 71: associate and store the Transaction ID of the third command to be monitored with the callback function for processing the third command.
[0100] Step 72: When the third command is received, the third command is processed using the callback function associated with the Transaction ID of the third command.
[0101] Optionally, in one embodiment, step 72 may specifically include: when receiving the command to be processed, obtaining the Transaction ID of the command to be processed; when the Transaction ID of the command to be processed is the same as the Transaction ID of the third command, processing the command to be processed using a callback function associated with the Transaction ID of the third command.
[0102] Combination Figure 7 , the whole process can include:
[0103] 1) Before starting to listen to commands from the second device, register the commands to be listened to through the addListener interface, which requires passing a callback function and the Transaction ID of the command to be listened to.
[0104] 2) The addListener interface saves the Transaction ID and the callback function together.
[0105] 3) When receiving a command from the second device, first save the Transaction ID of the received packet.
[0106] 4) Match the saved Transaction ID and callback function to find the corresponding callback function.
[0107] 5) Call the callback function found in 4), and after the callback function is executed, delete the corresponding TransactionID and callback function.
[0108] Understandably, the above Figure 6-7 The embodiment can be applied to the iAP1CommandTID command class.
[0109] In the above process, since iAP1AccRequest and its derived class iAP1CommandTID generate a unique waiting condition according to the specific command sent when sending iAP1packet, and match the waiting condition according to the reply command type after receiving the reply from the iPod, the above design can meet the purpose of multiple threads sending commands and waiting for replies at the same time without interfering with each other.
[0110] At the same time, the command sending / receiving process of iAP1CommandTID is matched through Transaction ID to meet the requirements of the iAP1 protocol.
[0111] iAP1Command is a proxy object for iAP1AccRequest / iAP1AccResponse and iAP1CommandTID. That is, the send interface function of iAP1Command is actually implemented by calling send of iAP1AccRequest or iAP1CommandTID. Other interfaces with the same name also have similar relationships.
[0112] In addition to acting as a proxy for iAP1AccRequest / iAP1AccResponse and iAP1CommandTID, iAP1Command must also manage the objects of iAP1AccRequest / iAP1AccResponse and iAP1CommandTID, and switch between these three objects under specified conditions according to the requirements of the iAP1 protocol.
[0113] Since the switching conditions involve the iAP1 protocol, they are not described in detail here, but the process may occur before sending certain specific commands or after receiving certain specific commands. The switching process is as follows:
[0114] 1) Prevent the upper layer from continuing to use iAP1AccRequest / iAP1AccResponse or iAP1CommandTID objects by calling interfaces such as send or addListener;
[0115] 2) If the upper layer is currently waiting for a reply to some command, notify the upper layer to stop waiting;
[0116] 3) Perform a switching action, that is, switch the iAP1AccRequest / iAP1AccResponse object to the iAP1CommandTID object, or switch the iAP1CommandTID object to the iAP1AccRequest / iAP1AccResponse object;
[0117] 4) Open interfaces such as send so that the upper layer can continue to call the iAP1Command interface.
[0118] In combination with the above embodiments, the present application has the following beneficial effects:
[0119] 1. Since a separate synchronization variable is used for each iAP1 command, each synchronization variable can be triggered separately without affecting other synchronization variables.
[0120] 2. Due to the use of two methods to generate IDs, in the fixed command / reply mode, iAP1Lingo and Command are used to match commands and replies, while in the Transaction ID mode, the Transaction ID in the iAP1packet is used to match commands and replies. This process complies with the requirements of the iAP1 protocol.
[0121] 3. Since the two methods use the same interface, the polymorphic characteristics of the programming language can be used at this time to easily switch between the two methods. Therefore, according to the protocol requirements, the corresponding sending method can be selected at the appropriate time, thereby simplifying the interface to the upper layer.
[0122] See also Figure 8 , Figure 8 1 is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. The electronic device 80 includes a processor 81 and a memory 82 connected to each other. The memory 82 is used to store program data. The processor 81 is used to execute the program data to implement the following method:
[0123] Based on the sent multiple first commands, conditional variables uniquely associated with each of the multiple first commands are created; when a first reply for replying to each of the multiple commands is received, the conditional variables uniquely associated with each of the first commands are completed.
[0124] Among them, the electronic device can be a non-IOS system device, specifically a mobile phone, a tablet computer, a wearable device, and the wearable device can be headphones, smart glasses, etc.
[0125] See also Fig. 9 , Fig. 9 1 is a schematic diagram of a structure of an embodiment of a computer-readable storage medium provided by the present application. The computer-readable storage medium 90 stores program data 91. When the program data 91 is executed by a processor, it is used to implement the following method:
[0126] Based on the sent multiple first commands, conditional variables uniquely associated with each of the multiple first commands are created; when a first reply for replying to each of the multiple commands is received, the conditional variables uniquely associated with each of the first commands are completed.
[0127] Optionally, in one embodiment, the processor is further configured to execute: creating first identification information uniquely associated with the first command based on the first command to be sent; and creating a conditional variable uniquely associated with the first identification information based on the first identification information.
[0128] Optionally, in one embodiment, the processor is further configured to execute: obtaining a first Lingo value and a first Command value of the first command; and combining the first Lingo value and the first Command value to obtain first identification information uniquely associated with the first command.
[0129] Optionally, in one embodiment, the processor is also used to execute: when receiving a reply to be processed, obtaining a second Lingo value and a second Command value of the reply to be processed; combining the second Lingo value and the second Command value to obtain second identification information uniquely associated with the reply to be processed; when the second identification signal and the first identification information are the same, completing the conditional variable uniquely associated with the first command.
[0130] Optionally, in one embodiment, the processor is further used to execute: associating and storing a callback function for processing a first reply with first identification information; and upon receiving a first reply for replying to a first command, processing the first reply using the callback function associated with the first identification information.
[0131] Optionally, in one embodiment, the processor is further configured to execute: when the first command is a command sent for the first time, using a preset Transaction ID as the Transaction ID of the first command, and as first identification information uniquely associated with the first command; or when the first command is not a command sent for the first time, adding 1 to the last used Transaction ID as the Transaction ID of the first command, and as first identification information uniquely associated with the first command; or when the first command is used to reply to a received target command, using the Transaction ID of the target command as the Transaction ID of the first command, and as first identification information uniquely associated with the first command.
[0132] Optionally, in one embodiment, the processor is further used to execute: when receiving a pending reply, obtaining the Transaction ID of the pending reply as the second identification information of the pending reply; when the second identification signal is the same as the first identification information, completing the conditional variable uniquely associated with the first command.
[0133] Optionally, in one embodiment, the processor is also used to execute: creating third identification information uniquely associated with the second command based on the second command to be monitored; associating and storing a callback function for processing the second command with the third identification information; and when the second command is received, processing the second command using the callback function associated with the third identification information.
[0134] Optionally, in one embodiment, the processor is further configured to execute: obtaining a third Lingo value and a third Command value of the second command to be monitored; and combining the third Lingo value and the third Command value to obtain third identification information uniquely associated with the second command.
[0135] Optionally, in one embodiment, the processor is also used to execute: when receiving a command to be processed, obtaining a fourth Lingo value and a fourth Command value of the command to be processed; combining the fourth Lingo value and the fourth Command value to obtain fourth identification information uniquely associated with the command to be processed; when the fourth identification signal and the third identification information are the same, processing the second command using the callback function associated with the third identification information.
[0136] Optionally, in one embodiment, the processor is further used to execute: associating and storing the TransactionID of the third command to be monitored with a callback function for processing the third command; when receiving the third command, processing the third command using the callback function associated with the Transaction ID of the third command.
[0137] Optionally, in one embodiment, the processor is further configured to execute: upon receiving the command to be processed, obtaining the Transaction ID of the command to be processed; and when the Transaction ID of the command to be processed is the same as the Transaction ID of the third command, processing the command to be processed using a callback function associated with the Transaction ID of the third command.
[0138] Optionally, in one embodiment, the processor is further used to execute: creating conditional variables that are respectively associated with the multiple commands in a one-to-one correspondence based on the multiple commands sent; and completing the conditional variable uniquely associated with the first command when receiving a reply for replying to the first command among the multiple commands.
[0139] In the several embodiments provided in this application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only illustrative, for example, the division of the modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0140] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0141] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0142] The above description is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made according to the description and drawings of the present application, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A command processing method based on the iAP1 protocol, characterized in that: The method comprises: Based on the multiple first commands sent, condition variables uniquely associated with each of the multiple first commands are created, so that each first command sent has a unique condition variable; the multiple first commands are commands sent from the non-IOS device to the IOS device; Upon receiving a first reply for replying each first command of the plurality of commands, a condition variable uniquely associated with each first command is completed.
2. The method according to claim 1, characterized in that The step of creating a condition variable uniquely associated with each of the plurality of first commands based on the sent plurality of first commands comprises: Creating first identification information uniquely associated with the first command based on the sent first command; A condition variable uniquely associated with the first identification information is created based on the first identification information.
3. The method according to claim 2, characterized in that The creating first identification information uniquely associated with the first command based on the sent first command includes: Obtaining a first Lingo value and a first Command value of the first command; The first Lingo value and the first Command value are combined to obtain first identification information uniquely associated with the first command.
4. The method according to claim 3, characterized in that The step of completing, upon receiving a first reply for replying to each first command among the plurality of commands, a condition variable uniquely associated with each first command comprises: When receiving a reply to be processed, obtaining a second Lingo value and a second Command value of the reply to be processed; Combining the second Lingo value and the second Command value to obtain second identification information uniquely associated with the reply to be processed; When the second identification information is the same as the first identification information, the condition variable uniquely associated with the first command is completed.
5. The method according to claim 2, characterized in that: The method further comprises: Associating and storing a callback function for processing the first reply with the first identification information; When the first reply for replying the first command is received, the first reply is processed using a callback function associated with the first identification information.
6. The method according to claim 2, characterized in that The creating first identification information uniquely associated with the first command based on the sent first command includes: When the first command is a command sent for the first time, using a preset Transaction ID as the Transaction ID of the first command and as first identification information uniquely associated with the first command; or When the first command is not a command sent for the first time, the last used Transaction ID is incremented by 1 and used as the Transaction ID of the first command, and as the first identification information uniquely associated with the first command; or When the first command is used to reply to a received target command, the Transaction ID of the target command is used as the Transaction ID of the first command and as first identification information uniquely associated with the first command.
7. The method according to claim 6, characterized in that The step of completing, upon receiving a first reply for replying to each first command among the plurality of commands, a condition variable uniquely associated with each first command comprises: When receiving a pending reply, obtaining a Transaction ID of the pending reply as second identification information of the pending reply; When the second identification information is the same as the first identification information, the condition variable uniquely associated with the first command is completed.
8. The method according to claim 1, characterized in that The method further comprises: Creating third identification information uniquely associated with the second command based on the second command to be monitored; Associating and storing the callback function for processing the second command with the third identification information; When the second command is received, the second command is processed using the callback function associated with the third identification information.
9. The method according to claim 8, characterized in that The creating, based on the second command to be monitored, third identification information uniquely associated with the second command includes: Get the third Lingo value and the third Command value of the second command to be monitored; The third Lingo value and the third Command value are combined to obtain third identification information uniquely associated with the second command.
10. The method according to claim 9, characterized in that The method of processing the second command by using the callback function associated with the third identification information upon receiving the second command includes: When receiving a command to be processed, obtaining a fourth Lingo value and a fourth Command value of the command to be processed; Combining the fourth Lingo value and the fourth Command value to obtain fourth identification information uniquely associated with the command to be processed; When the fourth identification information is the same as the third identification information, the to-be-processed command is processed using a callback function associated with the third identification information.
11. The method according to claim 1, characterized in that: The method further comprises: Associating and storing the Transaction ID of the third command to be monitored with the callback function for processing the third command; When the third command is received, the third command is processed using the callback function associated with the Transaction ID of the third command.
12. The method according to claim 11, characterized in that When receiving the third command, processing the third command by using a callback function associated with the Transaction ID of the third command includes: When receiving a pending command, obtaining a Transaction ID of the pending command; When the Transaction ID of the command to be processed is the same as the Transaction ID of the third command, the command to be processed is processed using a callback function associated with the Transaction ID of the third command.
13. An electronic device based on the iAP1 protocol, characterized in that: The electronic device comprises a processor and a memory connected to each other, the memory is used to store program data, and the processor is used to execute the program data to implement the method according to any one of claims 1 to 12.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program data, and when the program data is executed by a processor, it is used to implement the method according to any one of claims 1 to 12.
