GPS Data Transfer (NMEA) from Android to Windows



    Introduction


    Under windows there are applications that need NMEA messages from a GPS device transmitted over a COM port. Under Android, it’s possible to generate such messages using the API. In general, there was an idea to deliver data to a virtual COM port from Android. If you are interested in how this was implemented, I ask for a cat.


    What had to be done?


    The following was required to be implemented:
    • Configure TCP / IP connection between device and PC
    • Get NMEA data on Android'e
    • Send them over UDP to a computer
    • Receive a UDP packet on the computer and send it to the COM port


    TCP / IP connection


    The connection was organized using Revers wired tether, for this, root rights were obtained on the phone and using the android-wired-tether program a TCP / IP connection to the PC was created. Why not over WiFi? Yes, there is such an opportunity, you can create a virtual WiFi adapter on windows 7 and will already connect to it from Android. But my Atheros AR5B95 adapter after 5 minutes of connection led the system to a blue screen, so it was decided to create a connection all the same via wire + it also charges the device, which is not unimportant when working with GPS (it is voracious in terms of power).

    NMEA data from Android, receive and send


    Data on Android was obtained with the following code: And it was transferred to the SendNmea2UDP method that sent them to the PC’s UDP port:
    //NMEA listener
    LocationManager LM = (LocationManager) getSystemService(Context.LOCATION_SERVICE); ((LocationManager)getSystemService(Context.LOCATION_SERVICE)).requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,new LocationListener(){
    @Override
    public void onLocationChanged(Location loc) {}
    @Override
    public void onProviderDisabled(String provider) {}
    @Override
    public void onProviderEnabled(String provider) {}
    @Override
    public void onStatusChanged(String provider, int status,Bundle extras) {} });

    LM.addNmeaListener(new GpsStatus.NmeaListener() {
    public void onNmeaReceived(long timestamp, String nmea) {
    SendNmea2UDP(nmea);
    }});


    public void SendNmea2UDP(String nmeastring)
    {
    message = nmeastring;
    msg_length=message.length();
    messageB = message.getBytes();
    nmeapacket = new DatagramPacket(messageB, msg_length,local,server_port);
    try
    {
    socket.send(nmeapacket);
    }
    catch(Exception e) {}
    }


    NMEA data on PC


    To receive data and send it to the COM port from computers, a simple application was written in C #.
    Using the Virtual Serial Ports Emulator program , two connected virtual COM ports were created, one of which received data from the program on a PC, and on the second virtual COM port they can already be taken by any position that needs them.

    Conclusion


    If anyone is interested in the source code of the programs, then it is here on Android and Windows.

    As a result, you can run a program that understands NMEA data from the COM port:

    At the bottom right is a program that receives UDP from Android and transfers NMEA to the virtual COM port. The upd2com program sends to port 3, and for example, in this case, the SAS Planet accepts from port 4 (this is organized using VSPE). The little red dot is where I'm testing it all right now.
    Thank you for your attention, I hope the article was interesting to you.

    Sources used


    NMEA data
    wired_tether_1_4.apk
    Virtual Serial Port Emulator
    UDP listener C # sample
    Tethering and Reverse tethering
    root HTC Desire with HBOT 0.93

    Also popular now: