Summary of the invention
The technical problem that the present invention solves is to provide a kind of data transmission method based on audio interface,, to realize the transfer of data between each intelligent terminal and game control handle, further reduces development cost.
For solving the problems of the technologies described above, the technical solution used in the present invention is as follows.
Based on the intelligent terminal of audio interface and the data transmission method between control handle, described method specifically comprises the following steps:
A. receive the key assignments signal that control handle sends, the processing of encoding, and the key assignments signal that will encode after processing is packaged into Frame; Frame is encoded into the Difference Manchester analog signal according to the particular serial communications protocol by audio signal wire, is sent to the intelligent terminal audio interface;
B. intelligent terminal, to the Difference Manchester signal that the receives processing of decoding, converts the handle key assignments signal that intelligent terminal can be identified to, and performed game is controlled;
C. when intelligent terminal sends instruction to control handle, at first instruction is encoded to the Difference Manchester analog signal according to the particular serial communications protocol and sends by audio interface, through audio signal wire, be sent to control handle; The Difference Manchester signal that control handle will receive is carried out the instruction that intelligent terminal sends after decoding and processing.
Improvement of the present invention is: described data transfer mode adopts duplex mode, from the data of intelligent terminal output, by the audio output signal line, transfers to control handle, from the data of control handle output, by the audio input signal line, transfers to intelligent terminal.
Improvement of the present invention is: described particular serial communications protocol adopts Differential Manchester Encoding, and in communication signal, one of every transmission has individual saltus step at least, and in the middle of adopting, the saltus step in the moment represents to send 0 or 1.
Improvement of the present invention is: described particular serial communications protocol before sending data, should make audio signal wire be in idle condition; While sending data, adopt the frame beginning flag to carry out synchronously; When the transmission data are completed, adopt frame end mark to represent that data send end, and make audio signal wire be in idle condition.
Data verification method of the present invention is: the data frame format of described audio signal wire transmission uses CRC1 and CRC2 to carry out verification.
Intelligent terminal of the present invention adopts three threads to realize the reception of voice data, send and carry out, and three threads comprise watcher thread, main thread and business procedure, specifically comprise:
At first, set up the audible communication receiving or sending thread in main thread, be used for coordinating reception and the transmission of voice data;
Secondly, whether the audio interface that creates a monitoring intelligent terminal has the thread of data input, is used for the audio signal to from audio interface, collecting, and carries out the Difference Manchester decoding, and the data of decoding output receive the buffer memory of data; After watcher thread was received the valid data frame, by triggering the call back function in the external business program, notice external business program was obtained the data of importing into, and carries out;
Simultaneously, main thread circular wait data deposit event in, when the external business program, when having data to send, when the data that will send are put into shared transmission data buffer, namely have data to deposit event in and occur; Main thread is got the data that will send, and carries out Differential Manchester Encoding, then calls Differential Manchester Encoding that the audio frequency control interface function will deposit event in and send to audio interface and export to control handle.
Owing to having adopted above technical scheme, the invention technological progress is as follows.
Data transmission method of the present invention is based on the audio interface of intelligent terminal, realize the transfer of data between each intelligent terminal and game control handle, the high sampling rate of intelligent terminal audio decoder is 44.1kHz, the limit transmission rate of audio signal can reach 22.05kHz, remove the redundancy overhead in communication protocol, more than the valid data of system transmission have 11kHz at least, this speed is greater than the communication baud rate of common serial ports, controlling in real time of control handle can be guaranteed, obvious time delay can be do not produced.
Audio interface due to the intelligent terminal of each manufacturer production is open in addition, interface standard is unified, realize the transfer of data of mobile phone and control handle by it, development cost is low, highly versatile, in the little still application that requirement of real-time is very high of transmitted data amount, has very large compatible advantage.The present invention adopts the Difference Manchester analog signal to carry out transfer of data, meets the synchronous requirement of serial communication, has ensured the stability of transfer of data.
Embodiment
Below in conjunction with the drawings and specific embodiments, the present invention is further elaborated.
A kind of intelligent terminal based on audio interface and the data transmission method between control handle, the method is used for utilizing the audio interface of intelligent terminal and the transfer of data between audio signal wire realization game control handle and intelligent terminal, data transfer mode adopts duplex mode, transfer to control handle from the data of intelligent terminal output by the audio output signal line, from the data of control handle output, by the audio input signal line, transfer to intelligent terminal.
Specifically comprise the following steps based on the intelligent terminal of audio interface and the data transmission method between control handle:
A. receive the key assignments signal that control handle sends, the processing of encoding, and the key assignments signal that will encode after processing is packaged into Frame; Frame is encoded into the Difference Manchester analog signal according to the particular serial communications protocol by audio signal wire, is sent to the intelligent terminal audio interface.
B. intelligent terminal, to the Difference Manchester signal that the receives processing of decoding, converts the handle key assignments signal that intelligent terminal can be identified to, and performed game is controlled.
C. when intelligent terminal sends instruction to control handle, at first instruction is encoded to the Difference Manchester analog signal according to the particular serial communications protocol and sends by audio interface, through audio signal wire, be sent to control handle; The Difference Manchester signal that control handle will receive is carried out the instruction that intelligent terminal sends after decoding and processing.
Described particular serial communications protocol normative reference synchronous serial communication agreement, adopt Differential Manchester Encoding, and in communication signal, one of every transmission has individual saltus step at least, to adapt to, can only transmit the voice band line transmitting data of interchange; And in the middle of adopting, constantly saltus step represents to send 0 or 1.
For example: set positive transition and represent 1, negative saltus step represents 0, and when first saltus step was positive transition, difference was carried out in saltus step afterwards and previous saltus step so, by the result of comparing, determines it is 1 or 0; , if present bit saltus step direction is identical with the saltus step direction of last position, is expressed as 0, otherwise is expressed as 1.Adopt Differential Manchester Encoding, the synchronous tolerance of communicating pair is half bit time, and the data that receive in synchronization discrepancy half bit time are unaffected.
Before sending data, should make audio signal wire be in idle condition according to the particular serial communications protocol, the prompting recipient carries out data receiver and prepares; The idle preparation of bus can adopt continuous transmission 0 more than 8 to represent.
While sending data, adopt the frame beginning flag to carry out synchronously; Frame is initial can be from any one, the frame beginning flag of described serial communication adopt with the standard serial port communication synchronization in the same sign, namely send continuously 61, namely send character 0x7e and represent to have sent the frame beginning flag.
When the transmission data are completed, adopt frame end mark to represent that data send end, and make audio signal wire be in idle condition.Frame end mark adopts continuously and sends 71, namely sends character 0x7f and represents to have sent frame end.
In employing particular serial communications protocol was carried out the process of data transmission, the unit that the audio signal circuit is uploaded defeated data was position, at first sends highest order while sending byte, sends finally lowest order, there is no interval between byte during the transmission data.
Yet when sending data, in data be likely also continuous 61, this is identical with frame beginning flag and frame end mark, can cause the communication ambiguity.For disambiguation, stipulate in the particular serial communications protocol, in the process when sending data, after sending 51 continuously, must send one invalid 0, more then send other data; And after receiving continuous 51, need that deletion then receives 0.These continuous 51 not one fix in a byte, for example, two byte 0x0f and 0xc0, each byte does not have continuous 51, but first sends after 0x0f while sending 0xc0, has just had continuous 51, need to dynamically insert, delete one 0.
It is as follows that the audio signal circuit is uploaded defeated data format:
The data format of audio signal wire transmission uses CRC1 and CRC2 to carry out verification.The CRC algorithm that adopts is as follows:
const unsigned short GusFcsTab[256] = {
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78,
};
/*******************************************************************
** Function name: crc16Cal
* Descriptions: calculate crc16, expression formula is x^16+x^12+x^5+x^0
* input parameters:usFcs: initial crcr value, one's complement representation, be generally 0xffff.
* pucData: data
* iLen: data length
** output parameters: none
* Returned value: result of calculation, one's complement representation
***************************************************************/
unsigned short crc16Cal(unsigned short usFcs,const unsigned char *pucData,int iLen)
{
while (iLen--) {
usFcs=(unsigned short)((usFcs >>8)^GusFcsTab[(usFcs^*pucData++) & 0xff]);
}
return (usFcs);
}
The code that calculates CRC1 and CRC2 is as follows:
usCrc16 = crc16Cal(0xffff, pucData, uiLen);
CRC1 = usCrc16 / 0x100;
CRC2 = usCrc16 % 0x100。
In the present embodiment, described intelligent terminal based on audio interface and the data transmission method between control handle, the data transmission system that forms based on the mobile phone with audio interface, game control handle and audio signal wire realizes.
The structured flowchart of data transmission system as shown in Figure 1, comprises the mobile phone that is provided with audio interface and is used for the control handle of assisting the mobile phone games to complete, carrying out transfer of data by audio signal wire between the audio interface of mobile phone and control handle.
Control handle comprises shell, is provided with master control borad in shell, is provided with audio signal line jack and one group of handle button of being connected with master control borad on shell; Be provided with push button signalling processing module, main control module, power module and Difference Manchester change-over circuit on master control borad; The handle button is connected with the input of push button signalling processing module by wire, the output of push button signalling processing module connects main control module, main control module is communicated by letter mutually with the Difference Manchester change-over circuit, and power module is connected with push button signalling processing module, main control module and Difference Manchester change-over circuit respectively.
Power module possesses charging/discharging function, gives whole circuit supply, and power module is selected rechargeable lithium battary in the present embodiment, and the circuit diagram of power module as shown in Figure 5.
The push button signalling processing module is for the treatment of the action command that the handle button sends, and is transferred to main control module after changing the key assignments signal that main control module can identify into.
The digitlization serial signal that the Difference Manchester change-over circuit is used for main control module is sent is converted to according to the particular serial communications protocol Difference Manchester analog signal that audio signal wire can transmit; And the Difference Manchester analog signal conversion that will receive from mobile phone is the digitlization serial signal that main control module can be identified.The circuit diagram of Difference Manchester change-over circuit as shown in Figure 4.
Main control module carries out the digitized processing of encoding and decoding to two-way signaling: 1) main control module key assignments information that the push button signalling processing module is imported into is through the key assignments coding, protocol packing by agreement becomes communication data packet, again by IO mouth output packet, the serial data of IO output is encoded to the Difference Manchester analog signal through the Difference Manchester change-over circuit, is sent to passing through on audio signal wire of connection mobile audio interface; 2) main control module will receive the analog signal through Difference Manchester change-over circuit decoding, be decoded into digitized protocol package by the rule of Differential Manchester Encoding, then by protocol-decoding, obtain the effective communication data signal that mobile phone sends.In the present embodiment, main control module is selected the LPC1111 of the microcontroller based on ARM Cortex-M0 of low-power consumption, and the circuit diagram of main control module as shown in Figure 3.
Mobile phone adopts three threads to realize the reception of voice data, send and carry out, and three threads comprise watcher thread, main thread and business procedure, and its flow chart as shown in Figure 2, specifically comprises:
At first, set up the audible communication receiving or sending thread in main thread, be used for coordinating reception and the transmission of voice data; Secondly, whether the audio interface that creates a monitoring mobile phone has the thread of data input, is used for the audio signal to from audio interface, collecting, and carries out the Difference Manchester decoding, and the data of decoding output receive the buffer memory of data; After watcher thread was received the valid data frame, by triggering the call back function in the external business program, notice external business program was obtained the data of importing into, and carries out; Simultaneously, main thread circular wait data deposit event in, when the external business program, when having data to send, when the data that will send are put into shared transmission data buffer, namely have data to deposit event in and occur; Main thread is got the data that will send, and carries out Differential Manchester Encoding, then calls Differential Manchester Encoding that the audio frequency control interface function will deposit event in and send to audio interface and export to control handle.
The concrete data transmission method of the present embodiment is: when the user presses game while controlling handle button on shell, the push button signalling processing module of master control borad receives action command, and is converted into the key assignments signal that main control module can identify and is transferred to main control module; The key assignments signal that main control module will the receive processing of encoding, and the key assignments signal after processing of encoding is packaged into protocol data frame and is transferred to the Difference Manchester change-over circuit, the Difference Manchester change-over circuit converts Frame to the Difference Manchester analog signal according to above-mentioned particular serial communications protocol, send to mobile phone by audio signal wire, for the mobile phone decoding, read.Mobile phone becomes digital signal by the Difference Manchester analog signal conversion that decoding program will receive, and finally obtains the key assignments data message of game paddle; Application software by Cell Phone Design is connected with game interface again, realizes game paddle controlling game.
When mobile phone need to send instruction to control handle, at first to the transmission event that the receives processing of encoding, be converted to the Difference Manchester analog signal according to above-mentioned particular serial communications protocol, be transferred to the Difference Manchester change-over circuit of control handle through audio signal wire, the Difference Manchester analog signal conversion that the Difference Manchester change-over circuit will receive is the Frame that main control module can be identified, and main control module receives after the Frame that mobile phone sends to decode and obtains the effective instruction of mobile phone.
When the present invention not only can be applied on smart mobile phone, all have on the intelligent terminal of audio interface but also can be applied in panel computer, box, intelligent television etc., by audio interface, realize transfer of data between intelligent terminal and control handle.