handleTPV received twice
Opened this issue · 4 comments
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.
Maybe you could provide a bit more input or a code snippet? Very hard for anybody to help you like this.
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
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()?
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