Migrating C code that talks to a USB glucometer device from Linux to Android

3

Post for StackOverflow: Android 2.2 USB SW Support

I have a Bayer USB glucometer that I reverse engineered using a usbsnoop tool in Windows.

I also found a Perl script to convert the usbsnoop output into C code which initiates data transfer from the USB device when executed.

When I plug the glucometer into my (x86) laptop, and run the compiled C code on Ubuntu, the readings are captured from the meter and printed to the shell. (These readings are not viewable just by simply plugging the USB meter into the laptop, i.e., I cannot get the data I need by opening a file.)

I want to do something similar with Android. The communication with the glucometer will be part of an app running on a phone running Android 2.2.

Does anyone have suggestions on how to do this?

My complete C code is on Google docs, snippets are posted below. The key library that I use is libusb.

I believe USB support will not be officially available until Android 3.1, and although I have seen some mention of a Java libusb wrapper, it is dated 2009, and I have not been able to understand how to use it.

So I wanted to know if there are any applications that have used that Java libusb wrapper successfully and/or if there are more current solutions for USB support on Android 2.2.

I am using a Motorola Droid and have been able to get the phone in USB host mode using this hack.

Thanks in advance for your help.

Here are a snippets of my C code that works on Ubuntu; I compile it using sh> gcc driver.c -o driver -lusb

usb_init();
usb_set_debug(255);
usb_find_busses();
usb_find_devices();

...

vendor = strtol(argv[1], &endptr, 16);
product = strtol(argv[2], &endptr, 16);
dev = find_device(vendor, product);
assert(dev);
devh = usb_open(dev);

...
// the following code is autogenerated using usbsnoop2libusb
memcpy(buf, "\x00\x00\x00\x02\x52\x7c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x0000040);
ret = usb_interrupt_write(devh, 0x00000001, buf, 0x0000040, 1000);
printf("137 interrupt write returned %d, bytes: ", ret);
print_bytes(buf, ret);
printf("\n");
usleep(3*1000);
ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000040, 1000);
printf("138 interrupt read returned %d, bytes: ", ret);
print_bytes(buf, ret);
printf("\n");
usleep(19*1000);
memcpy(buf, "\x00\x00\x00\x02\x53\x7c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x0000040);
ret = usb_interrupt_write(devh, 0x00000001, buf, 0x0000040, 1000);
printf("139 interrupt write returned %d, bytes: ", ret);
print_bytes(buf, ret);
printf("\n");
usleep(2*1000);
ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000040, 1000);
printf("140 interrupt read returned %d, bytes: ", ret);
print_bytes(buf, ret);
printf("\n");
java
android
usb
android-2.2-froyo
jini
asked on Stack Overflow Jul 2, 2011 by adnan • edited Sep 24, 2011 by Jonathan Leffler

1 Answer

0

I have diabetes and am using the Glucometer Deluxe software, a java program on my Windows XP machine. The software lacks many features such as being able to adjust the vertical scale on the graph of glucose versus time, it is fixed at 600 which is too high. It also background colors the graph which makes black and white laser printouts hard to read. Furthermore it's printout of readings is so verbose it takes many many pages wasting paper, a simple spreadsheet format would be better.

In general programming for Android is done in Java. It seems to me using the JAD Java Decompiler , http://en.wikipedia.org/wiki/JAD_%28JAva_Decompiler%29 , on the provided Glucometer Deluxe software might be a way to hack the code. It won't be easy.

If this works you would also be able to improve the Java program for PC's etc as well as get it to work on Android.

cdh@cdhconsult.com

answered on Stack Overflow Jul 23, 2011 by Charles Havener

User contributions licensed under CC BY-SA 3.0