USB --- 和苹果手机通过EAP通信

EAP

EAP 全拼是 External Accessory Protocol,即外部配件协议。这个是苹果推荐使用的外设连接方式。需要外设集成 MFi 芯片进行 MFi 认证。手机端开发相对简单,只要集成 iOS 系统提供的一个框架 ExternalAccessory.framework,并且在 info.plist 中配置好协议字符串 (Supported external accessory protocols),当 iOS 设备通过 USB 或者蓝牙连接到对应硬件时,iOS 系统会把符合 MFi 认证要求的外设抽象成了一个流对象,App 通过指定的协议字符串来创建一个 EASession 类的实例来访问到该流对象,就能通过 NSInputStream 和 NSOutputStream 跟硬件件进行通信了。

  • EA Session 模式:它的带宽相对较低,但是允许同时通过多个协议字符串创建多个会话,也就是说直接支持多通道

  • Native Transport 模式:它的带宽足够大,理论值是 100MB 以上,但是不支持多通道,如果业务层需要支持多数据通道的话需要 App 自己进行通道的复用与拆分,并且 Native Transport 需要 iPhone 工作在 USB Host 模式,硬件需要支持 USB 模式切换

关于如何使用 EAP 跟外部设备进行通信,可以参考苹果官方的 Demo (https://developer.apple.com/library/content/samplecode/EADemo/Introduction/Intro.html)进行入门和学习。

iAP2 EA Session

all accessories shall establish a control session for the purposes of authentication and identification. Once initial authentication and identification are complete, the accessory may use additional sessions

Accessories supporting control session version 2 may send Accessory Identification (page 279) messages before authentication completes and shall complete authentication before sending any other messages. The accessories shall fall back to control session 1 if the device does not support control session 2 or does not support those devices.

USB Host Mode (page 507) accessories shall not use control session version 2

 一个 iAP2 EA session可以实现多个 EA protocols

EA Native Transport(USB Host Mode)

To implement an EA Native Transport over USB Host Mode, an accessory shall declare one additional USB interface in its device descriptor. The interface shall have two alternate settings; alternate setting 1 shall have one bulk IN and one bulk OUT endpoint, and alternate setting 0 shall be a zero-bandwidth setting with no endpoints. The accessory shall also declare the presence of an EA Native Transport component during identification.

一个 EA Native Transport 只支持一个 EA protocol

认证

认证一共有两个步骤,authentication 和 identification

authentication 

identification

image

IOS系统弹窗(App Lanuch)

image

 

 

 

 

 

 

 

 

posted @ 2025-07-10 14:35  流水灯  阅读(121)  评论(0)    收藏  举报