CAN/ISOBUS Enabled Android
This project is still evolving. Hence, there might be major changes to different parts of the project coming soon. This README will be updated frequently to reflect these changes.
- 1 x rooted [Nexus 9][N9]
- 1 x OTG Y-cable like [this][ycable]
- 1 x USB hub
- 2 x USB2CAN adapters from [8devices][usb2can] [N9]:https://www.google.com/nexus/9 [usb2can]:http://www.8devices.com/usb2can [ycable]:http://www.amazon.com/WOVTE-Micro-Cable-Galaxy-Samsung/dp/B00WWHNY0W
NOTE: Depends on the specific project, extra materials should be needed. For ISOBUS purposes, ISOBUS plugs are needed.
- Android NDK from [Google][ndk]
- adb and fastboot
- abootimg
- Nexus 9 kernel source code repo tegra from [Google][tegra] [ndk]:http://developer.android.com/ndk/downloads/index.html [tegra]:https://android.googlesource.com/kernel/tegra/
- Root and unlock your Nexus 9
- Install adb and fastboot
- Install Android NDK Download Android NDK and decompress it. What we want is in this directory:
your-android-ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin
It has prebuilt compiler for compiling the Android kernel. Make your sure you add these files to your system path. To verfiy, run:
$ aarch64-linux-android-gcc --version
You should get something similar like this:
aarch64-linux-android-gcc (GCC) 4.9 20140827 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- Install abootimg
- You may also want to add udev rules for Android devices to your system
Copy candroid.patch from this repo into tegra repo. Check out android-tegra -flounder-3.10-lollipop-mr1 branch and apply the patch:
git am candroid.patch
NOTE: This patch contains changes for both enabling OTG charging and ISOBUS as a builtin module.
Then, do:
$ export ARCH=arm64
$ export SUBARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-android-
$ make flounder_defconfig
Rename your config to .config, copy .config into tegra repo and do:
$ make all -j4
This generates a kernel image Image.gz-dtb in arch/arm64/boot.
Using the boot.img.test provided in this repo, run:
$ abootimg -u boot.img.test -k tegra/arch/arm64/boot/Image.gz-dtb
If the command gives an error complaining about bootsize, run the above command with -c bootsize=VALUE. VALUE is the larger value given in the error message.
NOTE: Details on how boot.img.test is generated can be found [here][bootimg] [bootimg]:http://forum.xda-developers.com/nexus-9/general/kernel-source-code-t2930286/page2
Connect your Nexus 9 into your computer, run:
$ adb devices
You should be able to see your device with a serial number if it's properly connected.
Then, reboot into bootloader:
$ adb reboot bootloader
Given that the device is unlocked, in the same directory where boot.img.test is, run:
$ fastboot boot boot.img.test
Nexus 9 should boot into the kernel you just compiled. To verify, on Nexus 9, go to Settings, About tablet, and in Kernel version you should see "candroid" being appended.
If you think the new kernel image is tested, you can flash the image by rebooting into the bootloader and then run:
$ fastboot flash boot boot.img.test
Now, you should have an Android device that has OTG charging capabilities and CAN/ISOBUS interfaces.
![Sample Connection][diagram] [diagram]: diagram.png NOTE: You don't have to have a power source unless you want to use OTG charging. NOTE': Currently, although charging is taking place in OTG mode, the battery gauge in system UI will not be updated accordingly.
This utility allows user to excute adb commands over Wifi. You can typically find this utility in Google Play Store.
can_log_raw.c can be found in tools/ and candroid-up/down.sh can be found in scripts/.
can_log_raw.c listens to all available CAN interfaces and print out CAN frames to stdout.
candroid-up/down.sh set and brings up can0 and can1.
To cross-compile can_log_raw.c, you need to have ndk-build in your system, and then in the tools directory do:
$ ndk-build V=1 NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk
After a succcessful build, the binary should be in libs/.
Then, move the scripts and the binary to Nexus 9. For example, after connecting to the device, do:
$ adb push can_log_raw /data/local/tmp
NOTE: You need to make the binary executable and have the right permission in order to execute it.
Wire the connections as in the Sample Connection.
The driver 8devices's USB2CAN adapter is already built into the kernel. So, when the adapters are plugged in, interfaces like can0, can1 will be automatically set up (but not the bitrate).
In Android's shell, cd into where scripts are stored, do:
# ./candroid-up.sh
This will birng up can0, can1 with 250kbps as bitrate.
Then, run the logger:
# ./can_log_raw > can-data.txt
Data should be redirected into the file you specified.
To stop the logger, in another Android's shell session, do:
# ./candroid-down.sh