Disclosure of Invention
An object of an embodiment of the present invention is to provide a method, a system and a readable storage medium for processing an operation command of a bluetooth device.
In a first aspect, an embodiment of the present invention provides a method for processing an operation command of a bluetooth device, where the method includes:
packaging the operation command of the Bluetooth equipment according to a preset rule and generating a uniform operation object;
adding the uniform operation object into a Bluetooth command processing queue;
and processing the unified operation object in the Bluetooth command processing queue.
Optionally, the operation command of the bluetooth device includes a read command, a write command, and a notification command.
Optionally, the preset rule is that the operation command type and the result return callback interface of the bluetooth device are packaged together with the format encryption check of the transmitted data frame, and then the package is performed.
Optionally, the method includes encapsulating an operation command for the bluetooth device according to a preset rule, and generating a unified operation object, and further includes:
packaging three operation commands of the Bluetooth equipment according to a preset rule;
identifying a command type of an operation command to be performed on the Bluetooth device;
carrying out type marking on the identified type of the Bluetooth equipment operation command;
and generating a unified operation object.
Optionally, processing the unified operation object in the bluetooth command processing queue includes the following steps:
calling an operation command processing interface of a corresponding type;
and returning the calling result to the callback interface and returning the prompt message of the command operation result.
Optionally, the prompt information of the command operation result includes success, failure and timeout.
Optionally, the calling result returning to the callback interface, and after returning the prompt information of the command operation result, further includes the following steps:
judging whether an unoperated command exists in the Bluetooth command processing queue;
if yes, continuing to execute the operation commands in the queue in sequence;
if not, waiting to add the uniform operation object to the Bluetooth command processing queue for processing.
Optionally, the unified operation objects in the bluetooth command processing queue are processed, and the unified operation objects are processed according to a first-in-first processing sequence.
In a second aspect, the present invention further provides a system for processing bluetooth device operation commands, comprising
The encapsulation generation module encapsulates the operation command of the Bluetooth equipment according to a preset rule and generates a uniform operation object;
the adding module is used for adding the uniform operation object into a Bluetooth command processing queue;
and the processor module is used for processing the uniform operation objects in the Bluetooth command processing queue.
In a third aspect, the present invention also provides a readable storage medium storing one or more programs, the one or more programs being executable by one or more processors to implement the steps of the method for processing bluetooth device operation commands as claimed in any one of claims 1 to 8.
By the invention, the following beneficial effects can be realized:
in the embodiment of the invention, the processing logic and the simplified logic code amount of the operation command of the Bluetooth equipment are simplified by packaging the operation command of the Bluetooth equipment according to the preset rule and generating a uniform operation object; by adding the uniform operation object into the Bluetooth command processing queue, the problem that the mobile terminal cannot perform data interaction with the Bluetooth device due to the blocking condition when a plurality of commands are performed on the Bluetooth device in a short time can be solved. The invention can simplify the logic and code amount of the operation command of the Bluetooth equipment and solve the problem of the blockage of the Bluetooth equipment caused by the operation of a plurality of commands on the Bluetooth equipment.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
An object of an embodiment of the present invention is to provide a method, a system and a readable storage medium for processing an operation command of a bluetooth device.
Referring to fig. 1, in a first aspect, an embodiment of the present invention provides a method for processing an operation command of a bluetooth device, where the method includes:
s1: packaging the operation command of the Bluetooth equipment according to a preset rule and generating a uniform operation object;
in the first embodiment of the present invention, the operation commands of the bluetooth device mainly include three types, a read command, a write command, and a notification command; the three commands are packaged according to preset rules, wherein the rules are that the operation command type and the result of the Bluetooth equipment are returned to the callback interface and the format of the transmitted data frame is encrypted and checked to be packaged together, and a uniform operation object is generated, namely, the read, write and notification operation commands are packaged together to generate a uniform operation object; if there are many operation commands, it will generate many common operations, and different common operations correspond to different operation results.
S2: adding the uniform operation object into a Bluetooth command processing queue;
the Bluetooth processing queue is only one, the unified operation object common generated by packaging is added into the Bluetooth processing queue, and when a plurality of common operations exist, the operations are sequentially processed according to the sequence of different common operations entering the queue.
S3: and processing the unified operation object in the Bluetooth command processing queue.
And processing the unified operation objects in the Bluetooth command processing queue according to a principle that the unified operation objects are firstly processed after entering the queue.
Further, referring to fig. 2, 3 and 4, the operation commands of the bluetooth device include a read command, a write command and a notification command.
As shown in fig. 2, the method for processing the read command of the bluetooth device includes:
s100: reading data in the Bluetooth equipment;
s101: judging whether the reading is successful;
s102: if yes, calling a corresponding callback interface for returning a success result;
s103: if not, calling a corresponding callback interface for returning a failure result;
s104: executing the next command;
as shown in fig. 3, the method for processing the write command of the bluetooth device includes:
s201: writing data into the Bluetooth equipment;
s202: judging whether the writing is successful;
s203: if the writing is successful, opening the notice, and judging whether the opening of the notice is successful;
s204: if the command is not written, calling a failure callback interface to process the next command;
s205: if the opening notification is successful, judging whether a response exists;
s206: if the opening of the notice is unsuccessful, the timer is overtime;
s207: if so, judging whether the notification is successful;
s208: if the notification is successful, calling a successful callback interface;
s209: if the notification fails, calling a failure callback interface;
s210: executing the next command;
as shown in fig. 4, the method for processing the notification command of the bluetooth device includes:
s300: judging whether the opening notification is successful;
s301: if the call is successful, calling a successful callback interface;
s302: if the call fails, calling a failure callback interface;
s303: the next command is executed.
Further, the preset rule is that the operation command type and the result return callback interface of the bluetooth device are packaged together with the format encryption check of the transmitted data frame, and then the bluetooth device is packaged.
In this embodiment, the operation command types of the bluetooth device are three operation commands of the bluetooth device, i.e., a read command, a write command, and a notification command; the result return callback interface comprises three callback interfaces of success, failure and overtime; the format encryption verification of the transmitted data frame is the verification of the frame data format, and the frame data format specifically comprises: frame header + frame number + frame length + equipment code + message ID + content + check code; and (4) the operation command type and the result of the Bluetooth equipment are returned to the callback interface, and the transmitted data frame format is encrypted, checked, packed and packaged.
Further, referring to fig. 5, the method for encapsulating the operation command of the bluetooth device according to the preset rule and generating a unified operation object further includes:
s11, packaging the three operation commands of the Bluetooth equipment according to a preset rule;
s12, identifying the command type of the operation command to be performed on the Bluetooth device;
s13, marking the type of the identified Bluetooth device operation command type;
and S14, generating a unified operation object.
Based on the above embodiment, in the second embodiment of the present invention, the bluetooth device is packaged and encapsulated according to the preset rule, that is, the operation command type and the result of the bluetooth device are returned to the callback interface and the transmitted data frame format is encrypted and verified; then, the command type of the operation command to be performed on the Bluetooth device is identified, the identified Bluetooth device operation command type is marked, and then a uniform operation object carrying the mark is generated. Subsequent operations on the bluetooth device, whether the operations are read command operations, write command operations or notification command operations, only need to operate the finally generated unified operation object carrying the read command mark, write command mark or notification command mark.
Further, referring to fig. 6, the processing of the unified operation object in the bluetooth command processing queue includes the following steps:
calling an operation command processing interface of a corresponding type;
and returning the calling result to the callback interface and returning the prompt message of the command operation result.
Based on the above embodiments, in the third embodiment of the present invention, when processing the unified operation object entering the bluetooth command processing queue, first, an operation command interface of a corresponding type should be called, for example, if the unified operation object is a read command, an interface corresponding to the read command should be called to perform a corresponding operation of "read"; then calling a result and returning to a callback interface, and returning prompt information of the command operation result, wherein the command operation result has three types, success, failure and overtime; for example, the operation result of the "read command" is "success", or "failure", or "timeout".
Further, the prompt information of the command operation result comprises success, failure and timeout.
Referring to fig. 7, the timeout determining step is as follows:
s400: the timer starts to time;
s401: judging whether the time is out;
s402: if so, calling a failure callback interface to start processing the next command;
s403: if not, waiting for the Bluetooth equipment to respond;
further, referring to fig. 8, after the call result returns to the callback interface and returns the prompt information of the command operation result, the method further includes the following steps:
s5, judging whether there is any command in the Bluetooth command processing queue;
s6, if yes, continuing to execute the operation commands in the queue in sequence;
and S7, if not, waiting for adding the uniform operation object to the Bluetooth command processing queue for processing.
In the fourth embodiment of the invention, the operation commands put into the Bluetooth command processing queue are processed according to the sequence of the operation commands in the queue; after the first command is processed, whether the command which is not operated is in the Bluetooth command processing queue or not is judged, if the command which is not operated is in the Bluetooth command processing queue, the command which is not operated is processed continuously according to the sequence, and if all the commands in the queue are processed, the operation is carried out after waiting for a new command to be put into the queue. For example, there are 8 commands to be processed in a bluetooth command processing queue, and the commands are processed in the order of 1-8 from first to last; 1 is treated first, 2 is operated later than 1, and so on, 8 is treated last. And when all the 1-8 commands are processed, waiting for new commands to be added into the queue again and then processing.
Further, the unified operation objects in the bluetooth command processing queue are processed, and the unified operation objects are processed according to a first-in-first processing sequence.
The order of the commands in the Bluetooth command processing queue is processed according to the principle of first-in-first processing. Such as 1-8 pending commands in the queue, 1 being the first to enqueue, 2 being the second to enqueue, and so on, 8 being the last command processed.
In a second aspect, referring to fig. 9, the present invention further provides a system for processing an operation command of a bluetooth device, including
The encapsulation generation module 1 encapsulates the operation command of the Bluetooth equipment according to a preset rule and generates a uniform operation object;
the device comprises an encapsulation generating module 1, a storage module and a processing module, wherein the encapsulation generating module 1 is used for encapsulating operation commands of the Bluetooth equipment and generating uniform operation objects, and the operation commands of the Bluetooth equipment mainly comprise three types, namely a read command, a write command and a notification command; the three commands are packaged according to preset rules, wherein the rules are that the operation command type and the result of the Bluetooth equipment are returned to the callback interface and the format of the transmitted data frame is encrypted and checked to be packaged together, and a uniform operation object is generated, namely, the read, write and notification operation commands are packaged together to generate a uniform operation object; if there are many operation commands, it will generate many common operations, and different common operations correspond to different operation results.
The adding module 3 is used for adding the uniform operation object into a Bluetooth command processing queue;
the bluetooth processing queue is only one, the unified operation object common generated by packaging is added into the bluetooth processing queue through the adding module 3, and when a plurality of common operations exist, the operations are sequentially processed according to the sequence of different common operations entering the queue.
And the processor module 2 is used for processing the uniform operation objects in the Bluetooth command processing queue.
The processor module 2 is used for processing the unified operation objects in the Bluetooth command processing queue according to the principle that the unified operation objects enter the queue first and then are processed first.
In a third aspect, the present invention also provides a readable storage medium storing one or more programs, the one or more programs being executable by one or more processors to implement the steps of the method for processing bluetooth device operation commands as claimed in any one of claims 1 to 8.
Further, the present invention provides a readable storage medium, on which one or more computer programs are stored, and the computer programs, when executed by a processor, implement the processing method of the bluetooth device operation command of the above embodiments.
The processing method or system of the bluetooth device operation command, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in the readable storage medium. Based on such understanding, all or part of the flow in the method of implementing the above embodiments of the present invention may also be implemented by hardware related to computer program instructions.
The computer program may be stored in a readable storage medium, which is a computer readable storage medium, and when being executed by a processor module, the computer program may implement the steps of the embodiments of the processing method for operating commands of a bluetooth device, where the computer program includes computer program code, and the computer program code may be in a source code form, an object code form, an executable file or some intermediate file form, and the like. The computer-readable storage medium may include: any entity or device capable of carrying the computer program code, recording media, U-disk, removable hard disk, magnetic diskette, optical disk, computer memory, random access memory, software distribution media and the like.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; within the idea of the invention, also technical features in the above embodiments or in different embodiments may be combined, steps may be implemented in any order, and there are many other variations of the different aspects of the invention as described above, which are not provided in detail for the sake of brevity; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.