开发者

Cannot get NMEA file based mock location provider to work

开发者 https://www.devze.com 2023-03-22 05:22 出处:网络
I am still working on my first Android challenge (to myself ;)) and I am now in a position where I would like to test/debug some location based features, but I cannot get it开发者_如何学C to work at a

I am still working on my first Android challenge (to myself ;)) and I am now in a position where I would like to test/debug some location based features, but I cannot get it开发者_如何学C to work at all...

Here my code where I subscribe to nav updates:

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// We create the mock location provider
try {
    locationManager.addTestProvider("mockgps", false, false,
            false, false, true, true, true, 0, 5);
} catch (IllegalArgumentException e) {
    Log.w(getString(R.string.debug_tag),String.format("%s: mockgps was already created...", this.getClass().getSimpleName()));;
}

// Debugging we have the providers we need
List<String> providers = locationManager.getAllProviders();
Log.v(getString(R.string.debug_tag),String.format("%s: location provider ={%s}...", this.getClass().getSimpleName(), providers));

locationManager.requestLocationUpdates("mockgps", 100L, 0, locationListener);

// Some code removed
locationManager.setTestProviderEnabled("mockgps", true);

Here my NMEA file that I have pushed to /data/misc/location/mockgps/nmea

geo nmea $GPGGA,101205.0,4341.421828,N,00355.725347,E,1,09,0.9,80.1,M,49.0,M,,*6B
geo nmea $GPRMC,101205.0,A,4341.421828,N,00355.725347,E,0.0,,210711,,,A*47
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,0.9,1.4*32
geo nmea $GPGGA,101206.0,4341.421827,N,00355.725350,E,1,09,0.9,80.1,M,49.0,M,,*61
geo nmea $GPRMC,101206.0,A,4341.421827,N,00355.725350,E,0.0,,210711,,,A*4D
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,0.9,1.4*32
geo nmea $GPGGA,101207.0,4341.421825,N,00355.725354,E,1,09,0.9,80.1,M,49.0,M,,*66
geo nmea $GPRMC,101207.0,A,4341.421825,N,00355.725354,E,0.0,,210711,,,A*4A
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,0.9,1.4*32
geo nmea $GPGGA,101208.0,4341.421825,N,00355.725354,E,1,09,0.9,80.1,M,49.0,M,,*69
geo nmea $GPRMC,101208.0,A,4341.421825,N,00355.725354,E,0.0,,210711,,,A*45
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,0.9,1.4*32
geo nmea $GPGGA,101209.0,4341.420608,N,00355.725766,E,1,09,0.9,79.9,M,49.0,M,,*63
geo nmea $GPRMC,101209.0,A,4341.420608,N,00355.725766,E,0.0,,210711,,,A*41
geo nmea $GPGGA,101210.0,4341.420878,N,00355.726052,E,1,09,1.1,80.0,M,49.0,M,,*67
geo nmea $GPRMC,101210.0,A,4341.420878,N,00355.726052,E,0.0,,210711,,,A*43
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.8,1.1,1.4*34
geo nmea $GPGGA,101211.0,4341.421209,N,00355.726245,E,1,09,0.9,78.9,M,49.0,M,,*68
geo nmea $GPRMC,101211.0,A,4341.421209,N,00355.726245,E,0.0,,210711,,,A*4B
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,0.9,1.4*32
geo nmea $GPGGA,101212.0,4341.421025,N,00355.726918,E,1,09,1.0,78.3,M,49.0,M,,*66
geo nmea $GPRMC,101212.0,A,4341.421025,N,00355.726918,E,0.0,,210711,,,A*47
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,1.0,1.4*3A
geo nmea $GPGGA,101213.0,4341.421078,N,00355.726329,E,1,09,0.9,78.7,M,49.0,M,,*6B
geo nmea $GPRMC,101213.0,A,4341.421078,N,00355.726329,E,0.0,,210711,,,A*46
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.7,0.9,1.4*32
geo nmea $GPGGA,101214.0,4341.420836,N,00355.726263,E,1,09,1.1,79.3,M,49.0,M,,*6C
geo nmea $GPRMC,101214.0,A,4341.420836,N,00355.726263,E,0.0,,210711,,,A*4D
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.8,1.1,1.4*34
geo nmea $GPGGA,101215.0,4341.420796,N,00355.726174,E,1,09,1.1,79.7,M,49.0,M,,*69
geo nmea $GPRMC,101215.0,A,4341.420796,N,00355.726174,E,0.0,,210711,,,A*4C
geo nmea $GPGSA,A,3,09,12,15,17,18,22,26,27,28,,,,1.8,1.1,1.4*34
geo nmea $GPGGA,101216.0,4341.420774,N,00355.725884,E,1,06,1.1,80.1,M,49.0,M,,*6C
geo nmea $GPVTG,nan,T,nan,M,0.0,N,0.0,K,A*23
geo nmea $GPRMC,101216.0,A,4341.420774,N,00355.725884,E,0.0,,210711,,,A*46
geo nmea $GPGSA,A,3,09,12,15,18,22,27,,,,,,,1.8,1.1,1.4*3C
geo nmea $GPGGA,101217.0,4341.420783,N,00355.725775,E,1,06,1.1,80.4,M,49.0,M,,*61
geo nmea $GPRMC,101217.0,A,4341.420783,N,00355.725775,E,0.0,,210711,,,A*4E
geo nmea $GPGSA,A,3,09,12,15,18,22,27,,,,,,,1.8,1.1,1.4*3C
geo nmea $GPGSV,4,1,16,09,48,291,35,18,27,291,35,15,80,212,33,22,08,322,28*7E
geo nmea $GPGSV,4,2,16,12,20,217,27,27,65,313,24,26,45,133,24,17,31,092,21*77
geo nmea $GPGSV,4,3,16,32,,,,31,,,,30,,,,29,,,*72
geo nmea $GPGSV,4,4,16,25,,,,24,,,,23,,,,21,,,*7D
geo nmea $GPGGA,101218.0,4341.420815,N,00355.725879,E,1,06,1.1,80.5,M,49.0,M,,*6C
geo nmea $GPRMC,101218.0,A,4341.420815,N,00355.725879,E,0.0,,210711,,,A*42
geo nmea $GPGSA,A,3,09,12,15,18,22,27,,,,,,,1.8,1.1,1.4*3C

I do have fairly comprehensive logging in the listener and absolutely NOTHING happens... I get no GPS status updates, no location update whatsoever...

You help will be much appreciated. This is a real pain as I cannot even think about the hassle of having to do any single tests on the real phone (bar the risk of bricking it, I only have my own "real" phone to play with).

I still work with the emulator and my test device is 2.3.3.

For the record, here is the listener code:

LocationListener locationListener = new LocationListener() {

    public void onLocationChanged(Location location) {
        // Called when a new location is found by the network location provider.
        Log.v(getString(R.string.debug_tag),String.format("%s: got new location (%s)",
                NavManager.class.getSimpleName(), location.toString()));
        if (currentLocation != null) {
            lastLocation = currentLocation;
            currentLocation = new Location(location);
        }

        if (navigation == null) {
            navigation = new Navigation();
        }

        navigation.setLocation(currentLocation);
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
        locProvider = provider;
        locProviderStatus = status;
        Log.v(getString(R.string.debug_tag),String.format("%s: location provider status changed (povider=\"%s\", status=%d)",
                NavManager.class.getSimpleName(), locProvider, locProviderStatus));
    }

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}
  };   


You can simply send coordinates from the DDMS perspective to test the code, no need loading the NMEA file. There is so much data like the strings for the coordinates, altitude, speed, span. velocity, heading, number of satellites, tracked satellites , to be extracted from that file. Do the easy way. Extracting all these strings will take you a lot of time.

With the Location Control in DDMS you still send kind of mock coordinates, actually you simulate GPS device which also send the same NMEA file, but the usage is simplier than parsing/extracting all the Strings.

See here what information provides NMEA file http://aprs.gids.nl/nmea/


There is a bug in the emulator so that the NmeaListener onNmeaReceived(long timestamp, String nmea) never receives anything.

0

精彩评论

暂无评论...
验证码 换一张
取 消