The present invention relates to a kind of message exchange and method, particularly realize the transmission of information, the apparatus and method of exchange about the mode of utilizing short-distance wireless communication.
[summary of the invention]
The technical disadvantages that exists in order to solve existing short distance internal information switch, the invention provides a kind of portable type information switching unit that is applicable to short distance internal information exchange, it has advantages of, and validity easy to operate, information exchange is high, Information Security, strong interference immunity during communication.
The present invention also provides a kind of information switching method that is applicable in the short distance, and it has advantages of, and the validity of information exchange is high, strong interference immunity, transmission speed are fast.
The portable type information switching unit that the present invention proposes, in order to send the built-in information in it, receive simultaneously the information that other portable type information switching units send, to reach the information exchange in short distance, it comprises: microprocessor, and it is controlled whole device; Package/parse module, it links to each other with microprocessor, the data that send is carried out package, and the data of receiving are unpacked; Sending module, it links to each other with package/parse module, the packet that sends is encapsulated to meet the form of RF host-host protocol, and be responsible for sending; Receiver module, it links to each other with package/parse module, is responsible for the receive data bag, and packet unpacks so that package/parse module can be identified to receiving; Matching module, it links to each other with microprocessor, and the data received and built-in information or identifying information are compared, and judges whether it mates or no transmitting terminal from being complementary with it, and corresponding information is sent to microprocessor; Frequency-selecting frequency hopping module, it links to each other with microprocessor, in order to selecting clean channel or to jump to the channel of appointment, and corresponding information is sent to microprocessor; Memory cell, it links to each other with microprocessor, in order to store data; Data input module, it links to each other with microprocessor, for the user provides operation interface; And display module, it links to each other with microprocessor, in order to demonstration information.
Described portable type information switching unit also comprises Error Control module, it is connected between receiver module and the microprocessor, the information that this Error Control module is received receiver module is carried out verification, with the validity of data that guarantees to receive, and with the verification result feedback to microprocessor.
Described portable type information switching unit also comprises Error Control module, also comprises timing module, and it links to each other with microprocessor, is responsible for providing overtime detection, timing service.
Described microprocessor also comprises the system mode handover module, and the message that it is sent according to package/parse module and timing module is responsible for the switching of the working state of system in the whole communication process.
Described operating state has transmission state, accepting state, idle condition.
Described portable type information switching unit also comprises synchronization character generator and address generator, and it all links to each other with microprocessor; The synchronization character generator produces a synchronization character automatically, at random according to the instruction of microprocessor; Address generator produces an address automatically, at random according to the instruction of microprocessor.
Frequency-selecting frequency hopping module jumps to the channel of appointment within the time of appointment according to synchronization character.
Described portable type information switching unit also comprises communication interface, and in order to connect main equipment such as computer, this communication interface is USB interface or 1394 interfaces.
Described memory cell is non-volatile memory medium.
A kind of method that realizes the information exchange between portable type information switching unit comprises transmit leg and recipient, comprises the steps:
(1) sending direction sends broadcast packet outward, comprises match information and pet name pet name parameter in the broadcast packet, and system is in idle condition;
Whether (2) recipient receives broadcast packet, judge and oneself mate;
If match information is identical, then be judged as Condition Matching, obtain the user's pet name pet name in the broadcast packet, select simultaneously clean channel, modified address and send details to respond bag, these details are responded the pet name pet name of pre-channel number, amended address, synchronization character and the transmit leg of jumping of bag parameter band, and enter the pre-receiving state, wait for the other side's echo; If have no reply at the appointed time, then get back to idle condition;
If match information is not identical, then do not do any response, system still is in idle condition;
(3) " be the local pet name, then send the echo of receiving details response bag, system enters pre-transmission state, according to modified address, the address parameter of receiving after transmit leg receives that details are responded bag, to check the parameters " pet name pet name;
(4) after the recipient receives that details are responded the echo of bag, whether match address is correct, correct then send the order begin now to send data, and order the other side enters the transmission state immediately to send data, oneself also enters accepting state immediately, waits for the other side's packet;
If send over without packet at the appointed time, then get back to idle condition;
(5) according to the time of synchronization character appointment, transmit leg and recipient jump to the channel of appointment simultaneously;
(6) the transmit leg system enters the transmission state, sends the order bag of beginning receive data, receive recipient's the echo to this order bag after, then the transmission packet waits for the other side's echo; If do not receive the other side's echo at the appointed time, then get back to idle condition.
(7) after the recipient enters accepting state, just wait for the other side's packet, receive bag of a bag response; If without packet, then get back to idle condition at the appointed time.
(8) transmit leg is sent packet and then sends the order that finishes receive data, receive recipient's the echo to this order after, the channel of rebound system default, the address returns to default value, system mode is made as idle condition;
(9) recipient receives the order that finishes receive data, then sends the echo of this order, the channel of rebound system default, and the address returns to default value, and system mode is made as idle condition.
The channel value of the described system default in the method for the information exchange between described realization portable type information switching unit is 0, and the default value of described address is 0.
The outer broadcast packet that sends of described sending direction in the method for the information exchange between described realization portable type information switching unit is outwards to send in mode regularly.
Recipient in the method for the information exchange between described realization portable type information switching unit preserves the data of its reception after receiving the order of end receive data of transmit leg.
Recipient in the method for the information exchange between described realization portable type information switching unit or transmit leg are after receiving the other side's package, the verification that all can effectively go to the data in its package of receiving, if check results is damaged for these data or is imperfect, then will not receive.
Portable type information switching unit of the present invention and information switching method thereof have the following advantages with respect to prior art:
1. error control: adopt the CRC16 verification, the packet of receiving all is CHECKSUM processes, guarantee the validity of data to receiving.
2. clocking capability: make up delayed retransmission, do not receive in a period of time that echo then retransmits, improve the anti-interference of communication.
Whenever 3. prevent co-channel interference: set up the select frequency automatically hopping, in a channel, only have two machines at swap data, realize the safely and fast transmission of large-scale data.
4. the address is as identifying information: automatic calculated address, filter out the information of non-target, and prevent from connecting and disturbed with the product machine afterwards.
5. synchronization character function: adopt the mode of synchronization character, cooperate the address, make the both sides of swap data enter simultaneously the channel of appointment, provide assurance for both sides carry out exchanges data at same channel.
6. memory function: when both sides when having exchanged data, data can be preserved.
7. wrap back an interaction mechanism that wraps by sending out one, strengthen robustness, reliability and the robustness of the method.
8. because exchanges data of the present invention is in short-range, the size of code of whole agreement is for being no more than 30KByte, and it is low that it occupies resource, is suitable for some storage resources relatively single-chip microcomputer, the MCU of anxiety.
[embodiment]
Portable type information switching unit provided by the invention in order to send the built-in information in it, receives the information that other portable type information switching units send simultaneously, to reach the information exchange in short distance.As shown in Figure 1, comprise microprocessor, package/parse module, sending module, receiver module, Error Control module, timing module, matching module, frequency-selecting frequency hopping module, memory cell, data input module, display module, data exchange interface, synchronization character generator and address generator, wherein, package/parse module, Error Control module, timing module, matching module, frequency-selecting frequency hopping module, memory cell, data input module, display module, data exchange interface, the synchronization character generator all links to each other with microprocessor with address generator, and sending module links to each other with package/parse module respectively with receiver module.
Microprocessor is controlled whole device, and it comprises the system mode handover module.
Sending module is responsible for the data envelope that will send being dressed up the form that meets RF (frequency modulation, radio frequency) transmission agreement and being responsible for sending.
The data structure of the exchange among the present invention is:
Table 1:
| The address |
The sign bag |
Redundancy check code |
Data |
Address (ADDR) is by the automated randomized generation of address generator, is the identifying informations of both sides when swap data, prevents from being disturbed with the product machine after connecting, and is generally 0~255 byte.
The type of sign bag has data and orders two kinds, as being 1 (code is 1 byte) when its inner information, then represents the broadcast data packet that this sign bag sends for the sender.The information of other sign bag is expressed as follows:
ENUM RFMsgNothing=0, // type do not had
Broadcast=1, // broadcasting
SendMeDetailFile=n2, the order of // transmission details
StartRxData=n3, the order of // beginning receive data
DataPkg=n4, // packet
EndRxData=n5, the order of // end receive data
AckSendDetail=n6, // response sends the details order
AckStartRxData=n7, the order of // response beginning receive data
JumpToTXNow=n8, // begin now to send data command
AckDataPkg=n9, // response data bag
AckEndRxData=n10, // respond and finish the receive data order
};
Wherein, n2-n10 is code, and the size of each code the most very much not can surpass the 30k byte.
Whether redundancy check code is to suffer damage at transport process for check data.The data message position concern redundancy check code that affix is certain according to certain first before sending to channel, consist of again transmission after the code word, and this process is called the error control coding process.After receiving terminal was received this code word, whether the relation between inspection message position and the additional redundancy check code had mistake to occur, this process is called checkout procedure to check in the transmission course.By package/parse module the data message that will send is encapsulated among the present invention, in encapsulation process, produce described redundancy check code.Data structure after the encapsulation is as shown in table 1.
The present invention adopts CRC16 (Cyclic Redundancy Check, cyclic redundancy check (CRC)) check for errors control method.
Data are real data.
For example: sending module externally sends broadcasting, and then the data structure of this broadcasting is, such as table 2.
Table 2:
| Address (1 byte) |
Broadcasting (1 byte) |
Redundancy check code (10 byte) |
User's pet name (20 byte) |
What group (1 byte) user belongs to |
Address in broadcast packet is the default value 0 of system when initial.
User's pet name defines in mydetail (details) file for user oneself, it can be stored by copying to after arranging in computer in the memory cell in apparatus of the present invention, also can directly also be edited by the data input module input message by the user, and store in the memory cell.In the time will externally sending information, microprocessor can call the information of user's pet name in the memory cell, and this information is sent in package/parse module, sends by sending module.
The component that the user belongs to is as the information of user's searching with own matching condition, that is match information.For example be preset with the information of following component among the present invention.
enum{
StudyGroup=0, // learning and communication group--together study
PlayGroup=1 // amusement and recreation group--play together
HelpGroup=2 // friend helps each other, and the group--give me a break
BusinessGroup=3 // Business Partner group--hand over a friend
OpenGroup=4 // opening group ...-understanding understanding
};
User's group can be edited immediately, and the user sends by broadcast message by the corresponding numeral of data input module input.The numeral of inputting such as the user is 0, represents its selected group and is " learning and communication group ", and store this information in matching module.When this device is received the broadcast message that similar other products sends, and the group information of the group information in this broadcast message and this device is consistent, illustrates that then both mate.By group information, the user can find the object that is complementary with it.
Receiver module be used for to receive the packet that the sending module of other portable type information switching units sends over, and sends to Error Control module after the packet that receives unpacked and verify its correctness.Error Control module among the present invention adopts the CRC16 method of calibration, the packet of receiving all is CHECKSUM (summation) processes.
The system mode handover module is detected, is switched the operating state of whole device.The message that it is sent according to package/parse module and timing module is responsible for the switching of the working state of system in the whole communication process.
Timing module is responsible for providing overtime detection, timing service.Provide every 3 seconds the once timing services of broadcasting such as this timing module, or after the other side's transmission information, the other side has no reply in setting time, or retransmitted information N time, the other side still has no reply, then this timing module can provide an overtime information to microprocessor, and the system mode control module in the microprocessor is according to this information switched system state.
Frequency-selecting frequency hopping module is responsible for selecting an at that time clean channel, so that the both sides of information exchange can carry out exchanges data in a clean channel, is not subjected to other third-party interference.Frequency-selecting frequency hopping module is got a channel number first at random, checks simultaneously whether this channel is busy, if busy, then selects an other channel, until get access to clean, the current channel that is not used.After frequency-selecting frequency hopping module is obtained clean channel, this channel is sent to microprocessor.Simultaneously, this frequency-selecting frequency hopping module also realizes the function of frequency modulation, receives the other side's information when this device, and when including the channel information of appointment in this information, microprocessor is controlled the channel that this frequency-selecting frequency hopping module jumps to appointment, so that both sides carry out exchanges data in the channel of appointment.This device can be realized the mechanism of select frequency automatically, frequency hopping by frequency-selecting frequency hopping module, thereby realizes safety, the fast transport of large-scale data.
The data that Error Control module cooperates receiver module that receiver module is received are tested, and whether check data is correct.Error Control module adopts the CRC16 verification, the packet of receiving all is CHECKSUM processes.Microprocessor is according to the receive data whether of the output control package/parse module after the Error Control module check, if the assay of Error Control module is correct, then microprocessor just sends command request package/parse module and receives this data; If the assay of Error Control module is incorrect, microprocessor is made corresponding processing, and control package/parse module does not receive these data.
The data that matching module receives this device and the built-in or recognition data compare, judge whether it mates or no transmitting terminal from being complementary with it, do not disturbed by the information of similar other products with the communication that guarantees both sides.
Address generator produces an address automatically, at random according to the instruction of microprocessor, and this address is in order to as an identifying information when both sides' swap data, prevents from connecting being disturbed by the like product machine afterwards.
The synchronization character generator produces a synchronization character automatically, at random according to the instruction of microprocessor, and this synchronization character is the expression both sides jump to appointment simultaneously in setting time channel, to prevent the interference of other like product.As to set this synchronization character be 5 seconds, and then both sides experience the channel that jumps to appointment in same time after 5 seconds at the same time.This synchronization character can be that the mode with increasing or decreasing realizes.By this synchronization character, can filter out the inhomogeneity product, so that like product has clean channel, that is, in a channel, only have simultaneously two machines in communication.
The information that display unit maybe will send in order to the information that shows this device and receive, it can be liquid crystal display or other display.
Data input module is button, and the user can input the built-in data that it is wanted by this module, such as the group of selection input or the code of other information.
Data exchange interface is the connection of setting up this device and main equipment such as computer, and it can be the usb interface, also can be 1394 interfaces.Data exchange interface can be that wired interface also can be wireless interface.
Memory cell bit non-volatile memory is such as flash memory.
As shown in Figure 3, device of the present invention is such as the operation principle of receiver:
Opening power (not shown), microprocessor work, device are in operation RF function, and are in accepting state.
After receiver module is received the broadcast packet that the sending module of other device sends, whether Error Control module at first checks this broadcast packet damaged, if not damaged, microprocessor control package/parse module receives information, and this information is sent to microprocessor.The built-in data are obtained in the work of microprocessor control matching module, and the broadcast packet and the bist data that receive are compared, and see whether the other side's condition mates.Do not receive other broadcast packet if do not mate continuation, and show the printed words of " do not mate, continue to receive " at display.If coupling, microprocessor control address generator, synchronization character generator, frequency-selecting frequency hopping module and timing module work simultaneously, are stored into the broadcast packet that receives in the memory cell.System mode handover module switching state makes this device be in the transmission state.The information such as the identifying information of the other side in the address that microprocessor produces address generator, synchronization character that the synchronization character generator produces, clean channel that frequency-selecting frequency hopping module is selected and the broadcast packet received such as the pet name send package/parse module to, send to sending module after by package/parse module those information being encapsulated, pack.Information after sending module will encapsulate is processed, so that its Packet Generation that meets the RF transmission is to the other side.The timing module timing.When the other side in the time in appointment without writing in reply, and retransmitted several times information, still without letter in reply, then system mode handover module switching state makes this device be in accepting state.
When the other side writes in reply in setting time, both sides jump in the channel of appointment simultaneously according to synchronization character, and after connecting, this device is receive data in this channel.After data receiver was complete, frequency-selecting frequency hopping module jumped back to the channel (being made as 0 such as initial channel) of initial setting, and system is in again accepting state.
As shown in Figure 4, device of the present invention is such as the operation principle of transmitter:
Start, system's RF function that brings into operation, a time that regularly sends broadcast packet is set in timing module work, such as 3 seconds broadcast packets.After receiving the echo of broadcast packet, frequency-selecting frequency hopping module is jumped into the channel of the other side's appointment immediately, carries out data and sends.After sending data, frequency-selecting frequency hopping module jumps back to the channel (being made as 0 such as initial channel) of original initial setting.System continues to send out in per 3 seconds a broadcast packet.
As shown in Figure 5, be to realize that the present invention's two table apparatus carry out the dynamic flow diagram of method for interchanging data: at first the illustrative system state is divided into following several situations:
Enum SysStaue{IdleTask=0, // the free time
PreRXTask=1, // pre-receiving state
RxTask=2, // accepting state
PreTxTask=3, // state sent in advance
TxTask=4, // transmission state
};
Replenish simultaneously other titles be described first:
Channel: channel; Sync: synchronization character.
[machine A] whenever sends broadcast packet such as 3S at regular intervals, and the form of broadcast packet is as shown in table 1, and system is in { IdleTask} state.
[machine B] receives broadcast packet
User in the broadcast packet and oneself be a group, namely match information is identical, then is judged as Condition Matching.Then obtain the user's pet name in the broadcast packet, search the file of whether receiving this pet name, then do not preserve, select simultaneously clean channel, modified address and send data (the pre-channel number of jumping of this SendmeDetail parameter band of SendmeDetail, with amended address, synchronization character and [machine A] pet name), and enter the PreRFTask state, wait for the other side's echo, if have no reply at the appointed time, then retransmit several times, still have no reply if retransmitted N time, then get back to the IdleTask state.
[machine A] receives SendmeDetail
Check the parameters " pet name " be the local machine pet name; then send AckSendDetail echo bag; system enters the PreTXTask state; according to modified address, the address parameter of receiving; and the channel of automatically jumping into [machine B] appointment according to the synchronization character of receiving (being the mode timing that increases progressively in the present embodiment) within the time of appointment with the address of receiving; then system enters the TXTask state, sends StartRxData order bag, waits for the other side's echo.If have no reply at the appointed time, then retransmit several times, still have no reply if retransmitted N time, then get back to the IdleTask state.
[machine B] receives AckSendDetail echo bag
Whether ADDR is correct for coupling, correctly then send the JumptoTXNow order, order the other side enters TXTask state transmission data immediately, and (mode by this kind order can save time, reach the purpose of quick interchange), oneself also enters the RXTask state immediately, wait for the other side's packet, if send over without packet at the appointed time, then get back to the IdleTask state.
According to the time of synchronization character appointment, [machine A] and [machine B] jumps to the channel of appointment simultaneously.
After [machine A] enters the TXTask state, send first StartRxData order bag, after receiving ackStartRxData echo bag, send the DataPkg packet, then wait for ackDataPkg echo bag, if having no reply at the appointed time, then retransmit several times, still have no reply if retransmitted N time, then get back to the IdleTask state.
After [machine B] enters RXTask, just wait for the other side's packet, receive bag of a bag response, if at the appointed time interior without packet, then get back to the IdleTask state.
[machine A] is sent packet and then sends EndRxData order, receive the ackEndRxData echo after, in the mode of successively decreasing, synchronization character jumps back to the channel of rebound system default behind the original value, be 0 such as the present embodiment, the address returns to default value, and system mode is made as the IdleTask state.
[machine B] receives the EndRxData order, then sends the ackEndRxData echo, preserves file, and the channel of rebound system default is 0 such as the present embodiment, and the address returns to default value, is 0 such as the present embodiment, and system mode is made as the IdleTask state.
Wherein, recipient or transmit leg all can carry out the verification of validity to the data in its package of receiving after receiving the other side's package, if check results is damaged for these data or is imperfect, then will not receive.In the present embodiment, adopt the CRC16 check addition, to the processing of suing for peace of the data in the package of receiving.