本帖最后由 xinxincaijq 于 2013-5-14 11:06 编辑
翻译文章送铜板!
欢迎广大热爱电子的网友对本E文进行翻译,将要翻译的原文和译文跟帖回复在本帖下,可以翻译一段或几段,如若能翻译全篇,更是欢迎!
凡是参与翻译,并且质量尚可的网友,均可获得10~100铜板奖励!
I came across an excellent bit of wizardry by Rasmus Andersson called PeerTalk. It’s a Objective-C library allowing you to communicate between your iPhone and your Mac over the USB dock cable using TCP sockets.
【译文 from@l廖天一阁主 】 我遇到一个相当不错的使用方案,这个是出自安德森的,被称作PeerTalk。他是一个基于Objective——c库来让你的苹果电话和电脑通过USB电缆使用TCP套接字进行通信。
http://player.youku.com/player.php/sid/XNTU2NTcyNDA4/v.swf
My immediate thought was that if this really only depended on having USB host mode capability at the far end, the same mechanism should be able to be used to talk to something like the BeagleBone, or the Raspberry Pi, not just your Mac. This would allow you connect your phone directly to the micro controller board and to drive hardware directly, a lot like the Redpark cable but bypassing Apple’s External Accessory framework.
【译文from@l廖天一阁主 】我立刻就想如果这真的只是取决于在远端的USB主机模式的能力大小,所以说同样的机制应该能用来和BeagleBone,或者Raspberry Pi,总之不仅仅是你的MAC。这就可以让你直接让你的手机和微控制器进行连接并且可以直接驱动外围硬件设备。这就非常像Redpark电缆但是又绕过了苹果的外部辅助架构。
So I started digging around inside the source code to see if it depended on anything that was going to be specific to OS X, it became apparent that PeerTalk was mostly some really nice socket code sitting on top of the USB Multiplex Daemon (usbmuxd). This bit of software is in charge of talking to your iPhone over USB and coordinating access to its services by other applications. Effectively this is what iTunes and Xcode use to talk to your phone when you plug it into your Mac’s USB port. 【译文from@l廖天一阁主 】于是,我开始到处深挖里面的源代码,看它是否依赖于任何东西,还是要具体到OS X,很明显,PeerTalk是非常好的套接字代码坐在了USB的多重守护进程(usbmuxd)的顶部。这个软件负责通过USB和你的iPhone进行对话并且协调由其他应用程序访问其服务。实际上这就是当你将它插入你的Mac的USB端口时iTunes和Xcode用他和你的手机进行对话。
所以任何设备想要使用这种方法和iphone进行通信都要通过usbmuxd。幸运的是,对我来说已经有很多人解决了如何在LINUX下和电话通信,并且也有一个USBmuxd在Linux上运行了。
So any device that wants to talk to the iPhone using this method needs usbmuxd. Fortunately for me there are a number of people who have worked out how to talk to the iPhone from Linux, and there is a working usbmuxd for Linux.
There are also As a few other dependencies which aren’t present on the stock Ångström Linux distribution on my BeagleBone, or even packages via opkg, building usbmuxd on my BeagleBone requires libusb and cmake. So before building usbmuxd, I had to build cmake, which meant resolving some problems with the stock compression libraries that shipped with Ångström.
However several hours later after enough waiting around for software to build to convince me that before doing any serious development on the BeagleBone I really had to build an ARMv7 toolchain on my Mac to cross-compile things instead of building them directly on the board….
…I managed to get a simple “hello” from my iPhone to the BeagleBone and then via screen to my Mac using port forwarding and that old stand by, telnet.
While I was hacking away on getting this working, I wasn’t alone. David House was looking down some of the same back alleyways to get PeerTalk talking to his Raspberry Pi, and we batted the problem back and forth on Twitter while waiting for code to compile well into the night…
While I was working on one end, David was working on the other, putting together a client on the Raspberry Pi sitting on top of usbmuxd that’d talk natively to the PeerTalk on iOS which he called peertalk-python. Since we had the source code of both ends, it wasn’t that hard. Just hard enough.
If you want to replicate this on the BeagleBone, or the Raspberry Pi, you should first download and build the PeerTalk library, and then build and deploy the iOS and OSX example applications and get that up and running.
Then connect up and boot your BeagleBone. You’ll need to power the board using a mains adapter as when you’re compiling things. It’s possible you’ll be drawing enough amperage that your computer will turn off the USB port to protect itself and as a result power down your BeagleBone. I had this happen to me a couple of times before I finally dug a mains adapter out of my office drawer. However since you’re powering the board from the mains you’ll also have to connect an Ethernet cable so that you can ssh root@beaglebone.local and log into the board over the network.
1. Go ahead and login to your BeagleBone as root.
2. Download, build and install libusb. Version 1.0.9 builds, links and installs okay.
3. Download, build and install cmake, which you’ll need to buildusbmuxd later.You’ll need to grab the latest Git nightly checkout as older release versions don’t build, having problems with the stock libbz2compression on the BeagleBone. 4. We also need libplist, however this is available as part of the package management system on Ångström Linux, so all you need to do to install this is type opkg install libplist-dev at the prompt. 5. Download, build and install usbmuxd. Version 1.0.8 builds, links and installs okay, although you may beed to use ccmake and configure by hand, rather than using cmake, as it can’t seem to find the libusb include files that got installed into /usr/local.
6. Create a usbmux user groupadd -r usbmux -g 114
useradd -r -g usbmux -d / -s /sbin/nologin -c “usbmux user” -u 114 usbmux 7. As the BeagleBoard doesn’t have syslog turned on by default, and you’ll need it for debugging, turn on syslogd from the relevant script in /etc/init.d. 8. Run up the usbmux deamon, by typing usbmuxd -v -v at the prompt.
9. Plug your iPhone into the (host side) USB on your BeagleBoard, you should see some debug scrolling by in /var/log/messages. 10. Download David House’s peertalk-python and its dependances. 11. On your iPhone start the PeerTalk client for iOS. 12. Start the python client on the BeagleBone by typing python ./peertalk.py at the prompt. Type in a message at the prompt, and you should see something like this…
From there it’s pretty trivial to build a “Hello World” example, just by hacking around with David’s code and toggling the heartbeat LED when the BeagleBone receives any messages.- def run(self):
- framestructure = struct.Struct("! I I I I")
- ledOn ='echo 1 > /sys/class/leds/beaglebone::usr0/brightness'
- ledOff ='echo 0 > /sys/class/leds/beaglebone::usr0/brightness'
- i = 0
- while self._running:
- try:
- msg = self._psock.recv(16)
- if len(msg) > 0:
- frame = framestructure.unpack(msg)
- size = frame[3]
- msgdata = self._psock.recv(size)
- print "Received: %s" % msgdata
- if i == 0:
- os.system(ledOn)
- i = 1
- else:
- os.system(ledOff)
- i = 0
- except:
- pass
复制代码 Which gets you to this point…
http://player.youku.com/player.php/sid/XNTU2NTczMDQ4/v.swf
Which is pretty much where I’ve reached right now. Next steps is a proper application on the iOS end of things with more generic control of the BeagleBone’s header pins, and a more flexible Python backend on the BeagleBone itself. David House also managed to get everything up and working on the Raspberry Pi.
http://player.youku.com/player.php/sid/XNTU2NTcyNzE2/v.swf
The only changes from the BeagleBone set up procedure is that you should grab libplist using apt-get rather than opkg, and since you won’t be logged in as root you should remember to sudo usbmuxd -v -v when you start the USB daemon. Apart from that, you should be good to go…
|