Bluetooth communication based on response type and Bluetooth communication method
Technical field
The present invention relates to computer communication fields, specifically, being to be related to a kind of bluetooth communication based on response type
And Bluetooth communication method.
Background technology
Bluetooth (Bluetooth) is a kind of short-distance wireless communication technology, is operated in for Alternative digital equipment tooth equipment
The wireless networking between cable coupling and realization digital device between computer peripheral equipment.In May, 1998 is by Ericsson, IBM, English
5 company such as Te Er, Nokia, Toshiba has set up Bluetooth Special Interest group (SIG), is responsible for joint and formulates Bluetooth specification.It is blue
Tooth is operated in the unified and open 2.4GHz industry in the whole world, science, medicine (Industrial Scientific Medical) frequency
Section can share channel width with simultaneous transmission data and voice, at most 8 movable bluetooth equipments, form so-called
Gram net (piconet).In each piconet, it is bluetooth master to have 1, remaining 7 are that may be allowed simultaneously from equipment
Have and is more locked to main equipment in a manner of suspending (park) from equipment.Multiple picon-et can be overlapped.It is formed and is dissipated
Penetrate net (scattern-et).
The Bluetooth specification that SIG is promulgated is exactly Bluetooth wireless communication consensus standard, it defines what bluetooth applications should follow
Standard and need requirement to be achieved, including core protocol (Core) and application framework (Profiles) two parts.Protocol specification portion
Divide each layer communication protocol for defining bluetooth, it then follows open system interconnection reference model defines Bluetooth protocol from low to high
Storehouse it is at all levels.According to the logic function of Bluetooth protocol, protocol stack is divided into three parts from the bottom to top:Transport protocol,
Broker protocol and application protocol.
Bluetooth module is a kind of PCBA board of integrated Bluetooth function, is used for short-distance wireless communication, is divided into bluetooth by function
Data module and blue tooth voice module.Bluetooth module in the prior art is all to need multiple step setting behaviour in compiling procedure
Make, multiple readjustment.
Invention content
Can technical problem to be solved by the invention is to provide a kind of bluetooth based on response type that avoid multiple readjustment
Communication module and Bluetooth communication method, the bluetooth communication can realize interaction between bluetooth equipment, avoid interim card.
In order to solve the above technical problems, the present invention provides a kind of bluetooth communication based on response type, it is located at movement
In terminal, including instruction dispensing unit, search unit, data transmission unit, instruction control unit, hardware push unit, switch
Unit, operation abstraction unit, status control unit and Date Conversion Unit, described search unit, data transmission unit, instruction control
Unit, hardware push unit and switch unit processed are encapsulated in the same package module, the package module respectively with described instruction
Dispensing unit is mutually coupled with operation abstraction unit, the data transmission for being uniformly processed between bluetooth equipment, wherein
Described instruction dispensing unit, respectively with parallel described search unit, data transmission unit, instruction control unit,
Hardware push unit is mutually coupled with switch unit, for described search unit, data transmission unit, instruction control unit, hard
Part push unit and switch unit carry out instruction configuration, send search instruction to search unit, transmission data transmission instruction to institute
It states data transmission unit, send operational order to described instruction control unit, transmission hardware trigger push instruction to the hardware
Push unit and switch order is sent to the switch unit;
Described search unit is mutually coupled with described instruction dispensing unit and operation abstraction unit respectively, described for receiving
The search instruction for instructing dispensing unit to send, and execute search instruction and obtain nearby just in whole bluetooth equipments of broadcast state,
The bluetooth equipment data searched are sent to the operation abstraction unit;
The data transmission unit mutually couples respectively with described instruction dispensing unit and operation abstraction unit, for receiving
The data transfer instruction that described instruction dispensing unit is sent, by actual data transfer to the operation abstraction unit, the reality
Data refer to the data transmitted when the mobile terminal is interacted with bluetooth equipment;
Described instruction control unit mutually couples respectively with described instruction dispensing unit and operation abstraction unit, for receiving
The operational order that described instruction dispensing unit is sent, cooperates with the operation abstraction unit and completes operational order, and the operation refers to
Order refer to the application program of the mobile terminal send out binding instruction, Planning Directive and unbinding;
The hardware push unit mutually couples respectively with described instruction dispensing unit and operation abstraction unit, for receiving
The hardware trigger push instruction that described instruction dispensing unit is sent, executes hardware trigger push operation, hardware trigger data is passed
It send to operation abstraction unit;
The switch unit is mutually coupled with described instruction dispensing unit and operation abstraction unit respectively, described for receiving
The switch order for instructing dispensing unit to send will determine that the data transfer instruction, operational order and hardware trigger push refer to
The switch order whether transmitted is enabled to be sent to the operation abstraction unit;
The operation abstraction unit, it is single with the parallel described search unit, data transmission unit, instruction control respectively
Member, hardware push unit are mutually coupled with switch unit and status control unit, the indigo plant for receiving the transmission of described search unit
Operational order, the hardware push unit of tooth device data, the real data that the data transmission unit is sent, instruction control unit
The switch order whether transmitted that the hardware trigger data and switch unit of transmission are sent is sent to the state control after processing
Unit;
The status control unit mutually couples respectively with the operation abstraction unit and Date Conversion Unit, for receiving
After the operation abstraction unit treated instruction and data, judged whether normally to get the data, it is normal to obtain
After be sent to the Date Conversion Unit;
The Date Conversion Unit is mutually coupled with the status control unit, for receiving in the status control unit
The data normally obtained are converted to readable data.
Preferably, further include bluetooth module communication interface, be located in the package module, connect with the package module,
For the Bluetooth commands blue-teeth data transmitting defined in instruction dispensing unit, the Bluetooth commands are binding, unbundlings, send
The operational order of plan, the blue-teeth data refer to the scrutable data of bluetooth equipment.
Preferably, the Date Conversion Unit is also mutually coupled with Basic API, for character string to be converted to byte, then general
Byte conversion is 16 system bytes, and is sent to the Basic API.
The method that the bluetooth communication that disclosed herein as well is a kind of using above-mentioned based on response type carries out Bluetooth communication,
Applied between mobile terminal and bluetooth equipment, including step:
Instruction configuration is carried out, described instruction includes search instruction, data transfer instruction, operational order, hardware trigger push
Instruction and switch order;
To described search instruction, data transfer instruction, operational order, hardware trigger push instruction and switch order into
Row encapsulation;
Execute described search instruction, data transfer instruction, operational order, hardware trigger push instruction and switch order:
It obtains nearby just in whole bluetooth equipments of broadcast state, the bluetooth equipment data searched is sent to operation level of abstraction;It will
Actual data transfer is to the operation level of abstraction;It cooperates with the operation level of abstraction and completes operational order, the operational order is
Refer to binding instruction, Planning Directive that the application program of the mobile terminal sends out and unbinding;Execute hardware trigger push
Operation, by hardware trigger data transmission to operating level of abstraction;Determine that the data transfer instruction, operational order and hardware touch
Whether hair push instruction is transmitted, and is sent to operation level of abstraction;
Operate level of abstraction to after execution search instruction, data transfer instruction, operational order, hardware trigger push instruction,
And switch order carries out data processing, and state control layer is sent to after processing;
State control layer judges whether normally to get the data, it is normal obtain after be sent to the data conversion layer;
Data conversion layer receives the data obtained in the state control layer, is converted to readable data.
Preferably, by described search instruction, data transfer instruction, operational order, hardware trigger push instruction and switch
Instruction be encapsulated in a package module, by between the package module and bluetooth equipment carry out data transmission and data turn
It changes.
Preferably, character string is converted to byte by the data conversion layer, then by byte conversion is 16 system bytes, concurrently
It send to Basic API.
Compared with prior art, bluetooth communication and Bluetooth communication method of the present invention based on response type, reach
Following effect is arrived:
1) bluetooth communication based on response type of the application and Bluetooth communication method are used using command mode as framework
Response type designs bluetooth communication, is encapsulated to bluetooth communication, code is write using response type, avoided multiple
Readjustment, can significantly simplified code;
2) module that this encapsulation is designed using the framework of command mode, makes the use of module more succinct;
3) with command mode framework in the application, Bluetooth communication (news) module is write using response type, it is logical using the bluetooth
Believe that module can be to need the application program of Bluetooth communication (news);More smooth user experience and simpler use are brought, is kept away
Exempt from application program interim card.
Description of the drawings
Attached drawing described herein is used to provide further understanding of the present invention, and constitutes the part of the present invention, this hair
Bright illustrative embodiments and their description are not constituted improper limitations of the present invention for explaining the present invention.In the accompanying drawings:
Fig. 1 is the bluetooth communication structure chart based on response type of embodiment 1;
Fig. 2 is the Bluetooth communication method flow chart based on response type of embodiment 2.
Specific implementation mode
Some vocabulary has such as been used to censure specific components in specification and claim.Those skilled in the art answer
It is understood that hardware manufacturer may call the same component with different nouns.This specification and claims are not with name
The difference of title is used as the mode for distinguishing component, but is used as the criterion of differentiation with the difference of component functionally.Such as logical
The "comprising" of piece specification and claim mentioned in is an open language, therefore should be construed to " include but do not limit
In "." substantially " refer in receivable error range, those skilled in the art can be described within a certain error range solution
Technical problem basically reaches the technique effect.In addition, " coupling " word includes any direct and indirect electric property coupling herein
Means.Therefore, if it is described herein that a first device is coupled to a second device, then representing the first device can directly electrical coupling
It is connected to the second device, or the second device indirectly electrically coupled through other devices or coupling means.Specification
Subsequent descriptions be implement the present invention better embodiment, so it is described description be by illustrate the present invention rule for the purpose of,
It is not limited to the scope of the present invention.Protection scope of the present invention is when subject to appended claims institute defender.
Below in conjunction with attached drawing, invention is further described in detail, but not as a limitation of the invention.
Embodiment 1:
In conjunction with Fig. 1, a kind of bluetooth communication and Bluetooth communication method based on response type are present embodiments provided, with life
Pattern architecture is enabled, bluetooth communication is designed using response type, is specifically included:Instruct dispensing unit 101, search unit 102, number
According to transmission unit 103, instruction control unit 104, hardware push unit 105, switch unit 106, operation abstraction unit 107, shape
State control unit 108 and Date Conversion Unit 109, wherein
Described instruction dispensing unit 101, respectively with parallel described search unit 102, data transmission unit 103, instruction
Control unit 104, hardware push unit 105 and switch unit 106 mutually couple, for described search unit 102, data transmission
Unit 103, instruction control unit 104, hardware push unit 105 and switch unit 106 carry out instruction configuration, send search instruction
To search unit 102, transmission data transmission instruction to the data transmission unit 103, operational order is sent to described instruction control
Unit 104 processed sends hardware trigger push instruction to the hardware push unit 105 and sends switch order and opened to described
Close unit 106;
Described search unit 102 is used for respectively with described instruction dispensing unit 101 and operation 107 phase of abstraction unit coupling
The search instruction that described instruction dispensing unit 101 is sent is received, and executes search instruction and obtains nearby just in the complete of broadcast state
The bluetooth equipment data searched are sent to the operation abstraction unit 107 by portion's bluetooth equipment;
The data transmission unit 103 is coupled with described instruction dispensing unit 101 and operation 107 phase of abstraction unit respectively,
Data transfer instruction for receiving the transmission of described instruction dispensing unit 101, actual data transfer is abstract single to the operation
Member 107;
Mobile terminal is by Bluetooth transmission to information such as the data of medicine box, such as medicine box token
Described instruction control unit 104 is coupled with described instruction dispensing unit 101 and operation 107 phase of abstraction unit respectively,
Operational order for receiving the transmission of described instruction dispensing unit 101, the completion operation that cooperates with the operation abstraction unit 107 refer to
It enables;Here operational order refers specifically to binding instruction, sends the medicine boxs control instruction such as Planning Directive, unbinding.
The hardware push unit 105 is coupled with described instruction dispensing unit 101 and operation 107 phase of abstraction unit respectively,
Hardware trigger for receiving the transmission of described instruction dispensing unit 101 pushes instruction, hardware trigger push operation is executed, by hardware
Trigger data is sent to operation abstraction unit 107;
The switch unit 106 is used for respectively with described instruction dispensing unit 101 and operation 107 phase of abstraction unit coupling
The switch order that described instruction dispensing unit 101 is sent is received, will determine the data transfer instruction, operational order and hard
The switch order whether part triggering push instruction is transmitted is sent to the operation abstraction unit 107;
Switch unit open and close state is determined that acquiescence is factory set conditions by hardware firmware, passes through later stage firmware version
This upgrading can change assigned switch order and determine that switch is to open or close.
The operation abstraction unit 107, respectively with the parallel described search unit 102, data transmission unit 103,
Instruction control unit 104, hardware push unit 105 and switch unit 106 and status control unit 108 mutually couple, for connecing
Receive the bluetooth equipment data of 102 transmission of described search unit, the real data that the data transmission unit 103 is sent, instruction control
Whether the operational order of unit 104 processed, the hardware trigger data of the transmission of hardware push unit 105 and the transmission of switch unit 106
The switch order of transmission is sent to the status control unit 108 after processing;
The status control unit 108 is coupled with the operation abstraction unit 107 and 109 phase of Date Conversion Unit respectively,
After instruction that treated for receiving the operation abstraction unit 107 and data, judged whether normally to get specified number
According to, it is normal obtain after be sent to the Date Conversion Unit 109;
Middle finger fixed number of the present invention is according to being the practical clothes for returning to application program for mobile terminal after the complete instruction of medicine box hardware handles
The information such as medicine record are packaged and return to the state successfully to fail.
The Date Conversion Unit 109 is coupled with 108 phase of the status control unit, for receiving the state control
The data normally obtained in unit 108 are converted to readable data.
Described search unit 102, data transmission unit 103, instruction control unit 104, hardware push unit 105 and switch
Unit 106 is encapsulated in the same package module, and the package module is abstract single with described instruction dispensing unit 101 and operation respectively
First 107 phases coupling, data transmission and data conversion for being uniformly processed between bluetooth equipment.
The bluetooth communication further includes bluetooth module communication interface, is located in the package module, with the Encapsulation Moulds
Block connects, for according to Bluetooth commands blue-teeth data transmitting good defined in instruction dispensing unit 101.
Bluetooth commands include binding, unbundlings, send the practical operations such as plan instruction, and blue-teeth data refers to according to Bluetooth protocol
The scrutable data of specified bluetooth equipment, such as including detailed associated datas such as binding, unbundlings, practical dosing regimens.
The Date Conversion Unit 109 is also coupled with 110 phase of Basic API, for character string to be converted to byte, then general
Byte conversion is 16 system bytes, and is sent to the Basic API 110.Command mode in the application refers to java design moulds
" command mode " inside formula, when application software and hardware device on mobile terminal (mobile phone) interact, there are four types of behaviors:Search
Bluetooth equipment, to equipment transmission data (instruction and general data may be referred to collectively as transmission data), the data of receiving device.
By taking the medicine box of applicant as an example, application program of mobile phone APP can formulate a dosing regimens and be sent to pill box storage,
Medicine box can also be controlled to go to play an order, can also be when medicine box detect that user has eaten medicine, proactive notification mobile phone
Application APP, although these interactive processes are all different operation, essence be all send instructions, receive data, search,
Connect this four most basic behaviors (can be understood as all be by these behavior combinations at).Different parameters can be set
To generate different operations.
So, it is the package module that a software has been fabricated separately in the application, these types behavior is respectively packaged into one
A object, application program (APP) need not carry out data interaction with the API of bluetooth bottom again.One specific application APP
The order of control bluetooth equipment of course not sends individual instructions, it may be necessary to and several instructing combinations are got up, such as:It is set with bluetooth
Standby connect is to need first to search for, and then establishes connection, then the switch that data are received inside bluetooth is opened.These three steps
It has been combined into a complete behavior.These three behaviors are packaged into a complete object (Encapsulation Moulds so in the application
Block), this object, which just becomes, at this time has a command object of concrete behavior (operation), this is order described herein
Pattern.When need this behavior (operation) when, call this package module it is all right, used compared to assembling bluetooth
Each step will save many steps.
Bluetooth interaction is an asynchronous process, and application APP interface is stuck in order to prevent, and the application is using response type
Literary style writes this module, application APP can be prevented to be stuck.Key technology is that several asynchronous operations are ined succession progress
When, response type frame is after having executed first step, and second step is triggered by first, then after second step
Third step is triggered, in the management of step, response type it is with better function.
Search unit 102 is called by instruction control unit 104 after searching and binds bluetooth equipment instruction, is operated abstract single
Member 107 encapsulates binding information, and binding data (such as token information) is sent to data conversion by data transmission unit 103
Unit 109 converts the data into the data that hardware device can identify, equipment receives the data of the transmission of data transmission unit 103
And after instruction corresponding hardware logic processing is carried out by 110 Basic APIs, and treated result and state are pushed by hardware
Unit 105 returns to status control unit 108, and switch unit 106 is a hardware manufacture configuration information, can pass through hardware
Firmware upgrade adjusts some on off states.
Embodiment 2:
In conjunction with Fig. 2, a kind of Bluetooth communication method based on response type is present embodiments provided, is applied between bluetooth equipment
Communication, including step:
Step 201:Instruction configuration is carried out, described instruction includes search instruction, data transfer instruction, operational order, hardware
Triggering push instruction and switch order;
Step 202:To described search instruction, data transfer instruction, operational order, hardware trigger push instruction, Yi Jikai
Instruction is closed to be packaged;
By described search instruction, data transfer instruction, operational order, hardware trigger push instruction and switch order envelope
In a package module, by between the package module and bluetooth equipment carry out data transmission and data conversion.
Step 203:Execute described search instruction, data transfer instruction, operational order, hardware trigger push instruct and
Switch order:It obtains nearby just in whole bluetooth equipments of broadcast state, the bluetooth equipment data searched is sent to operation
Level of abstraction;By actual data transfer to the operation level of abstraction;It cooperates with the operation level of abstraction and completes operational order, the behaviour
Make binding instruction, the Planning Directive and unbinding that the application program that instruction refers to the mobile terminal is sent out;Execute hardware
Push operation is triggered, hardware trigger data transmission to operation is abstracted single layer;Determine the data transfer instruction, operational order,
And whether hardware trigger push instruction is transmitted, and it is sent to operation level of abstraction;
Step 204:Operation level of abstraction pushes away the search instruction after execution, data transfer instruction, operational order, hardware trigger
It send instruction and switch order to carry out data processing, state control layer is sent to after processing;
Step 205:State control layer judges whether normally to get specified data, it is normal obtain after be sent to the data
Conversion layer;
Step 206:Data conversion layer receives the data normally obtained in the state control layer, is converted to readable number
According to.Character string is converted to byte by the data conversion layer, then by byte conversion is 16 system bytes.
It further include step 207:Data conversion coating is by 16 system bytes and is sent to Basic API.
Binding bluetooth equipment instruction, behaviour are called by instruction control unit after search unit searches in actual application
Make abstraction unit to encapsulate binding information, binding data (such as token information) is sent to data by data transmission unit to be turned
It changes unit and converts the data into data such as 16 system bytes, bluetooth equipment that hardware device can identify and receive data transmission list
Corresponding hardware logic processing is carried out by Basic API after the data of member transmission and instruction, and treated result and state are led to
It crosses hardware push unit and returns to status control unit, switch unit is a hardware manufacture configuration information, can pass through hardware
Firmware upgrade adjust some on off states.
Embodiment 3:
On the basis of embodiment 1, the present embodiment is Application Example, and the bluetooth communication provided in the present embodiment is
One service medicine box that can influence application APP, medicine box mentioned in the present invention are comprising fixer system (Basic API)
Intelligent hardware, function is mainly to receive the incoming data in upper layer and various orders are simultaneously handled, and replying mobile terminal (mobile phone) needs
The response wanted simultaneously reminds (such as sounding reminding) from the dosing regimens of main response user setting.
For medicine box when binding, the application APP interface prompts user binding of mobile terminal (mobile phone) notifies medicine box
Preparing to be bound, after medicine box has received the instruction of preparation, sounding reminding user taps medicine box and is confirmed with showing, after user taps, medicine
Box notice application APP user has tapped.After application program of mobile phone APP is notified, change interface display binding is completed.
Using the mode of response type, these steps all completely carry out one by one, previous not complete
Cheng Shi, program can wait for, and this waiting will not cause main thread to block, this is response type is used in the application good
Place.What the bluetooth communication based on response type and command mode framework of the application was is exactly that application APP is allowed to use
When function of Bluetooth communication, the object for simply calling some to order is adjusted back without repeating.
For medicine box under binding state, the application program of mobile terminal (mobile phone) is synchronized pre-set carry with medicine box
It wakes up information, is reminded the moment when time is up, medicine box actively triggering can remind operation, and pushed information is to mobile terminal (mobile phone),
After opening medicine box and opening medicine box stop operation triggering in 10 seconds, medicine box can generate a practical medication and record user, and will clothes
Medicine record information is pushed to mobile terminal (mobile phone), and mobile terminal through the invention can be by transformed letter after module data processing
Breath is synchronized to mobile terminal (mobile phone) interface, reaches medicine box prompting and the visible practical medication state of mobile phone.
Compared with prior art, bluetooth communication and Bluetooth communication method of the present invention based on response type, reach
Following effect is arrived:
1) encapsulation has been carried out to bluetooth communication in the application, code is write using response type, is avoided multiple
Readjustment, can significantly simplified code;
2) module that this encapsulation is designed using the framework of command mode, makes the use of module more succinct;
3) with command mode framework in the application, Bluetooth communication (news) module is write using response type, it is logical using the bluetooth
Believe that module can be that the application program of Bluetooth communication (news) is needed to bring more smooth user experience and simpler use, avoids
Application program interim card.
Several preferred embodiments of the present invention have shown and described in above description, but as previously described, it should be understood that the present invention
Be not limited to form disclosed herein, be not to be taken as excluding other embodiments, and can be used for various other combinations,
Modification and environment, and the above teachings or related fields of technology or knowledge can be passed through in the scope of the invention is set forth herein
It is modified.And changes and modifications made by those skilled in the art do not depart from the spirit and scope of the present invention, then it all should be in this hair
In the protection domain of bright appended claims.