Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handleTPV received twice #37

Open
Gianmariai opened this issue Mar 9, 2021 · 4 comments
Open

handleTPV received twice #37

Gianmariai opened this issue Mar 9, 2021 · 4 comments

Comments

@Gianmariai
Copy link

Hello,
I'm sure im not subscribing listrner 2 times, cause all passes in singleton but i continue to receive tpv twice with same data.

PLease Help.

@0x08
Copy link

0x08 commented Mar 9, 2021

Maybe you could provide a bit more input or a code snippet? Very hard for anybody to help you like this.

@Gianmariai
Copy link
Author

Sure.. my class is so simple:

`public class LocationManager {

private static LocationManager _instance;
public static String ON_GPS_POINT = "ON_GPS_POINT";

int currentSatsInView = 0;
int currentHDOP = 0;
int currentBearing = 0;
double lastDateTimeTrasmitted = 0.0;

public static LocationManager getInstance(){
    if(_instance == null)
        _instance = new LocationManager();
    return _instance;
}

private LocationManager(){

    try {

        GPSdEndpoint gpsd = new GPSdEndpoint("localhost", 2947, new ResultParser());
        gpsd.addListener(listener);
        gpsd.start();
        gpsd.watch(true, true);
        System.out.println("GPSD:Started");

    } catch (Exception ex) {
         System.out.println(ex.getMessage());
    }
}

ObjectListener listener = new ObjectListener(){
    
@Override
    public void handleTPV(TPVObject tpv) {

    //Fix same point received multiple times..
        if(tpv.getTimestamp() == lastDataTimeTrasmitted){
            return;
        }
        lastDataTimeTrasmitted = tpv.getTimestamp();


        if((tpv.getMode() == ENMEAMode.NoFix) || (tpv.getMode() == ENMEAMode.NotSeen)){
            return;
        } else {

	System.out.println("Lat:" + tpv.getLatitude());
	System.out.println("Lat:" + tpv.getLongitude());
	DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");  
            String strDate = dateFormat.format(new Date((long)tpv.getTimestamp() * 1000L));  
	System.out.println("Time:" + strDate); 
        }
    }

    @Override
    public void handleSKY(SKYObject sky) {
        currentSatsInView =  sky.getSatellites().size();
        currentHDOP = (int)sky.getHorizontalDOP();
        System.out.println("DOP:" + currentHDOP);
        System.out.println("SAT:" + currentSatsInView);
    }

    @Override
    public void handleATT(ATTObject att) {
        currentBearing = (int)att.getHeading();
        System.out.println(Direction(deg):" + currentBearing);
    }
};

}`

Thank you for your help.
Gianmaria

@hoegertn
Copy link
Member

First thing that comes to my mind is: Does the hardware/gpsd start in watch mode? So what happens if you do not call watch()?

@Gianmariai
Copy link
Author

Gianmariai commented Mar 10, 2021

Good Morning. I Tried. No events were generated all if I remove call to watch.
No events also if i call it with watch(true, false) or watch(false,true).

Also i noted that the more events I subscribe, the more same result were produced. I fixed temporary with this weird code:

if(tpv.getTimestamp() == lastDataTimeTrasmitted){ return; }
but I dont like it..

regards
Gianmaria
Italy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants