connect your device to applications

0xdroid 正式支援 DevKit8000 開發板 Hacking at 0xlab   March 10, 2010

沈寂的一段時間,現在 0xdroid 又恢復活躍的開發。正如稍早在 0xlab-devel 郵件討論區提及 "Return back to open source world",我們陸續將之前開發的成果,貢獻到自由軟體的世界,環繞在 0xdroid 的項目有:
  • Beagleboard 一貫的完整支援,不只是將 Android 運作起來,還要提昇整體的效能與可用性
  • 除了支援 Beagleboard 外,對 DevKit8000 也有充分的支援
  • 擴充 esuit 並整合 Android CTS (Compatibility Test Suite) Sikuli,提供涵蓋 board-level, API-level, Application-specific 的自動測試框架
  • 對 Android 為基礎的系統作全面性的功能、效能,與可靠度評比,以及整合上述的自動測試框架,以驗證量化系統的品質
在 kanru 的努力與若干網友的貢獻 (hychen, Fred, itszero) 下,現在對 DevKit8000 的支援已加入到 GIT repository,以下是執行時期的照片:
(0xdroid 的桌面與 Launcher)
(調整為直式顯示,符合原本 Android 的預期輸出假設)
目前支援 Android Donut 與 Eclair,在 0xdroid 即是 beagle-donut 與 beagle-eclair,需要搭配最新的 0xlab-kernel,對 DevKit8000 週邊做出更好的支援。以下是簡要的功能特徵描述:
  • 支援 DevKit8000 特有週邊:Ethernet, LCD panel / touchscreen, keypad
  • 提供對應的使用者介面 (UI) 設定程式,包含 Ethernet 與 Touchscrren calibration UI
  • 延續之前 0xdroid 在 TI OMAP3 平台的效能改善成果
近期內我們將會釋出新的 image installer,並持續改善 TI OMAP3 平台的 Android Eclair,而在今年的 OSDC.tw 研討會上,有個針對 0xdroid 的議程,歡迎前來指教,也希望對 0xlab 一系列開放原始碼專案有興趣的朋友,可來 0xlab-devel 郵件討論區參與討論,謝謝!


Ten Months Asleep from Day » 0xlab   February 23, 2010

Ten months ago when we just established 0xlab, we do have some ideas regarding our business model in mind. We cannot say exactly what it is, since we are under the constraint of NDA. However, I can roughly outline our goals and our progress here.

In the world of open source, you gain credibility by contributing. The more credibility you have, the more powerful you become. Basically 0xlab’s initial and first goal is to open up our development, establish our credibility and get more publicity. Our policy to open up as much as we can turns out to be more beneficial then we have expected. Since we put our code in the open, any individual or business entity who is interested in us can evaluate our results directly. This leads to direct communication channel to developers inside some big companies such as Google, Qualcomm (Innovation Center), Broadcom, TI, EMBINUX (SQL Star) and Motorola, or even cooperation in business level.

We found out that since we don’t sell software for a living, but instead we use software to add value to the hardware (made by AzureWave), the work we did is actually beneficial to our sponsor, so they are willing to keep supporting us. This means a lot (in my opinion), since nobody in Taiwan believes that people can write open source for a living, until we proved them wrong. I believe we’re reproducing a ecosystem, which is not uncommon in Europe and US, but never shows up in Taiwan before.

Since we can support ourselves now, what’s the next step? I can’t disclose it, but suffice to say we are planning to take this a step further. We hope, once we proved that business can make money from openness, more Taiwanese companies can understand and duplicate our open source model, thus creates more modern software developers and stay closer to the world.


Filed under: 0xlab


New Bluetooth Object Push Profile in Android 2.0 (Eclair) Reading, Writing and Arithmetic   February 02, 2010

From Android developer website, they said Android 2.0 provides two new Bluetooth profiles: Object Push Profile (OPP) and Phone Book Access Profile (PBAP). Seeing is believing. Where is the meat? ha, I found they finally released their Bluetooth application source code. Therefore, I tried to verify OPP in Beagle board. :D

As usual, I read Build-from-Scratch wiki page and download code from 0xdroid project with beagle-eclair branch. LIke beagle-donut, I can use USB mouse, keyboard, mount a SD sdcard, use USB networking, and then I turn Bluetooth on. It's very easy to set up the working environment with 0xdroid.

Check Bluetooth application source code and install it in Beagleboard

cd packages/apps
git clone git://android.git.kernel.org/platform/packages/apps/Bluetooth.git
cd Bluetooth
git checkout -b eclair remotes/origin/eclair
git pull
source ../../../build/envsetup.sh
mm
adb install ../../../out/target/product/beagleboard/system/app/Bluetooth.apk


Trace related log
When we saw the log like below, it means it provides OPP service in RFCOMM channel 12 and PBAP service in RFCOMM channel 19.

I/bluedroid( 736): Starting hciattach daemon
I/bluedroid( 736): Starting bluetoothd deamon

I/bluetooth_ScoSocket.cpp( 797): Listening SCO socket...
V/BtOpp Service( 933): Service onCreate

V/BtOpp Service( 933): Starting RfcommListener in 9 seconds
V/BtOpp Service( 933): Service onStartCommand

V/BluetoothPbapService( 933): Pbap Service onCreate
V/BluetoothPbapService( 933): Starting PBAP service
V/BluetoothPbapService( 933): Pbap Service onStartCommand

D/BluetoothService( 736): Registering hfag record
D/BluetoothService( 736): Registering opush record
D/BluetoothService( 736): Registering pbap record

V/BluetoothPbapService( 933): Handler(): got msg=1
V/BluetoothPbapService( 933): Pbap Service startRfcommSocketListener
V/BluetoothPbapService( 933): Pbap Service initSocket
V/BluetoothPbapService( 933): Succeed to create listening socket on channel 19

V/BtOpp Service( 933): start RfcommListener
V/BtOpp Service( 933): RfcommListener started
I/BtOppRfcommListener( 933): Accept thread started on channel 12


Receiving and sending out data via Bluetooth

Currently, it only accepts few media types, like image, video, audio, text/plain and text/html and it should have the extension name. It cannot accept vcard and vcalendar. But we can modify few lines in 'Bluetooth/src/com/android/bluetooth/opp/Constants.java ', then it can store vcard files. One more problem, there is no matched application can view *.vcf file. I guess I can reference with previous beagle-donut code to fix it. All incoming files are stored in /sdcard/bluetooth folder. Also, there is a db file to record all Bluetooth application actions.

# cd /sdcard/bluetooth
# ls
08042009068.jpg
08042009068-1.jpg

# cd /data/data/com.android.bluetooth/databases
# ls
btopp.db
# sqlite3 btopp.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> .tables
android_metadata btopp
sqlite> select * from btopp;
1||08042009068.jpg||image/jpeg|1|00:18:C5:42:18:78|1|1|493|394450||946685154325|0
2|content://media/external/images/media/1|08042009068.jpg|/sdcard/bluetooth/08042009068.jpg|image/jpeg|1|00:18:C5:42:18:78|1|1|200|394450|394450|946685200379|1
3||olv.vcf|/sdcard/bluetooth/olv.vcf|text/x-vcard|1|00:18:C5:42:18:78|1|1|200|68|68|946685305125|2
4|file:///sdcard/bluetooth/08042009068.jpg|08042009068.jpg||image/jpeg|0|00:18:C5:42:18:78|1|2|200|394450|394450|946685368037|0
5||btopp_vcard.vcf|/sdcard/bluetooth/btopp_vcard.vcf|text/x-vcard|1|00:22:A5:B8:AD:65|1|1|496|168||946685701894|0
6||btopp_vcard.vcf|/sdcard/bluetooth/btopp_vcard.vcf|text/x-vcard|1|00:22:A5:B8:AD:65|1|1|200|168|168|946685806848|2
7||08042009068.jpg||image/jpeg|1|00:18:C5:42:18:78|1|4|490|394450||946698435289|0
8||08042009068.jpg||image/jpeg|1|00:18:C5:42:18:78|1|4|490|394450||946698501841|0
9|content://media/external/images/media/1|08042009068.jpg|/sdcard/bluetooth/08042009068.jpg|image/jpeg|1|00:18:C5:42:18:78|1|1|200|394450|394450|946698554454|1
10|content://media/external/images/media/2|08042009068-1.jpg|/sdcard/bluetooth/08042009068-1.jpg|image/jpeg|1|00:18:C5:42:18:78|1|1|200|394450|394450|946698717592|1
11|file:///sdcard/bluetooth/08042009068-1.jpg|08042009068-1.jpg||image/jpeg|0|00:22:A5:B8:AD:65|1|2|495|394450|0|946698901473|0
12|content://media/external/images/media/2|08042009068-1.jpg||image/jpeg|0|00:18:C5:42:18:78|1|2|200|394450|394450|946699019695|0


Screenshots from beagle-eclair

* Turn Bluetooth On
* Pair with Nokia N73 phone
* Receive an image from N73 to Beagle board via BT
* Send an image from Beagle board to N73 via BT



Automated test in Android by Sikuli Reading, Writing and Arithmetic   January 28, 2010

There is a very friendly and pretty cool project called 'Sikuli' and the authors are from Taiwan too. What is Sikuli? I copy these texts from its website. Sikuli is a visual technology to search and automate graphical user interfaces (GUI) using images (screenshots). The first release of Sikuli contains Sikuli Script, a visual scripting API for Jython, and Sikuli IDE, an integrated development environment for writing visual scripts with screenshots easily. Sikuli Script automates anything you see on the screen without internal API's support. You can programmatically control a web page, a desktop application running on Windows/Linux/Mac OS X, or even an iphone application running in an emulator.

How I use Sikuli for Android? Since we can catch things from screenshots, it means we can run Android emulator in my Ubuntu machine. Furthermore, I can run a vnc server in Android device, then run a vnc viewer in Ubuntu. Therefore, I can see Android HOME screen in my Desktop. What it can do for me? ha, it can run automated tests and then we don't need SQA to verify phone basic functionalities. Like detect GSM signal, dial out a phone call, enable Bluetooth, connect to WiFi hotspot....etc.

Launch Sikuli IDE editor in Ubuntu

wget http://sikuli.org/dl/Sikuli-IDE-linux-20100104.zip
unzip Sikuli-IDE-linux-20100104.zip
sh Sikuli-IDE/sikuli-ide.sh



Launch Android in Ubuntu

There is another tool "androidscreencast" I am using for this automated test. It can allow me to control my Android Dev phone remotely. We can have keyboard and mouse input! This is very important for Sikuli scripts, coz I can say "Click" something or "type" something. :)

wget http://androidscreencast.googlecode.com/svn/trunk/AndroidScreencast/dist/androidscreencast.jnlp
javaws androidscreencast.jnlp



Let's write some examples! Please check these draft videos!



Build Sikuli in Ubuntu 9.10 (64 bit)

1. download the source code (you'll need to install bzr, if you don't have it)
> bzr branch lp:sikuli

2. check java version (use java-6-sun)
erin@midnight:~/code/sikuli$ file /etc/alternatives/java
/etc/alternatives/java: symbolic link to `/usr/lib/jvm/java-6-sun/jre/bin/java'
erin@midnight:~/code/sikuli$ file /etc/alternatives/javac
/etc/alternatives/javac: symbolic link to `/usr/lib/jvm/java-1.5.0-sun/bin/javac'

3. install some libraries
tesseract-ocr - Command line OCR tool
tesseract-ocr-dev - Development files for the tesseract command line OCR tool
maven2 - Java software project management and comprehension tool
libcv1 - computer vision library
libcvaux1 - computer vision extension library
libhighgui1 - computer vision GUI library

4. build code
>cd sikuli-script
>make

g++ ScreenMatchProxy.o ocr-matcher.o template-matcher.o myocr.o screendiff.o -o ../../../target/lib/libScreenMatchProxy.so `pkg-config --libs opencv` -shared -L/usr/local/lib -I/usr/lib/jvm/java-6-sun/lib -ltesseract_full -ltiff
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../../lib/libtesseract_full.a(libtesseract_full.o): relocation R_X86_64_32 against `BLOCK_zapper(ELIST_LINK*)' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../../lib/libtesseract_full.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [../../../target/lib/libScreenMatchProxy.so] Error 1

how i solved: i removed -ltesseract_full, then rebuilt it!
>cd src/main/native/
>g++ ScreenMatchProxy.o ocr-matcher.o template-matcher.o myocr.o screendiff.o -o ../../../target/lib/libScreenMatchProxy.so `pkg-config --libs opencv` -shared -L/usr/local/lib -I/usr/lib/jvm/java-6-sun/lib -ltiff

>make install-jar (it would build sikuli-script.jar, that is what we need!)
>make release (it would build for all platforms, then zip to a file.)

erin@midnight:~/project/sikuli/sikuli-script$ make release
mkdir -p target/sikuli-script
rm -rf target/sikuli-script/*
cp target/sikuli-script.{bat,sh} target/sikuli-script
cp: cannot stat `target/sikuli-script.{bat,sh}': No such file or directory
make: *** [release] Error 1

how i solved: modify two lines in sikuli-script/Makefile and mkdir ../release
cp target/sikuli-script.bat target/sikuli-script.sh $(RELEASE_TMP_PATH)
cp -r $(LIB_PATH)/win32 $(LIB_PATH)/tmplib $(RELEASE_TMP_PATH)

Done! you will find a zip file 'Sikuli-Script-all-20100128.zip' in release directory.

>cd sikuli-ide
>make install-jar
>make major-release

Done! you will find a zip file 'Sikuli-IDE-linux-20100128.zip' in release directory. This one is like we download from Sikuli website for linux version.


Android Bluetooth in Eclair Reading, Writing and Arithmetic   December 28, 2009


If you noticed the source code in Eclair branch, you will find few differences in Bluetooth function. There are three new git repositories for bluetooth. "bluez", "glib" and "hcidump", all of them are located in /external/bluetooth folder, not /external/bluez anymore.

bluez
android source: git://android.git.kernel.org/platform/external/bluetooth/bluez.git
Eclair is using bluez version 4.47 and the big difference would be bluez API. Since it has a lot of changes between bluez3 (android 1.6) and bluez4 (Android 2.0), we can tell from the documents in doc folder. Or we can use dbus-send to get the detailed information.



# dbus-send --system --type=method_call --print-reply --dest=org.bluez / org.bluez.Manager.DefaultAdapter
method return sender=:1.2 -> dest=:1.3
object path "/org/bluez/932/hci0"

# dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/932/hci0 org.freedesktop.DBus.Introspectable.Introspect


Also, bluetooth service name is changed in Eclair. It's "bluetoothd" now. Check init.rc in /system/core/rootdir.


service bluetoothd /system/bin/bluetoothd -d -n
socket bluetooth stream 660 bluetooth bluetooth
socket dbus_bluetooth stream 660 bluetooth bluetooth
# init.rc does not yet support applying capabilities, so run as root and
# let bluetoothd drop uid to bluetooth with the right linux capabilities
group bluetooth net_bt_admin misc
disabled

glib
android source: git://android.git.kernel.org/platform/external/bluetooth/glib.git
When we build bluez library, it would build glib as a static library.
GLib provides the core application building blocks for libraries and applications written in C. It provides the core object system used in GNOME, the main loop implementation, and a large set of utility functions for strings and common data structures. If you are interested in how bluez use glib, you can trace bluez source code.

new Bluetooth API
http://developer.android.com/guide/topics/wireless/bluetooth.html
About Bluetooth, Android website has a very good document. It lists the functions and example code.


Bluetooth
* Turn on/off Bluetooth
* Device and service discovery
* Connect to a remote device using RFCOMM and send/receive data
* Advertise RFCOMM services and listen for incoming RFCOMM connection


Bluetooth Chat application
What I am curious? It's related to using RFCOMM and send/receive data. In the beginning, I am not quite understand and I thought it's OBEX. After running Bluetooth Chat application, I know what it means now. I installed 0xlab experimental eclair image in Beagle board and installed Bluetooth chat example from Android. I also run a python script in my ubuntu machine and it's from pybluez. Then, I can chat between Beagle board and my laptop via Bluetooth. When we start to run Bluetooth Chat application, it would create a RFCOMM socket and set it to listen mode. We can retrieve the information from sdptool. Then other BT devices can connect to Android using RFCOMM protocol and set channel to the same one.


# sdptool browse local
Browsing FF:FF:FF:00:00:00 ...
Service Name: BluetoothChat
Service RecHandle: 0x10005
Service Class ID List:
UUID 128: fa87c0d0-afac-11de-8a39-0800200c9a66
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 30


From Collages


Android with 3D Effects olv   December 25, 2009

年終了。

最近幾個月不知道為什麼,沒辦法專心工作。利用上 ptt 跟看漫畫的空檔,把說很久的特效弄出可以 demo 的樣子



感謝 Erin 的幫忙,這段影片展示了 Cube 跟 Fire 特效。 WindowManagerService 允許的地方都可以接特效,但現在只有接在程式啟動時。

目前的進展可以在 gitorious 上取得。不過很顯然地,還有很多東西要弄。


Recently Passenger in the galaxy   December 19, 2009

Sometime I feel like I need to slow down my pace and my mind and now the time it is. Either for quiet thinking, intending to watch more or thinking about changing something. As you can see, I am a lazy blogger and not a good writer. Passion is the momentum for anything you want to do and it's the best gift.

Here are something about my work recently. Write it down here for arrangement.
It's about 0xdroid project. I have done implementing Camera HAL for usb camera. For this, I need to have some concept about V4L2 in kernel. It's related to V4L2 Video In. Though camera is more complicated cause it can be greatly performance related when it comes to embedded device. For most product design, the camera sensor module is connected with the camera interface of the SOC. Thus in this manner, most cases there will be closed library provided by the SOC vendor for doing some effect control and performance related tasks.

When doing video recording with the camera, colorspace conversion for encoding and for preview on the screen to make the acceptable frame rate is really critical, especially when the resolution is high. Better situation will be more task can be handled by hardware. For taking picture, it would be better if the hardware can do scaling and jpeg encoding, etc. For previewing and video recording, it also would be cool if we don't need to do heavy colorspace conversion in host software side by hardware conversion(YUYV to YUV420(sp) or RGB) and Overlay support.

Overlay is cooperated with V4L2 video out part. Overlay verifying and could be used by Camera HAL or multimedia video playback is important.

More ahead. Though I need to let myself know what's the value and getting prepared.

Off topic here in this post, most importantly, Glad and excited that we have a third release, beagle-donut-0x3.



0xdroid beagle-donut-0x3 is released now! Reading, Writing and Arithmetic   December 18, 2009

So exciting is our brand new release called '0xdroid beagle donut-0x3' that we forgot all about the coming bad weather in Taipei (raining, humid, and chill). This is our third released image for Beagle board in Android and it's based on Donut branch. If you have a beagle board on hand, you may give it a try. We provide a 'Happy installer' tool and it could give you a 'no pain no tears' good experiences on installing Android. Here is a 2 minutes video in youtube based on real booting time! If you don't have any beagle board to see our work, you could take it a look from our released videos in youtube.


What kind of meat we have this time?

Easy access to Internet through USB OTG network routed via host
  • Ethernet support + USB OTG network with default static IP configurations ...
Performance improvements
  • Dalvik VM + JIT compiler for ARMv7 ...
  • ARM NEON optimizations for PixelFlinger ...
Theme Flexibility
  • Theme selector introduced ...
  • Flexible resolution support for Launcher ...
More and better peripheral support
  • External GSM modem for functional Android Telephony/RIL ...
  • Bluetooth OBEX OPush and FTP support ...
  • Motion sensor support ...
  • Camera capture / recording ...
Stability improvements with several issues fixed
  • Dalvik stability fix ...
  • Wifi signal strength with Linux Wireless Extension fix ...
  • Mouse stability fix ...
Here is our Roadmap about all these releases. If you have interest on particular item, you could get more information from our issue tracker. Furthermore, we welcome your feedback or any suggestion on 0xlab-devel mailing list!

Frankly speaking, my favorite feature in this released image is neither Bluetooth Obex nor GSM modem, what I like most is our theme launcher. It has a Christmas theme inside. This theme is our best wishes. Wish everyone have a Merry Christmas and a Happy New Year!





Motion Sensor Demo on Beagleboard Abacus   December 10, 2009

If you saw my previous post, it was mentioned my next step is to integrate this 3-axis accelerometer into Android. To prove my implementation could work flawlessly, I ask my colleague, Jeremy to record the following clip.

The demo application is called 3D Level.

The HAL implementation could be found here:
http://gitorious.org/0xdroid/hardware_libhardware

It's based on Michael's porting on Android for Openmoko GTA02.


libacc : Android 2.0 內建的輕量級 C Compiler Hacking at 0xlab   December 09, 2009

Android 2.0 (Eclair) 原始程式碼已於一個月前釋出,在目錄 system/core 下有個 libacc 的子項目,這是開發者修改自 Fabrice Bellard 的大作 OTCC (Obfuscated Tiny C Compiler),以 C++ 與 Android 的執行時期函式庫重寫。libacc 的功能是提供給 Android 2.0 的 RenderScript 一個 C-like 語法的描述,如此一來,開發者可撰寫高效能的視覺效果與動畫,不過這部份並未完成,詳情可參考 "Android renderscript, more info' and an example application" 一文。

關於 libacc 的整合部份,可參考 frameworks/base/libs/rs 目錄下的兩個檔案:
  • rsScriptC.cpp
  • rsScriptC_Lib.cpp
筆者準備了一份可單獨執行於 GNU/Linux 環境的套件:"libacc.tar.bz2",除去 Android 的相依性並補上 Makefile,測試方式如下:
libacc$ make
g++ -I./include -DHAVE_PTHREADS -c acc.cpp
gcc -I./include -DHAVE_PTHREADS -c hashmap.c
gcc -I./include -DHAVE_PTHREADS -c logd_write.c
g++ -I./include -DHAVE_PTHREADS -c tests/main.cpp
g++ -I./include -DHAVE_PTHREADS -c tests/runtimeTest.cpp
g++ -o main \
acc.o \
hashmap.o \
logd_write.o \
main.o \
-ldl
g++ -o runtimeTest \
acc.o \
hashmap.o \
logd_write.o \
runtimeTest.o \
-ldl
libacc 的 Code generator 支援以下硬體架構:
  • x86 / IA32
  • x86_64
  • ARMv5
以 IA32 的環境為例,可透過測試程式來驗證 libacc: (參數 -R 表示作執行的動作)
libacc$ ./main -R tests/data/hello.c
Executing compiled code:
Hello, world
result: 0
其中 tests/data/hello.c 的內容為:
libacc$ cat tests/data/hello.c
int main() {
printf("Hello, world\n");
return 0;
}
若平台是 ARM 的話,還可以支援反組譯輸出,libacc 是 RenderScript 背後很重要的基礎建設,允許動態編譯 Android Graphics 的 RenderScript,輸出成機械碼並執行。參考檔案 tests/runtimeTest.cpp 可得知 RenderScript 的寫法,整個 libacc 可內嵌於程式中,比方說:
const char* text = "void op_int(int a);\n"
"void op_float12(float a, float b, float c, float d,\n"
" float e, float f, float g, float h,\n"
" float i, float j, float k, float l);\n"
"void script() {\n"
" globalVar += 3;\n"
" op_int(123);\n"
" op_float12(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);\n"
"}\n";
這個字串經過 libacc 的函式呼叫後,可得到以下的編譯與執行結果:
libacc$ ./runtimeTest
Executing script:
op_int(123)
op_float12(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
After script globalVar = 20
目錄 tests 還包含可在 Android 環境執行的自動測試 Python script。


Build 3-axis Accelerometer on Beagleboard from Scratch Abacus   December 02, 2009

First of all, I would like to thanks Jerry, who is the project manager from STMicroelectronic Taiwan branch. He sponsored 0xlab couple chips of LIS302DL, which is a 3-axis accelerometer device. And Neo (YOSUN's FAE) provides me a fixture for this device. So everything is ready for me to make it work on the Beagleboard.

- LIS302DL
You probably feel it is looked familiar. Yes, this chip is the same motion sensor as Openmoko Freerunner used. The only difference is that its interface would be adopted I2C instead of 3-wire SPI for Beagleboard.

- Power source for LIS302DL
If you probe the schematic of Beagleboard, the expansion header (J3) reserved DC 5v and VIO 1v8 respectively. You can leverage these as the power source for your own devices. Unfortunately, the range of Vdd for LIS302DL is located between 2v16 and 3v6. DC 5v is not fulfilled for this case. So tinker DC 5v is needed. Zerner diode can regulator the voltage as you want. In this case, one reistor and one zerner diode are required.

- TSX0102
It's very Beagleboard specific or you can say it's TI specific. If you want to add an external device on the Beagleboard, a voltage level translator might be necessity. Since most of current devices, the least signaling I/O would be around 2v6. But Beagleboard only provides 1v8 voltage as I/O signaling. The real reason behind this I don't know about it. Maybe for the power consumption issue. Or can I call it's a kind of "product placement"? :p


- Interrupt
Basically, all the I/O to the host controller, Beagleboard, are based on 1v8 signaling. The I2C communication is through TXS0102 to talk between host and device. But there is one more line for one-directional signaling, that is interrupt from LIS302DL to host. My former colleague, Dkay, suggested a simple approach to reslove this. A diode and two pull high resistors would be enough.

- Kernel driver
The corresponding kernel driver is put here:

http://gitorious.org/0xlab-kernel/kernel

Edit your kernel config with CONFIG_INPUT_ST_MOTION_SENSOR=y.


The following picture is the overall picture for this work. Although it's not pretty, but it works perfectly. With evtest utility, I can retrieve input events from LIS302DL device.




# ./evtest /dev/input/event1
Input driver version is 1.0.0
Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0
Input device name: "LIS302DL Motion Sensor"
Supported events:
Event type 0 (Sync)
Event type 3 (Absolute)
Event code 0 (X)
Value 3
Min 0
Max 0
Event code 1 (Y)
Value 245
Min 0
Max 0
Event code 2 (Z)
Value 56
Min 0
Max 0
Testing ... (interrupt to exit)
Event: time 12.269714, type 3 (Absolute), code 0 (X), value 4
Event: time 12.269989, type 3 (Absolute), code 1 (Y), value 245
Event: time 12.270233, type 3 (Absolute), code 2 (Z), value 55
Event: time 12.270233, -------------- Report Sync ------------
Event: time 12.273864, type 3 (Absolute), code 0 (X), value 3
Event: time 12.274200, type 3 (Absolute), code 2 (Z), value 56
Event: time 12.274200, -------------- Report Sync ------------
Event: time 12.284332, type 3 (Absolute), code 0 (X), value 4
Event: time 12.284545, type 3 (Absolute), code 1 (Y), value 244
Event: time 12.284698, -------------- Report Sync ------------
Event: time 12.294403, type 3 (Absolute), code 0 (X), value 3
Event: time 12.294799, type 3 (Absolute), code 2 (Z), value 55
Event: time 12.294799, -------------- Report Sync ------------
Event: time 12.304840, type 3 (Absolute), code 1 (Y), value 245
Event: time 12.305023, -------------- Report Sync ------------
Event: time 12.315063, type 3 (Absolute), code 1 (Y), value 244
Event: time 12.315277, type 3 (Absolute), code 2 (Z), value 56


So, what's the next? Making it integrated into Android would be a good idea.


Provide Bluetooth FTP profile in Android Reading, Writing and Arithmetic  

About providing Bluetooth FTP & OPP profile issue, I've merged all related source code to 0xdroid begle-donut branch. I verified these two services in both Beagle board and Android Dev phone. It looks good now.

When we turn BT on, we start 'obex-client' service in the background. It would register a record to SDP server in bluez and then other BT devices can find we provide this service. How it looks like? We provide channel 7 for FTP. Other BT device can browse our file system using rfcomm. They can pull data from us, modify file name, delete file, or push data to us. Below it's FTP record in SDP database:


Service Name: File Transfer server
Service RecHandle: 0x10003
Service Class ID List:
"OBEX File Transfer" (0x1106)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 7
"OBEX" (0x0008)
Profile Descriptor List:
"OBEX File Transfer" (0x1106)
Version: 0x0100





Let's explain it and trace the source code.
Eg. CreateSession method call in obex-client dbus API

How we connect obex-client with Bluetooth UI? [using JNI, aidl, and d-bus]
We register a FTP service from AndroidRuntime. We also create few methods and it's based on obex client API document. Below texts are related source code:

AndroidRuntime.cpp

REG_JNI(register_android_server_BluetoothFtpService),

android_server_BluetoothFtpService.cpp

int register_android_server_BluetoothFtpService(JNIEnv *env)
{
jclass clazz = env->FindClass("android/server/BluetoothFtpService");

method_onCreateSessionComplete = env->GetMethodID( clazz, "onCreateSessionComplete", "(Ljava/lang/String;Ljava/lang/String;Z)V" );
method_onChangeFolderComplete = env->GetMethodID( clazz, "onChangeFolderComplete", "(Ljava/lang/String;Ljava/lang/String;Z)V" );

return AndroidRuntime::registerNativeMethods(env,
"android/server/BluetoothFtpService", sMethods, NELEM(sMethods));
}


Below text is the sequence from UI to native code and then back to UI.

RemoteFileManagerActivity.java (Pick up one device from remote tab in Bluetooth UI)

public boolean onOptionsItemSelected(MenuItem item) {
// Intent intent;
switch (item.getItemId()) {
case MENU_SELECT_SERVER:
if (mFTPClient.isConnectionActive()) {
Toast.makeText(this, R.string.error_ftp_connect_timeout, Toast.LENGTH_LONG).show();
} else {
/* Connect to Server */
handleServerSelect();
}

public void handleServerSelect() {
mDirectoryButtons.removeAllViews();
currentDirectory = "/";
if (mContext.isBluetoothEnabled()) {
Intent intent = new Intent(getApplicationContext(), BluetoothDevicePicker.class);
intent.setAction(BluetoothAppIntent.ACTION_SELECT_BLUETOOTH_DEVICE);
intent.putExtra(BluetoothAppIntent.PROFILE, BluetoothAppIntent.PROFILE_FTP);
intent.setData(Uri.parse("file://" + currentDirectory));
try {
startActivityForResult(intent, SUBACTIVITY_PICK_BT_DEVICE);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "No Activity for : " + BluetoothAppIntent.ACTION_SELECT_BLUETOOTH_DEVICE, e);
}
}
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

switch (requestCode) {
case SUBACTIVITY_PICK_BT_DEVICE:
if (resultCode == RESULT_OK && data != null) {
/* Obtain the Server name and Address */
String serverAddress = data.getStringExtra(BluetoothDevicePicker.ADDRESS);
String serverName = data.getStringExtra(BluetoothDevicePicker.NAME);
if (mFTPClient != null) {
mFTPClient.setAddress(serverAddress);
mFTPClient.setName(serverName);
mServerConnectButtonLayout.setVisibility(View.GONE);
if(mFTPClient.createSession() != true) {
String szStr = getResources().getString(R.string.ftp_connect_failed, mFTPClient.getName());
Toast.makeText(this, szStr, Toast.LENGTH_LONG).show();
updateServerStatus();
} else {
String szStr = getResources().getString(R.string.ftp_connect_device, mFTPClient.getName());
showBusy(mFTPClient.getName(), szStr);
}
}
}
break;
}
} /* onActivityResult */

BluetoothFtpService.java (handle from Android Frameworks)

public synchronized boolean createSession(String address, IBluetoothFtpCallback callback) {
/*
* Need to register callback before calling native code
* (which could potentially call callback)
*/
BluetoothObexDatabase.SessionDbItem dbItem =
mSessionDb.new SessionDbItem(address,null,callback);
mSessionDb.insert(dbItem);

boolean ret = createSessionNative(address);

if (!ret) {
mSessionDb.deleteByAddress(address);
}

return ret;
}

android_server_BluetoothFtpService.cpp (use JNI and send a dbus method call to obex-client)
 
static jboolean createSessionNative(JNIEnv* env, jobject object, jstring address )
{
DBusMessage *msg = dbus_message_new_method_call(OBEXD_DBUS_CLIENT_SVC,
OBEXD_DBUS_CLIENT_PATH,
OBEXD_DBUS_CLIENT_IFC,
OBEXD_DBUS_CLIENT_CREATE);

pending = (dbus_async_call_t *) malloc(sizeof(dbus_async_call_t));
if (pending)
{
DBusPendingCall *call;
char *context_address = (char *) calloc(BTADDR_SIZE,
sizeof(char));
strlcpy(context_address, c_address, BTADDR_SIZE); // for callback
pending->env = env;
pending->user_cb = onCreateSessionComplete;
pending->user = context_address;
pending->nat = nat;
dbus_bool_t reply = dbus_connection_send_with_reply(nat->conn,
msg,
&call,
10*1000);

/external/obexd/client/main.c (handle from obex-client)

static DBusMessage *create_session(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
if (session_create(source, dest, target, create_callback, data) == 0)
return NULL;

/external/obexd/client/session.c (use rfcomm to connect with specific channel )

int session_create(const char *source,
const char *destination, const char *target,
session_callback_t function, void *user_data)
{
if (session->channel > 0) {
err = rfcomm_connect(&session->src, &session->dst,
session->channel, rfcomm_callback, callback);

android_server_BluetoothFtpService.cpp (we get the callback!)
 
static void onCreateSessionComplete(DBusMessage *msg, void *user, void *nat_cb)
{
char* c_address = (char *)user;
JNIEnv *env = NULL;
nat->vm->GetEnv((void**)&env, nat->envVer);
jstring address = env->NewStringUTF(c_address);

env->CallVoidMethod(nat->me,
method_onCreateSessionComplete,
obj_path,
address,
is_error);

BluetoothFTPClient.java (handle from Bluetooth UI)

public void onCreateSessionComplete(boolean isError) {
Message msg = Message.obtain();
msg.what = TYPE_CREATE_SESSION_COMPLETE;
Bundle b = new Bundle();
b.putBoolean("isError", isError);
msg.obj = b;
mHandler.sendMessage(msg);
}


RemoteFileManagerActivity.java (device is connected, going to refresh panel to display Remote file system)

public void onCreateSessionComplete(boolean isError) {
mSessionCreated = !isError;
hideBusy();
if (mFTPClient != null) {
if (isError == false) {
mContext.onServerConnected();
goHomeDir();
} else {
String szStr = getResources().getString(R.string.ftp_connect_failed, mFTPClient.getName());
Toast.makeText(this, szStr, Toast.LENGTH_LONG).show();
}
}
updateServerStatus();
refreshDirectoryPanel();
}



© 2009 0xLab All rights reserved
All trademarks are the property of their respective owners.