iPhone 应用里与外设装置交换数据的原理(转)
http://www.cocoachina.com/iphonedev/sdk/2010/0723/1922.html
如果我们的应用程序想跟外设传输数据,先要透过 iPhone 的操作系统,也就是 iPhone OS,而最开始的认证过程也是在外设和 iPhone OS 之间发生的,苹果为这个过程提供了一颗认证芯片(这颗芯片的作用是用来让 iPhone OS 识别这个外设是经过苹果公司承认的,他的通信方式是 I2C 总线, 而且每出一个产品苹果都会收几美元的认证费用)
iPhone OS 承认外设分两个步骤,识别和认证,我们先说说识别过程。
识别过程是使用纯物理连接来实现的,在这个过程中 iPhone 的 30pin 有三个引脚被用到,分别是 Accessory Identify,Accessory Detect,Accessory Power,Accessory Identify 接 549k 欧姆的电阻,告知 iPhone OS 使用串口通信,Accessory Detect 直接接地,告知 iPhone OS 有外设插入,Accessory Power 相当于 iPhone OS 的信号,待机时这个引脚没有输出,否则会有 3.3V 的电压输出。如果按照以上连接就完成了识别过程。
下面开始认证过程,认证过程也叫 IDPS 过程,这些就牵扯到苹果指定的通信协议了,苹果给自己的通信协议起了一个名字叫 Lingo,Lingo 分好多种有 音频的 Lingo还有显示遥控的 Lingo,而我们认证使用的 Lingo 叫做 General Lingo。可能大家这时有点晕,那我就给大家看一个 iPhone 的命令包。
StartIDPS packet
Byte Value Comment
0 0XFF Sync byte(required only for UART serial)
1 0X55 Start of packet(SOP)
2 0XNN Length of packet payload
3 0X00 General Lingo
4 0X38 StartIDPS
5 0XNN transID [bit 15:8] Transaction ID
6 0XNN transID [bit 7:0]
7 0XNN 校验
这是 iPhone 的命令包,大家看到这个应该就明白了。开始 IDPS 过程首先要发送 StartIDPS 命令,这样,外设与 iPhone OS 之间的认证过程 就开始了。其中咱们应用中 EAAccessory 关于一些外设的属性,都是在这个过程中外设发给操作系统的,具体还是大家加入苹果的 mfi(made for ipod),拿到资料后,才能更明白。稍后我会将 iPhone 串口通信的源码发出来。先写到这儿吧,这些东西不能说的太多,希望会对大家有点帮助。
MFI地址:http://developer.apple.com/programs/mfi/
MFi, WWi, iAP over UART, iAP over Bluetooth, iAP over USB
communication with iOS Application
我现在
1、发送startIDPS
2、收到ACK status 0x00
3、发送SetFIDTokenValues
4、收到RetFIDTokenValueAcks 不过IdentifyToken的status为0x01
不知是什么问题?
另:没有授权IC,IDPS可以成功么?
没有IC idps同样可以成功的。但就是不能完成认证的所有步骤。
1。TransactionID 是IPOD或者IPHONE使用指令的流水号,
2。0xff 是IPOD&IPHONE为了校验你发送指令使用的波特率及同步。
3。10脚接一个电阻,根据手册你不一样的外围设备使用不一样的电阻,仔细看手册。20脚可跟30PIN相连,或者接地。
4 PIN13是IPOD&IPHONE向外供电一个脚,电压为3。3V。当IPOD通过检测10脚有一个电阻,然后PIN13才开始输出电压。
肯定是你設定的問題,把你發送的,setfidtokenvalue發送的碼,貼上來我幫你看一下。
send_char_com(0xff); //setfidtokenvalue one
send_char_com(0x55);
checksum=0;
send_char_com(0x75); //receive number
send_char_com(0x00); //
send_char_com(0x39); // SetFIDtoken command
send_char_com(transactionid2); //transaction ID
send_char_com(transactionid3);
transactionid3++;
send_char_com(0x09); // send item number
send_char_com(0x0e); //length item0
send_char_com(0x00); //infobyteone
send_char_com(0x00); //infobytetwo
send_char_com(0x03); //numlingoes 0xa4
send_char_com(0x00); // general lingo
send_char_com(0x02); //simple lingo
send_char_com(0x03); // display lingo
// send_char_com(0x04); //extended interface lingo
send_char_com(0x00); //device option
send_char_com(0x00);
send_char_com(0x00);
send_char_com(0x06);
send_char_com(0x00); // device ID
send_char_com(0x00);
send_char_com(0x02);
send_char_com(0x00);
send_char_com(0x0a); //length item1
send_char_com(0x00); //infobyteone
send_char_com(0x01); //infobytetwo 0x22
send_char_com(0x00); //accCapsbitmask
send_char_com(0x00);
send_char_com(0x00);
send_char_com(0x00);
send_char_com(0x00);
send_char_com(0x00);
send_char_com(0x00);
send_char_com(0x01);
send_char_com(0x1b); //length item2
send_char_com(0x00); //infobyteone
send_char_com(0x02); //infobytetwo 0x26
send_char_com(0x01); //name "speaker"
//Speaker for IPOD&IPHONE
send_char_com(0x53); //S
send_char_com(0x70); //p
send_char_com(0x65); //e
send_char_com(0x61); //a
send_char_com(0x6b); //k
send_char_com(0x65); //e
send_char_com(0x72); //r
send_char_com(0x20); //space
send_char_com(0x66); //f
send_char_com(0x6f); //0
send_char_com(0x72); //r
send_char_com(0x20); //space
send_char_com(0x49); //I
send_char_com(0x50); //P
send_char_com(0x4f); //O
send_char_com(0x44); //D
send_char_com(0x26); //&
send_char_com(0x49); //I
send_char_com(0x50); //P
send_char_com(0x48); //H
send_char_com(0x4f); //O
send_char_com(0x4e); //N
send_char_com(0x45); //E
send_char_com(0x00); //nul
send_char_com(0x06); //length item2
send_char_com(0x00); //infobyteone
send_char_com(0x02); //infobytetwo
send_char_com(0x04); //firmware version
send_char_com(0x01);
send_char_com(0x00);
send_char_com(0x00);
send_char_com(0x06); //length item2
send_char_com(0x00); //infobyteone
send_char_com(0x02); //infobytetwo
send_char_com(0x05); //hardware version
send_char_com(0x01);
send_char_com(0x00); //1c
send_char_com(0x00);
send_char_com(0x0b); //length item2
send_char_com(0x00); //infobyteone
send_char_com(0x02); //infobytetwo
send_char_com(0x07); //model number
//
send_char_com(0x53);
send_char_com(0x50);
send_char_com(0x2d);
send_char_com(0x42);
send_char_com(0x42);
send_char_com(0x31);
send_char_com(0x31);
send_char_com(0x00); // 117
send_char_com(0x07); //add RF certifications
send_char_com(0x00); //infobyteone
send_char_com(0x02); //infobytetwo
send_char_com(0x0c); // RF certifications
send_char_com(0x00);
send_char_com(0x00);
send_char_com(0x00);
send_char_com(0x03); //iphone 3g &iphone 3gs & iphone & iphone 4g & ipad RF certification
send_char_com(0x05); //length item2
send_char_com(0x00); //infobyteone
send_char_com(0x03); //infobytetwo
send_char_com(0x03);
send_char_com(0x01);
send_char_com(0x01);
checksum=~checksum+1;
send_char_com(checksum);
多谢回复!
send_char_com(0x00); //device option
send_char_com(0x00);
send_char_com(0x00);
send_char_com(0x06);
send_char_com(0x00); // device ID
send_char_com(0x00);
send_char_com(0x02);
send_char_com(0x00);
你的这两项设置,是要求验证的。我这样设的话也可以idps成功。
不过我不想验证,当我把device option 和 device ID全改为0(不要求验证)就无法成功。