CN104572564A - Method for realizing communication of Android mobile equipment and USB OTG (On-The-Go) host computer - Google Patents

Method for realizing communication of Android mobile equipment and USB OTG (On-The-Go) host computer Download PDF

Info

Publication number
CN104572564A
CN104572564A CN201510016220.8A CN201510016220A CN104572564A CN 104572564 A CN104572564 A CN 104572564A CN 201510016220 A CN201510016220 A CN 201510016220A CN 104572564 A CN104572564 A CN 104572564A
Authority
CN
China
Prior art keywords
android
usb
agreement
usb otg
mobile phone
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201510016220.8A
Other languages
Chinese (zh)
Other versions
CN104572564B (en
Inventor
胡永刚
沈勇坚
王翔平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Dynamicode Co Ltd
Original Assignee
Dynamicode Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Dynamicode Co Ltd filed Critical Dynamicode Co Ltd
Priority to CN201510016220.8A priority Critical patent/CN104572564B/en
Publication of CN104572564A publication Critical patent/CN104572564A/en
Application granted granted Critical
Publication of CN104572564B publication Critical patent/CN104572564B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
    • G06F13/4286Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus using a handshaking protocol, e.g. RS232C link

Abstract

The invention discloses a method for realizing communication of Android mobile equipment and an USB OTG (On-The-Go) host computer; with the combination of an Android Open Accessory Protocol and an Android Debug Bridge interface protocol, the OTG connecting manner supported by mobile phones is judged in a firmware program and the corresponding protocol is chosen to be connected according to the judging result. The scheme is capable of covering all Android mobile phones in the market, and the electrification requirement on external equipment is reduced.

Description

A kind of method realizing android mobile device and USB OTG host communication
Technical field
The present invention relates to mobile device mechanics of communication, be specifically related to the technology of android mobile device and USB OTG host communication.
Background technology
Due to the rise of Mobile Market, present people are becoming more and more various to the usability of mobile phone and security requirement, the external unit of some specialties not only can utilize the portability of mobile phone to promote its usage space, more can meet the security needs of user, the market outlook of its mobile phone peripheral hardware are very wide.Along with the continuous upgrading of mobile phone is progressive, peripheral hardware and mobile phone can not need to be connected by pc, but directly can carry out wired and wireless connection, realize the object of communication.
Android mobile phone has had at present supports that the mobile phone as OTG main equipment occurs, but from evolution, former most of mobile phone is subject to the restriction of power supply, still can only support mobile phone as OTG from equipment,
After determining USB scheme, existing two kinds of the USB scheme of discovery Android of being not difficult:
One, by the Android Debug Bridge debugging interface of Android system, use the tcp forward function of its ADB daemon, the master-slave equipment communication based on tcp socket can be realized.
The benefit of ADB scheme has:
1, ADB damon program is primary with Android system, therefore in theory.As long as Android system, all there is ADB program, as long as user opens debugging interface, can start ADB daemon process, now namely peripheral hardware sets up communication with it by tcp socket.
2, ADB is also that communication is relatively simple by tcp communication between the app of upper strata.
But ADB scheme is relatively good for the support of comparing early version (less than 4.0), for more than 4.2.2 version, support that cannot be reliable and stable.Android is proposed secure adb and carries out RSA signature to main equipment for this reason, remarkable to the performance requirement of hardware owing to generating RSA secret key pair and carrying out rsa encryption, therefore not easily realizes for peripheral hardware.
Two, the Android Open Accessory Protocol agreement provided by android 3.1 version is connected.AOA agreement is the new peripheral hardware agreement that android introduces on 3.1 versions, and this agreement supported by the built-in jar bag of more than 3.1 version, for 2.3.6-3.0 version, add-on lib can be provided to support.
The benefit of AOA scheme is used to have:
1, AOA primary support more than android3.1 version;
2, application api layer provides usb.accessory API external member, writes app and carrys out administrative standard peripheral hardware and become very easy;
3, xml-filter setting can be carried out to app, after Android system has detected the access of AOA peripheral hardware, the app that meeting automatic search has been installed, if the match is successful, automatically starting app; If do not find coupling, the URL that peripheral hardware is arranged can be opened, guide user to go to website to download corresponding app.
As from the foregoing, existing ADB scheme and AOA scheme are all merely able to the Android system mobile device of compatible respective version, cannot realize the support to all android mobile devices.
Summary of the invention
For the problem between existing android mobile device and USB OTG main frame existing for communication, the object of the present invention is to provide a kind of can the USB OTG host communication scheme of compatible all android mobile devices.
In order to achieve the above object, the present invention adopts following technical scheme:
A kind of method realizing android mobile device and USB OTG host communication, described method merges Android Open Accessory Protocol agreement and Android Debug Bridge interface protocol in firmware program, and the OTG connected mode that intelligent decision mobile phone is supported in firmware program, select corresponding agreement to connect according to judged result.
In the preferred version of this programme, in the connected mode of application program according to Android Open Accessory Protocol agreement and the built-in formation support of Android Debug Bridge interface protocol two kinds of connection protocols in described method.
Further, the process of described firmware program connection USB OTG main frame is as follows:
(1), after equipment access, firmware program is initiated USB and is connected, and enumerates USB descriptor;
(2) complete after USB enumerates, initiate AOA agreement and connect, attempt opening accessory mode pattern, if open failure, extend the reset time, and repeated attempt;
(3) attempt unsuccessfully all, reset equipment, then initiate ADB by ADB agreement and connect, instruct successful connection.
Further, the process of described application program connection USB OTG main frame is as follows:
(11), after application program launching, the accessory class list of AOA agreement is first obtained by usb.usbmanager, if mobile phone firmware program can support AOA agreement, then this List shows, i.e. accessory class list, in comprise effective device id, can directly be communicated by ID;
(12) if List table is for empty, then set up socket server and listening port, wait for that the socket of adbd connects.
This programme is by the judgement of firmware to equipment, intelligent selection two kinds of connected modes can carry out OTG and connect and to go forward side by side the news that work, the compatible to greatest extent diversity of android equipment, and because android4.2 equipment needs to carry out RSA authentication, need great computing requirement, therefore adopt AOA agreement to evade authentication operations, decrease the requirement of equipment to external world.
Embodiment
The technological means realized to make the present invention, creation characteristic, reaching object and effect is easy to understand, setting forth the present invention further below.
The present invention is in order to realize support maximization to Android and connection reliability, AOA agreement and ADB interface protocol merge by the present invention in firmware program, and the OTG connected mode that intelligent decision mobile phone is supported in firmware program, select corresponding agreement to connect according to judged result.
Thus, this firmware program realizes mobile phone to connect the process of USB OTG equipment as follows:
A () equipment starts to carry out USB device enumeration process after inserting;
B () has enumerated after, first carry out the connection of AOA agreement;
If (c) connection failure, is set, restarting equipment the reset time, carries out maximum 3 times and attempt;
If (d) successful connection, start to communicate with AOA agreement; If unsuccessful, then continue;
E () starts ADB and connects, send host request;
If (f) successful connection, start communication with ADB agreement; If unsuccessful, then connection failure.
For general application program of mobile phone (APP), based on the scheme that above-mentioned AOA agreement and ADB interface protocol merge, the connected mode of built-in formation support two kinds of connection protocols in the application.
Accordingly, the process of application program connection USB OTG equipment is as follows:
A () is when the equipment insertion mobile phone meeting AOA agreement, the Android system run on mobile phone automatically will identify and starts corresponding application, initialization section in APP, first be connected with peripheral hardware by newly-built UsbAccessory object, if successful connection, then communicated by Usb Accessory object;
If b () connects unsuccessful, then attempt ADB and connect, by the forwarding capability of ADB, set up socket client end, port 4567, socket is initiated to server and connects; If successful connection, then ADB Path Setup, uses socket communication;
If c () socket sets up time-out (as more than 20 seconds), then agreement is not supported, returns connection failure.
Based on above-mentioned two schemes, Android mobile phone equipment all on the market can be covered, and also reduce the electrified requirement to peripheral hardware.
When specific implementation, in order to realize the full compatibility to Android series mobile phone, can choose MCU external equipment as OTG master, mobile phone is as the scheme from equipment.When connecting, comprising firmware program connection and being connected two kinds with application program.
Wherein, the process of firmware program connection USB OTG main frame is as follows:
(1) after equipment access, firmware program detects that equipment initiates USB connection after inserting signal immediately, enumerate USB descriptor, specifically comprise device descriptor, configuration descriptor, interface descriptor and endpoint descriptor, descriptor here refers to the information characteristics of equipment.
(2) complete after USB enumerates, initiate AOA agreement and connect, attempt opening accessory mode pattern, if open failure, extend the reset time, and repeated attempt.
The detailed process that this step carries out the connection of AOA agreement is as follows:
(21) first judge whether mobile phone is in accessory pattern: if then can directly communicate; If not, continue;
(22) send getProtocol instruction, obtain the version information of hardware supported;
(23) send getInfo instruction, obtain hardware equipment information, as: manufacturer name, model name, description, version, URI, serial number etc.;
(24) startup instruction is sent, the accessory pattern Activated Phone;
(25) after having activated, check whether mobile phone is in accessory pattern, and concrete mode can be: check whether mobile phone PID whether be 0x2D00 or 0x2D01, VID is googleID:0x18D1;
(26) attempt opening accessory mode pattern, if open failure, extend the reset time, this reset time refers to usb bus reset time, and repeated attempt, forward step a to.
(3) attempt unsuccessfully all, reset equipment, then initiate ADB by ADB agreement and connect, instruct successful connection.
This step realize ADB connect time, by firmware program set up a port be the socket server of 4567 to accept the connection request of client in APP, concrete steps are as follows:
A () MCU first sends host connect request to mobile phone, if mobile phone has returned connect device signal, then established ADB and connect;
B () then main frame opens the port of 4567, mobile phone terminal can return the signal of an OK;
C () successful connection, waits for that client holds connect request.
Based on such scheme, after completing firmware program connection USB OTG main frame, the process that the application program run in mobile phone connects USB OTG main frame is as follows:
(11) after application program launching, first obtained the accessory class list of AOA agreement by usb.usbmanager, if mobile phone firmware program can support AOA agreement, then this List comprises effective device id in showing, and can directly be communicated by ID.
In this step, when obtaining accessory class list, due to the peripheral hardware list being connected to the AOA agreement of mobile phone having interface to get in com.android.usb.usbmanager bag, this list contains all AOA equipment being currently connected to mobile phone, get this list, can by UsbAccessory object to operate.
In this step, mobile phone firmware program, by sending getProtocol order, gets the AOA version of current connection devices support according to the form of getProtocol order.
Here need to illustrate, List table is for the aforementioned accessory class list got by usbmanager, and it is expressed as a List list in app.Here device id is ProductID, is generally 0x2D00 or 0x2D01, namely represents that this equipment has entered accessory pattern; If the equipment entering accessory pattern can carry out the input and output of flow data by instream and the outstream member object in usbAccessory object.
(12) if List table is for empty, then set up socket server and listening port, wait for that the socket of adbd connects.
In this step, determine whether List table is empty by calling List.size () function, if be 0, represent empty, now illustrate do not have AOA equipment, the socker mode by ADB attempts connecting by next step.
Wherein, set up listening port and completed by APP code, set up the server of 4567 by socket standard A PI, and monitor the client request whether having and be connected to port 4567, this request is sent by adbd.
Here adbd is android debug bridge deamon, is that program is garrisoned in the built-in debugging of Android mobile phone, and namely its start starts and in memory-resident, be responsible for operating mobile phone.
Visible, this programme, by the judgement of firmware to equipment, intelligent selection two kinds of connected modes can carry out OTG and connects and to go forward side by side the news that work, to greatest extent the compatibility diversity of android equipment; Adopt AOA agreement to evade authentication operations simultaneously, decrease the requirement of equipment to external world.
More than show and describe ultimate principle of the present invention, principal character and advantage of the present invention.The technician of the industry should understand; the present invention is not restricted to the described embodiments; what describe in above-described embodiment and instructions just illustrates principle of the present invention; without departing from the spirit and scope of the present invention; the present invention also has various changes and modifications, and these changes and improvements all fall in the claimed scope of the invention.Application claims protection domain is defined by appending claims and equivalent thereof.

Claims (4)

1. one kind realizes the method for android mobile device and USB OTG host communication, it is characterized in that, described method merges Android Open Accessory Protocol agreement and AndroidDebug Bridge interface protocol in firmware program, and the OTG connected mode that intelligent decision mobile phone is supported in firmware program, select corresponding agreement to connect according to judged result.
2. a kind of method realizing android mobile device and USB OTG host communication according to claim 1, it is characterized in that, in the connected mode of application program according to Android Open AccessoryProtocol agreement and the built-in formation support of Android Debug Bridge interface protocol two kinds of connection protocols in described method.
3. a kind of method realizing android mobile device and USB OTG host communication according to claim 1, is characterized in that, the process that described firmware program connects USB OTG main frame is as follows:
(1), after equipment access, firmware program is initiated USB and is connected, and enumerates USB descriptor;
(2) complete after USB enumerates, initiate AOA agreement and connect, attempt opening accessory mode pattern, if open failure, extend the reset time, and repeated attempt;
(3) attempt unsuccessfully all, reset equipment, then initiate ADB by ADB agreement and connect, instruct successful connection.
4. a kind of method realizing android mobile device and USB OTG host communication according to claim 2, is characterized in that, the process that described application program connects USB OTG main frame is as follows:
(11), after application program launching, the accessory class list of AOA agreement is first obtained by usb.usbmanager, if mobile phone firmware program can support AOA agreement, then this List shows, i.e. accessory class list, in comprise effective device id, can directly be communicated by ID;
(12) if List table is for empty, then set up socket server and listening port, wait for that the socket of adbd connects.
CN201510016220.8A 2015-01-13 2015-01-13 It is a kind of to realize android movement equipment and the method for USB OTG host communications Active CN104572564B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510016220.8A CN104572564B (en) 2015-01-13 2015-01-13 It is a kind of to realize android movement equipment and the method for USB OTG host communications

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510016220.8A CN104572564B (en) 2015-01-13 2015-01-13 It is a kind of to realize android movement equipment and the method for USB OTG host communications

Publications (2)

Publication Number Publication Date
CN104572564A true CN104572564A (en) 2015-04-29
CN104572564B CN104572564B (en) 2018-04-20

Family

ID=53088674

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510016220.8A Active CN104572564B (en) 2015-01-13 2015-01-13 It is a kind of to realize android movement equipment and the method for USB OTG host communications

Country Status (1)

Country Link
CN (1) CN104572564B (en)

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105182111A (en) * 2015-08-17 2015-12-23 上海斐讯数据通信技术有限公司 Mobile terminal performance test method and system
CN106357607A (en) * 2016-07-20 2017-01-25 北京海誉动想科技股份有限公司 Method and device for connection, security verification, communication, communication monitoring of electronic equipment
WO2017185694A1 (en) * 2016-04-29 2017-11-02 乐视控股(北京)有限公司 Electronic device, and method for providing data for another directly connected electronic device
CN107450947A (en) * 2017-07-26 2017-12-08 北京疯景科技有限公司 Start the method and device of application
CN107483696A (en) * 2017-07-12 2017-12-15 武汉卡比特信息有限公司 A kind of mobile phone and the communication means and system of computer equipment
CN107783930A (en) * 2016-08-29 2018-03-09 现代自动车株式会社 Usb communication control method for USB annexes
CN108259652A (en) * 2016-12-28 2018-07-06 上海大唐移动通信设备有限公司 A kind of terminal dials the method and device of voice and video test
CN108733607A (en) * 2017-04-25 2018-11-02 中国移动通信集团公司 A kind of connection communication method and apparatus
CN109150926A (en) * 2018-11-19 2019-01-04 炬星科技(深圳)有限公司 A kind of data communications method and man-machine interactive system
TWI677789B (en) * 2018-07-06 2019-11-21 英研智能移動股份有限公司 Peripheral hardware operating method and system
CN110688161A (en) * 2018-07-06 2020-01-14 英研智能移动股份有限公司 Peripheral hardware operation method and system
CN114936175A (en) * 2022-07-21 2022-08-23 飞天诚信科技股份有限公司 Method, device, terminal equipment and medium for realizing OTG communication without plugging

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030229723A1 (en) * 2002-03-22 2003-12-11 Nokia Corporation Support of an accessory device by a mobile terminal
CN103049403A (en) * 2013-01-11 2013-04-17 福建鑫诺通讯技术有限公司 Method for communication between embedded terminal device and cell phone
CN103401997A (en) * 2013-07-15 2013-11-20 东软集团股份有限公司 Data transmission method and system of vehicle-mounted terminal and intelligent mobile phone under USB (universal serial bus) connection
CN103970582A (en) * 2013-01-28 2014-08-06 联想(北京)有限公司 USB device simulation method
US20140351446A1 (en) * 2013-05-21 2014-11-27 Samsung Electronics Co., Ltd. Electronic device using logical channels for communication

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030229723A1 (en) * 2002-03-22 2003-12-11 Nokia Corporation Support of an accessory device by a mobile terminal
CN103049403A (en) * 2013-01-11 2013-04-17 福建鑫诺通讯技术有限公司 Method for communication between embedded terminal device and cell phone
CN103970582A (en) * 2013-01-28 2014-08-06 联想(北京)有限公司 USB device simulation method
US20140351446A1 (en) * 2013-05-21 2014-11-27 Samsung Electronics Co., Ltd. Electronic device using logical channels for communication
CN103401997A (en) * 2013-07-15 2013-11-20 东软集团股份有限公司 Data transmission method and system of vehicle-mounted terminal and intelligent mobile phone under USB (universal serial bus) connection

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
FUN123246: ""Android Open Accessory相关资讯整理"", 《百度文库》 *
位恒曦 等: ""基于AOA协议实现Android设备的USB通信"", 《电子技术应用》 *

Cited By (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105182111A (en) * 2015-08-17 2015-12-23 上海斐讯数据通信技术有限公司 Mobile terminal performance test method and system
WO2017185694A1 (en) * 2016-04-29 2017-11-02 乐视控股(北京)有限公司 Electronic device, and method for providing data for another directly connected electronic device
CN106357607A (en) * 2016-07-20 2017-01-25 北京海誉动想科技股份有限公司 Method and device for connection, security verification, communication, communication monitoring of electronic equipment
CN107783930B (en) * 2016-08-29 2022-05-17 现代自动车株式会社 USB communication control method for USB accessory
CN107783930A (en) * 2016-08-29 2018-03-09 现代自动车株式会社 Usb communication control method for USB annexes
CN108259652A (en) * 2016-12-28 2018-07-06 上海大唐移动通信设备有限公司 A kind of terminal dials the method and device of voice and video test
CN108733607B (en) * 2017-04-25 2022-04-01 中国移动通信集团公司 Connection communication method and device
CN108733607A (en) * 2017-04-25 2018-11-02 中国移动通信集团公司 A kind of connection communication method and apparatus
CN107483696A (en) * 2017-07-12 2017-12-15 武汉卡比特信息有限公司 A kind of mobile phone and the communication means and system of computer equipment
CN107483696B (en) * 2017-07-12 2019-11-22 武汉卡比特信息有限公司 A kind of communication means and system of mobile phone and computer equipment
CN107450947A (en) * 2017-07-26 2017-12-08 北京疯景科技有限公司 Start the method and device of application
TWI677789B (en) * 2018-07-06 2019-11-21 英研智能移動股份有限公司 Peripheral hardware operating method and system
CN110688161A (en) * 2018-07-06 2020-01-14 英研智能移动股份有限公司 Peripheral hardware operation method and system
CN109150926A (en) * 2018-11-19 2019-01-04 炬星科技(深圳)有限公司 A kind of data communications method and man-machine interactive system
CN114936175A (en) * 2022-07-21 2022-08-23 飞天诚信科技股份有限公司 Method, device, terminal equipment and medium for realizing OTG communication without plugging
CN114936175B (en) * 2022-07-21 2022-10-04 飞天诚信科技股份有限公司 Method, device, terminal equipment and medium for realizing OTG communication without plugging
WO2024016810A1 (en) * 2022-07-21 2024-01-25 飞天诚信科技股份有限公司 Method and apparatus for implementing otg communication without plugging, terminal device, and medium

Also Published As

Publication number Publication date
CN104572564B (en) 2018-04-20

Similar Documents

Publication Publication Date Title
CN104572564A (en) Method for realizing communication of Android mobile equipment and USB OTG (On-The-Go) host computer
US9804859B2 (en) Re-enumeration of USB 3.0 compatible devices
US9268381B2 (en) Terminal device and power supply method for terminal device
WO2019105466A1 (en) Remotely upgradable portable power supply and upgrading method
EP2549678A1 (en) Method and apparatus for protecting software of mobile terminal
CN107926075B (en) System and method for supporting data communication in heterogeneous environment
CN104199706A (en) Firmware upgrade method and device for eMMC
CN102857915B (en) Electronic equipment, intelligent terminal and the authentication method with wireless router
KR101674515B1 (en) System and method of providing embedded software development environment for IoT device
KR101554599B1 (en) Mobile Terminal for connection with external device, and method for running application thereof
KR20150032703A (en) Method, apparatus and system of recovering an operating system on a portable communication device
CN103092648B (en) A kind of image upgrade method, system and subscriber equipment and personal computer
CN102073524B (en) A kind of method of wireless communication terminal and self-starting thereof
TW201316216A (en) System and method for touch device with external input function
WO2017107528A1 (en) Multi-security boot chip and startup method thereof and storage medium
CN111680336B (en) Firmware safety protection method, device, system and equipment
CN111338673B (en) Equipment debugging method and device, electronic equipment and storage medium
CN104346572A (en) Construction method of universal external intelligent terminal safety operation environment
CN105786659A (en) Remote debugging method and server
KR20130003645A (en) Method for establishing connection between external device and mobile terminal docking thereat
WO2013004175A1 (en) Software upgrading method and apparatus for electronic devices
CN101998691B (en) Method, system and device for data transmission
CN104378403A (en) Terminal and updating method thereof
KR20130073430A (en) System and method for authorizing mobile terminal connecting to external device, and external device authorizing mobile terminal
CN106101784B (en) A kind of repositioning method and device of smart television control Bluetooth chip

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant