Controlling external camera with Android smartphone - android

I would like to write an Android app to pass commands to an external camera whose SDK is available from the manufacturer's website. The SDK is C-based and the camera I/O is done through a mini-USB or mini-HDMI ports. This is a two part question:
Can Android-based smartphones send commands to external USB devices? I do know that they can access data from an external USB device.
Will C wrappers for Java (that work on laptops) work on Android-based smartphone?

Q: Can Android-based smartphones send commands to external USB
devices? I do know that they can access data from an external USB
device.
A: Sure, as long as the device is connected via the Android USB port :)
Q: Will C ... work on Android-based smartphone?
A: With much effort, you can interface Java and C on android (analogous to JNI on other platforms). Look at the NDK docs for more details.
Q: Can I interface a binary C language library that's probably written
for Windows, in i386 object code, from Java, on Android, running an
ARM CPU?
A: Nope. It's more than just a different language. You're also dealing with a different platform, different object formats, and a completely different CPU architecture.
Your best bet is if the vendor can provide either a USB-level or message-level interface to the device. You're pretty much SOL with a binary .dll or .lib library interface.

Related

Hardware Access

I've always liked cheap smartphones ($ 50) because with little money I can have a powerful system with lots of sensors and things like that. So I wondered if it was possible to use the hardware without using the very limited android APIs, programming it at a low level then, of course with the root. In particular I wanted to see how the LTE module worked and experiment with this having full control, the Android API does not allow it to do much.
UPDATE: I'm using something called libhybris, a wrapper that permit the use of android driver blobs in Linux.
The first layer of software for the phone is the bootloader. It tells the processor what partition to load into memory for executing the kernel. This is the level that is usually blocked by manufacturers because of greedy corporate reasons that are beyond the scope of this site.
The second layer of the phone is the linux kernel. Rooting is the process of gaining root user access to this layer. Root is the main administrator user account that has permission to do anything to the device. Accessing this layer is what most people refer to rooting. A large portion of the kernel is written in C, with other parts in c++. What happens at this level is where all the magic is. For most phone this is where the code for the modem resides. Talking to this can usually be done via at commands of serial. Sensors are also programmed at this level and communicate via drivers. Root access is not normally needed to read sensor data, its just a case of permissions usually.
The next level is the android operating system, the java instance runs on top of that, which in turn executes the android operating system. This is the portion that most users will see and is primarily written in java. In reality you can run any kind of user interface at this level.
A very brief view of android apps.
The android api provides a way for java developers to write "apps" that communicate with the kernel and access different parts of the phone's hardware. These apps can also be written using c++. Only until recently has google integrated c++ into android studio, but the most common and still most effective method of doing so is using the QT framework.
It's a bit problematic.
Hardware manufacturers do that actually.
Take into account that Android is Linux much like other distributions.
The manufacturers develop hardware and then compile a version Android that sits on top of it. Each Android compilation is specifically tailored to the hardware and equipped with drivers that enable the main OS access to the different hardware capabilities.
For example, some tables will tweak the Android OS to not support cellular communication because they decided to cut costs and deliver the tablet without a cellular module.
From here you have 2 options:
To hack a specific hardware and understand how the OS communicates with the hardware.
Find hardware manufacturers that release some/all of their Android OS code. This is a much simpler way as you can both learn and extend the Android OS for that specific device.
An example of the 2nd way is Sony who has AOSP that allows low-level access to some of the Sony devices.
Also, there is always the Android NDK which gives you a more low-level access to Android but you are still constrained by the KIT API so I'm not sure it will help you.
I'm using something called libhybris, a wrapper that permit the use of android driver blobs in Linux.

Run Machine Code On Android Devices?

Is Way To Run Machine Code Instead Android OS In Android Devices ?
I Want Remove Android Os And Work With Cpu And Other Devices Directly .
What Compiler I Can Use ?
MASM is an x86 assembler, so it would not be suitable for most Android devices as the vast majority use ARM-based processors.
That said, Android phones are computers just like any other and can be programmed in assembly. The first thing you'll need to do is select a device running a well documented CPU and chipset.
Since you'll be removing Android and plan on programming in assembly you'll need to write your own routines for nearly everything. An understanding of the CPU, power management and some form of I/O (you can avoid having to write complex display code if you plan to interface with the phone through serial communication, for example).
Unfortunately, much of the information required for successfully writing your own OS for an Android device is unavailable so you'll need some hardware analysis tools to assist in reverse engineering some of this information. A logic analyzer may be useful in sniffing some of the protocols used between chips, although much of modern phones is done on a single SoC, so you'll need to experiment heavily and compile information from a wide variety of online sources.
Aside from that, it's smooth sailing. Programming an OS in assembly for Android is pretty much the same as programming an OS in assembly for any other computer and you'll find it to be rather familiar territory.

How do I expose a USB device to the Java API through HAL?

Background:
I'm trying to integrate a new sensor into an Android platform. For development purposes, I am using a Nvidia Jetson-TK1 dev board and a Spark Core. The Spark Core communicates with the sensor and outputs the data serially through USB.
At a high level, my needs are:
To be able to read/write serial data to the Spark Core over USB
To handle the data with Android Service written with the API
Accomplish all this at high speeds
In the future when I become more experienced at working with the HAL, I may eliminate the Spark Core completely and use the GPIO pins on the Jetson to control the sensor IC.
Onto the Details:
I can read the data through the command cat /dev/ttyACM0, but I'm looking for a more low-level approach. I want to use the HAL to communicate with the device. Specifically, I want the Spark Core to show up when I cat /proc/bus/input/devices.
Then I want to be able to read the data using getevent /dev/input/eventXX.
The Main Question:
Here is my approach:
Find or develop a USB device driver in native C code
Use JNI to compile the driver within Android source code
Create a HAL module (.so binary) with a HAL definition
Compile Android source code into the kernel
Flash onto the Jetson
Profit
Is this correct? Can someone point me in the direction of what I would take as a first step? I'm mostly confused because I know Android is built on the Linux kernel and the Linux kernel should have USB device drivers built into it (right?)

How to use Linux C++ drivers for USB sensor on Android?

I'm currently working on an Android project, where I have to collect data from a USB thermometer stick, called Temper, which will be directly connected to a tablet.
This device has Linux drivers, written in C, and I would like to make use of them for my Android app.
Do you know how to integrate those drivers into my apk, or somewhere else?
Or is it possible just to use the android.hardware.usb package (Android 3.0+), thus making my own "driver"?
Thanks in advance.
Option a) you compile just the kernel modules and use the specific device nodes. This would require rooting your device and compiling specific kernel modules for specific kernels for specific devices (ugly!)
Option b) you write a wrapper around the Linux drivers using NDK and let the wrapper be the man-in-the-middle between the Android USB Host interface (Java) and the Linux drivers (C) coordinating all events and pushing data around.
I started work on option b) for usb-dvb device drivers, and it's an incredible amount of work to do. I hope your driver isn't that complicated.
If your driver is very easy (only few files and not 10k+ lines of low-level code or even assembler) to translate into Java, go ahead and use
Option c) re-write C code in Java. Thus you don't need a wrapper in C and you can skip the NDK part which saves you lots of trouble and nightmares.

android: api to external usb devices for robotic applications

Android devices become incredible cheap (especially those with android v1.6). I'm considering to use one as a brain of autonomous robot. Unfortunately I didn't find any info on that.
I would like to connect two external USB-webcams and some DIY-selfmade USB ADC & output-ports converter to steer the wheels and read analog distance sensors. If I choose some cheap netbook than they usually already have 3 usb ports. But if I will be forced to use a tablet, then it requires also an usb hub.
Do android devices support usb-hubs?
Is there any API to grab still frames from external usb webcams (e.g. "vfa://0" & "vfa://1")
Is there any API to read from USB custom device? Let assume that it will simulate serial port for simplicity.
Do I get all of this in android 1.6 or any newer version?
As an update for your information: Based on answers I assume that android device will be too expensive in comparison to effort. I will go for cheap atom netbook with standard linux & arduinio USB device for controls & sensors. At cost of half kg (one pound) heavier device I will save months on learning & development.
You need an android device that either supports usb host mode out of the box (a few of the cheap tablets apparently do) or a phone that can do so with custom usb power wiring and perhaps a new kernel driver (as many phones can).
You will likely need root.
The api would be the normal linux USB stack, including just about any C-coded source-available device driver available for a desktop linux (excepting those that use bits of x86 binary windows drivers run in a compatibility wrapper).
You could interact with that either from the ndk using normal methods (device files, read/write/ioctl) or with careful driver design so things really look like files you can probably get at some of it from java or at the very least java with some thin ndk wrappers around device file operations.
Essentially, this isn't an "android" question, it's a question about the capabilities of a particular android device's hardware, how to get root on that device, and then it becomes a standard embedded linux question.
As far as I know you won't get any of this with the default Java API. Lots of this stuff can however be achieved if you build a custom kernel and add needed modules to it. Basically it all comes down to kernel hacking and won't be really Android related.
I'm very interested in stuff like that myself so keep me updated please.

Categories

Resources