DistoX + Android

foobarbecue

New member
I'm very interested in getting my DistoX to work with my Android device. This possibility has been mentioned in two other threads on this forum but I'd like to have a thread where people can discuss how to do this and post their successes.

My device is a Motorola Defy phone -- totally waterproof and surprisingly tough; I have taken it caving and would recommend it for cave use.

I guess the best starting point is to get TopoLinux working on Android. The new [url http://sourceforge.net/p/necessitas/home/]Necessitas Suite[/url] provides QT for Android, so it should be possible to get TopoLinux running.

I've also been thinking about porting Tunnel (survey program by Julian Todd) to Android and implementing DistoX data grabbing in that program. Since Tunnel is already written in Java, this seems fairly feasible.

Anyone want to collaborate on this stuff?

Aaron Curtis
 

martinm

New member
Hi Aaron.

I too have a Motorola Defy phone. I love it. I am also thinking of starting to develop apps for it as it's standard Java (J2SE) which I have experience of.

Currently for surveys I use Compass for Windows, (in an emulator, VMWare, on Linux), but I've also got Palm OS software to produce surveys, just haven't got round to doing anything with any of it yet.

I also have a Disto A3, though sadly couldn't afford an X upgrade.

So, in summary, I would be interested in helping with this if I can.

Regards, Mel.
 

foobarbecue

New member
Mel, glad to hear you're interested. In the last couple of days I got a start on this project by writing a script to download legs from the DistoX. The script is written in python and runs on Android using the Scripting Layer for Android (SL4A). It seems to work pretty well.

I've also gone through a bunch of the Android tutorials (java, don't know if this is what you'd call J2SE or J2ME) and am thinking about porting this script into a java application. After learning some Android UI stuff I think it may be better not to bother trying to port any of the topolinux interface, or trying to cross-compile it using the android NDK, but I think it could be re-written in the form of an android app. Either I'd like to get commit access to the topolinux googlecode repository and do it there or else start a new googlecode repository.

Code:
''''''
Created on May 26, 2011

@author: Aaron Curtis
'''

import android
from base64 import b64decode, b64encode

distoMacAddr='10:00:E8:C0:F2:D8'

def connectToDstx(distoMacAddr=distoMacAddr):
    """
    Connect to the DistoX at distoMacAddr and return an android object.
    """
    dr=android.Android()
    dr.bluetoothStop()
    dr.bluetoothConnect('00001101-0000-1000-8000-00805F9B34FB','10:00:E8:C0:F2:D8')
    return dr

def getAleg(dr):
    """
    Download one leg from the DistoX connected to android instance dr
    and return it as a string of hex characters. Also sends acknowledge
    byte to DistoX.
    """
    dstxPacket=b64decode(dr.bluetoothReadBinary(8).result)
    firstByte=ord(dstxPacket[0])
    print dstxPacket
    #Send acknowledgement.
    if firstByte==0b00000001:
        dr.bluetoothWriteBinary(b64encode(chr(0b01010101)))
    elif firstByte==0b10000001:
        dr.bluetoothWriteBinary(b64encode(chr(0b11010101)))
    return dstxPacket
          

def getAllLegs(dr):
    """
    Take download all survey legs from the DistoX connected to android
    instance dr, and return them as a list.
    """ 
    legs=[None]
    while legs[-1]!='':
        #get a leg
        legs.append(processLeg(getAleg(dr)))
        print legs[-1]
        dr.makeToast(str(legs[-1]))
    #Trim off the None that we used to avoid an IndexError
    legs=legs[1:]
    return legs

def processLeg(leg):
    """
    Given a DistoX leg as a string of hex characters, returns
    a dictionary of the data.
    """
    distance=ord(leg[1])+(ord(leg[2])<<8)+(ord(leg[0])&7)
    compass=((ord(leg[3])+(ord(leg[4])<<8))*360.0/2**16)
    clino=((ord(leg[5])+(ord(leg[6])<<8))*360.0/2**16)
    outp={'distance':distance, 'compass':compass, 'clino':clino}
    return outp
    
    
dr=connectToDstx()
outp=getAllLegs(dr)
 

wookey

Active member
Hi, I've built and used topolinux. At some point I'll get round to packaging it for Debian & Ubuntu. I have so far failed to get it going on my linux phone (openmoko running SHR), but I haven't actually tried very hard. I will have a go in time for expo this year. I was waiting for Marco Corvi to put the distoX calibration routing into the code (which he had agreed not to do until Beat's article waqs published, but that was done early in 2010 so there should be no problem now. I'll poke him again.

I don't have any android devices (poor-man's linux :), but I suppose I might end up getting one as they are plentiful.

Topolinux interface is a bit too desktop-oriented, as that's how the author has been using it. Pockettopo has a better in-cave interface, but it also has annoying bugs, especially for a UK caver, and it's nonfree so we can't fix it, or build it for linux/android etc. As you say a re-implementation of the good bits of pockettopo and topolinux is the best answer. If we do it right it'll be fairly easy to build it for android or linux.

In principle I'd love to help but a) I have way too many thing to do already and b) I don't know how to write GUI software or java. All sorts of monkeys seem to write Android apps, so I guess it's not actually that hard, but I'm not sure when anything might happen. I am a cross-building guru though so I can probably help out with some stuff.
 

marco_corvi

New member
Making TopoDroid an Android app for the DistoX.
Any help (develop, docs, test, ... ) is appreciated.

source and compiled (debug) apk are on code.google.com/topolinux

marco
 
Top