Bluetooth communication based on response type and Bluetooth communication method
Technical field
The present invention relates to computer communication field, specifically, it is 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, operates in for Alternative digital equipment tooth equipment
Cable and between computer peripheral equipment couples and realizes the wireless networking between digital device.In May, 1998 is by Ericsson, IBM, English
Company of Te Er, Nokia, Toshiba etc. 5 has set up Bluetooth Special Interest group (SIG), is responsible for joint formulation Bluetooth specification.Blue
Tooth is operated in the unified and open 2.4GHz industry in the whole world, science, medical science (Industrial Scientific Medical) frequently
Section, can be with simultaneous transmission data and voice, and at most 8 movable bluetooth equipments can form so-called with shared channel bandwidth
Gram net (piconet).In each piconet, 1 is had to be bluetooth master, remaining 7 is from equipment, may be allowed to simultaneously
Have and more lock onto main equipment from equipment in the way of suspending (park).Multiple picon-et can be overlapped.Formed and dissipate
Penetrate net (scattern-et).
The Bluetooth specification that SIG is promulgated is exactly Bluetooth wireless communication consensus standard, and it defines what bluetooth applications should be followed
The requirement that standard reaches with needs, including core protocol (Core) and application framework (Profiles) two parts.Protocol specification portion
Divide each layer communication protocol defining bluetooth, it then follows open system interconnection reference model, define Bluetooth protocol from low to high
Storehouse at all levels.According to the logic function of Bluetooth protocol, protocol stack is divided into three parts from the bottom to top:Host-host protocol,
Broker protocol and application protocol.
Bluetooth module, is a kind of PCBA board of integrated Bluetooth function, for short-distance wireless communication, is divided into bluetooth by function
Data module and blue tooth voice module.Bluetooth module of the prior art is all to need multiple step setting behaviour in compiling procedure
Make, multiple readjustment.
Content of the invention
Can the technical problem to be solved be to provide a kind of bluetooth based on response type that avoid multiple readjustment
Communication module and Bluetooth communication method, this bluetooth communication can be realized interacting between bluetooth equipment, it is to avoid interim card.
For solving above-mentioned technical problem, the invention provides a kind of bluetooth communication based on response type, positioned 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 unit data converting unit, described search unit, data transmission unit, instruction control
Unit processed, hardware push unit and switch element are encapsulated in same package module, this package module respectively with described instruction
Dispensing unit mutually couples with operation abstraction unit, for the data transfer that is uniformly processed and bluetooth equipment between and data conversion,
Wherein,
Described instruction dispensing unit, respectively with parallel described search unit, data transmission unit, instruction control unit,
Hardware push unit mutually couples with switch element, for described search unit, data transmission unit, instruction control unit, hard
Part push unit and switch element carry out instruction configuration, send search instruction to search unit, transmission data transfer instruction to institute
State data transmission unit, send operational order to described instruction control unit, transmission hardware trigger push instruction to described hardware
Push unit and transmission switch order are to described switch element;
Described search unit, is coupled with described instruction dispensing unit and operation abstraction unit phase respectively, described for receiving
The search instruction that instruction dispensing unit sends, and execute search instruction acquisition nearby just in whole bluetooth equipments of broadcast state,
By the bluetooth equipment searching data is activation to described operation abstraction unit;
Described data transmission unit, is coupled with described instruction dispensing unit and operation abstraction unit phase, respectively for receiving
The data transfer instruction that described instruction dispensing unit sends, by actual data transfer to operating described operation abstraction unit, described
Real data refers to the data transmitted when described mobile terminal is interacted with bluetooth equipment;
Described instruction control unit, is coupled with described instruction dispensing unit and operation abstraction unit phase, respectively for receiving
The operational order that described instruction dispensing unit sends, is cooperated with described operation abstraction unit and completes operational order, described operation refers to
Order refers to binding instruction, Planning Directive that the application program of described mobile terminal sends and unbinding;
Described hardware push unit, is coupled with described instruction dispensing unit and operation abstraction unit phase, respectively for receiving
The hardware trigger that described instruction dispensing unit sends pushes instruction, executes hardware trigger push operation, hardware trigger data is passed
Deliver to operation abstraction unit;
Described switch element, is coupled with described instruction dispensing unit and operation abstraction unit phase respectively, described for receiving
The switch order that instruction dispensing unit sends, determines that described data transfer instruction, operational order and hardware trigger push instruction
The switch order whether transmitted is to described operation abstraction unit;
Described operation abstraction unit, controls single respectively with described parallel described search unit, data transmission unit, instruction
Unit, hardware push unit mutually couple with switch element and status unit, for receiving the indigo plant that described search unit sends
Tooth device data, the real data of described data transmission unit transmission, the operational order of instruction control unit, hardware push unit
The hardware trigger data sending and the switch order whether transmitted of switch element transmission, send after process and control to described state
Unit;
Described status unit, is coupled with described operation abstraction unit data converting unit phase, respectively for receiving
After instruction after described operation abstraction unit process and data, carry out judging whether normally to get described data, normal acquisition
After send to described Date Conversion Unit;
Described Date Conversion Unit, is coupled with described status unit phase, for receiving in described status unit
The normal data obtaining, is converted to readable data.
Preferably, also include bluetooth module communication interface, in described package module, be connected with described package module,
For the Bluetooth commands blue-teeth data transmitting according to defined in instruction dispensing unit, described Bluetooth commands are to bind, unbind, sending
The operational order of plan, described blue-teeth data refers to the scrutable data of bluetooth equipment.
Preferably, described Date Conversion Unit, is also coupled with Basic API phase, for character string is converted to byte, then will
Byte conversion is 16 system bytes, and sends to described Basic API.
Disclosed herein as well is a kind of method carrying out Bluetooth communication using the above-mentioned bluetooth communication based on response type,
It is applied between mobile terminal and bluetooth equipment, including step:
Carry out instruction configuration, 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 pushes instruction and switch order is entered
Row encapsulation;
Execute described search instruction, data transfer instruction, operational order, hardware trigger push instruction and switch order:
Obtain nearby just in whole bluetooth equipments of broadcast state, by the bluetooth equipment searching data is activation to operating level of abstraction;Will
Actual data transfer is to operating described operation level of abstraction;Cooperate with described operation level of abstraction and complete operational order, described operation refers to
Order refers to binding instruction, Planning Directive that the application program of described mobile terminal sends and unbinding;Execution hardware trigger
Push operation, hardware trigger data is sent to operation level of abstraction;Determine described data transfer instruction, operational order and hard
Part triggering pushes whether instruction is transmitted, and sends to operation level of abstraction;
Operation level of abstraction to execution after search instruction, data transfer instruction, operational order, hardware trigger push instruction,
And switch order carries out data processing, send after process to state key-course;
State key-course judges whether normally to get described data, sends to described data conversion layer after normal acquisition;
Data conversion layer, receives the data obtaining in described state key-course, is converted to readable data.
Preferably, described search instruction, data transfer instruction, operational order, hardware trigger are pushed instruction and switch
Instruction is encapsulated in a package module, is turned by carrying out data transmission between this package module and bluetooth equipment and data
Change.
Preferably, character string is converted to byte by described data conversion layer, then byte conversion is 16 system bytes, concurrently
Deliver to Basic API.
Compared with prior art, the bluetooth communication based on response type of the present invention and Bluetooth communication method, reach
Arrive following effect:
1) bluetooth communication based on response type of the application and Bluetooth communication method, with command mode as framework, adopt
Response type designs bluetooth communication, bluetooth communication is encapsulated, writes code using response type, it is to avoid multiple
Readjustment, can significantly simplified code;
2) to design the module of this encapsulation using the framework of command mode, to make the use of module more succinct;
3) with command mode framework in the application, Bluetooth communication (news) module is write using response type, led to using this bluetooth
Letter module can be the application program needing Bluetooth communication (news);Bring more smooth Consumer's Experience and simpler use, keep away
Exempt from application program interim card.
Brief description
Accompanying drawing described herein is used for providing a further understanding of the present invention, constitutes the part of the present invention, this
Bright schematic description and description is used for explaining the present invention, does not constitute inappropriate limitation of 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 embodiment
To censure specific components as employed some vocabulary in the middle of description and claim.Those skilled in the art should
It is understood that hardware manufacturer may call same assembly with different nouns.This specification and claims are not with name
The difference claiming is used as distinguishing the mode of assembly, but difference functionally is used as the criterion distinguished with assembly.As logical
In the middle of piece description and claim, mentioned "comprising" is an open language, therefore should be construed to " comprise but do not limit
In "." substantially " refer in receivable range of error, those skilled in the art can solve described in the range of certain error
Technical problem, basically reaches described technique effect.Additionally, " coupling " word here comprises any directly and indirectly electric property coupling
Means.Therefore, if a first device is coupled to a second device described in literary composition, representing described first device can direct electrical coupling
It is connected to described second device, or be indirectly electrically coupled to described second device by other devices or the means that couple.Description
Subsequent descriptions are to implement the better embodiment of the present invention, and so described description is for the purpose of the rule that the present invention is described,
It is not limited to the scope of the present invention.Protection scope of the present invention ought be defined depending on the defined person of claims.
Below in conjunction with accompanying drawing, the present invention is described in further detail, but not as a limitation of the invention.
Embodiment 1:
In conjunction with Fig. 1, present embodiments provide a kind of bluetooth communication based on response type and Bluetooth communication method, to order
Make pattern architecture, bluetooth communication is designed using response type, specifically includes:Instruction dispensing unit 101, search unit 102, number
According to transmission unit 103, instruction control unit 104, hardware push unit 105, switch element 106, operation abstraction unit 107, shape
State control unit 108 data converting 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 mutually couple with switch element 106, for described search unit 102, data transfer
Unit 103, instruction control unit 104, hardware push unit 105 and switch element 106 carry out instruction configuration, send search instruction
To search unit 102, send data transfer instruction to described data transmission unit 103, transmission operational order to described instruction control
Unit 104 processed, send hardware trigger and push instruction and to described hardware push unit 105 and send switch order and open to described
Close unit 106;
Described search unit 102, is mutually coupled with described instruction dispensing unit 101 and operation abstraction unit 107 respectively, is used for
Receive the search instruction that described instruction dispensing unit 101 sends, and it is just complete in broadcast state nearby to execute search instruction acquisition
Portion's bluetooth equipment, by the bluetooth equipment searching data is activation to described operation abstraction unit 107;
Described data transmission unit 103, is mutually coupled with described instruction dispensing unit 101 and operation abstraction unit 107 respectively,
For receiving the data transfer instruction that described instruction dispensing unit 101 sends, by actual data transfer to operating described operation to take out
As unit 107;
Mobile terminal is administered the data of box, the such as information such as medicine box token by Bluetooth transmission
Described instruction control unit 104, is mutually coupled with described instruction dispensing unit 101 and operation abstraction unit 107 respectively,
For receiving the operational order that described instruction dispensing unit 101 sends, cooperate with described operation abstraction unit 107 and complete operation and refer to
Order;Here operational order refers specifically to binding instruction, sends Planning Directive, the medicine box control instruction such as unbinding.
Described hardware push unit 105, is mutually coupled with described instruction dispensing unit 101 and operation abstraction unit 107 respectively,
Push instruction for receiving the hardware trigger that described instruction dispensing unit 101 sends, execute hardware trigger push operation, by hardware
Trigger data is sent to operation abstraction unit 107;
Described switch element 106, is mutually coupled with described instruction dispensing unit 101 and operation abstraction unit 107 respectively, is used for
Receive the switch order that described instruction dispensing unit 101 sends, determine described data transfer instruction, operational order and hardware
Triggering pushes and instructs the switch order whether transmitted to described operation abstraction unit 107;
Switch element open and close state is determined by hardware firmware, acquiescence is factory set conditions, by later stage firmware version
This upgrading can be changed assigned switch order and determine that switch opens or cuts out.
Described operation abstraction unit 107, respectively with described parallel described search unit 102, data transmission unit 103,
Instruction control unit 104, hardware push unit 105 mutually couple with switch element 106 and status unit 108, are used for connecing
Receive the bluetooth equipment data that described search unit 102 sends, real data that described data transmission unit 103 sends, instruction control
Whether the operational order of unit 104 processed, the hardware trigger data of hardware push unit 105 transmission and switch element 106 transmission
The switch order of transmission, sends after process to described status unit 108;
Described status unit 108, is mutually coupled with described operation abstraction unit 107 data converting unit 109 respectively,
For receiving after the instruction after described operation abstraction unit 107 is processed and data, carry out judging whether normally to get specified number
According to, normal obtain after send to described Date Conversion Unit 109;
Middle finger fixed number of the present invention is according to being the actual clothes 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 the state of successfully failure.
Described Date Conversion Unit 109, is mutually coupled with described status unit 108, controls for receiving described state
In unit 108, the normal data obtaining, is 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 same package module, and this package module instructs dispensing unit 101 and operates abstract list with described respectively
Unit 107 mutually couples, for the data transfer that is uniformly processed and bluetooth equipment between and data conversion.
This bluetooth communication also includes bluetooth module communication interface, in described package module, with described Encapsulation Moulds
Block connects, for good Bluetooth commands blue-teeth data transmitting according to defined in instruction dispensing unit 101.
The practical operation instruction such as Bluetooth commands include binding, unbind, transmission plan, blue-teeth data refers to according to Bluetooth protocol
The scrutable data of bluetooth equipment specified, for example, include binding, unbind, the associated data in detail such as actual dosing regimens.
Described Date Conversion Unit 109, is also mutually coupled with Basic API 110, for character string is converted to byte, then will
Byte conversion is 16 system bytes, and sends to described Basic API 110.Command mode in the application refers to java design mould
When " command mode " inside formula, the application software on mobile terminal (mobile phone) and hardware device interaction, there are four kinds of behaviors:Search
Bluetooth equipment, the data to equipment sending data (instruction and general data may be referred to collectively as sending data), receiving device.
, application program of mobile phone APP can formulate dosing regimens and be sent to pill box storage taking the medicine box of applicant as a example,
Medicine box can also be controlled to go to play an order, when medicine box can also be worked as user is detected and eaten medicine, proactive notification mobile phone
Application APP, although these interactions are all different operations, essence be all send instructions, accept data, search,
Connect this four most basic behaviors (can be understood as all being become) by these behavior combinations.Different parameters can be set
To produce different operations.
So, it is the package module that a software has been fabricated separately in the application, this several behavior is each packaged into one
Individual object, application program (APP) does not need to carry out data interaction with the API of bluetooth bottom again.One specific application APP
The order controlling bluetooth equipment of course not sends individual instructions it may be necessary to several instructing combinations, such as:Set with bluetooth
Standby coupling together is to need first to search for, and then sets up connection, then the switch of receiving data inside bluetooth is opened.These three steps
It has been combined into a complete behavior.So in the application, these three behaviors are packaged into complete object (Encapsulation Moulds
Block), now this object just becomes a command object possessing concrete behavior (operation), and this is order described herein
Pattern.When needing this behavior (operation), call this package module all right, use compared to assembling bluetooth
Each step will save a lot of steps.
Bluetooth interaction is an asynchronous process, and in order to prevent application APP interface stuck, the application adopts response type
Literary style, to write this module, can prevent application APP to be stuck.Key technology is that several asynchronous operations are ined succession and carried out
When, after response type framework has been carried out first step, second step is triggered by first, after then second step terminates
3rd step is triggered, in the management of step, response type with better function.
Search unit 102 calls binding bluetooth equipment instruction by instruction control unit 104 after searching, and operates abstract list
Binding information is encapsulated by unit 107, and binding data (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 data transmission unit 103 transmission
And carry out corresponding hardware logic process by 110 Basic APIs after instruction, and the result after processing and state are pushed by hardware
Unit 105 returns to status unit 108, and switch element 106 is that a hardware dispatches from the factory configuration information, can pass through hardware
Firmware upgrade is adjusting some on off states.
Embodiment 2:
In conjunction with Fig. 2, present embodiments provide a kind of Bluetooth communication method based on response type, be applied between bluetooth equipment
Communication, including step:
Step 201:Carry out instruction configuration, described instruction includes search instruction, data transfer instruction, operational order, hardware
Triggering pushes instruction and switch order;
Step 202:Instruction, Yi Jikai are pushed to described search instruction, data transfer instruction, operational order, hardware trigger
Close instruction to be packaged;
Described search instruction, data transfer instruction, operational order, hardware trigger are pushed instruction and switch order envelope
It is contained in a package module, by carrying out data transmission between this package module and bluetooth equipment and data conversion.
Step 203:Execute described search instruction, data transfer instruction, operational order, hardware trigger push instruction and
Switch order:Obtain nearby just in whole bluetooth equipments of broadcast state, by the bluetooth equipment searching data is activation to operation
Level of abstraction;By actual data transfer to operating described operation level of abstraction;Cooperate with described operation level of abstraction and complete operational order, institute
State the binding instruction that operational order refers to that the application program of described mobile terminal sends, Planning Directive and unbinding;Execution
Hardware trigger push operation, hardware trigger data is sent to the abstract monolayer of operation;Determine that described data transfer instruction, operation refer to
Make and hardware trigger pushes whether instruction is transmitted, and send to operation level of abstraction;
Step 204:Operation level of abstraction pushes away to the search instruction after execution, data transfer instruction, operational order, hardware trigger
Send instruction and switch order to carry out data processing, send after process to state key-course;
Step 205:State key-course judges whether normally to get specified data, sends to described data after normal acquisition
Conversion layer;
Step 206:Data conversion layer, receives the normal data obtaining in described state key-course, is converted to readable number
According to.Character string is converted to byte by described data conversion layer, then byte conversion is 16 system bytes.
Also include step step 207:Data conversion coating by 16 system bytes and sends to Basic API.
After search unit searches in actual application, binding bluetooth equipment instruction, behaviour are called by instruction control unit
Make abstraction unit to encapsulate binding information, binding data (as token information) is sent to data by data transmission unit and turns
Change unit and convert the data into the data such as 16 system byte that hardware device can identify, bluetooth equipment receives data transfer list
After the data of unit's transmission and instruction, corresponding hardware logic process is carried out by Basic API, and the result after processing and state are led to
Cross hardware push unit and return to status unit, switch element is that a hardware dispatches from the factory configuration information, can pass through hardware
Firmware upgrade adjusting some on off states.
Embodiment 3:
On the basis of embodiment 1, the present embodiment is Application Example, and the bluetooth communication providing in the present embodiment is
One service medicine box that can affect application APP, the medicine box being previously mentioned in the present invention is to comprise fixer system (Basic API)
Intelligent hardware, function be mainly receive the incoming data in upper strata and various order and process, replying mobile terminal (mobile phone) needs
The response wanted dosing regimens prompting (as sounding reminding) from main response user setup.
When binding, the application APP interface prompts user of mobile terminal (mobile phone) binds medicine box, notifies medicine box
Prepare bound, after medicine box have received the instruction of preparation, sounding reminding user taps medicine box to show confirmation, after user taps, medicine
Box notifies application APP user to tap.After application program of mobile phone APP is notified, change interface display binding completes.
Using the mode of response type, these steps are all completely carried out one by one, previous not complete
Cheng Shi, program can wait, and this wait does not result in main thread and blocks, and this is employ response type in the application good
Place.The application based on the bluetooth communication of response type and command mode framework be be exactly allow application APP use
When function of Bluetooth communication, simply call the object of certain order, need not repeat to adjust back.
Under binding state, the application program of mobile terminal (mobile phone) has been synchronized carrying of pre-setting to medicine box with medicine box
Awake information, reminds the moment when time is up, and 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 an actual medication and record user, and will take
Medicine record information is pushed to mobile terminal (mobile phone), and mobile terminal can be by the letter after conversion after module data of the present invention is processed
Breath is synchronized to mobile terminal (mobile phone) interface, reaches medicine box and reminds and the visible actual medication state of mobile phone.
Compared with prior art, the bluetooth communication based on response type of the present invention and Bluetooth communication method, reach
Arrive following effect:
1) in the application, bluetooth communication has been carried out with an encapsulation, code has been write using response type, it is to avoid multiple
Readjustment, can significantly simplified code;
2) to design the module of this encapsulation using the framework of command mode, to make the use of module more succinct;
3) with command mode framework in the application, Bluetooth communication (news) module is write using response type, led to using this bluetooth
Letter module can be for needing the application program of Bluetooth communication (news) to bring more smooth Consumer's Experience and simpler use, it is to avoid
Application program interim card.
Described above illustrate and describes some preferred embodiments of the present invention, but as previously mentioned it should be understood that the present invention
Be not limited to form disclosed herein, be not to be taken as the exclusion to other embodiment, and can be used for various other combinations,
Modification and environment, and can be in invention contemplated scope described herein, by technology or the knowledge of above-mentioned teaching or association area
It is modified.And the change that those skilled in the art are carried out and change without departing from the spirit and scope of the present invention, then all should be at this
In the protection domain of bright claims.